Fresh tabler icon class
Hello
I want to use the fresh tabler icon lib without using the npm version like this:
Then using it with a tailwind class conditioned by the value of a signal:
I'm encountering an error because the props class is not available with the tabler preact icon, but it is available when the import is done that way:
Can you help me make this work with the npm import? Because it's enough that I have several icons to import that the number of import lines may be too large.
Thanks
2 Replies
Based on the documentation, you can use Tabler icons with Fresh by importing them directly from the Deno.land URL. Here's an example of how you can import and use Tabler icons in your Fresh project:
In your case, you want to use the npm version of the Tabler icons with Preact and apply Tailwind classes conditionally based on the value of a signal. However, you're encountering an error because the
className
prop is not available with the npm import.
The documentation does not provide a direct solution for using the npm version of Tabler icons with Fresh. However, I can offer some general advice that isn't in the documentation:
1. Ensure that the npm package you are using exports the icons as Preact components that accept a className
prop. If the package does not support this, you may not be able to pass class names as you intend.
2. If the npm package does support passing a className
prop, double-check that you are importing the icons correctly. The import statement should match the export format used by the npm package.
3. If the number of import lines is a concern, consider creating a single module that re-exports all the icons you need. This way, you can import multiple icons from a single local file, reducing the number of import lines in your components.
Here's an example of how you might create such a module:
Then, in your component file, you can import the icons fromyour local
icons.ts
file:
Remember, this advice is general and not directly supported by the documentation. If the npm package you're using does not support the className
prop, you might need to stick with the direct imports from Deno.land as shown in the documentation examples. 🦕