@hamster-note/components 0.3.0 → 0.4.0-beta.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 (74) hide show
  1. package/README.md +28 -0
  2. package/dist/Icon-BuZRZcjv.js +1143 -0
  3. package/dist/button-mmBNcoG1.js +45 -0
  4. package/dist/button.js +1 -1
  5. package/dist/components/button/Button.d.ts +3 -2
  6. package/dist/components/icon/icon-names.d.ts +1 -15
  7. package/dist/components/theme/theme.d.ts +1 -87
  8. package/dist/{confirm-Faavk_5T.js → confirm-DKgVMWkR.js} +2 -2
  9. package/dist/confirm.js +1 -1
  10. package/dist/{dialog-BYlEUJ_j.js → dialog-DI_yumUn.js} +1 -1
  11. package/dist/dialog.js +1 -1
  12. package/dist/{drawer-BV9RFSna.js → drawer-Cpe3Yf3K.js} +1 -1
  13. package/dist/drawer.js +1 -1
  14. package/dist/hamster-note-components.css +1 -1
  15. package/dist/{icon-BFAcjkFI.js → icon-u7jiIYal.js} +1 -1
  16. package/dist/icon.js +2 -2
  17. package/dist/index.js +7 -7
  18. package/dist/shared/icon-names.d.ts +15 -0
  19. package/dist/shared/icons.d.ts +1216 -0
  20. package/dist/shared/theme.d.ts +87 -0
  21. package/dist/shared/tokens.d.ts +67 -0
  22. package/dist/test/shared-data.test.d.ts +1 -0
  23. package/dist/{theme-CVNLJL1G.js → theme-DNK-xd31.js} +1 -1
  24. package/dist/theme.js +1 -1
  25. package/dist-native/badge.d.ts +10 -0
  26. package/dist-native/badge.js +7 -0
  27. package/dist-native/button.d.ts +16 -0
  28. package/dist-native/button.js +7 -0
  29. package/dist-native/chunk-6RD26X3W.js +78 -0
  30. package/dist-native/chunk-6SR5ZHDD.js +13 -0
  31. package/dist-native/chunk-6VYUVVCP.js +27 -0
  32. package/dist-native/chunk-7LN4VNRB.js +124 -0
  33. package/dist-native/chunk-CF76TWL4.js +85 -0
  34. package/dist-native/chunk-ENTYQ6M4.js +256 -0
  35. package/dist-native/chunk-GSG6CXIE.js +1688 -0
  36. package/dist-native/chunk-JHT74YG3.js +186 -0
  37. package/dist-native/chunk-KPDK62A5.js +106 -0
  38. package/dist-native/chunk-PLFX4RVR.js +134 -0
  39. package/dist-native/chunk-QUGLAOXA.js +49 -0
  40. package/dist-native/chunk-S2EUKEYI.js +35 -0
  41. package/dist-native/chunk-VTE5RPMO.js +38 -0
  42. package/dist-native/chunk-YJ4H3ZBQ.js +145 -0
  43. package/dist-native/chunk-ZTQATW6Y.js +127 -0
  44. package/dist-native/confirm.d.ts +24 -0
  45. package/dist-native/confirm.js +14 -0
  46. package/dist-native/dialog.d.ts +8 -0
  47. package/dist-native/dialog.js +10 -0
  48. package/dist-native/drawer.d.ts +13 -0
  49. package/dist-native/drawer.js +10 -0
  50. package/dist-native/focus-C0k0lLui.d.ts +9 -0
  51. package/dist-native/icon.d.ts +28 -0
  52. package/dist-native/icon.js +9 -0
  53. package/dist-native/index.d.ts +20 -0
  54. package/dist-native/index.js +84 -0
  55. package/dist-native/kbd.d.ts +9 -0
  56. package/dist-native/kbd.js +7 -0
  57. package/dist-native/loading.d.ts +19 -0
  58. package/dist-native/loading.js +11 -0
  59. package/dist-native/menu.d.ts +31 -0
  60. package/dist-native/menu.js +17 -0
  61. package/dist-native/modal-panel-BOpp1oRC.d.ts +23 -0
  62. package/dist-native/note-card.d.ts +13 -0
  63. package/dist-native/note-card.js +7 -0
  64. package/dist-native/popover.d.ts +34 -0
  65. package/dist-native/popover.js +8 -0
  66. package/dist-native/position-CkPoZ5AD.d.ts +3 -0
  67. package/dist-native/text-field.d.ts +13 -0
  68. package/dist-native/text-field.js +7 -0
  69. package/dist-native/theme.d.ts +120 -0
  70. package/dist-native/theme.js +16 -0
  71. package/dist-native/tokens-DHoNd-yT.d.ts +41 -0
  72. package/package.json +137 -5
  73. package/dist/Icon-BBSPOBTI.js +0 -531
  74. package/dist/button-DjMS8bKj.js +0 -20
