@cognitap/radiant 0.0.49 → 0.0.51
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/CHANGELOG.md +9 -1
- package/dist/library/Autocomplete.d.ts +26 -0
- package/dist/library/Autocomplete.d.ts.map +1 -0
- package/dist/library/Autocomplete.js +51 -0
- package/dist/library/Autocomplete.js.map +1 -0
- package/dist/library/Combobox.d.ts +8 -0
- package/dist/library/Combobox.d.ts.map +1 -1
- package/dist/library/Combobox.js +101 -24
- package/dist/library/Combobox.js.map +1 -1
- package/dist/library/NavLink.d.ts +33 -0
- package/dist/library/NavLink.d.ts.map +1 -0
- package/dist/library/NavLink.js +42 -0
- package/dist/library/NavLink.js.map +1 -0
- package/dist/library/cn.d.ts.map +1 -1
- package/dist/library/cn.js +11 -0
- package/dist/library/cn.js.map +1 -1
- package/dist/library/index.d.ts +2 -0
- package/dist/library/index.d.ts.map +1 -1
- package/dist/library/index.js +2 -0
- package/dist/library/index.js.map +1 -1
- package/dist/library/styles.css +1 -1
- package/dist/library/themes/components.d.ts +20 -0
- package/dist/library/themes/components.d.ts.map +1 -1
- package/dist/library/themes/components.js +20 -0
- package/dist/library/themes/components.js.map +1 -1
- package/docs/architecture.md +42 -39
- package/package.json +1 -1
- package/src/Autocomplete.tsx +116 -0
- package/src/Combobox.tsx +117 -31
- package/src/NavLink.tsx +183 -0
- package/src/cn.ts +11 -0
- package/src/index.ts +31 -0
- package/src/themes/components.ts +20 -0
package/src/Combobox.tsx
CHANGED
|
@@ -21,6 +21,7 @@ import { useArrayFormBridge } from './react/useArrayFormBridge.js'
|
|
|
21
21
|
import { useField, useFieldControl } from './Field.js'
|
|
22
22
|
import type { DistributiveOmit } from './internal/types.js'
|
|
23
23
|
import { cn } from './cn.js'
|
|
24
|
+
import { joinIds } from './internal/ids.js'
|
|
24
25
|
import { controlMetrics } from './controlStyles.js'
|
|
25
26
|
import {
|
|
26
27
|
comboboxInputClass,
|
|
@@ -92,6 +93,7 @@ export type ComboboxMultipleState = Omit<ComboboxState, 'value' | 'setValue'> &
|
|
|
92
93
|
type Context = Omit<ComboboxState, 'value' | 'setValue'> & {
|
|
93
94
|
value: Selection
|
|
94
95
|
multiple: boolean
|
|
96
|
+
textInput?: { name?: string; form?: string }
|
|
95
97
|
readOnly: boolean
|
|
96
98
|
setValue(value: Selection): void
|
|
97
99
|
selected: readonly ComboboxOption[]
|
|
@@ -132,6 +134,23 @@ function useComboboxContext() {
|
|
|
132
134
|
if (!context) throw new Error('Combobox parts must render inside Combobox.')
|
|
133
135
|
return context
|
|
134
136
|
}
|
|
137
|
+
/** Private text-mode seam; public families keep their own value contract. */
|
|
138
|
+
export function useAutocompleteParts() {
|
|
139
|
+
const box = useContext(ComboboxContext)
|
|
140
|
+
if (!box?.textInput) throw new Error('Autocomplete parts must render inside Autocomplete.')
|
|
141
|
+
}
|
|
142
|
+
function componentSlot(multiple: boolean, textMode: boolean, name: string) {
|
|
143
|
+
return (
|
|
144
|
+
joinIds(
|
|
145
|
+
name,
|
|
146
|
+
multiple
|
|
147
|
+
? name.replaceAll('combobox-', 'multi-select-')
|
|
148
|
+
: textMode
|
|
149
|
+
? name.replaceAll('combobox-', 'autocomplete-')
|
|
150
|
+
: undefined
|
|
151
|
+
) ?? name
|
|
152
|
+
)
|
|
153
|
+
}
|
|
135
154
|
const textOf = (item?: ComboboxOption) =>
|
|
136
155
|
item?.textValue ?? (typeof item?.label === 'string' ? item.label : '')
|
|
137
156
|
const localFilter = (item: ComboboxOption, query: string) =>
|
|
@@ -139,8 +158,18 @@ const localFilter = (item: ComboboxOption, query: string) =>
|
|
|
139
158
|
|
|
140
159
|
/** Editable search and committed selection have independent owners; results never select themselves. */
|
|
141
160
|
export function Combobox(props: ComboboxProps) {
|
|
161
|
+
return (
|
|
162
|
+
<ComboboxRoot
|
|
163
|
+
{...props}
|
|
164
|
+
textInput={undefined}
|
|
165
|
+
/>
|
|
166
|
+
)
|
|
167
|
+
}
|
|
168
|
+
/** Private composition entry. Text mode edits the actual input instead of a selection carrier. */
|
|
169
|
+
export function ComboboxRoot(props: ComboboxProps & { textInput?: { reset: () => void } }) {
|
|
142
170
|
const {
|
|
143
171
|
items,
|
|
172
|
+
textInput,
|
|
144
173
|
value,
|
|
145
174
|
defaultValue,
|
|
146
175
|
selectedItem,
|
|
@@ -165,6 +194,8 @@ export function Combobox(props: ComboboxProps) {
|
|
|
165
194
|
controlSize = 'medium',
|
|
166
195
|
children
|
|
167
196
|
} = props
|
|
197
|
+
const textMode = !!textInput
|
|
198
|
+
if (textMode && multiple) throw new TypeError('Autocomplete is a single text input.')
|
|
168
199
|
const [initialMultiple] = useState(multiple)
|
|
169
200
|
if (multiple !== initialMultiple)
|
|
170
201
|
throw new TypeError('Combobox cannot change multiple mode. Remount with a new key.')
|
|
@@ -247,15 +278,17 @@ export function Combobox(props: ComboboxProps) {
|
|
|
247
278
|
const enabled = visible.filter(item => !item.disabled)
|
|
248
279
|
const activeValue = enabled.some(item => item.value === active) ? active : null
|
|
249
280
|
if (active !== null && activeValue === null) highlight(null)
|
|
250
|
-
const text =
|
|
281
|
+
const text = textMode
|
|
251
282
|
? search.value
|
|
252
|
-
:
|
|
283
|
+
: multiple
|
|
253
284
|
? search.value
|
|
254
|
-
:
|
|
255
|
-
?
|
|
256
|
-
:
|
|
257
|
-
?
|
|
258
|
-
: ''
|
|
285
|
+
: isOpen && (searching || search.value !== '')
|
|
286
|
+
? search.value
|
|
287
|
+
: selected
|
|
288
|
+
? textOf(selected)
|
|
289
|
+
: typeof selection.value === 'string'
|
|
290
|
+
? selection.value
|
|
291
|
+
: ''
|
|
259
292
|
const setOpen = (next: boolean) => {
|
|
260
293
|
if (next && unavailable()) return
|
|
261
294
|
expansion.request(next)
|
|
@@ -265,7 +298,7 @@ export function Combobox(props: ComboboxProps) {
|
|
|
265
298
|
expansion.request(false)
|
|
266
299
|
highlight(null)
|
|
267
300
|
setSearching(false)
|
|
268
|
-
search.request('')
|
|
301
|
+
if (!textMode) search.request('')
|
|
269
302
|
}
|
|
270
303
|
const setQuery = (next: string) => {
|
|
271
304
|
if (unavailable()) return
|
|
@@ -296,6 +329,23 @@ export function Combobox(props: ComboboxProps) {
|
|
|
296
329
|
}
|
|
297
330
|
const commit = (next: string | null) => {
|
|
298
331
|
if (unavailable() || (next !== null && !enabled.some(item => item.value === next))) return
|
|
332
|
+
if (textMode) {
|
|
333
|
+
const completion = next ?? ''
|
|
334
|
+
if (input && input.value !== completion) {
|
|
335
|
+
const view = input.ownerDocument.defaultView
|
|
336
|
+
if (view) {
|
|
337
|
+
const setter = Object.getOwnPropertyDescriptor(
|
|
338
|
+
view.HTMLInputElement.prototype,
|
|
339
|
+
'value'
|
|
340
|
+
)!.set!
|
|
341
|
+
setter.call(input, completion)
|
|
342
|
+
input.dispatchEvent(new view.Event('input', { bubbles: true }))
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
dismiss()
|
|
346
|
+
input?.focus({ preventScroll: true })
|
|
347
|
+
return
|
|
348
|
+
}
|
|
299
349
|
const item = enabled.find(item => item.value === next)
|
|
300
350
|
if (item) setRetained(previous => new Map(previous).set(item.value, item))
|
|
301
351
|
if (multiple) {
|
|
@@ -311,12 +361,12 @@ export function Combobox(props: ComboboxProps) {
|
|
|
311
361
|
input?.focus({ preventScroll: true })
|
|
312
362
|
}
|
|
313
363
|
const nativeValue = typeof selection.value === 'string' ? selection.value : ''
|
|
314
|
-
const latest = useRef({ selection, search, nativeValue, expansion })
|
|
364
|
+
const latest = useRef({ selection, search, nativeValue, expansion, textReset: textInput?.reset })
|
|
315
365
|
useLayoutEffect(() => {
|
|
316
|
-
latest.current = { selection, search, nativeValue, expansion }
|
|
366
|
+
latest.current = { selection, search, nativeValue, expansion, textReset: textInput?.reset }
|
|
317
367
|
})
|
|
318
368
|
useLayoutEffect(() => {
|
|
319
|
-
if (multiple) return
|
|
369
|
+
if (multiple || textMode) return
|
|
320
370
|
const node = bridge.current
|
|
321
371
|
if (!node) return
|
|
322
372
|
const changedByUser = pending.current && Object.is(pending.current.value, selection.value)
|
|
@@ -338,7 +388,7 @@ export function Combobox(props: ComboboxProps) {
|
|
|
338
388
|
}
|
|
339
389
|
})
|
|
340
390
|
useEffect(() => {
|
|
341
|
-
if (multiple) return
|
|
391
|
+
if (multiple || textMode) return
|
|
342
392
|
const node = bridge.current
|
|
343
393
|
const owner = node?.form
|
|
344
394
|
if (!node || !owner) return
|
|
@@ -361,7 +411,29 @@ export function Combobox(props: ComboboxProps) {
|
|
|
361
411
|
owner.removeEventListener('reset', reset)
|
|
362
412
|
win.clearTimeout(timer)
|
|
363
413
|
}
|
|
364
|
-
}, [input, form, multiple])
|
|
414
|
+
}, [input, form, multiple, textMode])
|
|
415
|
+
useEffect(() => {
|
|
416
|
+
if (!textMode || !input) return
|
|
417
|
+
const view = input.ownerDocument.defaultView
|
|
418
|
+
if (!view) return
|
|
419
|
+
const roots = new Set([input.ownerDocument, input.getRootNode()])
|
|
420
|
+
let timer: number | undefined
|
|
421
|
+
const reset = (event: Event) => {
|
|
422
|
+
if (event.target !== input.form) return
|
|
423
|
+
view.clearTimeout(timer)
|
|
424
|
+
timer = view.setTimeout(() => {
|
|
425
|
+
if (event.defaultPrevented || !input.isConnected) return
|
|
426
|
+
latest.current.textReset?.()
|
|
427
|
+
highlight(null)
|
|
428
|
+
latest.current.expansion.request(false)
|
|
429
|
+
}, 0)
|
|
430
|
+
}
|
|
431
|
+
for (const root of roots) root.addEventListener('reset', reset, true)
|
|
432
|
+
return () => {
|
|
433
|
+
for (const root of roots) root.removeEventListener('reset', reset, true)
|
|
434
|
+
view.clearTimeout(timer)
|
|
435
|
+
}
|
|
436
|
+
}, [input, textMode])
|
|
365
437
|
useLayoutEffect(() => {
|
|
366
438
|
if (!isOpen || activeValue === null) return
|
|
367
439
|
const option = content.current?.ownerDocument.getElementById(
|
|
@@ -385,6 +457,7 @@ export function Combobox(props: ComboboxProps) {
|
|
|
385
457
|
})
|
|
386
458
|
const context: Context = {
|
|
387
459
|
multiple,
|
|
460
|
+
textInput: textMode ? { name, form } : undefined,
|
|
388
461
|
readOnly,
|
|
389
462
|
selected: selectedEntries,
|
|
390
463
|
remove(value) {
|
|
@@ -442,7 +515,7 @@ export function Combobox(props: ComboboxProps) {
|
|
|
442
515
|
{multiple && <ComboboxTags />}
|
|
443
516
|
<div
|
|
444
517
|
className="relative w-full min-w-0"
|
|
445
|
-
data-slot={multiple
|
|
518
|
+
data-slot={componentSlot(multiple, textMode, 'combobox-control')}
|
|
446
519
|
>
|
|
447
520
|
<ComboboxInput />
|
|
448
521
|
<ComboboxTrigger className="absolute inset-y-0 end-0 w-12" />
|
|
@@ -452,7 +525,7 @@ export function Combobox(props: ComboboxProps) {
|
|
|
452
525
|
</ComboboxPortal>
|
|
453
526
|
</>
|
|
454
527
|
)}
|
|
455
|
-
{multiple ? (
|
|
528
|
+
{textMode ? null : multiple ? (
|
|
456
529
|
<>
|
|
457
530
|
<input
|
|
458
531
|
ref={arrayBridgeRef}
|
|
@@ -550,7 +623,9 @@ export function ComboboxInput({
|
|
|
550
623
|
ref={inputRef}
|
|
551
624
|
type="text"
|
|
552
625
|
role="combobox"
|
|
553
|
-
|
|
626
|
+
name={box.textInput?.name}
|
|
627
|
+
form={box.textInput?.form}
|
|
628
|
+
required={box.textInput ? control.required : false}
|
|
554
629
|
readOnly={box.readOnly || props.readOnly}
|
|
555
630
|
autoComplete={props.autoComplete ?? 'off'}
|
|
556
631
|
value={box.text}
|
|
@@ -559,7 +634,7 @@ export function ComboboxInput({
|
|
|
559
634
|
controlMetrics({ controlSize: box.controlSize }),
|
|
560
635
|
className
|
|
561
636
|
)}
|
|
562
|
-
data-slot={box.multiple
|
|
637
|
+
data-slot={componentSlot(box.multiple, !!box.textInput, 'combobox-input')}
|
|
563
638
|
data-control-size={box.controlSize}
|
|
564
639
|
aria-autocomplete="list"
|
|
565
640
|
aria-expanded={box.open}
|
|
@@ -602,7 +677,13 @@ export function ComboboxInput({
|
|
|
602
677
|
box.remove(box.value.at(-1)!)
|
|
603
678
|
return
|
|
604
679
|
}
|
|
605
|
-
if (
|
|
680
|
+
if (
|
|
681
|
+
!box.textInput &&
|
|
682
|
+
!box.multiple &&
|
|
683
|
+
event.key === 'Escape' &&
|
|
684
|
+
!box.open &&
|
|
685
|
+
box.value !== null
|
|
686
|
+
) {
|
|
606
687
|
event.preventDefault()
|
|
607
688
|
box.commit(null)
|
|
608
689
|
return
|
|
@@ -613,6 +694,10 @@ export function ComboboxInput({
|
|
|
613
694
|
box.dismiss()
|
|
614
695
|
return
|
|
615
696
|
}
|
|
697
|
+
if (box.textInput && event.key === 'Enter' && box.open && box.active === null) {
|
|
698
|
+
box.dismiss()
|
|
699
|
+
return
|
|
700
|
+
}
|
|
616
701
|
if (event.key === 'Tab') {
|
|
617
702
|
box.dismiss()
|
|
618
703
|
return
|
|
@@ -692,12 +777,10 @@ export function ComboboxTrigger({
|
|
|
692
777
|
return render ? render(native) : <button {...native} />
|
|
693
778
|
}}
|
|
694
779
|
tabIndex={-1}
|
|
695
|
-
aria-label={props['aria-label'] ?? 'Show options'}
|
|
780
|
+
aria-label={props['aria-label'] ?? (box.textInput ? 'Show suggestions' : 'Show options')}
|
|
696
781
|
aria-controls={box.open ? box.listId : undefined}
|
|
697
782
|
aria-expanded={box.open}
|
|
698
|
-
data-slot={
|
|
699
|
-
box.multiple ? 'button combobox-trigger multi-select-trigger' : 'button combobox-trigger'
|
|
700
|
-
}
|
|
783
|
+
data-slot={componentSlot(box.multiple, !!box.textInput, 'button combobox-trigger')}
|
|
701
784
|
onPointerDown={event => {
|
|
702
785
|
onPointerDown?.(event)
|
|
703
786
|
if (!event.defaultPrevented) event.preventDefault()
|
|
@@ -739,7 +822,12 @@ export function ComboboxClear({
|
|
|
739
822
|
...props
|
|
740
823
|
}: ComboboxClearProps) {
|
|
741
824
|
const box = useComboboxContext()
|
|
742
|
-
if (
|
|
825
|
+
if (
|
|
826
|
+
box.textInput
|
|
827
|
+
? box.query === ''
|
|
828
|
+
: box.value === null || (Array.isArray(box.value) && !box.value.length)
|
|
829
|
+
)
|
|
830
|
+
return null
|
|
743
831
|
return (
|
|
744
832
|
<Button
|
|
745
833
|
variant="ghost"
|
|
@@ -755,10 +843,8 @@ export function ComboboxClear({
|
|
|
755
843
|
return render ? render(native) : <button {...native} />
|
|
756
844
|
}}
|
|
757
845
|
tabIndex={box.multiple ? 0 : -1}
|
|
758
|
-
aria-label={props['aria-label'] ?? 'Clear selection'}
|
|
759
|
-
data-slot={
|
|
760
|
-
box.multiple ? 'button combobox-clear multi-select-clear' : 'button combobox-clear'
|
|
761
|
-
}
|
|
846
|
+
aria-label={props['aria-label'] ?? (box.textInput ? 'Clear text' : 'Clear selection')}
|
|
847
|
+
data-slot={componentSlot(box.multiple, !!box.textInput, 'button combobox-clear')}
|
|
762
848
|
onPointerDown={event => {
|
|
763
849
|
onPointerDown?.(event)
|
|
764
850
|
if (!event.defaultPrevented) event.preventDefault()
|
|
@@ -821,7 +907,7 @@ export function ComboboxContent({
|
|
|
821
907
|
{...props}
|
|
822
908
|
ref={transitionRef}
|
|
823
909
|
popover="manual"
|
|
824
|
-
data-slot={box.multiple
|
|
910
|
+
data-slot={componentSlot(box.multiple, !!box.textInput, 'combobox-content')}
|
|
825
911
|
data-motion={motion}
|
|
826
912
|
data-state={box.open ? 'open' : 'closed'}
|
|
827
913
|
className={cn(
|
|
@@ -840,7 +926,7 @@ export function ComboboxContent({
|
|
|
840
926
|
aria-label={props['aria-label'] ?? box.input?.getAttribute('aria-label') ?? 'Suggestions'}
|
|
841
927
|
aria-labelledby={props['aria-label'] ? undefined : box.input?.labels?.[0]?.id}
|
|
842
928
|
aria-busy={box.loading || undefined}
|
|
843
|
-
data-slot={box.multiple
|
|
929
|
+
data-slot={componentSlot(box.multiple, !!box.textInput, 'combobox-listbox')}
|
|
844
930
|
className="max-h-[calc(var(--_rad-combobox-max-height,100dvh)-0.5rem)] overflow-y-auto overscroll-contain"
|
|
845
931
|
>
|
|
846
932
|
{children ??
|
|
@@ -880,7 +966,7 @@ export function ComboboxItem({
|
|
|
880
966
|
onKeyDown={props.onKeyDown}
|
|
881
967
|
aria-selected={box.multiple ? isItemOpen(box.value, value) : box.active === value}
|
|
882
968
|
aria-disabled={item.disabled || undefined}
|
|
883
|
-
data-slot={box.multiple
|
|
969
|
+
data-slot={componentSlot(box.multiple, !!box.textInput, 'combobox-item')}
|
|
884
970
|
data-value={value}
|
|
885
971
|
data-highlighted={box.active === value ? '' : undefined}
|
|
886
972
|
data-selected={isItemOpen(box.value, value) ? '' : undefined}
|
|
@@ -925,7 +1011,7 @@ export function ComboboxStatus({ children, className, ...props }: ComboboxStatus
|
|
|
925
1011
|
role="status"
|
|
926
1012
|
aria-live="polite"
|
|
927
1013
|
aria-atomic="true"
|
|
928
|
-
data-slot={box.multiple
|
|
1014
|
+
data-slot={componentSlot(box.multiple, !!box.textInput, 'combobox-status')}
|
|
929
1015
|
className={cn('px-3 py-2 empty:hidden', className)}
|
|
930
1016
|
>
|
|
931
1017
|
{box.open ? (children ?? box.status) : null}
|
package/src/NavLink.tsx
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import type { ReactNode } from 'react'
|
|
4
|
+
import {
|
|
5
|
+
ComposedLink,
|
|
6
|
+
type ComposedLinkProps,
|
|
7
|
+
type ComposedLinkRenderProps
|
|
8
|
+
} from './composedLink.js'
|
|
9
|
+
import {
|
|
10
|
+
Collapsible,
|
|
11
|
+
CollapsibleTrigger,
|
|
12
|
+
CollapsibleContent,
|
|
13
|
+
type CollapsibleProps,
|
|
14
|
+
type CollapsibleTriggerProps,
|
|
15
|
+
type CollapsibleContentProps
|
|
16
|
+
} from './Collapsible.js'
|
|
17
|
+
import { cn } from './cn.js'
|
|
18
|
+
import { controlMetrics } from './controlStyles.js'
|
|
19
|
+
import { joinIds } from './internal/ids.js'
|
|
20
|
+
import type { ControlSize, PartStyle } from './presentation.js'
|
|
21
|
+
|
|
22
|
+
type LabelParts = { icon?: PartStyle; label?: PartStyle; description?: PartStyle }
|
|
23
|
+
type ContentProps = {
|
|
24
|
+
children: ReactNode
|
|
25
|
+
icon?: ReactNode
|
|
26
|
+
description?: ReactNode
|
|
27
|
+
parts?: LabelParts
|
|
28
|
+
}
|
|
29
|
+
type ItemProps = ContentProps & { controlSize?: ControlSize }
|
|
30
|
+
export type NavLinkRenderProps = ComposedLinkRenderProps
|
|
31
|
+
export type NavLinkProps = Omit<
|
|
32
|
+
ComposedLinkProps,
|
|
33
|
+
'children' | 'aria-current' | 'variant' | 'tone'
|
|
34
|
+
> &
|
|
35
|
+
ItemProps & { active?: boolean }
|
|
36
|
+
export type NavLinkGroupProps = CollapsibleProps
|
|
37
|
+
export type NavLinkGroupTriggerProps = Omit<
|
|
38
|
+
CollapsibleTriggerProps,
|
|
39
|
+
'children' | 'role' | 'aria-current' | 'aria-expanded' | 'aria-controls'
|
|
40
|
+
> &
|
|
41
|
+
ItemProps
|
|
42
|
+
export type NavLinkGroupContentProps = CollapsibleContentProps
|
|
43
|
+
|
|
44
|
+
const itemClass = [
|
|
45
|
+
'box-border flex w-full min-w-0 items-center text-start no-underline hover:no-underline min-h-[var(--_rad-control-height)]',
|
|
46
|
+
'gap-[var(--rad-nav-link-gap,0.5rem)] px-[var(--rad-nav-link-padding-inline,var(--_rad-control-padding))] py-[var(--rad-nav-link-padding-block,0.375rem)] rounded-[var(--rad-nav-link-radius,var(--rad-control-radius,0.5rem))]',
|
|
47
|
+
'font-[family-name:var(--rad-nav-link-font-family,var(--rad-typography-roles-ui-label-family,system-ui,sans-serif))] text-[length:var(--rad-nav-link-font-size,var(--_rad-control-font-size))] font-[number:var(--rad-nav-link-font-weight,var(--rad-typography-roles-ui-label-weight,550))] leading-[var(--rad-typography-roles-ui-label-line-height,1.4)]',
|
|
48
|
+
'[color:var(--rad-nav-link-color,var(--rad-color-foreground))] hover:[color:var(--rad-nav-link-color,var(--rad-color-foreground))] hover:bg-[var(--rad-nav-link-hover-background,var(--rad-color-neutral))]',
|
|
49
|
+
'focus-visible:outline-solid focus-visible:[outline-color:var(--rad-nav-link-focus-color,var(--rad-color-focus))] focus-visible:[outline-width:var(--rad-nav-link-focus-width,var(--rad-focus-width,2px))] focus-visible:[outline-offset:var(--rad-nav-link-focus-offset,var(--rad-focus-offset,2px))]',
|
|
50
|
+
'forced-colors:bg-[Canvas] forced-colors:text-[CanvasText] forced-colors:hover:bg-[ButtonFace] forced-colors:hover:text-[CanvasText] forced-colors:focus-visible:outline-[Highlight]'
|
|
51
|
+
]
|
|
52
|
+
function Content({ children, icon, description, parts }: ContentProps) {
|
|
53
|
+
return (
|
|
54
|
+
<>
|
|
55
|
+
{icon !== undefined && icon !== null && icon !== false && (
|
|
56
|
+
<span
|
|
57
|
+
aria-hidden="true"
|
|
58
|
+
data-slot="nav-link-icon"
|
|
59
|
+
className={cn(
|
|
60
|
+
'flex shrink-0 items-center [&_svg]:size-[var(--_rad-control-indicator-size)]',
|
|
61
|
+
parts?.icon?.className
|
|
62
|
+
)}
|
|
63
|
+
style={parts?.icon?.style}
|
|
64
|
+
>
|
|
65
|
+
{icon}
|
|
66
|
+
</span>
|
|
67
|
+
)}
|
|
68
|
+
<span
|
|
69
|
+
data-slot="nav-link-body"
|
|
70
|
+
className="min-w-0 flex-1"
|
|
71
|
+
>
|
|
72
|
+
<span
|
|
73
|
+
data-slot="nav-link-label"
|
|
74
|
+
className={cn('block [overflow-wrap:anywhere]', parts?.label?.className)}
|
|
75
|
+
style={parts?.label?.style}
|
|
76
|
+
>
|
|
77
|
+
{children}
|
|
78
|
+
</span>
|
|
79
|
+
{description !== undefined && description !== null && description !== false && (
|
|
80
|
+
<span
|
|
81
|
+
data-slot="nav-link-description"
|
|
82
|
+
className={cn(
|
|
83
|
+
'block [overflow-wrap:anywhere] font-[family-name:var(--rad-typography-roles-ui-supporting-family,system-ui,sans-serif)] text-[length:var(--rad-nav-link-description-size,var(--rad-typography-roles-ui-supporting-size,0.8125rem))] font-normal leading-[var(--rad-typography-roles-ui-supporting-line-height,1.5)] [color:var(--rad-nav-link-description-color,var(--rad-color-muted-foreground))] forced-colors:[color:inherit]',
|
|
84
|
+
parts?.description?.className
|
|
85
|
+
)}
|
|
86
|
+
style={parts?.description?.style}
|
|
87
|
+
>
|
|
88
|
+
{description}
|
|
89
|
+
</span>
|
|
90
|
+
)}
|
|
91
|
+
</span>
|
|
92
|
+
</>
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
/** A real Link; the consumer's router owns which destination is current. */
|
|
96
|
+
export function NavLink({
|
|
97
|
+
active = false,
|
|
98
|
+
controlSize = 'medium',
|
|
99
|
+
icon,
|
|
100
|
+
description,
|
|
101
|
+
parts,
|
|
102
|
+
children,
|
|
103
|
+
className,
|
|
104
|
+
...props
|
|
105
|
+
}: NavLinkProps) {
|
|
106
|
+
if (typeof active !== 'boolean') throw new TypeError('NavLink active must be boolean.')
|
|
107
|
+
return (
|
|
108
|
+
<ComposedLink
|
|
109
|
+
{...props}
|
|
110
|
+
identity="nav-link"
|
|
111
|
+
variant="subtle"
|
|
112
|
+
tone="neutral"
|
|
113
|
+
controlSize={controlSize}
|
|
114
|
+
aria-current={active ? 'page' : undefined}
|
|
115
|
+
className={cn(
|
|
116
|
+
controlMetrics({ controlSize }),
|
|
117
|
+
itemClass,
|
|
118
|
+
'border-s-[3px] border-s-transparent aria-[current=page]:[border-inline-start-color:var(--rad-nav-link-indicator-color,var(--rad-color-accent))] aria-[current=page]:bg-[var(--rad-nav-link-active-background,var(--rad-color-neutral))] aria-[current=page]:[color:var(--rad-nav-link-active-color,var(--rad-color-foreground))] aria-[current=page]:font-semibold',
|
|
119
|
+
'aria-[current=page]:[&_[data-slot=nav-link-description]]:[color:inherit] aria-[current=page]:hover:bg-[var(--rad-nav-link-active-background,var(--rad-color-neutral))] aria-[current=page]:hover:[color:var(--rad-nav-link-active-color,var(--rad-color-foreground))]',
|
|
120
|
+
'forced-colors:aria-[current=page]:[border-inline-start-color:Highlight] forced-colors:aria-[current=page]:bg-[Highlight] forced-colors:aria-[current=page]:text-[HighlightText] forced-colors:aria-[current=page]:hover:bg-[Highlight] forced-colors:aria-[current=page]:hover:text-[HighlightText]',
|
|
121
|
+
className
|
|
122
|
+
)}
|
|
123
|
+
>
|
|
124
|
+
<Content {...{ icon, description, parts, children }} />
|
|
125
|
+
</ComposedLink>
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
/** Disclosure headers stay summaries; destination anchors belong in Content. */
|
|
129
|
+
export function NavLinkGroup({ className, 'data-slot': slot, ...props }: NavLinkGroupProps) {
|
|
130
|
+
return (
|
|
131
|
+
<Collapsible
|
|
132
|
+
{...props}
|
|
133
|
+
data-slot={joinIds('nav-link-group', slot)}
|
|
134
|
+
className={cn('gap-0 rounded-none [border-width:0px] bg-transparent', className)}
|
|
135
|
+
/>
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
export function NavLinkGroupTrigger({
|
|
139
|
+
controlSize = 'medium',
|
|
140
|
+
icon,
|
|
141
|
+
description,
|
|
142
|
+
parts,
|
|
143
|
+
children,
|
|
144
|
+
className,
|
|
145
|
+
'data-slot': slot,
|
|
146
|
+
...props
|
|
147
|
+
}: NavLinkGroupTriggerProps) {
|
|
148
|
+
const native = {
|
|
149
|
+
...props,
|
|
150
|
+
role: undefined,
|
|
151
|
+
'aria-current': undefined,
|
|
152
|
+
'aria-expanded': undefined,
|
|
153
|
+
'aria-controls': undefined
|
|
154
|
+
}
|
|
155
|
+
return (
|
|
156
|
+
<CollapsibleTrigger
|
|
157
|
+
{...native}
|
|
158
|
+
data-slot={joinIds('nav-link-group-trigger', slot)}
|
|
159
|
+
data-control-size={controlSize}
|
|
160
|
+
className={cn(
|
|
161
|
+
controlMetrics({ controlSize }),
|
|
162
|
+
itemClass,
|
|
163
|
+
'rtl:[&>svg]:rotate-180 rtl:data-[state=open]:[&>svg]:rotate-90',
|
|
164
|
+
className
|
|
165
|
+
)}
|
|
166
|
+
>
|
|
167
|
+
<Content {...{ icon, description, parts, children }} />
|
|
168
|
+
</CollapsibleTrigger>
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
export function NavLinkGroupContent({
|
|
172
|
+
className,
|
|
173
|
+
'data-slot': slot,
|
|
174
|
+
...props
|
|
175
|
+
}: NavLinkGroupContentProps) {
|
|
176
|
+
return (
|
|
177
|
+
<CollapsibleContent
|
|
178
|
+
{...props}
|
|
179
|
+
data-slot={joinIds('nav-link-group-content', slot)}
|
|
180
|
+
className={cn('px-0 pb-0 ps-[var(--rad-nav-link-indent,1rem)]', className)}
|
|
181
|
+
/>
|
|
182
|
+
)
|
|
183
|
+
}
|
package/src/cn.ts
CHANGED
|
@@ -18,6 +18,7 @@ export const cn: CnFunction = createCn({
|
|
|
18
18
|
bottom: ['bottom-(--rad-toast-inset)'],
|
|
19
19
|
z: ['z-(--rad-toast-z-index)'],
|
|
20
20
|
'font-family': [
|
|
21
|
+
'font-(--rad-nav-link-font-family)',
|
|
21
22
|
'font-(--rad-native-select-font-family)',
|
|
22
23
|
...roleClasses('font', 'family'),
|
|
23
24
|
'font-(--rad-combobox-font-family)',
|
|
@@ -26,6 +27,7 @@ export const cn: CnFunction = createCn({
|
|
|
26
27
|
'font-(--rad-tabs-font-family)'
|
|
27
28
|
],
|
|
28
29
|
'font-weight': [
|
|
30
|
+
'font-(--rad-nav-link-font-weight)',
|
|
29
31
|
'font-(--rad-native-select-font-weight)',
|
|
30
32
|
'font-(--rad-toast-title-weight)',
|
|
31
33
|
'font-(--rad-alert-title-weight)',
|
|
@@ -37,6 +39,8 @@ export const cn: CnFunction = createCn({
|
|
|
37
39
|
'font-(--rad-tabs-font-weight)'
|
|
38
40
|
],
|
|
39
41
|
'font-size': [
|
|
42
|
+
'text-(--rad-nav-link-font-size)',
|
|
43
|
+
'text-(--rad-nav-link-description-size)',
|
|
40
44
|
'text-(--rad-native-select-font-size)',
|
|
41
45
|
'text-(--rad-kbd-font-size)',
|
|
42
46
|
'text-(--rad-table-font-size)',
|
|
@@ -97,6 +101,7 @@ export const cn: CnFunction = createCn({
|
|
|
97
101
|
],
|
|
98
102
|
mb: ['mb-(--rad-multi-select-gap)', 'mb-(--rad-fieldset-gap)'],
|
|
99
103
|
gap: [
|
|
104
|
+
'gap-(--rad-nav-link-gap)',
|
|
100
105
|
'gap-(--rad-password-input-gap)',
|
|
101
106
|
'gap-(--rad-input-group-gap)',
|
|
102
107
|
'gap-(--rad-kbd-gap)',
|
|
@@ -123,13 +128,16 @@ export const cn: CnFunction = createCn({
|
|
|
123
128
|
'min-h-(--rad-textarea-min-height)',
|
|
124
129
|
'min-h-(--rad-tabs-trigger-height)'
|
|
125
130
|
],
|
|
131
|
+
ps: ['ps-(--rad-nav-link-indent)'],
|
|
126
132
|
py: [
|
|
133
|
+
'py-(--rad-nav-link-padding-block)',
|
|
127
134
|
'py-(--rad-kbd-padding-block)',
|
|
128
135
|
'py-(--rad-table-padding-block)',
|
|
129
136
|
'py-(--rad-textarea-padding-block)',
|
|
130
137
|
'py-(--rad-badge-padding-block)'
|
|
131
138
|
],
|
|
132
139
|
px: [
|
|
140
|
+
'px-(--rad-nav-link-padding-inline)',
|
|
133
141
|
'px-(--rad-native-select-padding)',
|
|
134
142
|
'px-(--rad-input-group-padding-inline)',
|
|
135
143
|
'px-(--rad-kbd-padding-inline)',
|
|
@@ -156,6 +164,7 @@ export const cn: CnFunction = createCn({
|
|
|
156
164
|
'p-(--rad-tabs-content-padding)'
|
|
157
165
|
],
|
|
158
166
|
rounded: [
|
|
167
|
+
'rounded-(--rad-nav-link-radius)',
|
|
159
168
|
'rounded-(--rad-meter-radius)',
|
|
160
169
|
'rounded-(--rad-native-select-radius)',
|
|
161
170
|
'rounded-(--rad-input-group-radius)',
|
|
@@ -258,6 +267,7 @@ export const cn: CnFunction = createCn({
|
|
|
258
267
|
'[corner-shape:var(--rad-tabs-corner-shape)]'
|
|
259
268
|
],
|
|
260
269
|
'outline-w': [
|
|
270
|
+
'outline-(--rad-nav-link-focus-width)',
|
|
261
271
|
'outline-(--rad-native-select-focus-width)',
|
|
262
272
|
'outline-(--rad-input-group-focus-width)',
|
|
263
273
|
'outline-(--rad-popover-focus-width)',
|
|
@@ -267,6 +277,7 @@ export const cn: CnFunction = createCn({
|
|
|
267
277
|
'outline-(--rad-tabs-focus-width)'
|
|
268
278
|
],
|
|
269
279
|
'outline-offset': [
|
|
280
|
+
'outline-offset-(--rad-nav-link-focus-offset)',
|
|
270
281
|
'outline-offset-(--rad-native-select-focus-offset)',
|
|
271
282
|
'outline-offset-(--rad-input-group-focus-offset)',
|
|
272
283
|
'outline-offset-(--rad-popover-focus-offset)',
|
package/src/index.ts
CHANGED
|
@@ -582,3 +582,34 @@ export type {
|
|
|
582
582
|
} from './MultiSelect.js'
|
|
583
583
|
|
|
584
584
|
export { PasswordInput, type PasswordInputProps } from './PasswordInput.js'
|
|
585
|
+
|
|
586
|
+
export {
|
|
587
|
+
NavLink,
|
|
588
|
+
NavLinkGroup,
|
|
589
|
+
NavLinkGroupTrigger,
|
|
590
|
+
NavLinkGroupContent,
|
|
591
|
+
type NavLinkProps,
|
|
592
|
+
type NavLinkRenderProps,
|
|
593
|
+
type NavLinkGroupProps,
|
|
594
|
+
type NavLinkGroupTriggerProps,
|
|
595
|
+
type NavLinkGroupContentProps
|
|
596
|
+
} from './NavLink.js'
|
|
597
|
+
export {
|
|
598
|
+
Autocomplete,
|
|
599
|
+
AutocompleteInput,
|
|
600
|
+
AutocompleteTrigger,
|
|
601
|
+
AutocompleteClear,
|
|
602
|
+
AutocompletePortal,
|
|
603
|
+
AutocompleteContent,
|
|
604
|
+
AutocompleteItem,
|
|
605
|
+
AutocompleteStatus,
|
|
606
|
+
type AutocompleteProps,
|
|
607
|
+
type AutocompleteOption,
|
|
608
|
+
type AutocompleteInputProps,
|
|
609
|
+
type AutocompleteTriggerProps,
|
|
610
|
+
type AutocompleteClearProps,
|
|
611
|
+
type AutocompletePortalProps,
|
|
612
|
+
type AutocompleteContentProps,
|
|
613
|
+
type AutocompleteItemProps,
|
|
614
|
+
type AutocompleteStatusProps
|
|
615
|
+
} from './Autocomplete.js'
|
package/src/themes/components.ts
CHANGED
|
@@ -2,6 +2,26 @@ import { kebabCase } from './tokens.js'
|
|
|
2
2
|
|
|
3
3
|
/** Explicit component slots; omitted slots reset to CSS fallback semantics. */
|
|
4
4
|
export const componentRegistry = {
|
|
5
|
+
navLink: {
|
|
6
|
+
fontFamily: 'css',
|
|
7
|
+
fontSize: 'css',
|
|
8
|
+
fontWeight: 'weight',
|
|
9
|
+
paddingInline: 'css',
|
|
10
|
+
paddingBlock: 'css',
|
|
11
|
+
gap: 'css',
|
|
12
|
+
radius: 'css',
|
|
13
|
+
color: 'css',
|
|
14
|
+
hoverBackground: 'css',
|
|
15
|
+
activeBackground: 'css',
|
|
16
|
+
activeColor: 'css',
|
|
17
|
+
indicatorColor: 'css',
|
|
18
|
+
descriptionColor: 'css',
|
|
19
|
+
descriptionSize: 'css',
|
|
20
|
+
indent: 'css',
|
|
21
|
+
focusColor: 'css',
|
|
22
|
+
focusWidth: 'css',
|
|
23
|
+
focusOffset: 'css'
|
|
24
|
+
},
|
|
5
25
|
passwordInput: { gap: 'css' },
|
|
6
26
|
meter: {
|
|
7
27
|
height: 'css',
|