lucide-react
Version:
A Lucide icon library package for React applications.
1 lines • 3.23 kB
Source Map (JSON)
{"version":3,"file":"Icon.mjs","sources":["../../src/Icon.ts"],"sourcesContent":["'use client';\n\nimport { createElement, forwardRef } from 'react';\nimport { buildLucideIconForReact, hasA11yProp, mergeClasses } from '@lucide/shared';\nimport { LucideIconData, LucideIconNode, LucideProps } from './types';\nimport { useLucideContext } from './context';\n\ntype IconComponentProps = LucideProps &\n (\n | {\n iconNode: LucideIconNode[];\n icon?: never;\n }\n | {\n icon: LucideIconData;\n iconNode?: never;\n }\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 {boolean} props.nonScalingStroke - Whether to use non scaling strokes\n * @param {string} props.className - The class name of the icon\n * @param {LucideIconNode[]} props.children - The children of the icon\n * @param {LucideIconNode[]} props.iconNode - The icon node of the icon\n *\n * @returns {ForwardRefExoticComponent} LucideIcon\n */\nconst Icon = forwardRef<SVGSVGElement, IconComponentProps>(\n (\n {\n color,\n size,\n width,\n height,\n strokeWidth,\n absoluteStrokeWidth,\n nonScalingStroke,\n className = '',\n children,\n iconNode = [],\n icon = {\n node: iconNode,\n aliases: [],\n size: 24,\n },\n ...rest\n },\n ref,\n ) => {\n const {\n size: contextSize = 24,\n strokeWidth: contextStrokeWidth = 2,\n absoluteStrokeWidth: contextAbsoluteStrokeWidth = false,\n nonScalingStroke: contextNonScalingStroke = false,\n color: contextColor = 'currentColor',\n className: contextClass = '',\n } = useLucideContext() ?? {};\n\n const hasAccessibleProp = Boolean(children) || hasA11yProp(rest);\n\n const [name, svgAttributes, builtIconNode = []] = buildLucideIconForReact(icon, {\n color: color ?? contextColor,\n width: width ?? size ?? contextSize,\n height: height ?? size ?? contextSize,\n strokeWidth: strokeWidth ?? contextStrokeWidth,\n absoluteStrokeWidth: absoluteStrokeWidth ?? contextAbsoluteStrokeWidth,\n nonScalingStroke: nonScalingStroke ?? contextNonScalingStroke,\n className: mergeClasses(contextClass, className),\n hasA11yProp: hasAccessibleProp,\n attributes: rest,\n });\n\n return createElement(\n name,\n {\n ref,\n ...svgAttributes,\n },\n [\n ...builtIconNode.map(([tag, attrs]) => createElement(tag, attrs)),\n ...(Array.isArray(children) ? children : [children]),\n ],\n );\n },\n);\n\nexport default Icon;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAmCA;AAAa;AAET;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACY;AACZ;AACY;AACL;AACC;AACI;AACJ;AACR;AACG;AAIL;AAAM;AACgB;AACc;AACgB;AACN;AACtB;AACI;AAG5B;AAEA;AAAgF;AAC9D;AACQ;AACE;AACE;AACgB;AACN;AACS;AAClC;AACD;AAGd;AAAO;AACL;AACA;AACE;AACG;AACL;AACA;AACkE;AACd;AACpD;AACF;AAEJ;;"}