lucide-react
Version:
A Lucide icon library package for React applications.
1 lines • 2.62 kB
Source Map (JSON)
{"version":3,"file":"Icon.mjs","sources":["../../src/Icon.ts"],"sourcesContent":["'use client';\n\nimport { createElement, forwardRef } from 'react';\nimport defaultAttributes from './defaultAttributes';\nimport { IconNode, LucideProps } from './types';\nimport { mergeClasses, hasA11yProp } from '@lucide/shared';\nimport { useLucideContext } from './context';\n\ninterface IconComponentProps extends LucideProps {\n iconNode: IconNode;\n}\n\n/**\n * Lucide icon component\n *\n * @component Icon\n * @param {object} props\n * @param {string} props.color - The color of the icon\n * @param {number} props.size - The size of the icon\n * @param {number} props.strokeWidth - The stroke width of the icon\n * @param {boolean} props.absoluteStrokeWidth - Whether to use absolute stroke width\n * @param {string} props.className - The class name of the icon\n * @param {IconNode} props.children - The children of the icon\n * @param {IconNode} props.iconNode - The icon node of the icon\n *\n * @returns {ForwardRefExoticComponent} LucideIcon\n */\nconst Icon = forwardRef<SVGSVGElement, IconComponentProps>(\n (\n { color, size, strokeWidth, absoluteStrokeWidth, className = '', children, iconNode, ...rest },\n ref,\n ) => {\n const {\n size: contextSize = 24,\n strokeWidth: contextStrokeWidth = 2,\n absoluteStrokeWidth: contextAbsoluteStrokeWidth = false,\n color: contextColor = 'currentColor',\n className: contextClass = '',\n } = useLucideContext() ?? {};\n\n const calculatedStrokeWidth =\n absoluteStrokeWidth ?? contextAbsoluteStrokeWidth\n ? (Number(strokeWidth ?? contextStrokeWidth) * 24) / Number(size ?? contextSize)\n : strokeWidth ?? contextStrokeWidth;\n\n return createElement(\n 'svg',\n {\n ref,\n ...defaultAttributes,\n width: size ?? contextSize ?? defaultAttributes.width,\n height: size ?? contextSize ?? defaultAttributes.height,\n stroke: color ?? contextColor,\n strokeWidth: calculatedStrokeWidth,\n className: mergeClasses('lucide', contextClass, className),\n ...(!children && !hasA11yProp(rest) && { 'aria-hidden': 'true' }),\n ...rest,\n },\n [\n ...iconNode.map(([tag, attrs]) => createElement(tag, attrs)),\n ...(Array.isArray(children) ? children : [children]),\n ],\n );\n },\n);\n\nexport default Icon;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AA2BA;AAAa;AAKT;AAAM;AACgB;AACc;AACgB;AAC5B;AACI;AAG5B;AAKA;AAAO;AACL;AACA;AACE;AACG;AAC6C;AACC;AAChC;AACJ;AAC4C;AACM;AAC5D;AACL;AACA;AAC6D;AACT;AACpD;AACF;AAEJ;;"}