-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathHelpText.tsx
45 lines (42 loc) · 1.1 KB
/
HelpText.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import type { Placement } from '@floating-ui/utils';
import cl from 'clsx/lite';
import { forwardRef } from 'react';
import type { ButtonHTMLAttributes } from 'react';
import { Popover, type PopoverProps } from '../Popover';
export type HelpTextProps = {
/**
* Required descriptive label for screen readers.
**/
'aria-label': string;
/**
* Size of the helptext
* @default md
*/
size?: PopoverProps['size'];
/**
* Placement of the Popover.
* @default 'right'
*/
placement?: Placement;
} & Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'color'>;
export const HelpText = forwardRef<HTMLButtonElement, HelpTextProps>(
function HelpText(
{ placement = 'right', size = 'md', className, children, ...rest },
ref,
) {
return (
<Popover.Context>
<Popover.Trigger
className={cl('ds-helptext', className)}
ref={ref}
size={size}
variant='tertiary'
{...rest}
/>
<Popover placement={placement} size={size} variant='info'>
{children}
</Popover>
</Popover.Context>
);
},
);