-
-
Notifications
You must be signed in to change notification settings - Fork 692
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
feat(@lucide/svelte): Lucide svelte 5 package #2753
Conversation
* Update peerDependencies to support Svelte 5 * Bump svelte version * Bump @testing-library/svelte version * Remove alias in vitest.config.ts that causes tests to fail due to deprecated svelte/internal API * Convert to svelte 5 syntax * Bump vite & @sveltejs/vite-plugin-svelte version * Fix error during render when children prop is missing & fix components being mounted on the server during tests * Update test snapshots to reflect the differences in the html generated by svelte 5 * Convert class attribute to new array syntax with built-in clsx * Convert export template to svelte 5 syntax
* Update peerDependencies to support Svelte 5 * Bump svelte version * Bump @testing-library/svelte version * Remove alias in vitest.config.ts that causes tests to fail due to deprecated svelte/internal API * Convert to svelte 5 syntax * Bump vite & @sveltejs/vite-plugin-svelte version * Fix error during render when children prop is missing & fix components being mounted on the server during tests * Update test snapshots to reflect the differences in the html generated by svelte 5 * Convert class attribute to new array syntax with built-in clsx * Convert export template to svelte 5 syntax
Hello, thanks for putting this together. I would like to try Lucide with Svelte 5 but I am getting a TypeScript error when I try to import an icon (any icon) from
I also noticed a test is failing which might be related?
|
@woconnor Thanks for checking, made some fixes. |
Thanks for the work @ericfennis! <script lang="ts">
import { Home, Library, Cog } from '@lucide/svelte';
const menuItems = [
{
name: 'Home',
href: '/',
icon: Home
},
{
name: 'Blog',
href: '/blog',
icon: Library
},
{
name: 'Projects',
href: '/projects',
icon: Cog
}
] as const;
</script>
{#each menuItems as item}
{@const Icon = item.icon}
<!-- const Icon: typeof Home | typeof Library | typeof Cog -->
<Icon />
<a href={item.href}>
<span>{item.name}</span>
</a>
{/each} It got rid of the error and I believe gives better type information as well, but I'll leave it up to you to be the judge of that. The other thing I noticed is that the component type definitions generated during build use the |
Yes, I ran into this too. Svelte has moved to the new Also, side note @aurelienrichard - you can just render |
Thanks for the fixes @ericfennis. I am also running into the type error that the icons do not extend the Svelte 5 Here's the output from
Apart from this type error, everything seems to work fine at runtime. |
@woconnor Can you maybe post your |
Any update on this package being updated to svelte 5? |
Here's the component. As a workaround, I let the icon props type be either <script lang="ts">
import type { Component, ComponentType } from "svelte";
import { page } from "$app/state";
interface Props {
href: string;
title: string;
// eslint-disable-next-line @typescript-eslint/no-deprecated
icon: Component | ComponentType;
}
const { href, title, icon: Icon }: Props = $props();
</script>
<a
{href}
data-prime={page.url.pathname == href}
class="p-2 rounded-md flex items-center leading-none gap-3 text-grey-700 dark:text-grey-400 hover:text-primary-700 dark:hover:text-white data-prime:text-primary-700 dark:data-prime:text-white hover:bg-primary-300/25 dark:hover:bg-grey-800 data-prime:bg-primary-300/25 dark:data-prime:bg-grey-800"
>
<Icon class="shrink-0 size-6" />
<span class="text-sm leading-6 font-semibold">{title}</span>
</a> To use it, an icon is imported and then passed as a prop. This works with other Svelte components, e.g. I have a Logo.svelte file that contains an SVG that I can pass as an icon. I found that I must import Lucide icons using the full path otherwise I get an error. <script lang="ts">
// Module '"@lucide/svelte"' has no exported member 'House'. ts (2305)
// import { House } from "@lucide/svelte";
import House from "@lucide/svelte/icons/house";
import Button from "$lib/components/Button.svelte";
</script>
<Button href="/" title="Home" icon={House} /> I looked at the type declaration file import { SvelteComponent } from "svelte";
declare const __propDef: {
props: $$_sveltets_Props;
events: {
[evt: string]: CustomEvent<any>;
};
slots: {};
};
export type HouseProps = typeof __propDef.props;
export type HouseEvents = typeof __propDef.events;
export type HouseSlots = typeof __propDef.slots;
export default class House extends SvelteComponent<HouseProps, HouseEvents, HouseSlots> {
}
export {}; |
@woconnor Thanks this helped. I've fixed the types created a new version on: |
Thanks @ericfennis, I confirmed that fixes my issue with the component type. |
I've been using lucide-svelte with Svelte 5 for some time now. Should I switch to this new package? How are they different? |
For more info see #2727
This PR creates a new package:
@lucide/svelte
.