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

Using Lucide Lab custom icons doesn't work as documented for vanilla JS #2300

Open
6 of 30 tasks
jamiemlaw opened this issue Jul 8, 2024 · 0 comments
Open
6 of 30 tasks
Labels
🐛 bug Something isn't working

Comments

@jamiemlaw
Copy link
Contributor

jamiemlaw commented Jul 8, 2024

Package

  • lucide
  • lucide-angular
  • lucide-flutter
  • lucide-preact
  • lucide-react
  • lucide-react-native
  • lucide-solid
  • lucide-svelte
  • lucide-vue
  • lucide-vue-next
  • Figma plugin
  • source/main
  • other/not relevant

Version

0.402.0

Can you reproduce this in the latest version?

  • Yes
  • No

Browser

  • Chrome/Chromium
  • Firefox
  • Safari
  • Edge
  • iOS Safari
  • Opera
  • Other/not relevant

Operating system

  • Windows
  • Linux
  • macOS
  • ChromeOS
  • iOS
  • Android
  • Other/not relevant

Description

The documentation says that the way to use Lucide Lab custom icons in vanilla JS is with the following code:

<i data-lucide="burger"></i>
import { createIcons } from 'lucide';
import { burger } from '@lucide/lab';

createIcons({
  icons: {
    burger,
  },
});

When I do that, I see the following error in the console:

<i data-lucide="burger"></i> icon name was not found in the provided icons object.

I have got it to work, but by using the following code to wrap the iconNode data, so that it matches the format that you'd get when importing an icon from the main Lucide package:

function icon(iconNode) {
  return [
    "svg",
    {
      "xmlns": "http://www.w3.org/2000/svg",
      "width": 24,
      "height": 24,
      "viewBox": "0 0 24 24",
      "fill": "none",
      "stroke": "currentColor",
      "stroke-width": 2,
      "stroke-linecap": "round",
      "stroke-linejoin": "round"
    },
    iconNode,
  ];
}

createIcons({
  icons: {
    Burger: icon(burger)
  }
});

Assuming that I'm not doing something wrong, and that this is how to get Lucide Lab icons working in vanilla JS, I don't know if it's worth updating the documentation to include this?

Or, alternatively, may I suggest a feature to update createIcons to perform the transforms automatically if it detects bare iconNode data with no SVG wrapper.

Steps to reproduce

See the following CodePen: https://codepen.io/jamiemlaw/pen/poXoWjd/3b4db0e038ed7e644a2e58fca8c55906

Checklist

  • I have searched if someone has submitted a similar issue before and there weren't any. (Please make sure to also search closed issues, as this issue might already have been resolved.)
@jamiemlaw jamiemlaw added the 🐛 bug Something isn't working label Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant