@dogsbay/ui 0.2.0-beta.10 → 0.2.0-beta.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dogsbay/ui",
3
- "version": "0.2.0-beta.10",
3
+ "version": "0.2.0-beta.12",
4
4
  "description": "Accessible UI components for Astro, inspired by Base UI and shadcn",
5
5
  "type": "module",
6
6
  "exports": {
@@ -11,9 +11,9 @@
11
11
  },
12
12
  "peerDependencies": {
13
13
  "astro": "^5.0.0 || ^6.0.0",
14
- "@dogsbay/primitives": "0.2.0-beta.10",
15
- "@dogsbay/icons": "0.2.0-beta.10",
16
- "@dogsbay/elements": "0.2.0-beta.10"
14
+ "@dogsbay/primitives": "0.2.0-beta.12",
15
+ "@dogsbay/elements": "0.2.0-beta.12",
16
+ "@dogsbay/icons": "0.2.0-beta.12"
17
17
  },
18
18
  "optionalDependencies": {
19
19
  "shiki": "^4.0.0",
@@ -0,0 +1,84 @@
1
+ ---
2
+ /**
3
+ * Icon — render an icon by name from any Iconify pack (defaults
4
+ * to Lucide).
5
+ *
6
+ * Resolves at BUILD time via `@dogsbay/icons`'s registry — the
7
+ * SVG is inlined into the static HTML, so there's no client-side
8
+ * fetch and no FOUC. Tree-shakeable: only icons actually used in
9
+ * pages get inlined, since Astro statically evaluates the
10
+ * resolution per template instance.
11
+ *
12
+ * Usage:
13
+ *
14
+ * <Icon name="rocket" /> // bare → Lucide rocket
15
+ * <Icon name="lucide:book-open" /> // explicit pack
16
+ * <Icon name="mdi:home" /> // Material Design Icons
17
+ * <Icon name="simple-icons:github" /> // brand icons
18
+ * <Icon name="rocket" class="size-5 text-primary" />
19
+ *
20
+ * Bare names check the emoji map first (so `rocket` → 🚀
21
+ * matches existing inline-icon behaviour), then fall through to
22
+ * Lucide. When the icon doesn't exist anywhere, the component
23
+ * renders nothing — silent fallback rather than a broken-image
24
+ * box, since icons are decorative and consistent typography is
25
+ * preferable to a placeholder.
26
+ *
27
+ * Accessibility: when `alt` is supplied, the icon is announced
28
+ * to screen readers as a labelled image. Without `alt` (the
29
+ * default), the SVG is `aria-hidden` because most icons in this
30
+ * codebase are paired with adjacent text that already conveys
31
+ * the meaning. Pass `alt=""` explicitly to force the
32
+ * decorative-only state when needed by external tooling.
33
+ */
34
+ import { resolveIcon } from "@dogsbay/icons";
35
+
36
+ interface Props {
37
+ /**
38
+ * Icon shorthand. Either bare (`rocket`, `book-open`) or
39
+ * namespaced (`pack:name`). See file header for examples.
40
+ */
41
+ name: string;
42
+ /** Tailwind class string. Defaults to `size-4` for inline-text sizing. */
43
+ class?: string;
44
+ /**
45
+ * Accessible label. Set to a non-empty string for icons that
46
+ * convey information without surrounding text. Leave undefined
47
+ * (or pass empty string) for decorative icons paired with a
48
+ * text label.
49
+ */
50
+ alt?: string;
51
+ }
52
+
53
+ const { name, class: className = "size-4", alt } = Astro.props;
54
+ const svg = resolveIcon(name);
55
+ const labelled = typeof alt === "string" && alt.length > 0;
56
+ ---
57
+
58
+ {
59
+ svg ? (
60
+ svg.startsWith("<") ? (
61
+ <span
62
+ class:list={["inline-flex shrink-0", className]}
63
+ role={labelled ? "img" : undefined}
64
+ aria-label={labelled ? alt : undefined}
65
+ aria-hidden={labelled ? undefined : "true"}
66
+ set:html={svg}
67
+ data-icon={name}
68
+ />
69
+ ) : (
70
+ // Emoji fallback — `svg` is actually a Unicode character
71
+ // when the name resolved against the emoji map (e.g.
72
+ // `rocket` → 🚀). Render it as text so font emoji shows.
73
+ <span
74
+ class:list={["inline-flex shrink-0", className]}
75
+ role={labelled ? "img" : undefined}
76
+ aria-label={labelled ? alt : undefined}
77
+ aria-hidden={labelled ? undefined : "true"}
78
+ data-icon={name}
79
+ >
80
+ {svg}
81
+ </span>
82
+ )
83
+ ) : null
84
+ }
@@ -0,0 +1 @@
1
+ export { default as Icon } from "./Icon.astro";