@adea-ai/ui 0.158.0 → 0.159.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/components/composites/action-button/action-button.d.ts +6 -0
- package/dist/components/composites/action-button/action-button.d.ts.map +1 -1
- package/dist/components/composites/action-button/action-button.js +29 -2
- package/dist/components/composites/action-button/action-button.js.map +1 -1
- package/dist/components/composites/model-selector/index.d.ts +1 -1
- package/dist/components/composites/model-selector/index.d.ts.map +1 -1
- package/dist/components/composites/model-selector/model-selector.d.ts +22 -0
- package/dist/components/composites/model-selector/model-selector.d.ts.map +1 -1
- package/dist/components/composites/model-selector/model-selector.js +191 -46
- package/dist/components/composites/model-selector/model-selector.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/r/action-button.json +1 -0
- package/dist/r/registry.json +1 -0
- package/dist/r/src/components/composites/action-button/action-button.tsx +17 -1
- package/dist/r/src/components/composites/model-selector/index.ts +1 -1
- package/dist/r/src/components/composites/model-selector/model-selector.tsx +155 -10
- package/package.json +1 -1
- package/registry.json +1 -0
- package/src/components/composites/action-button/action-button.tsx +17 -1
- package/src/components/composites/model-selector/index.ts +1 -1
- package/src/components/composites/model-selector/model-selector.tsx +155 -10
package/package.json
CHANGED
package/registry.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
For,
|
|
2
3
|
Show,
|
|
3
4
|
createRoot,
|
|
4
5
|
mergeProps,
|
|
@@ -13,6 +14,7 @@ import { callHandler } from '#lib/events'
|
|
|
13
14
|
import { Polymorphic } from '@kobalte/core/polymorphic'
|
|
14
15
|
import { buttonVariants, type ButtonProps } from '../../ui/button'
|
|
15
16
|
import { cn } from '#lib/utils'
|
|
17
|
+
import { Kbd, KbdGroup } from '../../ui/kbd'
|
|
16
18
|
import { Spinner } from '../../ui/spinner'
|
|
17
19
|
import { createDeferredTooltip, Tooltip, TooltipContent, TooltipTrigger } from '../../ui/tooltip'
|
|
18
20
|
|
|
@@ -44,6 +46,12 @@ export type ActionButtonProps<T extends ValidComponent = 'button'> = ButtonProps
|
|
|
44
46
|
* lacks. Size it by leaving the svg bare; the slot fixes it to control size.
|
|
45
47
|
*/
|
|
46
48
|
tooltipIcon?: JSX.Element
|
|
49
|
+
/**
|
|
50
|
+
* The action's keyboard chord, one entry per key (`['⇧', '⌘', 'D']`), drawn as keys after the
|
|
51
|
+
* explanation. Decorative like the rest of the tip: put the parseable chord on the control
|
|
52
|
+
* itself with `aria-keyshortcuts`.
|
|
53
|
+
*/
|
|
54
|
+
tooltipShortcut?: readonly string[]
|
|
47
55
|
/** Disables the action and announces the busy label through a polite status region. */
|
|
48
56
|
busy?: boolean
|
|
49
57
|
/** The activity announced while busy. The Button's accessible name stays unchanged. */
|
|
@@ -103,6 +111,7 @@ export function ActionButton<T extends ValidComponent = 'button'>(props: ActionB
|
|
|
103
111
|
'tooltip',
|
|
104
112
|
'tooltipSide',
|
|
105
113
|
'tooltipIcon',
|
|
114
|
+
'tooltipShortcut',
|
|
106
115
|
'busy',
|
|
107
116
|
'busyLabel',
|
|
108
117
|
// Split, not read from `rest`: mergeProps falls back to an earlier source when a
|
|
@@ -256,7 +265,14 @@ export function ActionButton<T extends ValidComponent = 'button'>(props: ActionB
|
|
|
256
265
|
>
|
|
257
266
|
<TooltipTrigger as={deferred.Target} />
|
|
258
267
|
<TooltipContent id={tooltipId} icon={local.tooltipIcon}>
|
|
259
|
-
{tooltipSlot()}
|
|
268
|
+
<Show when={local.tooltipShortcut?.length} fallback={tooltipSlot()}>
|
|
269
|
+
<span class="inline-flex items-center gap-2 whitespace-nowrap">
|
|
270
|
+
{tooltipSlot()}
|
|
271
|
+
<KbdGroup data-slot="action-button-shortcut" aria-hidden="true">
|
|
272
|
+
<For each={local.tooltipShortcut}>{(key) => <Kbd>{key}</Kbd>}</For>
|
|
273
|
+
</KbdGroup>
|
|
274
|
+
</span>
|
|
275
|
+
</Show>
|
|
260
276
|
</TooltipContent>
|
|
261
277
|
</Tooltip>
|
|
262
278
|
)}
|
|
@@ -29,7 +29,9 @@ import {
|
|
|
29
29
|
DropdownMenuGroup,
|
|
30
30
|
DropdownMenuLabel,
|
|
31
31
|
DropdownMenuRadioGroup,
|
|
32
|
+
DropdownMenuItem,
|
|
32
33
|
DropdownMenuRadioItem,
|
|
34
|
+
DropdownMenuSeparator,
|
|
33
35
|
DropdownMenuTrigger,
|
|
34
36
|
} from '../../ui/dropdown-menu'
|
|
35
37
|
import { Popover, PopoverContent, PopoverTrigger } from '../../ui/popover'
|
|
@@ -45,6 +47,7 @@ import {
|
|
|
45
47
|
type ModelOption,
|
|
46
48
|
} from './models'
|
|
47
49
|
import { fastIcon } from '#lib/fast-icon'
|
|
50
|
+
import { menuItem } from '#lib/overlay'
|
|
48
51
|
|
|
49
52
|
// lucide icons drawn from a cloned template (see fastIcon).
|
|
50
53
|
const Brain = fastIcon(LucideBrain)
|
|
@@ -95,7 +98,28 @@ const ChevronsUpDown = fastIcon(LucideChevronsUpDown)
|
|
|
95
98
|
* or the provider's initial and named by its tooltip. Under the tabs, a search
|
|
96
99
|
* box and the list cover the selected tab's models only. The tab starts on the
|
|
97
100
|
* selected model's provider. Effort stays its own menu.
|
|
101
|
+
*
|
|
102
|
+
* ## Footer
|
|
103
|
+
*
|
|
104
|
+
* `footer` is one choice that is not a model, such as "Workspace default", which
|
|
105
|
+
* lets the host pick both the provider and the model. It sits under the list,
|
|
106
|
+
* outside the search and the scroll, in every layout, and closes the menu when
|
|
107
|
+
* chosen. While `footer.selected` is true the trigger shows its label (and its
|
|
108
|
+
* `icon`) in place of a model.
|
|
109
|
+
*
|
|
110
|
+
* The searchable layouts trap focus while open: Tab and Shift+Tab move between
|
|
111
|
+
* the tabs, the search box and the footer instead of leaving the popover, which
|
|
112
|
+
* would close it.
|
|
98
113
|
*/
|
|
114
|
+
export type ModelSelectorFooter = {
|
|
115
|
+
label: string
|
|
116
|
+
/** The footer is the current choice: the trigger names it and it carries the check. */
|
|
117
|
+
selected?: boolean
|
|
118
|
+
/** Drawn before the label in the footer, and in the trigger while selected. */
|
|
119
|
+
icon?: JSX.Element
|
|
120
|
+
onSelect: () => void
|
|
121
|
+
}
|
|
122
|
+
|
|
99
123
|
export type ModelSelectorProps = {
|
|
100
124
|
models: readonly ModelOption[]
|
|
101
125
|
/** The selected model's id. */
|
|
@@ -114,6 +138,8 @@ export type ModelSelectorProps = {
|
|
|
114
138
|
layout?: 'list' | 'tabs'
|
|
115
139
|
/** The provider's mark, drawn with `currentColor`, for the tabs and the trigger. */
|
|
116
140
|
providerIcon?: (provider: string) => JSX.Element
|
|
141
|
+
/** A fixed choice under the list that is not a model; see Footer. */
|
|
142
|
+
footer?: ModelSelectorFooter
|
|
117
143
|
class?: string
|
|
118
144
|
}
|
|
119
145
|
|
|
@@ -129,6 +155,7 @@ export function ModelSelector(props: ModelSelectorProps) {
|
|
|
129
155
|
'label',
|
|
130
156
|
'layout',
|
|
131
157
|
'providerIcon',
|
|
158
|
+
'footer',
|
|
132
159
|
'class',
|
|
133
160
|
])
|
|
134
161
|
const blocked = () => local.disabledReason !== undefined
|
|
@@ -153,7 +180,7 @@ export function ModelSelector(props: ModelSelectorProps) {
|
|
|
153
180
|
<Show when={local.value}>
|
|
154
181
|
<span class="truncate px-2 text-sm text-muted-foreground">
|
|
155
182
|
<span class="visually-hidden">Model: </span>
|
|
156
|
-
{triggerText({ selected: selected(), value: local.value })}
|
|
183
|
+
{triggerText({ selected: selected(), value: local.value, footer: local.footer })}
|
|
157
184
|
</span>
|
|
158
185
|
</Show>
|
|
159
186
|
}
|
|
@@ -168,6 +195,7 @@ export function ModelSelector(props: ModelSelectorProps) {
|
|
|
168
195
|
blocked={blocked()}
|
|
169
196
|
describedBy={describedBy()}
|
|
170
197
|
providerIcon={local.providerIcon}
|
|
198
|
+
footer={local.footer}
|
|
171
199
|
onChange={(id) => local.onChange?.(id)}
|
|
172
200
|
/>
|
|
173
201
|
}
|
|
@@ -181,6 +209,7 @@ export function ModelSelector(props: ModelSelectorProps) {
|
|
|
181
209
|
value={local.value}
|
|
182
210
|
blocked={blocked()}
|
|
183
211
|
describedBy={describedBy()}
|
|
212
|
+
footer={local.footer}
|
|
184
213
|
onChange={(id) => local.onChange?.(id)}
|
|
185
214
|
/>
|
|
186
215
|
}
|
|
@@ -191,6 +220,7 @@ export function ModelSelector(props: ModelSelectorProps) {
|
|
|
191
220
|
value={local.value}
|
|
192
221
|
blocked={blocked()}
|
|
193
222
|
describedBy={describedBy()}
|
|
223
|
+
footer={local.footer}
|
|
194
224
|
onChange={(id) => local.onChange?.(id)}
|
|
195
225
|
/>
|
|
196
226
|
</Show>
|
|
@@ -230,7 +260,12 @@ export function ModelSelector(props: ModelSelectorProps) {
|
|
|
230
260
|
)
|
|
231
261
|
}
|
|
232
262
|
|
|
233
|
-
function triggerText(props: {
|
|
263
|
+
function triggerText(props: {
|
|
264
|
+
selected?: ModelOption
|
|
265
|
+
value?: string
|
|
266
|
+
footer?: ModelSelectorFooter
|
|
267
|
+
}): string {
|
|
268
|
+
if (props.footer?.selected) return boundText(props.footer.label, 60)
|
|
234
269
|
if (props.selected) return boundText(props.selected.label, 60)
|
|
235
270
|
return props.value ? boundText(props.value, 60) : 'Choose a model'
|
|
236
271
|
}
|
|
@@ -262,14 +297,27 @@ type PickerProps = {
|
|
|
262
297
|
value?: string
|
|
263
298
|
blocked: boolean
|
|
264
299
|
describedBy?: string
|
|
300
|
+
footer?: ModelSelectorFooter
|
|
265
301
|
onChange: (id: string) => void
|
|
266
302
|
}
|
|
267
303
|
|
|
268
|
-
function ModelTrigger(props: {
|
|
304
|
+
function ModelTrigger(props: {
|
|
305
|
+
selected?: ModelOption
|
|
306
|
+
value?: string
|
|
307
|
+
footer?: ModelSelectorFooter
|
|
308
|
+
empty: boolean
|
|
309
|
+
}) {
|
|
269
310
|
return (
|
|
270
311
|
<>
|
|
312
|
+
<Show when={props.footer?.selected && props.footer.icon}>
|
|
313
|
+
{(icon) => (
|
|
314
|
+
<span aria-hidden="true" class="inline-flex size-4 shrink-0 items-center justify-center">
|
|
315
|
+
{icon()}
|
|
316
|
+
</span>
|
|
317
|
+
)}
|
|
318
|
+
</Show>
|
|
271
319
|
<span class="max-w-48 truncate">
|
|
272
|
-
{props.empty ? 'No models available' : triggerText(props)}
|
|
320
|
+
{props.empty && !props.footer ? 'No models available' : triggerText(props)}
|
|
273
321
|
</span>
|
|
274
322
|
<ChevronsUpDown aria-hidden="true" />
|
|
275
323
|
</>
|
|
@@ -279,7 +327,7 @@ function ModelTrigger(props: { selected?: ModelOption; value?: string; empty: bo
|
|
|
279
327
|
function ModelMenu(props: PickerProps) {
|
|
280
328
|
const [open, setOpen] = createSignal(false)
|
|
281
329
|
const groups = createMemo(() => groupModels(props.models))
|
|
282
|
-
const inert = () => props.blocked || props.models.length === 0
|
|
330
|
+
const inert = () => props.blocked || (props.models.length === 0 && !props.footer)
|
|
283
331
|
|
|
284
332
|
createEffect(() => {
|
|
285
333
|
if (inert()) setOpen(false)
|
|
@@ -294,13 +342,14 @@ function ModelMenu(props: PickerProps) {
|
|
|
294
342
|
>
|
|
295
343
|
<DropdownMenuTrigger
|
|
296
344
|
as={PromptInputControl}
|
|
297
|
-
aria-label={`Model: ${props.models.length === 0 ? 'No models available' : triggerText(props)}`}
|
|
345
|
+
aria-label={`Model: ${props.models.length === 0 && !props.footer ? 'No models available' : triggerText(props)}`}
|
|
298
346
|
aria-disabled={inert() || undefined}
|
|
299
347
|
aria-describedby={props.describedBy}
|
|
300
348
|
>
|
|
301
349
|
<ModelTrigger
|
|
302
350
|
selected={props.selected}
|
|
303
351
|
value={props.value}
|
|
352
|
+
footer={props.footer}
|
|
304
353
|
empty={props.models.length === 0}
|
|
305
354
|
/>
|
|
306
355
|
</DropdownMenuTrigger>
|
|
@@ -333,11 +382,79 @@ function ModelMenu(props: PickerProps) {
|
|
|
333
382
|
)}
|
|
334
383
|
</For>
|
|
335
384
|
</DropdownMenuRadioGroup>
|
|
385
|
+
<Show when={props.footer}>
|
|
386
|
+
{(footer) => (
|
|
387
|
+
<>
|
|
388
|
+
<DropdownMenuSeparator />
|
|
389
|
+
<DropdownMenuItem
|
|
390
|
+
data-slot="model-selector-footer"
|
|
391
|
+
disabled={props.blocked}
|
|
392
|
+
onSelect={() => {
|
|
393
|
+
if (!props.blocked) footer().onSelect()
|
|
394
|
+
}}
|
|
395
|
+
>
|
|
396
|
+
<FooterBody footer={footer()} />
|
|
397
|
+
</DropdownMenuItem>
|
|
398
|
+
</>
|
|
399
|
+
)}
|
|
400
|
+
</Show>
|
|
336
401
|
</DropdownMenuContent>
|
|
337
402
|
</DropdownMenu>
|
|
338
403
|
)
|
|
339
404
|
}
|
|
340
405
|
|
|
406
|
+
/** The footer's icon, label and, while it is the current choice, the check. */
|
|
407
|
+
function FooterBody(props: { footer: ModelSelectorFooter }) {
|
|
408
|
+
return (
|
|
409
|
+
<>
|
|
410
|
+
<Show when={props.footer.icon}>
|
|
411
|
+
{(icon) => (
|
|
412
|
+
<span aria-hidden="true" class="inline-flex size-4 shrink-0 items-center justify-center">
|
|
413
|
+
{icon()}
|
|
414
|
+
</span>
|
|
415
|
+
)}
|
|
416
|
+
</Show>
|
|
417
|
+
<span class="min-w-0 truncate">{boundText(props.footer.label, 60)}</span>
|
|
418
|
+
<Show when={props.footer.selected}>
|
|
419
|
+
<Check aria-hidden="true" class="ms-auto text-primary" />
|
|
420
|
+
<span class="visually-hidden">Current choice</span>
|
|
421
|
+
</Show>
|
|
422
|
+
</>
|
|
423
|
+
)
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* The footer of a searchable picker: one full-width button under the list, outside its search
|
|
428
|
+
* and scroll, so it stays in view however long the list is.
|
|
429
|
+
*/
|
|
430
|
+
function PaletteFooter(props: {
|
|
431
|
+
footer: ModelSelectorFooter
|
|
432
|
+
blocked: boolean
|
|
433
|
+
onDone: () => void
|
|
434
|
+
}) {
|
|
435
|
+
return (
|
|
436
|
+
<div data-slot="model-selector-footer" class="border-t border-border p-1">
|
|
437
|
+
<button
|
|
438
|
+
type="button"
|
|
439
|
+
aria-pressed={props.footer.selected ? 'true' : 'false'}
|
|
440
|
+
aria-disabled={props.blocked || undefined}
|
|
441
|
+
class={cn(
|
|
442
|
+
menuItem,
|
|
443
|
+
'w-full cursor-pointer text-start hover:bg-surface-hover focus-visible:bg-surface-hover',
|
|
444
|
+
'aria-disabled:pointer-events-none aria-disabled:text-muted-foreground'
|
|
445
|
+
)}
|
|
446
|
+
onClick={() => {
|
|
447
|
+
if (props.blocked) return
|
|
448
|
+
props.footer.onSelect()
|
|
449
|
+
props.onDone()
|
|
450
|
+
}}
|
|
451
|
+
>
|
|
452
|
+
<FooterBody footer={props.footer} />
|
|
453
|
+
</button>
|
|
454
|
+
</div>
|
|
455
|
+
)
|
|
456
|
+
}
|
|
457
|
+
|
|
341
458
|
function ModelSearch(props: PickerProps) {
|
|
342
459
|
const [open, setOpen] = createSignal(false)
|
|
343
460
|
const groups = createMemo(() => groupModels(props.models))
|
|
@@ -350,6 +467,8 @@ function ModelSearch(props: PickerProps) {
|
|
|
350
467
|
<Popover
|
|
351
468
|
open={open()}
|
|
352
469
|
onOpenChange={(next) => setOpen(next && !props.blocked)}
|
|
470
|
+
// Traps focus: Tab past the search box would otherwise leave the popover and close it.
|
|
471
|
+
modal
|
|
353
472
|
placement="top-start"
|
|
354
473
|
gutter={6}
|
|
355
474
|
>
|
|
@@ -359,7 +478,12 @@ function ModelSearch(props: PickerProps) {
|
|
|
359
478
|
aria-disabled={props.blocked || undefined}
|
|
360
479
|
aria-describedby={props.describedBy}
|
|
361
480
|
>
|
|
362
|
-
<ModelTrigger
|
|
481
|
+
<ModelTrigger
|
|
482
|
+
selected={props.selected}
|
|
483
|
+
value={props.value}
|
|
484
|
+
footer={props.footer}
|
|
485
|
+
empty={false}
|
|
486
|
+
/>
|
|
363
487
|
</PopoverTrigger>
|
|
364
488
|
<PopoverContent class="w-80 max-w-full">
|
|
365
489
|
<Command
|
|
@@ -396,6 +520,15 @@ function ModelSearch(props: PickerProps) {
|
|
|
396
520
|
</For>
|
|
397
521
|
</CommandList>
|
|
398
522
|
</Command>
|
|
523
|
+
<Show when={props.footer}>
|
|
524
|
+
{(footer) => (
|
|
525
|
+
<PaletteFooter
|
|
526
|
+
footer={footer()}
|
|
527
|
+
blocked={props.blocked}
|
|
528
|
+
onDone={() => setOpen(false)}
|
|
529
|
+
/>
|
|
530
|
+
)}
|
|
531
|
+
</Show>
|
|
399
532
|
</PopoverContent>
|
|
400
533
|
</Popover>
|
|
401
534
|
)
|
|
@@ -424,7 +557,7 @@ function ProviderGlyph(props: { provider: string; icon?: (provider: string) => J
|
|
|
424
557
|
function ModelTabs(props: PickerProps & { providerIcon?: (provider: string) => JSX.Element }) {
|
|
425
558
|
const [open, setOpen] = createSignal(false)
|
|
426
559
|
const groups = createMemo(() => groupModels(props.models))
|
|
427
|
-
const inert = () => props.blocked || props.models.length === 0
|
|
560
|
+
const inert = () => props.blocked || (props.models.length === 0 && !props.footer)
|
|
428
561
|
const groupOf = (model: ModelOption | undefined) =>
|
|
429
562
|
model ? groups().find((group) => group.models.includes(model))?.provider : undefined
|
|
430
563
|
const [tab, setTab] = createSignal<string>()
|
|
@@ -450,21 +583,24 @@ function ModelTabs(props: PickerProps & { providerIcon?: (provider: string) => J
|
|
|
450
583
|
setOpen(next && !inert())
|
|
451
584
|
if (!next) setTab(undefined)
|
|
452
585
|
}}
|
|
586
|
+
// Traps focus: Tab from the last control would otherwise leave the popover and close it.
|
|
587
|
+
modal
|
|
453
588
|
placement="top-start"
|
|
454
589
|
gutter={6}
|
|
455
590
|
>
|
|
456
591
|
<PopoverTrigger
|
|
457
592
|
as={PromptInputControl}
|
|
458
|
-
aria-label={`Model: ${props.models.length === 0 ? 'No models available' : triggerText(props)}`}
|
|
593
|
+
aria-label={`Model: ${props.models.length === 0 && !props.footer ? 'No models available' : triggerText(props)}`}
|
|
459
594
|
aria-disabled={inert() || undefined}
|
|
460
595
|
aria-describedby={props.describedBy}
|
|
461
596
|
>
|
|
462
|
-
<Show when={groupOf(props.selected)}>
|
|
597
|
+
<Show when={!props.footer?.selected && groupOf(props.selected)}>
|
|
463
598
|
{(provider) => <ProviderGlyph provider={provider()} icon={props.providerIcon} />}
|
|
464
599
|
</Show>
|
|
465
600
|
<ModelTrigger
|
|
466
601
|
selected={props.selected}
|
|
467
602
|
value={props.value}
|
|
603
|
+
footer={props.footer}
|
|
468
604
|
empty={props.models.length === 0}
|
|
469
605
|
/>
|
|
470
606
|
</PopoverTrigger>
|
|
@@ -538,6 +674,15 @@ function ModelTabs(props: PickerProps & { providerIcon?: (provider: string) => J
|
|
|
538
674
|
)}
|
|
539
675
|
</For>
|
|
540
676
|
</Tabs>
|
|
677
|
+
<Show when={props.footer}>
|
|
678
|
+
{(footer) => (
|
|
679
|
+
<PaletteFooter
|
|
680
|
+
footer={footer()}
|
|
681
|
+
blocked={props.blocked}
|
|
682
|
+
onDone={() => setOpen(false)}
|
|
683
|
+
/>
|
|
684
|
+
)}
|
|
685
|
+
</Show>
|
|
541
686
|
</PopoverContent>
|
|
542
687
|
</Popover>
|
|
543
688
|
)
|