mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-11-17 14:28:25 +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>
79 lines
2.1 KiB
TypeScript
79 lines
2.1 KiB
TypeScript
import { computed, type FunctionalComponent, h } from 'vue';
|
|
import { isEmptyString, mergeClasses, toKebabCase, toPascalCase } from '@lucide/shared';
|
|
import defaultAttributes from './defaultAttributes';
|
|
import { IconNode, LucideProps } from './types';
|
|
import { useLucideProps } from './context';
|
|
|
|
interface IconProps {
|
|
iconNode: IconNode;
|
|
name: string;
|
|
}
|
|
|
|
const Icon: FunctionalComponent<LucideProps & IconProps> = (
|
|
{
|
|
name,
|
|
iconNode,
|
|
absoluteStrokeWidth,
|
|
'absolute-stroke-width': absoluteStrokeWidthKebabCase,
|
|
strokeWidth,
|
|
'stroke-width': strokeWidthKebabCase,
|
|
size,
|
|
color,
|
|
...props
|
|
},
|
|
{ slots },
|
|
) => {
|
|
const {
|
|
size: contextSize,
|
|
color: contextColor,
|
|
strokeWidth: contextStrokeWidth = 2,
|
|
absoluteStrokeWidth: contextAbsoluteStrokeWidth = false,
|
|
class: contextClass = '',
|
|
} = useLucideProps();
|
|
|
|
const calculatedStrokeWidth = computed(() => {
|
|
const isAbsoluteStrokeWidth =
|
|
isEmptyString(absoluteStrokeWidth) ||
|
|
isEmptyString(absoluteStrokeWidthKebabCase) ||
|
|
absoluteStrokeWidth === true ||
|
|
absoluteStrokeWidthKebabCase === true ||
|
|
contextAbsoluteStrokeWidth === true;
|
|
|
|
const strokeWidthValue =
|
|
strokeWidth ||
|
|
strokeWidthKebabCase ||
|
|
contextStrokeWidth ||
|
|
defaultAttributes['stroke-width'];
|
|
|
|
if (isAbsoluteStrokeWidth) {
|
|
return (
|
|
(Number(strokeWidthValue) * 24) / Number(size ?? contextSize ?? defaultAttributes.width)
|
|
);
|
|
}
|
|
|
|
return strokeWidthValue;
|
|
});
|
|
|
|
return h(
|
|
'svg',
|
|
{
|
|
...defaultAttributes,
|
|
...props,
|
|
width: size ?? contextSize ?? defaultAttributes.width,
|
|
height: size ?? contextSize ?? defaultAttributes.height,
|
|
stroke: color ?? contextColor ?? defaultAttributes.stroke,
|
|
'stroke-width': calculatedStrokeWidth.value,
|
|
class: mergeClasses(
|
|
'lucide',
|
|
contextClass,
|
|
...(name
|
|
? [`lucide-${toKebabCase(toPascalCase(name))}-icon`, `lucide-${toKebabCase(name)}`]
|
|
: ['lucide-icon']),
|
|
),
|
|
},
|
|
[...iconNode.map((child) => h(...child)), ...(slots.default ? [slots.default()] : [])],
|
|
);
|
|
};
|
|
|
|
export default Icon;
|