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 = {
|
2023-12-06 14:44:13 -05:00
|
|
|
xs: 12,
|
|
|
|
sm: 14,
|
|
|
|
md: 20,
|
|
|
|
lg: 24,
|
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) => {
|
2024-05-10 19:02:11 -04:00
|
|
|
const computedIconClassName = `h-auto text-inherit dark:text-current !group-disabled:text-chalkboard-60 !group-disabled:text-chalkboard-60 ${iconClassName}`
|
|
|
|
const computedBgClassName = `bg-chalkboard-20 dark:bg-chalkboard-80 !group-disabled:bg-chalkboard-30 !dark:group-disabled:bg-chalkboard-80 ${bgClassName}`
|
2023-09-16 01:23:11 -04:00
|
|
|
|
2023-07-13 07:22:08 -04:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={
|
2024-08-29 14:21:42 -04:00
|
|
|
`w-fit self-stretch 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>
|
|
|
|
)
|
|
|
|
}
|