@astryxdesign/core 0.2.0-canary.2e89616 → 0.2.0-canary.37626ca

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.
@@ -16,6 +16,16 @@ import type { DefinedTheme } from '../theme/defineTheme';
16
16
  * visual representation. Themes provide the actual icon components.
17
17
  */
18
18
  export type IconName = 'close' | 'chevronDown' | 'chevronLeft' | 'chevronRight' | 'check' | 'success' | 'error' | 'warning' | 'info' | 'calendar' | 'clock' | 'externalLink' | 'menu' | 'moreHorizontal' | 'search' | 'arrowUp' | 'arrowDown' | 'arrowsUpDown' | 'funnel' | 'eyeSlash' | 'viewColumns' | 'copy' | 'checkDouble' | 'wrench' | 'stop' | 'microphone';
19
+ /**
20
+ * A semantic icon name — either one of the built-in {@link IconName}s or an
21
+ * arbitrary string key contributed by a library/app.
22
+ *
23
+ * The `(string & {})` intersection keeps the built-in names available for
24
+ * autocomplete while still allowing any string, so downstream libraries can
25
+ * register and resolve their own keys (e.g. `'richtext:bold'`) without having
26
+ * to widen the core `IconName` union.
27
+ */
28
+ export type ExtendedIconName = IconName | (string & {});
19
29
  /**
20
30
  * Icon registry mapping semantic names to React nodes.
21
31
  */
@@ -34,8 +44,17 @@ export type IconRegistrySource = DefinedTheme | string | null | undefined;
34
44
  * import { brandIcons } from './brand-icons';
35
45
  * registerIcons(brandIcons);
