tailwindlabs / heroicons

A set of free MIT-licensed high-quality SVG icons for UI development.
https://heroicons.com
MIT License
21.33k stars 1.28k forks source link

Svelte Components #245

Closed mattjennings closed 3 years ago

mattjennings commented 3 years ago

Adds Svelte components, which can be built with npm run build-svelte.

They are exported as .svelte components rather than compiled .js files. This is the recommended way to provide svelte components in a library, and are found via the svelte entry field in package.json.

If there's a strong argument for compiling them as .js files, I did do this initially using svelte's compiler API but I could not get them to work in SSR environments. I am sure there's a solution to this, but at that point I felt .svelte components may be best anyway.

mattjennings commented 3 years ago

These are published under heroicons-svelte.

Note: if you want to use this with SvelteKit, make sure you install it as a regular dependency and not a devDependency.

Usage

import { HomeIcon } from 'heroicons-svelte/solid'
import { HomeIcon } from 'heroicons-svelte/outline'

// alternatively
import HomeIcon from 'heroicons-svelte/solid/HomeIcon.svelte'
import HomeIcon from 'heroicons-svelte/outline/HomeIcon.svelte'
joshua1 commented 3 years ago

@adamwathan and @sschoger , can this be merged in for svelte users please. This will help with working with tailwindUI examples written for Vue, when creating svelte components

mattjennings commented 3 years ago

I've been looking at adding typescript types so that the components use SVG attributes as their props. However, Svelte doesn't ship types for HTML elements, instead they're in their svelte2tsx package (which powers their language server). So in order to use those we'd have to add that as a dependency to @heroicons/svelte.

If we're OK with doing that for the sake of types, I can push my changes to this PR. I have these changes published in @mattjennings/heroicons-svelte@0.0.6 in the meantime.

Clee681 commented 3 years ago

Wow, thanks for doing this @mattjennings!!

ojczeo commented 3 years ago

If anybody needs it to install now: add to package.json:

"dependencies":
...
    "@heroicons/svelte": "git+https://github.com/mattjennings/heroicons.git#@mattjennings/heroicons-svelte",
...

and run:

npm install  @heroicons/svelte`
maraisr commented 3 years ago

How are we going with this one?

adamwathan commented 3 years ago

Maintaining additional wrapper libraries isn't a priority right now I'm afraid, better for someone who wants this to exist to publish and maintain it themselves 👍🏻

Thanks either way I do appreciate the contribution ❤️ we just don't have the resources to take on additional OSS maintenance.

mattjennings commented 3 years ago

No worries, I understand the decision completely.

I've published this under heroicons-svelte now and will keep it maintained as best I can.