Files
web/packages/design-system/lib/components/Icons/MaterialIcon/index.tsx
Anton Gunnarsson cc60cf2903 Merged in chore/change-icons-to-rounded (pull request #3520)
chore: Change default icon style to rounded

* Change default icon style to rounded


Approved-by: Linus Flood
2026-01-30 10:13:03 +00:00

73 lines
1.7 KiB
TypeScript

import { HTMLAttributes } from "react"
import { MaterialIconName, materialIcons } from "./generated"
import { VariantProps, cx } from "class-variance-authority"
import { iconVariants } from "../variants"
import styles from "./index.module.css"
export interface MaterialIconProps
extends
Omit<HTMLAttributes<HTMLOrSVGElement>, "color" | "id">,
VariantProps<typeof iconVariants> {
icon: MaterialIconName
size?: number
styleName?: "outlined" | "rounded" | "sharp"
isFilled?: boolean
className?: string
}
export type MaterialIconSetIconProps = Omit<MaterialIconProps, "icon">
export function MaterialIcon({
icon,
size = 24,
styleName = "rounded",
color = "CurrentColor",
isFilled,
className,
...rest
}: MaterialIconProps) {
const iconStyles = materialIcons[icon]
if (!iconStyles) {
console.warn(`Icon "${icon}" not found in registry`)
return null
}
const styleVariants = iconStyles[styleName]
if (!styleVariants) {
console.warn(`Icon "${icon}" does not have style "${styleName}"`)
return null
}
const IconComponent = isFilled ? styleVariants.filled : styleVariants.outlined
if (!IconComponent) {
console.warn(
`Icon "${icon}" does not have ${
isFilled ? "filled" : "outlined"
} variant for style "${styleName}"`
)
return null
}
const iconClassName = iconVariants({ color })
return (
<span
data-testid="MaterialIcon"
data-icon-name={icon}
className={cx(styles.iconWrapper, className)}
{...rest}
>
<IconComponent
width={size}
height={size}
className={iconClassName}
aria-hidden
focusable={false}
/>
</span>
)
}