@seanyeh77/ui 0.47.0 → 0.47.1
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/bundle.js +2 -2
- package/dist/components/DataTable/DataTable.js +8 -2
- package/dist/components/DataTable/DataTable.js.map +1 -1
- package/dist/components/TextField/TextField.js +6 -0
- package/dist/components/TextField/TextField.js.map +1 -1
- package/docs/DataTable.md +1 -1
- package/docs/agents.md +5 -5
- package/package.json +2 -2
|
@@ -42,6 +42,12 @@ function TextField({ label, hideLabel, hint, error, id, className, required, dis
|
|
|
42
42
|
}),
|
|
43
43
|
/* @__PURE__ */ jsxs("div", {
|
|
44
44
|
className: cx("ui-field-box", affixed && "has-affix"),
|
|
45
|
+
onMouseDown: (e) => {
|
|
46
|
+
const box = e.currentTarget.querySelector("input");
|
|
47
|
+
if (!box || disabled || e.button !== 0 || e.target === box) return;
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
box.focus();
|
|
50
|
+
},
|
|
45
51
|
children: [
|
|
46
52
|
prefix ? /* @__PURE__ */ jsx("span", {
|
|
47
53
|
id: fieldId + "-pre",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextField.js","names":[],"sources":["../../../src/components/TextField/TextField.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cx } from '../../internal/util';\nimport { describedBy, FieldErrorIcon, FieldLabel, FieldMessage, type FieldProps } from '../../internal/Field';\n\nexport interface TextFieldProps\n extends FieldProps, Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange' | 'value' | 'name' | 'required' | 'disabled' | 'prefix'> {\n /** The text. */\n value?: string;\n /** Muted text inside the box before the value, e.g. 「NT$」 or 「https://」. */\n prefix?: string;\n /** Muted text inside the box at its end, e.g. 「元」 or 「.example.com」. */\n suffix?: string;\n /** The value's unit, muted, right after the typed text (「12 GB」), or after the placeholder while empty. */\n unit?: string;\n /** Receives the new text, then the native event: onChange={(v) => setName(v)}. */\n onChange?: (value: string, event: React.ChangeEvent<HTMLInputElement>) => void;\n /** The underlying <input>. */\n ref?: React.Ref<HTMLInputElement>;\n}\n\n/** A labelled one-line input with a hint or an error under it. */\nexport function TextField({ label, hideLabel, hint, error, id, className, required, disabled, onChange, prefix, suffix, unit, ...native }: TextFieldProps) {\n const auto = React.useId();\n const fieldId = id || auto;\n const msg = error ? fieldId + '-err' : hint ? fieldId + '-hint' : undefined;\n // Uncontrolled with a unit: the typed text, so the unit follows it.\n const [typed, setTyped] = React.useState(String(native.defaultValue ?? ''));\n const affixed = !!(prefix || suffix || unit);\n // Screen readers hear the prefix, suffix and unit with the field's description.\n const affixIds = [prefix && fieldId + '-pre', unit && fieldId + '-unit', suffix && fieldId + '-suf'];\n const input = (\n <input\n type=\"text\"\n {...native}\n required={required}\n disabled={disabled}\n id={fieldId}\n className=\"ui-input\"\n onChange={\n onChange || (unit && native.value === undefined)\n ? (e) => {\n if (unit && native.value === undefined) setTyped(e.target.value);\n onChange?.(e.target.value, e);\n }\n : undefined\n }\n aria-invalid={error ? true : native['aria-invalid']}\n // Your own description first, then the prefix, unit and suffix, then the hint or the error.\n aria-describedby={describedBy(native['aria-describedby'], ...affixIds, msg)}\n />\n );\n const shown = String(native.value ?? typed) || native.placeholder || '';\n return (\n <div className={cx('ui-field', error && 'has-error', disabled && 'is-disabled', className)}>\n <FieldLabel htmlFor={fieldId} required={required} hidden={hideLabel}>\n {label}\n </FieldLabel>\n <div
|
|
1
|
+
{"version":3,"file":"TextField.js","names":[],"sources":["../../../src/components/TextField/TextField.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cx } from '../../internal/util';\nimport { describedBy, FieldErrorIcon, FieldLabel, FieldMessage, type FieldProps } from '../../internal/Field';\n\nexport interface TextFieldProps\n extends FieldProps, Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange' | 'value' | 'name' | 'required' | 'disabled' | 'prefix'> {\n /** The text. */\n value?: string;\n /** Muted text inside the box before the value, e.g. 「NT$」 or 「https://」. */\n prefix?: string;\n /** Muted text inside the box at its end, e.g. 「元」 or 「.example.com」. */\n suffix?: string;\n /** The value's unit, muted, right after the typed text (「12 GB」), or after the placeholder while empty. */\n unit?: string;\n /** Receives the new text, then the native event: onChange={(v) => setName(v)}. */\n onChange?: (value: string, event: React.ChangeEvent<HTMLInputElement>) => void;\n /** The underlying <input>. */\n ref?: React.Ref<HTMLInputElement>;\n}\n\n/** A labelled one-line input with a hint or an error under it. */\nexport function TextField({ label, hideLabel, hint, error, id, className, required, disabled, onChange, prefix, suffix, unit, ...native }: TextFieldProps) {\n const auto = React.useId();\n const fieldId = id || auto;\n const msg = error ? fieldId + '-err' : hint ? fieldId + '-hint' : undefined;\n // Uncontrolled with a unit: the typed text, so the unit follows it.\n const [typed, setTyped] = React.useState(String(native.defaultValue ?? ''));\n const affixed = !!(prefix || suffix || unit);\n // Screen readers hear the prefix, suffix and unit with the field's description.\n const affixIds = [prefix && fieldId + '-pre', unit && fieldId + '-unit', suffix && fieldId + '-suf'];\n const input = (\n <input\n type=\"text\"\n {...native}\n required={required}\n disabled={disabled}\n id={fieldId}\n className=\"ui-input\"\n onChange={\n onChange || (unit && native.value === undefined)\n ? (e) => {\n if (unit && native.value === undefined) setTyped(e.target.value);\n onChange?.(e.target.value, e);\n }\n : undefined\n }\n aria-invalid={error ? true : native['aria-invalid']}\n // Your own description first, then the prefix, unit and suffix, then the hint or the error.\n aria-describedby={describedBy(native['aria-describedby'], ...affixIds, msg)}\n />\n );\n const shown = String(native.value ?? typed) || native.placeholder || '';\n return (\n <div className={cx('ui-field', error && 'has-error', disabled && 'is-disabled', className)}>\n <FieldLabel htmlFor={fieldId} required={required} hidden={hideLabel}>\n {label}\n </FieldLabel>\n <div\n className={cx('ui-field-box', affixed && 'has-affix')}\n // A press on the frame outside the input (the prefix, suffix or unit text) focuses the input, as a click on\n // the label does; preventDefault keeps the focus from going to the body first.\n onMouseDown={(e) => {\n const box = e.currentTarget.querySelector('input');\n if (!box || disabled || e.button !== 0 || e.target === box) return;\n e.preventDefault();\n box.focus();\n }}\n >\n {prefix ? (\n <span id={fieldId + '-pre'} className=\"ui-field-affix\">\n {prefix}\n </span>\n ) : null}\n {unit ? (\n // The unit sits after the text: an invisible copy of the text pushes it there.\n <span className=\"ui-field-unitwrap\">\n {input}\n <span className=\"ui-field-unitline\" aria-hidden=\"true\">\n <span className=\"ui-field-mirror\">{shown}</span>\n <span className=\"ui-field-affix\">{(shown ? '\\u00a0' : '') + unit}</span>\n </span>\n <span id={fieldId + '-unit'} className=\"ui-visually-hidden\">\n {unit}\n </span>\n </span>\n ) : (\n input\n )}\n {suffix ? (\n <span id={fieldId + '-suf'} className=\"ui-field-affix\">\n {suffix}\n </span>\n ) : null}\n {error ? <FieldErrorIcon inline={affixed} /> : null}\n </div>\n {msg ? <FieldMessage id={msg} error={error} hint={hint} /> : null}\n </div>\n );\n}\n"],"mappings":";;;;;;;AAqBA,SAAgB,UAAU,EAAE,OAAO,WAAW,MAAM,OAAO,IAAI,WAAW,UAAU,UAAU,UAAU,QAAQ,QAAQ,MAAM,GAAG,UAA0B;CACzJ,MAAM,OAAO,MAAM,MAAM;CACzB,MAAM,UAAU,MAAM;CACtB,MAAM,MAAM,QAAQ,UAAU,SAAS,OAAO,UAAU,UAAU,KAAA;CAElE,MAAM,CAAC,OAAO,YAAY,MAAM,SAAS,OAAO,OAAO,gBAAgB,EAAE,CAAC;CAC1E,MAAM,UAAU,CAAC,EAAE,UAAU,UAAU;CAEvC,MAAM,WAAW;EAAC,UAAU,UAAU;EAAQ,QAAQ,UAAU;EAAS,UAAU,UAAU;CAAM;CACnG,MAAM,QACJ,oBAAC,SAAD;EACE,MAAK;EACL,GAAI;EACM;EACA;EACV,IAAI;EACJ,WAAU;EACV,UACE,YAAa,QAAQ,OAAO,UAAU,KAAA,KACjC,MAAM;GACL,IAAI,QAAQ,OAAO,UAAU,KAAA,GAAW,SAAS,EAAE,OAAO,KAAK;GAC/D,WAAW,EAAE,OAAO,OAAO,CA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EAC1D;;AAET"}
|
package/docs/DataTable.md
CHANGED
|
@@ -55,7 +55,7 @@ const columns: DataTableColumn<Import>[] = [
|
|
|
55
55
|
- `rowHref={(row) => url}`:整列是連結(中鍵、Ctrl+點開新分頁);SPA 另給 `onRowOpen` 推路由。第一欄的 `render` 裡不再放連結。
|
|
56
56
|
- `totals={{ amount: 'sum', rate: 'avg' }}`:合計列,有金額或數量要加總時才開(看情況)。`stickyFirst`:欄位多、常橫向捲動時固定第一欄(看情況)。`views`:幾組固定的看法(「我負責的」)時才開(看情況)。
|
|
57
57
|
- 欄位:`hidden: true` 一開始不顯示(「⋯」的「欄位」可以打開);`width` 只是最小寬度;`grow` 改變分剩下寬度的份數;`long: true` 的長文字截斷並可展開;`fullText` 給縮短的格子完整文字;`currency`、`decimals` 調整格式。
|
|
58
|
-
- 手機(小於 600 px
|
|
58
|
+
- 手機(小於 600 px):每列一張卡片,第一欄是標題(第一欄是 `mono` 的 ID、表格又有主要欄時,改用主要欄,ID 變成一行欄位),`mobile: 'status'` 的欄在標題右邊,`mobile: 'hide'` 不顯示,其他欄「欄名|值」一行一欄,`rowActions` 在卡片最下面。
|
|
59
59
|
- 記住讀者的選擇:`storageKey` 把拖出的欄寬和顯示的欄位存在 localStorage(和其他元件同名;`widthKey` 已棄用)。換成另一份資料時給新的 `resetKey`;同一頁兩個表格用 `urlKey` 分開網址參數,`urlSync={false}` 不寫網址。
|
|
60
60
|
- `emptyText`:搜尋或篩選後沒有結果的一句話(預設「沒有符合的資料」)。完全沒有資料時用 EmptyState,見 guidelines。
|
|
61
61
|
- 「⋯」裡的放大表格(`zoom`)、複製成 Markdown(`copy`、`copyText`、`onCopyError`)預設開;`columnMenu={false}` 拿掉「欄位」。
|
package/docs/agents.md
CHANGED
|
@@ -65,11 +65,11 @@ export default [ui.configs.recommended];
|
|
|
65
65
|
```html
|
|
66
66
|
<meta charset="utf-8">
|
|
67
67
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
68
|
-
<link rel="stylesheet" href="https://seanyeh77.github.io/ui-design-system/dist/0.47.
|
|
69
|
-
<link rel="stylesheet" href="https://seanyeh77.github.io/ui-design-system/dist/0.47.
|
|
70
|
-
<link rel="stylesheet" href="https://seanyeh77.github.io/ui-design-system/dist/0.47.
|
|
68
|
+
<link rel="stylesheet" href="https://seanyeh77.github.io/ui-design-system/dist/0.47.1/fonts.css">
|
|
69
|
+
<link rel="stylesheet" href="https://seanyeh77.github.io/ui-design-system/dist/0.47.1/tokens.css">
|
|
70
|
+
<link rel="stylesheet" href="https://seanyeh77.github.io/ui-design-system/dist/0.47.1/styles.css">
|
|
71
71
|
<div id="root"></div>
|
|
72
|
-
<script src="https://seanyeh77.github.io/ui-design-system/dist/0.47.
|
|
72
|
+
<script src="https://seanyeh77.github.io/ui-design-system/dist/0.47.1/bundle.js"></script>
|
|
73
73
|
<script>
|
|
74
74
|
const h = React.createElement;
|
|
75
75
|
UI.initTheme();
|
|
@@ -77,6 +77,6 @@ export default [ui.configs.recommended];
|
|
|
77
77
|
</script>
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
Pin a version as above: `/dist/<version>/` never changes; `/dist/` always serves the latest release. jsDelivr has the same files (`https://cdn.jsdelivr.net/npm/@seanyeh77/ui@0.47.
|
|
80
|
+
Pin a version as above: `/dist/<version>/` never changes; `/dist/` always serves the latest release. jsDelivr has the same files (`https://cdn.jsdelivr.net/npm/@seanyeh77/ui@0.47.1/dist/bundle.js`, `…/dist/styles.css`; the fonts at `https://cdn.jsdelivr.net/npm/@seanyeh77/tokens@0.47.1/fonts.css`). Without a bundler, `@seanyeh77/ui/dist/fonts.css` cannot resolve its import: load the tokens package's `fonts.css` or the pinned site URL.
|
|
81
81
|
|
|
82
82
|
Scope: web UI, and the tokens of SeanYeh's Slidev decks (`initTheme({ preset: 'teaching' })`, see `theme.md`). Slide layout, Notion documents and teaching diagrams follow the separate `teaching-materials-style` skill.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seanyeh77/ui",
|
|
3
|
-
"version": "0.47.
|
|
3
|
+
"version": "0.47.1",
|
|
4
4
|
"description": "SeanYeh's design system: typed React components on Base UI, styled with design tokens.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Hsiu-An Yeh",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@base-ui/react": "^1.9.0",
|
|
61
|
-
"@seanyeh77/tokens": "^0.47.
|
|
61
|
+
"@seanyeh77/tokens": "^0.47.1"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "node scripts/theme-defaults.ts && tsdown && node scripts/postbuild.ts",
|