@h-ai/ui 0.1.0-alpha.74 → 0.1.0-alpha.76
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/README.en.md +46 -17
- package/README.ja.md +46 -17
- package/README.md +46 -17
- package/auto-import.d.ts +2 -0
- package/auto-import.js +2 -0
- package/dist/components/compounds/Alert.svelte +2 -2
- package/dist/components/compounds/Alert.svelte.d.ts +1 -1
- package/dist/components/compounds/Confirm.svelte +12 -2
- package/dist/components/compounds/Drawer.svelte +32 -14
- package/dist/components/compounds/FilterBar.svelte +77 -0
- package/dist/components/compounds/FilterBar.svelte.d.ts +39 -0
- package/dist/components/compounds/Modal.svelte +4 -37
- package/dist/components/compounds/PageHeader.svelte +18 -11
- package/dist/components/compounds/TableToolbar.svelte +1 -1
- package/dist/components/compounds/ToastContainer.svelte +96 -42
- package/dist/components/compounds/ToastContainer.svelte.d.ts +1 -1
- package/dist/components/compounds/index.d.ts +1 -0
- package/dist/components/compounds/index.js +1 -0
- package/dist/components/primitives/Button.svelte +7 -0
- package/dist/components/primitives/Input.svelte +1 -1
- package/dist/components/primitives/Textarea.svelte +1 -1
- package/dist/components/scenes/app/FeedbackDetail.svelte +2 -2
- package/dist/components/scenes/app/FeedbackForm.svelte +5 -7
- package/dist/components/scenes/app/FeedbackList.svelte +4 -4
- package/dist/components/scenes/app/SettingsLayout.svelte +4 -15
- package/dist/components/scenes/app/ThemeSelector.svelte +56 -16
- package/dist/components/scenes/app/WorkspaceLayout.svelte +64 -0
- package/dist/components/scenes/app/WorkspaceLayout.svelte.d.ts +36 -0
- package/dist/components/scenes/app/feedback-functions.d.ts +16 -0
- package/dist/components/scenes/app/feedback-functions.js +31 -0
- package/dist/components/scenes/app/index.d.ts +1 -0
- package/dist/components/scenes/app/index.js +1 -0
- package/dist/components/scenes/crud/CrudEditPanel.svelte +18 -9
- package/dist/components/scenes/crud/CrudFilterBar.svelte +39 -30
- package/dist/components/scenes/crud/CrudFilterBar.svelte.d.ts +4 -1
- package/dist/components/scenes/crud/CrudPage.svelte +27 -7
- package/dist/components/scenes/crud/CrudPage.svelte.d.ts +1 -1
- package/dist/components/scenes/crud/crud-types.d.ts +1 -1
- package/dist/components/scenes/guide/GuideHost.svelte +22 -102
- package/dist/components/scenes/guide/GuideHost.svelte.d.ts +5 -13
- package/dist/components/scenes/guide/GuideHostContent.svelte +143 -0
- package/dist/components/scenes/guide/GuideHostContent.svelte.d.ts +43 -0
- package/dist/components/scenes/guide/HelpCenter.svelte +22 -9
- package/dist/components/scenes/iam/AuthPanel.svelte +5 -3
- package/dist/components/scenes/iam/LoginForm.svelte +25 -1
- package/dist/components/scenes/iam/PasswordInput.svelte +1 -1
- package/dist/components/scenes/iam/SensitiveOperationsForm.svelte +1 -1
- package/dist/components/scenes/types.d.ts +2 -0
- package/dist/guide.svelte.js +61 -26
- package/dist/internal/dialog-focus.d.ts +21 -0
- package/dist/internal/dialog-focus.js +77 -0
- package/dist/internal/form-validation.svelte.d.ts +2 -1
- package/dist/internal/form-validation.svelte.js +9 -1
- package/dist/messages/en-US.json +9 -2
- package/dist/messages/ja-JP.json +9 -2
- package/dist/messages/zh-CN.json +9 -2
- package/dist/styles/formal.css +55 -0
- package/dist/styles/high-contrast.css +64 -0
- package/dist/styles/theme.css +2 -0
- package/dist/theme-config.d.ts +2 -2
- package/dist/theme-config.js +5 -2
- package/dist/toast.svelte.d.ts +7 -6
- package/dist/toast.svelte.js +23 -23
- package/dist/types.d.ts +6 -2
- package/dist/workspace-context.d.ts +20 -0
- package/dist/workspace-context.js +9 -0
- package/package.json +7 -2
package/README.en.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
Built-in messages support `zh-CN`, `en-US` and `ja-JP`; the language selector offers all three by default.
|
|
10
10
|
|
|
11
|
-
A cross-platform Svelte 5 Runes component library with DaisyUI v5 + Tailwind CSS v4 styling and Bits UI v2 headless interactions. Includes built-in i18n (zh-CN / en-US) and 15 curated DaisyUI themes.
|
|
11
|
+
A cross-platform Svelte 5 Runes component library with DaisyUI v5 + Tailwind CSS v4 styling and Bits UI v2 headless interactions. Includes built-in i18n (zh-CN / en-US / ja-JP) and 15 curated DaisyUI themes plus high contrast and square business themes.
|
|
12
12
|
|
|
13
13
|
## Core features
|
|
14
14
|
|
|
@@ -201,7 +201,7 @@ Labels connect to nested UI controls automatically; use `<FormField for="control
|
|
|
201
201
|
|
|
202
202
|
`Input`, `Textarea`, `Select` and `PasswordInput` provide Chinese/English/Japanese native validation messages. `validationMessage` overrides failures without keeping valid input invalid. Sync locale with the UI `setGlobalLocale` / `createLocaleStore` to update visible validation errors immediately. `Textarea` supports `minlength` / `maxlength`; `Select` supports `name`, required validation and FormData serialization.
|
|
203
203
|
|
|
204
|
-
|
|
204
|
+
Text controls validate on blur after input and update errors as input is corrected. Pristine empty fields validate on submit, so leaving default focus does not shift actions. CRUD create/edit forms also validate on blur after input or on submit, honor custom messages and reset validation when reopened. `Select` validates when focus leaves both its trigger and options. `PasswordInput.minLength` enforces length and informs strength; omitting it leaves login password length unrestricted while strength uses an eight-character baseline.
|
|
205
205
|
|
|
206
206
|
`UserProfile.fieldConstraints` accepts per-field `required`, `minlength`, `maxlength`, `pattern` and `validationMessage` (`pattern` applies to single-line inputs), so application rules such as username formats share blur validation. `validationMessage` also accepts a deferred translation function.
|
|
207
207
|
|
|
@@ -483,24 +483,21 @@ Defaults match `@h-ai/crypto`: `SM4` for encrypted inputs, `SM3` for hashes, and
|
|
|
483
483
|
<ToastContainer />
|
|
484
484
|
```
|
|
485
485
|
|
|
486
|
+
Toasts float at the bottom right by default without shifting layout, using UI-owned semantic colors for information, success, warning and error, with a soft tinted background, a narrow color border, a distinct icon and a subtle shadow. They can be dismissed manually. Notifications share one FIFO queue and appear one at a time; each timer starts when its notification is shown (3 seconds by default, `duration: 0` waits for dismissal). Mount `<ToastContainer />` once in the root layout. Set a position with `toast.add({ message: m.saved(), variant: 'success', position: 'bottom-center' })`, where `m.saved()` is an application translation. Positions: `bottom-right` (default), `top-right`, `bottom-center`, `top-center`, `bottom-left`, `top-left`. Use Toast for save/copy results. Keep field validation, persistent business status and recovery actions inline; `Alert` uses a soft background.
|
|
487
|
+
|
|
486
488
|
> Built-in `notifySuccess` / `notifyError` / `notifyInfo` / `notifyWarning` remove the need for application toast wrappers. `notifyError(err, fallback?)` accepts `Error` or strings with a fallback message. Success lasts 3s and errors 5s by default.
|
|
487
489
|
|
|
488
|
-
|
|
490
|
+
State modules can import `toast`, `notifySuccess` / `notifyError` / `notifyInfo` / `notifyWarning` and `errorMessage` from the lightweight `@h-ai/ui/toast` entry without loading components or tour CSS. Import `ToastContainer` from a component entry and mount it in the root layout.
|
|
489
491
|
|
|
490
|
-
|
|
491
|
-
<script>
|
|
492
|
-
import { message, MessageContainer } from '@h-ai/ui'
|
|
492
|
+
#### Choosing a Toast position
|
|
493
493
|
|
|
494
|
-
|
|
495
|
-
message.success('操作成功')
|
|
496
|
-
message.error('操作失败')
|
|
497
|
-
message.warning('请注意')
|
|
498
|
-
message.info('提示信息', 5000)
|
|
499
|
-
}
|
|
500
|
-
</script>
|
|
494
|
+
The application provides the `m.saved()` translation below. Notifications at different positions still share one queue and appear in order.
|
|
501
495
|
|
|
502
|
-
|
|
503
|
-
|
|
496
|
+
```ts
|
|
497
|
+
import { toast } from '@h-ai/ui/toast'
|
|
498
|
+
|
|
499
|
+
toast.add({ message: m.saved(), variant: 'success', position: 'top-right' })
|
|
500
|
+
toast.add({ message: m.saved(), position: 'bottom-center' })
|
|
504
501
|
```
|
|
505
502
|
|
|
506
503
|
#### Typical CRUD page
|
|
@@ -704,7 +701,11 @@ npm install -D @iconify/tailwind4 @iconify-json/tabler
|
|
|
704
701
|
|
|
705
702
|
#### Theme switching
|
|
706
703
|
|
|
707
|
-
Manage 15 curated DaisyUI themes through built-in utilities:
|
|
704
|
+
Manage 15 curated DaisyUI themes plus high contrast and square business themes through built-in utilities:
|
|
705
|
+
|
|
706
|
+
`high-contrast` ships in shared theme.css with bright text on dark surfaces, clear borders/focus, and stronger muted text/placeholders. ThemeSelector has localized labels; examples and default generated projects offer it. Explicit fullstack themes lists remain host controlled. Palette checks target 7:1 for normal text; arbitrary application content still needs accessibility review.
|
|
707
|
+
|
|
708
|
+
`formal` provides square corners for business buttons, fields, cards and dialogs, with localized labels in examples and default templates. Button submitHint displays the native Enter action only for type=submit; it adds no global shortcut. LoginForm focuses its identifier on desktop when ready and no element has focus; autoFocus=false opts out. Search Enter submits immediately while respecting IME composition. Theme choices support arrows/Home/End, Enter/Space and Escape focus restoration. Confirmation dialogs initially focus Cancel and synchronize Escape cancellation.
|
|
708
709
|
|
|
709
710
|
```ts
|
|
710
711
|
import {
|
|
@@ -717,7 +718,7 @@ import {
|
|
|
717
718
|
normalizeHexColor, // 归一化 #RGB / #RRGGBB 主题色
|
|
718
719
|
normalizeThemeId, // 校验主题 ID 并自动回退
|
|
719
720
|
THEME_GROUPS, // 按亮色/暗色分组
|
|
720
|
-
THEMES, // ThemeInfo[] —
|
|
721
|
+
THEMES, // ThemeInfo[] — 17 个主题元数据
|
|
721
722
|
} from '@h-ai/ui/theme'
|
|
722
723
|
```
|
|
723
724
|
|
|
@@ -957,6 +958,34 @@ Browsers keep application-level `setGlobalLocale` / `createLocaleStore`. During
|
|
|
957
958
|
|
|
958
959
|
Object keys are limited to 1024 UTF-8 bytes and reject absolute paths, backslashes, control characters and dot segments. Each public HTTP batch delete accepts 1–1000 entries. `@h-ai/storage/schemas` exposes the shared browser-safe rules. Presign expiry is an integer from 1 to 604800 seconds (Node default 3600, HTTP default 900). Upload signing accepts only key/contentType/expiresIn; contentLength/maxSize/metadata/checksum are unsupported. Invalid input returns HTTP 400 and the typed client maps it to VALIDATION_FAILED. FileUpload limits guide file selection; applications must validate actual objects on the server. Node streaming/checksum/conditional-write options have no default HTTP endpoints. See the [capability and authorization matrix (Chinese)](../storage/README.md#存储输入约束与跨端能力).
|
|
959
960
|
|
|
961
|
+
## Compact workspaces and collapsible filters
|
|
962
|
+
|
|
963
|
+
`WorkspaceLayout` shares a compact navigation header, a content area with 12/16px padding and an optional footer. An omitted footer reserves no space. title is the page title in navigation; leading/actions/footer are snippets. data-* attributes reach the content main. The host must pass down available height and min-height: 0.
|
|
964
|
+
|
|
965
|
+
A matching `PageHeader` omits the repeated title and retains its description and actions; `SettingsLayout` shares this behavior. Inside a workspace, `CrudPage` defaults to one navigation title and keeps actions in its toolbar. Standalone usage retains its title; showHeader explicitly overrides the default.
|
|
966
|
+
|
|
967
|
+
`FilterBar` keeps leading and actions visible, with children collapsed by default. bind:expanded controls disclosure, activeCount reports active conditions, and onreset supplies the built-in localized reset button. Collapsing preserves controls and values. The host resets state and performs queries. `CrudFilterBar` reuses it, supports custom actions and cancels pending debounce queries when destroyed.
|
|
968
|
+
|
|
969
|
+
In this example, m, statusOptions, clearFilters and loadRows belong to the host application. The reset callback must clear search and all conditions.
|
|
970
|
+
|
|
971
|
+
```svelte
|
|
972
|
+
<script lang="ts">
|
|
973
|
+
import { Button, FilterBar, Input, Select, WorkspaceLayout } from '@h-ai/ui'
|
|
974
|
+
let search = $state('')
|
|
975
|
+
let status = $state('')
|
|
976
|
+
</script>
|
|
977
|
+
|
|
978
|
+
<div class="flex h-dvh min-h-0">
|
|
979
|
+
<WorkspaceLayout title={m.page_title()}>
|
|
980
|
+
<FilterBar activeCount={status ? 1 : 0} onreset={clearFilters}>
|
|
981
|
+
{#snippet leading()}<Input size="sm" bind:value={search} placeholder={m.search()} />{/snippet}
|
|
982
|
+
{#snippet actions()}<Button size="sm" onclick={loadRows}>{m.search()}</Button>{/snippet}
|
|
983
|
+
<div class="w-40"><Select size="sm" bind:value={status} options={statusOptions} /></div>
|
|
984
|
+
</FilterBar>
|
|
985
|
+
</WorkspaceLayout>
|
|
986
|
+
</div>
|
|
987
|
+
```
|
|
988
|
+
|
|
960
989
|
## Design and interaction acceptance
|
|
961
990
|
|
|
962
991
|
Use [hai-ui-design](../cli/templates/skills/hai-ui-design/SKILL.md) for page decisions, [hai-ui](../cli/templates/skills/hai-ui/SKILL.md) for implementation, and [hai-ui-review](../cli/templates/skills/hai-ui-review/SKILL.md) for rendered UI review. See the [shared design guidance](../../.agents/instructions/ui-design.md).
|
package/README.ja.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
内蔵メッセージは `zh-CN`、`en-US`、`ja-JP` に対応し、言語セレクターは既定で3言語を表示します。
|
|
10
10
|
|
|
11
|
-
Svelte 5 Runes のクロスプラットフォーム UI ライブラリーです。DaisyUI v5 + Tailwind CSS v4 のスタイル、Bits UI v2 のヘッドレス UI、内蔵 i18n(zh-CN / en-US)、15
|
|
11
|
+
Svelte 5 Runes のクロスプラットフォーム UI ライブラリーです。DaisyUI v5 + Tailwind CSS v4 のスタイル、Bits UI v2 のヘッドレス UI、内蔵 i18n(zh-CN / en-US / ja-JP)、15 種類の厳選テーマ、ハイコントラストと直角のビジネステーマを提供します。
|
|
12
12
|
|
|
13
13
|
## 主な機能
|
|
14
14
|
|
|
@@ -201,7 +201,7 @@ components/
|
|
|
201
201
|
|
|
202
202
|
`Input`、`Textarea`、`Select`、`PasswordInput` のネイティブ検証は中国語・英語・日本語に対応します。`validationMessage` は失敗時だけ適用され、有効な入力を無効にし続けません。UI の `setGlobalLocale` / `createLocaleStore` で言語を同期すると表示中のエラーも更新されます。`Textarea` は `minlength` / `maxlength`、`Select` は `name`・必須検証・FormData に対応します。
|
|
203
203
|
|
|
204
|
-
|
|
204
|
+
テキスト入力後のフォーカス離脱時に検証し、修正中も更新します。未入力の空欄は送信時に検証し、初期フォーカスの移動で操作を押し下げません。CRUD も入力後のフォーカス離脱時または送信時に検証し、カスタムメッセージに対応して再表示時に検証状態をリセットします。`Select` はトリガーと選択肢の両方からフォーカスが離れた時に検証します。`PasswordInput.minLength` は長さ制約と強度計算に使い、省略時はログイン用の長さ制限を設けず、強度のみ8文字を基準にします。
|
|
205
205
|
|
|
206
206
|
`UserProfile.fieldConstraints` は項目別に `required`、`minlength`、`maxlength`、`pattern`、`validationMessage` を受け取り、ユーザー名などの業務ルールをフォーカス離脱時に検証します。`pattern` は単一行の入力に適用し、`validationMessage` は翻訳関数にも対応します。
|
|
207
207
|
|
|
@@ -483,24 +483,21 @@ components/
|
|
|
483
483
|
<ToastContainer />
|
|
484
484
|
```
|
|
485
485
|
|
|
486
|
+
通知は既定で右下に浮かび、ページのレイアウトを変えません。UI モジュールのテーマ色でお知らせ・成功・警告・エラーを区別し、淡い背景、細い色枠、種類別アイコンと控えめな影を使用し、手動で閉じられます。複数の通知は共通の FIFO キューから 1 件ずつ表示され、表示開始から計時します(既定 3 秒、`duration: 0` は手動で閉じるまで保持)。ルートに `<ToastContainer />` を 1 回だけ配置します。`toast.add({ message: m.saved(), variant: 'success', position: 'bottom-center' })` で位置を指定できます。`m.saved()` はアプリの翻訳関数です。位置は `bottom-right`(既定)、`top-right`、`bottom-center`、`top-center`、`bottom-left`、`top-left`。保存やコピーの結果は Toast、フィールド検証や継続的な業務状態、復旧操作はインラインで表示します。`Alert` は淡い背景を使用します。
|
|
487
|
+
|
|
486
488
|
> `notifySuccess` / `notifyError` / `notifyInfo` / `notifyWarning` を内蔵し、アプリ独自の toast ツールは不要です。`notifyError(err, fallback?)` は `Error`・文字列と代替文言を受け付け、既定は成功 3 秒・失敗 5 秒です。
|
|
487
489
|
|
|
488
|
-
|
|
490
|
+
状態層は軽量な `@h-ai/ui/toast` から `toast`、`notifySuccess` / `notifyError` / `notifyInfo` / `notifyWarning`、`errorMessage` を読み込めます。コンポーネントやガイド CSS は読み込みません。`ToastContainer` はコンポーネントの入口から読み込み、ルートに配置します。
|
|
489
491
|
|
|
490
|
-
|
|
491
|
-
<script>
|
|
492
|
-
import { message, MessageContainer } from '@h-ai/ui'
|
|
492
|
+
#### 通知の位置を指定する
|
|
493
493
|
|
|
494
|
-
|
|
495
|
-
message.success('操作成功')
|
|
496
|
-
message.error('操作失败')
|
|
497
|
-
message.warning('请注意')
|
|
498
|
-
message.info('提示信息', 5000)
|
|
499
|
-
}
|
|
500
|
-
</script>
|
|
494
|
+
以下の `m.saved()` はアプリの翻訳関数です。異なる位置の通知も共通のキューから順番に表示されます。
|
|
501
495
|
|
|
502
|
-
|
|
503
|
-
|
|
496
|
+
```ts
|
|
497
|
+
import { toast } from '@h-ai/ui/toast'
|
|
498
|
+
|
|
499
|
+
toast.add({ message: m.saved(), variant: 'success', position: 'top-right' })
|
|
500
|
+
toast.add({ message: m.saved(), position: 'bottom-center' })
|
|
504
501
|
```
|
|
505
502
|
|
|
506
503
|
#### 標準的な CRUD ページ
|
|
@@ -704,7 +701,11 @@ npm install -D @iconify/tailwind4 @iconify-json/tabler
|
|
|
704
701
|
|
|
705
702
|
#### テーマ切り替え
|
|
706
703
|
|
|
707
|
-
内蔵ツールで 15 種類の厳選 DaisyUI
|
|
704
|
+
内蔵ツールで 15 種類の厳選 DaisyUI テーマ、ハイコントラストと直角のビジネステーマを管理します:
|
|
705
|
+
|
|
706
|
+
`high-contrast` は共有 theme.css に含まれます。暗い背景と明るい文字、明確な境界線・フォーカス、補助文字とプレースホルダーの強いコントラストを提供します。ThemeSelector は3言語に対応し、サンプルと既定の生成プロジェクトで選択できます。fullstack の明示的な themes はホスト設定を尊重します。通常文字の配色目標は7:1ですが、各業務コンテンツは別途アクセシビリティ確認が必要です。
|
|
707
|
+
|
|
708
|
+
`formal` はボタン・入力欄・カード・ダイアログを直角にし、サンプルと既定テンプレートで選択できます。Button の submitHint は type=submit のネイティブ Enter 操作だけを表示します。LoginForm はデスクトップで準備完了時に既存のフォーカスがなければ識別子へ移動し、autoFocus=false で無効化できます。検索の Enter は IME 確定を除いて即時実行します。テーマは方向キー/Home/End、Enter/Space、Esc とフォーカス復帰に対応し、確認画面は取消を初期選択して Esc の状態を同期します。
|
|
708
709
|
|
|
709
710
|
```ts
|
|
710
711
|
import {
|
|
@@ -717,7 +718,7 @@ import {
|
|
|
717
718
|
normalizeHexColor, // 归一化 #RGB / #RRGGBB 主题色
|
|
718
719
|
normalizeThemeId, // 校验主题 ID 并自动回退
|
|
719
720
|
THEME_GROUPS, // 按亮色/暗色分组
|
|
720
|
-
THEMES, // ThemeInfo[] —
|
|
721
|
+
THEMES, // ThemeInfo[] — 17 个主题元数据
|
|
721
722
|
} from '@h-ai/ui/theme'
|
|
722
723
|
```
|
|
723
724
|
|
|
@@ -957,6 +958,34 @@ Node リクエストと SSR は `core.i18n.runWithLocale(locale, () => handleReq
|
|
|
957
958
|
|
|
958
959
|
キーは UTF-8 で最大 1024 バイトで、絶対パス、バックスラッシュ、制御文字、ドットセグメントを拒否します。公開 HTTP 一括削除は一度に 1–1000 件です。共通規則はブラウザー対応の `@h-ai/storage/schemas` から参照できます。署名有効期限は整数 1–604800 秒(Node 既定 3600、HTTP 既定 900)。アップロード署名の入力は key/contentType/expiresIn のみで、contentLength/maxSize/metadata/checksum は未対応です。不正入力は HTTP 400、typed client では VALIDATION_FAILED です。FileUpload の制限は選択時の補助であり、実際のオブジェクトはサーバーで検証してください。Node のストリーム/checksum/条件付き書き込みには既定の HTTP エンドポイントがありません。[機能と認可の対応表(中国語)](../storage/README.md#存储输入约束与跨端能力)を参照してください。
|
|
959
960
|
|
|
961
|
+
## コンパクトな作業領域と折りたたみ式の絞り込み
|
|
962
|
+
|
|
963
|
+
`WorkspaceLayout` はコンパクトなナビゲーション、12/16px の余白を持つ本文、任意のフッターを統一します。フッターを省略すると高さを確保しません。title はナビゲーションのページ名、leading/actions/footer は snippet です。data-* は本文の main に渡します。親レイアウトから残りの高さと min-height: 0 を引き継いでください。
|
|
964
|
+
|
|
965
|
+
同名の `PageHeader` は重複する見出しを省略し、説明と操作を保持します。`SettingsLayout` も同じ動作です。作業領域内の `CrudPage` は既定でナビゲーションの見出しだけを表示し、操作をツールバーに残します。単独利用時は見出しを表示し、showHeader で明示的に変更できます。
|
|
966
|
+
|
|
967
|
+
`FilterBar` は leading と actions を常に表示し、children を既定で折りたたみます。bind:expanded は開閉、activeCount は適用中の件数、onreset は3言語対応のリセットボタンです。折りたたんでも入力を保持し、条件の初期化と問い合わせは業務側のコールバックが担当します。`CrudFilterBar` もこれを利用し、actions を追加でき、破棄時に未送信の遅延検索を取り消します。
|
|
968
|
+
|
|
969
|
+
例の m、statusOptions、clearFilters、loadRows は業務アプリが提供します。リセット時は検索語と全条件を初期化してください。
|
|
970
|
+
|
|
971
|
+
```svelte
|
|
972
|
+
<script lang="ts">
|
|
973
|
+
import { Button, FilterBar, Input, Select, WorkspaceLayout } from '@h-ai/ui'
|
|
974
|
+
let search = $state('')
|
|
975
|
+
let status = $state('')
|
|
976
|
+
</script>
|
|
977
|
+
|
|
978
|
+
<div class="flex h-dvh min-h-0">
|
|
979
|
+
<WorkspaceLayout title={m.page_title()}>
|
|
980
|
+
<FilterBar activeCount={status ? 1 : 0} onreset={clearFilters}>
|
|
981
|
+
{#snippet leading()}<Input size="sm" bind:value={search} placeholder={m.search()} />{/snippet}
|
|
982
|
+
{#snippet actions()}<Button size="sm" onclick={loadRows}>{m.search()}</Button>{/snippet}
|
|
983
|
+
<div class="w-40"><Select size="sm" bind:value={status} options={statusOptions} /></div>
|
|
984
|
+
</FilterBar>
|
|
985
|
+
</WorkspaceLayout>
|
|
986
|
+
</div>
|
|
987
|
+
```
|
|
988
|
+
|
|
960
989
|
## デザインと操作の検証
|
|
961
990
|
|
|
962
991
|
画面設計は [hai-ui-design](../cli/templates/skills/hai-ui-design/SKILL.md)、実装は [hai-ui](../cli/templates/skills/hai-ui/SKILL.md)、実画面の確認は [hai-ui-review](../cli/templates/skills/hai-ui-review/SKILL.md) を参照してください。[共通設計指針](../../.agents/instructions/ui-design.md) も利用できます。
|
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
内置中英日文消息(`zh-CN` / `en-US` / `ja-JP`),语言选择器默认提供三种语言。
|
|
10
10
|
|
|
11
|
-
基于 Svelte 5 Runes 的多端 UI 组件库,采用 DaisyUI v5 + Tailwind CSS v4 样式 + Bits UI v2 headless 交互,内置 i18n(zh-CN / en-US),内置 15 个精选 DaisyUI
|
|
11
|
+
基于 Svelte 5 Runes 的多端 UI 组件库,采用 DaisyUI v5 + Tailwind CSS v4 样式 + Bits UI v2 headless 交互,内置 i18n(zh-CN / en-US / ja-JP),内置 15 个精选 DaisyUI 主题、高对比及直角商务主题。
|
|
12
12
|
|
|
13
13
|
## 核心功能清单
|
|
14
14
|
|
|
@@ -201,7 +201,7 @@ components/
|
|
|
201
201
|
|
|
202
202
|
`Input`、`Textarea`、`Select` 和 `PasswordInput` 的原生校验使用内置中英日文提示;`validationMessage` 只覆盖失败提示,不让有效输入一直无效。应用通过 UI 的 `setGlobalLocale` / `createLocaleStore` 同步语言,已显示的校验错误即时更新。`Textarea` 支持 `minlength` / `maxlength`,`Select` 支持 `name`、必填校验和 FormData 序列化。
|
|
203
203
|
|
|
204
|
-
|
|
204
|
+
文本控件输入后失焦显示前端校验错误,修正输入时即时更新;未输入的空字段留到提交时校验,避免默认焦点离开时挤动操作。CRUD 新增/编辑同样在输入后失焦或提交时校验,支持自定义校验文案,关闭重开清空校验状态。`Select` 在焦点离开触发器和选项后校验。`PasswordInput.minLength` 同时约束长度并用于强度计算;省略时不限制登录密码长度,强度计算仍以 8 位为基准。
|
|
205
205
|
|
|
206
206
|
`UserProfile.fieldConstraints` 按字段接收 `required`、`minlength`、`maxlength`、`pattern` 和 `validationMessage`(`pattern` 用于单行输入),让应用的用户名等业务规则复用失焦校验;`validationMessage` 支持延迟翻译函数。
|
|
207
207
|
|
|
@@ -482,24 +482,21 @@ components/
|
|
|
482
482
|
<ToastContainer />
|
|
483
483
|
```
|
|
484
484
|
|
|
485
|
+
默认在右下角浮动显示,不占页面布局;由 UI 模块统一使用提示蓝、成功绿、警告黄、错误红等主题语义色,以浅色底、细色边和对应图标区分,并保留轻阴影,支持手工关闭。多个提示进入同一 FIFO 队列,逐条展示,每条从展示时开始计时(默认 3 秒,`duration: 0` 等待手工关闭)。根布局只挂载一次 `<ToastContainer />`。用 `toast.add({ message: m.saved(), variant: 'success', position: 'bottom-center' })` 指定方位;`m.saved()` 是应用自身的翻译函数。可选 `bottom-right`(默认)、`top-right`、`bottom-center`、`top-center`、`bottom-left`、`top-left`。保存、复制等操作结果使用 Toast;字段校验、持续业务状态和恢复操作保留行内,`Alert` 使用柔和背景。
|
|
486
|
+
|
|
485
487
|
> 已内置 `notifySuccess` / `notifyError` / `notifyInfo` / `notifyWarning` 封装,业务应用无需自建 toast 工具文件:`notifyError(err, fallback?)` 接受 `Error` 或字符串并内置兑底文案,默认成功 3s / 失败 5s。
|
|
486
488
|
|
|
487
|
-
|
|
489
|
+
状态层可从轻量入口 `@h-ai/ui/toast` 导入 `toast`、`notifySuccess` / `notifyError` / `notifyInfo` / `notifyWarning` 和 `errorMessage`,不会连带加载组件及引导 CSS;`ToastContainer` 仍从组件入口导入并在根布局挂载。
|
|
488
490
|
|
|
489
|
-
|
|
490
|
-
<script>
|
|
491
|
-
import { message, MessageContainer } from '@h-ai/ui'
|
|
491
|
+
#### 指定提示方位
|
|
492
492
|
|
|
493
|
-
|
|
494
|
-
message.success('操作成功')
|
|
495
|
-
message.error('操作失败')
|
|
496
|
-
message.warning('请注意')
|
|
497
|
-
message.info('提示信息', 5000)
|
|
498
|
-
}
|
|
499
|
-
</script>
|
|
493
|
+
下例 `m.saved()` 由应用自己的 i18n 提供;不同方位也共用同一个队列,按顺序展示。
|
|
500
494
|
|
|
501
|
-
|
|
502
|
-
|
|
495
|
+
```ts
|
|
496
|
+
import { toast } from '@h-ai/ui/toast'
|
|
497
|
+
|
|
498
|
+
toast.add({ message: m.saved(), variant: 'success', position: 'top-right' })
|
|
499
|
+
toast.add({ message: m.saved(), position: 'bottom-center' })
|
|
503
500
|
```
|
|
504
501
|
|
|
505
502
|
#### 典型 CRUD 页面
|
|
@@ -703,7 +700,11 @@ npm install -D @iconify/tailwind4 @iconify-json/tabler
|
|
|
703
700
|
|
|
704
701
|
#### 主题切换
|
|
705
702
|
|
|
706
|
-
使用内置的主题工具函数管理 15 个精选 DaisyUI
|
|
703
|
+
使用内置的主题工具函数管理 15 个精选 DaisyUI 主题、高对比及直角商务主题:
|
|
704
|
+
|
|
705
|
+
`high-contrast` 随共享 theme.css 提供:黑底亮字、清晰边框/焦点、增强次要文字及占位符对比度。ThemeSelector 提供三语名称;示例与默认生成工程可选择,fullstack 的显式 themes 列表仍由宿主决定。配色按普通文字 7:1 的目标验收,不代表任意业务内容已通过整站无障碍认证。
|
|
706
|
+
|
|
707
|
+
`formal` 提供直角的商务外观,按钮、输入框、卡片与弹窗不使用装饰性圆角;主题选择器提供三语名称,示例和默认模板可选择。Button 的 submitHint 仅在 type=submit 时显示原生 Enter 提示,不绑定全局快捷键;LoginForm 默认在桌面首次就绪且页面无焦点时聚焦标识,autoFocus=false 可关闭。筛选 Enter 即时查询且忽略输入法确认;主题菜单支持方向键/Home/End、Enter/Space 及 Esc 恢复焦点;确认框默认聚焦取消,Esc 同步取消状态。
|
|
707
708
|
|
|
708
709
|
```ts
|
|
709
710
|
import {
|
|
@@ -716,7 +717,7 @@ import {
|
|
|
716
717
|
normalizeHexColor, // 归一化 #RGB / #RRGGBB 主题色
|
|
717
718
|
normalizeThemeId, // 校验主题 ID 并自动回退
|
|
718
719
|
THEME_GROUPS, // 按亮色/暗色分组
|
|
719
|
-
THEMES, // ThemeInfo[] —
|
|
720
|
+
THEMES, // ThemeInfo[] — 17 个主题元数据
|
|
720
721
|
} from '@h-ai/ui/theme'
|
|
721
722
|
```
|
|
722
723
|
|
|
@@ -960,6 +961,34 @@ Node 请求与 SSR 使用 `core.i18n.runWithLocale(locale, () => handleRequest()
|
|
|
960
961
|
|
|
961
962
|
存储 key 按 UTF-8 最多 1024 字节,并拒绝绝对路径、反斜线、控制字符及点路径段;公开 HTTP 批量删除每次 1–1000 项。`@h-ai/storage/schemas` 提供浏览器安全的共同规则。预签名有效期为整数 1–604800 秒(Node 默认 3600,HTTP 默认 900);HTTP 上传仅接受 key/contentType/expiresIn,不支持 contentLength/maxSize/metadata/checksum。无效输入返回 HTTP 400,typed client 映射 VALIDATION_FAILED。FileUpload 的大小/类型限制仅为前端体验,实际对象须由应用服务端复核。Node 流式读写/checksum/条件写等没有默认 HTTP 端点。完整映射与授权边界见 [存储 API 能力](../storage/README.md#存储输入约束与跨端能力)。
|
|
962
963
|
|
|
964
|
+
## 紧凑工作区与可收起筛选
|
|
965
|
+
|
|
966
|
+
`WorkspaceLayout` 统一导航、内容区和可选页脚:顶栏采用紧凑高度,主内容使用 12/16px 内边距;没有页脚时不预留高度。通过 `title` 提供导航中的页面标题,`leading/actions/footer` 为 snippet,`data-*` 透传内容 main。父布局需传递剩余高度及 min-height: 0。
|
|
967
|
+
|
|
968
|
+
同名 `PageHeader` 自动省略重复标题,保留说明和操作;`SettingsLayout` 复用该行为。工作区中的 `CrudPage` 默认不重复显示页面标题,操作并入工具栏;独立使用仍显示标题,可用 `showHeader` 显式覆盖。
|
|
969
|
+
|
|
970
|
+
`FilterBar` 的 leading 和 actions 保持可见,children 默认收起,`bind:expanded` 控制展开,`activeCount` 提示已启用条件,`onreset` 提供内置三语重置按钮。收起保留控件和值;重置和请求逻辑由宿主回调处理。`CrudFilterBar` 已复用它,支持自定义 actions,卸载时取消待发出的防抖查询。
|
|
971
|
+
|
|
972
|
+
下例的 m、statusOptions、clearFilters 和 loadRows 由业务应用提供;清空回调须重置搜索及全部条件。
|
|
973
|
+
|
|
974
|
+
```svelte
|
|
975
|
+
<script lang="ts">
|
|
976
|
+
import { Button, FilterBar, Input, Select, WorkspaceLayout } from '@h-ai/ui'
|
|
977
|
+
let search = $state('')
|
|
978
|
+
let status = $state('')
|
|
979
|
+
</script>
|
|
980
|
+
|
|
981
|
+
<div class="flex h-dvh min-h-0">
|
|
982
|
+
<WorkspaceLayout title={m.page_title()}>
|
|
983
|
+
<FilterBar activeCount={status ? 1 : 0} onreset={clearFilters}>
|
|
984
|
+
{#snippet leading()}<Input size="sm" bind:value={search} placeholder={m.search()} />{/snippet}
|
|
985
|
+
{#snippet actions()}<Button size="sm" onclick={loadRows}>{m.search()}</Button>{/snippet}
|
|
986
|
+
<div class="w-40"><Select size="sm" bind:value={status} options={statusOptions} /></div>
|
|
987
|
+
</FilterBar>
|
|
988
|
+
</WorkspaceLayout>
|
|
989
|
+
</div>
|
|
990
|
+
```
|
|
991
|
+
|
|
963
992
|
## 设计与交互验收
|
|
964
993
|
|
|
965
994
|
页面设计使用 [hai-ui-design](../cli/templates/skills/hai-ui-design/SKILL.md),组件实现使用 [hai-ui](../cli/templates/skills/hai-ui/SKILL.md),真实界面走查使用 [hai-ui-review](../cli/templates/skills/hai-ui-review/SKILL.md)。[设计约定](../../.agents/instructions/ui-design.md) 说明布局、状态和示例。
|
package/auto-import.d.ts
CHANGED
|
@@ -66,6 +66,8 @@ declare global {
|
|
|
66
66
|
const MessageBoxDialog: typeof import('@h-ai/ui')['MessageBoxDialog']
|
|
67
67
|
const Modal: typeof import('@h-ai/ui')['Modal']
|
|
68
68
|
const PageHeader: typeof import('@h-ai/ui')['PageHeader']
|
|
69
|
+
const FilterBar: typeof import('@h-ai/ui')['FilterBar']
|
|
70
|
+
const WorkspaceLayout: typeof import('@h-ai/ui')['WorkspaceLayout']
|
|
69
71
|
const Pagination: typeof import('@h-ai/ui')['Pagination']
|
|
70
72
|
const Popover: typeof import('@h-ai/ui')['Popover']
|
|
71
73
|
const PullRefresh: typeof import('@h-ai/ui')['PullRefresh']
|
package/auto-import.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { mount, unmount, createRawSnippet } from 'svelte'
|
|
8
8
|
import type { ComponentProps } from 'svelte'
|
|
9
9
|
import { Alert } from '@h-ai/ui'
|
|
10
|
-
const props: ComponentProps<typeof Alert> = { title: '
|
|
10
|
+
const props: ComponentProps<typeof Alert> = { title: '服务状态', variant: 'info', children: createRawSnippet(() => ({ render: () => "<span>系统将于今晚进行维护。</span>" })) }
|
|
11
11
|
const component = mount(Alert, { target: document.body, props })
|
|
12
12
|
await unmount(component)
|
|
13
13
|
```
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
|
|
34
34
|
const alertClass = $derived(
|
|
35
35
|
cn(
|
|
36
|
-
'alert',
|
|
36
|
+
'alert alert-soft shadow-none',
|
|
37
37
|
'flex items-start gap-3',
|
|
38
38
|
getAlertVariantClass(variant),
|
|
39
39
|
className,
|
|
@@ -9,7 +9,7 @@ type $$ComponentProps = AlertProps & DataAttributes;
|
|
|
9
9
|
* import { mount, unmount, createRawSnippet } from 'svelte'
|
|
10
10
|
* import type { ComponentProps } from 'svelte'
|
|
11
11
|
* import { Alert } from '@h-ai/ui'
|
|
12
|
-
* const props: ComponentProps<typeof Alert> = { title: '
|
|
12
|
+
* const props: ComponentProps<typeof Alert> = { title: '服务状态', variant: 'info', children: createRawSnippet(() => ({ render: () => "<span>系统将于今晚进行维护。</span>" })) }
|
|
13
13
|
* const component = mount(Alert, { target: document.body, props })
|
|
14
14
|
* await unmount(component)
|
|
15
15
|
* ```
|
|
@@ -40,6 +40,8 @@
|
|
|
40
40
|
}: ConfirmProps & DataAttributes = $props()
|
|
41
41
|
|
|
42
42
|
const dataAttributes = $derived(getDataAttributes(restProps))
|
|
43
|
+
const titleId = $props.id()
|
|
44
|
+
const messageId = `${titleId}-message`
|
|
43
45
|
/** 响应式 i18n 显示值 */
|
|
44
46
|
const displayTitle = $derived(title ?? uiM('confirm_title'))
|
|
45
47
|
const displayMessage = $derived(message ?? uiM('confirm_message'))
|
|
@@ -63,6 +65,8 @@
|
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
function handleCancel() {
|
|
68
|
+
if (loading)
|
|
69
|
+
return
|
|
66
70
|
oncancel?.()
|
|
67
71
|
open = false
|
|
68
72
|
}
|
|
@@ -78,10 +82,16 @@
|
|
|
78
82
|
bind:this={modalElement}
|
|
79
83
|
class={cn('modal', className)}
|
|
80
84
|
onclick={handleBackdropClick}
|
|
85
|
+
aria-labelledby={titleId}
|
|
86
|
+
aria-describedby={messageId}
|
|
87
|
+
oncancel={(event) => {
|
|
88
|
+
event.preventDefault()
|
|
89
|
+
handleCancel()
|
|
90
|
+
}}
|
|
81
91
|
>
|
|
82
92
|
<div class='modal-box'>
|
|
83
|
-
<h3 class='font-bold text-lg'>{displayTitle}</h3>
|
|
84
|
-
<p class='py-4'>{displayMessage}</p>
|
|
93
|
+
<h3 id={titleId} class='font-bold text-lg'>{displayTitle}</h3>
|
|
94
|
+
<p id={messageId} class='py-4'>{displayMessage}</p>
|
|
85
95
|
<div class='modal-action'>
|
|
86
96
|
<Button
|
|
87
97
|
variant='ghost'
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
import type { DataAttributes, DrawerProps } from '../../types.js'
|
|
24
24
|
import { onDestroy, onMount, setContext } from 'svelte'
|
|
25
25
|
import { readStoredValue, writeStoredValue } from '../../internal/browser-safety.js'
|
|
26
|
+
import { focusDialog, handleDialogKeydown } from '../../internal/dialog-focus.js'
|
|
26
27
|
import { FORM_VISIBILITY_CONTEXT } from '../../internal/form-context.js'
|
|
27
28
|
import { uiM } from '../../messages.js'
|
|
28
|
-
import { cn,
|
|
29
|
+
import { cn, getDataAttributes } from '../../utils.js'
|
|
29
30
|
import IconButton from '../primitives/IconButton.svelte'
|
|
30
|
-
import ToggleCheckbox from '../primitives/ToggleCheckbox.svelte'
|
|
31
31
|
|
|
32
32
|
let {
|
|
33
33
|
open = $bindable(false),
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
resizable = false,
|
|
39
39
|
widthStorageKey,
|
|
40
40
|
closeOnBackdrop = true,
|
|
41
|
+
closeOnEscape = true,
|
|
41
42
|
showClose = true,
|
|
42
43
|
class: className = '',
|
|
43
44
|
onclose,
|
|
@@ -49,7 +50,19 @@
|
|
|
49
50
|
setContext(FORM_VISIBILITY_CONTEXT, {
|
|
50
51
|
get open() { return open },
|
|
51
52
|
})
|
|
52
|
-
const id =
|
|
53
|
+
const id = $props.id()
|
|
54
|
+
const titleId = `${id}-title`
|
|
55
|
+
let panel = $state<HTMLDivElement>()
|
|
56
|
+
let resizing = false
|
|
57
|
+
$effect(() => {
|
|
58
|
+
if (!open || !panel)
|
|
59
|
+
return
|
|
60
|
+
const restore = focusDialog(panel)
|
|
61
|
+
return () => {
|
|
62
|
+
finishResize()
|
|
63
|
+
restore()
|
|
64
|
+
}
|
|
65
|
+
})
|
|
53
66
|
/** 用户拖动后的像素宽度;优先于 width 与 size。 */
|
|
54
67
|
let resizedWidth = $state<number | null>(null)
|
|
55
68
|
/** 与响应式渲染解耦的同步宽度,确保 mouseup 时持久化最后一次 mousemove 的值。 */
|
|
@@ -106,6 +119,7 @@
|
|
|
106
119
|
)
|
|
107
120
|
|
|
108
121
|
function handleClose() {
|
|
122
|
+
finishResize()
|
|
109
123
|
open = false
|
|
110
124
|
onclose?.()
|
|
111
125
|
}
|
|
@@ -135,8 +149,9 @@
|
|
|
135
149
|
|
|
136
150
|
/** 结束拖动并在配置了 key 时记忆最终宽度。 */
|
|
137
151
|
function finishResize() {
|
|
138
|
-
if (typeof document === 'undefined')
|
|
152
|
+
if (typeof document === 'undefined' || !resizing)
|
|
139
153
|
return
|
|
154
|
+
resizing = false
|
|
140
155
|
|
|
141
156
|
globalThis.removeEventListener('mousemove', handleResizeMove)
|
|
142
157
|
globalThis.removeEventListener('mouseup', finishResize)
|
|
@@ -162,6 +177,7 @@
|
|
|
162
177
|
resizeStartWidth = drawer.getBoundingClientRect().width
|
|
163
178
|
resizeWidthForStorage = resizeStartWidth
|
|
164
179
|
previousUserSelect = document.documentElement.style.userSelect
|
|
180
|
+
resizing = true
|
|
165
181
|
document.documentElement.style.userSelect = 'none'
|
|
166
182
|
globalThis.addEventListener('mousemove', handleResizeMove)
|
|
167
183
|
globalThis.addEventListener('mouseup', finishResize, { once: true })
|
|
@@ -203,20 +219,22 @@
|
|
|
203
219
|
onDestroy(finishResize)
|
|
204
220
|
</script>
|
|
205
221
|
|
|
206
|
-
<div {...dataAttributes} class={drawerClass}
|
|
207
|
-
|
|
222
|
+
<div {...dataAttributes} class={drawerClass} role='presentation' onkeydown={(event) => {
|
|
223
|
+
if (open && panel)
|
|
224
|
+
handleDialogKeydown(event, panel, closeOnEscape ? handleClose : undefined)
|
|
225
|
+
}}>
|
|
226
|
+
<input {id} type='checkbox' class='drawer-toggle' tabindex='-1' aria-hidden='true' bind:checked={open} />
|
|
208
227
|
|
|
209
|
-
<div class={sideClass}>
|
|
210
|
-
<
|
|
211
|
-
|
|
212
|
-
tabindex='
|
|
228
|
+
<div class={sideClass} inert={!open}>
|
|
229
|
+
<button
|
|
230
|
+
type='button'
|
|
231
|
+
tabindex='-1'
|
|
213
232
|
aria-label={uiM('drawer_close')}
|
|
214
233
|
class='drawer-overlay'
|
|
215
234
|
onclick={handleBackdropClick}
|
|
216
|
-
|
|
217
|
-
></div>
|
|
235
|
+
></button>
|
|
218
236
|
|
|
219
|
-
<div class={contentClass} style={widthStyle}>
|
|
237
|
+
<div bind:this={panel} class={contentClass} style={widthStyle} role='dialog' aria-modal={open ? 'true' : undefined} aria-labelledby={title ? titleId : undefined} aria-label={title ? undefined : uiM('common_dialog')} tabindex='-1'>
|
|
220
238
|
{#if canResize}
|
|
221
239
|
<button
|
|
222
240
|
type='button'
|
|
@@ -230,7 +248,7 @@
|
|
|
230
248
|
|
|
231
249
|
<div class='flex items-center justify-between mb-4'>
|
|
232
250
|
{#if title}
|
|
233
|
-
<h3 class='text-lg font-bold'>{title}</h3>
|
|
251
|
+
<h3 id={titleId} class='text-lg font-bold'>{title}</h3>
|
|
234
252
|
{:else}
|
|
235
253
|
<div></div>
|
|
236
254
|
{/if}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component FilterBar
|
|
3
|
+
常用搜索与操作保持可见,更多筛选可展开收起;收起不卸载控件或清除值。
|
|
4
|
+
@example
|
|
5
|
+
```ts
|
|
6
|
+
import type { ComponentProps } from 'svelte'
|
|
7
|
+
import { FilterBar } from '@h-ai/ui/components/compounds/index'
|
|
8
|
+
const props: Pick<ComponentProps<typeof FilterBar>, 'expanded' | 'activeCount'> = { expanded: false, activeCount: 2 }
|
|
9
|
+
```
|
|
10
|
+
-->
|
|
11
|
+
<script lang='ts'>
|
|
12
|
+
import type { Snippet } from 'svelte'
|
|
13
|
+
import type { DataAttributes } from '../../types.js'
|
|
14
|
+
import { uiM } from '../../messages.js'
|
|
15
|
+
import { cn, getDataAttributes } from '../../utils.js'
|
|
16
|
+
import Button from '../primitives/Button.svelte'
|
|
17
|
+
|
|
18
|
+
/** FilterBar 组件的属性契约。
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import type { ComponentProps } from 'svelte'
|
|
22
|
+
* import { FilterBar } from '@h-ai/ui'
|
|
23
|
+
* const props: Partial<ComponentProps<typeof FilterBar>> = {}
|
|
24
|
+
* void props
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
interface Props extends DataAttributes {
|
|
28
|
+
/** 常驻搜索或主要条件。 */
|
|
29
|
+
leading?: Snippet
|
|
30
|
+
/** 查询、重置和业务操作。 */
|
|
31
|
+
actions?: Snippet
|
|
32
|
+
/** 可收起的筛选字段。 */
|
|
33
|
+
children?: Snippet
|
|
34
|
+
/** 是否展开;默认收起,可 bind:expanded。 */
|
|
35
|
+
expanded?: boolean
|
|
36
|
+
/** 已启用条件数量,收起时仍提示。 */
|
|
37
|
+
activeCount?: number
|
|
38
|
+
/** 清空查询与全部筛选;按钮文案由 UI 提供。 */
|
|
39
|
+
onreset?: () => void
|
|
40
|
+
class?: string
|
|
41
|
+
}
|
|
42
|
+
let { leading, actions, children, expanded = $bindable(false), activeCount = 0, onreset, class: className = '', ...restProps }: Props = $props()
|
|
43
|
+
const dataAttributes = $derived(getDataAttributes(restProps))
|
|
44
|
+
const panelId = $props.id()
|
|
45
|
+
const toggleLabel = $derived(uiM(expanded ? 'filter_bar_collapse' : 'filter_bar_expand'))
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<div {...dataAttributes} class={cn('hai-filter-bar min-w-0 space-y-2 [&_.fieldset]:m-0 [&_.fieldset]:min-w-0', className)}>
|
|
49
|
+
<div class='flex min-w-0 flex-wrap items-center gap-2'>
|
|
50
|
+
{#if leading}<div class='flex min-w-0 max-w-full flex-[1_1_14rem] flex-wrap items-center gap-2'>{@render leading()}</div>{/if}
|
|
51
|
+
<div class='ml-auto flex max-w-full shrink-0 flex-wrap items-center gap-2'>
|
|
52
|
+
{#if actions}{@render actions()}{/if}
|
|
53
|
+
{#if onreset}<Button type='button' variant='ghost' size='sm' onclick={onreset}>{uiM('crud_reset')}</Button>{/if}
|
|
54
|
+
{#if children}
|
|
55
|
+
<button type='button' class='hai-filter-bar__toggle inline-flex h-8 items-center gap-1.5 whitespace-nowrap rounded-md px-2 text-sm text-base-content/65 hover:bg-base-content/5 hover:text-base-content' aria-expanded={expanded} aria-controls={panelId} onclick={() => { expanded = !expanded }}>
|
|
56
|
+
<span>{toggleLabel}</span>
|
|
57
|
+
{#if activeCount > 0}<span class='rounded bg-primary/10 px-1.5 text-xs text-primary' aria-label={uiM('filter_bar_active').replace('{count}', String(activeCount))}>{activeCount}</span>{/if}
|
|
58
|
+
<span class='icon-[tabler--chevron-down] size-4 transition-transform' class:rotate-180={expanded} aria-hidden='true'></span>
|
|
59
|
+
</button>
|
|
60
|
+
{/if}
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
{#if children}
|
|
64
|
+
<div id={panelId} hidden={!expanded} class={expanded ? 'flex min-w-0 flex-wrap items-end gap-2 border-t border-base-content/8 pt-2' : 'hidden'}>
|
|
65
|
+
{@render children()}
|
|
66
|
+
</div>
|
|
67
|
+
{/if}
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
<style>
|
|
71
|
+
@media (pointer: coarse) {
|
|
72
|
+
.hai-filter-bar__toggle {
|
|
73
|
+
min-height: var(--hai-touch-target-min, 44px);
|
|
74
|
+
min-width: var(--hai-touch-target-min, 44px);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
</style>
|