@kbach/react 0.6.34 → 0.6.35

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/dist/index.d.ts CHANGED
@@ -29,17 +29,43 @@ interface ColorScale {
29
29
  /** `colors.blue['6/50']` → shade 6 at 50% opacity */
30
30
  readonly [key: string]: string;
31
31
  }
32
- type ColorValueFor<K extends string> = K extends keyof typeof defaultColors ? (typeof defaultColors)[K] extends string ? string : ColorScale : ColorScale | string;
33
32
  /**
34
- * `ColorName` defaults to the built-in theme's color names (`DefaultColorName`,
35
- * derived from `defaultColors` in core/theme.ts), so `useColors()` gets full
36
- * autocomplete and typo-catching out of the box for any project on the default
37
- * theme. A customized `kbach.config.js` isn't visible to TypeScript (it's a
38
- * plain .js file loaded at runtime, not a statically-analyzed module), so a
39
- * project with extra colors needs to widen the type parameter explicitly:
33
+ * Empty on purpose — augment it via declaration merging so `useColors()` (and
34
+ * `useSpacing()`'s equivalent, `KbachCustomSpacing`) know about a project's
35
+ * `kbach.config.js` colors without repeating a type parameter at every call
36
+ * site. `kbach.config.js` is a plain runtime-loaded .js file, so TypeScript
37
+ * can't see into it on its own — this is the same declaration-merging pattern
38
+ * styled-components' `DefaultTheme` and i18next's resource typing use for the
39
+ * identical problem. Put this in any .d.ts your tsconfig includes:
40
+ *
41
+ * ```ts
42
+ * import '@kbach/react'; // or '@kbach/native' — either works, native re-exports react's types
43
+ * declare module '@kbach/react' {
44
+ * interface KbachCustomColors {
45
+ * primary: string; // a flat color, like the built-in `white`/`black`
46
+ * brand: ColorScale; // a 1–12 shade scale, like the built-in `blue`/`red`
47
+ * }
48
+ * }
49
+ * ```
50
+ *
51
+ * A mode-aware `{ light, dark }` config color (see ColorValue) still resolves
52
+ * to a flat `string` at read time — declare those as `string` here too, not
53
+ * as the config shape.
54
+ */
55
+ interface KbachCustomColors {
56
+ }
57
+ type ColorValueFor<K extends string> = K extends keyof typeof defaultColors ? (typeof defaultColors)[K] extends string ? string : ColorScale : K extends keyof KbachCustomColors ? KbachCustomColors[K] : ColorScale | string;
58
+ /** Every color name TypeScript knows about without an explicit type parameter: the built-in theme plus whatever's been added via the KbachCustomColors augmentation above. */
59
+ type KnownColorName = DefaultColorName | Extract<keyof KbachCustomColors, string>;
60
+ /**
61
+ * `ColorName` defaults to `KnownColorName` (the built-in theme's color names
62
+ * plus anything augmented onto `KbachCustomColors` above), so `useColors()`
63
+ * gets full autocomplete and typo-catching out of the box — including custom
64
+ * `kbach.config.js` colors, once augmented once project-wide. Without that
65
+ * augmentation, a project with extra colors can still widen per call instead:
40
66
  * `useColors<DefaultColorName | 'brand'>()`.
41
67
  */
