icon.tsx 888 B

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