UNPKG

@klnjs/react-icon

Version:

An icon component for React.

18 lines (17 loc) 1.08 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { memo } from 'react'; import { forwardRef } from '@klnjs/react-core'; import { IconTitle } from './IconTitle'; import { IconDescription } from './IconDescription'; import { IconPath } from './IconPath'; import { IconProvider } from './IconContext'; import { useIcon } from './useIcon'; export const Icon = forwardRef((props, forwardedRef) => { const icon = useIcon(); return (_jsx(IconProvider, { value: icon, children: _jsx("svg", { ref: forwardedRef, fill: "currentColor", "aria-labelledby": icon.labelId, "aria-describedby": icon.descriptionId, ...props }) })); }); export const createIcon = ({ title, description, path, viewBox }) => { const Component = forwardRef((props, forwardedRef) => (_jsxs(Icon, { ref: forwardedRef, viewBox: viewBox, ...props, children: [title ? _jsx(IconTitle, { children: title }) : null, description ? (_jsx(IconDescription, { children: description })) : null, _jsx(IconPath, { d: path })] }))); Component.displayName = title; return memo(Component); };