Icon
195 vector icons from the Lucide set, drawn with Lynx's <svg> element. It draws your own SVG too, such as a sign-in provider's mark.
Installation
Usage
Register the icons your app draws, then draw them by name:
Register the icons you draw
Each icon is an export of its own, named for the icon with Icon on the end: heart is heartIcon, and chevron-right is chevronRightIcon.
provideIcons() registers the ones you pass, and only those go into your app's scripts. A set that every icon came with, whatever an app drew, took about 34 kB of the main-thread script. And Lynx keeps a script's whole bytecode in memory.
- Register an icon wherever you draw it by name. That's
nameon an icon, andiconon an Empty State. It's alsoiconon the items of a Tab Bar, a Dock, a Menu, a Toolbar or a Navigation Bar. - A name bound from data, as in
[name]="item.icon", needs each icon the data can hold. - The components' own icons need nothing. A calendar's chevrons, a search field's magnifier or a copy button's check are registered by the component that draws them.
- Give it in the app's config for the whole app, or in a component's
providersfor that component and everything it shows. EachprovideIcons()adds to the icons registered above it, so a feature can register its own icons where it draws them. - An icon nobody registered throws an error that names its export, such as
No icon named "chevron-right" is registered. Register it with provideIcons({ chevronRightIcon }), rather than drawing an empty box. - The keys don't matter: each icon carries its own name, so
provideIcons({ heartIcon })registersheart.
To draw any icon by a name you can't list, such as names from a server, register the whole set with provideAllIcons(). It brings every icon back into your app's scripts.
Specs render components without the app's config, so they need the icons registered too. Export the same provideIcons() from the file your test target names as providersFile in angular.json, and ng test gives it to every spec, render() and TestBed alike:
From a copy that had every icon
Icon copies before provideIcons() came with every icon, so an app drew any of them without registering it. The dolan update that brings the new copy registers the icons your app names for you:
- It looks for icon names in your
.tsand.htmlfiles, outside the components' own folders: innameandiconattributes (name="check"), and in[name]and[icon]bindings ([name]="done() ? 'check' : 'x'"). - A binding that reads data counts every icon name in your source. With
[icon]="item.icon", oron() ? 'check' : item.icon, the names are in your data ({ icon: 'home' }), so every quoted string that's an icon's name counts. A string that only happens to be one, such as'x'for an axis, registers an icon you don't draw, which costs a few hundred bytes. - It adds
provideIcons()with them to theprovidersof yourApplicationConfig, inapp.config.ts, and says which it registered. Without anApplicationConfig, it prints the call to add. - It does this once. An app that calls
provideIcons()orprovideAllIcons()outside its specs is left alone. - A name built at runtime can't be found, such as
'arrow-' + side. Drawing it throws the error above, naming the icon to register. ICONSis gone.updatelists your files that read it. For an icon's markup, useiconSvg(chevronRightIcon).
Colors
Without color, an icon draws in your theme's foreground, like the text next to it. Pass color a theme token or a literal color:
- Theme tokens are looked up in TypeScript. Lynx's
<svg>element can't read CSS, soicon-theme.ts, copied next to the icon, keeps the theme's colors. If you change a color indefault.cssordark.css, pass the new value toprovideIconTheme()too (see below). Text color classes such astext-primaryhave no effect on an icon. - Some containers color the icons inside them. A destructive nav drawer item draws its icons in
--destructive. The icon's owncolorstill wins.
Dark mode
Icons follow the app's appearance: light colors in light mode, dark colors in dark mode, as the theme does. There's nothing to set up.
To change the colors, or where the scheme comes from, use provideIconTheme():
lightanddarktake token values to override, if you changed your theme's colors.colorSchemeis'system'by default: the appearance the app is drawn in,LynxTheme.appearance.'light'or'dark'keeps to one table, and a function such as() => (settings.dark() ? 'dark' : 'light')follows a theme class of your own.
The same setting colors Spinner, Pagination's arrows and a loading Button's spinner, and picks Glass's light or dark material. Charts have their own, provideChartTheme().
Your own SVG
For a mark the set doesn't have, such as a sign-in provider's, pass its markup to svg instead of name:
currentColortakes the icon's color, as the set's icons do:color, a button's label color, or the theme's foreground. A one-color mark written incurrentColorfollows your theme, and dark mode as set above.- Colors written out stay, so a multi-color mark, such as Google's, keeps them.
xmlnsis optional. The icon adds it to the root<svg>: without it, the web preview draws nothing.- Draw lines with
<path>. The<svg>element has the same limits here: no<line>on iOS and Android, and no CSS. - Components that show an icon take one too:
[svg]in place oficon, drawn in their own row, at their size and in their color for their state. That's the items of a Tab Bar, a Dock, a Menu and a Toolbar, and an Empty State. Pass it to them rather than putting a<ui-icon>beside them. - Give an icon
nameorsvg, not both. With neither or both, it throws an error.
The example at the top of this page draws Google's and GitHub's marks, and Button's example puts them in sign-in buttons.
Sizes
The sizes are 16, 20, 24 and 32 pixels square. Without a size, an icon is 24px, or the size its container gives it: an icon in a Button or a Button Group fits the button's size.
Type-safe names
IconName is the union of every icon name in the set, registered or not. It's a type, so it adds nothing to your app's scripts.
For an icon's markup, as a string to pass to svg or an <svg> element's content, iconSvg(checkIcon) puts the icon's body in its root <svg>.
Spacing
class takes Tailwind classes for the icon, such as class="mr-2".
Available icons
Each is the export of its name in camel case with Icon on the end: alert-triangle is alertTriangleIcon, and undo-2 is undo2Icon.
Common: check, x, plus, minus, chevron-down, chevron-up, chevron-left, chevron-right, arrow-left, arrow-right, search, menu, info, alert-triangle, loader, circle, ellipsis, eye, eye-off, settings, trash, heart, star, bell
Navigation and arrows: arrow-up, arrow-down, arrow-up-right, arrow-up-left, arrow-down-right, arrow-down-left, chevrons-up, chevrons-down, chevrons-left, chevrons-right, move, maximize, minimize, external-link, refresh-cw, rotate-cw, undo-2, redo-2
Actions and editing: edit, pencil, copy, clipboard, save, download, upload, share-2, sliders-horizontal, zoom-in, zoom-out, scissors, trash-2, pin, link, filter
Media: play, pause, square, circle-stop, skip-forward, skip-back, rewind, fast-forward, volume-2, volume-x, mic, mic-off, camera, video, music, headphones
Communication: mail, message-circle, message-square, send, phone, phone-call, at-sign, inbox, megaphone, rss, reply, globe
Files and folders: file, file-text, file-plus, folder, folder-open, book, book-open, archive, paperclip, newspaper, database, hard-drive
Status: check-circle, x-circle, alert-circle, plus-circle, minus-circle, shield, shield-check, lock, lock-open, key, ban, help-circle
People: user, users, user-circle, user-plus, user-check, user-x, thumbs-up, thumbs-down, smile, frown, hand, handshake
Commerce: shopping-cart, shopping-bag, credit-card, dollar-sign, tag, tags, gift, package, truck, wallet, receipt, store
Weather and nature: sun, moon, cloud, cloud-rain, cloud-snow, wind, droplet, zap, snowflake, flame, sunrise, sparkles
Places and devices: home, calendar, clock, map-pin, map, compass, wifi, bluetooth, battery, smartphone, monitor, laptop, server, cpu, keyboard, power
Layout and text: layout-grid, layout-dashboard, table, columns-3, rows-3, list, list-checks, list-ordered, bold, quote, align-left, align-center, align-right, type
Charts: chart-bar, chart-line, chart-pie, chart-column, activity, trending-up, trending-down, target
Objects: award, trophy, crown, rocket, lightbulb, coffee, terminal, code, command, git-branch, bug
API
UiIcon
No outputs.
Functions
Related
<svg>: the element that draws the icons- Empty State: shows an icon above a message
- Theming: the colors to match
- Dark mode: switching the theme with the phone
