brainstorming about ux_icons for javascript #2281
Replies: 2 comments 2 replies
-
That's an interesting idea! If you use a bundler system like Webpack Encore or Vite, you can directly import the icon by using If you use a the AssetMapper, I'm not super fan about dumping icons into a file since... they are already files and I believe they can be accessed through Let's wait for other suggestions :) |
Beta Was this translation helpful? Give feedback.
-
For javascript i think the Iconify packages would be more suited no ? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
There are a few libraries that make tools normally available in twig also available in javascript. Some that come to mind:
I'd like to be able to call ux_icon in javascript to render the svg. Like the two examples above, this would require dumping a map (in json or js) that is loaded (possibly via 'import') and then a call to the function would return the svg (without the fancy automatic lookup).
Use case: a stimulus controller that needs to update a status based on a json response.
Currently I create a lookup table in twig, then pass it to the stimulus controller:
Since in this particular case, the rendering happens in javacript, not twig, I can render the icon based on the map, but it requires passing this array in as a big object.
I'm envisioning something like
bin/console ux:icons:dump --format=js --target=public/js/icons.js --callback="export default"
and then icons.js would contain the map
Perhaps there's a better way? My skills with creating javascript libraries are limited, I mostly use stimulus when I need something like this.
Beta Was this translation helpful? Give feedback.
All reactions