42
- type ColorsAPI<ColorName extends string = DefaultColorName> = {
68
+ type ColorsAPI<ColorName extends string = KnownColorName> = {
43
69
  readonly [K in ColorName]: ColorValueFor<K>;
44
70
  } & {
45
71
  /**
@@ -50,22 +76,40 @@ type ColorsAPI<ColorName extends string = DefaultColorName> = {
50
76
  */
51
77
  readonly alpha: (color: string, opacity?: number) => string;
52
78
  };
53
- declare function wrapColors<ColorName extends string = DefaultColorName>(rawColors: ThemeColors, isDark?: boolean): ColorsAPI<ColorName>;
54
- declare function useColors<ColorName extends string = DefaultColorName>(): ColorsAPI<ColorName>;
79
+ declare function wrapColors<ColorName extends string = KnownColorName>(rawColors: ThemeColors, isDark?: boolean): ColorsAPI<ColorName>;
80
+ declare function useColors<ColorName extends string = KnownColorName>(): ColorsAPI<ColorName>;
55
81
 
56
82
  /**
57
- * `SpacingKey` defaults to the built-in theme's spacing keys (`DefaultSpacingKey`,
58
- * derived from `defaultTheme.spacing` in core/theme.ts), so `useSpacing()` gets
59
- * full autocomplete and typo-catching out of the box for any project on the
60
- * default scale. A customized `kbach.config.js` isn't visible to TypeScript
61
- * (it's a plain .js file loaded at runtime, not a statically-analyzed module),
62
- * so a project with extra spacing keys needs to widen the type parameter
63
- * explicitly: `useSpacing<DefaultSpacingKey | '18'>()`.
83
+ * Empty on purpose — augment it via declaration merging so `useSpacing()`
84
+ * (like `useColors()`'s `KbachCustomColors`) knows about a project's
85
+ * `kbach.config.js` spacing keys without repeating a type parameter at every
86
+ * call site:
87
+ *
88
+ * ```ts
89
+ * import '@kbach/react'; // or '@kbach/native'
90
+ * declare module '@kbach/react' {
91
+ * interface KbachCustomSpacing {
92
+ * 18: true; // value doesn't matter — only the key is read (see SpacingAPI)
93
+ * }
94
+ * }
95
+ * ```
96
+ */
97
+ interface KbachCustomSpacing {
98
+ }
99
+ /** Every spacing key TypeScript knows about without an explicit type parameter. */
100
+ type KnownSpacingKey = DefaultSpacingKey | Extract<keyof KbachCustomSpacing, string>;
101
+ /**
102
+ * `SpacingKey` defaults to `KnownSpacingKey` (the built-in theme's spacing keys
103
+ * plus anything augmented onto `KbachCustomSpacing` above), so `useSpacing()`
104
+ * gets full autocomplete and typo-catching out of the box — including custom
105
+ * `kbach.config.js` keys, once augmented once project-wide. Without that
106
+ * augmentation, a project with extra keys can still widen per call instead:
107
+ * `useSpacing<DefaultSpacingKey | '18'>()`.
64
108
  */
65
- type SpacingAPI<SpacingKey extends string = DefaultSpacingKey> = {
109
+ type SpacingAPI<SpacingKey extends string = KnownSpacingKey> = {
66
110
  readonly [K in SpacingKey]: number | string;
67
111
  };
68
- declare function wrapSpacing<SpacingKey extends string = DefaultSpacingKey>(rawSpacing: ThemeSpacing): SpacingAPI<SpacingKey>;
112
+ declare function wrapSpacing<SpacingKey extends string = KnownSpacingKey>(rawSpacing: ThemeSpacing): SpacingAPI<SpacingKey>;
69
113
  /**
70
114
  * Returns the active theme's spacing scale as a typed, autocomplete-friendly
71
115
  * object — useful anywhere a raw JS number/string is needed instead of a
@@ -80,7 +124,7 @@ declare function wrapSpacing<SpacingKey extends string = DefaultSpacingKey>(rawS
80
124
  * spacing['1/2'] // '50%'
81
125
  * ```
82
126
  */
83
- declare function useSpacing<SpacingKey extends string = DefaultSpacingKey>(): SpacingAPI<SpacingKey>;
127
+ declare function useSpacing<SpacingKey extends string = KnownSpacingKey>(): SpacingAPI<SpacingKey>;
84
128
 
85
129
  interface ThemeProviderProps {
86
130
  children: ReactNode;
@@ -278,4 +322,4 @@ declare function kb(classString: string, isDark?: boolean): StyleValue | string;
278
322
  */
279
323
  declare function cx(...classes: Array<string | false | null | undefined>): string;
280
324
 
281
- export { type ColorScale, type ColorsAPI, type InteractionState, InteractiveWrapper, type InteractiveWrapperProps, KbachReset, type SpacingAPI, type StyledProps, ThemeContext, type ThemeContextValue, ThemeProvider, type ThemeProviderProps, cx, kb, styled, useBreakpoint, useColors, useGlobalDarkMode, useIsDark, useResolvedStyle, useResponsive, useSpacing, useStyles, useTheme, wrapColors, wrapSpacing };
325
+ export { type ColorScale, type ColorsAPI, type InteractionState, InteractiveWrapper, type InteractiveWrapperProps, type KbachCustomColors, type KbachCustomSpacing, KbachReset, type SpacingAPI, type StyledProps, ThemeContext, type ThemeContextValue, ThemeProvider, type ThemeProviderProps, cx, kb, styled, useBreakpoint, useColors, useGlobalDarkMode, useIsDark, useResolvedStyle, useResponsive, useSpacing, useStyles, useTheme, wrapColors, wrapSpacing };
package/kbach-react.md CHANGED
@@ -189,7 +189,19 @@ colors.white // '#ffffff'
189
189
  colors['white/20'] // 'rgba(255,255,255,0.2)'
190
190
  colors.alpha('#ff6b35', 60) // 'rgba(255,107,53,0.6)'
191
191
  ```
192
- Typed against the built-in theme by default — `colors.blu` (typo) is a compile error. Custom `kbach.config.js` colors aren't visible to TypeScript (runtime-loaded plain `.js`), so widen manually: `useColors<DefaultColorName | 'brand'>()`. `useSpacing()` is the same pattern for the spacing scale (`spacing[4]` → `16`, `spacing.full` → `'100%'`).
192
+ Typed against the built-in theme by default — `colors.blu` (typo) is a compile error. Custom `kbach.config.js` colors aren't visible to TypeScript (runtime-loaded plain `.js`), so either widen per call — `useColors<DefaultColorName | 'brand'>()` — or, better, augment once project-wide in any `.d.ts` your tsconfig includes:
193
+
194
+ ```ts
195
+ import '@kbach/react'; // or '@kbach/native' — either works, native re-exports react's types
196
+ declare module '@kbach/react' {
197
+ interface KbachCustomColors {
198
+ brand: ColorScale; // a 1–12 shade scale, like the built-in blue/red
199
+ accent: string; // a flat color, like the built-in white/black — also what a
200
+ // mode-aware { light, dark } config color resolves to at read time
201
+ }
202
+ }
203
+ ```
204
+ Every `useColors()` call in the project then sees `brand`/`accent` automatically, no type parameter needed — same typo-catching as the built-in names. `useSpacing()` has the equivalent `KbachCustomSpacing` interface (`interface KbachCustomSpacing { 18: true }` — only the key is read) for the spacing scale (`spacing[4]` → `16`, `spacing.full` → `'100%'`).
193
205
 
194
206
  ---
195
207
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kbach/react",
3
- "version": "0.6.34",
3
+ "version": "0.6.35",
4
4
  "description": "React / React Native components and hooks for the Kbach framework",
5
5
  "repository": {
6
6
  "type": "git",