Skip to content
ui8kit

primitive / primitives

Lucide Icon

Lucide Icon primitive

Install

npx ui8kit add lucide-icon

Pulls in: compose, kit-icon, recipes, utils

Preview

No static preview for this item: it needs content or a parent that this page cannot supply. The code is below.

Code

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework svelte --dir src --registry-url https://registry.buildy.tw/svelte --strict-cdn
npx ui8kit add lucide-icon
compose/LucideIcon.svelte
<!-- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. -->
<!-- LucideIcon: Icon + recipe lucide-icon. -->
<script lang="ts">
  import type { ComponentProps, Snippet } from "svelte";
  import Prim from "../kit/ui/icon/Icon.svelte";
  import { cn } from "../kit/utils";
  import { rc } from "./recipes";

  let { class: className, children, ...rest }: ComponentProps<typeof Prim> & { class?: string; children?: Snippet } = $props();
  const cls = $derived(cn(rc("lucide-icon", {  }), className));
</script>

<Prim class={cls} {...rest}>{@render children?.()}</Prim>
icons/LucideIcon.svelte
<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!--
  LucideIcon: a Lucide glyph (ISC license) by kebab-case name (any glyph of the `lucide` package, through ./lucide-icons), inside the Icon primitive
  (the kit-compose LucideIcon frame: span[data-slot=icon]). Decorative (the frame is aria-hidden) unless a `label` is given.
-->
<script lang="ts" module>
  export type LucideIconProps = { name: string; size?: number; strokeWidth?: number; label?: string; class?: string };
</script>

<script lang="ts">
  import Frame from "../compose/LucideIcon.svelte";
  import { lucideNodes } from "./lucide-icons";

  let { name, size = 16, strokeWidth = 2, label, class: className }: LucideIconProps = $props();
  const nodes = $derived(lucideNodes(name) ?? lucideNodes("circle") ?? []);
</script>