@@ -0,0 +1,120 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+ import { N as NUMERIC_TOKENS } from './tokens-DHoNd-yT.js';
4
+
5
+ /**
6
+ * 主题色配置(accent 主色)。
7
+ *
8
+ * 设计哲学:组件库所有组件只引用全局 token(见 tokens.css 的 :root),
9
+ * 主题切换通过在包裹层重定义同名 token、经 CSS 级联让子树自动继承
10
+ * (Popover 的 dark/light 即是这一范式)。本文件是 accent 主题色的
11
+ * 唯一数据源:ThemeProvider 读取这里的预设值,内联下发到包裹 div 的
12
+ * style 上,子树所有组件经 var(--hn-color-accent) 等拿到新色值。
13
+ *
14
+ * 预设色刻意避开既有语义色(danger #fb7185 / success #4ade80 /
15
+ * warning #fbbf24),避免主题色与语义色产生视觉冲突。
16
+ */
17
+ /**
18
+ * 预设主题色表。
19
+ *
20
+ * 每个预设包含三个字段,分别对应 tokens.css 中被 accent 影响的三个 token:
21
+ * - accent:主色,映射到 --hn-color-accent
22
+ * - accentHover:hover 态色,映射到 --hn-color-accent-hover
23
+ * - focusRingColor:焦点环颜色(不含 box-shadow 前缀,仅颜色部分),
24
+ * ThemeProvider 会拼成 `0 0 0 3px ${focusRingColor}` 写入 --hn-focus-ring
25
+ *
26
+ * `violet` 与 tokens.css 的默认值完全一致,作为 ThemeProvider 的默认预设,
27
+ * 保证不传 accent 时视觉与未包裹 ThemeProvider 时完全等价(零 Breaking Change)。
28
+ */
29
+ declare const THEME_ACCENTS: {
30
+ readonly violet: {
31
+ readonly accent: "#7c83ff";
32
+ readonly accentHover: "#9197ff";
33
+ readonly focusRingColor: "rgb(145 151 255 / 42%)";
34
+ };
35
+ readonly blue: {
36
+ readonly accent: "#60a5fa";
37
+ readonly accentHover: "#7db6fb";
38
+ readonly focusRingColor: "rgb(96 165 250 / 42%)";
39
+ };
40
+ readonly teal: {
41
+ readonly accent: "#2dd4bf";
42
+ readonly accentHover: "#4fdcc9";
43
+ readonly focusRingColor: "rgb(45 212 191 / 42%)";
44
+ };
45
+ readonly orange: {
46
+ readonly accent: "#fb923c";
47
+ readonly accentHover: "#fca45c";
48
+ readonly focusRingColor: "rgb(251 146 60 / 42%)";
49
+ };
50
+ readonly pink: {
51
+ readonly accent: "#f472b6";
52
+ readonly accentHover: "#f68cc4";
53
+ readonly focusRingColor: "rgb(244 114 182 / 42%)";
54
+ };
55
+ };
56
+ /**
57
+ * 预设主题色名:`violet` | `blue` | `teal` | `orange` | `pink`。
58
+ */
59
+ type ThemeAccentPreset = keyof typeof THEME_ACCENTS;
60
+ /**
61
+ * 明暗模式。
62
+ *
63
+ * 与 accent 主题色正交:accent 重定义 `--hn-color-accent` 等 accent 三件套,
64
+ * mode 重定义 `--hn-color-surface` / `--hn-color-text` / `--hn-color-border`
65
+ * 等全套表面与文字 token。两个轴独立组合,例如可以同时「浅色背景 + 蓝色 accent」。
66
+ *
67
+ * - `dark`(默认):与 tokens.css 的 :root 默认值一致,不传时视觉无变化;
68
+ * - `light`:重定义全套表面/文字/边框 token 为浅色配色。
69
+ *
70
+ * 实际的 token 覆盖值定义在 theme.css 的 `.hn-theme[data-mode='light']` 与
71
+ * `.hn-theme[data-mode='dark']` 规则中,ThemeProvider 只负责把 mode 写到
72
+ * 根 div 的 `data-mode` 属性上,CSS 级联完成其余工作。
73
+ */
74
+ type ThemeMode = 'dark' | 'light';
75
+
76
+ interface AccentColors {
77
+ accent: string;
78
+ accentHover: string;
79
+ focusRingColor: string;
80
+ }
81
+ type NativeAccent = ThemeAccentPreset | `#${string}` | AccentColors;
82
+ type NumericTokens = {
83
+ [K in keyof typeof NUMERIC_TOKENS]: {
84
+ [P in keyof (typeof NUMERIC_TOKENS)[K]]: number;
85
+ };
86
+ };
87
+ type TokenOverrides = {
88
+ [K in keyof NumericTokens]?: Partial<NumericTokens[K]>;
89
+ };
90
+ interface NativeTheme extends NumericTokens {
91
+ mode: ThemeMode;
92
+ colors: AccentColors & {
93
+ surface: string;
94
+ surfaceHover: string;
95
+ text: string;
96
+ textMuted: string;
97
+ border: string;
98
+ borderStrong: string;
99
+ danger: string;
100
+ dangerHover: string;
101
+ success: string;
102
+ warning: string;
103
+ onDanger: string;
104
+ info: string;
105
+ onSemantic: string;
106
+ };
107
+ }
108
+ declare function resolveAccent(accent: NativeAccent): AccentColors;
109
+ declare function createTheme(mode?: ThemeMode, accent?: NativeAccent, tokens?: TokenOverrides): NativeTheme;
110
+ interface ThemeProviderProps {
111
+ children: ReactNode;
112
+ mode?: ThemeMode;
113
+ accent?: NativeAccent;
114
+ tokens?: TokenOverrides;
115
+ theme?: NativeTheme;
116
+ }
117
+ declare function ThemeProvider({ children, mode, accent, tokens, theme, }: ThemeProviderProps): react.JSX.Element;
118
+ declare function useTheme(): NativeTheme;
119
+
120
+ export { type AccentColors, NUMERIC_TOKENS, type NativeAccent, type NativeTheme, THEME_ACCENTS, type ThemeAccentPreset, type ThemeMode, ThemeProvider, type ThemeProviderProps, type TokenOverrides, createTheme, resolveAccent, useTheme };
@@ -0,0 +1,16 @@
1
+ import {
2
+ NUMERIC_TOKENS,
3
+ THEME_ACCENTS,
4
+ ThemeProvider,
5
+ createTheme,
6
+ resolveAccent,
7
+ useTheme
8
+ } from "./chunk-YJ4H3ZBQ.js";
9
+ export {
10
+ NUMERIC_TOKENS,
11
+ THEME_ACCENTS,
12
+ ThemeProvider,
13
+ createTheme,
14
+ resolveAccent,
15
+ useTheme
16
+ };
@@ -0,0 +1,41 @@
1
+ declare const BUTTON_SIZES: {
2
+ readonly small: {
3
+ readonly height: 30;
4
+ readonly padding: 11;
5
+ readonly fontSize: 12;
6
+ };
7
+ readonly medium: {
8
+ readonly height: 36;
9
+ readonly padding: 14;
10
+ readonly fontSize: 13;
11
+ };
12
+ readonly large: {
13
+ readonly height: 42;
14
+ readonly padding: 18;
15
+ readonly fontSize: 14;
16
+ };
17
+ };
18
+ declare const NUMERIC_TOKENS: {
19
+ readonly radius: {
20
+ readonly small: 6;
21
+ readonly medium: 8;
22
+ readonly large: 12;
23
+ };
24
+ readonly spacing: {
25
+ readonly buttonGap: 8;
26
+ readonly fieldGap: 7;
27
+ readonly fieldPadding: 11;
28
+ readonly panelPadding: 12;
29
+ };
30
+ readonly fontSize: {
31
+ readonly small: 12;
32
+ readonly medium: 13;
33
+ readonly large: 14;
34
+ };
35
+ readonly layer: {
36
+ readonly popover: 1000;
37
+ readonly menu: 1000;
38
+ };
39
+ };
40
+
41
+ export { BUTTON_SIZES as B, NUMERIC_TOKENS as N };
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@hamster-note/components",
3
- "version": "0.3.0",
3
+ "version": "0.4.0-beta.0",
4
4
  "description": "Reusable React components for HamsterNote products.",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "files": [
8
- "dist"
8
+ "dist",
9
+ "dist-native"
9
10
  ],
