@appica/ui-react 1.4.0 → 1.5.0
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 +20 -0
- package/README.md +8 -2
- package/agent-rules.md +8 -2
- package/appica.css +2 -2
- package/dist/components/badge/badge.js +1 -1
- package/dist/components/badge/badge.js.map +1 -1
- package/dist/components/button/button-variants.js +1 -1
- package/dist/components/button/button-variants.js.map +1 -1
- package/dist/components/card/card.js +1 -1
- package/dist/components/card/card.js.map +1 -1
- package/dist/components/carousel/carousel.d.ts.map +1 -1
- package/dist/components/carousel/carousel.js +12 -4
- package/dist/components/carousel/carousel.js.map +1 -1
- package/dist/components/checkbox/checkbox.js +1 -1
- package/dist/components/checkbox/checkbox.js.map +1 -1
- package/dist/components/command-palette/command-palette.d.ts +91 -0
- package/dist/components/command-palette/command-palette.d.ts.map +1 -0
- package/dist/components/command-palette/command-palette.js +376 -0
- package/dist/components/command-palette/command-palette.js.map +1 -0
- package/dist/components/date-field/date-field.js +1 -1
- package/dist/components/date-field/date-field.js.map +1 -1
- package/dist/components/date-picker/date-picker.js +1 -1
- package/dist/components/date-picker/date-picker.js.map +1 -1
- package/dist/components/input/input-variants.js +2 -2
- package/dist/components/input/input-variants.js.map +1 -1
- package/dist/components/radio/radio.js +1 -1
- package/dist/components/radio/radio.js.map +1 -1
- package/dist/components/splitter/splitter.d.ts +57 -0
- package/dist/components/splitter/splitter.d.ts.map +1 -0
- package/dist/components/splitter/splitter.js +395 -0
- package/dist/components/splitter/splitter.js.map +1 -0
- package/dist/components/textarea/textarea.js +1 -1
- package/dist/components/textarea/textarea.js.map +1 -1
- package/dist/components/time-field/time-field.js +1 -1
- package/dist/components/time-field/time-field.js.map +1 -1
- package/dist/components/toc/toc.d.ts +6 -1
- package/dist/components/toc/toc.d.ts.map +1 -1
- package/dist/components/toc/toc.js +15 -7
- package/dist/components/toc/toc.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +24 -14
- package/src/components/badge/badge.tsx +1 -1
- package/src/components/button/button-variants.ts +1 -1
- package/src/components/card/card.tsx +1 -1
- package/src/components/carousel/carousel.test.tsx +134 -1
- package/src/components/carousel/carousel.tsx +13 -4
- package/src/components/checkbox/checkbox.tsx +1 -1
- package/src/components/command-palette/command-palette.test.tsx +280 -0
- package/src/components/command-palette/command-palette.tsx +544 -0
- package/src/components/compare-slider/compare-slider.test.tsx +8 -7
- package/src/components/date-field/date-field.tsx +1 -1
- package/src/components/date-picker/date-picker.tsx +1 -1
- package/src/components/input/input-variants.ts +2 -2
- package/src/components/radio/radio.tsx +1 -1
- package/src/components/rating/rating.test.tsx +10 -3
- package/src/components/splitter/splitter.test.tsx +415 -0
- package/src/components/splitter/splitter.tsx +555 -0
- package/src/components/textarea/textarea.tsx +1 -1
- package/src/components/time-field/time-field.tsx +1 -1
- package/src/components/toc/toc.test.tsx +15 -0
- package/src/components/toc/toc.tsx +22 -7
- package/src/index.ts +2 -0
- package/src/test/css.ts +9 -0
- package/src/test/setup.ts +13 -0
- package/styles.css +3 -0
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import { Autocomplete as BaseAutocomplete } from '@base-ui/react/autocomplete'
|
|
5
|
+
import { Dialog as BaseDialog } from '@base-ui/react/dialog'
|
|
6
|
+
import { cn, useComposedRefs } from '../../internal/utils'
|
|
7
|
+
import { type ModalContentProps, splitModalProps } from '../../internal/modal'
|
|
8
|
+
import { inputVariants } from '../input/input-variants'
|
|
9
|
+
import { ScrollArea } from '../scroll-area/scroll-area'
|
|
10
|
+
|
|
11
|
+
type CommandPaletteSize = 'sm' | 'md' | 'lg'
|
|
12
|
+
type CommandPaletteVariant = 'outline' | 'soft'
|
|
13
|
+
|
|
14
|
+
type BaseDialogRootProps = React.ComponentProps<typeof BaseDialog.Root>
|
|
15
|
+
type BaseAutocompleteRootProps = React.ComponentProps<typeof BaseAutocomplete.Root>
|
|
16
|
+
type CommandPaletteSearchProps = Pick<
|
|
17
|
+
BaseAutocompleteRootProps,
|
|
18
|
+
| 'items'
|
|
19
|
+
| 'filteredItems'
|
|
20
|
+
| 'filter'
|
|
21
|
+
| 'value'
|
|
22
|
+
| 'defaultValue'
|
|
23
|
+
| 'onValueChange'
|
|
24
|
+
| 'onItemHighlighted'
|
|
25
|
+
| 'itemToStringValue'
|
|
26
|
+
| 'limit'
|
|
27
|
+
| 'locale'
|
|
28
|
+
>
|
|
29
|
+
|
|
30
|
+
interface CommandPaletteContextValue {
|
|
31
|
+
size: CommandPaletteSize
|
|
32
|
+
handle: NonNullable<BaseDialogRootProps['handle']>
|
|
33
|
+
search: CommandPaletteSearchProps
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const CommandPaletteContext = React.createContext<CommandPaletteContextValue | null>(null)
|
|
37
|
+
|
|
38
|
+
function useCommandPaletteContext(component: string) {
|
|
39
|
+
const ctx = React.useContext(CommandPaletteContext)
|
|
40
|
+
if (!ctx) throw new Error(`Appica UI: <${component}> must be used within <CommandPalette>.`)
|
|
41
|
+
return ctx
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface CommandPaletteContentContextValue {
|
|
45
|
+
inputRef: React.RefObject<HTMLInputElement | null>
|
|
46
|
+
label: string
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const CommandPaletteContentContext = React.createContext<CommandPaletteContentContextValue | null>(null)
|
|
50
|
+
|
|
51
|
+
interface CommandPaletteProps extends BaseDialogRootProps, CommandPaletteSearchProps {
|
|
52
|
+
/**
|
|
53
|
+
* Key that opens and closes the palette together with ⌘ or Ctrl, e.g. `'k'` for ⌘K.
|
|
54
|
+
*/
|
|
55
|
+
shortcut?: string
|
|
56
|
+
/**
|
|
57
|
+
* Input height, item and label sizing.
|
|
58
|
+
* @default 'md'
|
|
59
|
+
*/
|
|
60
|
+
size?: CommandPaletteSize
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function CommandPaletteRoot({
|
|
64
|
+
shortcut,
|
|
65
|
+
size = 'md',
|
|
66
|
+
handle,
|
|
67
|
+
items,
|
|
68
|
+
filteredItems,
|
|
69
|
+
filter,
|
|
70
|
+
value,
|
|
71
|
+
defaultValue,
|
|
72
|
+
onValueChange,
|
|
73
|
+
onItemHighlighted,
|
|
74
|
+
itemToStringValue,
|
|
75
|
+
limit,
|
|
76
|
+
locale,
|
|
77
|
+
...props
|
|
78
|
+
}: CommandPaletteProps) {
|
|
79
|
+
const [ownHandle] = React.useState(() => BaseDialog.createHandle())
|
|
80
|
+
const dialogHandle = handle ?? ownHandle
|
|
81
|
+
|
|
82
|
+
React.useEffect(() => {
|
|
83
|
+
if (!shortcut) return
|
|
84
|
+
const key = shortcut.toLowerCase()
|
|
85
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
86
|
+
if (event.key.toLowerCase() !== key || !(event.metaKey || event.ctrlKey) || event.altKey) return
|
|
87
|
+
event.preventDefault()
|
|
88
|
+
if (dialogHandle.isOpen) dialogHandle.close()
|
|
89
|
+
else dialogHandle.open(null)
|
|
90
|
+
}
|
|
91
|
+
window.addEventListener('keydown', onKeyDown)
|
|
92
|
+
return () => window.removeEventListener('keydown', onKeyDown)
|
|
93
|
+
}, [shortcut, dialogHandle])
|
|
94
|
+
|
|
95
|
+
const ctx = React.useMemo<CommandPaletteContextValue>(
|
|
96
|
+
() => ({
|
|
97
|
+
size,
|
|
98
|
+
handle: dialogHandle,
|
|
99
|
+
search: {
|
|
100
|
+
items,
|
|
101
|
+
filteredItems,
|
|
102
|
+
filter,
|
|
103
|
+
value,
|
|
104
|
+
defaultValue,
|
|
105
|
+
onValueChange,
|
|
106
|
+
onItemHighlighted,
|
|
107
|
+
itemToStringValue,
|
|
108
|
+
limit,
|
|
109
|
+
locale,
|
|
110
|
+
},
|
|
111
|
+
}),
|
|
112
|
+
[
|
|
113
|
+
size,
|
|
114
|
+
dialogHandle,
|
|
115
|
+
items,
|
|
116
|
+
filteredItems,
|
|
117
|
+
filter,
|
|
118
|
+
value,
|
|
119
|
+
defaultValue,
|
|
120
|
+
onValueChange,
|
|
121
|
+
onItemHighlighted,
|
|
122
|
+
itemToStringValue,
|
|
123
|
+
limit,
|
|
124
|
+
locale,
|
|
125
|
+
],
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<CommandPaletteContext.Provider value={ctx}>
|
|
130
|
+
<BaseDialog.Root handle={dialogHandle} {...props} />
|
|
131
|
+
</CommandPaletteContext.Provider>
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const CommandPalette = Object.assign(CommandPaletteRoot, { createHandle: BaseDialog.createHandle })
|
|
136
|
+
|
|
137
|
+
type CommandPaletteTriggerProps = React.ComponentProps<typeof BaseDialog.Trigger>
|
|
138
|
+
|
|
139
|
+
function CommandPaletteTrigger({ className, ...props }: CommandPaletteTriggerProps) {
|
|
140
|
+
return <BaseDialog.Trigger data-slot="command-palette-trigger" className={cn(className)} {...props} />
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
type CommandPaletteContentProps = ModalContentProps<
|
|
144
|
+
React.ComponentProps<typeof BaseDialog.Popup>,
|
|
145
|
+
React.ComponentProps<typeof BaseDialog.Portal>,
|
|
146
|
+
React.ComponentProps<typeof BaseDialog.Backdrop>,
|
|
147
|
+
React.ComponentProps<typeof BaseDialog.Viewport>
|
|
148
|
+
> & {
|
|
149
|
+
/**
|
|
150
|
+
* Accessible name of the dialog, read by screen readers and kept out of sight.
|
|
151
|
+
* @default 'Command palette'
|
|
152
|
+
*/
|
|
153
|
+
label?: string
|
|
154
|
+
/**
|
|
155
|
+
* Render the dimmed, blurred backdrop behind the palette.
|
|
156
|
+
* @default true
|
|
157
|
+
*/
|
|
158
|
+
backdrop?: boolean
|
|
159
|
+
/**
|
|
160
|
+
* Wrap the palette in a translucent glass frame. Needs `backdrop`: without one the palette is
|
|
161
|
+
* always a plain solid card.
|
|
162
|
+
* @default true
|
|
163
|
+
*/
|
|
164
|
+
frame?: boolean
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function CommandPaletteContent({
|
|
168
|
+
className,
|
|
169
|
+
children,
|
|
170
|
+
label = 'Command palette',
|
|
171
|
+
backdrop = true,
|
|
172
|
+
frame = true,
|
|
173
|
+
initialFocus,
|
|
174
|
+
backdropProps,
|
|
175
|
+
viewportProps,
|
|
176
|
+
...props
|
|
177
|
+
}: CommandPaletteContentProps) {
|
|
178
|
+
const { search } = useCommandPaletteContext('CommandPaletteContent')
|
|
179
|
+
const inputRef = React.useRef<HTMLInputElement>(null)
|
|
180
|
+
const showFrame = frame && backdrop
|
|
181
|
+
const { portal, popup } = splitModalProps(props)
|
|
182
|
+
const { onValueChange } = search
|
|
183
|
+
|
|
184
|
+
const handleValueChange = React.useCallback<NonNullable<CommandPaletteSearchProps['onValueChange']>>(
|
|
185
|
+
(next, eventDetails) => {
|
|
186
|
+
// Running an item would otherwise write its label into the input.
|
|
187
|
+
if (eventDetails.reason === 'item-press') {
|
|
188
|
+
eventDetails.cancel()
|
|
189
|
+
return
|
|
190
|
+
}
|
|
191
|
+
onValueChange?.(next, eventDetails)
|
|
192
|
+
},
|
|
193
|
+
[onValueChange],
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
const contentCtx = React.useMemo(() => ({ inputRef, label }), [label])
|
|
197
|
+
|
|
198
|
+
return (
|
|
199
|
+
<BaseDialog.Portal {...portal}>
|
|
200
|
+
{backdrop && (
|
|
201
|
+
<BaseDialog.Backdrop
|
|
202
|
+
data-slot="command-palette-backdrop"
|
|
203
|
+
{...backdropProps}
|
|
204
|
+
className={cn(
|
|
205
|
+
'fixed inset-0 z-50 bg-black/30 backdrop-blur-sm supports-[-webkit-touch-callout:none]:absolute',
|
|
206
|
+
'motion-safe:transition-opacity motion-safe:duration-250 motion-safe:ease-out',
|
|
207
|
+
'data-ending-style:motion-safe:opacity-0 data-starting-style:motion-safe:opacity-0',
|
|
208
|
+
backdropProps?.className as string | undefined,
|
|
209
|
+
)}
|
|
210
|
+
/>
|
|
211
|
+
)}
|
|
212
|
+
<BaseDialog.Viewport
|
|
213
|
+
data-slot="command-palette-viewport"
|
|
214
|
+
{...viewportProps}
|
|
215
|
+
className={cn(
|
|
216
|
+
'fixed inset-0 z-50 flex items-start justify-center overflow-hidden px-4 py-16 md:py-24',
|
|
217
|
+
viewportProps?.className as string | undefined,
|
|
218
|
+
)}
|
|
219
|
+
>
|
|
220
|
+
<BaseDialog.Popup
|
|
221
|
+
data-slot="command-palette-content"
|
|
222
|
+
{...(showFrame ? { 'data-frame': '' } : {})}
|
|
223
|
+
initialFocus={initialFocus ?? inputRef}
|
|
224
|
+
className={cn(
|
|
225
|
+
'relative flex max-h-full min-h-0 w-140 max-w-full flex-col',
|
|
226
|
+
'rounded-2xl border',
|
|
227
|
+
showFrame ? 'border-white/15 bg-white/10 p-1.5 backdrop-blur-sm' : 'bg-background border-border-overlay',
|
|
228
|
+
!showFrame && 'shadow-2xl',
|
|
229
|
+
'isolate transform-gpu outline-none',
|
|
230
|
+
'motion-safe:ease-spring motion-safe:transition-[opacity,scale] motion-safe:duration-250',
|
|
231
|
+
'data-starting-style:motion-safe:scale-95 data-starting-style:motion-safe:opacity-0',
|
|
232
|
+
'data-ending-style:motion-safe:scale-95 data-ending-style:motion-safe:opacity-0 data-ending-style:motion-safe:duration-100 data-ending-style:motion-safe:ease-out',
|
|
233
|
+
className,
|
|
234
|
+
)}
|
|
235
|
+
{...popup}
|
|
236
|
+
>
|
|
237
|
+
<div
|
|
238
|
+
data-slot="command-palette-body"
|
|
239
|
+
className={cn(
|
|
240
|
+
'relative flex min-h-0 flex-col overflow-hidden',
|
|
241
|
+
showFrame && 'bg-background rounded-[calc(var(--radius-2xl)*5/6)]',
|
|
242
|
+
)}
|
|
243
|
+
>
|
|
244
|
+
<BaseDialog.Title className="sr-only">{label}</BaseDialog.Title>
|
|
245
|
+
<CommandPaletteContentContext.Provider value={contentCtx}>
|
|
246
|
+
<BaseAutocomplete.Root inline open autoHighlight="always" {...search} onValueChange={handleValueChange}>
|
|
247
|
+
{children}
|
|
248
|
+
</BaseAutocomplete.Root>
|
|
249
|
+
</CommandPaletteContentContext.Provider>
|
|
250
|
+
</div>
|
|
251
|
+
</BaseDialog.Popup>
|
|
252
|
+
</BaseDialog.Viewport>
|
|
253
|
+
</BaseDialog.Portal>
|
|
254
|
+
)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// The list is always open inline, so the input always carries `data-popup-open`: Input's
|
|
258
|
+
// `within` state would read that as focus. Only real focus styles the palette's input.
|
|
259
|
+
const INPUT_STATE =
|
|
260
|
+
'flex items-center has-focus:ring-3 has-focus:ring-ring-input has-focus:border-transparent has-focus:bg-background has-[input:disabled]:cursor-not-allowed has-[input:disabled]:opacity-disabled'
|
|
261
|
+
|
|
262
|
+
const INPUT_HOVER: Record<CommandPaletteVariant, string> = {
|
|
263
|
+
outline: 'hover:not-has-focus:border-border-emphasis',
|
|
264
|
+
soft: 'hover:not-has-focus:border-border-strong',
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
interface CommandPaletteInputProps extends Omit<React.ComponentProps<typeof BaseAutocomplete.Input>, 'size'> {
|
|
268
|
+
/**
|
|
269
|
+
* Input appearance, bordered or filled.
|
|
270
|
+
* @default 'soft'
|
|
271
|
+
*/
|
|
272
|
+
variant?: CommandPaletteVariant
|
|
273
|
+
/** Adornment rendered before the field, inside the input frame. A search icon unless you pass your own or `null`. */
|
|
274
|
+
startSlot?: React.ReactNode
|
|
275
|
+
/** Adornment rendered after the field, inside the input frame. */
|
|
276
|
+
endSlot?: React.ReactNode
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function CommandPaletteInput({
|
|
280
|
+
className,
|
|
281
|
+
variant = 'soft',
|
|
282
|
+
startSlot,
|
|
283
|
+
endSlot,
|
|
284
|
+
placeholder,
|
|
285
|
+
ref,
|
|
286
|
+
...props
|
|
287
|
+
}: CommandPaletteInputProps) {
|
|
288
|
+
const { size } = useCommandPaletteContext('CommandPaletteInput')
|
|
289
|
+
const content = React.useContext(CommandPaletteContentContext)
|
|
290
|
+
const inputRef = useComposedRefs(content?.inputRef, ref)
|
|
291
|
+
const start = startSlot === undefined ? <SearchIcon /> : startSlot
|
|
292
|
+
|
|
293
|
+
return (
|
|
294
|
+
<BaseAutocomplete.InputGroup
|
|
295
|
+
data-slot="command-palette-input"
|
|
296
|
+
className={cn(
|
|
297
|
+
inputVariants({ variant, size, state: null }),
|
|
298
|
+
INPUT_STATE,
|
|
299
|
+
INPUT_HOVER[variant],
|
|
300
|
+
'm-3 w-auto shrink-0',
|
|
301
|
+
className,
|
|
302
|
+
)}
|
|
303
|
+
>
|
|
304
|
+
{start != null && (
|
|
305
|
+
<div data-slot="command-palette-input-start" className="text-foreground-subtle -ms-1 flex shrink-0">
|
|
306
|
+
{start}
|
|
307
|
+
</div>
|
|
308
|
+
)}
|
|
309
|
+
<BaseAutocomplete.Input
|
|
310
|
+
ref={inputRef}
|
|
311
|
+
data-slot="command-palette-input-field"
|
|
312
|
+
aria-label={content?.label}
|
|
313
|
+
placeholder={placeholder ?? ' '}
|
|
314
|
+
className="text-foreground placeholder:text-foreground-subtle h-full min-w-0 flex-1 bg-transparent outline-none"
|
|
315
|
+
{...props}
|
|
316
|
+
/>
|
|
317
|
+
{endSlot != null && (
|
|
318
|
+
<div data-slot="command-palette-input-end" className="flex shrink-0">
|
|
319
|
+
{endSlot}
|
|
320
|
+
</div>
|
|
321
|
+
)}
|
|
322
|
+
</BaseAutocomplete.InputGroup>
|
|
323
|
+
)
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const LIST_PADDING: Record<CommandPaletteSize, string> = {
|
|
327
|
+
sm: 'p-2',
|
|
328
|
+
md: 'p-3',
|
|
329
|
+
lg: 'p-3.5',
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
interface CommandPaletteListProps<T = any> extends Omit<
|
|
333
|
+
React.ComponentProps<typeof BaseAutocomplete.List>,
|
|
334
|
+
'children'
|
|
335
|
+
> {
|
|
336
|
+
/** A render function over the filtered items, or static items. */
|
|
337
|
+
children?: React.ReactNode | ((item: T, index: number) => React.ReactNode)
|
|
338
|
+
/** Props forwarded to the scroll area around the list, e.g. a fixed `className="h-110"`. */
|
|
339
|
+
scrollAreaProps?: Omit<React.ComponentProps<typeof ScrollArea>, 'children'>
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function CommandPaletteList<T = any>({ className, children, scrollAreaProps, ...props }: CommandPaletteListProps<T>) {
|
|
343
|
+
const { size } = useCommandPaletteContext('CommandPaletteList')
|
|
344
|
+
return (
|
|
345
|
+
<ScrollArea
|
|
346
|
+
scrollShadow
|
|
347
|
+
{...scrollAreaProps}
|
|
348
|
+
className={cn(
|
|
349
|
+
'border-border-muted max-h-[min(27.5rem,60vh)] min-h-0 shrink border-t',
|
|
350
|
+
scrollAreaProps?.className as string | undefined,
|
|
351
|
+
)}
|
|
352
|
+
>
|
|
353
|
+
<BaseAutocomplete.List
|
|
354
|
+
data-slot="command-palette-list"
|
|
355
|
+
className={cn('flex flex-col gap-0.5 outline-none data-empty:p-0', LIST_PADDING[size], className)}
|
|
356
|
+
{...props}
|
|
357
|
+
>
|
|
358
|
+
{children as React.ComponentProps<typeof BaseAutocomplete.List>['children']}
|
|
359
|
+
</BaseAutocomplete.List>
|
|
360
|
+
</ScrollArea>
|
|
361
|
+
)
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const ITEM_SIZE: Record<CommandPaletteSize, string> = {
|
|
365
|
+
sm: "gap-2 rounded-xs px-2 py-1.5 text-xs [&_svg:not([class*='size-'])]:size-3.5",
|
|
366
|
+
md: "gap-2.5 rounded-sm px-2.5 py-2 text-sm [&_svg:not([class*='size-'])]:size-4",
|
|
367
|
+
lg: "gap-3 rounded-md px-3 py-2.5 text-base [&_svg:not([class*='size-'])]:size-4.5",
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
interface CommandPaletteItemProps extends React.ComponentProps<typeof BaseAutocomplete.Item> {
|
|
371
|
+
/**
|
|
372
|
+
* Close the palette once the item runs, by click or Enter.
|
|
373
|
+
* @default true
|
|
374
|
+
*/
|
|
375
|
+
closeOnSelect?: boolean
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function CommandPaletteItem({ className, closeOnSelect = true, onClick, ...props }: CommandPaletteItemProps) {
|
|
379
|
+
const { size, handle } = useCommandPaletteContext('CommandPaletteItem')
|
|
380
|
+
return (
|
|
381
|
+
<BaseAutocomplete.Item
|
|
382
|
+
data-slot="command-palette-item"
|
|
383
|
+
onClick={(event) => {
|
|
384
|
+
onClick?.(event)
|
|
385
|
+
if (closeOnSelect) handle.close()
|
|
386
|
+
}}
|
|
387
|
+
className={cn(
|
|
388
|
+
'text-foreground relative isolate flex w-full cursor-default items-center outline-hidden select-none',
|
|
389
|
+
"[&_svg:not([class*='text-'])]:text-foreground-subtle [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='stroke-'])]:stroke-[1.75]",
|
|
390
|
+
'before:bg-background-muted before:absolute before:inset-0 before:-z-10 before:rounded-[inherit] before:opacity-0',
|
|
391
|
+
'data-highlighted:not-data-disabled:text-foreground-intense data-highlighted:not-data-disabled:before:opacity-100',
|
|
392
|
+
'motion-safe:before:transition-opacity motion-safe:before:duration-200 motion-safe:before:ease-out',
|
|
393
|
+
'data-disabled:opacity-disabled data-disabled:pointer-events-none',
|
|
394
|
+
ITEM_SIZE[size],
|
|
395
|
+
className,
|
|
396
|
+
)}
|
|
397
|
+
{...props}
|
|
398
|
+
/>
|
|
399
|
+
)
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
const EMPTY_SIZE: Record<CommandPaletteSize, string> = {
|
|
403
|
+
sm: 'px-3 py-6 text-xs',
|
|
404
|
+
md: 'px-4 py-8 text-sm',
|
|
405
|
+
lg: 'px-5 py-10 text-base',
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
interface CommandPaletteEmptyProps extends React.ComponentProps<typeof BaseAutocomplete.Empty> {}
|
|
409
|
+
|
|
410
|
+
function CommandPaletteEmpty({ className, ...props }: CommandPaletteEmptyProps) {
|
|
411
|
+
const { size } = useCommandPaletteContext('CommandPaletteEmpty')
|
|
412
|
+
return (
|
|
413
|
+
<BaseAutocomplete.Empty
|
|
414
|
+
data-slot="command-palette-empty"
|
|
415
|
+
className={cn('text-foreground-muted text-center empty:p-0', EMPTY_SIZE[size], className)}
|
|
416
|
+
{...props}
|
|
417
|
+
/>
|
|
418
|
+
)
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
type CommandPaletteStatusProps = React.ComponentProps<typeof BaseAutocomplete.Status>
|
|
422
|
+
|
|
423
|
+
function CommandPaletteStatus({ className, ...props }: CommandPaletteStatusProps) {
|
|
424
|
+
const { size } = useCommandPaletteContext('CommandPaletteStatus')
|
|
425
|
+
return (
|
|
426
|
+
<BaseAutocomplete.Status
|
|
427
|
+
data-slot="command-palette-status"
|
|
428
|
+
className={cn('text-foreground-muted text-center empty:p-0', EMPTY_SIZE[size], className)}
|
|
429
|
+
{...props}
|
|
430
|
+
/>
|
|
431
|
+
)
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
type CommandPaletteGroupProps = React.ComponentProps<typeof BaseAutocomplete.Group>
|
|
435
|
+
|
|
436
|
+
function CommandPaletteGroup({ className, ...props }: CommandPaletteGroupProps) {
|
|
437
|
+
return (
|
|
438
|
+
<BaseAutocomplete.Group
|
|
439
|
+
data-slot="command-palette-group"
|
|
440
|
+
className={cn('flex flex-col gap-0.5 not-first:mt-2', className)}
|
|
441
|
+
{...props}
|
|
442
|
+
/>
|
|
443
|
+
)
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
const LABEL_SIZE: Record<CommandPaletteSize, string> = {
|
|
447
|
+
sm: 'px-2 pt-1 pb-1 text-[0.6875rem]',
|
|
448
|
+
md: 'px-2.5 pt-1 pb-1.5 text-xs',
|
|
449
|
+
lg: 'px-3 pt-1.5 pb-1.5 text-sm',
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
type CommandPaletteLabelProps = React.ComponentProps<typeof BaseAutocomplete.GroupLabel>
|
|
453
|
+
|
|
454
|
+
function CommandPaletteLabel({ className, ...props }: CommandPaletteLabelProps) {
|
|
455
|
+
const { size } = useCommandPaletteContext('CommandPaletteLabel')
|
|
456
|
+
return (
|
|
457
|
+
<BaseAutocomplete.GroupLabel
|
|
458
|
+
data-slot="command-palette-label"
|
|
459
|
+
className={cn('text-foreground-subtle font-medium', LABEL_SIZE[size], className)}
|
|
460
|
+
{...props}
|
|
461
|
+
/>
|
|
462
|
+
)
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
type CommandPaletteCollectionProps = React.ComponentProps<typeof BaseAutocomplete.Collection>
|
|
466
|
+
|
|
467
|
+
function CommandPaletteCollection(props: CommandPaletteCollectionProps) {
|
|
468
|
+
return <BaseAutocomplete.Collection {...props} />
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
type CommandPaletteSeparatorProps = React.ComponentProps<typeof BaseAutocomplete.Separator>
|
|
472
|
+
|
|
473
|
+
function CommandPaletteSeparator({ className, ...props }: CommandPaletteSeparatorProps) {
|
|
474
|
+
return (
|
|
475
|
+
<BaseAutocomplete.Separator
|
|
476
|
+
data-slot="command-palette-separator"
|
|
477
|
+
className={cn('bg-border-muted -mx-3 my-2 h-px shrink-0', className)}
|
|
478
|
+
{...props}
|
|
479
|
+
/>
|
|
480
|
+
)
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
type CommandPaletteFooterProps = React.ComponentPropsWithoutRef<'div'>
|
|
484
|
+
|
|
485
|
+
function CommandPaletteFooter({ className, ...props }: CommandPaletteFooterProps) {
|
|
486
|
+
return (
|
|
487
|
+
<div
|
|
488
|
+
data-slot="command-palette-footer"
|
|
489
|
+
className={cn(
|
|
490
|
+
'border-border-muted text-foreground-subtle flex shrink-0 items-center justify-end gap-4 border-t px-4 py-2.5 text-xs',
|
|
491
|
+
className,
|
|
492
|
+
)}
|
|
493
|
+
{...props}
|
|
494
|
+
/>
|
|
495
|
+
)
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
function SearchIcon(props: React.SVGProps<SVGSVGElement>) {
|
|
499
|
+
return (
|
|
500
|
+
<svg
|
|
501
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
502
|
+
viewBox="0 0 24 24"
|
|
503
|
+
fill="none"
|
|
504
|
+
stroke="currentColor"
|
|
505
|
+
strokeLinecap="round"
|
|
506
|
+
strokeLinejoin="round"
|
|
507
|
+
aria-hidden="true"
|
|
508
|
+
{...props}
|
|
509
|
+
>
|
|
510
|
+
<path d="m21 21-4.35-4.35M10.5 18a7.5 7.5 0 1 0 0-15 7.5 7.5 0 0 0 0 15Z" />
|
|
511
|
+
</svg>
|
|
512
|
+
)
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
export {
|
|
516
|
+
CommandPalette,
|
|
517
|
+
CommandPaletteTrigger,
|
|
518
|
+
CommandPaletteContent,
|
|
519
|
+
CommandPaletteInput,
|
|
520
|
+
CommandPaletteList,
|
|
521
|
+
CommandPaletteItem,
|
|
522
|
+
CommandPaletteEmpty,
|
|
523
|
+
CommandPaletteStatus,
|
|
524
|
+
CommandPaletteGroup,
|
|
525
|
+
CommandPaletteLabel,
|
|
526
|
+
CommandPaletteCollection,
|
|
527
|
+
CommandPaletteSeparator,
|
|
528
|
+
CommandPaletteFooter,
|
|
529
|
+
}
|
|
530
|
+
export type {
|
|
531
|
+
CommandPaletteProps,
|
|
532
|
+
CommandPaletteTriggerProps,
|
|
533
|
+
CommandPaletteContentProps,
|
|
534
|
+
CommandPaletteInputProps,
|
|
535
|
+
CommandPaletteListProps,
|
|
536
|
+
CommandPaletteItemProps,
|
|
537
|
+
CommandPaletteEmptyProps,
|
|
538
|
+
CommandPaletteStatusProps,
|
|
539
|
+
CommandPaletteGroupProps,
|
|
540
|
+
CommandPaletteLabelProps,
|
|
541
|
+
CommandPaletteCollectionProps,
|
|
542
|
+
CommandPaletteSeparatorProps,
|
|
543
|
+
CommandPaletteFooterProps,
|
|
544
|
+
}
|
|
@@ -5,6 +5,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
|
5
5
|
import { axe } from 'vitest-axe'
|
|
6
6
|
import { CompareSlider, type CompareSliderProps } from './compare-slider'
|
|
7
7
|
import { DirectionProvider } from '../../providers/direction-provider'
|
|
8
|
+
import { cssValue } from '../../test/css'
|
|
8
9
|
|
|
9
10
|
const RECT = { x: 0, y: 0, top: 0, left: 0, right: 200, bottom: 100, width: 200, height: 100 }
|
|
10
11
|
|
|
@@ -62,8 +63,8 @@ describe('CompareSlider', () => {
|
|
|
62
63
|
it('clips each layer to its side of the divider, starting at defaultValue', () => {
|
|
63
64
|
renderSlider({ defaultValue: 30 })
|
|
64
65
|
expect(slider()).toHaveValue('30')
|
|
65
|
-
expect(layer('before').style.clipPath).toBe('inset(0 70% 0 0)')
|
|
66
|
-
expect(layer('after').style.clipPath).toBe('inset(0 0 0 30%)')
|
|
66
|
+
expect(layer('before').style.clipPath).toBe(cssValue('clip-path', 'inset(0 70% 0 0)'))
|
|
67
|
+
expect(layer('after').style.clipPath).toBe(cssValue('clip-path', 'inset(0 0 0 30%)'))
|
|
67
68
|
})
|
|
68
69
|
|
|
69
70
|
it('puts before on the right in a right-to-left layout', () => {
|
|
@@ -72,16 +73,16 @@ describe('CompareSlider', () => {
|
|
|
72
73
|
<CompareSlider data-testid="root" aria-label="Compare" defaultValue={30} before="Before" after="After" />
|
|
73
74
|
</DirectionProvider>,
|
|
74
75
|
)
|
|
75
|
-
expect(layer('before').style.clipPath).toBe('inset(0 0 0 70%)')
|
|
76
|
-
expect(layer('after').style.clipPath).toBe('inset(0 30% 0 0)')
|
|
76
|
+
expect(layer('before').style.clipPath).toBe(cssValue('clip-path', 'inset(0 0 0 70%)'))
|
|
77
|
+
expect(layer('after').style.clipPath).toBe(cssValue('clip-path', 'inset(0 30% 0 0)'))
|
|
77
78
|
})
|
|
78
79
|
|
|
79
80
|
it('stacks before above after when vertical', () => {
|
|
80
81
|
renderSlider({ orientation: 'vertical', defaultValue: 30 })
|
|
81
82
|
expect(root()).toHaveAttribute('data-orientation', 'vertical')
|
|
82
83
|
expect(slider()).toHaveAttribute('aria-orientation', 'vertical')
|
|
83
|
-
expect(layer('before').style.clipPath).toBe('inset(0 0 70% 0)')
|
|
84
|
-
expect(layer('after').style.clipPath).toBe('inset(30% 0 0 0)')
|
|
84
|
+
expect(layer('before').style.clipPath).toBe(cssValue('clip-path', 'inset(0 0 70% 0)'))
|
|
85
|
+
expect(layer('after').style.clipPath).toBe(cssValue('clip-path', 'inset(30% 0 0 0)'))
|
|
85
86
|
})
|
|
86
87
|
|
|
87
88
|
it('moves the divider to a mouse press, follows the drag and commits on release', async () => {
|
|
@@ -222,7 +223,7 @@ describe('CompareSlider', () => {
|
|
|
222
223
|
vi.stubGlobal('IntersectionObserver', MockIntersectionObserver)
|
|
223
224
|
renderSlider({ reveal: true, defaultValue: 40 })
|
|
224
225
|
expect(slider()).toHaveValue('100')
|
|
225
|
-
expect(layer('after').style.clipPath).toBe('inset(0 0 0 100%)')
|
|
226
|
+
expect(layer('after').style.clipPath).toBe(cssValue('clip-path', 'inset(0 0 0 100%)'))
|
|
226
227
|
|
|
227
228
|
act(() => {
|
|
228
229
|
MockIntersectionObserver.instances[0]!.callback(
|
|
@@ -476,7 +476,7 @@ function DateField({
|
|
|
476
476
|
: cn(
|
|
477
477
|
inputVariants({ variant, size, state: 'within' }),
|
|
478
478
|
'select-none',
|
|
479
|
-
'data-disabled:border-border-strong! data-disabled:bg-background-subtle! data-disabled:opacity-disabled data-disabled:pointer-events-none data-disabled:cursor-not-allowed data-disabled:border-dashed',
|
|
479
|
+
'data-disabled:border-border-strong! data-disabled:bg-background-subtle! data-disabled:opacity-disabled data-disabled:pointer-events-none data-disabled:cursor-not-allowed data-disabled:border-dashed data-disabled:backdrop-blur-md',
|
|
480
480
|
),
|
|
481
481
|
className,
|
|
482
482
|
)}
|
|
@@ -608,7 +608,7 @@ function UnifiedWrapper({
|
|
|
608
608
|
className={cn(
|
|
609
609
|
inputVariants({ variant, size, state: 'within' }),
|
|
610
610
|
'flex w-full',
|
|
611
|
-
'data-disabled:border-border-strong! data-disabled:bg-background-subtle! data-disabled:opacity-disabled data-disabled:pointer-events-none data-disabled:cursor-not-allowed data-disabled:border-dashed',
|
|
611
|
+
'data-disabled:border-border-strong! data-disabled:bg-background-subtle! data-disabled:opacity-disabled data-disabled:pointer-events-none data-disabled:cursor-not-allowed data-disabled:border-dashed data-disabled:backdrop-blur-md',
|
|
612
612
|
className,
|
|
613
613
|
)}
|
|
614
614
|
>
|
|
@@ -24,7 +24,7 @@ const inputVariants = cva(
|
|
|
24
24
|
'data-invalid:focus-visible:border-transparent data-invalid:focus-visible:ring-ring-error data-invalid:focus-visible:bg-background',
|
|
25
25
|
'data-invalid:data-popup-open:border-transparent data-invalid:data-popup-open:ring-ring-error data-invalid:data-popup-open:bg-background',
|
|
26
26
|
'data-invalid:data-pressed:border-transparent data-invalid:data-pressed:ring-ring-error data-invalid:data-pressed:bg-background',
|
|
27
|
-
'data-disabled:border-border-strong! data-disabled:bg-background-subtle! data-disabled:cursor-not-allowed data-disabled:border-dashed data-disabled:opacity-disabled',
|
|
27
|
+
'data-disabled:border-border-strong! data-disabled:bg-background-subtle! data-disabled:backdrop-blur-md data-disabled:cursor-not-allowed data-disabled:border-dashed data-disabled:opacity-disabled',
|
|
28
28
|
),
|
|
29
29
|
within: cn(
|
|
30
30
|
'flex items-center',
|
|
@@ -37,7 +37,7 @@ const inputVariants = cva(
|
|
|
37
37
|
'has-data-invalid:bg-error-subtle has-data-invalid:border-error has-data-invalid:has-focus:border-transparent has-data-invalid:has-focus:ring-ring-error has-data-invalid:has-focus:bg-background',
|
|
38
38
|
'has-data-invalid:has-data-popup-open:border-transparent has-data-invalid:has-data-popup-open:ring-ring-error has-data-invalid:has-data-popup-open:bg-background',
|
|
39
39
|
'has-data-invalid:has-data-pressed:border-transparent has-data-invalid:has-data-pressed:ring-ring-error has-data-invalid:has-data-pressed:bg-background',
|
|
40
|
-
'has-[input:disabled]:border-border-strong! has-[input:disabled]:bg-background-subtle! has-[input:disabled]:cursor-not-allowed has-[input:disabled]:border-dashed has-[input:disabled]:opacity-disabled',
|
|
40
|
+
'has-[input:disabled]:border-border-strong! has-[input:disabled]:bg-background-subtle! has-[input:disabled]:backdrop-blur-md has-[input:disabled]:cursor-not-allowed has-[input:disabled]:border-dashed has-[input:disabled]:opacity-disabled',
|
|
41
41
|
),
|
|
42
42
|
},
|
|
43
43
|
},
|
|
@@ -80,7 +80,7 @@ function Radio({ className, ...props }: RadioProps) {
|
|
|
80
80
|
'transition-[background-color,border-color,box-shadow] duration-200 motion-reduce:transition-none',
|
|
81
81
|
'hover:not-data-checked:not-data-disabled:not-data-invalid:border-border-emphasis',
|
|
82
82
|
'data-checked:bg-primary data-checked:outline-ring-primary data-checked:border-transparent',
|
|
83
|
-
'data-disabled:not-data-checked:bg-background-subtle data-disabled:data-checked:opacity-disabled data-disabled:cursor-not-allowed data-disabled:not-data-checked:border-dashed',
|
|
83
|
+
'data-disabled:not-data-checked:bg-background-subtle data-disabled:data-checked:opacity-disabled data-disabled:cursor-not-allowed data-disabled:not-data-checked:border-dashed data-disabled:not-data-checked:backdrop-blur-md',
|
|
84
84
|
'data-invalid:border-error data-invalid:not-data-checked:bg-error-subtle data-invalid:outline-ring-error',
|
|
85
85
|
className,
|
|
86
86
|
)}
|
|
@@ -3,6 +3,7 @@ import userEvent from '@testing-library/user-event'
|
|
|
3
3
|
import { describe, it, expect, vi } from 'vitest'
|
|
4
4
|
import { axe } from 'vitest-axe'
|
|
5
5
|
import { DirectionProvider } from '../../providers/direction-provider'
|
|
6
|
+
import { cssValue } from '../../test/css'
|
|
6
7
|
import { Rating } from './rating'
|
|
7
8
|
|
|
8
9
|
describe('Rating', () => {
|
|
@@ -114,7 +115,9 @@ describe('Rating', () => {
|
|
|
114
115
|
const clips = [...container.querySelectorAll<HTMLElement>('[data-slot=rating-item-fill]')].map(
|
|
115
116
|
(el) => el.style.clipPath,
|
|
116
117
|
)
|
|
117
|
-
expect(clips).toEqual(
|
|
118
|
+
expect(clips).toEqual(
|
|
119
|
+
['inset(0 0 0% 0)', 'inset(0 0 0% 0)', 'inset(0 0 100% 0)'].map((v) => cssValue('clip-path', v)),
|
|
120
|
+
)
|
|
118
121
|
|
|
119
122
|
vi.spyOn(root, 'getBoundingClientRect').mockReturnValue({ top: 0, height: 300 } as DOMRect)
|
|
120
123
|
fireEvent.pointerMove(root, { clientY: 250 })
|
|
@@ -181,7 +184,9 @@ describe('Rating', () => {
|
|
|
181
184
|
const clips = [...container.querySelectorAll<HTMLElement>('[data-slot=rating-item-fill]')].map(
|
|
182
185
|
(el) => el.style.clipPath,
|
|
183
186
|
)
|
|
184
|
-
expect(clips).toEqual(
|
|
187
|
+
expect(clips).toEqual(
|
|
188
|
+
['inset(0 0% 0 0)', 'inset(0 0% 0 0)', 'inset(0 100% 0 0)'].map((v) => cssValue('clip-path', v)),
|
|
189
|
+
)
|
|
185
190
|
})
|
|
186
191
|
})
|
|
187
192
|
|
|
@@ -215,7 +220,9 @@ describe('Rating', () => {
|
|
|
215
220
|
const clips = [...container.querySelectorAll<HTMLElement>('[data-slot=rating-item-fill]')].map(
|
|
216
221
|
(el) => el.style.clipPath,
|
|
217
222
|
)
|
|
218
|
-
expect(clips).toEqual(
|
|
223
|
+
expect(clips).toEqual(
|
|
224
|
+
['inset(0 0% 0 0)', 'inset(0 0% 0 0)', 'inset(0 60% 0 0)'].map((v) => cssValue('clip-path', v)),
|
|
225
|
+
)
|
|
219
226
|
})
|
|
220
227
|
|
|
221
228
|
it('sizes the icons from a number of pixels or any CSS length', () => {
|