Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

svelte: update for runes mode #2380

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ packages/lucide-static/icon-nodes.json
packages/lucide-static/font

# lucide-svelte
packages/lucide-svelte/src/icons/*.svelte
packages/lucide-svelte/.svelte-kit
2 changes: 1 addition & 1 deletion categories/charts.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "../category.schema.json",
"title": "Charts",
"icon": "pie-chart"
"icon": "chart-pie"
}
4 changes: 2 additions & 2 deletions docs/guide/packages/lucide-svelte.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ The example below imports all ES Modules, so exercise caution when using it. Imp
```svelte
<script>
import * as icons from 'lucide-svelte';
export let name;
const { name, ...props } = $props();
</script>

<svelte:component this="{icons[name]}" {...$$props} />
<svelte:component this="{icons[name]}" {...props} />
```

#### Using the Icon Component
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
"generate:nextJSAliases": "node ./scripts/generateNextJSAliases.mjs",
"postinstall": "husky install",
"lint:es": "eslint .",
"lint:format": "prettier \"**/*.{js,mjs,ts,jsx,tsx,html,css,scss,json,yml,yaml}\" --check",
"lint:format": "pnpm exec prettier \"**/*.{js,mjs,ts,jsx,tsx,html,css,scss,json,yml,yaml,svelte}\" --plugin prettier-plugin-svelte --check",
"lint:json:icons": "ajv --spec=draft2020 -s icon.schema.json -d 'icons/*.json' > /dev/null",
"lint:json:categories": "ajv --spec=draft2020 -s category.schema.json -d 'categories/*.json' > /dev/null",
"lint:json": "pnpm run lint:json:icons && pnpm run lint:json:categories",
"lint": "pnpm lint:es && pnpm lint:format && pnpm lint:json",
"format": "prettier \"**/*.{js,mjs,ts,jsx,tsx,html,css,scss,json,yml,yaml}\" --write",
"format": "pnpm exec prettier \"**/*.{js,mjs,ts,jsx,tsx,html,css,scss,json,yml,yaml,svelte}\" --plugin prettier-plugin-svelte --write",
"prepare": "husky install",
"gi": "node ./scripts/generate/generateIcons.mjs",
"rename": "node scripts/rename/renameIcon.mjs",
Expand All @@ -60,6 +60,7 @@
"minimist": "^1.2.8",
"p-memoize": "^7.1.1",
"prettier": "3.2.4",
"prettier-plugin-svelte": "^3.2.6",
"semver": "^7.5.4",
"simple-git": "^3.25.0",
"svgo": "^3.1.0",
Expand Down
14 changes: 7 additions & 7 deletions packages/lucide-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@
"devDependencies": {
"@lucide/build-icons": "workspace:*",
"@lucide/helpers": "workspace:*",
"@sveltejs/package": "^2.2.3",
"@sveltejs/vite-plugin-svelte": "^2.4.2",
"@sveltejs/package": "^2.3.4",
"@sveltejs/vite-plugin-svelte": "^3.1.1",
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/svelte": "^4.0.2",
"@tsconfig/svelte": "^5.0.0",
"@testing-library/svelte": "^5.2.1",
"@tsconfig/svelte": "^5.0.4",
"jest-serializer-html": "^7.1.0",
"jsdom": "^20.0.3",
"svelte": "^4.0.1",
"svelte-check": "^3.4.4",
"svelte-preprocess": "^5.0.4",
"svelte": "5.0.0-next.222",
"svelte-check": "^3.8.5",
"svelte-preprocess": "^6.0.2",
"typescript": "^5.1.6",
"vite": "5.0.13",
"vitest": "^1.1.1"
Expand Down
4 changes: 2 additions & 2 deletions packages/lucide-svelte/scripts/exportTemplate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ${getJSBanner()}
import Icon from '../Icon.svelte';
import type { IconNode, IconProps } from '../types.js';

type $$Props = IconProps;
const props: IconProps = $props();

const iconNode: IconNode = ${JSON.stringify(children)};

Expand All @@ -29,7 +29,7 @@ const iconNode: IconNode = ${JSON.stringify(children)};
*/
</script>

<Icon name="${iconName}" {...$$props} iconNode={iconNode}>
<Icon name="${iconName}" {...props} iconNode={iconNode}>
<slot/>
</Icon>
`;
Expand Down
64 changes: 35 additions & 29 deletions packages/lucide-svelte/src/Icon.svelte
Original file line number Diff line number Diff line change
@@ -1,45 +1,51 @@
<script lang="ts">
import defaultAttributes from './defaultAttributes'
import defaultAttributes from './defaultAttributes';
import type { IconNode } from './types';
import type { SvelteHTMLElements } from 'svelte/elements';

export let name: string | undefined = undefined
export let color = 'currentColor'
export let size: number | string = 24
export let strokeWidth: number | string = 2
export let absoluteStrokeWidth: boolean = false
export let iconNode: IconNode = []
const {
class: className,
children,

const mergeClasses = <ClassType = string | undefined | null>(
...classes: ClassType[]
) => classes.filter((className, index, array) => {
return Boolean(className) && array.indexOf(className) === index;
})
.join(' ');
name = undefined,
color = 'currentColor',
size = 24,
strokeWidth = 2,
absoluteStrokeWidth = false,
iconNode = [],

...props
}: SvelteHTMLElements['svg'] & {
name: string | undefined;
color: string;
size: number | string;
strokeWidth: number | string;
absoluteStrokeWidth: boolean;
iconNode: IconNode;
} = $props();

const mergeClasses = <ClassType = string | undefined | null,>(...classes: ClassType[]) =>
classes
.filter((className, index, array) => {
return Boolean(className) && array.indexOf(className) === index;
})
.join(' ');
</script>

<svg
{...defaultAttributes}
{...$$restProps}
{...props}
width={size}
height={size}
stroke={color}
stroke-width={
absoluteStrokeWidth
? Number(strokeWidth) * 24 / Number(size)
: strokeWidth
}
class={
mergeClasses(
'lucide-icon',
'lucide',
name ? `lucide-${name}`: '',
$$props.class
)
}
stroke-width={absoluteStrokeWidth ? (Number(strokeWidth) * 24) / Number(size) : strokeWidth}
class={mergeClasses('lucide-icon', 'lucide', name ? `lucide-${name}` : '', className)}
>
{#each iconNode as [tag, attrs]}
<svelte:element this={tag} {...attrs}/>
<svelte:element
this={tag}
{...attrs}
/>
{/each}
<slot />
{@render children?.()}
</svg>
2 changes: 1 addition & 1 deletion packages/lucide-svelte/tests/TestSlots.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import Smile from '../src/icons/smile.svelte'
import Smile from '../src/icons/smile.svelte';
</script>

<Smile>
Expand Down
Loading
Loading