10
11
  "sideEffects": [
11
12
  "**/*.css"
@@ -15,58 +16,170 @@
15
16
  "types": "./dist/index.d.ts",
16
17
  "exports": {
17
18
  ".": {
19
+ "browser": {
20
+ "types": "./dist/index.d.ts",
21
+ "default": "./dist/index.js"
22
+ },
23
+ "react-native": {
24
+ "types": "./dist-native/index.d.ts",
25
+ "default": "./dist-native/index.js"
26
+ },
18
27
  "types": "./dist/index.d.ts",
19
28
  "import": "./dist/index.js"
20
29
  },
21
30
  "./button": {
31
+ "browser": {
32
+ "types": "./dist/button.d.ts",
33
+ "default": "./dist/button.js"
34
+ },
35
+ "react-native": {
36
+ "types": "./dist-native/button.d.ts",
37
+ "default": "./dist-native/button.js"
38
+ },
22
39
  "types": "./dist/button.d.ts",
23
40
  "import": "./dist/button.js"
24
41
  },
25
42
  "./icon": {
43
+ "browser": {
44
+ "types": "./dist/icon.d.ts",
45
+ "default": "./dist/icon.js"
46
+ },
47
+ "react-native": {
48
+ "types": "./dist-native/icon.d.ts",
49
+ "default": "./dist-native/icon.js"
50
+ },
26
51
  "types": "./dist/icon.d.ts",
27
52
  "import": "./dist/icon.js"
28
53
  },
29
54
  "./badge": {
55
+ "browser": {
56
+ "types": "./dist/badge.d.ts",
57
+ "default": "./dist/badge.js"
58
+ },
59
+ "react-native": {
60
+ "types": "./dist-native/badge.d.ts",
61
+ "default": "./dist-native/badge.js"
62
+ },
30
63
  "types": "./dist/badge.d.ts",
31
64
  "import": "./dist/badge.js"
32
65
  },
33
66
  "./confirm": {
67
+ "browser": {
68
+ "types": "./dist/confirm.d.ts",
69
+ "default": "./dist/confirm.js"
70
+ },
71
+ "react-native": {
72
+ "types": "./dist-native/confirm.d.ts",
73
+ "default": "./dist-native/confirm.js"
74
+ },
34
75
  "types": "./dist/confirm.d.ts",
35
76
  "import": "./dist/confirm.js"
36
77
  },
37
78
  "./dialog": {
79
+ "browser": {
80
+ "types": "./dist/dialog.d.ts",
81
+ "default": "./dist/dialog.js"
82
+ },
83
+ "react-native": {
84
+ "types": "./dist-native/dialog.d.ts",
85
+ "default": "./dist-native/dialog.js"
86
+ },
38
87
  "types": "./dist/dialog.d.ts",
39
88
  "import": "./dist/dialog.js"
40
89
  },
41
90
  "./drawer": {
91
+ "browser": {
92
+ "types": "./dist/drawer.d.ts",
93
+ "default": "./dist/drawer.js"
94
+ },
95
+ "react-native": {
96
+ "types": "./dist-native/drawer.d.ts",
97
+ "default": "./dist-native/drawer.js"
98
+ },
42
99
  "types": "./dist/drawer.d.ts",
43
100
  "import": "./dist/drawer.js"
44
101
  },
45
102
  "./kbd": {
103
+ "browser": {
104
+ "types": "./dist/kbd.d.ts",
105
+ "default": "./dist/kbd.js"
106
+ },
107
+ "react-native": {
108
+ "types": "./dist-native/kbd.d.ts",
109
+ "default": "./dist-native/kbd.js"
110
+ },
46
111
  "types": "./dist/kbd.d.ts",
47
112
  "import": "./dist/kbd.js"
48
113
  },
49
114
  "./loading": {
115
+ "browser": {
116
+ "types": "./dist/loading.d.ts",
117
+ "default": "./dist/loading.js"
118
+ },
119
+ "react-native": {
120
+ "types": "./dist-native/loading.d.ts",
121
+ "default": "./dist-native/loading.js"
122
+ },
50
123
  "types": "./dist/loading.d.ts",
51
124
  "import": "./dist/loading.js"
52
125
  },
53
126
  "./menu": {
127
+ "browser": {
128
+ "types": "./dist/menu.d.ts",
129
+ "default": "./dist/menu.js"
130
+ },
131
+ "react-native": {
132
+ "types": "./dist-native/menu.d.ts",
133
+ "default": "./dist-native/menu.js"
134
+ },
54
135
  "types": "./dist/menu.d.ts",
55
136
  "import": "./dist/menu.js"
56
137
  },
57
138
  "./note-card": {
139
+ "browser": {
140
+ "types": "./dist/note-card.d.ts",
141
+ "default": "./dist/note-card.js"
142
+ },
143
+ "react-native": {
144
+ "types": "./dist-native/note-card.d.ts",
145
+ "default": "./dist-native/note-card.js"
146
+ },
58
147
  "types": "./dist/note-card.d.ts",
59
148
  "import": "./dist/note-card.js"
60
149
  },
61
150
  "./popover": {
151
+ "browser": {
152
+ "types": "./dist/popover.d.ts",
153
+ "default": "./dist/popover.js"
154
+ },
155
+ "react-native": {
156
+ "types": "./dist-native/popover.d.ts",
157
+ "default": "./dist-native/popover.js"
158
+ },
62
159
  "types": "./dist/popover.d.ts",
63
160
  "import": "./dist/popover.js"
64
161
  },
65
162
  "./text-field": {
163
+ "browser": {
164
+ "types": "./dist/text-field.d.ts",
165
+ "default": "./dist/text-field.js"
166
+ },
167
+ "react-native": {
168
+ "types": "./dist-native/text-field.d.ts",
169
+ "default": "./dist-native/text-field.js"
170
+ },
66
171
  "types": "./dist/text-field.d.ts",
67
172
  "import": "./dist/text-field.js"
68
173
  },
69
174
  "./theme": {
175
+ "browser": {
176
+ "types": "./dist/theme.d.ts",
177
+ "default": "./dist/theme.js"
178
+ },
179
+ "react-native": {
180
+ "types": "./dist-native/theme.d.ts",
181
+ "default": "./dist-native/theme.js"
182
+ },
70
183
  "types": "./dist/theme.d.ts",
71
184
  "import": "./dist/theme.js"
72
185
  },
@@ -78,6 +191,7 @@
78
191
  "build:demo": "yarn typecheck && vite build",
79
192
  "preview": "vite preview --host 0.0.0.0 --port 9810 --strictPort",
80
193
  "test": "vitest run",
194
+ "test:native": "node --experimental-strip-types --test native/test/*.test.mjs",
81
195
  "test:coverage": "vitest run --coverage",
82
196
  "test:e2e": "playwright test",
83
197
  "test:e2e:update": "playwright test --update-snapshots",
@@ -85,11 +199,15 @@
85
199
  "lint": "eslint . --max-warnings 0",
86
200
  "format": "prettier --write .",
87
201
  "format:check": "prettier --check .",
88
- "check": "yarn typecheck && yarn lint && yarn format:check && yarn test"
202
+ "check": "yarn typecheck && yarn lint && yarn format:check && yarn test",
203
+ "build:native": "tsc -p tsconfig.native.json && tsup",
204
+ "build:package": "yarn build && yarn build:native"
89
205
  },
90
206
  "peerDependencies": {
91
207
  "react": "^19.0.0",
92
- "react-dom": "^19.0.0"
208
+ "react-dom": "^19.0.0",
209
+ "react-native": ">=0.86.3 <0.87.0",
210
+ "react-native-svg": "15.15.4"
93
211
  },
94
212
  "devDependencies": {
95
213
  "@eslint/js": "10.0.1",
@@ -111,6 +229,9 @@
111
229
  "prettier": "3.9.5",
112
230
  "react": "19.2.7",
113
231
  "react-dom": "19.2.7",
232
+ "react-native": "0.86.3",
233
+ "react-native-svg": "15.15.4",
234
+ "tsup": "8.5.0",
114
235
  "typescript": "6.0.3",
115
236
  "typescript-eslint": "8.64.0",
116
237
  "vite": "8.1.5",
@@ -120,5 +241,16 @@
120
241
  "engines": {
121
242
  "node": "^20.19.0 || >=22.12.0"
122
243
  },
123
- "packageManager": "yarn@1.22.22"
244
+ "packageManager": "yarn@1.22.22",
245
+ "peerDependenciesMeta": {
246
+ "react-dom": {
247
+ "optional": true
248
+ },
249
+ "react-native": {
250
+ "optional": true
251
+ },
252
+ "react-native-svg": {
253
+ "optional": true
254
+ }
255
+ }
124
256
  }