@stylhero/native 0.0.0-stage → 0.1.0

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/LICENSE +21 -0
  3. package/README.md +85 -2
  4. package/dist/components/Badge.d.ts +11 -0
  5. package/dist/components/Badge.js +31 -0
  6. package/dist/components/Badge.js.map +1 -0
  7. package/dist/components/Button.d.ts +24 -0
  8. package/dist/components/Button.js +59 -0
  9. package/dist/components/Button.js.map +1 -0
  10. package/dist/components/Card.d.ts +17 -0
  11. package/dist/components/Card.js +22 -0
  12. package/dist/components/Card.js.map +1 -0
  13. package/dist/components/IconButton.d.ts +13 -0
  14. package/dist/components/IconButton.js +28 -0
  15. package/dist/components/IconButton.js.map +1 -0
  16. package/dist/components/ListItem.d.ts +24 -0
  17. package/dist/components/ListItem.js +34 -0
  18. package/dist/components/ListItem.js.map +1 -0
  19. package/dist/components/Stack.d.ts +14 -0
  20. package/dist/components/Stack.js +19 -0
  21. package/dist/components/Stack.js.map +1 -0
  22. package/dist/components/Text.d.ts +15 -0
  23. package/dist/components/Text.js +28 -0
  24. package/dist/components/Text.js.map +1 -0
  25. package/dist/components/TextField.d.ts +24 -0
  26. package/dist/components/TextField.js +40 -0
  27. package/dist/components/TextField.js.map +1 -0
  28. package/dist/index.d.ts +10 -0
  29. package/dist/index.js +11 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/theme/ThemeProvider.d.ts +33 -0
  32. package/dist/theme/ThemeProvider.js +45 -0
  33. package/dist/theme/ThemeProvider.js.map +1 -0
  34. package/dist/theme/tokens.d.ts +152 -0
  35. package/dist/theme/tokens.js +150 -0
  36. package/dist/theme/tokens.js.map +1 -0
  37. package/package.json +63 -4
  38. package/src/components/Badge.tsx +54 -0
  39. package/src/components/Button.tsx +128 -0
  40. package/src/components/Card.tsx +72 -0
  41. package/src/components/IconButton.tsx +59 -0
  42. package/src/components/ListItem.tsx +104 -0
  43. package/src/components/Stack.tsx +35 -0
  44. package/src/components/Text.tsx +46 -0
  45. package/src/components/TextField.tsx +123 -0
  46. package/src/index.ts +18 -0
  47. package/src/theme/ThemeProvider.tsx +87 -0
  48. package/src/theme/tokens.ts +163 -0
