icon.tsx 758 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import classNames from 'classnames'
  2. type IconOwnProps = {
  3. type: string
  4. spin?: boolean
  5. fw?: boolean
  6. modifier?: string
  7. accessibilityLabel?: string
  8. }
  9. type IconProps = IconOwnProps &
  10. Omit<React.ComponentProps<'i'>, keyof IconOwnProps>
  11. function Icon({
  12. type,
  13. spin,
  14. fw,
  15. modifier,
  16. className = '',
  17. accessibilityLabel,
  18. ...rest
  19. }: IconProps) {
  20. const iconClassName = classNames(
  21. 'fa',
  22. `fa-${type}`,
  23. {
  24. 'fa-spin': spin,
  25. 'fa-fw': fw,
  26. [`fa-${modifier}`]: modifier,
  27. },
  28. className
  29. )
  30. return (
  31. <>
  32. <i className={iconClassName} aria-hidden="true" {...rest} />
  33. {accessibilityLabel && (
  34. <span className="sr-only">{accessibilityLabel}</span>
  35. )}
  36. </>
  37. )
  38. }
  39. export default Icon