material-icon.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import classNames from 'classnames'
  2. import React from 'react'
  3. import unfilledIconTypes from '../../../fonts/material-symbols/unfilled-symbols.mjs'
  4. export type AvailableUnfilledIcon = (typeof unfilledIconTypes)[number]
  5. type BaseIconProps = React.ComponentProps<'i'> & {
  6. accessibilityLabel?: string
  7. modifier?: string
  8. size?: '2x'
  9. }
  10. type FilledIconProps = BaseIconProps & {
  11. type: string
  12. unfilled?: false
  13. }
  14. type UnfilledIconProps = BaseIconProps & {
  15. type: AvailableUnfilledIcon
  16. unfilled: true
  17. }
  18. type IconProps = FilledIconProps | UnfilledIconProps
  19. function MaterialIcon({
  20. type,
  21. className,
  22. accessibilityLabel,
  23. modifier,
  24. size,
  25. unfilled,
  26. ...rest
  27. }: IconProps) {
  28. const iconClassName = classNames('material-symbols', className, modifier, {
  29. [`size-${size}`]: size,
  30. unfilled,
  31. })
  32. return (
  33. <>
  34. <span className={iconClassName} aria-hidden="true" {...rest}>
  35. {type}
  36. </span>
  37. {accessibilityLabel && (
  38. <span className="visually-hidden">{accessibilityLabel}</span>
  39. )}
  40. </>
  41. )
  42. }
  43. export default MaterialIcon