@@ -0,0 +1,10 @@
1
+ export { ThemeProvider, useTheme, createTheme, type Theme, type ThemeProviderProps, type FontResolver, } from "./theme/ThemeProvider";
2
+ export * from "./theme/tokens";
3
+ export { Text, type TextProps, type TextVariant, type TextTone } from "./components/Text";
4
+ export { Stack, type StackProps } from "./components/Stack";
5
+ export { Button, MIN_TOUCH_TARGET, type ButtonProps, type ButtonVariant, type ButtonSize } from "./components/Button";
6
+ export { IconButton, type IconButtonProps } from "./components/IconButton";
7
+ export { Badge, type BadgeProps, type BadgeTone } from "./components/Badge";
8
+ export { Card, type CardProps } from "./components/Card";
9
+ export { TextField, type TextFieldProps } from "./components/TextField";
10
+ export { ListItem, type ListItemProps } from "./components/ListItem";
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ export { ThemeProvider, useTheme, createTheme, } from "./theme/ThemeProvider";
2
+ export * from "./theme/tokens";
3
+ export { Text } from "./components/Text";
4
+ export { Stack } from "./components/Stack";
5
+ export { Button, MIN_TOUCH_TARGET } from "./components/Button";
6
+ export { IconButton } from "./components/IconButton";
7
+ export { Badge } from "./components/Badge";
8
+ export { Card } from "./components/Card";
9
+ export { TextField } from "./components/TextField";
10
+ export { ListItem } from "./components/ListItem";
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,QAAQ,EACR,WAAW,GAIZ,MAAM,uBAAuB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAE/B,OAAO,EAAE,IAAI,EAAmD,MAAM,mBAAmB,CAAC;AAC1F,OAAO,EAAE,KAAK,EAAmB,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAyD,MAAM,qBAAqB,CAAC;AACtH,OAAO,EAAE,UAAU,EAAwB,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,KAAK,EAAmC,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,IAAI,EAAkB,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAuB,MAAM,wBAAwB,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAsB,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { type ReactNode } from "react";
2
+ import { type TextStyle } from "react-native";
3
+ import { radius, shadows, spacing, type ColorScheme, type Colors, type FontFamilyToken, type TypographyToken } from "./tokens";
4
+ type FontWeight = "400" | "500" | "600" | "700" | "800";
5
+ /**
6
+ * Maps a token font family + weight to a loaded font name, e.g. with
7
+ * `@expo-google-fonts/plus-jakarta-sans`:
8
+ * (family, weight) => family === "mono" ? undefined : `PlusJakartaSans_${names[weight]}`
9
+ * Custom fonts bake the weight into the family name, so when this returns a
10
+ * name the style drops `fontWeight` (Android would otherwise fake-bold it).
11
+ * Returning undefined keeps the platform system font with `fontWeight`.
12
+ */
13
+ export type FontResolver = (family: FontFamilyToken, weight: FontWeight) => string | undefined;
14
+ export type Theme = {
15
+ scheme: ColorScheme;
16
+ colors: Colors;
17
+ spacing: typeof spacing;
18
+ radius: typeof radius;
19
+ shadows: Record<keyof (typeof shadows)["light"], string>;
20
+ /** Text style for a type token, with the font resolver applied. */
21
+ text: (variant: TypographyToken, weight?: FontWeight) => TextStyle;
22
+ };
23
+ export declare function createTheme(scheme: ColorScheme, resolveFont?: FontResolver): Theme;
24
+ export type ThemeProviderProps = {
25
+ /** "system" (default) follows the device setting and updates live. */
26
+ colorScheme?: ColorScheme | "system";
27
+ fonts?: FontResolver;
28
+ children: ReactNode;
29
+ };
30
+ export declare function ThemeProvider({ colorScheme, fonts, children }: ThemeProviderProps): import("react").JSX.Element;
31
+ /** The current theme. Outside a ThemeProvider it returns the light theme with system fonts. */
32
+ export declare function useTheme(): Theme;
33
+ export {};
@@ -0,0 +1,45 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useMemo } from "react";
3
+ import { useColorScheme } from "react-native";
4
+ import { colors, radius, shadows, spacing, typography, } from "./tokens";
5
+ export function createTheme(scheme, resolveFont) {
6
+ const cache = new Map();
7
+ return {
8
+ scheme,
9
+ colors: colors[scheme],
10
+ spacing,
11
+ radius,
12
+ shadows: shadows[scheme],
13
+ text(variant, weight) {
14
+ const key = `${variant}:${weight ?? ""}`;
15
+ const cached = cache.get(key);
16
+ if (cached)
17
+ return cached;
18
+ const t = typography[variant];
19
+ const fontWeight = (weight ?? t.fontWeight);
20
+ const fontFamily = resolveFont?.(t.family, fontWeight);
21
+ const style = {
22
+ fontSize: t.fontSize,
23
+ lineHeight: t.lineHeight,
24
+ ...("letterSpacing" in t ? { letterSpacing: t.letterSpacing } : null),
25
+ ...(fontFamily ? { fontFamily } : { fontWeight }),
26
+ ...(t.family === "mono" && !fontFamily ? { fontVariant: ["tabular-nums"] } : null),
27
+ };
28
+ cache.set(key, style);
29
+ return style;
30
+ },
31
+ };
32
+ }
33
+ const ThemeContext = createContext(null);
34
+ export function ThemeProvider({ colorScheme = "system", fonts, children }) {
35
+ const system = useColorScheme();
36
+ const scheme = colorScheme === "system" ? (system === "dark" ? "dark" : "light") : colorScheme;
37
+ const theme = useMemo(() => createTheme(scheme, fonts), [scheme, fonts]);
38
+ return _jsx(ThemeContext.Provider, { value: theme, children: children });
39
+ }
40
+ const fallback = createTheme("light");
41
+ /** The current theme. Outside a ThemeProvider it returns the light theme with system fonts. */
42
+ export function useTheme() {
43
+ return useContext(ThemeContext) ?? fallback;
44
+ }
45
+ //# sourceMappingURL=ThemeProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ThemeProvider.js","sourceRoot":"","sources":["../../src/theme/ThemeProvider.tsx"],"names":[],"mappings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,CAAC,CAAC,MAAM,KAAK,MAAM,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;aACnF,CAAC;YACF,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACtB,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC;AACJ,CAAC;AAED,MAAM,YAAY,GAAG,aAAa,CAAe,IAAI,CAAC,CAAC;AASvD,MAAM,UAAU,aAAa,CAAC,EAAE,WAAW,GAAG,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAsB;IAC3F,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAChC,MAAM,MAAM,GACV,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;IAClF,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IACzE,OAAO,KAAC,YAAY,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAyB,CAAC;AACjF,CAAC;AAED,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;AAEtC,+FAA+F;AAC/F,MAAM,UAAU,QAAQ;IACtB,OAAO,UAAU,CAAC,YAAY,CAAC,IAAI,QAAQ,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,152 @@
1
+ export declare const colorSchemes: readonly ["light", "dark"];
2
+ export type ColorScheme = (typeof colorSchemes)[number];
3
+ export declare const colors: {
4
+ readonly light: {
5
+ readonly surface: "#f7f9fc";
6
+ readonly surfaceRaised: "#ffffff";
7
+ readonly surfaceSunken: "#edf2f8";
8
+ readonly ink: "#0b1b33";
9
+ readonly inkMuted: "#4b5b73";
10
+ readonly line: "#d6dfeb";
11
+ readonly lineStrong: "#76869e";
12
+ readonly primary: "#173a7a";
13
+ readonly primaryHover: "#112c5e";
14
+ readonly onPrimary: "#ffffff";
15
+ readonly primarySoft: "#e3ebf8";
16
+ readonly sky: "#3ba3e6";
17
+ readonly skySoft: "#e0f1fc";
18
+ readonly accent: "#f5d23d";
19
+ readonly onAccent: "#0b1b33";
20
+ readonly accentSoft: "#fdf6d3";
21
+ readonly accentInk: "#7a5c00";
22
+ readonly success: "#1f7a3d";
23
+ readonly successSoft: "#dff2e5";
24
+ readonly danger: "#b3261e";
25
+ readonly dangerSoft: "#fbe3e1";
26
+ readonly chart1: "#2a78d6";
27
+ readonly chart2: "#eb6834";
28
+ readonly chart3: "#1baf7a";
29
+ readonly chart4: "#eda100";
30
+ readonly chart5: "#e87ba4";
31
+ readonly chart6: "#008300";
32
+ readonly chart7: "#6250d6";
33
+ readonly chart8: "#e34948";
34
+ };
35
+ readonly dark: {
36
+ readonly surface: "#0a1220";
37
+ readonly surfaceRaised: "#111b2e";
38
+ readonly surfaceSunken: "#070d18";
39
+ readonly ink: "#e8eef7";
40
+ readonly inkMuted: "#9fb0c8";
41
+ readonly line: "#24324a";
42
+ readonly lineStrong: "#5b6d8f";
43
+ readonly primary: "#7fb2ff";
44
+ readonly primaryHover: "#a3c8ff";
45
+ readonly onPrimary: "#0a1a36";
46
+ readonly primarySoft: "#16264a";
47
+ readonly sky: "#5cb8f0";
48
+ readonly skySoft: "#0f2a3d";
49
+ readonly accent: "#f7dc5c";
50
+ readonly onAccent: "#1a1600";
51
+ readonly accentSoft: "#332b0a";
52
+ readonly accentInk: "#f7dc5c";
53
+ readonly success: "#5bc67f";
54
+ readonly successSoft: "#13301d";
55
+ readonly danger: "#f2867e";
56
+ readonly dangerSoft: "#3a1715";
57
+ readonly chart1: "#3987e5";
58
+ readonly chart2: "#d95926";
59
+ readonly chart3: "#199e70";
60
+ readonly chart4: "#c98500";
61
+ readonly chart5: "#d55181";
62
+ readonly chart6: "#008300";
63
+ readonly chart7: "#9085e9";
64
+ readonly chart8: "#e66767";
65
+ };
66
+ };
67
+ export type ColorToken = keyof (typeof colors)["light"];
68
+ export type Colors = Record<ColorToken, string>;
69
+ export declare const spacing: {
70
+ readonly 1: 4;
71
+ readonly 2: 8;
72
+ readonly 3: 12;
73
+ readonly 4: 16;
74
+ readonly 6: 24;
75
+ readonly 8: 32;
76
+ readonly 12: 48;
77
+ };
78
+ export type SpacingToken = keyof typeof spacing;
79
+ export declare const radius: {
80
+ readonly sm: 6;
81
+ readonly md: 10;
82
+ readonly lg: 16;
83
+ readonly full: 9999;
84
+ };
85
+ export type RadiusToken = keyof typeof radius;
86
+ export declare const typography: {
87
+ readonly display: {
88
+ readonly family: "display";
89
+ readonly fontSize: 48;
90
+ readonly lineHeight: 52;
91
+ readonly fontWeight: "800";
92
+ readonly letterSpacing: -1.44;
93
+ };
94
+ readonly h1: {
95
+ readonly family: "display";
96
+ readonly fontSize: 32;
97
+ readonly lineHeight: 38;
98
+ readonly fontWeight: "800";
99
+ readonly letterSpacing: -0.64;
100
+ };
101
+ readonly h2: {
102
+ readonly family: "display";
103
+ readonly fontSize: 24;
104
+ readonly lineHeight: 30;
105
+ readonly fontWeight: "700";
106
+ readonly letterSpacing: -0.24;
107
+ };
108
+ readonly h3: {
109
+ readonly family: "sans";
110
+ readonly fontSize: 18;
111
+ readonly lineHeight: 24;
112
+ readonly fontWeight: "700";
113
+ };
114
+ readonly body: {
115
+ readonly family: "sans";
116
+ readonly fontSize: 16;
117
+ readonly lineHeight: 24;
118
+ readonly fontWeight: "400";
119
+ };
120
+ readonly small: {
121
+ readonly family: "sans";
122
+ readonly fontSize: 14;
123
+ readonly lineHeight: 20;
124
+ readonly fontWeight: "400";
125
+ };
126
+ readonly label: {
127
+ readonly family: "sans";
128
+ readonly fontSize: 12;
129
+ readonly lineHeight: 16;
130
+ readonly fontWeight: "700";
131
+ readonly letterSpacing: 0.72;
132
+ };
133
+ readonly mono: {
134
+ readonly family: "mono";
135
+ readonly fontSize: 14;
136
+ readonly lineHeight: 20;
137
+ readonly fontWeight: "400";
138
+ };
139
+ };
140
+ export type TypographyToken = keyof typeof typography;
141
+ export type FontFamilyToken = (typeof typography)[TypographyToken]["family"];
142
+ export declare const shadows: {
143
+ readonly light: {
144
+ readonly card: "0 1px 2px #0b1b330f, 0 4px 12px #0b1b330d";
145
+ readonly dialog: "0 16px 40px #0b1b3333";
146
+ };
147
+ readonly dark: {
148
+ readonly card: "0 1px 2px #00000066";
149
+ readonly dialog: "0 16px 40px #000000a6";
150
+ };
151
+ };
152
+ export type ShadowToken = keyof (typeof shadows)["light"];
@@ -0,0 +1,150 @@
1
+ // GENERATED by scripts/build-tokens.mjs from tokens.json. Do not edit by hand.
2
+ // Run `npm run tokens` after changing tokens.json.
3
+ export const colorSchemes = [
4
+ "light",
5
+ "dark"
6
+ ];
7
+ export const colors = {
8
+ "light": {
9
+ "surface": "#f7f9fc",
10
+ "surfaceRaised": "#ffffff",
11
+ "surfaceSunken": "#edf2f8",
12
+ "ink": "#0b1b33",
13
+ "inkMuted": "#4b5b73",
14
+ "line": "#d6dfeb",
15
+ "lineStrong": "#76869e",
16
+ "primary": "#173a7a",
17
+ "primaryHover": "#112c5e",
18
+ "onPrimary": "#ffffff",
19
+ "primarySoft": "#e3ebf8",
20
+ "sky": "#3ba3e6",
21
+ "skySoft": "#e0f1fc",
22
+ "accent": "#f5d23d",
23
+ "onAccent": "#0b1b33",
24
+ "accentSoft": "#fdf6d3",
25
+ "accentInk": "#7a5c00",
26
+ "success": "#1f7a3d",
27
+ "successSoft": "#dff2e5",
28
+ "danger": "#b3261e",
29
+ "dangerSoft": "#fbe3e1",
30
+ "chart1": "#2a78d6",
31
+ "chart2": "#eb6834",
32
+ "chart3": "#1baf7a",
33
+ "chart4": "#eda100",
34
+ "chart5": "#e87ba4",
35
+ "chart6": "#008300",
36
+ "chart7": "#6250d6",
37
+ "chart8": "#e34948"
38
+ },
39
+ "dark": {
40
+ "surface": "#0a1220",
41
+ "surfaceRaised": "#111b2e",
42
+ "surfaceSunken": "#070d18",
43
+ "ink": "#e8eef7",
44
+ "inkMuted": "#9fb0c8",
45
+ "line": "#24324a",
46
+ "lineStrong": "#5b6d8f",
47
+ "primary": "#7fb2ff",
48
+ "primaryHover": "#a3c8ff",
49
+ "onPrimary": "#0a1a36",
50
+ "primarySoft": "#16264a",
51
+ "sky": "#5cb8f0",
52
+ "skySoft": "#0f2a3d",
53
+ "accent": "#f7dc5c",
54
+ "onAccent": "#1a1600",
55
+ "accentSoft": "#332b0a",
56
+ "accentInk": "#f7dc5c",
57
+ "success": "#5bc67f",
58
+ "successSoft": "#13301d",
59
+ "danger": "#f2867e",
60
+ "dangerSoft": "#3a1715",
61
+ "chart1": "#3987e5",
62
+ "chart2": "#d95926",
63
+ "chart3": "#199e70",
64
+ "chart4": "#c98500",
65
+ "chart5": "#d55181",
66
+ "chart6": "#008300",
67
+ "chart7": "#9085e9",
68
+ "chart8": "#e66767"
69
+ }
70
+ };
71
+ export const spacing = {
72
+ 1: 4,
73
+ 2: 8,
74
+ 3: 12,
75
+ 4: 16,
76
+ 6: 24,
77
+ 8: 32,
78
+ 12: 48
79
+ };
80
+ export const radius = {
81
+ "sm": 6,
82
+ "md": 10,
83
+ "lg": 16,
84
+ "full": 9999
85
+ };
86
+ export const typography = {
87
+ "display": {
88
+ "family": "display",
89
+ "fontSize": 48,
90
+ "lineHeight": 52,
91
+ "fontWeight": "800",
92
+ "letterSpacing": -1.44
93
+ },
94
+ "h1": {
95
+ "family": "display",
96
+ "fontSize": 32,
97
+ "lineHeight": 38,
98
+ "fontWeight": "800",
99
+ "letterSpacing": -0.64
100
+ },
101
+ "h2": {
102
+ "family": "display",
103
+ "fontSize": 24,
104
+ "lineHeight": 30,
105
+ "fontWeight": "700",
106
+ "letterSpacing": -0.24
107
+ },
108
+ "h3": {
109
+ "family": "sans",
110
+ "fontSize": 18,
111
+ "lineHeight": 24,
112
+ "fontWeight": "700"
113
+ },
114
+ "body": {
115
+ "family": "sans",
116
+ "fontSize": 16,
117
+ "lineHeight": 24,
118
+ "fontWeight": "400"
119
+ },
120
+ "small": {
121
+ "family": "sans",
122
+ "fontSize": 14,
123
+ "lineHeight": 20,
124
+ "fontWeight": "400"
125
+ },
126
+ "label": {
127
+ "family": "sans",
128
+ "fontSize": 12,
129
+ "lineHeight": 16,
130
+ "fontWeight": "700",
131
+ "letterSpacing": 0.72
132
+ },
133
+ "mono": {
134
+ "family": "mono",
135
+ "fontSize": 14,
136
+ "lineHeight": 20,
137
+ "fontWeight": "400"
138
+ }
139
+ };
140
+ export const shadows = {
141
+ "light": {
142
+ "card": "0 1px 2px #0b1b330f, 0 4px 12px #0b1b330d",
143
+ "dialog": "0 16px 40px #0b1b3333"
144
+ },
145
+ "dark": {
146
+ "card": "0 1px 2px #00000066",
147
+ "dialog": "0 16px 40px #000000a6"
148
+ }
149
+ };
150
+ //# sourceMappingURL=tokens.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../src/theme/tokens.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,mDAAmD;AAEnD,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,OAAO;IACP,MAAM;CACE,CAAC;AAGX,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,OAAO,EAAE;QACP,SAAS,EAAE,SAAS;QACpB,eAAe,EAAE,SAAS;QAC1B,eAAe,EAAE,SAAS;QAC1B,KAAK,EAAE,SAAS;QAChB,UAAU,EAAE,SAAS;QACrB,MAAM,EAAE,SAAS;QACjB,YAAY,EAAE,SAAS;QACvB,SAAS,EAAE,SAAS;QACpB,cAAc,EAAE,SAAS;QACzB,WAAW,EAAE,SAAS;QACtB,aAAa,EAAE,SAAS;QACxB,KAAK,EAAE,SAAS;QAChB,SAAS,EAAE,SAAS;QACpB,QAAQ,EAAE,SAAS;QACnB,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;QACN,QAAQ,EAAE,MAAM;QAChB,UAAU,EAAE,EAAE;QACd,YAAY,EAAE,EAAE;QAChB,YAAY,EAAE,KAAK;KACpB;CACO,CAAC;AAIX,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,OAAO,EAAE;QACP,MAAM,EAAE,2CAA2C;QACnD,QAAQ,EAAE,uBAAuB;KAClC;IACD,MAAM,EAAE;QACN,MAAM,EAAE,qBAAqB;QAC7B,QAAQ,EAAE,uBAAuB;KAClC;CACO,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
2
  "name": "@stylhero/native",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Stylhero design system for React Native: tokens, theming and accessible components",
