2023-07-13 07:22:08 -04:00
|
|
|
import {
|
2023-08-15 22:33:52 -04:00
|
|
|
IconDefinition as SolidIconDefinition,
|
2023-07-13 07:22:08 -04:00
|
|
|
faCircleExclamation,
|
|
|
|
} from '@fortawesome/free-solid-svg-icons'
|
2023-08-15 22:33:52 -04:00
|
|
|
import { IconDefinition as BrandIconDefinition } from '@fortawesome/free-brands-svg-icons'
|
2023-07-13 07:22:08 -04:00
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
2023-09-16 01:23:11 -04:00
|
|
|
import { CustomIcon, CustomIconName } from './CustomIcon'
|
2023-07-13 07:22:08 -04:00
|
|
|
|
|
|
|
const iconSizes = {
|
|
|
|
sm: 12,
|
|
|
|
md: 14.4,
|
2023-08-28 20:31:49 -04:00
|
|
|
lg: 20,
|
|
|
|
xl: 28,
|
2023-07-13 07:22:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface ActionIconProps extends React.PropsWithChildren {
|
2023-09-16 01:23:11 -04:00
|
|
|
icon?: SolidIconDefinition | BrandIconDefinition | CustomIconName
|
2023-08-28 20:31:49 -04:00
|
|
|
className?: string
|
2023-07-13 07:22:08 -04:00
|
|
|
bgClassName?: string
|
|
|
|
iconClassName?: string
|
|
|
|
size?: keyof typeof iconSizes
|
|
|
|
}
|
|
|
|
|
|
|
|
export const ActionIcon = ({
|
2023-08-15 22:33:52 -04:00
|
|
|
icon = faCircleExclamation,
|
2023-08-28 20:31:49 -04:00
|
|
|
className,
|
2023-07-13 07:22:08 -04:00
|
|
|
bgClassName,
|
|
|
|
iconClassName,
|
|
|
|
size = 'md',
|
|
|
|
children,
|
|
|
|
}: ActionIconProps) => {
|
2023-09-16 01:23:11 -04:00
|
|
|
// By default, we reverse the icon color and background color in dark mode
|
|
|
|
const computedIconClassName =
|
|
|
|
iconClassName ||
|
|
|
|
`text-liquid-20 h-auto group-hover:text-liquid-10 hover:text-liquid-10 dark:text-chalkboard-100 dark:group-hover:text-chalkboard-100 dark:hover:text-chalkboard-100 group-disabled:bg-chalkboard-50 dark:group-disabled:bg-chalkboard-60 group-hover:group-disabled:bg-chalkboard-50 dark:group-hover:group-disabled:bg-chalkboard-50`
|
|
|
|
|
|
|
|
const computedBgClassName =
|
|
|
|
bgClassName ||
|
|
|
|
`bg-chalkboard-100 group-hover:bg-chalkboard-90 hover:bg-chalkboard-90 dark:bg-liquid-20 dark:group-hover:bg-liquid-10 dark:hover:bg-liquid-10 group-disabled:bg-chalkboard-80 dark:group-disabled:bg-chalkboard-80`
|
|
|
|
|
2023-07-13 07:22:08 -04:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={
|
2023-08-28 20:31:49 -04:00
|
|
|
`p-${
|
|
|
|
size === 'xl' ? '2' : '1'
|
|
|
|
} w-fit inline-grid place-content-center ${className} ` +
|
2023-09-16 01:23:11 -04:00
|
|
|
computedBgClassName
|
2023-07-13 07:22:08 -04:00
|
|
|
}
|
|
|
|
>
|
2023-09-16 01:23:11 -04:00
|
|
|
{children ? (
|
|
|
|
children
|
|
|
|
) : typeof icon === 'string' ? (
|
|
|
|
<CustomIcon
|
|
|
|
name={icon}
|
|
|
|
width={iconSizes[size]}
|
|
|
|
height={iconSizes[size]}
|
|
|
|
className={computedIconClassName}
|
|
|
|
/>
|
|
|
|
) : (
|
2023-07-13 07:22:08 -04:00
|
|
|
<FontAwesomeIcon
|
2023-08-15 22:33:52 -04:00
|
|
|
icon={icon}
|
2023-07-13 07:22:08 -04:00
|
|
|
width={iconSizes[size]}
|
|
|
|
height={iconSizes[size]}
|
2023-09-16 01:23:11 -04:00
|
|
|
className={computedIconClassName}
|
2023-07-13 07:22:08 -04:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|