({
tooltip,
className,
isDisabled,
icon: Icon,
size = "sm",
color = "secondary",
tooltipPlacement = "top",
...otherProps
}: Props)
| 53 | export type Props = ButtonProps | LinkProps; |
| 54 | |
| 55 | export const ButtonUtility = ({ |
| 56 | tooltip, |
| 57 | className, |
| 58 | isDisabled, |
| 59 | icon: Icon, |
| 60 | size = "sm", |
| 61 | color = "secondary", |
| 62 | tooltipPlacement = "top", |
| 63 | ...otherProps |
| 64 | }: Props) => { |
| 65 | const href = "href" in otherProps ? otherProps.href : undefined; |
| 66 | const Component = href ? AriaLink : AriaButton; |
| 67 | |
| 68 | let props = {}; |
| 69 | |
| 70 | if (href) { |
| 71 | props = { |
| 72 | ...otherProps, |
| 73 | |
| 74 | href: isDisabled ? undefined : href, |
| 75 | |
| 76 | // Since anchor elements do not support the `disabled` attribute and state, |
| 77 | // we need to specify `data-rac` and `data-disabled` in order to be able |
| 78 | // to use the `disabled:` selector in classes. |
| 79 | ...(isDisabled ? { "data-rac": true, "data-disabled": true } : {}), |
| 80 | }; |
| 81 | } else { |
| 82 | props = { |
| 83 | ...otherProps, |
| 84 | |
| 85 | type: otherProps.type || "button", |
| 86 | isDisabled, |
| 87 | }; |
| 88 | } |
| 89 | |
| 90 | const content = ( |
| 91 | <Component |
| 92 | aria-label={tooltip} |
| 93 | {...props} |
| 94 | className={cx( |
| 95 | "group relative inline-flex h-max cursor-pointer items-center justify-center rounded-md p-1.5 outline-focus-ring transition duration-100 ease-linear focus-visible:outline-2 focus-visible:outline-offset-2 disabled:cursor-not-allowed disabled:opacity-50", |
| 96 | styles[color], |
| 97 | |
| 98 | // Icon styles |
| 99 | "*:data-icon:pointer-events-none *:data-icon:shrink-0 *:data-icon:text-current *:data-icon:transition-inherit-all", |
| 100 | size === "xs" ? "*:data-icon:size-4" : "*:data-icon:size-5", |
| 101 | |
| 102 | className, |
| 103 | )} |
| 104 | > |
| 105 | {isReactComponent(Icon) && <Icon data-icon />} |
| 106 | {isValidElement(Icon) && Icon} |
| 107 | </Component> |
| 108 | ); |
| 109 | |
| 110 | if (tooltip) { |
| 111 | return ( |
| 112 | <Tooltip title={tooltip} placement={tooltipPlacement} isDisabled={isDisabled} offset={size === "xs" ? 4 : 6}> |
nothing calls this directly
no test coverage detected