Skip to content

Commit debca00

Browse files
authored
fix gale typing (#4)
1 parent b306fa8 commit debca00

3 files changed

Lines changed: 28 additions & 7 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pistonite/celera",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"type": "module",
55
"private": true,
66
"description": "In-house UI framework",

src/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,17 @@ export {
5454
type DisplayModeOptions,
5555
} from "#pref";
5656

57-
export { gale, GALE_BUILTIN_STYLES, injectStyle, ThemeProvider } from "#style";
57+
export {
58+
gale,
59+
GALE_BUILTIN_STYLES,
60+
injectStyle,
61+
ThemeProvider,
62+
type GaleEngine,
63+
type GaleKeys,
64+
type GaleHook,
65+
type GaleFn,
66+
type GaleString,
67+
} from "#style";
5868

5969
import { log } from "#util";
6070
export { log as celeraLogger };

src/style/gale.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,25 @@ export const gale = <T extends string>(
170170
return Object.assign(useStyleEngine, { extend: makeComponentLevelStyleEngine });
171171
};
172172

173-
type GaleKeys<T extends string> = T | GaleBuiltinKey;
174-
interface GaleEngine<T extends string> extends GaleHook<T> {
173+
/**
174+
* Engine function created by {@link gale}
175+
*
176+
* Can either be used as a hook to get the `m` function, or use `.extend()`
177+
* to extend the styles for component-specific hook.
178+
*/
179+
export interface GaleEngine<T extends string> extends GaleHook<T> {
180+
/** Extend the styles to get a component-specific hook */
175181
extend: <K extends string>(componentStyles: Record<K, GriffelStyle>) => GaleHook<K | T>;
176182
}
177-
type GaleHook<T extends string> = () => GaleFn<T>;
178-
type GaleFn<T extends string> = <K extends string>(classes: GaleString<K, T>) => string;
183+
/** Wrapper to concatenate built-in style keys with project-specific style keys */
184+
export type GaleKeys<T extends string> = T | GaleBuiltinKey;
185+
/** Hook to be called inside a component to get the `m` function. See {@link gale} */
186+
export type GaleHook<T extends string> = () => GaleFn<T>;
187+
/** The `m` function that turns a style string into class names */
188+
export type GaleFn<T extends string> = <K extends string>(classes: GaleString<K, T>) => string;
179189

180-
type GaleString<K extends string, T extends string> = K extends T
190+
/** Type-safe, space-separated style idents */
191+
export type GaleString<K extends string, T extends string> = K extends T
181192
? K
182193
: K extends `${infer U} ${infer N}`
183194
? U extends T

0 commit comments

Comments
 (0)