@h-ai/ui 1.0.0-beta.12 → 1.0.0-beta.14
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 +9 -1
- package/README.ja.md +9 -1
- package/README.md +9 -1
- package/dist/components/compounds/BottomNav.svelte +8 -0
- package/dist/components/compounds/Combobox.svelte +18 -0
- package/dist/components/compounds/Dropdown.svelte +128 -59
- package/dist/components/compounds/Popover.svelte +68 -12
- package/dist/components/compounds/Steps.svelte +18 -6
- package/dist/components/compounds/Tabs.svelte +10 -0
- package/dist/components/compounds/TagInput.svelte +2 -0
- package/dist/components/compounds/Tooltip.svelte +1 -1
- package/dist/components/compounds/Tooltip.svelte.d.ts +1 -1
- package/dist/components/primitives/Checkbox.svelte +5 -0
- package/dist/components/primitives/Input.svelte +1 -1
- package/dist/components/primitives/Radio.svelte +1 -0
- package/dist/components/primitives/Tag.svelte +6 -10
- package/dist/components/scenes/app/ThemeSelector.svelte +7 -1
- package/dist/components/scenes/app/WorkspaceLayout.svelte +1 -1
- package/dist/components/scenes/iam/PasswordInput.svelte +1 -1
- package/dist/styles/global.css +16 -0
- package/dist/types.d.ts +2 -2
- package/package.json +2 -2
package/README.en.md
CHANGED
|
@@ -180,6 +180,8 @@ components/
|
|
|
180
180
|
| `Spinner` | Loading animation | `size`, `variant` |
|
|
181
181
|
| `Progress` | Progress bar | `value`, `max`, `variant`, `striped`, `animated` |
|
|
182
182
|
|
|
183
|
+
`Checkbox`, `Switch` and `Radio` default to the theme primary color, and their checked states follow the current DaisyUI theme; `Checkbox` colors can be overridden with a `checkbox-*` class.
|
|
184
|
+
|
|
183
185
|
For `BareInput` with `type="file"`, read `event.currentTarget.files` in `onchange` and leave the file path `value` unbound. Other input types support `bind:value`.
|
|
184
186
|
|
|
185
187
|
#### Compounds (37)
|
|
@@ -242,6 +244,8 @@ Text controls validate on blur after input and update errors as input is correct
|
|
|
242
244
|
| `Confirm` | Confirmation dialog | `open`, `title`, `message`, `variant`, `onconfirm` |
|
|
243
245
|
| `Popover` | Popover | `open`, `position`, `trigger`, `offset`, `portal` |
|
|
244
246
|
|
|
247
|
+
`Popover` renders in `body` by default. In `click` mode, Enter or Space opens the panel and moves focus into it. Escape closes the panel and returns focus to the trigger. Use `portal={false}` to render inline.
|
|
248
|
+
|
|
245
249
|
##### Data display
|
|
246
250
|
|
|
247
251
|
| Component | Description | Key props |
|
|
@@ -283,7 +287,9 @@ Text controls validate on blur after input and update errors as input is correct
|
|
|
283
287
|
| `Breadcrumb` | Breadcrumbs | `items`, `separator` |
|
|
284
288
|
| `Steps` | Steps | `items`, `current`, `direction`, `clickable` |
|
|
285
289
|
| `Dropdown` | Dropdown menu | `items`, `trigger`, `triggerClass`, `position` |
|
|
286
|
-
| `Tooltip` | Tooltip | `content`, `position`, `delay` |
|
|
290
|
+
| `Tooltip` | Tooltip | `content`, `position`, `delay`, `portal` (use inside overflow-clipped containers) |
|
|
291
|
+
|
|
292
|
+
`Dropdown` renders the menu in `body` in `click` and `hover` modes. In `manual` mode, toggle `dropdown-open` through `class` to control the inline menu.
|
|
287
293
|
|
|
288
294
|
##### State placeholders
|
|
289
295
|
|
|
@@ -722,6 +728,8 @@ On mobile pages, match `BottomNav` width to the page shell to avoid spanning the
|
|
|
722
728
|
</div>
|
|
723
729
|
```
|
|
724
730
|
|
|
731
|
+
`BottomNav` and `ThemeSelector` keep their trigger buttons disabled until the client has mounted and the event handlers are ready.
|
|
732
|
+
|
|
725
733
|
#### Icons
|
|
726
734
|
|
|
727
735
|
Components use Iconify (Tabler Icons):
|
package/README.ja.md
CHANGED
|
@@ -180,6 +180,8 @@ components/
|
|
|
180
180
|
| `Spinner` | 読み込み表示 | `size`, `variant` |
|
|
181
181
|
| `Progress` | プログレスバー | `value`, `max`, `variant`, `striped`, `animated` |
|
|
182
182
|
|
|
183
|
+
`Checkbox`・`Switch`・`Radio` は既定でテーマの primary 色を使用し、選択状態は現在の DaisyUI テーマに追従します。`Checkbox` は `checkbox-*` クラスで色を上書きできます。
|
|
184
|
+
|
|
183
185
|
`BareInput` の `type="file"` では `onchange` の `event.currentTarget.files` を読み取り、ファイルパスの `value` はバインドしません。他の入力型では `bind:value` を使用できます。
|
|
184
186
|
|
|
185
187
|
#### Compounds:複合コンポーネント(37)
|
|
@@ -242,6 +244,8 @@ components/
|
|
|
242
244
|
| `Confirm` | 確認ダイアログ | `open`, `title`, `message`, `variant`, `onconfirm` |
|
|
243
245
|
| `Popover` | ポップオーバー | `open`, `position`, `trigger`, `offset`, `portal` |
|
|
244
246
|
|
|
247
|
+
`Popover` は既定で `body` に描画されます。`click` モードでは Enter または Space で開くとパネルにフォーカスが移り、Escape で閉じるとトリガーに戻ります。インラインで描画する場合は `portal={false}` を指定します。
|
|
248
|
+
|
|
245
249
|
##### データ表示
|
|
246
250
|
|
|
247
251
|
| コンポーネント | 説明 | 主なプロパティ |
|
|
@@ -283,7 +287,9 @@ components/
|
|
|
283
287
|
| `Breadcrumb` | パンくず | `items`, `separator` |
|
|
284
288
|
| `Steps` | ステップ | `items`, `current`, `direction`, `clickable` |
|
|
285
289
|
| `Dropdown` | ドロップダウンメニュー | `items`, `trigger`, `triggerClass`, `position` |
|
|
286
|
-
| `Tooltip` | ツールチップ | `content`, `position`, `delay` |
|
|
290
|
+
| `Tooltip` | ツールチップ | `content`, `position`, `delay`, `portal`(クリップされるコンテナ内で使用) |
|
|
291
|
+
|
|
292
|
+
`Dropdown` の `click` と `hover` モードではメニューが `body` に描画されます。`manual` モードでは `class` の `dropdown-open` を切り替えてインラインメニューの開閉を制御します。
|
|
287
293
|
|
|
288
294
|
##### 状態表示
|
|
289
295
|
|
|
@@ -722,6 +728,8 @@ toast.add({ message: m.saved(), position: 'bottom-center' })
|
|
|
722
728
|
</div>
|
|
723
729
|
```
|
|
724
730
|
|
|
731
|
+
`BottomNav` と `ThemeSelector` のボタンは、クライアントでのマウントが完了し、イベントを処理できる状態になってから有効になります。
|
|
732
|
+
|
|
725
733
|
#### アイコン
|
|
726
734
|
|
|
727
735
|
Iconify(Tabler Icons)を使用します:
|
package/README.md
CHANGED
|
@@ -180,6 +180,8 @@ components/
|
|
|
180
180
|
| `Spinner` | 加载动画 | `size`, `variant` |
|
|
181
181
|
| `Progress` | 进度条 | `value`, `max`, `variant`, `striped`, `animated` |
|
|
182
182
|
|
|
183
|
+
`Checkbox`、`Switch` 和 `Radio` 默认使用主题主色,选中态跟随当前 DaisyUI 主题;`Checkbox` 可用 `checkbox-*` 类名覆盖颜色。
|
|
184
|
+
|
|
183
185
|
`BareInput` 的 `file` 类型通过 `onchange` 读取 `event.currentTarget.files`,不绑定文件路径 `value`;其他输入类型可使用 `bind:value`。
|
|
184
186
|
|
|
185
187
|
#### 组合组件 Compounds(37 个)
|
|
@@ -242,6 +244,8 @@ components/
|
|
|
242
244
|
| `Confirm` | 确认框 | `open`, `title`, `message`, `variant`, `onconfirm` |
|
|
243
245
|
| `Popover` | 弹出层 | `open`, `position`, `trigger`, `offset`, `portal` |
|
|
244
246
|
|
|
247
|
+
`Popover` 默认挂载到 `body`。在 `click` 模式下按 Enter 或空格打开后,焦点进入面板,按 Escape 关闭并返回触发控件。需要内联挂载时使用 `portal={false}`。
|
|
248
|
+
|
|
245
249
|
##### 数据展示
|
|
246
250
|
|
|
247
251
|
| 组件 | 描述 | 主要属性 |
|
|
@@ -283,7 +287,9 @@ components/
|
|
|
283
287
|
| `Breadcrumb` | 面包屑 | `items`, `separator` |
|
|
284
288
|
| `Steps` | 步骤条 | `items`, `current`, `direction`, `clickable` |
|
|
285
289
|
| `Dropdown` | 下拉菜单 | `items`, `trigger`, `triggerClass`, `position` |
|
|
286
|
-
| `Tooltip` | 提示 | `content`, `position`, `delay` |
|
|
290
|
+
| `Tooltip` | 提示 | `content`, `position`, `delay`, `portal`(裁剪容器内使用) |
|
|
291
|
+
|
|
292
|
+
`Dropdown` 的 `click` 和 `hover` 模式将菜单挂载到 `body`。在 `manual` 模式下,调用方通过 `class` 切换 `dropdown-open` 来控制内联菜单。
|
|
287
293
|
|
|
288
294
|
##### 状态占位
|
|
289
295
|
|
|
@@ -721,6 +727,8 @@ toast.add({ message: m.saved(), position: 'bottom-center' })
|
|
|
721
727
|
</div>
|
|
722
728
|
```
|
|
723
729
|
|
|
730
|
+
`BottomNav` 的导航按钮与 `ThemeSelector` 的主题按钮在客户端挂载后启用,确保点击时事件已绑定。
|
|
731
|
+
|
|
724
732
|
#### 图标
|
|
725
733
|
|
|
726
734
|
组件使用 Iconify (Tabler Icons):
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
<script lang='ts'>
|
|
19
19
|
import type { DataAttributes } from '../../types.js'
|
|
20
20
|
import type { BottomNavItem } from './bottom-nav-types.js'
|
|
21
|
+
import { onMount } from 'svelte'
|
|
21
22
|
import { cn, getDataAttributes } from '../../utils.js'
|
|
22
23
|
|
|
23
24
|
// eslint-disable-next-line no-import-assign -- type re-export
|
|
@@ -89,6 +90,12 @@
|
|
|
89
90
|
|
|
90
91
|
const dataAttributes = $derived(getDataAttributes(restProps))
|
|
91
92
|
const constrained = $derived(centered && maxWidth !== 'none')
|
|
93
|
+
|
|
94
|
+
// 服务端已渲染导航时,先等待客户端绑定事件,避免提前点击丢失。
|
|
95
|
+
let ready = $state(false)
|
|
96
|
+
onMount(() => {
|
|
97
|
+
ready = true
|
|
98
|
+
})
|
|
92
99
|
</script>
|
|
93
100
|
|
|
94
101
|
<nav {...dataAttributes}
|
|
@@ -104,6 +111,7 @@
|
|
|
104
111
|
{#each items as item (item.id)}
|
|
105
112
|
<button
|
|
106
113
|
type='button'
|
|
114
|
+
disabled={!ready}
|
|
107
115
|
class={cn(
|
|
108
116
|
'flex flex-col items-center justify-center flex-1 h-full relative transition-colors',
|
|
109
117
|
'hai-no-select',
|
|
@@ -135,6 +135,10 @@
|
|
|
135
135
|
|
|
136
136
|
let searchValue = $state('')
|
|
137
137
|
let open = $state(false)
|
|
138
|
+
// 多选触发器宽度:标签会挤占内层 input,弹出层仍应与整个输入框等宽。
|
|
139
|
+
let triggerWidth = $state(0)
|
|
140
|
+
let fieldEl = $state<HTMLDivElement | null>(null)
|
|
141
|
+
let anchorOffset = $state(0)
|
|
138
142
|
let inputRef = $state<HTMLInputElement | null>(null)
|
|
139
143
|
|
|
140
144
|
/** 根据搜索关键词过滤选项 */
|
|
@@ -185,6 +189,15 @@
|
|
|
185
189
|
syncInputElementValue()
|
|
186
190
|
})
|
|
187
191
|
|
|
192
|
+
// 多选时 input 从标签后开始,按其在字段内的左偏移把弹出层对齐到字段左边。
|
|
193
|
+
$effect(() => {
|
|
194
|
+
void multiVal.length
|
|
195
|
+
void triggerWidth
|
|
196
|
+
if (!open || !fieldEl || !inputRef)
|
|
197
|
+
return
|
|
198
|
+
anchorOffset = -Math.round(inputRef.getBoundingClientRect().left - fieldEl.getBoundingClientRect().left)
|
|
199
|
+
})
|
|
200
|
+
|
|
188
201
|
function handleInput(e: Event & { currentTarget: HTMLInputElement }) {
|
|
189
202
|
searchValue = e.currentTarget.value
|
|
190
203
|
if (!open)
|
|
@@ -244,6 +257,8 @@
|
|
|
244
257
|
>
|
|
245
258
|
<div class='relative'>
|
|
246
259
|
<div
|
|
260
|
+
bind:this={fieldEl}
|
|
261
|
+
bind:clientWidth={triggerWidth}
|
|
247
262
|
class={cn(
|
|
248
263
|
'rounded-lg border bg-base-100 flex flex-wrap gap-1.5 items-center py-1 pl-2.5 pr-9 transition-[border-color,box-shadow] duration-150',
|
|
249
264
|
sizeClasses.minHeight,
|
|
@@ -293,6 +308,9 @@
|
|
|
293
308
|
<Combobox.Portal>
|
|
294
309
|
<Combobox.Content
|
|
295
310
|
class={contentClass}
|
|
311
|
+
align='start'
|
|
312
|
+
alignOffset={anchorOffset}
|
|
313
|
+
style={triggerWidth > 0 ? `--bits-combobox-anchor-width:${triggerWidth}px` : undefined}
|
|
296
314
|
sideOffset={4}
|
|
297
315
|
>
|
|
298
316
|
{#if filteredOptions.length === 0}
|
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
```
|
|
14
14
|
-->
|
|
15
15
|
<script lang='ts'>
|
|
16
|
-
import type { DataAttributes, DropdownProps } from '../../types.js'
|
|
16
|
+
import type { DataAttributes, DropdownItem, DropdownProps } from '../../types.js'
|
|
17
|
+
import { DropdownMenu } from 'bits-ui'
|
|
18
|
+
import { onDestroy } from 'svelte'
|
|
17
19
|
import { cn, getDataAttributes } from '../../utils.js'
|
|
18
20
|
import BareButton from '../primitives/BareButton.svelte'
|
|
19
21
|
|
|
@@ -30,76 +32,143 @@
|
|
|
30
32
|
}: DropdownProps & DataAttributes = $props()
|
|
31
33
|
|
|
32
34
|
const dataAttributes = $derived(getDataAttributes(restProps))
|
|
33
|
-
|
|
35
|
+
const manualClass = $derived(cn(
|
|
36
|
+
'dropdown',
|
|
37
|
+
{ top: 'dropdown-top', right: 'dropdown-right', bottom: 'dropdown-bottom', left: 'dropdown-left' }[position],
|
|
38
|
+
{ start: 'dropdown-start', center: '', end: 'dropdown-end' }[align],
|
|
39
|
+
))
|
|
40
|
+
let open = $state(false)
|
|
41
|
+
let openTimer: ReturnType<typeof setTimeout> | undefined
|
|
42
|
+
let closeTimer: ReturnType<typeof setTimeout> | undefined
|
|
34
43
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
bottom: 'dropdown-bottom',
|
|
39
|
-
left: 'dropdown-left',
|
|
44
|
+
function clearTimers() {
|
|
45
|
+
clearTimeout(openTimer)
|
|
46
|
+
clearTimeout(closeTimer)
|
|
40
47
|
}
|
|
41
48
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
center: '',
|
|
45
|
-
end: 'dropdown-end',
|
|
49
|
+
function canHover() {
|
|
50
|
+
return typeof window !== 'undefined' && typeof window.matchMedia === 'function' && window.matchMedia('(hover: hover)').matches
|
|
46
51
|
}
|
|
47
52
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
function scheduleOpen() {
|
|
54
|
+
if (trigger !== 'hover' || !canHover())
|
|
55
|
+
return
|
|
56
|
+
clearTimers()
|
|
57
|
+
if (!open) {
|
|
58
|
+
openTimer = setTimeout(() => {
|
|
59
|
+
open = true
|
|
60
|
+
}, 100)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function scheduleClose() {
|
|
65
|
+
if (trigger !== 'hover')
|
|
66
|
+
return
|
|
67
|
+
clearTimers()
|
|
68
|
+
closeTimer = setTimeout(() => {
|
|
69
|
+
open = false
|
|
70
|
+
}, 140)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function handleWrapperLeave(event: PointerEvent) {
|
|
74
|
+
if (trigger !== 'hover')
|
|
75
|
+
return
|
|
76
|
+
const rect = (event.currentTarget as HTMLElement | null)?.getBoundingClientRect()
|
|
77
|
+
if (!rect)
|
|
78
|
+
return
|
|
79
|
+
const { clientX, clientY } = event
|
|
80
|
+
if (clientX >= rect.left && clientX <= rect.right && clientY >= rect.top && clientY <= rect.bottom)
|
|
81
|
+
return
|
|
82
|
+
scheduleClose()
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function handleOpenChange(next: boolean) {
|
|
86
|
+
open = next
|
|
87
|
+
if (!next)
|
|
88
|
+
clearTimers()
|
|
89
|
+
}
|
|
58
90
|
|
|
59
91
|
function handleSelect(key: string) {
|
|
60
|
-
|
|
92
|
+
open = false
|
|
61
93
|
onselect?.(key)
|
|
62
94
|
}
|
|
63
95
|
|
|
64
|
-
|
|
65
|
-
if (trigger === 'click') {
|
|
66
|
-
isOpen = !isOpen
|
|
67
|
-
}
|
|
68
|
-
}
|
|
96
|
+
onDestroy(clearTimers)
|
|
69
97
|
</script>
|
|
70
98
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
onkeydown={e => e.key === 'Enter' && toggleDropdown()}
|
|
78
|
-
>
|
|
79
|
-
{#if children}
|
|
80
|
-
{@render children()}
|
|
81
|
-
{/if}
|
|
82
|
-
</BareButton>
|
|
99
|
+
{#snippet itemContents(item: DropdownItem)}
|
|
100
|
+
{#if item.icon}
|
|
101
|
+
<span>{item.icon}</span>
|
|
102
|
+
{/if}
|
|
103
|
+
{item.label}
|
|
104
|
+
{/snippet}
|
|
83
105
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
>
|
|
96
|
-
{#if item.icon}
|
|
97
|
-
<span>{item.icon}</span>
|
|
98
|
-
{/if}
|
|
99
|
-
{item.label}
|
|
100
|
-
</BareButton>
|
|
101
|
-
</li>
|
|
106
|
+
<div
|
|
107
|
+
{...dataAttributes}
|
|
108
|
+
class={cn(trigger === 'manual' ? manualClass : 'relative inline-block', className)}
|
|
109
|
+
onpointerenter={scheduleOpen}
|
|
110
|
+
onpointerleave={handleWrapperLeave}
|
|
111
|
+
>
|
|
112
|
+
{#if trigger === 'manual'}
|
|
113
|
+
<!-- 调用方使用 dropdown-open 控制内联菜单。 -->
|
|
114
|
+
<BareButton type='button' class={triggerClass}>
|
|
115
|
+
{#if children}
|
|
116
|
+
{@render children()}
|
|
102
117
|
{/if}
|
|
103
|
-
|
|
104
|
-
|
|
118
|
+
</BareButton>
|
|
119
|
+
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
120
|
+
<ul tabindex='0' class='manual-menu dropdown-content menu bg-base-100 rounded-xl z-[var(--hai-z-dropdown,1000)] w-52 p-1.5 shadow-lg border border-base-content/6'>
|
|
121
|
+
{#each items as item, index (item.key || `divider-${index}`)}
|
|
122
|
+
{#if item.divider}
|
|
123
|
+
<li class='divider'></li>
|
|
124
|
+
{:else}
|
|
125
|
+
<li>
|
|
126
|
+
<BareButton type='button' class='w-full text-left text-[13px] rounded-lg' disabled={item.disabled} onclick={() => handleSelect(item.key)}>
|
|
127
|
+
{@render itemContents(item)}
|
|
128
|
+
</BareButton>
|
|
129
|
+
</li>
|
|
130
|
+
{/if}
|
|
131
|
+
{/each}
|
|
132
|
+
</ul>
|
|
133
|
+
{:else}
|
|
134
|
+
<DropdownMenu.Root {open} onOpenChange={handleOpenChange}>
|
|
135
|
+
<DropdownMenu.Trigger type='button' class={triggerClass}>
|
|
136
|
+
{#if children}
|
|
137
|
+
{@render children()}
|
|
138
|
+
{/if}
|
|
139
|
+
</DropdownMenu.Trigger>
|
|
140
|
+
|
|
141
|
+
<DropdownMenu.Portal>
|
|
142
|
+
<DropdownMenu.Content
|
|
143
|
+
side={position}
|
|
144
|
+
{align}
|
|
145
|
+
sideOffset={0}
|
|
146
|
+
class='dropdown-content bg-base-100 rounded-xl z-[var(--hai-z-dropdown,1000)] w-52 p-1.5 shadow-lg border border-base-content/6 outline-none animate-[hai-scale-in_0.15s_cubic-bezier(0.16,1,0.3,1)]'
|
|
147
|
+
onpointerenter={() => clearTimeout(closeTimer)}
|
|
148
|
+
onpointerleave={scheduleClose}
|
|
149
|
+
>
|
|
150
|
+
{#each items as item, index (item.key || `divider-${index}`)}
|
|
151
|
+
{#if item.divider}
|
|
152
|
+
<DropdownMenu.Separator class='divider my-4' />
|
|
153
|
+
{:else}
|
|
154
|
+
<DropdownMenu.Item
|
|
155
|
+
class='flex w-full cursor-pointer items-center gap-2 rounded-lg px-3 py-1.5 text-left text-[13px] outline-none select-none data-[highlighted]:bg-base-content/10 data-[disabled]:pointer-events-none data-[disabled]:opacity-40'
|
|
156
|
+
disabled={item.disabled}
|
|
157
|
+
onSelect={() => handleSelect(item.key)}
|
|
158
|
+
>
|
|
159
|
+
{@render itemContents(item)}
|
|
160
|
+
</DropdownMenu.Item>
|
|
161
|
+
{/if}
|
|
162
|
+
{/each}
|
|
163
|
+
</DropdownMenu.Content>
|
|
164
|
+
</DropdownMenu.Portal>
|
|
165
|
+
</DropdownMenu.Root>
|
|
166
|
+
{/if}
|
|
105
167
|
</div>
|
|
168
|
+
|
|
169
|
+
<style>
|
|
170
|
+
/* 手动菜单只响应调用方状态,避免 DaisyUI 在触发按钮聚焦时自动展开。 */
|
|
171
|
+
:global(.dropdown:not(.dropdown-open)) > .manual-menu {
|
|
172
|
+
display: none;
|
|
173
|
+
}
|
|
174
|
+
</style>
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
-->
|
|
21
21
|
<script lang='ts'>
|
|
22
22
|
import type { DataAttributes, PopoverProps } from '../../types.js'
|
|
23
|
-
import { tick } from 'svelte'
|
|
23
|
+
import { onDestroy, tick } from 'svelte'
|
|
24
24
|
import { cn, getDataAttributes, portal as portalAction } from '../../utils.js'
|
|
25
25
|
|
|
26
26
|
let {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
position = 'bottom',
|
|
29
29
|
trigger = 'click',
|
|
30
30
|
offset = 8,
|
|
31
|
-
portal =
|
|
31
|
+
portal = true,
|
|
32
32
|
class: className = '',
|
|
33
33
|
onopen,
|
|
34
34
|
onclose,
|
|
@@ -44,6 +44,8 @@
|
|
|
44
44
|
let portalStyle = $state('')
|
|
45
45
|
/** 首帧布局收敛后的二次定位帧,关闭时必须取消避免过期写入。 */
|
|
46
46
|
let portalPositionFrame: number | undefined = $state()
|
|
47
|
+
let closeTimer: ReturnType<typeof setTimeout> | undefined
|
|
48
|
+
let returnFocus: HTMLElement | null = null
|
|
47
49
|
|
|
48
50
|
const positionClass = $derived({
|
|
49
51
|
top: 'bottom-full left-1/2 -translate-x-1/2 mb-2',
|
|
@@ -96,6 +98,10 @@
|
|
|
96
98
|
return
|
|
97
99
|
}
|
|
98
100
|
|
|
101
|
+
if (typeof window.requestAnimationFrame !== 'function') {
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
|
|
99
105
|
portalPositionFrame = window.requestAnimationFrame(() => {
|
|
100
106
|
portalPositionFrame = undefined
|
|
101
107
|
if (open && portal) {
|
|
@@ -114,29 +120,67 @@
|
|
|
114
120
|
onclose?.()
|
|
115
121
|
}
|
|
116
122
|
|
|
117
|
-
function handleTriggerClick() {
|
|
118
|
-
if (trigger
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
async function handleTriggerClick(): Promise<void> {
|
|
124
|
+
if (trigger !== 'click')
|
|
125
|
+
return
|
|
126
|
+
if (open) {
|
|
127
|
+
handleClose()
|
|
128
|
+
return
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const active = document.activeElement
|
|
132
|
+
returnFocus = active instanceof HTMLElement && triggerElement?.contains(active) ? active : triggerElement
|
|
133
|
+
handleOpen()
|
|
134
|
+
await tick()
|
|
135
|
+
if (open)
|
|
136
|
+
popoverElement?.focus({ preventScroll: true })
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function handleEscape(event: KeyboardEvent): void {
|
|
140
|
+
if (event.key !== 'Escape' || !open)
|
|
141
|
+
return
|
|
142
|
+
event.preventDefault()
|
|
143
|
+
event.stopPropagation()
|
|
144
|
+
handleClose()
|
|
145
|
+
returnFocus?.focus({ preventScroll: true })
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function handleTriggerKeydown(event: KeyboardEvent): void {
|
|
149
|
+
// 插槽中的原生按钮会自行触发 click,只处理包装层本身的键盘激活。
|
|
150
|
+
if (event.target === event.currentTarget && trigger === 'click' && (event.key === 'Enter' || event.key === ' ')) {
|
|
151
|
+
event.preventDefault()
|
|
152
|
+
void handleTriggerClick()
|
|
125
153
|
}
|
|
154
|
+
handleEscape(event)
|
|
126
155
|
}
|
|
127
156
|
|
|
128
157
|
function handleMouseEnter() {
|
|
129
158
|
if (trigger === 'hover') {
|
|
159
|
+
cancelClose()
|
|
130
160
|
handleOpen()
|
|
131
161
|
}
|
|
132
162
|
}
|
|
133
163
|
|
|
134
164
|
function handleMouseLeave() {
|
|
135
165
|
if (trigger === 'hover') {
|
|
136
|
-
|
|
166
|
+
scheduleClose()
|
|
137
167
|
}
|
|
138
168
|
}
|
|
139
169
|
|
|
170
|
+
function scheduleClose() {
|
|
171
|
+
cancelClose()
|
|
172
|
+
closeTimer = setTimeout(() => {
|
|
173
|
+
handleClose()
|
|
174
|
+
}, 140)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function cancelClose() {
|
|
178
|
+
clearTimeout(closeTimer)
|
|
179
|
+
closeTimer = undefined
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
onDestroy(cancelClose)
|
|
183
|
+
|
|
140
184
|
function handleClickOutside(e: MouseEvent) {
|
|
141
185
|
if (
|
|
142
186
|
open
|
|
@@ -193,7 +237,9 @@
|
|
|
193
237
|
onclick={handleTriggerClick}
|
|
194
238
|
role='button'
|
|
195
239
|
tabindex='0'
|
|
196
|
-
|
|
240
|
+
aria-haspopup='dialog'
|
|
241
|
+
aria-expanded={open}
|
|
242
|
+
onkeydown={handleTriggerKeydown}
|
|
197
243
|
>
|
|
198
244
|
{#if triggerContent}
|
|
199
245
|
{@render triggerContent()}
|
|
@@ -209,7 +255,13 @@
|
|
|
209
255
|
class='fixed z-50 rounded-box border border-base-200 bg-base-100 p-4 shadow-lg'
|
|
210
256
|
style={portalStyle}
|
|
211
257
|
role='dialog'
|
|
258
|
+
tabindex='-1'
|
|
259
|
+
onkeydown={handleEscape}
|
|
260
|
+
onmouseenter={cancelClose}
|
|
261
|
+
onmouseleave={handleMouseLeave}
|
|
212
262
|
>
|
|
263
|
+
<div class={cn('absolute w-0 h-0 border-8', arrowClass)}></div>
|
|
264
|
+
|
|
213
265
|
{#if children}
|
|
214
266
|
{@render children()}
|
|
215
267
|
{/if}
|
|
@@ -223,6 +275,10 @@
|
|
|
223
275
|
)}
|
|
224
276
|
style='--offset: {offset}px'
|
|
225
277
|
role='dialog'
|
|
278
|
+
tabindex='-1'
|
|
279
|
+
onkeydown={handleEscape}
|
|
280
|
+
onmouseenter={cancelClose}
|
|
281
|
+
onmouseleave={handleMouseLeave}
|
|
226
282
|
>
|
|
227
283
|
<!-- 箭头 -->
|
|
228
284
|
<div class={cn('absolute w-0 h-0 border-8', arrowClass)}></div>
|
|
@@ -36,7 +36,6 @@
|
|
|
36
36
|
const dataAttributes = $derived(getDataAttributes(restProps))
|
|
37
37
|
const containerClass = $derived(
|
|
38
38
|
cn(
|
|
39
|
-
'steps',
|
|
40
39
|
direction === 'vertical' && 'steps-vertical',
|
|
41
40
|
className,
|
|
42
41
|
),
|
|
@@ -60,11 +59,10 @@
|
|
|
60
59
|
function getStepClass(index: number) {
|
|
61
60
|
const status = getStepStatus(index)
|
|
62
61
|
return cn(
|
|
63
|
-
'step',
|
|
64
62
|
stepSizeClass,
|
|
65
63
|
status === 'completed' && 'step-primary',
|
|
66
64
|
status === 'current' && 'step-primary',
|
|
67
|
-
clickable && 'cursor-pointer
|
|
65
|
+
clickable && 'cursor-pointer',
|
|
68
66
|
)
|
|
69
67
|
}
|
|
70
68
|
|
|
@@ -75,12 +73,12 @@
|
|
|
75
73
|
}
|
|
76
74
|
</script>
|
|
77
75
|
|
|
78
|
-
<ul {...dataAttributes} class={containerClass}>
|
|
76
|
+
<ul {...dataAttributes} class='steps {containerClass}'>
|
|
79
77
|
{#each items as item, index (index)}
|
|
80
78
|
{#if clickable}
|
|
81
79
|
<!-- svelte-ignore a11y_no_noninteractive_element_to_interactive_role -->
|
|
82
80
|
<li
|
|
83
|
-
class={getStepClass(index)}
|
|
81
|
+
class='step {getStepClass(index)}'
|
|
84
82
|
data-content={item.icon || (index < current ? '✓' : index + 1)}
|
|
85
83
|
onclick={() => handleClick(index)}
|
|
86
84
|
onkeydown={e => e.key === 'Enter' && handleClick(index)}
|
|
@@ -96,7 +94,7 @@
|
|
|
96
94
|
</li>
|
|
97
95
|
{:else}
|
|
98
96
|
<li
|
|
99
|
-
class={getStepClass(index)}
|
|
97
|
+
class='step {getStepClass(index)}'
|
|
100
98
|
data-content={item.icon || (index < current ? '✓' : index + 1)}
|
|
101
99
|
>
|
|
102
100
|
<div class='step-content'>
|
|
@@ -118,6 +116,20 @@
|
|
|
118
116
|
text-align: left;
|
|
119
117
|
}
|
|
120
118
|
|
|
119
|
+
.step[role='button']:hover::after,
|
|
120
|
+
.step[role='button']:hover>.step-icon {
|
|
121
|
+
background-color: color-mix(in oklab, var(--step-bg) 78%, var(--color-base-100));
|
|
122
|
+
border-color: color-mix(in oklab, var(--step-bg) 78%, var(--color-base-100));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.steps:not(.steps-vertical) .step-content {
|
|
126
|
+
align-self: start;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.step[role='button']:hover .step-content>span {
|
|
130
|
+
color: var(--color-primary);
|
|
131
|
+
}
|
|
132
|
+
|
|
121
133
|
.steps-vertical .step-content {
|
|
122
134
|
margin-left: 0.5rem;
|
|
123
135
|
}
|
|
@@ -147,3 +147,13 @@
|
|
|
147
147
|
{@render children({ active, isActivated })}
|
|
148
148
|
</div>
|
|
149
149
|
{/if}
|
|
150
|
+
|
|
151
|
+
<style>
|
|
152
|
+
/* 禁用 tab 需要显示不可用指针;DaisyUI 的 hover 会恢复文字颜色,这里保持禁用外观。 */
|
|
153
|
+
button[disabled],
|
|
154
|
+
button[disabled]:hover {
|
|
155
|
+
pointer-events: auto;
|
|
156
|
+
cursor: not-allowed;
|
|
157
|
+
color: color-mix(in oklab, var(--color-base-content) 50%, transparent);
|
|
158
|
+
}
|
|
159
|
+
</style>
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
=============================================================================
|
|
6
6
|
提示框组件,支持两种渲染模式:
|
|
7
7
|
- 默认:DaisyUI CSS 伪元素(::before),轻量无 JS 开销
|
|
8
|
-
- portal:通过 document.body 渲染,不受父容器 overflow
|
|
8
|
+
- portal:通过 document.body 渲染,不受父容器 overflow 裁剪;在 overflow 裁剪容器内请显式传入 `portal`
|
|
9
9
|
|
|
10
10
|
使用 Svelte 5 Runes ($props, $derived)
|
|
11
11
|
=============================================================================
|
|
@@ -7,7 +7,7 @@ type $$ComponentProps = TooltipProps & DataAttributes;
|
|
|
7
7
|
* =============================================================================
|
|
8
8
|
* 提示框组件,支持两种渲染模式:
|
|
9
9
|
* - 默认:DaisyUI CSS 伪元素(::before),轻量无 JS 开销
|
|
10
|
-
* - portal:通过 document.body 渲染,不受父容器 overflow
|
|
10
|
+
* - portal:通过 document.body 渲染,不受父容器 overflow 裁剪;在 overflow 裁剪容器内请显式传入 `portal`
|
|
11
11
|
*
|
|
12
12
|
* 使用 Svelte 5 Runes ($props, $derived)
|
|
13
13
|
* =============================================================================
|
|
@@ -41,10 +41,15 @@
|
|
|
41
41
|
const uniqueId = $props.id()
|
|
42
42
|
const id = $derived(providedId ?? uniqueId)
|
|
43
43
|
|
|
44
|
+
const hasCheckboxColorVariant = $derived(
|
|
45
|
+
/\bcheckbox-(?:primary|secondary|accent|neutral|success|warning|info|error)\b/.test(className),
|
|
46
|
+
)
|
|
47
|
+
|
|
44
48
|
const checkboxClass = $derived(
|
|
45
49
|
cn(
|
|
46
50
|
'checkbox',
|
|
47
51
|
getSizeClass(size, 'checkbox'),
|
|
52
|
+
!hasCheckboxColorVariant && 'checkbox-primary',
|
|
48
53
|
className,
|
|
49
54
|
),
|
|
50
55
|
)
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
|
|
76
76
|
const containerClass = $derived(
|
|
77
77
|
cn(
|
|
78
|
-
'flex items-center w-full rounded-lg border bg-base-100',
|
|
78
|
+
'flex items-center w-full rounded-lg border bg-base-100 overflow-hidden',
|
|
79
79
|
sizeClasses.height,
|
|
80
80
|
effectiveError
|
|
81
81
|
? 'border-error/60 focus-within:ring-2 focus-within:ring-error/15'
|
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
<script lang='ts'>
|
|
22
22
|
import type { DataAttributes, TagProps } from '../../types.js'
|
|
23
23
|
import { cn, getDataAttributes, getSizeClass, getVariantClass } from '../../utils.js'
|
|
24
|
-
import IconButton from './IconButton.svelte'
|
|
25
24
|
|
|
26
25
|
const {
|
|
27
26
|
text = '',
|
|
@@ -62,16 +61,13 @@
|
|
|
62
61
|
{/if}
|
|
63
62
|
|
|
64
63
|
{#if closable}
|
|
65
|
-
<
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
<button
|
|
65
|
+
type='button'
|
|
66
|
+
class='-mr-1 flex size-4 shrink-0 items-center justify-center rounded-full text-current/70 transition-colors hover:bg-current/15 hover:text-current focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-current/40'
|
|
67
|
+
aria-label={removeLabel}
|
|
69
68
|
onclick={handleClose}
|
|
70
|
-
ariaLabel={removeLabel}
|
|
71
69
|
>
|
|
72
|
-
<
|
|
73
|
-
|
|
74
|
-
</svg>
|
|
75
|
-
</IconButton>
|
|
70
|
+
<span class='icon-[tabler--x] size-3' aria-hidden='true'></span>
|
|
71
|
+
</button>
|
|
76
72
|
{/if}
|
|
77
73
|
</span>
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
<script lang='ts'>
|
|
21
21
|
import type { ThemeInfo } from '../../../theme-config.js'
|
|
22
22
|
import type { DataAttributes } from '../../../types.js'
|
|
23
|
-
import { tick } from 'svelte'
|
|
23
|
+
import { onMount, tick } from 'svelte'
|
|
24
24
|
import { uiM } from '../../../messages.js'
|
|
25
25
|
import { THEME_GROUPS, THEMES } from '../../../theme-config.js'
|
|
26
26
|
import { cn, getDataAttributes } from '../../../utils.js'
|
|
@@ -68,6 +68,11 @@
|
|
|
68
68
|
const displaySelectLabel = $derived(selectLabel ?? uiM('theme_selector_label'))
|
|
69
69
|
const menuId = $props.id()
|
|
70
70
|
|
|
71
|
+
// SSR 先渲染按钮,等客户端绑定点击和键盘事件后再启用。
|
|
72
|
+
let ready = $state(false)
|
|
73
|
+
onMount(() => {
|
|
74
|
+
ready = true
|
|
75
|
+
})
|
|
71
76
|
let open = $state(false)
|
|
72
77
|
let containerRef = $state<HTMLDivElement | null>(null)
|
|
73
78
|
|
|
@@ -135,6 +140,7 @@
|
|
|
135
140
|
<div {...dataAttributes} bind:this={containerRef} class={cn('dropdown', align === 'end' ? 'dropdown-end' : '', open ? 'dropdown-open' : '', className)}>
|
|
136
141
|
<button
|
|
137
142
|
type='button'
|
|
143
|
+
disabled={!ready}
|
|
138
144
|
class='btn btn-ghost {compact ? 'btn-sm btn-square' : 'gap-2'}'
|
|
139
145
|
onclick={() => (open = !open)}
|
|
140
146
|
onkeydown={handleKeydown}
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
{#if actions}<div class='ml-auto flex max-w-full shrink-0 flex-wrap items-center gap-1.5 sm:gap-2'>{@render actions()}</div>{/if}
|
|
58
58
|
</header>
|
|
59
59
|
{/if}
|
|
60
|
-
<main {...dataAttributes} aria-labelledby={title ? headingId : undefined} class='flex min-h-0 min-w-0 flex-1 flex-col overflow-auto p-3 sm:p-4'>
|
|
60
|
+
<main {...dataAttributes} aria-labelledby={title ? headingId : undefined} class='relative flex min-h-0 min-w-0 flex-1 flex-col overflow-auto p-3 sm:p-4'>
|
|
61
61
|
{@render children()}
|
|
62
62
|
</main>
|
|
63
63
|
{#if footer}<footer class='shrink-0 border-t border-base-content/8 px-3 py-1 text-center text-xs text-base-content/45 sm:px-4'>{@render footer()}</footer>{/if}
|
|
@@ -177,7 +177,7 @@
|
|
|
177
177
|
<div {...dataAttributes} class='fieldset w-full'>
|
|
178
178
|
<!-- 输入框容器 -->
|
|
179
179
|
<div class={cn(
|
|
180
|
-
'flex items-center w-full rounded-lg border bg-base-100',
|
|
180
|
+
'flex items-center w-full rounded-lg border bg-base-100 overflow-hidden',
|
|
181
181
|
sizeClasses.height,
|
|
182
182
|
effectiveError
|
|
183
183
|
? 'border-error/60 focus-within:ring-2 focus-within:ring-error/15'
|
package/dist/styles/global.css
CHANGED
|
@@ -49,6 +49,22 @@ body {
|
|
|
49
49
|
outline-offset: 2px;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
/* 禁用控件统一为不可用指针,避免内层 input 的原生 default 指针覆盖容器反馈。 */
|
|
53
|
+
input:disabled,
|
|
54
|
+
textarea:disabled,
|
|
55
|
+
select:disabled {
|
|
56
|
+
cursor: not-allowed;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/* 原生禁用按钮保持可命中才能显示不可用指针;disabled 已阻止点击,不会触发业务。 */
|
|
60
|
+
button:disabled:not(.pointer-events-none),
|
|
61
|
+
input[type='button']:disabled,
|
|
62
|
+
input[type='submit']:disabled,
|
|
63
|
+
input[type='reset']:disabled {
|
|
64
|
+
pointer-events: auto;
|
|
65
|
+
cursor: not-allowed;
|
|
66
|
+
}
|
|
67
|
+
|
|
52
68
|
/* ─── 隐藏浏览器原生密码显示按钮(使用自定义切换) ─── */
|
|
53
69
|
input::-ms-reveal,
|
|
54
70
|
input::-ms-clear,
|
package/dist/types.d.ts
CHANGED
|
@@ -1097,7 +1097,7 @@ export interface DropdownItem {
|
|
|
1097
1097
|
export interface DropdownProps extends DataAttributes {
|
|
1098
1098
|
/** 菜单项 */
|
|
1099
1099
|
items: DropdownItem[];
|
|
1100
|
-
/**
|
|
1100
|
+
/** 触发方式。`manual` 使用内联菜单,由调用方通过 `class` 切换 `dropdown-open`。 */
|
|
1101
1101
|
trigger?: 'click' | 'hover' | 'manual';
|
|
1102
1102
|
/** 位置 */
|
|
1103
1103
|
position?: Position;
|
|
@@ -1565,7 +1565,7 @@ export interface PopoverProps extends DataAttributes {
|
|
|
1565
1565
|
trigger?: 'click' | 'hover';
|
|
1566
1566
|
/** 偏移量 */
|
|
1567
1567
|
offset?: number;
|
|
1568
|
-
/** 是否将内容挂到 body,以逃逸祖先 overflow
|
|
1568
|
+
/** 是否将内容挂到 body,以逃逸祖先 overflow 和堆叠上下文;默认 `true`,设为 `false` 时使用相对定位。 */
|
|
1569
1569
|
portal?: boolean;
|
|
1570
1570
|
/** 自定义类名 */
|
|
1571
1571
|
class?: string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h-ai/ui",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.0-beta.
|
|
4
|
+
"version": "1.0.0-beta.14",
|
|
5
5
|
"description": "Hai Framework UI component library for Svelte 5 Runes.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"svelte": "./dist/index.js",
|
|
@@ -124,7 +124,7 @@
|
|
|
124
124
|
"svelte": "^5.57.2"
|
|
125
125
|
},
|
|
126
126
|
"dependencies": {
|
|
127
|
-
"@h-ai/core": "1.0.0-beta.
|
|
127
|
+
"@h-ai/core": "1.0.0-beta.14",
|
|
128
128
|
"@internationalized/date": "^3.12.4",
|
|
129
129
|
"@rrweb/replay": "^2.1.7",
|
|
130
130
|
"@shikijs/langs": "^4.5.0",
|