mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-11-15 14:08:49 +00:00
* Add context provider for svelte package * Add context provider for react * Remove old vue 2 package * Add @lucide/vue package * Remove old vue 2 doc * Update docs * Adjust export template * Add context provider to solid package * Fix context * Implement context providers * Add context provider to preact * Adjust vue package! * Fix tests * Format code * Add context provider for Vue * Improve memoization * Update packages/lucide-react-native/tests/context.spec.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply fixes * Cleanup * Formatting * Move on * Update packages/lucide-react/tests/context.spec.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update packages/lucide-preact/tests/context.spec.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update packages/vue/tests/context.spec.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Remove x * update export template * apply feedback * fix export template * Fixes types and tests * fix tests * apply feedback * Remove class * Formatting * Update packages/svelte/src/context.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Remove fill form context providers * formatting * Add classname to context provider * Apply feedback * Format code * Rename files * Rename tsx to ts * Format file --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
89 lines
2.8 KiB
TypeScript
89 lines
2.8 KiB
TypeScript
import { createElement, forwardRef, type FunctionComponent } from 'react';
|
|
import * as NativeSvg from 'react-native-svg';
|
|
import defaultAttributes, { childDefaultAttributes } from './defaultAttributes';
|
|
import { IconNode, LucideProps } from './types';
|
|
import { useLucideContext } from './context';
|
|
|
|
interface IconComponentProps extends LucideProps {
|
|
iconNode: IconNode;
|
|
testID?: string;
|
|
className?: string;
|
|
}
|
|
|
|
/**
|
|
* Lucide icon component
|
|
*
|
|
* @component Icon
|
|
* @param {object} props
|
|
* @param {string} props.color - The color of the icon
|
|
* @param {number} props.size - The size of the icon
|
|
* @param {number} props.strokeWidth - The stroke width of the icon
|
|
* @param {boolean} props.absoluteStrokeWidth - Whether to use absolute stroke width
|
|
* @param {string} props.className - The class name of the icon
|
|
* @param {IconNode} props.children - The children of the icon
|
|
* @param {IconNode} props.iconNode - The icon node of the icon
|
|
*
|
|
* @returns {ForwardRefExoticComponent} LucideIcon
|
|
*/
|
|
const Icon = forwardRef<SVGSVGElement, IconComponentProps>(
|
|
(
|
|
{
|
|
color,
|
|
size,
|
|
strokeWidth,
|
|
absoluteStrokeWidth,
|
|
children,
|
|
iconNode,
|
|
className,
|
|
testID,
|
|
...rest
|
|
},
|
|
ref,
|
|
) => {
|
|
const {
|
|
size: contextSize = 24,
|
|
strokeWidth: contextStrokeWidth = 2,
|
|
absoluteStrokeWidth: contextAbsoluteStrokeWidth = false,
|
|
color: contextColor = 'currentColor',
|
|
} = useLucideContext() ?? {};
|
|
|
|
const calculatedStrokeWidth =
|
|
absoluteStrokeWidth ?? contextAbsoluteStrokeWidth
|
|
? (Number(strokeWidth ?? contextStrokeWidth) * 24) / Number(size ?? contextSize)
|
|
: strokeWidth ?? contextStrokeWidth;
|
|
|
|
const customAttrs = {
|
|
stroke: color ?? contextColor ?? defaultAttributes.stroke,
|
|
strokeWidth: calculatedStrokeWidth,
|
|
...rest,
|
|
};
|
|
|
|
return createElement(
|
|
NativeSvg.Svg as unknown as string,
|
|
{
|
|
ref,
|
|
...defaultAttributes,
|
|
width: size ?? contextSize ?? defaultAttributes.width,
|
|
height: size ?? contextSize ?? defaultAttributes.height,
|
|
'data-testid': testID,
|
|
className,
|
|
...customAttrs,
|
|
},
|
|
[
|
|
...iconNode.map(([tag, attrs]) => {
|
|
const upperCasedTag = (tag.charAt(0).toUpperCase() +
|
|
tag.slice(1)) as keyof typeof NativeSvg;
|
|
// duplicating the attributes here because generating the OTA update bundles don't inherit the SVG properties from parent (codepush, expo-updates)
|
|
return createElement(
|
|
NativeSvg[upperCasedTag] as FunctionComponent<LucideProps>,
|
|
{ ...childDefaultAttributes, ...customAttrs, ...attrs } as LucideProps,
|
|
);
|
|
}),
|
|
...((Array.isArray(children) ? children : [children]) || []),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
|
|
export default Icon;
|