36
46
  * ```
47
+ *
48
+ * Libraries may also register their own extension keys (any string), so a
49
+ * theme can override them the same way it overrides built-in icons:
50
+ * @example
51
+ * ```
52
+ * // In a library that ships its own icons:
53
+ * registerIcons({ 'richtext:bold': <MyBoldIcon /> });
54
+ * // resolve with getIcon('richtext:bold')
55
+ * ```
37
56
  */
38
- export declare function registerIcons(icons: Partial<IconRegistry>): void;
57
+ export declare function registerIcons(icons: Partial<Record<ExtendedIconName, ReactNode>>): void;
39
58
  /**
40
59
  * Get a snapshot of the full icon registry, with registered icons overriding
41
60
  * built-in defaults.
@@ -50,8 +69,29 @@ export declare function getIconRegistry(source?: IconRegistrySource): Readonly<I
50
69
  *
51
70
  * Works in both server and client environments.
52
71
  * Falls back to built-in default icons when no override is registered.
72
+ *
73
+ * Accepts extension keys (any string) in addition to the built-in
74
+ * {@link IconName}s — useful for library-contributed icons. For a
75
+ * caller-supplied fallback when a key isn't registered, use
76
+ * {@link getExtendedIcon}.
77
+ */
78
+ export declare function getIcon(name: ExtendedIconName, source?: IconRegistrySource): ReactNode;
79
+ /**
80
+ * Resolve an extension icon by an arbitrary string key, falling back to a
81
+ * caller-supplied default when nothing is registered.
82
+ *
83
+ * This is the seam libraries use to make their own icons themeable: ship the
84
+ * inline SVG as `fallback`, resolve through this function, and a theme can
85
+ * override the key via {@link registerIcons} without the library having to
86
+ * widen the core {@link IconName} union.
87
+ *
88
+ * @example
89
+ * ```
90
+ * // Library default, overridable by a theme registering 'richtext:bold':
91
+ * getExtendedIcon('richtext:bold', <BoldGlyph />)
92
+ * ```
53
93
  */
54
- export declare function getIcon(name: IconName, source?: IconRegistrySource): ReactNode;
94
+ export declare function getExtendedIcon(name: ExtendedIconName, fallback?: ReactNode, source?: IconRegistrySource): ReactNode;
55
95
  /**
56
96
  * Reset the global registry. For testing only.
57
97
  * @internal
@@ -1 +1 @@
1
- {"version":3,"file":"globalIconRegistry.d.ts","sourceRoot":"","sources":["../../src/Icon/globalIconRegistry.tsx"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAErC,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,sBAAsB,CAAC;AAQvD;;;;;GAKG;AAEH,MAAM,MAAM,QAAQ,GAChB,OAAO,GACP,aAAa,GACb,aAAa,GACb,cAAc,GACd,OAAO,GACP,SAAS,GACT,OAAO,GACP,SAAS,GACT,MAAM,GACN,UAAU,GACV,OAAO,GACP,cAAc,GACd,MAAM,GACN,gBAAgB,GAChB,QAAQ,GACR,SAAS,GACT,WAAW,GACX,cAAc,GACd,QAAQ,GACR,UAAU,GACV,aAAa,GACb,MAAM,GACN,aAAa,GACb,QAAQ,GACR,MAAM,GACN,YAAY,CAAC;AAEjB;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AAEvD,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AAsB1E;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI,CAOhE;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,MAAM,CAAC,EAAE,kBAAkB,GAC1B,QAAQ,CAAC,YAAY,CAAC,CAexB;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CACrB,IAAI,EAAE,QAAQ,EACd,MAAM,CAAC,EAAE,kBAAkB,GAC1B,SAAS,CAGX;AAED;;;GAGG;AACH,wBAAgB,UAAU,IAAI,IAAI,CAEjC"}
1
+ {"version":3,"file":"globalIconRegistry.d.ts","sourceRoot":"","sources":["../../src/Icon/globalIconRegistry.tsx"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAErC,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,sBAAsB,CAAC;AAQvD;;;;;GAKG;AAEH,MAAM,MAAM,QAAQ,GAChB,OAAO,GACP,aAAa,GACb,aAAa,GACb,cAAc,GACd,OAAO,GACP,SAAS,GACT,OAAO,GACP,SAAS,GACT,MAAM,GACN,UAAU,GACV,OAAO,GACP,cAAc,GACd,MAAM,GACN,gBAAgB,GAChB,QAAQ,GACR,SAAS,GACT,WAAW,GACX,cAAc,GACd,QAAQ,GACR,UAAU,GACV,aAAa,GACb,MAAM,GACN,aAAa,GACb,QAAQ,GACR,MAAM,GACN,YAAY,CAAC;AAEjB;;;;;;;;GAQG;AACH,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAExD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AAEvD,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AAsB1E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,gBAAgB,EAAE,SAAS,CAAC,CAAC,GAClD,IAAI,CAON;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,MAAM,CAAC,EAAE,kBAAkB,GAC1B,QAAQ,CAAC,YAAY,CAAC,CAkBxB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,OAAO,CACrB,IAAI,EAAE,gBAAgB,EACtB,MAAM,CAAC,EAAE,kBAAkB,GAC1B,SAAS,CAOX;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,gBAAgB,EACtB,QAAQ,CAAC,EAAE,SAAS,EACpB,MAAM,CAAC,EAAE,kBAAkB,GAC1B,SAAS,CAQX;AAED;;;GAGG;AACH,wBAAgB,UAAU,IAAI,IAAI,CAEjC"}
@@ -26,6 +26,16 @@ import { warnOnce } from "../utils/devWarning.js";
26
26
  */
27
27
  // SYNC: packages/cli/assets/docs/icons.doc.mjs — update USAGE_HINTS when adding names
28
28
 
29
+ /**
30
+ * A semantic icon name — either one of the built-in {@link IconName}s or an
31
+ * arbitrary string key contributed by a library/app.
32
+ *
33
+ * The `(string & {})` intersection keeps the built-in names available for
34
+ * autocomplete while still allowing any string, so downstream libraries can
35
+ * register and resolve their own keys (e.g. `'richtext:bold'`) without having
36
+ * to widen the core `IconName` union.
37
+ */
38
+
29
39
  /**
30
40
  * Icon registry mapping semantic names to React nodes.
31
41
  */
@@ -58,6 +68,15 @@ function getThemeIconOverrides(source) {
58
68
  * import { brandIcons } from './brand-icons';
59
69
  * registerIcons(brandIcons);
60
70
  * ```
71
+ *
72
+ * Libraries may also register their own extension keys (any string), so a
73
+ * theme can override them the same way it overrides built-in icons:
74
+ * @example
75
+ * ```
76
+ * // In a library that ships its own icons:
77
+ * registerIcons({ 'richtext:bold': <MyBoldIcon /> });
78
+ * // resolve with getIcon('richtext:bold')
79
+ * ```
61
80
  */
