@hamsterbase/ui 0.0.0-stage → 0.2.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.
- package/dist/components/Button/Button.d.ts +9 -0
- package/dist/components/Button/styles.d.ts +14 -0
- package/dist/components/Checkbox/Checkbox.d.ts +5 -0
- package/dist/components/Checkbox/styles.d.ts +7 -0
- package/dist/components/Divider/Divider.d.ts +13 -0
- package/dist/components/Divider/styles.d.ts +11 -0
- package/dist/components/IconButton/IconButton.d.ts +11 -0
- package/dist/components/IconButton/styles.d.ts +12 -0
- package/dist/components/ResizeHandle/ResizeHandle.d.ts +17 -0
- package/dist/components/ResizeHandle/styles.d.ts +11 -0
- package/dist/components/Toast/Toast.d.ts +17 -0
- package/dist/components/Toast/ToastStore.d.ts +33 -0
- package/dist/components/Toast/Toaster.d.ts +7 -0
- package/dist/components/Toast/styles.d.ts +15 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +499 -0
- package/dist/styles.css +967 -0
- package/dist/utils/focus.d.ts +4 -0
- package/docs/Button.md +6 -0
- package/docs/Checkbox.md +7 -0
- package/docs/Divider.md +11 -0
- package/docs/IconButton.md +7 -0
- package/docs/ResizeHandle.md +19 -0
- package/docs/Toast.md +60 -0
- package/docs/index.md +19 -0
- package/package.json +50 -4
- package/README.md +0 -3
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** 元素自身获得键盘焦点时。 */
|
|
2
|
+
export declare const focusRing = "focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-hub-focus-ring";
|
|
3
|
+
/** 前一个兄弟节点(peer,如隐藏的原生 input)获得键盘焦点时。 */
|
|
4
|
+
export declare const peerFocusRing = "peer-focus-visible:outline-2 peer-focus-visible:outline-solid peer-focus-visible:outline-offset-2 peer-focus-visible:outline-hub-focus-ring";
|
package/docs/Button.md
ADDED
package/docs/Checkbox.md
ADDED
package/docs/Divider.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Divider
|
|
2
|
+
|
|
3
|
+
装饰性半像素分隔线,不进入无障碍树。支持原生 span 属性和 ref。
|
|
4
|
+
|
|
5
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
6
|
+
| --- | --- | --- | --- |
|
|
7
|
+
| orientation | `'horizontal' \| 'vertical'` | `'horizontal'` | 内联分隔线方向;垂直线在 flex 容器中自动拉伸。 |
|
|
8
|
+
| tone | `'default' \| 'subtle'` | `'default'` | 分隔线颜色强度:`default` 为正常颜色,`subtle` 将颜色透明度设为 50%。 |
|
|
9
|
+
| edge | `'top' \| 'bottom' \| 'left' \| 'right'` | — | 将分隔线固定在父容器的上、下、左或右边,不占布局空间。上、下边为横线,左、右边为竖线,此时 `orientation` 不生效。父容器需设置 `position: relative`。 |
|
|
10
|
+
| inset | `number` | `0` | 沿分隔线两端内缩的像素数。 |
|
|
11
|
+
| length | `number` | — | 固定长度(像素);默认填满可用空间,边界模式从内缩后的起点延伸。 |
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# IconButton
|
|
2
|
+
|
|
3
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
4
|
+
| --- | --- | --- | --- |
|
|
5
|
+
| variant | `'surface' \| 'ghost'` | `'surface'` | surface 带描边与轻阴影;ghost 透明、无边框,与 Button 的 ghost 含义一致。 |
|
|
6
|
+
| size | `'sm' \| 'md' \| 'lg'` | `'md'` | 按钮尺寸分别为 24、28、32px;内部 SVG 尺寸分别为 14、14、16px。 |
|
|
7
|
+
| pressed | `boolean` | `undefined` | 受控选中状态,内部映射为 `aria-pressed`。不传时为普通按钮;点击不会自动修改状态。 |
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# ResizeHandle
|
|
2
|
+
|
|
3
|
+
受控面板调宽手柄,组合 Divider 显示边界。放在具有定位的面板内,由调用方把 value 应用到面板宽度并处理持久化。保留 7px 拖拽热区、半像素边界与跟随指针的渐变反馈。
|
|
4
|
+
|
|
5
|
+
支持原生 div 展示属性和 ref;交互事件由组件管理。label 和 controls 分别提供可访问名称和受控面板 id。←/→ 按 step 移动边界,Home/End 调至最小/最大值;提供 defaultValue 后可双击复位。所有交互输出都限制在 min/max 范围内。调用方应保证 min ≤ value ≤ max。
|
|
6
|
+
|
|
7
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
8
|
+
| --- | --- | --- | --- |
|
|
9
|
+
| label | `string` | 必填 | 手柄的可访问名称。 |
|
|
10
|
+
| controls | `string` | 必填 | 受控面板的 DOM id。 |
|
|
11
|
+
| value | `number` | 必填 | 当前面板宽度,单位像素。 |
|
|
12
|
+
| min | `number` | 必填 | 最小宽度。 |
|
|
13
|
+
| max | `number` | 必填 | 最大宽度。 |
|
|
14
|
+
| onChange | `(value: number) => void` | 必填 | 宽度变化回调。 |
|
|
15
|
+
| defaultValue | `number` | — | 双击复位宽度;不提供时不复位,不代表非受控初值。 |
|
|
16
|
+
| step | `number` | `16` | 每次按 ←/→ 移动的像素数。方向键移动的是边界:`edge='left'` 时按 → 宽度减小。 |
|
|
17
|
+
| showDivider | `boolean` | `true` | 是否显示静态分隔线,隐藏时仍保留交互反馈。 |
|
|
18
|
+
| inset | `number` | `0` | 手柄上下内缩像素数。 |
|
|
19
|
+
| edge | `'left' \| 'right'` | `'right'` | 面板的可拖动边界;左边界向左移动时增大宽度。 |
|
package/docs/Toast.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Toast
|
|
2
|
+
|
|
3
|
+
轻提示。包含三部分:`ToastStore` 保存状态,`Toaster` 订阅并渲染到右下角,`Toast` 是单张卡片。应用通常只创建一个 `ToastStore`,在根节点放一个 `Toaster`。
|
|
4
|
+
|
|
5
|
+
```tsx
|
|
6
|
+
const toasts = new ToastStore();
|
|
7
|
+
|
|
8
|
+
<Toaster store={toasts} closeLabel="关闭" aria-label="通知" />;
|
|
9
|
+
|
|
10
|
+
toasts.show({ message: '已复制', variant: 'success' });
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## ToastStore
|
|
14
|
+
|
|
15
|
+
不依赖 React 的状态容器。
|
|
16
|
+
|
|
17
|
+
| 成员 | 类型 | 说明 |
|
|
18
|
+
| --- | --- | --- |
|
|
19
|
+
| constructor | `(options?: { max?: number })` | `max` 为同时展示的最大条数,默认 `1`;超出时移除最早的一条。 |
|
|
20
|
+
| show | `(options: ToastOptions) => string` | 显示一条提示并返回 id。`message`、`description`、`variant` 都相同且双方都没有 `action` 时,不新增,而是刷新已有提示的计时并强调。 |
|
|
21
|
+
| dismiss | `(id?: string) => void` | 立即移除指定提示;不传 id 时移除全部。 |
|
|
22
|
+
| subscribe | `(listener: () => void) => () => void` | 订阅变化,返回取消订阅函数。 |
|
|
23
|
+
| getSnapshot | `() => readonly ToastItem[]` | 当前提示列表;内容不变时引用不变。 |
|
|
24
|
+
|
|
25
|
+
### ToastOptions
|
|
26
|
+
|
|
27
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
28
|
+
| --- | --- | --- | --- |
|
|
29
|
+
| message | `string` | 必填 | 主文案。 |
|
|
30
|
+
| description | `string` | `undefined` | 补充说明,最多显示两行。 |
|
|
31
|
+
| variant | `'info' \| 'success' \| 'error'` | `'info'` | 图标与语义。 |
|
|
32
|
+
| duration | `number` | `4000`,error 为 `8000` | 自动关闭的毫秒数;`0` 表示不自动关闭。 |
|
|
33
|
+
| action | `{ label: ReactNode; onClick: () => void \| Promise<void> }` | `undefined` | 操作按钮,见下方 Toast 的说明。 |
|
|
34
|
+
| onClose | `() => void` | `undefined` | 提示被移除后调用,包括超时、手动关闭、被新提示挤掉和 `dismiss`。 |
|
|
35
|
+
|
|
36
|
+
## Toaster
|
|
37
|
+
|
|
38
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
39
|
+
| --- | --- | --- | --- |
|
|
40
|
+
| store | `ToastStore` | 必填 | 要渲染的状态容器。 |
|
|
41
|
+
| closeLabel | `string` | 必填 | 每张卡片关闭按钮的无障碍名称。 |
|
|
42
|
+
|
|
43
|
+
没有提示时不渲染任何节点。容器为 `position: fixed`,位于右下角,`z-index` 取自 `--hub-z-toast`(默认 1500);其余属性透传到容器,可用 `style` 覆盖层级与位置(`--hub-z-toast` 是内部变量,不建议直接覆盖)。组件不使用 portal,祖先元素有 `transform` 等属性时需由应用自行挂到 `body`。
|
|
44
|
+
|
|
45
|
+
## Toast
|
|
46
|
+
|
|
47
|
+
单张卡片,不负责定位。直接使用时由调用方决定何时挂载和卸载。
|
|
48
|
+
|
|
49
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
50
|
+
| --- | --- | --- | --- |
|
|
51
|
+
| message | `ReactNode` | 必填 | 主文案。error 变体以 `role="alert"` 播报,其余为 `role="status"`。 |
|
|
52
|
+
| description | `ReactNode` | `undefined` | 补充说明,最多显示两行。 |
|
|
53
|
+
| variant | `'info' \| 'success' \| 'error'` | `'info'` | 图标与语义。 |
|
|
54
|
+
| action | `{ label: ReactNode; onClick: () => void \| Promise<void> }` | `undefined` | 操作按钮。`onClick` 返回 Promise 时,等待期间禁用按钮并暂停计时;成功后关闭;失败(抛出异常或 Promise 被拒绝)后保持打开、恢复按钮并重新计时,异常不会被捕获,错误提示由调用方在 `onClick` 内自行处理。 |
|
|
55
|
+
| duration | `number` | `4000`,error 为 `8000` | 自动关闭的毫秒数;`0` 表示不自动关闭。鼠标悬停或焦点在卡片内时暂停。 |
|
|
56
|
+
| revision | `number` | `0` | 数值变化时重新计时并播放强调动画。 |
|
|
57
|
+
| closeLabel | `string` | 必填 | 关闭按钮的无障碍名称。 |
|
|
58
|
+
| onDismiss | `() => void` | 必填 | 退出动画结束后调用,调用方应在此时卸载组件。 |
|
|
59
|
+
|
|
60
|
+
`className`、`ref` 和其余属性落在最外层的动画容器上。
|
package/docs/index.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @hamsterbase/ui
|
|
2
|
+
|
|
3
|
+
React 19 组件库。引入组件及样式即可使用,无需配置 Tailwind。
|
|
4
|
+
|
|
5
|
+
```tsx
|
|
6
|
+
import { Button } from '@hamsterbase/ui';
|
|
7
|
+
import '@hamsterbase/ui/styles.css';
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
样式不包含全局 reset。可在应用根节点或局部容器覆盖 `--hub-*` CSS 变量来调整主题。
|
|
11
|
+
|
|
12
|
+
## 组件文档
|
|
13
|
+
|
|
14
|
+
- [Button](./Button.md)
|
|
15
|
+
- [Checkbox](./Checkbox.md)
|
|
16
|
+
- [Divider](./Divider.md)
|
|
17
|
+
- [IconButton](./IconButton.md)
|
|
18
|
+
- [ResizeHandle](./ResizeHandle.md)
|
|
19
|
+
- [Toast](./Toast.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hamsterbase/ui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"files": [
|
|
5
|
+
"dist",
|
|
6
|
+
"docs",
|
|
7
|
+
"!dist/playground"
|
|
8
|
+
],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"sideEffects": [
|
|
11
|
+
"**/*.css"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./styles.css": "./dist/styles.css",
|
|
19
|
+
"./docs/*": "./docs/*"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@tailwindcss/vite": "4.3.4",
|
|
23
|
+
"@types/node": "^24.19.2",
|
|
24
|
+
"@types/react": "19.2.17",
|
|
25
|
+
"@types/react-dom": "^19.2.7",
|
|
26
|
+
"react": "19.2.8",
|
|
27
|
+
"tailwindcss": "4.3.4",
|
|
28
|
+
"typescript": "~6.0.3",
|
|
29
|
+
"vite": "8.3.5"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"react": "^19.0.0"
|
|
33
|
+
},
|
|
34
|
+
"packageManager": "pnpm@10.14.0",
|
|
35
|
+
"scripts": {
|
|
36
|
+
"dev": "pnpm --filter @hamsterbase/ui-playground exec vite --host 0.0.0.0",
|
|
37
|
+
"build": "vite build && tsc -p tsconfig.build.json && node scripts/finalize-build.mjs",
|
|
38
|
+
"check": "tsc -p tsconfig.json",
|
|
39
|
+
"build:playground": "pnpm --filter @hamsterbase/ui-playground exec vite build",
|
|
40
|
+
"prepack": "pnpm build"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"clsx": "^2.1.1",
|
|
44
|
+
"lucide-react": "^1.68.0"
|
|
45
|
+
},
|
|
46
|
+
"main": "./dist/index.js",
|
|
47
|
+
"types": "./dist/index.d.ts",
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public",
|
|
50
|
+
"registry": "https://registry.npmjs.org/"
|
|
51
|
+
}
|
|
52
|
+
}
|
package/README.md
DELETED