Apply feedback

This commit is contained in:
Eric Fennis
2025-12-12 10:52:32 +01:00
parent 636ae1d9e0
commit 5528e13644
6 changed files with 29 additions and 17 deletions

View File

@@ -21,7 +21,7 @@ interface LucideProviderProps {
color?: string;
strokeWidth?: number;
absoluteStrokeWidth?: boolean;
class?: string
class?: string;
}
export function LucideProvider({

View File

@@ -1,4 +1,4 @@
import { createContext, type ReactNode, useContext } from 'react';
import { createContext, type ReactNode, useContext, useMemo } from 'react';
const LucideContext = createContext<{
size?: number;
@@ -20,8 +20,24 @@ interface LucideProviderProps {
absoluteStrokeWidth?: boolean;
}
export function LucideProvider({ children, ...props }: LucideProviderProps) {
return <LucideContext.Provider value={props}>{children}</LucideContext.Provider>;
export function LucideProvider({
children,
size,
color,
strokeWidth,
absoluteStrokeWidth,
}: LucideProviderProps) {
const value = useMemo(
() => ({
size,
color,
strokeWidth,
absoluteStrokeWidth,
}),
[size, color, strokeWidth, absoluteStrokeWidth],
);
return <LucideContext.Provider value={value}>{children}</LucideContext.Provider>;
}
export const useLucideContext = () => useContext(LucideContext);

View File

@@ -1,9 +1,6 @@
import { forwardRef, createElement } from 'react';
import { IconNode, LucideIcon, LucideProps } from './types';
// import { createElement, forwardRef } from 'react';
import { mergeClasses, toKebabCase, toPascalCase } from '@lucide/shared';
// import { IconNode, LucideProps } from './types';
import { IconNode, LucideProps } from './types';
import { toPascalCase } from '@lucide/shared';
import Icon from './Icon';
/**

View File

@@ -63,18 +63,18 @@ describe('Using LucideProvider', () => {
strokeWidth={4}
>
<House
size={24}
size={32}
color="blue"
strokeWidth={2}
strokeWidth={3}
/>
</LucideProvider>,
);
const IconComponent = container.firstElementChild;
expect(IconComponent).toHaveAttribute('width', '24');
expect(IconComponent).toHaveAttribute('height', '24');
expect(IconComponent).toHaveAttribute('width', '32');
expect(IconComponent).toHaveAttribute('height', '32');
expect(IconComponent).toHaveAttribute('stroke', 'blue');
expect(IconComponent).toHaveAttribute('stroke-width', '2');
expect(IconComponent).toHaveAttribute('stroke-width', '3');
});
});

View File

@@ -83,7 +83,7 @@ describe('Using lucide icon components', () => {
expect(container.innerHTML).toMatchSnapshot();
});
it('should use context values from he global set properties', () => {
it('should use context values from the global set properties', () => {
const { container } = render(ContextWrapper);
const IconComponent = container.firstElementChild;

View File

@@ -1,6 +1,5 @@
import { h } from 'vue';
import type { FunctionalComponent } from 'vue';
import { IconNode, LucideProps, LucideIcon } from './types';
import { IconNode, LucideIcon } from './types';
import Icon from './Icon';
/**