5
+ "license": "MIT",
6
+ "author": "Oscar Ruíz",
7
+ "homepage": "https://github.com/raiburn/stylhero/tree/main/native#readme",
8
+ "bugs": {
9
+ "url": "https://github.com/raiburn/stylhero/issues"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/raiburn/stylhero.git",
14
+ "directory": "native"
15
+ },
16
+ "keywords": [
17
+ "react-native",
18
+ "expo",
19
+ "design-system",
20
+ "design-tokens",
21
+ "accessibility",
22
+ "components"
23
+ ],
24
+ "main": "./dist/index.js",
25
+ "types": "./dist/index.d.ts",
26
+ "react-native": "./src/index.ts",
27
+ "source": "./src/index.ts",
28
+ "files": [
29
+ "dist",
30
+ "src",
31
+ "!src/**/__tests__",
32
+ "CHANGELOG.md"
33
+ ],
34
+ "sideEffects": false,
35
+ "scripts": {
36
+ "tokens": "node scripts/build-tokens.mjs",
37
+ "build": "npm run tokens && tsc -p tsconfig.build.json",
38
+ "typecheck": "tsc --noEmit",
39
+ "test": "jest",
40
+ "changeset": "changeset",
41
+ "version-packages": "changeset version && npm install --package-lock-only --ignore-scripts",
42
+ "check:pack": "npm pack --dry-run",
43
+ "prepublishOnly": "npm run typecheck && npm run build && npm test"
44
+ },
45
+ "peerDependencies": {
46
+ "react": ">=19",
47
+ "react-native": ">=0.78"
48
+ },
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "devDependencies": {
53
+ "@changesets/cli": "^3.1.0",
54
+ "@react-native/babel-preset": "^0.88.1",
55
+ "@react-native/jest-preset": "^0.88.1",
56
+ "@testing-library/react-native": "^14.1.0",
57
+ "@types/jest": "^30.0.0",
58
+ "@types/react": "^19.3.0",
59
+ "jest": "^30.5.2",
60
+ "react": "^19.3.1",
61
+ "react-native": "^0.88.1",
62
+ "test-renderer": "^1.3.1",
63
+ "typescript": "^5.9.3"
64
+ }
65
+ }
@@ -0,0 +1,54 @@
1
+ import type { ReactNode } from "react";
2
+ import { View, type StyleProp, type ViewProps, type ViewStyle } from "react-native";
3
+ import { useTheme } from "../theme/ThemeProvider";
4
+ import type { ColorToken } from "../theme/tokens";
5
+ import { Text } from "./Text";
6
+
7
+ export type BadgeTone = "neutral" | "primary" | "info" | "accent" | "success" | "danger";
8
+
9
+ export type BadgeProps = Omit<ViewProps, "children" | "style"> & {
10
+ children: string;
11
+ tone?: BadgeTone;
12
+ icon?: ReactNode;
13
+ style?: StyleProp<ViewStyle>;
14
+ };
15
+
16
+ const tones: Record<BadgeTone, [bg: ColorToken, fg: ColorToken]> = {
17
+ neutral: ["surfaceSunken", "inkMuted"],
18
+ primary: ["primarySoft", "primary"],
19
+ info: ["skySoft", "primary"],
20
+ accent: ["accentSoft", "accentInk"],
21
+ success: ["successSoft", "success"],
22
+ danger: ["dangerSoft", "danger"],
23
+ };
24
+
25
+ /** Small status label, e.g. "Compatible" or "Out of stock". */
26
+ export function Badge({ children, tone = "neutral", icon, style, ...props }: BadgeProps) {
27
+ const theme = useTheme();
28
+ const [bg, fg] = tones[tone];
29
+ return (
30
+ <View
31
+ accessible
32
+ accessibilityLabel={children}
33
+ style={[
34
+ {
35
+ flexDirection: "row",
36
+ alignItems: "center",
37
+ alignSelf: "flex-start",
38
+ gap: theme.spacing[1],
39
+ paddingVertical: 2,
40
+ paddingHorizontal: theme.spacing[2],
41
+ borderRadius: theme.radius.sm,
42
+ backgroundColor: theme.colors[bg],
43
+ },
44
+ style,
45
+ ]}
46
+ {...props}
47
+ >
48
+ {icon}
49
+ <Text variant="label" style={{ color: theme.colors[fg], letterSpacing: 0 }} maxFontSizeMultiplier={1.5}>
50
+ {children}
51
+ </Text>
52
+ </View>
53
+ );
54
+ }
@@ -0,0 +1,128 @@
1
+ import type { ComponentRef, ReactElement, ReactNode, Ref } from "react";
2
+ import {
3
+ ActivityIndicator,
4
+ Pressable,
5
+ View,
6
+ type PressableProps,
7
+ type StyleProp,
8
+ type ViewStyle,
9
+ } from "react-native";
10
+ import { useTheme, type Theme } from "../theme/ThemeProvider";
11
+ import { Text } from "./Text";
12
+
13
+ export type ButtonVariant = "primary" | "secondary" | "ghost" | "danger";
14
+ export type ButtonSize = "sm" | "md" | "lg";
15
+
16
+ export type ButtonProps = Omit<PressableProps, "children" | "style"> & {
17
+ ref?: Ref<ComponentRef<typeof View>>;
18
+ children: string;
19
+ variant?: ButtonVariant;
20
+ size?: ButtonSize;
21
+ /** Shows a spinner, keeps the width, and blocks presses. Announced as busy. */
22
+ loading?: boolean;
23
+ fullWidth?: boolean;
24
+ /** Icon shown before the label (e.g. a lucide-react-native icon). */
25
+ icon?: ReactNode;
26
+ /**
27
+ * Caps the label's lines. Unset by default so long labels wrap instead of
28
+ * being cut off when the user picks a large text size.
29
+ */
30
+ numberOfLines?: number;
31
+ style?: StyleProp<ViewStyle>;
32
+ };
33
+
34
+ const heights: Record<ButtonSize, number> = { sm: 32, md: 40, lg: 48 };
35
+ /** Minimum touch target (WCAG 2.5.5 / Apple HIG 44pt). */
36
+ export const MIN_TOUCH_TARGET = 44;
37
+
38
+ function palette(theme: Theme, variant: ButtonVariant, pressed: boolean) {
39
+ const c = theme.colors;
40
+ switch (variant) {
41
+ case "primary":
42
+ return { bg: pressed ? c.primaryHover : c.primary, fg: c.onPrimary, border: "transparent" };
43
+ case "secondary":
44
+ return { bg: pressed ? c.surfaceSunken : c.surfaceRaised, fg: c.ink, border: c.line };
45
+ case "ghost":
46
+ return { bg: pressed ? c.primarySoft : "transparent", fg: c.primary, border: "transparent" };
47
+ case "danger":
48
+ return { bg: c.danger, fg: c.surfaceRaised, border: "transparent", opacity: pressed ? 0.9 : 1 };
49
+ }
50
+ }
51
+
52
+ export function Button({
53
+ ref,
54
+ children,
55
+ variant = "primary",
56
+ size = "md",
57
+ loading = false,
58
+ fullWidth,
59
+ icon,
60
+ numberOfLines,
61
+ disabled,
62
+ style,
63
+ hitSlop,
64
+ accessibilityLabel,
65
+ ...props
66
+ }: ButtonProps): ReactElement {
67
+ const theme = useTheme();
68
+ const height = heights[size];
69
+ const inactive = Boolean(disabled) || loading;
70
+ // Small buttons keep their look but get an invisible touch area of at least 44pt.
71
+ const slop = hitSlop ?? Math.max(0, Math.ceil((MIN_TOUCH_TARGET - height) / 2));
72
+
73
+ return (
74
+ <Pressable
75
+ ref={ref}
76
+ accessibilityRole="button"
77
+ accessibilityLabel={accessibilityLabel ?? children}
78
+ accessibilityState={{ disabled: inactive, busy: loading }}
79
+ disabled={inactive}
80
+ hitSlop={slop}
81
+ style={({ pressed }) => {
82
+ const p = palette(theme, variant, pressed && !inactive);
83
+ return [
84
+ {
85
+ // minHeight, not height: the label grows with the user's font size setting
86
+ minHeight: height,
87
+ minWidth: height,
88
+ maxWidth: "100%",
89
+ paddingVertical: theme.spacing[1],
90
+ paddingHorizontal: size === "sm" ? theme.spacing[3] : size === "lg" ? theme.spacing[6] : theme.spacing[4],
91
+ flexDirection: "row",
92
+ alignItems: "center",
93
+ justifyContent: "center",
94
+ gap: theme.spacing[2],
95
+ backgroundColor: p.bg,
96
+ borderColor: p.border,
97
+ borderWidth: 1,
98
+ borderRadius: theme.radius.md,
99
+ opacity: disabled ? 0.5 : loading ? 0.8 : p.opacity ?? 1,
100
+ alignSelf: fullWidth ? "stretch" : "flex-start",
101
+ },
102
+ style,
103
+ ];
104
+ }}
105
+ {...props}
106
+ >
107
+ {({ pressed }) => {
108
+ const p = palette(theme, variant, pressed && !inactive);
109
+ return (
110
+ <>
111
+ {loading ? <ActivityIndicator size="small" color={p.fg} testID="button-spinner" /> : icon}
112
+ <Text
113
+ variant="body"
114
+ numberOfLines={numberOfLines}
115
+ style={[
116
+ theme.text("body", "700"),
117
+ // flexShrink lets the label wrap inside the button instead of overflowing it
118
+ { color: p.fg, fontSize: size === "sm" ? 13 : size === "lg" ? 16 : 15, flexShrink: 1, textAlign: "center" },
119
+ ]}
120
+ >
121
+ {children}
122
+ </Text>
123
+ </>
124
+ );
125
+ }}
126
+ </Pressable>
127
+ );
128
+ }