<Frame {label} class={className} data-lucide={name}>
  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width={size} height={size} fill="none" stroke="currentColor"
    stroke-width={strokeWidth} stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
    {#each nodes as [tag, attrs], i (i)}
      <svelte:element this={tag} {...attrs} />
    {/each}
  </svg>
</Frame>
icons/lucide-icons.ts
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
// Lucide icons (ISC license, https://lucide.dev): every glyph of the `lucide` package (1.57.0, a dependency of this package), by kebab-case name.
import { icons } from "lucide";

export type LucideNode = [string, Record<string, string | number>];
const ICONS = icons as unknown as Record<string, LucideNode[] | undefined>;
const pascal = (name: string): string => name.replace(/(^|-)([a-z0-9])/g, (_m: string, _d: string, c: string) => c.toUpperCase());

/** the nodes of a Lucide glyph by kebab-case name (`chef-hat`), undefined for a name Lucide does not have */
export function lucideNodes(name: string): LucideNode[] | undefined {
  return /^[a-z0-9]+(-[a-z0-9]+)*$/.test(name) ? ICONS[pascal(name)] : undefined;
}

Svelte registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework react --dir src --registry-url https://registry.buildy.tw/react --strict-cdn
npx ui8kit add lucide-icon
compose/lucide-icon.tsx
// Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.
import type { ComponentProps } from "react";
import { Icon as Prim } from "../kit/ui/icon/icon";
import { cn } from "../kit/utils";
import { rc } from "./recipes";

export type LucideIconProps = Omit<ComponentProps<typeof Prim>, "tag"> & { className?: string };

/** LucideIcon: Icon + recipe lucide-icon. */
export function LucideIcon({ className, ...rest }: LucideIconProps) {
  return <Prim className={cn(rc("lucide-icon", {  }), className)} {...rest} />;
}
icons/LucideIcon.tsx
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
 * LucideIcon: a Lucide glyph (ISC license) by kebab-case name (any glyph of the `lucide` package, through ./lucide-icons), inside the Icon primitive
 * (the kit-compose LucideIcon frame: span[data-slot=icon]). Decorative (the frame is aria-hidden) unless a `label` is given.
 */
import { createElement } from "react";
import { LucideIcon as Frame } from "../compose";
import { lucideNodes } from "./lucide-icons";

export type LucideIconProps = { name: string; size?: number; strokeWidth?: number; label?: string; className?: string };

export function LucideIcon({ name, size = 16, strokeWidth = 2, label, className }: LucideIconProps) {
  const nodes = lucideNodes(name) ?? lucideNodes("circle") ?? [];
  return (
    <Frame label={label} className={className} data-lucide={name}>
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width={size} height={size} fill="none" stroke="currentColor"
        strokeWidth={strokeWidth} strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
        {nodes.map(([tag, attrs], i) => createElement(tag, { key: i, ...attrs }))}
      </svg>
    </Frame>
  );
}
icons/lucide-icons.ts
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
// Lucide icons (ISC license, https://lucide.dev): every glyph of the `lucide` package (1.57.0, a dependency of this package), by kebab-case name.
import { icons } from "lucide";

export type LucideNode = [string, Record<string, string | number>];
const ICONS = icons as unknown as Record<string, LucideNode[] | undefined>;
const pascal = (name: string): string => name.replace(/(^|-)([a-z0-9])/g, (_m: string, _d: string, c: string) => c.toUpperCase());

/** the nodes of a Lucide glyph by kebab-case name (`chef-hat`), undefined for a name Lucide does not have */
export function lucideNodes(name: string): LucideNode[] | undefined {
  return /^[a-z0-9]+(-[a-z0-9]+)*$/.test(name) ? ICONS[pascal(name)] : undefined;
}

React registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework vue --dir src --registry-url https://registry.buildy.tw/vue --strict-cdn
npx ui8kit add lucide-icon
compose/LucideIcon.vue
<!-- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. -->
<!-- LucideIcon: Icon + recipe lucide-icon. -->
<script setup lang="ts">
import { computed, useAttrs } from "vue";
import Prim from "../kit/ui/icon/Icon.vue";
import { cn } from "../kit/utils";
import { rc } from "./recipes";

defineOptions({ name: "LucideIcon", inheritAttrs: false });
const props = defineProps<{  }>();
const attrs = useAttrs();
const rest = computed(() => {
  const { class: _class, ...r } = attrs;
  return r;
});
const cls = computed(() => cn(rc("lucide-icon", {  }), attrs.class as string | undefined));
const tagValue = computed(() => "");
</script>

<template>
  <Prim :class="cls" v-bind="rest"><slot /></Prim>
</template>
icons/LucideIcon.vue
<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!--
  LucideIcon: a Lucide glyph (ISC license) by kebab-case name (any glyph of the `lucide` package, through ./lucide-icons), inside the Icon primitive
  (the kit-compose LucideIcon frame: span[data-slot=icon]). Decorative (the frame is aria-hidden) unless a `label` is given.
-->
<script lang="ts">
export type LucideIconProps = { name: string; size?: number; strokeWidth?: number; label?: string; class?: string };
</script>

<script setup lang="ts">
import { computed } from "vue";
import Frame from "../compose/LucideIcon.vue";
import { lucideNodes } from "./lucide-icons";

defineOptions({ inheritAttrs: false });
const { name, size = 16, strokeWidth = 2, label, class: className } = defineProps<LucideIconProps>();
const nodes = computed(() => lucideNodes(name) ?? lucideNodes("circle") ?? []);
</script>

<template>
  <Frame :label="label" :class="className" :data-lucide="name">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" :width="size" :height="size" fill="none" stroke="currentColor"
      :stroke-width="strokeWidth" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
      <component :is="tag" v-for="([tag, attrs], i) in nodes" :key="i" v-bind="attrs" />
    </svg>
  </Frame>
</template>
icons/lucide-icons.ts
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
// Lucide icons (ISC license, https://lucide.dev): every glyph of the `lucide` package (1.57.0, a dependency of this package), by kebab-case name.
import { icons } from "lucide";

export type LucideNode = [string, Record<string, string | number>];
const ICONS = icons as unknown as Record<string, LucideNode[] | undefined>;
const pascal = (name: string): string => name.replace(/(^|-)([a-z0-9])/g, (_m: string, _d: string, c: string) => c.toUpperCase());

/** the nodes of a Lucide glyph by kebab-case name (`chef-hat`), undefined for a name Lucide does not have */
export function lucideNodes(name: string): LucideNode[] | undefined {
  return /^[a-z0-9]+(-[a-z0-9]+)*$/.test(name) ? ICONS[pascal(name)] : undefined;
}

Vue registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework solid --dir src --registry-url https://registry.buildy.tw/solid --strict-cdn
npx ui8kit add lucide-icon
compose/lucide-icon.solid.tsx
// Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.
import { splitProps, type ComponentProps } from "solid-js";
import { Icon as Prim } from "../kit/ui/icon/icon.solid";
import { cn } from "../kit/utils";
import { rc } from "./recipes";

export type LucideIconProps = Omit<ComponentProps<typeof Prim>, "tag" | "class" | "className"> & { class?: string; className?: string };

/** LucideIcon: Icon + recipe lucide-icon. */
export function LucideIcon(props: LucideIconProps) {
  const [local, rest] = splitProps(props, ["class", "className"]);
  return <Prim class={cn(rc("lucide-icon", {  }), local.class ?? local.className)} {...rest} />;
}
icons/LucideIcon.tsx
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
 * LucideIcon: a Lucide glyph (ISC license) by kebab-case name (any glyph of the `lucide` package, through ./lucide-icons), inside the Icon primitive
 * (the kit-compose LucideIcon frame: span[data-slot=icon]). Decorative (the frame is aria-hidden) unless a `label` is given.
 */
import { For, type JSX } from "solid-js";
import { Dynamic } from "solid-js/web";
import { LucideIcon as Frame } from "../compose";
import { lucideNodes } from "./lucide-icons";

export type LucideIconProps = { name: string; size?: number; strokeWidth?: number; label?: string; class?: string };

export function LucideIcon(props: LucideIconProps): JSX.Element {
  const nodes = () => lucideNodes(props.name) ?? lucideNodes("circle") ?? [];
  return (
    <Frame label={props.label} class={props.class} data-lucide={props.name}>
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width={props.size ?? 16} height={props.size ?? 16} fill="none" stroke="currentColor"
        stroke-width={props.strokeWidth ?? 2} stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
        <For each={nodes()}>{([tag, attrs]) => <Dynamic component={tag} {...attrs} />}</For>
      </svg>
    </Frame>
  );
}
icons/lucide-icons.ts
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
// Lucide icons (ISC license, https://lucide.dev): every glyph of the `lucide` package (1.57.0, a dependency of this package), by kebab-case name.
import { icons } from "lucide";

export type LucideNode = [string, Record<string, string | number>];
const ICONS = icons as unknown as Record<string, LucideNode[] | undefined>;
const pascal = (name: string): string => name.replace(/(^|-)([a-z0-9])/g, (_m: string, _d: string, c: string) => c.toUpperCase());

/** the nodes of a Lucide glyph by kebab-case name (`chef-hat`), undefined for a name Lucide does not have */
export function lucideNodes(name: string): LucideNode[] | undefined {
  return /^[a-z0-9]+(-[a-z0-9]+)*$/.test(name) ? ICONS[pascal(name)] : undefined;
}

Solid registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework templ --dir src --registry-url https://registry.buildy.tw/templ --strict-cdn
npx ui8kit add lucide-icon
compose/lucide-icon.templ
// Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.

package compose

import "github.com/ui8kit/codegen/generated/templ/ui/icon"

// LucideIconProps: LucideIcon: Icon + recipe lucide-icon.
type LucideIconProps struct {
	icon.IconProps
}

func lucideIconInner(p LucideIconProps) icon.IconProps {
	in := p.IconProps
	in.Class = Join(Rc("lucide-icon", map[string]string{}), p.IconProps.Class)
	return in
}

// LucideIcon renders Icon with the composition classes.
templ LucideIcon(p LucideIconProps) {
	@icon.Icon(lucideIconInner(p)) {
		{ children... }
	}
}
icons/lucide-icon.templ
// Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
// LucideIcon: a Lucide glyph (ISC license) by kebab-case name from the registry next to this file (lucide_icons.go), inside
// the Icon primitive (the kit-compose LucideIcon frame: span[data-slot=icon]). Decorative (the frame is aria-hidden) unless a
// Label is given. Size and StrokeWidth default to 16 and 2.

package icons

import (
	"html"
	"sort"
	"strconv"
	"strings"

	"github.com/ui8kit/codegen/generated/templ/compose"
	"github.com/ui8kit/codegen/generated/templ/ui/icon"
)

// LucideIconProps configures LucideIcon.
type LucideIconProps struct {
	Name        string
	Size        int
	StrokeWidth int
	Label       string
	Class       string
	Attrs       templ.Attributes
}

func orInt(v, d int) string {
	if v == 0 {
		return strconv.Itoa(d)
	}
	return strconv.Itoa(v)
}

// glyph is the inner markup of the icon: its nodes with their attributes in name order, escaped.
func glyph(name string) string {
	nodes, ok := lucide[name]
	if !ok {
		nodes = lucide["circle"]
	}
	var b strings.Builder
	for _, n := range nodes {
		keys := make([]string, 0, len(n.Attrs))
		for k := range n.Attrs {
			keys = append(keys, k)
		}
		sort.Strings(keys)
		b.WriteString("<" + n.Tag)
		for _, k := range keys {
			b.WriteString(" " + k + "=\"" + html.EscapeString(n.Attrs[k]) + "\"")
		}
		b.WriteString("></" + n.Tag + ">")
	}
	return b.String()
}

func frameAttrs(a templ.Attributes, name string) templ.Attributes {
	out := templ.Attributes{}
	for k, v := range a {
		out[k] = v
	}
	if name != "" {
		out["data-lucide"] = name
	}
	return out
}

// LucideIcon renders the glyph as an inline svg inside the Icon primitive.
templ LucideIcon(p LucideIconProps) {
	@compose.LucideIcon(compose.LucideIconProps{IconProps: icon.IconProps{Label: p.Label, Class: p.Class, Attrs: frameAttrs(p.Attrs, p.Name)}}) {
		<svg
			xmlns="http://www.w3.org/2000/svg"
			viewBox="0 0 24 24"
			width={ orInt(p.Size, 16) }
			height={ orInt(p.Size, 16) }
			fill="none"
			stroke="currentColor"
			stroke-width={ orInt(p.StrokeWidth, 2) }
			stroke-linecap="round"
			stroke-linejoin="round"
			aria-hidden="true"
		>
			@templ.Raw(glyph(p.Name))
		</svg>
	}
}
icons/lucide_icons.go
Not shown here (603 KB of data): the file is in the registry item (JSON)

templ registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework twig --dir src --registry-url https://registry.buildy.tw/twig --strict-cdn
npx ui8kit add lucide-icon
compose/LucideIcon.html.twig
{# Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. #}
{# LucideIcon: Icon + recipe lucide-icon. Params: class, attrs + the params of Icon. #}
{% include 'ui/icon/Icon.html.twig' with compose_props('LucideIcon', _context) only %}
icons/LucideIcon.html.twig
{#- Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
    LucideIcon: a Lucide glyph (ISC license) by kebab-case name from icons/lucide-icons.json, inside the Icon primitive (the
    kit-compose LucideIcon frame: span[data-slot=icon]). Decorative (the frame is aria-hidden) unless a label is given.
    Params: name, size (16), strokeWidth (2), label, class, attrs. -#}
{%- set name = name ?? '' -%}
{%- set size = (size ?? 0) ?: 16 -%}
{%- set glyph -%}
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="{{ size }}" height="{{ size }}" fill="none" stroke="currentColor" stroke-width="{{ (strokeWidth ?? 0) ?: 2 }}" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">{{ og_lucide(name) }}</svg>
{%- endset -%}
{{ include('compose/LucideIcon.html.twig', {'label': label ?? '', 'class': class ?? '', 'attrs': (attrs ?? {})|merge({'data-lucide': name}), 'children': glyph}, with_context = false) }}
icons/lucide-icons.json
Not shown here (429 KB of data): the file is in the registry item (JSON)

Twig registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework latte --dir src --registry-url https://registry.buildy.tw/latte --strict-cdn
npx ui8kit add lucide-icon
compose/LucideIcon.latte
{* Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. *}
{* LucideIcon: Icon + recipe lucide-icon. *}
{parameters
  string $size = '',
  string $class = '',
  string $label = '',
  array $attrs = [],
  string $children = '',
}
{include '../ui/icon/Icon.latte', ...\CodegenX\Compose\Latte\Compose::props('LucideIcon', ['size' => $size, 'class' => $class, 'label' => $label, 'attrs' => $attrs, 'children' => $children])}
icons/LucideIcon.latte
{* Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
    LucideIcon: a Lucide glyph (ISC license) by kebab-case name from icons/lucide-icons.json, inside the Icon primitive (the
   kit-compose LucideIcon frame: span[data-slot=icon]). Decorative (the frame is aria-hidden) unless a label is given.
   Params: name, size (16), strokeWidth (2), label, class, attrs. *}
{parameters
  $name = '',
  $size = null,
  $strokeWidth = null,
  $label = '',
  $class = '',
  array $attrs = [],
}
{capture $glyph}<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="{$size ?: 16}" height="{$size ?: 16}" fill="none" stroke="currentColor" stroke-width="{$strokeWidth ?: 2}" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">{=og_lucide((string) $name)|noescape}</svg>{/capture}
{=og_include('compose/LucideIcon.latte', ['label' => (string) $label, 'class' => (string) $class, 'attrs' => array_merge($attrs, ['data-lucide' => (string) $name]), 'children' => (string) $glyph])|noescape}
icons/lucide-icons.json
Not shown here (429 KB of data): the file is in the registry item (JSON)

Latte registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework jinja2 --dir src --registry-url https://registry.buildy.tw/jinja2 --strict-cdn
npx ui8kit add lucide-icon
compose/lucide-icon.html.j2
{#- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.
    LucideIcon: Icon + recipe lucide-icon. Props (p): Class, Attrs + the props of Icon. -#}
{%- with p = compose_props('LucideIcon', p) %}{% include 'ui/icon/icon.html.j2' %}{% endwith %}
icons/lucide-icon.html.j2
{#- Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
    LucideIcon: a Lucide glyph (ISC license) by kebab-case name from icons/lucide-icons.json, inside the Icon primitive (the
    kit-compose LucideIcon frame: span[data-slot=icon]). Decorative (the frame is aria-hidden) unless a Label is given.
    Props (p): Name, Size (16), StrokeWidth (2), Label, Class, Attrs. -#}
{%- set name = ui_def(p['Name'], '') -%}
{%- set size = ui_def(p['Size'], 0) or 16 -%}
{%- set glyph -%}
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="{{ size }}" height="{{ size }}" fill="none" stroke="currentColor" stroke-width="{{ ui_def(p['StrokeWidth'], 0) or 2 }}" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">{{ og_lucide(name) }}</svg>
{%- endset -%}
{{ og_include('compose/lucide-icon.html.j2', {'p': {'Label': ui_def(p['Label'], ''), 'Class': ui_def(p['Class'], ''), 'Attrs': og_merge(ui_def(p['Attrs'], {}), {'data-lucide': name})}, 'children': glyph}) }}
icons/lucide-icons.json
Not shown here (429 KB of data): the file is in the registry item (JSON)

Jinja2 registry item (JSON)

Props

Names and types come from the xgen specs of the source. Standard HTML attributes (id, role, tabIndex, aria-*) pass through to the root element; the class prop is className in React.

No props.

Used in