IconBase.tsx 710 B

12345678910111213141516171819202122232425262728293031
  1. import { forwardRef } from 'react'
  2. import { generate } from './utils'
  3. import type { AbstractNode } from './utils'
  4. export type IconData = {
  5. name: string
  6. icon: AbstractNode
  7. }
  8. export type IconBaseProps = {
  9. data: IconData
  10. className?: string
  11. onClick?: React.MouseEventHandler<SVGElement>
  12. style?: React.CSSProperties
  13. }
  14. const IconBase = forwardRef<React.MutableRefObject<HTMLOrSVGElement>, IconBaseProps>((props, ref) => {
  15. const { data, className, onClick, style, ...restProps } = props
  16. return generate(data.icon, `svg-${data.name}`, {
  17. className,
  18. onClick,
  19. style,
  20. 'data-icon': data.name,
  21. 'aria-hidden': 'true',
  22. ...restProps,
  23. 'ref': ref,
  24. })
  25. })
  26. export default IconBase