Live examples
The icons below are rendered by renderIcon() from Lucide icons dumped by the bundle. The
documentation build renders each one with ux_icon() too, and fails if the HTML differs: what you see is what Twig
renders. The examples use this configuration:
ux_icons: default_icon_attributes: width: 1.5em height: 1.5em icon_sets: lucide: icon_attributes: class: lucide aliases: delete: 'lucide:trash-2'An icon
Section titled “An icon”The dumped attributes already carry the configuration: the default size, and the class of the icon set.
aria-hidden="true" is added, as the icon has no text alternative.
import { renderIcon } from '@silarhi/ux-icons-js'import { LucideHeartIcon } from '../var/icons/index.js'
element.innerHTML = renderIcon(LucideHeartIcon){{ ux_icon('lucide:heart') }}<svg xmlns="http://www.w3.org/2000/svg" width="1.5em" height="1.5em" viewBox="0 0 24 24" class="lucide" aria-hidden="true"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2 9.5a5.5 5.5 0 0 1 9.591-3.676a.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5"></path></svg>Attributes
Section titled “Attributes”Given attributes override the dumped ones; aria-label makes the icon meaningful, so no aria-hidden.
import { renderIcon } from '@silarhi/ux-icons-js'import { LucideTrash2Icon } from '../var/icons/index.js'
element.innerHTML = renderIcon(LucideTrash2Icon, { class: 'text-danger', 'aria-label': 'Delete' }){{ ux_icon('lucide:trash-2', { class: 'text-danger', 'aria-label': 'Delete' }) }}<svg xmlns="http://www.w3.org/2000/svg" width="1.5em" height="1.5em" viewBox="0 0 24 24" class="text-danger" aria-label="Delete"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 11v6m4-6v6m5-11v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6M3 6h18M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path></svg>import { renderIcon } from '@silarhi/ux-icons-js'import { LucideCheckIcon } from '../var/icons/index.js'
element.innerHTML = renderIcon(LucideCheckIcon, { width: 48, height: 48, class: 'text-success' }){{ ux_icon('lucide:check', { width: 48, height: 48, class: 'text-success' }) }}<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" class="text-success" aria-hidden="true"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 6L9 17l-5-5"></path></svg>Token lists and styles
Section titled “Token lists and styles”Arrays are token lists, null entries dropped; style objects are inline styles, null declarations dropped. See
attributes.
import { renderIcon } from '@silarhi/ux-icons-js'import { LucideStarIcon } from '../var/icons/index.js'
element.innerHTML = renderIcon(LucideStarIcon, { class: ['icon', null, 'active'], style: { color: '#e8a33d', rotate: null } }){{ ux_icon('lucide:star', { class: ['icon', null, 'active'], style: { color: '#e8a33d', rotate: null } }) }}<svg xmlns="http://www.w3.org/2000/svg" width="1.5em" height="1.5em" viewBox="0 0 24 24" class="icon active" style="color: #e8a33d;" aria-hidden="true"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.12 2.12 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.12 2.12 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.12 2.12 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.12 2.12 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.12 2.12 0 0 0 1.597-1.16z"></path></svg>Booleans
Section titled “Booleans”data-* and aria-* booleans become "true" and "false", other false attributes are omitted.
import { renderIcon } from '@silarhi/ux-icons-js'import { LucideBellIcon } from '../var/icons/index.js'
element.innerHTML = renderIcon(LucideBellIcon, { 'data-unread': true, 'aria-hidden': false, focusable: false }){{ ux_icon('lucide:bell', { 'data-unread': true, 'aria-hidden': false, focusable: false }) }}<svg xmlns="http://www.w3.org/2000/svg" width="1.5em" height="1.5em" viewBox="0 0 24 24" class="lucide" data-unread="true" aria-hidden="false"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.268 21a2 2 0 0 0 3.464 0m-10.47-5.674A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326"></path></svg>JSON data attributes
Section titled “JSON data attributes”data-* arrays and objects are JSON encoded like PHP json_encode().
import { renderIcon } from '@silarhi/ux-icons-js'import { LucideSettingsIcon } from '../var/icons/index.js'
element.innerHTML = renderIcon(LucideSettingsIcon, { 'data-config': { panel: 'a/b', label: 'Réglages' } }){{ ux_icon('lucide:settings', { 'data-config': { panel: 'a/b', label: 'Réglages' } }) }}<svg xmlns="http://www.w3.org/2000/svg" width="1.5em" height="1.5em" viewBox="0 0 24 24" class="lucide" data-config="{"panel":"a\/b","label":"R\u00e9glages"}" aria-hidden="true"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M9.671 4.136a2.34 2.34 0 0 1 4.659 0a2.34 2.34 0 0 0 3.319 1.915a2.34 2.34 0 0 1 2.33 4.033a2.34 2.34 0 0 0 0 3.831a2.34 2.34 0 0 1-2.33 4.033a2.34 2.34 0 0 0-3.319 1.915a2.34 2.34 0 0 1-4.659 0a2.34 2.34 0 0 0-3.32-1.915a2.34 2.34 0 0 1-2.33-4.033a2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915"></path><circle cx="12" cy="12" r="3"></circle></g></svg>Aliases
Section titled “Aliases”An alias is dumped too, with the attributes of its target.
import { renderIcon } from '@silarhi/ux-icons-js'import { DeleteIcon } from '../var/icons/index.js'
element.innerHTML = renderIcon(DeleteIcon){{ ux_icon('delete') }}<svg xmlns="http://www.w3.org/2000/svg" width="1.5em" height="1.5em" viewBox="0 0 24 24" class="lucide" aria-hidden="true"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 11v6m4-6v6m5-11v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6M3 6h18M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path></svg>