@idealyst/theme 1.2.14 → 1.2.16
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 +1 -1
- package/src/styleBuilder.ts +25 -3
- package/src/variants/color.ts +4 -3
package/package.json
CHANGED
package/src/styleBuilder.ts
CHANGED
|
@@ -24,6 +24,7 @@ export type ComponentName =
|
|
|
24
24
|
| 'Badge'
|
|
25
25
|
| 'Breadcrumb'
|
|
26
26
|
| 'Button'
|
|
27
|
+
| 'CameraPreview'
|
|
27
28
|
| 'Card'
|
|
28
29
|
| 'Checkbox'
|
|
29
30
|
| 'Chip'
|
|
@@ -38,6 +39,7 @@ export type ComponentName =
|
|
|
38
39
|
| 'Link'
|
|
39
40
|
| 'List'
|
|
40
41
|
| 'Menu'
|
|
42
|
+
| 'MenuItem'
|
|
41
43
|
| 'Popover'
|
|
42
44
|
| 'Pressable'
|
|
43
45
|
| 'Progress'
|
|
@@ -59,16 +61,36 @@ export type ComponentName =
|
|
|
59
61
|
|
|
60
62
|
export type StyleCallback<TTheme, TStyles> = (theme: TTheme) => TStyles;
|
|
61
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Permissive variant type that accepts any variant configuration.
|
|
66
|
+
* The actual variant names are determined at build time by Unistyles.
|
|
67
|
+
*/
|
|
68
|
+
export type PermissiveVariants = Record<string, string | number | boolean | undefined>;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Return type for defineStyle that preserves style keys and adds useVariants.
|
|
72
|
+
* Style values are typed as 'any' to allow both static styles and dynamic functions.
|
|
73
|
+
*/
|
|
74
|
+
export type DefineStyleResult<TStyles> = {
|
|
75
|
+
[K in keyof TStyles]: TStyles[K];
|
|
76
|
+
} & {
|
|
77
|
+
/**
|
|
78
|
+
* Apply variant values to the stylesheet.
|
|
79
|
+
* Variant names are inferred from the 'variants' property in style definitions.
|
|
80
|
+
*/
|
|
81
|
+
useVariants: (variants: PermissiveVariants) => void;
|
|
82
|
+
};
|
|
83
|
+
|
|
62
84
|
/**
|
|
63
85
|
* Define base styles for a component.
|
|
64
86
|
* Babel transforms this to StyleSheet.create with merged extensions.
|
|
65
87
|
*/
|
|
66
|
-
export function defineStyle<TTheme, TStyles
|
|
88
|
+
export function defineStyle<TTheme, TStyles extends Record<string, unknown>>(
|
|
67
89
|
_componentName: ComponentName,
|
|
68
90
|
styles: StyleCallback<TTheme, TStyles>
|
|
69
|
-
):
|
|
91
|
+
): DefineStyleResult<TStyles> {
|
|
70
92
|
// Babel replaces this - runtime fallback for dev
|
|
71
|
-
return StyleSheet.create(styles as any)
|
|
93
|
+
return StyleSheet.create(styles as any) as DefineStyleResult<TStyles>;
|
|
72
94
|
}
|
|
73
95
|
|
|
74
96
|
/**
|
package/src/variants/color.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { ColorValue, Pallet, Theme } from "../theme";
|
|
1
|
+
import { ColorValue, Pallet, Shade, Theme } from "../theme";
|
|
2
2
|
|
|
3
3
|
export function getColorFromString(theme: Theme, color: string): ColorValue {
|
|
4
|
-
const [colorName,
|
|
4
|
+
const [colorName, shadeStr] = color.split('.') as [Pallet, string | undefined];
|
|
5
5
|
const colorPallet = theme.colors.pallet;
|
|
6
|
-
|
|
6
|
+
const shade = (shadeStr ? Number(shadeStr) : 500) as Shade;
|
|
7
|
+
return colorPallet[colorName]?.[shade];
|
|
7
8
|
}
|