Files
modeling-app/src/components/ActionIcon.tsx

64 lines
1.7 KiB
TypeScript
Raw Normal View History

import {
IconDefinition as SolidIconDefinition,
faCircleExclamation,
} from '@fortawesome/free-solid-svg-icons'
import { IconDefinition as BrandIconDefinition } from '@fortawesome/free-brands-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
2023-09-16 01:23:11 -04:00
import { CustomIcon, CustomIconName } from './CustomIcon'
const iconSizes = {
xs: 12,
sm: 14,
md: 20,
lg: 24,
}
export interface ActionIconProps extends React.PropsWithChildren {
2023-09-16 01:23:11 -04:00
icon?: SolidIconDefinition | BrandIconDefinition | CustomIconName
className?: string
bgClassName?: string
iconClassName?: string
size?: keyof typeof iconSizes
}
export const ActionIcon = ({
icon = faCircleExclamation,
className,
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 = `h-auto text-primary dark:text-current !group-disabled:text-chalkboard-60 !group-disabled:text-chalkboard-60 ${iconClassName}`
2023-09-16 01:23:11 -04:00
const computedBgClassName = `bg-primary/10 dark:bg-chalkboard-90 !group-disabled:bg-chalkboard-30 !dark:group-disabled:bg-chalkboard-80 ${bgClassName}`
2023-09-16 01:23:11 -04:00
return (
<div
className={
`w-fit inline-grid place-content-center ${className} ` +
2023-09-16 01:23:11 -04:00
computedBgClassName
}
>
2023-09-16 01:23:11 -04:00
{children ? (
children
) : typeof icon === 'string' ? (
<CustomIcon
name={icon}
width={iconSizes[size]}
height={iconSizes[size]}
className={computedIconClassName}
/>
) : (
<FontAwesomeIcon
icon={icon}
width={iconSizes[size]}
height={iconSizes[size]}
2023-09-16 01:23:11 -04:00
className={computedIconClassName}
/>
)}
</div>
)
}