PluginProbe
Code Snippets / 4.0.0-beta.1
Code Snippets v4.0.0-beta.1
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
code-snippets / js / components / common / Tooltip.tsx

Tooltip.tsx in Code Snippets 4.0.0-beta.1, at js/components/common/Tooltip.tsx

50 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import React, { useId } from 'react'
2 import classnames from 'classnames'
3 import { __ } from '@wordpress/i18n'
4 import { trimTrailingChar } from '../../utils/text'
5 import type { ReactNode } from 'react'
6
7 export interface TooltipProps {
8 block?: boolean
9 inline?: boolean
10 start?: boolean
11 end?: boolean
12 icon?: ReactNode
13 children: ReactNode
14 className?: classnames.Argument
15 label?: string
16 }
17
18 export const Tooltip: React.FC<TooltipProps> = ({ block, inline, start, end, icon, className, children, label }) => {
19 const tooltipId = useId()
20 return (
21 <div className={classnames(
22 'tooltip',
23 { 'tooltip-block': block, 'tooltip-inline': inline, 'tooltip-start': start, 'tooltip-end': end },
24 className
25 )}>
26 <button
27 type="button"
28 className="tooltip-trigger"
29 aria-label={label ?? __('More information', 'code-snippets')}
30 aria-describedby={tooltipId}
31 >
32 {icon ?? <span className="dashicons dashicons-editor-help" aria-hidden="true"></span>}
33 </button>
34 <div role="tooltip" className="tooltip-content" id={tooltipId}>
35 {children}
36 </div>
37 </div>
38 )
39 }
40
41 export const ErrorTooltip: React.FC<{ message: string }> = ({ message }) =>
42 <Tooltip
43 block
44 end
45 label={__('Error', 'code-snippets')}
46 icon={<span className="dashicons dashicons-warning" aria-hidden="true"></span>}
47 >
48 {`${trimTrailingChar(message, '.!?')}. ${__('Please try again.', 'code-snippets')}`}
49 </Tooltip>
50