@cognitap/radiant 0.0.12 → 0.0.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/CHANGELOG.md +9 -1
- package/dist/library/AlertDialog.d.ts +25 -0
- package/dist/library/AlertDialog.d.ts.map +1 -0
- package/dist/library/AlertDialog.js +56 -0
- package/dist/library/AlertDialog.js.map +1 -0
- package/dist/library/Combobox.d.ts +88 -0
- package/dist/library/Combobox.d.ts.map +1 -0
- package/dist/library/Combobox.js +365 -0
- package/dist/library/Combobox.js.map +1 -0
- package/dist/library/Dialog.d.ts +7 -1
- package/dist/library/Dialog.d.ts.map +1 -1
- package/dist/library/Dialog.js +33 -16
- package/dist/library/Dialog.js.map +1 -1
- package/dist/library/Select.js +1 -1
- package/dist/library/Select.js.map +1 -1
- package/dist/library/cn.d.ts.map +1 -1
- package/dist/library/cn.js +18 -1
- package/dist/library/cn.js.map +1 -1
- package/dist/library/comboboxStyles.d.ts +6 -0
- package/dist/library/comboboxStyles.d.ts.map +1 -0
- package/dist/library/comboboxStyles.js +38 -0
- package/dist/library/comboboxStyles.js.map +1 -0
- package/dist/library/index.d.ts +4 -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/motion/popup.js +5 -5
- package/dist/library/motion/popup.js.map +1 -1
- package/dist/library/react/useComboboxPopup.d.ts +4 -0
- package/dist/library/react/useComboboxPopup.d.ts.map +1 -0
- package/dist/library/react/useComboboxPopup.js +118 -0
- package/dist/library/react/useComboboxPopup.js.map +1 -0
- package/dist/library/styles.css +1 -1
- package/dist/library/themes/components.d.ts +25 -0
- package/dist/library/themes/components.d.ts.map +1 -1
- package/dist/library/themes/components.js +25 -0
- package/dist/library/themes/components.js.map +1 -1
- package/docs/architecture.md +30 -21
- package/package.json +1 -1
- package/src/AlertDialog.tsx +110 -0
- package/src/Combobox.tsx +752 -0
- package/src/Dialog.tsx +52 -22
- package/src/Select.tsx +1 -1
- package/src/cn.ts +18 -1
- package/src/comboboxStyles.ts +41 -0
- package/src/index.ts +43 -0
- package/src/motion/popup.ts +5 -5
- package/src/react/useComboboxPopup.ts +130 -0
- package/src/themes/components.ts +25 -0
package/src/Dialog.tsx
CHANGED
|
@@ -108,6 +108,12 @@ export type DialogDescriptionProps = Omit<ComponentProps<'p'>, 'style'> & { styl
|
|
|
108
108
|
export type DialogCloseProps = DialogTriggerProps
|
|
109
109
|
|
|
110
110
|
const DialogContext = createContext<DialogState | null>(null)
|
|
111
|
+
const DialogFamilyContext = createContext<'dialog' | 'alert-dialog'>('dialog')
|
|
112
|
+
|
|
113
|
+
/** Private composition seam for AlertDialog; not exported from the package. */
|
|
114
|
+
export function useDialogFamily() {
|
|
115
|
+
return useContext(DialogFamilyContext)
|
|
116
|
+
}
|
|
111
117
|
|
|
112
118
|
export function useDialog(): DialogState | null {
|
|
113
119
|
return useContext(DialogContext)
|
|
@@ -119,15 +125,21 @@ function useDialogContext() {
|
|
|
119
125
|
return dialog
|
|
120
126
|
}
|
|
121
127
|
|
|
122
|
-
export function Dialog({
|
|
128
|
+
export function Dialog(props: DialogProps) {
|
|
129
|
+
return <DialogRoot {...props} />
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Private shared owner: both families keep the same native lifecycle. */
|
|
133
|
+
export function DialogRoot({
|
|
123
134
|
open,
|
|
124
135
|
defaultOpen,
|
|
125
136
|
onOpenChange,
|
|
126
137
|
modal = true,
|
|
127
138
|
closeOnBackdrop = true,
|
|
128
139
|
closeOnEscape = true,
|
|
129
|
-
children
|
|
130
|
-
|
|
140
|
+
children,
|
|
141
|
+
family = 'dialog'
|
|
142
|
+
}: DialogProps & { family?: 'dialog' | 'alert-dialog' }) {
|
|
131
143
|
const contentId = useId()
|
|
132
144
|
const titleId = useId()
|
|
133
145
|
const descriptionId = useId()
|
|
@@ -144,26 +156,29 @@ export function Dialog({
|
|
|
144
156
|
})
|
|
145
157
|
|
|
146
158
|
return (
|
|
147
|
-
<
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
159
|
+
<DialogFamilyContext.Provider value={family}>
|
|
160
|
+
<DialogContext.Provider
|
|
161
|
+
value={{
|
|
162
|
+
open: isOpen,
|
|
163
|
+
setOpen,
|
|
164
|
+
contentId,
|
|
165
|
+
titleId,
|
|
166
|
+
descriptionId,
|
|
167
|
+
modal,
|
|
168
|
+
closeOnBackdrop,
|
|
169
|
+
closeOnEscape,
|
|
170
|
+
controlled
|
|
171
|
+
}}
|
|
172
|
+
>
|
|
173
|
+
{children}
|
|
174
|
+
</DialogContext.Provider>
|
|
175
|
+
</DialogFamilyContext.Provider>
|
|
162
176
|
)
|
|
163
177
|
}
|
|
164
178
|
|
|
165
179
|
function DialogAction({ action, ...props }: DialogTriggerProps & { action: 'open' | 'close' }) {
|
|
166
180
|
const dialog = useDialogContext()
|
|
181
|
+
const family = useDialogFamily()
|
|
167
182
|
const slot = action === 'open' ? 'button dialog-trigger' : 'button dialog-close'
|
|
168
183
|
const buttonProps: ButtonProps = {
|
|
169
184
|
...props,
|
|
@@ -174,7 +189,13 @@ function DialogAction({ action, ...props }: DialogTriggerProps & { action: 'open
|
|
|
174
189
|
'aria-controls': dialog.contentId
|
|
175
190
|
}
|
|
176
191
|
: {}),
|
|
177
|
-
'data-slot':
|
|
192
|
+
'data-slot': joinIds(
|
|
193
|
+
slot,
|
|
194
|
+
family === 'alert-dialog'
|
|
195
|
+
? `alert-dialog-${action === 'open' ? 'trigger' : 'close'}`
|
|
196
|
+
: undefined,
|
|
197
|
+
props['data-slot']
|
|
198
|
+
),
|
|
178
199
|
onClick: composeAction(props.onClick, () => dialog.setOpen(action === 'open'))
|
|
179
200
|
}
|
|
180
201
|
return <Button {...buttonProps} />
|
|
@@ -199,6 +220,7 @@ export function DialogContent({
|
|
|
199
220
|
...props
|
|
200
221
|
}: DialogContentProps) {
|
|
201
222
|
const dialog = useDialogContext()
|
|
223
|
+
const family = useDialogFamily()
|
|
202
224
|
const nodeRef = useRef<HTMLDialogElement>(null)
|
|
203
225
|
const transition = useTransitionHost<HTMLDialogElement>(
|
|
204
226
|
'dialog',
|
|
@@ -242,10 +264,12 @@ export function DialogContent({
|
|
|
242
264
|
{...props}
|
|
243
265
|
open={undefined}
|
|
244
266
|
ref={hostRef}
|
|
267
|
+
role={family === 'alert-dialog' ? 'alertdialog' : props.role}
|
|
268
|
+
aria-modal={family === 'alert-dialog' ? true : props['aria-modal']}
|
|
245
269
|
aria-describedby={joinIds(dialog.descriptionId, props['aria-describedby'])}
|
|
246
270
|
aria-labelledby={props['aria-label'] ? props['aria-labelledby'] : dialog.titleId}
|
|
247
271
|
className={cn(dialogVariants(), className)}
|
|
248
|
-
data-slot=
|
|
272
|
+
data-slot={family === 'alert-dialog' ? 'dialog alert-dialog' : 'dialog'}
|
|
249
273
|
data-state={dialog.open ? 'open' : 'closed'}
|
|
250
274
|
id={dialog.contentId}
|
|
251
275
|
onCancel={event => {
|
|
@@ -274,11 +298,12 @@ export function DialogContent({
|
|
|
274
298
|
|
|
275
299
|
export function DialogTitle({ className, children, ...props }: DialogTitleProps) {
|
|
276
300
|
const dialog = useDialogContext()
|
|
301
|
+
const family = useDialogFamily()
|
|
277
302
|
return (
|
|
278
303
|
<h2
|
|
279
304
|
{...props}
|
|
280
305
|
className={cn(dialogTitleVariants(), className)}
|
|
281
|
-
data-slot=
|
|
306
|
+
data-slot={family === 'alert-dialog' ? 'dialog-title alert-dialog-title' : 'dialog-title'}
|
|
282
307
|
id={dialog.titleId}
|
|
283
308
|
>
|
|
284
309
|
{children}
|
|
@@ -288,11 +313,16 @@ export function DialogTitle({ className, children, ...props }: DialogTitleProps)
|
|
|
288
313
|
|
|
289
314
|
export function DialogDescription({ className, ...props }: DialogDescriptionProps) {
|
|
290
315
|
const dialog = useDialogContext()
|
|
316
|
+
const family = useDialogFamily()
|
|
291
317
|
return (
|
|
292
318
|
<p
|
|
293
319
|
{...props}
|
|
294
320
|
className={cn(dialogDescriptionVariants(), className)}
|
|
295
|
-
data-slot=
|
|
321
|
+
data-slot={
|
|
322
|
+
family === 'alert-dialog'
|
|
323
|
+
? 'dialog-description alert-dialog-description'
|
|
324
|
+
: 'dialog-description'
|
|
325
|
+
}
|
|
296
326
|
id={dialog.descriptionId}
|
|
297
327
|
/>
|
|
298
328
|
)
|
package/src/Select.tsx
CHANGED
|
@@ -606,7 +606,7 @@ export function SelectContent({
|
|
|
606
606
|
controlMetrics({ controlSize: select.controlSize }),
|
|
607
607
|
motionActive &&
|
|
608
608
|
!motionOff &&
|
|
609
|
-
'opacity-[var(--_rad-
|
|
609
|
+
'opacity-[var(--_rad-popup-enter,0)] motion-reduce:opacity-100',
|
|
610
610
|
className
|
|
611
611
|
)}
|
|
612
612
|
data-slot="select-content"
|
package/src/cn.ts
CHANGED
|
@@ -11,12 +11,14 @@ export const cn: CnFunction = createCn({
|
|
|
11
11
|
classGroups: {
|
|
12
12
|
'font-family': [
|
|
13
13
|
...roleClasses('font', 'family'),
|
|
14
|
+
'font-(--rad-combobox-font-family)',
|
|
14
15
|
'font-(--rad-select-font-family)',
|
|
15
16
|
'font-(--rad-textarea-font-family)',
|
|
16
17
|
'font-(--rad-tabs-font-family)'
|
|
17
18
|
],
|
|
18
19
|
'font-weight': [
|
|
19
20
|
...roleClasses('font', 'weight'),
|
|
21
|
+
'font-(--rad-combobox-font-weight)',
|
|
20
22
|
'font-(--rad-select-font-weight)',
|
|
21
23
|
'font-(--rad-textarea-font-weight)',
|
|
22
24
|
'font-(--rad-tabs-font-weight)'
|
|
@@ -24,12 +26,14 @@ export const cn: CnFunction = createCn({
|
|
|
24
26
|
'font-size': [
|
|
25
27
|
...roleClasses('text', 'size'),
|
|
26
28
|
...roleClasses('text', 'fluid-size'),
|
|
29
|
+
'text-(--rad-combobox-font-size)',
|
|
27
30
|
'text-(--rad-select-font-size)',
|
|
28
31
|
'text-(--rad-textarea-font-size)',
|
|
29
32
|
'text-(--rad-switch-label-size)',
|
|
30
33
|
'text-(--rad-tabs-font-size)'
|
|
31
34
|
],
|
|
32
35
|
h: [
|
|
36
|
+
'h-(--rad-combobox-height)',
|
|
33
37
|
'h-(--rad-select-height)',
|
|
34
38
|
'h-(--rad-switch-height)',
|
|
35
39
|
'h-(--rad-slider-height)',
|
|
@@ -41,21 +45,26 @@ export const cn: CnFunction = createCn({
|
|
|
41
45
|
'min-h': ['min-h-(--rad-textarea-min-height)', 'min-h-(--rad-tabs-trigger-height)'],
|
|
42
46
|
py: ['py-(--rad-textarea-padding-block)'],
|
|
43
47
|
px: [
|
|
48
|
+
'px-(--rad-combobox-padding)',
|
|
44
49
|
'px-(--rad-select-padding)',
|
|
45
50
|
'px-(--rad-textarea-padding)',
|
|
46
51
|
'px-(--rad-tabs-trigger-padding)'
|
|
47
52
|
],
|
|
48
53
|
p: [
|
|
54
|
+
'p-(--rad-combobox-content-padding)',
|
|
49
55
|
'p-(--rad-select-content-padding)',
|
|
50
56
|
'p-(--rad-tabs-list-padding)',
|
|
51
57
|
'p-(--rad-tabs-content-padding)'
|
|
52
58
|
],
|
|
53
59
|
rounded: [
|
|
60
|
+
'rounded-(--rad-combobox-radius)',
|
|
54
61
|
'rounded-(--rad-select-radius)',
|
|
55
62
|
'rounded-(--rad-textarea-radius)',
|
|
56
63
|
'rounded-(--rad-switch-radius)',
|
|
57
64
|
'rounded-(--rad-switch-thumb-radius)',
|
|
65
|
+
'rounded-(--rad-combobox-content-radius)',
|
|
58
66
|
'rounded-(--rad-select-content-radius)',
|
|
67
|
+
'rounded-(--rad-combobox-item-radius)',
|
|
59
68
|
'rounded-(--rad-select-item-radius)',
|
|
60
69
|
'rounded-(--rad-slider-track-radius)',
|
|
61
70
|
'rounded-(--rad-slider-thumb-radius)',
|
|
@@ -64,6 +73,7 @@ export const cn: CnFunction = createCn({
|
|
|
64
73
|
'rounded-(--rad-tabs-content-radius)'
|
|
65
74
|
],
|
|
66
75
|
'border-w': [
|
|
76
|
+
'border-(--rad-combobox-border-width)',
|
|
67
77
|
'border-(--rad-select-border-width)',
|
|
68
78
|
'border-(--rad-textarea-border-width)',
|
|
69
79
|
'border-(--rad-switch-border-width)',
|
|
@@ -71,17 +81,21 @@ export const cn: CnFunction = createCn({
|
|
|
71
81
|
'border-(--rad-tabs-trigger-border-width)'
|
|
72
82
|
],
|
|
73
83
|
'border-style': [
|
|
84
|
+
'border-(--rad-combobox-border-style)',
|
|
74
85
|
'border-(--rad-select-border-style)',
|
|
75
86
|
'border-(--rad-textarea-border-style)',
|
|
76
87
|
'border-(--rad-switch-border-style)'
|
|
77
88
|
],
|
|
78
89
|
shadow: [
|
|
90
|
+
'shadow-(--rad-combobox-shadow)',
|
|
79
91
|
'shadow-(--rad-select-shadow)',
|
|
92
|
+
'shadow-(--rad-combobox-content-shadow)',
|
|
80
93
|
'shadow-(--rad-select-content-shadow)',
|
|
81
94
|
'shadow-(--rad-textarea-shadow)',
|
|
82
95
|
'shadow-(--rad-slider-thumb-shadow)'
|
|
83
96
|
],
|
|
84
97
|
'corner-shape': [
|
|
98
|
+
'[corner-shape:var(--rad-combobox-corner-shape)]',
|
|
85
99
|
'[corner-shape:var(--rad-select-corner-shape)]',
|
|
86
100
|
'[corner-shape:var(--rad-textarea-corner-shape)]',
|
|
87
101
|
'[corner-shape:var(--rad-switch-corner-shape)]',
|
|
@@ -107,7 +121,10 @@ export const cn: CnFunction = createCn({
|
|
|
107
121
|
'outline-(--rad-tabs-focus-style)'
|
|
108
122
|
],
|
|
109
123
|
opacity: ['opacity-(--rad-tabs-disabled-opacity)'],
|
|
110
|
-
'backdrop-filter': [
|
|
124
|
+
'backdrop-filter': [
|
|
125
|
+
'[backdrop-filter:var(--rad-combobox-content-backdrop-filter)]',
|
|
126
|
+
'[backdrop-filter:var(--rad-select-content-backdrop-filter)]'
|
|
127
|
+
],
|
|
111
128
|
leading: roleClasses('leading', 'line-height'),
|
|
112
129
|
tracking: roleClasses('tracking', 'letter-spacing'),
|
|
113
130
|
'max-inline-size': roleClasses('max-inline', 'measure'),
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { controlBorderClass } from './controlStyles.js'
|
|
2
|
+
|
|
3
|
+
export const comboboxInputClass = [
|
|
4
|
+
controlBorderClass,
|
|
5
|
+
'box-border w-full min-w-0 text-start pe-12',
|
|
6
|
+
'h-[var(--rad-combobox-height,var(--_rad-control-height))] px-[var(--rad-combobox-padding,var(--_rad-control-padding))]',
|
|
7
|
+
'font-[family-name:var(--rad-combobox-font-family,var(--rad-typography-roles-ui-body-family,system-ui,sans-serif))] text-[length:var(--rad-combobox-font-size,var(--_rad-control-font-size))] font-[number:var(--rad-combobox-font-weight,var(--rad-typography-roles-ui-body-weight,400))] leading-[var(--rad-typography-roles-ui-body-line-height,1.5)] tracking-[var(--rad-typography-roles-ui-body-letter-spacing,-0.011em)]',
|
|
8
|
+
'[color:var(--rad-combobox-color,var(--rad-color-foreground,oklch(0.21_0.006_286)))] bg-[var(--rad-combobox-background,var(--rad-color-surface,white))]',
|
|
9
|
+
'[border-width:var(--rad-combobox-border-width,var(--rad-control-border-width,1px))] [border-style:var(--rad-combobox-border-style,var(--rad-control-border-style,solid))] [border-color:var(--rad-combobox-border-color,var(--_rad-control-border))]',
|
|
10
|
+
'rounded-[var(--rad-combobox-radius,var(--rad-control-radius,0.5rem))] [corner-shape:var(--rad-combobox-corner-shape,var(--rad-control-corner-shape,round))] [box-shadow:var(--rad-combobox-shadow,none)]',
|
|
11
|
+
'focus-visible:outline-solid focus-visible:[outline-color:var(--rad-combobox-focus-color,var(--rad-color-focus))] focus-visible:[outline-width:var(--rad-focus-width,2px)] focus-visible:[outline-offset:var(--rad-focus-offset,2px)]',
|
|
12
|
+
'data-invalid:[border-color:var(--rad-color-invalid)] placeholder:[color:var(--rad-combobox-placeholder,var(--rad-color-placeholder))] disabled:cursor-not-allowed disabled:bg-[var(--rad-color-disabled-background)]',
|
|
13
|
+
'forced-colors:border-[CanvasText] forced-colors:bg-[Canvas] forced-colors:text-[CanvasText] forced-colors:disabled:text-[GrayText]'
|
|
14
|
+
].join(' ')
|
|
15
|
+
|
|
16
|
+
export const comboboxContentClass = [
|
|
17
|
+
'fixed right-auto bottom-auto m-0 box-border min-w-0 overflow-hidden overscroll-contain',
|
|
18
|
+
'left-[var(--_rad-combobox-left,0px)] top-[var(--_rad-combobox-top,0px)] w-[var(--_rad-combobox-width,auto)] max-h-[var(--_rad-combobox-max-height,calc(100dvh-1rem))]',
|
|
19
|
+
'p-[var(--rad-combobox-content-padding,0.25rem)] rounded-[var(--rad-combobox-content-radius,var(--rad-surface-radius,0.75rem))]',
|
|
20
|
+
'[border-width:var(--rad-combobox-border-width,var(--rad-surface-border-width,1px))] [border-style:var(--rad-combobox-border-style,var(--rad-surface-border-style,solid))] [border-color:var(--rad-combobox-border-color,var(--rad-color-border))]',
|
|
21
|
+
'bg-[var(--rad-combobox-content-background,var(--rad-color-surface,white))] [color:var(--rad-combobox-color,var(--rad-color-foreground))] [box-shadow:var(--rad-combobox-content-shadow,var(--rad-surface-overlay-shadow,0_8px_32px_#0003))]',
|
|
22
|
+
'[backdrop-filter:var(--rad-combobox-content-backdrop-filter,none)]',
|
|
23
|
+
'font-[family-name:var(--rad-combobox-font-family,var(--rad-typography-roles-ui-body-family,system-ui,sans-serif))] text-[length:var(--rad-combobox-font-size,var(--_rad-control-font-size))] leading-[var(--rad-typography-roles-ui-body-line-height,1.5)] font-[number:var(--rad-combobox-font-weight,var(--rad-typography-roles-ui-body-weight,400))]',
|
|
24
|
+
'outline-none forced-colors:border-[CanvasText] forced-colors:bg-[Canvas] forced-colors:text-[CanvasText]'
|
|
25
|
+
].join(' ')
|
|
26
|
+
|
|
27
|
+
export const comboboxItemClass = [
|
|
28
|
+
'relative flex min-w-0 cursor-default select-none items-center gap-2 break-words rounded-[var(--rad-combobox-item-radius,var(--rad-control-radius,0.5rem))]',
|
|
29
|
+
'min-h-[var(--_rad-control-height,2.5rem)] px-[var(--_rad-control-padding,1rem)] py-2 outline-none',
|
|
30
|
+
'data-highlighted:[background:var(--rad-combobox-item-background,var(--rad-color-accent))] data-highlighted:[color:var(--rad-combobox-item-color,var(--rad-color-accent-foreground))]',
|
|
31
|
+
'data-disabled:opacity-[var(--rad-state-disabled-opacity,0.5)] data-disabled:cursor-not-allowed',
|
|
32
|
+
'forced-colors:data-highlighted:bg-[Highlight] forced-colors:data-highlighted:text-[HighlightText] forced-colors:data-disabled:text-[GrayText] forced-colors:data-disabled:opacity-100'
|
|
33
|
+
].join(' ')
|
|
34
|
+
|
|
35
|
+
/** An input adornment keeps Button semantics without inheriting action presentation. */
|
|
36
|
+
export const comboboxActionClass = [
|
|
37
|
+
'inline-flex shrink-0 items-center justify-center border-0 bg-transparent p-0 [font:inherit]',
|
|
38
|
+
'[color:var(--rad-combobox-color,var(--rad-color-foreground))] shadow-none cursor-pointer',
|
|
39
|
+
'focus-visible:outline-solid focus-visible:[outline-color:var(--rad-combobox-focus-color,var(--rad-color-focus))] focus-visible:[outline-width:var(--rad-focus-width,2px)] focus-visible:[outline-offset:var(--rad-focus-offset,2px)]',
|
|
40
|
+
'disabled:cursor-not-allowed forced-colors:text-[CanvasText] forced-colors:disabled:text-[GrayText]'
|
|
41
|
+
].join(' ')
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
export {
|
|
2
|
+
Combobox,
|
|
3
|
+
ComboboxInput,
|
|
4
|
+
ComboboxTrigger,
|
|
5
|
+
ComboboxClear,
|
|
6
|
+
ComboboxPortal,
|
|
7
|
+
ComboboxContent,
|
|
8
|
+
ComboboxItem,
|
|
9
|
+
ComboboxStatus,
|
|
10
|
+
useCombobox
|
|
11
|
+
} from './Combobox.js'
|
|
12
|
+
export type {
|
|
13
|
+
ComboboxProps,
|
|
14
|
+
ComboboxOption,
|
|
15
|
+
ComboboxState,
|
|
16
|
+
ComboboxInputProps,
|
|
17
|
+
ComboboxTriggerProps,
|
|
18
|
+
ComboboxClearProps,
|
|
19
|
+
ComboboxContentProps,
|
|
20
|
+
ComboboxItemProps,
|
|
21
|
+
ComboboxStatusProps
|
|
22
|
+
} from './Combobox.js'
|
|
1
23
|
export { Button } from './Button.js'
|
|
2
24
|
export { Link } from './Link.js'
|
|
3
25
|
export type { LinkProps, LinkRenderProps, LinkVariant } from './Link.js'
|
|
@@ -69,6 +91,27 @@ export type {
|
|
|
69
91
|
DialogTitleProps,
|
|
70
92
|
DialogTriggerProps
|
|
71
93
|
} from './Dialog.js'
|
|
94
|
+
export {
|
|
95
|
+
AlertDialog,
|
|
96
|
+
AlertDialogTrigger,
|
|
97
|
+
AlertDialogContent,
|
|
98
|
+
AlertDialogTitle,
|
|
99
|
+
AlertDialogDescription,
|
|
100
|
+
AlertDialogAction,
|
|
101
|
+
AlertDialogCancel,
|
|
102
|
+
useAlertDialog
|
|
103
|
+
} from './AlertDialog.js'
|
|
104
|
+
export type {
|
|
105
|
+
AlertDialogProps,
|
|
106
|
+
AlertDialogState,
|
|
107
|
+
AlertDialogRenderProps,
|
|
108
|
+
AlertDialogTriggerProps,
|
|
109
|
+
AlertDialogContentProps,
|
|
110
|
+
AlertDialogTitleProps,
|
|
111
|
+
AlertDialogDescriptionProps,
|
|
112
|
+
AlertDialogActionProps,
|
|
113
|
+
AlertDialogCancelProps
|
|
114
|
+
} from './AlertDialog.js'
|
|
72
115
|
export {
|
|
73
116
|
Collapsible,
|
|
74
117
|
CollapsibleContent,
|
package/src/motion/popup.ts
CHANGED
|
@@ -12,11 +12,11 @@ export function bindPopupMotion(node: HTMLElement, initial: MotionProfile): Moti
|
|
|
12
12
|
...resolveMotion(profile, 'dialog', query.matches),
|
|
13
13
|
reducedValue: 0
|
|
14
14
|
})
|
|
15
|
-
const previous = node.style.getPropertyValue('--_rad-
|
|
15
|
+
const previous = node.style.getPropertyValue('--_rad-popup-enter')
|
|
16
16
|
let owned = previous
|
|
17
17
|
const render = (value: number) => {
|
|
18
18
|
owned = String(Math.max(0, Math.min(1, value)))
|
|
19
|
-
node.style.setProperty('--_rad-
|
|
19
|
+
node.style.setProperty('--_rad-popup-enter', owned)
|
|
20
20
|
}
|
|
21
21
|
const off = spring.subscribe(render)
|
|
22
22
|
render(spring.get())
|
|
@@ -46,9 +46,9 @@ export function bindPopupMotion(node: HTMLElement, initial: MotionProfile): Moti
|
|
|
46
46
|
query.removeEventListener('change', sync)
|
|
47
47
|
off()
|
|
48
48
|
spring.destroy()
|
|
49
|
-
if (node.style.getPropertyValue('--_rad-
|
|
50
|
-
if (previous) node.style.setProperty('--_rad-
|
|
51
|
-
else node.style.removeProperty('--_rad-
|
|
49
|
+
if (node.style.getPropertyValue('--_rad-popup-enter') === owned) {
|
|
50
|
+
if (previous) node.style.setProperty('--_rad-popup-enter', previous)
|
|
51
|
+
else node.style.removeProperty('--_rad-popup-enter')
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useLayoutEffect, useRef, type RefObject } from 'react'
|
|
4
|
+
import { positionSelect } from '../internal/select.js'
|
|
5
|
+
|
|
6
|
+
/** Local top-layer popup: preserve theme/modal ancestry and place before its first paint. */
|
|
7
|
+
export function useComboboxPopup(
|
|
8
|
+
nodeRef: RefObject<HTMLDivElement | null>,
|
|
9
|
+
input: HTMLInputElement | null,
|
|
10
|
+
open: boolean,
|
|
11
|
+
dismiss: () => void,
|
|
12
|
+
sideOffset: number,
|
|
13
|
+
collisionPadding: number
|
|
14
|
+
) {
|
|
15
|
+
const latest = useRef(dismiss)
|
|
16
|
+
useLayoutEffect(() => {
|
|
17
|
+
latest.current = dismiss
|
|
18
|
+
})
|
|
19
|
+
useLayoutEffect(() => {
|
|
20
|
+
const node = nodeRef.current
|
|
21
|
+
if (!node || !input) return
|
|
22
|
+
if (!open) {
|
|
23
|
+
if (node.matches(':popover-open')) node.hidePopover()
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
const doc = input.ownerDocument
|
|
27
|
+
const win = doc.defaultView!
|
|
28
|
+
const seedWidth = () => {
|
|
29
|
+
const available =
|
|
30
|
+
(win.visualViewport?.width ?? win.innerWidth) - 2 * Math.max(0, collisionPadding)
|
|
31
|
+
node.style.setProperty(
|
|
32
|
+
'--_rad-combobox-width',
|
|
33
|
+
`${Math.min(input.getBoundingClientRect().width, Math.max(0, available))}px`
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
seedWidth()
|
|
37
|
+
node.showPopover()
|
|
38
|
+
const place = () => {
|
|
39
|
+
if (!node.isConnected || !node.matches(':popover-open')) return
|
|
40
|
+
seedWidth()
|
|
41
|
+
const viewport = win.visualViewport
|
|
42
|
+
const css = win.getComputedStyle(node)
|
|
43
|
+
const anchor = input.getBoundingClientRect()
|
|
44
|
+
const padding = Math.max(0, collisionPadding)
|
|
45
|
+
const list = node.querySelector<HTMLElement>('[data-slot="combobox-listbox"]')
|
|
46
|
+
const status = node.querySelector<HTMLElement>('[data-slot="combobox-status"]')
|
|
47
|
+
const naturalHeight =
|
|
48
|
+
(list?.scrollHeight ?? node.scrollHeight) +
|
|
49
|
+
(status?.offsetHeight ?? 0) +
|
|
50
|
+
parseFloat(css.paddingTop) +
|
|
51
|
+
parseFloat(css.paddingBottom) +
|
|
52
|
+
parseFloat(css.borderTopWidth) +
|
|
53
|
+
parseFloat(css.borderBottomWidth)
|
|
54
|
+
const above = anchor.top - (viewport?.offsetTop ?? 0) - padding - sideOffset
|
|
55
|
+
const below =
|
|
56
|
+
(viewport?.offsetTop ?? 0) +
|
|
57
|
+
(viewport?.height ?? win.innerHeight) -
|
|
58
|
+
anchor.bottom -
|
|
59
|
+
padding -
|
|
60
|
+
sideOffset
|
|
61
|
+
const next = positionSelect({
|
|
62
|
+
trigger: anchor,
|
|
63
|
+
width: node.getBoundingClientRect().width,
|
|
64
|
+
height: Math.min(naturalHeight, Math.max(0, above, below)),
|
|
65
|
+
selectedOffset: 0,
|
|
66
|
+
viewport: {
|
|
67
|
+
top: viewport?.offsetTop ?? 0,
|
|
68
|
+
left: viewport?.offsetLeft ?? 0,
|
|
69
|
+
width: viewport?.width ?? win.innerWidth,
|
|
70
|
+
height: viewport?.height ?? win.innerHeight
|
|
71
|
+
},
|
|
72
|
+
padding: Math.max(0, collisionPadding),
|
|
73
|
+
offset: sideOffset,
|
|
74
|
+
aligned: false,
|
|
75
|
+
rtl: win.getComputedStyle(input).direction === 'rtl'
|
|
76
|
+
})
|
|
77
|
+
for (const [key, value] of Object.entries({
|
|
78
|
+
top: next.top,
|
|
79
|
+
left: next.left,
|
|
80
|
+
width: next.width,
|
|
81
|
+
'max-height': next.maxHeight
|
|
82
|
+
})) {
|
|
83
|
+
const property = `--_rad-combobox-${key}`
|
|
84
|
+
if (node.style.getPropertyValue(property) !== `${value}px`)
|
|
85
|
+
node.style.setProperty(property, `${value}px`)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
place()
|
|
89
|
+
let frame = 0
|
|
90
|
+
const schedule = () => {
|
|
91
|
+
if (!frame)
|
|
92
|
+
frame = win.requestAnimationFrame(() => {
|
|
93
|
+
frame = 0
|
|
94
|
+
place()
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
const outside = (event: PointerEvent | FocusEvent) => {
|
|
98
|
+
const target = event.target
|
|
99
|
+
if (
|
|
100
|
+
target instanceof win.Node &&
|
|
101
|
+
!node.contains(target) &&
|
|
102
|
+
!input.parentElement?.contains(target)
|
|
103
|
+
)
|
|
104
|
+
latest.current()
|
|
105
|
+
}
|
|
106
|
+
const observer = new win.ResizeObserver(schedule)
|
|
107
|
+
const mutations = new win.MutationObserver(schedule)
|
|
108
|
+
observer.observe(input)
|
|
109
|
+
observer.observe(node)
|
|
110
|
+
mutations.observe(node, { childList: true, subtree: true, characterData: true })
|
|
111
|
+
doc.addEventListener('pointerdown', outside, true)
|
|
112
|
+
doc.addEventListener('focusin', outside)
|
|
113
|
+
doc.addEventListener('scroll', schedule, true)
|
|
114
|
+
win.addEventListener('resize', schedule)
|
|
115
|
+
win.visualViewport?.addEventListener('resize', schedule)
|
|
116
|
+
win.visualViewport?.addEventListener('scroll', schedule)
|
|
117
|
+
return () => {
|
|
118
|
+
observer.disconnect()
|
|
119
|
+
mutations.disconnect()
|
|
120
|
+
win.cancelAnimationFrame(frame)
|
|
121
|
+
doc.removeEventListener('pointerdown', outside, true)
|
|
122
|
+
doc.removeEventListener('focusin', outside)
|
|
123
|
+
doc.removeEventListener('scroll', schedule, true)
|
|
124
|
+
win.removeEventListener('resize', schedule)
|
|
125
|
+
win.visualViewport?.removeEventListener('resize', schedule)
|
|
126
|
+
win.visualViewport?.removeEventListener('scroll', schedule)
|
|
127
|
+
if (node.matches(':popover-open')) node.hidePopover()
|
|
128
|
+
}
|
|
129
|
+
}, [nodeRef, input, open, sideOffset, collisionPadding])
|
|
130
|
+
}
|
package/src/themes/components.ts
CHANGED
|
@@ -169,6 +169,31 @@ export const componentRegistry = {
|
|
|
169
169
|
contentColor: 'css',
|
|
170
170
|
contentBackground: 'css'
|
|
171
171
|
},
|
|
172
|
+
combobox: {
|
|
173
|
+
placeholder: 'css',
|
|
174
|
+
height: 'css',
|
|
175
|
+
padding: 'css',
|
|
176
|
+
fontFamily: 'css',
|
|
177
|
+
fontSize: 'css',
|
|
178
|
+
fontWeight: 'weight',
|
|
179
|
+
color: 'css',
|
|
180
|
+
background: 'css',
|
|
181
|
+
borderWidth: 'css',
|
|
182
|
+
borderStyle: 'css',
|
|
183
|
+
borderColor: 'css',
|
|
184
|
+
radius: 'css',
|
|
185
|
+
cornerShape: 'css',
|
|
186
|
+
shadow: 'css',
|
|
187
|
+
focusColor: 'css',
|
|
188
|
+
contentPadding: 'css',
|
|
189
|
+
contentRadius: 'css',
|
|
190
|
+
contentBackground: 'css',
|
|
191
|
+
contentBackdropFilter: 'css',
|
|
192
|
+
contentShadow: 'css',
|
|
193
|
+
itemRadius: 'css',
|
|
194
|
+
itemBackground: 'css',
|
|
195
|
+
itemColor: 'css'
|
|
196
|
+
},
|
|
172
197
|
select: {
|
|
173
198
|
height: 'css',
|
|
174
199
|
padding: 'css',
|