Compare commits
1 commit
icon/motio
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c1a02a04d4 |
10 changed files with 60 additions and 24 deletions
|
|
@ -18,7 +18,7 @@ export interface LucideConfig {
|
|||
* Stroke width
|
||||
* @default 2
|
||||
*/
|
||||
strokeWidth: number;
|
||||
strokeWidth: string | number;
|
||||
/**
|
||||
* Whether to use absolute stroke width.
|
||||
* @deprecated Use `nonScalingStroke` instead.
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ import { createContext, h, type ComponentChildren } from 'preact';
|
|||
import { useContext, useMemo } from 'preact/hooks';
|
||||
|
||||
const LucideContext = createContext<{
|
||||
size?: number;
|
||||
size?: number | string;
|
||||
color?: string;
|
||||
strokeWidth?: number;
|
||||
strokeWidth?: number | string;
|
||||
/**
|
||||
* @deprecated Use `nonScalingStroke` instead.
|
||||
*/
|
||||
|
|
@ -22,9 +22,9 @@ const LucideContext = createContext<{
|
|||
|
||||
interface LucideProviderProps {
|
||||
children: ComponentChildren;
|
||||
size?: number;
|
||||
size?: number | string;
|
||||
color?: string;
|
||||
strokeWidth?: number;
|
||||
strokeWidth?: number | string;
|
||||
/**
|
||||
* @deprecated Use `nonScalingStroke` instead.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { createContext, createElement, type ReactNode, useContext, useMemo } from 'react';
|
||||
|
||||
const LucideContext = createContext<{
|
||||
size?: number;
|
||||
size?: number | string;
|
||||
color?: string;
|
||||
strokeWidth?: number;
|
||||
strokeWidth?: number | string;
|
||||
/**
|
||||
* @deprecated Use `nonScalingStroke` instead.
|
||||
*/
|
||||
|
|
@ -21,9 +21,9 @@ const LucideContext = createContext<{
|
|||
|
||||
interface LucideProviderProps {
|
||||
children: ReactNode;
|
||||
size?: number;
|
||||
size?: number | string;
|
||||
color?: string;
|
||||
strokeWidth?: number;
|
||||
strokeWidth?: number | string;
|
||||
/**
|
||||
* @deprecated Use `nonScalingStroke` instead.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ import { createContext, createElement, type ReactNode, useContext, useMemo } fro
|
|||
import { LucideProps } from './types';
|
||||
|
||||
type LucideConfig = {
|
||||
size: number;
|
||||
size: number | string;
|
||||
color: string;
|
||||
strokeWidth: number;
|
||||
strokeWidth: number | string;
|
||||
/**
|
||||
* @deprecated Use `nonScalingStroke` instead.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { createContext, splitProps, type JSXElement } from 'solid-js';
|
||||
|
||||
export const LucideContext = createContext<{
|
||||
size?: number;
|
||||
size?: number | string;
|
||||
color?: string;
|
||||
strokeWidth?: number;
|
||||
strokeWidth?: number | string;
|
||||
/**
|
||||
* @deprecated Use `nonScalingStroke` instead.
|
||||
*/
|
||||
|
|
@ -21,9 +21,9 @@ export const LucideContext = createContext<{
|
|||
|
||||
interface LucideProviderProps {
|
||||
children: JSXElement;
|
||||
size?: number;
|
||||
size?: number | string;
|
||||
color?: string;
|
||||
strokeWidth?: number;
|
||||
strokeWidth?: number | string;
|
||||
/**
|
||||
* @deprecated Use `nonScalingStroke` instead.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -30,11 +30,18 @@ function buildLucideIconNode(icon: LucideIconData, params: LucideBuildParams = {
|
|||
? mergeClasses(...classNamesFromClassName)
|
||||
: mergeClasses('lucide', ...iconClassNames, ...classNamesFromClassName);
|
||||
|
||||
const calculatedStrokeWidth = params.absoluteStrokeWidth
|
||||
? (Number(params.strokeWidth ?? defaultAttributes['stroke-width']) *
|
||||
let calculatedStrokeWidth = params.strokeWidth ?? defaultAttributes['stroke-width'];
|
||||
|
||||
if (params.absoluteStrokeWidth) {
|
||||
const scaled =
|
||||
(Number(calculatedStrokeWidth) *
|
||||
Number(icon.size ?? icon.width ?? defaultAttributes['width'])) /
|
||||
Number(params.size ?? params.width ?? defaultAttributes['width'])
|
||||
: (params.strokeWidth ?? defaultAttributes['stroke-width']);
|
||||
Number(params.size ?? params.width ?? defaultAttributes['width']);
|
||||
|
||||
// Only numeric lengths can be scaled; a CSS unit such as `1em`, or a size of `0`, makes the
|
||||
// conversion non-finite, so the unscaled width stands rather than emitting `NaN`.
|
||||
if (Number.isFinite(scaled)) calculatedStrokeWidth = scaled;
|
||||
}
|
||||
|
||||
const attributes = {
|
||||
...Object.entries(defaultAttributes).reduce((attrs, [attrName, value]) => {
|
||||
|
|
|
|||
29
packages/shared/tests/buildLucideIconNode.spec.ts
Normal file
29
packages/shared/tests/buildLucideIconNode.spec.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import { describe, it, expect } from 'vitest';
|
||||
import buildLucideIconNode from '../src/build/buildLucideIconNode';
|
||||
|
||||
const icon = { name: 'circle', size: 24, node: [] };
|
||||
|
||||
const strokeWidthOf = (params: Parameters<typeof buildLucideIconNode>[1]) =>
|
||||
buildLucideIconNode(icon, params)[1]['stroke-width'];
|
||||
|
||||
describe('buildLucideIconNode absoluteStrokeWidth', () => {
|
||||
it('scales the stroke width for numeric sizes', () => {
|
||||
expect(strokeWidthOf({ absoluteStrokeWidth: true, strokeWidth: 2, size: 48 })).toBe(1);
|
||||
});
|
||||
|
||||
it('falls back to the unscaled width for a CSS unit size', () => {
|
||||
expect(strokeWidthOf({ absoluteStrokeWidth: true, strokeWidth: 2, size: '1em' })).toBe(2);
|
||||
});
|
||||
|
||||
it('falls back to the unscaled width for a non-numeric stroke width', () => {
|
||||
expect(strokeWidthOf({ absoluteStrokeWidth: true, strokeWidth: '1em', size: 48 })).toBe('1em');
|
||||
});
|
||||
|
||||
it('falls back to the unscaled width for a zero size', () => {
|
||||
expect(strokeWidthOf({ absoluteStrokeWidth: true, strokeWidth: 2, size: 0 })).toBe(2);
|
||||
});
|
||||
|
||||
it('leaves the stroke width alone when not absolute', () => {
|
||||
expect(strokeWidthOf({ strokeWidth: 2, size: 48 })).toBe(2);
|
||||
});
|
||||
});
|
||||
|
|
@ -4,8 +4,8 @@ const LucideContext = Symbol('lucide-context');
|
|||
|
||||
export interface LucideGlobalContext {
|
||||
color?: string;
|
||||
size?: number;
|
||||
strokeWidth?: number;
|
||||
size?: number | string;
|
||||
strokeWidth?: number | string;
|
||||
/**
|
||||
* @deprecated Use `nonScalingStroke` instead.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ import { provide, inject } from 'vue';
|
|||
export const LUCIDE_CONTEXT = Symbol('lucide-icons');
|
||||
|
||||
interface LucideIconsContext {
|
||||
size?: number;
|
||||
size?: number | string;
|
||||
color?: string;
|
||||
strokeWidth?: number;
|
||||
strokeWidth?: number | string;
|
||||
/**
|
||||
* @deprecated Use `nonScalingStroke` instead.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import type {
|
|||
} from '@lucide/shared/types';
|
||||
|
||||
export interface LucideProps extends Partial<SVGAttributes> {
|
||||
size?: 24 | number;
|
||||
size?: 24 | number | string;
|
||||
strokeWidth?: number | string;
|
||||
/**
|
||||
* @deprecated Use `nonScalingStroke` instead.
|
||||
|
|
|
|||
Loading…
Reference in a new issue