@ahomeyonglin/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/AGENTS.md +72 -0
- package/LICENSE +21 -0
- package/dist/components/Badge/Badge.css +43 -0
- package/dist/components/Badge/Badge.d.ts +8 -0
- package/dist/components/Badge/Badge.js +5 -0
- package/dist/components/Button/Button.css +70 -0
- package/dist/components/Button/Button.d.ts +11 -0
- package/dist/components/Button/Button.js +5 -0
- package/dist/components/Card/Card.css +8 -0
- package/dist/components/Card/Card.d.ts +6 -0
- package/dist/components/Card/Card.js +5 -0
- package/dist/components/Text/Text.css +63 -0
- package/dist/components/Text/Text.d.ts +11 -0
- package/dist/components/Text/Text.js +5 -0
- package/dist/components/TextField/TextField.css +66 -0
- package/dist/components/TextField/TextField.d.ts +16 -0
- package/dist/components/TextField/TextField.js +11 -0
- package/package.json +57 -4
- package/registry.json +281 -0
- package/README.md +0 -3
package/AGENTS.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# AGENTS.md — @ahomeyonglin/ui 组件使用与新增规则
|
|
2
|
+
|
|
3
|
+
本文件约束 `packages/ui` 内的所有工作。根目录 `AGENTS.md` 的规则同样有效,冲突时以本文件为准(更具体)。
|
|
4
|
+
|
|
5
|
+
## 1. 定位
|
|
6
|
+
|
|
7
|
+
组件库的核心产物不是代码,而是**可被 AI 检索的能力清单**。代码能用但 `registry.json` 里查不到,等于组件不存在。
|
|
8
|
+
|
|
9
|
+
## 2. 必读顺序
|
|
10
|
+
|
|
11
|
+
写任何组件代码之前,按顺序读:
|
|
12
|
+
|
|
13
|
+
1. `registry.json` —— 现有组件、props、可用变体
|
|
14
|
+
2. 目标组件的 `component.meta.json` —— 精确的 API 与依赖 token
|
|
15
|
+
3. 根 `specs/tech-stack.md §4` —— 目录与命名约定
|
|
16
|
+
|
|
17
|
+
**不要跳过第 1 步直接写代码。** 需要的能力可能已有组件,也可能只差一个变体。
|
|
18
|
+
|
|
19
|
+
## 3. 目录结构
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
src/components/<PascalCase>/
|
|
23
|
+
├── <PascalCase>.tsx
|
|
24
|
+
├── <PascalCase>.css # 只引用语义 token 变量
|
|
25
|
+
└── component.meta.json # 名称、props、变体、依赖的 token
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
- 目录与文件一律 PascalCase,一个组件一个目录,不建 `index.ts` 桶文件。
|
|
29
|
+
- `component.meta.json` 与实现同目录,不允许集中放在别处。
|
|
30
|
+
- 组件间不互相 import 实现细节;共享逻辑抽到 `src/lib`,不抽公共组件(除非已有 registry 条目)。
|
|
31
|
+
|
|
32
|
+
## 4. 硬规则
|
|
33
|
+
|
|
34
|
+
1. 只使用 `registry.json` 中存在的组件;缺能力时先补组件,不要在页面里内联实现。
|
|
35
|
+
2. 样式只引用语义 token 变量,禁止 hex、禁止写死 px 间距与圆角。
|
|
36
|
+
3. 禁止直接引用 core 层(`raw.color.red.500` 这类),只用 `semantic` / `comp`。
|
|
37
|
+
4. 禁止手改 `registry.json`;改动后运行 `pnpm --filter @ahomeyonglin/ui build:registry`。
|
|
38
|
+
5. 组件不承载业务逻辑,不发起请求,不含文案常量。
|
|
39
|
+
6. 变体只做真实存在的需求,不预埋 `size="xl"` 这类无人使用的取值。
|
|
40
|
+
7. 禁止消费带 `$deprecated` 的 token;lint 同时检查组件样式与 `component.meta.json`。
|
|
41
|
+
|
|
42
|
+
## 5. 新增组件的流程
|
|
43
|
+
|
|
44
|
+
按 `.trae/skills/component-sync/SKILL.md` 执行,不要凭经验自由发挥。最少包含:
|
|
45
|
+
|
|
46
|
+
1. 确认 registry 中确实没有可复用能力
|
|
47
|
+
2. 建目录与三个文件
|
|
48
|
+
3. 写实现与样式(只用 token 变量)
|
|
49
|
+
4. 写 `component.meta.json`,字段齐全,`$description` 写清「什么时候用」
|
|
50
|
+
5. 重新生成 `registry.json` 并检查 diff 是否只包含预期变更
|
|
51
|
+
6. 跑 lint,确认没有硬编码值与 `raw` token 引用
|
|
52
|
+
|
|
53
|
+
## 6. registry.json 规则
|
|
54
|
+
|
|
55
|
+
- 由脚本生成,**生成后提交入库**,与代码同版本可追溯。
|
|
56
|
+
- 字段与排序固定,保证 diff 稳定;排序变化视为脚本 bug,不是内容变更。
|
|
57
|
+
- CI 会用 `git diff --exit-code` 校验漂移,本地忘记重新生成会直接失败。
|
|
58
|
+
- 新增组件的描述文字写给 AI 看:说清使用场景,而不是外观。
|
|
59
|
+
|
|
60
|
+
## 7. 不要做
|
|
61
|
+
|
|
62
|
+
- 不要在组件里写死任何视觉值,哪怕只出现一次。
|
|
63
|
+
- 不要引入第三方 UI 库来「省事」。
|
|
64
|
+
- 不要新增文档说明组件怎么用——用法属于 `registry.json` 与 `component.meta.json`。
|
|
65
|
+
- 不要为了让某个页面好看而单独定制某个组件;那是变体或新组件的决策,需要先确认。
|
|
66
|
+
|
|
67
|
+
## 8. 发布产物与下游接入
|
|
68
|
+
|
|
69
|
+
- 发布内容来自 `pnpm --filter @ahomeyonglin/ui build` 生成的 `dist`;`dist` 不入库,不手改。
|
|
70
|
+
- 新增组件时同步 `package.json` 的 `exports`:`"./<PascalCase>"` 的 `types` 指向 `dist/components/<PascalCase>/<PascalCase>.d.ts`,`default` 指向同名 `.js`。
|
|
71
|
+
- 下游安装后必须自行引入 tokens 的 CSS,顺序为 `theme-light.css` → `theme-dark.css` → `brand-*.css`。
|
|
72
|
+
- `ui` 不声明对 `tokens` 的依赖;缺 CSS 时组件不报错但会失去颜色,这是预期行为。
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ahomeyonglin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
.ds-badge {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
padding: var(--semantic-space-inline-sm) var(--semantic-space-inset-sm);
|
|
5
|
+
border-width: 1px;
|
|
6
|
+
border-style: solid;
|
|
7
|
+
border-radius: var(--semantic-radius-pill);
|
|
8
|
+
font-family: var(--semantic-text-label-md-font-family);
|
|
9
|
+
font-size: var(--semantic-text-label-md-font-size);
|
|
10
|
+
font-weight: var(--semantic-text-label-md-font-weight);
|
|
11
|
+
line-height: var(--semantic-text-label-md-line-height);
|
|
12
|
+
white-space: nowrap;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.ds-badge[data-tone='neutral'] {
|
|
16
|
+
color: var(--semantic-color-text-secondary);
|
|
17
|
+
background: var(--semantic-color-bg-subtle);
|
|
18
|
+
border-color: var(--semantic-color-border-default);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.ds-badge[data-tone='info'] {
|
|
22
|
+
color: var(--semantic-color-status-info-text);
|
|
23
|
+
background: var(--semantic-color-status-info-bg);
|
|
24
|
+
border-color: var(--semantic-color-status-info-border);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.ds-badge[data-tone='success'] {
|
|
28
|
+
color: var(--semantic-color-status-success-text);
|
|
29
|
+
background: var(--semantic-color-status-success-bg);
|
|
30
|
+
border-color: var(--semantic-color-status-success-border);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.ds-badge[data-tone='warning'] {
|
|
34
|
+
color: var(--semantic-color-status-warning-text);
|
|
35
|
+
background: var(--semantic-color-status-warning-bg);
|
|
36
|
+
border-color: var(--semantic-color-status-warning-border);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.ds-badge[data-tone='danger'] {
|
|
40
|
+
color: var(--semantic-color-status-danger-text);
|
|
41
|
+
background: var(--semantic-color-status-danger-bg);
|
|
42
|
+
border-color: var(--semantic-color-status-danger-border);
|
|
43
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import './Badge.css';
|
|
3
|
+
export type BadgeTone = 'neutral' | 'info' | 'success' | 'warning' | 'danger';
|
|
4
|
+
export type BadgeProps = {
|
|
5
|
+
tone?: BadgeTone;
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
};
|
|
8
|
+
export declare function Badge({ tone, children }: BadgeProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
.ds-button {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
justify-content: center;
|
|
5
|
+
padding: var(--semantic-space-inset-sm) var(--semantic-space-inset-lg);
|
|
6
|
+
border-width: 1px;
|
|
7
|
+
border-style: solid;
|
|
8
|
+
border-radius: var(--semantic-radius-control);
|
|
9
|
+
font-family: var(--semantic-text-label-md-font-family);
|
|
10
|
+
font-size: var(--semantic-text-label-md-font-size);
|
|
11
|
+
font-weight: var(--semantic-text-label-md-font-weight);
|
|
12
|
+
line-height: var(--semantic-text-label-md-line-height);
|
|
13
|
+
cursor: pointer;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.ds-button:focus-visible {
|
|
17
|
+
outline-width: 2px;
|
|
18
|
+
outline-style: solid;
|
|
19
|
+
outline-color: var(--semantic-color-border-focus);
|
|
20
|
+
outline-offset: 2px;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.ds-button[data-variant='primary'] {
|
|
24
|
+
color: var(--semantic-color-action-primary-text);
|
|
25
|
+
background: var(--semantic-color-action-primary-bg);
|
|
26
|
+
border-color: var(--semantic-color-action-primary-border);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.ds-button[data-variant='primary']:not(:disabled):hover {
|
|
30
|
+
background: var(--semantic-color-action-primary-bg-hover);
|
|
31
|
+
border-color: var(--semantic-color-action-primary-border-hover);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.ds-button[data-variant='primary']:disabled {
|
|
35
|
+
color: var(--semantic-color-text-disabled);
|
|
36
|
+
background: var(--semantic-color-action-primary-bg-disabled);
|
|
37
|
+
border-color: var(--semantic-color-action-primary-border-disabled);
|
|
38
|
+
cursor: not-allowed;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.ds-button[data-variant='secondary'] {
|
|
42
|
+
color: var(--semantic-color-action-secondary-text);
|
|
43
|
+
background: var(--semantic-color-action-secondary-bg);
|
|
44
|
+
border-color: var(--semantic-color-action-secondary-border);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.ds-button[data-variant='secondary']:not(:disabled):hover {
|
|
48
|
+
background: var(--semantic-color-action-secondary-bg-hover);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.ds-button[data-variant='secondary']:disabled {
|
|
52
|
+
color: var(--semantic-color-text-disabled);
|
|
53
|
+
border-color: var(--semantic-color-action-secondary-border-disabled);
|
|
54
|
+
cursor: not-allowed;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.ds-button[data-variant='ghost'] {
|
|
58
|
+
color: var(--semantic-color-action-ghost-text);
|
|
59
|
+
background: var(--semantic-color-action-ghost-bg);
|
|
60
|
+
border-color: var(--semantic-color-action-ghost-border);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.ds-button[data-variant='ghost']:not(:disabled):hover {
|
|
64
|
+
background: var(--semantic-color-action-ghost-bg-hover);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.ds-button[data-variant='ghost']:disabled {
|
|
68
|
+
color: var(--semantic-color-text-disabled);
|
|
69
|
+
cursor: not-allowed;
|
|
70
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import './Button.css';
|
|
3
|
+
export type ButtonVariant = 'primary' | 'secondary' | 'ghost';
|
|
4
|
+
export type ButtonProps = {
|
|
5
|
+
variant?: ButtonVariant;
|
|
6
|
+
type?: 'button' | 'submit' | 'reset';
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
onClick?: () => void;
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
};
|
|
11
|
+
export declare function Button({ variant, type, disabled, onClick, children, }: ButtonProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import './Button.css';
|
|
3
|
+
export function Button({ variant = 'primary', type = 'button', disabled = false, onClick, children, }) {
|
|
4
|
+
return (_jsx("button", { className: "ds-button", "data-variant": variant, type: type, disabled: disabled, onClick: onClick, children: children }));
|
|
5
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
.ds-text {
|
|
2
|
+
color: var(--semantic-color-text-primary);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.ds-text[data-tone='secondary'] {
|
|
6
|
+
color: var(--semantic-color-text-secondary);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.ds-text[data-tone='tertiary'] {
|
|
10
|
+
color: var(--semantic-color-text-tertiary);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.ds-text[data-tone='disabled'] {
|
|
14
|
+
color: var(--semantic-color-text-disabled);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.ds-text[data-variant='display.lg'] {
|
|
18
|
+
font-family: var(--semantic-text-display-lg-font-family);
|
|
19
|
+
font-size: var(--semantic-text-display-lg-font-size);
|
|
20
|
+
font-weight: var(--semantic-text-display-lg-font-weight);
|
|
21
|
+
line-height: var(--semantic-text-display-lg-line-height);
|
|
22
|
+
letter-spacing: var(--semantic-text-display-lg-letter-spacing);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.ds-text[data-variant='heading.md'] {
|
|
26
|
+
font-family: var(--semantic-text-heading-md-font-family);
|
|
27
|
+
font-size: var(--semantic-text-heading-md-font-size);
|
|
28
|
+
font-weight: var(--semantic-text-heading-md-font-weight);
|
|
29
|
+
line-height: var(--semantic-text-heading-md-line-height);
|
|
30
|
+
letter-spacing: var(--semantic-text-heading-md-letter-spacing);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.ds-text[data-variant='body.md'] {
|
|
34
|
+
font-family: var(--semantic-text-body-md-font-family);
|
|
35
|
+
font-size: var(--semantic-text-body-md-font-size);
|
|
36
|
+
font-weight: var(--semantic-text-body-md-font-weight);
|
|
37
|
+
line-height: var(--semantic-text-body-md-line-height);
|
|
38
|
+
letter-spacing: var(--semantic-text-body-md-letter-spacing);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.ds-text[data-variant='body.sm'] {
|
|
42
|
+
font-family: var(--semantic-text-body-sm-font-family);
|
|
43
|
+
font-size: var(--semantic-text-body-sm-font-size);
|
|
44
|
+
font-weight: var(--semantic-text-body-sm-font-weight);
|
|
45
|
+
line-height: var(--semantic-text-body-sm-line-height);
|
|
46
|
+
letter-spacing: var(--semantic-text-body-sm-letter-spacing);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.ds-text[data-variant='label.md'] {
|
|
50
|
+
font-family: var(--semantic-text-label-md-font-family);
|
|
51
|
+
font-size: var(--semantic-text-label-md-font-size);
|
|
52
|
+
font-weight: var(--semantic-text-label-md-font-weight);
|
|
53
|
+
line-height: var(--semantic-text-label-md-line-height);
|
|
54
|
+
letter-spacing: var(--semantic-text-label-md-letter-spacing);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.ds-text[data-variant='code.md'] {
|
|
58
|
+
font-family: var(--semantic-text-code-md-font-family);
|
|
59
|
+
font-size: var(--semantic-text-code-md-font-size);
|
|
60
|
+
font-weight: var(--semantic-text-code-md-font-weight);
|
|
61
|
+
line-height: var(--semantic-text-code-md-line-height);
|
|
62
|
+
letter-spacing: var(--semantic-text-code-md-letter-spacing);
|
|
63
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import './Text.css';
|
|
3
|
+
export type TextVariant = 'display.lg' | 'heading.md' | 'body.md' | 'body.sm' | 'label.md' | 'code.md';
|
|
4
|
+
export type TextTone = 'primary' | 'secondary' | 'tertiary' | 'disabled';
|
|
5
|
+
export type TextProps = {
|
|
6
|
+
variant?: TextVariant;
|
|
7
|
+
tone?: TextTone;
|
|
8
|
+
as?: 'span' | 'p' | 'h1' | 'h2' | 'h3';
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
};
|
|
11
|
+
export declare function Text({ variant, tone, as: Element, children, }: TextProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import './Text.css';
|
|
3
|
+
export function Text({ variant = 'body.md', tone = 'primary', as: Element = 'span', children, }) {
|
|
4
|
+
return (_jsx(Element, { className: "ds-text", "data-variant": variant, "data-tone": tone, children: children }));
|
|
5
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
.ds-text-field {
|
|
2
|
+
display: grid;
|
|
3
|
+
gap: var(--semantic-space-stack-sm);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.ds-text-field__label {
|
|
7
|
+
color: var(--semantic-color-text-primary);
|
|
8
|
+
font-family: var(--semantic-text-label-md-font-family);
|
|
9
|
+
font-size: var(--semantic-text-label-md-font-size);
|
|
10
|
+
font-weight: var(--semantic-text-label-md-font-weight);
|
|
11
|
+
line-height: var(--semantic-text-label-md-line-height);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.ds-text-field__input {
|
|
15
|
+
box-sizing: border-box;
|
|
16
|
+
width: 100%;
|
|
17
|
+
padding: var(--semantic-space-inset-sm) var(--semantic-space-inset-md);
|
|
18
|
+
color: var(--semantic-color-text-primary);
|
|
19
|
+
background: var(--semantic-color-bg-surface);
|
|
20
|
+
border-width: 1px;
|
|
21
|
+
border-style: solid;
|
|
22
|
+
border-color: var(--semantic-color-border-strong);
|
|
23
|
+
border-radius: var(--semantic-radius-control);
|
|
24
|
+
font-family: var(--semantic-text-body-md-font-family);
|
|
25
|
+
font-size: var(--semantic-text-body-md-font-size);
|
|
26
|
+
font-weight: var(--semantic-text-body-md-font-weight);
|
|
27
|
+
line-height: var(--semantic-text-body-md-line-height);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.ds-text-field__input::placeholder {
|
|
31
|
+
color: var(--semantic-color-text-tertiary);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.ds-text-field__input:focus-visible {
|
|
35
|
+
border-color: var(--semantic-color-border-strong);
|
|
36
|
+
border-bottom-color: var(--semantic-color-border-focus);
|
|
37
|
+
border-bottom-width: 2px;
|
|
38
|
+
outline: none;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.ds-text-field__input[aria-invalid='true'] {
|
|
42
|
+
border-color: var(--semantic-color-border-invalid);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.ds-text-field__input:disabled {
|
|
46
|
+
color: var(--semantic-color-text-disabled);
|
|
47
|
+
background: var(--semantic-color-bg-subtle);
|
|
48
|
+
border-color: var(--semantic-color-border-default);
|
|
49
|
+
cursor: not-allowed;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.ds-text-field__description {
|
|
53
|
+
color: var(--semantic-color-text-tertiary);
|
|
54
|
+
font-family: var(--semantic-text-body-sm-font-family);
|
|
55
|
+
font-size: var(--semantic-text-body-sm-font-size);
|
|
56
|
+
font-weight: var(--semantic-text-body-sm-font-weight);
|
|
57
|
+
line-height: var(--semantic-text-body-sm-line-height);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.ds-text-field__error {
|
|
61
|
+
color: var(--semantic-color-status-danger-text);
|
|
62
|
+
font-family: var(--semantic-text-body-sm-font-family);
|
|
63
|
+
font-size: var(--semantic-text-body-sm-font-size);
|
|
64
|
+
font-weight: var(--semantic-text-body-sm-font-weight);
|
|
65
|
+
line-height: var(--semantic-text-body-sm-line-height);
|
|
66
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import './TextField.css';
|
|
2
|
+
export type TextFieldType = 'text' | 'password' | 'email' | 'number' | 'search' | 'tel' | 'url';
|
|
3
|
+
export type TextFieldProps = {
|
|
4
|
+
label: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
error?: string;
|
|
7
|
+
type?: TextFieldType;
|
|
8
|
+
value: string;
|
|
9
|
+
onChange: (value: string) => void;
|
|
10
|
+
placeholder?: string;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
required?: boolean;
|
|
13
|
+
name?: string;
|
|
14
|
+
id?: string;
|
|
15
|
+
};
|
|
16
|
+
export declare function TextField({ label, description, error, type, value, onChange, placeholder, disabled, required, name, id, }: TextFieldProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId } from 'react';
|
|
3
|
+
import './TextField.css';
|
|
4
|
+
export function TextField({ label, description, error, type = 'text', value, onChange, placeholder, disabled = false, required = false, name, id, }) {
|
|
5
|
+
const generatedId = useId();
|
|
6
|
+
const inputId = id ?? generatedId;
|
|
7
|
+
const descriptionId = `${inputId}-description`;
|
|
8
|
+
const errorId = `${inputId}-error`;
|
|
9
|
+
const describedBy = error ? errorId : description ? descriptionId : undefined;
|
|
10
|
+
return (_jsxs("div", { className: "ds-text-field", children: [_jsx("label", { className: "ds-text-field__label", htmlFor: inputId, children: label }), _jsx("input", { className: "ds-text-field__input", id: inputId, type: type, value: value, onChange: (event) => onChange(event.target.value), placeholder: placeholder, disabled: disabled, required: required, name: name, "aria-invalid": error ? true : undefined, "aria-describedby": describedBy }), error ? (_jsx("span", { className: "ds-text-field__error", id: errorId, children: error })) : description ? (_jsx("span", { className: "ds-text-field__description", id: descriptionId, children: description })) : null] }));
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ahomeyonglin/ui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": [
|
|
7
|
+
"**/*.css"
|
|
8
|
+
],
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"registry.json",
|
|
12
|
+
"AGENTS.md"
|
|
13
|
+
],
|
|
14
|
+
"exports": {
|
|
15
|
+
"./Badge": {
|
|
16
|
+
"types": "./dist/components/Badge/Badge.d.ts",
|
|
17
|
+
"default": "./dist/components/Badge/Badge.js"
|
|
18
|
+
},
|
|
19
|
+
"./Button": {
|
|
20
|
+
"types": "./dist/components/Button/Button.d.ts",
|
|
21
|
+
"default": "./dist/components/Button/Button.js"
|
|
22
|
+
},
|
|
23
|
+
"./Card": {
|
|
24
|
+
"types": "./dist/components/Card/Card.d.ts",
|
|
25
|
+
"default": "./dist/components/Card/Card.js"
|
|
26
|
+
},
|
|
27
|
+
"./Text": {
|
|
28
|
+
"types": "./dist/components/Text/Text.d.ts",
|
|
29
|
+
"default": "./dist/components/Text/Text.js"
|
|
30
|
+
},
|
|
31
|
+
"./TextField": {
|
|
32
|
+
"types": "./dist/components/TextField/TextField.d.ts",
|
|
33
|
+
"default": "./dist/components/TextField/TextField.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/Ahomeyonglin/design-system.git",
|
|
42
|
+
"directory": "packages/ui"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "node scripts/build.mjs",
|
|
46
|
+
"typecheck": "tsc --noEmit",
|
|
47
|
+
"build:registry": "node scripts/build-registry.mjs",
|
|
48
|
+
"lint": "node scripts/lint-components.mjs",
|
|
49
|
+
"test": "node --test --test-concurrency=1 tests/"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"react": "^19"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@types/react": "^19.3.0",
|
|
56
|
+
"react": "^19.3.1",
|
|
57
|
+
"typescript": "^7.0.2"
|
|
58
|
+
}
|
|
59
|
+
}
|
package/registry.json
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"generatedFrom": "src/components/*/component.meta.json",
|
|
4
|
+
"components": [
|
|
5
|
+
{
|
|
6
|
+
"id": "Badge",
|
|
7
|
+
"name": "Badge",
|
|
8
|
+
"category": "marker",
|
|
9
|
+
"importPath": "@ahomeyonglin/ui/Badge",
|
|
10
|
+
"$description": "用于表达状态或分类的静态标记。",
|
|
11
|
+
"props": [
|
|
12
|
+
{
|
|
13
|
+
"name": "tone",
|
|
14
|
+
"type": "\"neutral\" | \"info\" | \"success\" | \"warning\" | \"danger\"",
|
|
15
|
+
"required": false,
|
|
16
|
+
"defaultValue": "\"neutral\"",
|
|
17
|
+
"description": "状态语义。"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"name": "children",
|
|
21
|
+
"type": "ReactNode",
|
|
22
|
+
"required": true,
|
|
23
|
+
"description": "标记文字。"
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
"tokens": [
|
|
27
|
+
"semantic.color.bg.subtle",
|
|
28
|
+
"semantic.color.border.default",
|
|
29
|
+
"semantic.color.status.danger.bg",
|
|
30
|
+
"semantic.color.status.danger.border",
|
|
31
|
+
"semantic.color.status.danger.text",
|
|
32
|
+
"semantic.color.status.info.bg",
|
|
33
|
+
"semantic.color.status.info.border",
|
|
34
|
+
"semantic.color.status.info.text",
|
|
35
|
+
"semantic.color.status.success.bg",
|
|
36
|
+
"semantic.color.status.success.border",
|
|
37
|
+
"semantic.color.status.success.text",
|
|
38
|
+
"semantic.color.status.warning.bg",
|
|
39
|
+
"semantic.color.status.warning.border",
|
|
40
|
+
"semantic.color.status.warning.text",
|
|
41
|
+
"semantic.color.text.secondary",
|
|
42
|
+
"semantic.radius.pill",
|
|
43
|
+
"semantic.space.inline.sm",
|
|
44
|
+
"semantic.space.inset.sm",
|
|
45
|
+
"semantic.text.label.md"
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"id": "Button",
|
|
50
|
+
"name": "Button",
|
|
51
|
+
"category": "action",
|
|
52
|
+
"importPath": "@ahomeyonglin/ui/Button",
|
|
53
|
+
"$description": "触发操作的按钮,用 primary / secondary / ghost 表达操作优先级。",
|
|
54
|
+
"props": [
|
|
55
|
+
{
|
|
56
|
+
"name": "variant",
|
|
57
|
+
"type": "\"primary\" | \"secondary\" | \"ghost\"",
|
|
58
|
+
"required": false,
|
|
59
|
+
"defaultValue": "\"primary\"",
|
|
60
|
+
"description": "操作优先级。"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"name": "type",
|
|
64
|
+
"type": "\"button\" | \"submit\" | \"reset\"",
|
|
65
|
+
"required": false,
|
|
66
|
+
"defaultValue": "\"button\"",
|
|
67
|
+
"description": "原生按钮类型。"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"name": "disabled",
|
|
71
|
+
"type": "boolean",
|
|
72
|
+
"required": false,
|
|
73
|
+
"defaultValue": "false",
|
|
74
|
+
"description": "禁用态。"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"name": "onClick",
|
|
78
|
+
"type": "() => void",
|
|
79
|
+
"required": false,
|
|
80
|
+
"description": "点击回调。"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"name": "children",
|
|
84
|
+
"type": "ReactNode",
|
|
85
|
+
"required": true,
|
|
86
|
+
"description": "按钮文字。"
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
"tokens": [
|
|
90
|
+
"semantic.color.action.ghost.bg",
|
|
91
|
+
"semantic.color.action.ghost.bg-hover",
|
|
92
|
+
"semantic.color.action.ghost.border",
|
|
93
|
+
"semantic.color.action.ghost.text",
|
|
94
|
+
"semantic.color.action.primary.bg",
|
|
95
|
+
"semantic.color.action.primary.bg-disabled",
|
|
96
|
+
"semantic.color.action.primary.bg-hover",
|
|
97
|
+
"semantic.color.action.primary.border",
|
|
98
|
+
"semantic.color.action.primary.border-disabled",
|
|
99
|
+
"semantic.color.action.primary.border-hover",
|
|
100
|
+
"semantic.color.action.primary.text",
|
|
101
|
+
"semantic.color.action.secondary.bg",
|
|
102
|
+
"semantic.color.action.secondary.bg-hover",
|
|
103
|
+
"semantic.color.action.secondary.border",
|
|
104
|
+
"semantic.color.action.secondary.border-disabled",
|
|
105
|
+
"semantic.color.action.secondary.text",
|
|
106
|
+
"semantic.color.border.focus",
|
|
107
|
+
"semantic.color.text.disabled",
|
|
108
|
+
"semantic.radius.control",
|
|
109
|
+
"semantic.space.inset.lg",
|
|
110
|
+
"semantic.space.inset.sm",
|
|
111
|
+
"semantic.text.label.md"
|
|
112
|
+
]
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"id": "Card",
|
|
116
|
+
"name": "Card",
|
|
117
|
+
"category": "container",
|
|
118
|
+
"importPath": "@ahomeyonglin/ui/Card",
|
|
119
|
+
"$description": "带描边的容器,用于把相关内容聚合成一个独立区块。",
|
|
120
|
+
"props": [
|
|
121
|
+
{
|
|
122
|
+
"name": "children",
|
|
123
|
+
"type": "ReactNode",
|
|
124
|
+
"required": true,
|
|
125
|
+
"description": "卡片内容。"
|
|
126
|
+
}
|
|
127
|
+
],
|
|
128
|
+
"tokens": [
|
|
129
|
+
"semantic.color.bg.surface",
|
|
130
|
+
"semantic.color.border.subtle",
|
|
131
|
+
"semantic.radius.surface",
|
|
132
|
+
"semantic.space.inset.lg"
|
|
133
|
+
]
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"id": "Text",
|
|
137
|
+
"name": "Text",
|
|
138
|
+
"category": "text",
|
|
139
|
+
"importPath": "@ahomeyonglin/ui/Text",
|
|
140
|
+
"$description": "承载排版组合与文字颜色的文本单元,用于标题、正文、标签与代码;不负责布局。",
|
|
141
|
+
"props": [
|
|
142
|
+
{
|
|
143
|
+
"name": "variant",
|
|
144
|
+
"type": "\"display.lg\" | \"heading.md\" | \"body.md\" | \"body.sm\" | \"label.md\" | \"code.md\"",
|
|
145
|
+
"required": false,
|
|
146
|
+
"defaultValue": "\"body.md\"",
|
|
147
|
+
"description": "对应 semantic.text.* 排版组合。"
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"name": "tone",
|
|
151
|
+
"type": "\"primary\" | \"secondary\" | \"tertiary\" | \"disabled\"",
|
|
152
|
+
"required": false,
|
|
153
|
+
"defaultValue": "\"primary\"",
|
|
154
|
+
"description": "文字强弱层级。"
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
"name": "as",
|
|
158
|
+
"type": "\"span\" | \"p\" | \"h1\" | \"h2\" | \"h3\"",
|
|
159
|
+
"required": false,
|
|
160
|
+
"defaultValue": "\"span\"",
|
|
161
|
+
"description": "渲染的语义标签。"
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
"name": "children",
|
|
165
|
+
"type": "ReactNode",
|
|
166
|
+
"required": true,
|
|
167
|
+
"description": "文本内容。"
|
|
168
|
+
}
|
|
169
|
+
],
|
|
170
|
+
"tokens": [
|
|
171
|
+
"semantic.color.text.disabled",
|
|
172
|
+
"semantic.color.text.primary",
|
|
173
|
+
"semantic.color.text.secondary",
|
|
174
|
+
"semantic.color.text.tertiary",
|
|
175
|
+
"semantic.text.body.md",
|
|
176
|
+
"semantic.text.body.sm",
|
|
177
|
+
"semantic.text.code.md",
|
|
178
|
+
"semantic.text.display.lg",
|
|
179
|
+
"semantic.text.heading.md",
|
|
180
|
+
"semantic.text.label.md"
|
|
181
|
+
]
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
"id": "TextField",
|
|
185
|
+
"name": "TextField",
|
|
186
|
+
"category": "form",
|
|
187
|
+
"importPath": "@ahomeyonglin/ui/TextField",
|
|
188
|
+
"$description": "带标签、帮助文本与错误提示的单行输入域,用于表单中的文本采集。",
|
|
189
|
+
"props": [
|
|
190
|
+
{
|
|
191
|
+
"name": "label",
|
|
192
|
+
"type": "string",
|
|
193
|
+
"required": true,
|
|
194
|
+
"description": "标签文字,渲染为 label[for]。"
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
"name": "description",
|
|
198
|
+
"type": "string",
|
|
199
|
+
"required": false,
|
|
200
|
+
"description": "帮助文本,error 存在时不显示。"
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
"name": "error",
|
|
204
|
+
"type": "string",
|
|
205
|
+
"required": false,
|
|
206
|
+
"description": "错误文案,存在时进入 invalid 状态。"
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
"name": "type",
|
|
210
|
+
"type": "\"text\" | \"password\" | \"email\" | \"number\" | \"search\" | \"tel\" | \"url\"",
|
|
211
|
+
"required": false,
|
|
212
|
+
"defaultValue": "\"text\"",
|
|
213
|
+
"description": "输入类型。"
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
"name": "value",
|
|
217
|
+
"type": "string",
|
|
218
|
+
"required": true,
|
|
219
|
+
"description": "受控值。"
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
"name": "onChange",
|
|
223
|
+
"type": "(value: string) => void",
|
|
224
|
+
"required": true,
|
|
225
|
+
"description": "值变化回调。"
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
"name": "placeholder",
|
|
229
|
+
"type": "string",
|
|
230
|
+
"required": false,
|
|
231
|
+
"description": "占位提示,不能替代标签。"
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
"name": "disabled",
|
|
235
|
+
"type": "boolean",
|
|
236
|
+
"required": false,
|
|
237
|
+
"defaultValue": "false",
|
|
238
|
+
"description": "禁用态。"
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
"name": "required",
|
|
242
|
+
"type": "boolean",
|
|
243
|
+
"required": false,
|
|
244
|
+
"defaultValue": "false",
|
|
245
|
+
"description": "透传原生 required,不渲染星号。"
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
"name": "name",
|
|
249
|
+
"type": "string",
|
|
250
|
+
"required": false,
|
|
251
|
+
"description": "表单字段名。"
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
"name": "id",
|
|
255
|
+
"type": "string",
|
|
256
|
+
"required": false,
|
|
257
|
+
"description": "输入框 id,未传时自动生成。"
|
|
258
|
+
}
|
|
259
|
+
],
|
|
260
|
+
"tokens": [
|
|
261
|
+
"semantic.color.bg.subtle",
|
|
262
|
+
"semantic.color.bg.surface",
|
|
263
|
+
"semantic.color.border.default",
|
|
264
|
+
"semantic.color.border.focus",
|
|
265
|
+
"semantic.color.border.invalid",
|
|
266
|
+
"semantic.color.border.strong",
|
|
267
|
+
"semantic.color.status.danger.text",
|
|
268
|
+
"semantic.color.text.disabled",
|
|
269
|
+
"semantic.color.text.primary",
|
|
270
|
+
"semantic.color.text.tertiary",
|
|
271
|
+
"semantic.radius.control",
|
|
272
|
+
"semantic.space.inset.md",
|
|
273
|
+
"semantic.space.inset.sm",
|
|
274
|
+
"semantic.space.stack.sm",
|
|
275
|
+
"semantic.text.body.md",
|
|
276
|
+
"semantic.text.body.sm",
|
|
277
|
+
"semantic.text.label.md"
|
|
278
|
+
]
|
|
279
|
+
}
|
|
280
|
+
]
|
|
281
|
+
}
|
package/README.md
DELETED