62
81
  export function registerIcons(icons) {
63
82
  warnOnce('icon-registry:global-register-icons', 'Icon', '`registerIcons()` applies icon overrides globally. Prefer `defineTheme({ icons })` for theme-scoped icon overrides.');
@@ -79,7 +98,11 @@ export function getIconRegistry(source) {
79
98
  const registry = {
80
99
  ...defaultIcons
81
100
  };
82
- for (const name of Object.keys(globalRegistry)) {
101
+
102
+ // Only surface built-in IconName keys here — extension keys registered by
103
+ // libraries are resolved via getIcon/getExtendedIcon and intentionally kept
104
+ // out of the typed IconRegistry snapshot.
105
+ for (const name of Object.keys(defaultIcons)) {
83
106
  registry[name] = globalRegistry[name] ?? defaultIcons[name];
84
107
  }
85
108
  const themeIcons = getThemeIconOverrides(source);
@@ -96,12 +119,37 @@ export function getIconRegistry(source) {
96
119
  *
97
120
  * Works in both server and client environments.
98
121
  * Falls back to built-in default icons when no override is registered.
122
+ *
123
+ * Accepts extension keys (any string) in addition to the built-in
124
+ * {@link IconName}s — useful for library-contributed icons. For a
125
+ * caller-supplied fallback when a key isn't registered, use
126
+ * {@link getExtendedIcon}.
99
127
  */
100
128
  export function getIcon(name, source) {
101
129
  const themeIcons = getThemeIconOverrides(source);
102
130
  return themeIcons?.[name] ?? globalRegistry[name] ?? defaultIcons[name];
103
131
  }
104
132
 
133
+ /**
134
+ * Resolve an extension icon by an arbitrary string key, falling back to a
135
+ * caller-supplied default when nothing is registered.
136
+ *
137
+ * This is the seam libraries use to make their own icons themeable: ship the
138
+ * inline SVG as `fallback`, resolve through this function, and a theme can
139
+ * override the key via {@link registerIcons} without the library having to
140
+ * widen the core {@link IconName} union.
141
+ *
142
+ * @example
143
+ * ```
144
+ * // Library default, overridable by a theme registering 'richtext:bold':
145
+ * getExtendedIcon('richtext:bold', <BoldGlyph />)
146
+ * ```
147
+ */
148
+ export function getExtendedIcon(name, fallback, source) {
149
+ const themeIcons = getThemeIconOverrides(source);
150
+ return themeIcons?.[name] ?? globalRegistry[name] ?? defaultIcons[name] ?? fallback;
151
+ }
152
+
105
153
  /**
106
154
  * Reset the global registry. For testing only.
107
155
  * @internal
@@ -9,6 +9,6 @@
9
9
  export { Icon, renderIconSlot } from './Icon';
10
10
  export { useIcon } from './useIcon';
11
11
  export type { IconProps, IconColor, IconSize, IconType } from './Icon';
12
- export { registerIcons, getIconRegistry, getIcon, resetIcons, } from './globalIconRegistry';
13
- export type { IconName, IconRegistry, IconRegistrySource, } from './globalIconRegistry';
12
+ export { registerIcons, getIconRegistry, getIcon, getExtendedIcon, resetIcons, } from './globalIconRegistry';
13
+ export type { IconName, ExtendedIconName, IconRegistry, IconRegistrySource, } from './globalIconRegistry';
14
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Icon/index.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AAEH,OAAO,EAAC,IAAI,EAAE,cAAc,EAAC,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,YAAY,EAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAC,MAAM,QAAQ,CAAC;AAGrE,OAAO,EACL,aAAa,EACb,eAAe,EACf,OAAO,EACP,UAAU,GACX,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,QAAQ,EACR,YAAY,EACZ,kBAAkB,GACnB,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Icon/index.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AAEH,OAAO,EAAC,IAAI,EAAE,cAAc,EAAC,MAAM,QAAQ,CAAC;AAC5C,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,YAAY,EAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAC,MAAM,QAAQ,CAAC;AAGrE,OAAO,EACL,aAAa,EACb,eAAe,EACf,OAAO,EACP,eAAe,EACf,UAAU,GACX,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,QAAQ,EACR,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,GACnB,MAAM,sBAAsB,CAAC"}
@@ -13,4 +13,4 @@
13
13
  export { Icon, renderIconSlot } from "./Icon.js";
14
14
  export { useIcon } from "./useIcon.js";
15
15
  // Global registry (RSC-compatible, no 'use client')
16
- export { registerIcons, getIconRegistry, getIcon, resetIcons } from "./globalIconRegistry.js";
16
+ export { registerIcons, getIconRegistry, getIcon, getExtendedIcon, resetIcons } from "./globalIconRegistry.js";