@fabricator-ui/react-native 0.0.0-stage → 0.10.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/README.md +8 -2
- package/dist/LICENSE.md +25 -0
- package/dist/NOTICE.md +24 -0
- package/dist/lib/data-variants.ts +23 -0
- package/dist/lib/density-scale.ts +208 -0
- package/dist/lib/fabricator/css-object.ts +2 -0
- package/dist/lib/fabricator/density-scale.ts +210 -0
- package/dist/lib/fabricator/density-variables.ts +37 -0
- package/dist/lib/fabricator/motion-speeds.ts +566 -0
- package/dist/lib/fabricator/radius.ts +240 -0
- package/dist/lib/feedback.ts +124 -0
- package/dist/lib/field-frame.ts +53 -0
- package/dist/lib/field-model.ts +112 -0
- package/dist/lib/fluid-hover-model.ts +142 -0
- package/dist/lib/fluid-hover.tsx +788 -0
- package/dist/lib/icon-stroke.ts +38 -0
- package/dist/lib/motion-tokens.ts +97 -0
- package/dist/lib/motion.ts +292 -0
- package/dist/lib/overlay-model.ts +205 -0
- package/dist/lib/press-wash.tsx +73 -0
- package/dist/lib/render.tsx +53 -0
- package/dist/lib/select-model.ts +87 -0
- package/dist/lib/sheet-model.ts +101 -0
- package/dist/lib/sheet-surface.tsx +429 -0
- package/dist/lib/sound-recipes.ts +449 -0
- package/dist/lib/spring-model.ts +214 -0
- package/dist/lib/surface-color.tsx +27 -0
- package/dist/lib/text-children.ts +43 -0
- package/dist/styles.css +610 -0
- package/dist/ui/badge.tsx +108 -0
- package/dist/ui/button.tsx +285 -0
- package/dist/ui/card.tsx +365 -0
- package/dist/ui/checkbox.tsx +230 -0
- package/dist/ui/collapsible.tsx +194 -0
- package/dist/ui/density.tsx +79 -0
- package/dist/ui/dialog.tsx +232 -0
- package/dist/ui/dropdown-menu.tsx +687 -0
- package/dist/ui/fabricator-root.tsx +68 -0
- package/dist/ui/input.tsx +63 -0
- package/dist/ui/label.tsx +22 -0
- package/dist/ui/select.tsx +616 -0
- package/dist/ui/switch.tsx +177 -0
- package/dist/ui/tabs.tsx +272 -0
- package/dist/ui/text.tsx +125 -0
- package/dist/ui/textarea.tsx +65 -0
- package/package.json +54 -4
|
@@ -0,0 +1,616 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import {
|
|
3
|
+
CheckIcon,
|
|
4
|
+
ChevronDownIcon,
|
|
5
|
+
ChevronUpIcon,
|
|
6
|
+
IconProvider,
|
|
7
|
+
} from "@fabricator-ui/icons-react-native"
|
|
8
|
+
import { useControllableState } from "@rn-primitives/hooks"
|
|
9
|
+
import * as PopoverPrimitive from "@rn-primitives/popover"
|
|
10
|
+
import { cn } from "cn"
|
|
11
|
+
import {
|
|
12
|
+
Pressable,
|
|
13
|
+
ScrollView,
|
|
14
|
+
useWindowDimensions,
|
|
15
|
+
View,
|
|
16
|
+
type GestureResponderEvent,
|
|
17
|
+
} from "react-native"
|
|
18
|
+
import Animated from "react-native-reanimated"
|
|
19
|
+
|
|
20
|
+
import { getTouchSlop } from "../lib/density-scale"
|
|
21
|
+
import { useFeedback, useMountFeedback } from "../lib/feedback"
|
|
22
|
+
import {
|
|
23
|
+
FluidHoverArea,
|
|
24
|
+
FluidHoverHighlight,
|
|
25
|
+
FluidHoverProvider,
|
|
26
|
+
FluidHoverSelection,
|
|
27
|
+
useFluidHover,
|
|
28
|
+
useFluidRow,
|
|
29
|
+
} from "../lib/fluid-hover"
|
|
30
|
+
import {
|
|
31
|
+
useChevronIcon,
|
|
32
|
+
useIconStroke,
|
|
33
|
+
} from "../lib/icon-stroke"
|
|
34
|
+
import { useSurfaceAnimation } from "../lib/motion"
|
|
35
|
+
import {
|
|
36
|
+
COLLISION_INSETS,
|
|
37
|
+
getFittedSide,
|
|
38
|
+
getMenuMaxHeight,
|
|
39
|
+
getMenuMinWidth,
|
|
40
|
+
getTextContent,
|
|
41
|
+
getVerticalSide,
|
|
42
|
+
useTriggerOpen,
|
|
43
|
+
} from "../lib/overlay-model"
|
|
44
|
+
import {
|
|
45
|
+
getSelectLabel,
|
|
46
|
+
getSelectPresentation,
|
|
47
|
+
isSelectValueEmpty,
|
|
48
|
+
isValueSelected,
|
|
49
|
+
toggleSelectValue,
|
|
50
|
+
type SelectItems,
|
|
51
|
+
} from "../lib/select-model"
|
|
52
|
+
import {
|
|
53
|
+
SheetSurface,
|
|
54
|
+
SheetSurfaceScrollView,
|
|
55
|
+
} from "../lib/sheet-surface"
|
|
56
|
+
import {
|
|
57
|
+
DensityScope,
|
|
58
|
+
useControlSize,
|
|
59
|
+
useDensity,
|
|
60
|
+
} from "./density"
|
|
61
|
+
import { renderTextChildren, Text, TextStyle } from "./text"
|
|
62
|
+
|
|
63
|
+
type SelectContextValue = {
|
|
64
|
+
value: unknown
|
|
65
|
+
items: SelectItems | undefined
|
|
66
|
+
labels: ReadonlyMap<unknown, string>
|
|
67
|
+
multiple: boolean
|
|
68
|
+
disabled: boolean
|
|
69
|
+
isOpen: boolean
|
|
70
|
+
setIsOpen: (open: boolean) => void
|
|
71
|
+
triggerRef: React.RefObject<PopoverPrimitive.TriggerRef | null>
|
|
72
|
+
choose: (value: unknown) => void
|
|
73
|
+
registerLabel: (value: unknown, label: string) => void
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const SelectContext = React.createContext<SelectContextValue | null>(null)
|
|
77
|
+
|
|
78
|
+
// Where the selected row names itself: a value can be anything, a row's key can't.
|
|
79
|
+
const SelectSelectedRowContext = React.createContext<
|
|
80
|
+
((key: string | undefined) => void) | null
|
|
81
|
+
>(null)
|
|
82
|
+
|
|
83
|
+
function useSelect() {
|
|
84
|
+
const context = React.use(SelectContext)
|
|
85
|
+
if (!context) throw new Error("useSelect must be used within a Select.")
|
|
86
|
+
return context
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function Select<Value = string, Multiple extends boolean | undefined = false>({
|
|
90
|
+
items,
|
|
91
|
+
value,
|
|
92
|
+
defaultValue,
|
|
93
|
+
onValueChange,
|
|
94
|
+
multiple,
|
|
95
|
+
open,
|
|
96
|
+
defaultOpen,
|
|
97
|
+
onOpenChange,
|
|
98
|
+
disabled = false,
|
|
99
|
+
...props
|
|
100
|
+
}: Omit<PopoverPrimitive.RootProps, "onOpenChange"> & {
|
|
101
|
+
items?: SelectItems
|
|
102
|
+
value?: (Multiple extends true ? readonly Value[] : Value) | null
|
|
103
|
+
defaultValue?: (Multiple extends true ? readonly Value[] : Value) | null
|
|
104
|
+
onValueChange?: (
|
|
105
|
+
value: Multiple extends true ? Value[] : Value | null
|
|
106
|
+
) => void
|
|
107
|
+
multiple?: Multiple
|
|
108
|
+
open?: boolean
|
|
109
|
+
defaultOpen?: boolean
|
|
110
|
+
onOpenChange?: (open: boolean) => void
|
|
111
|
+
disabled?: boolean
|
|
112
|
+
}) {
|
|
113
|
+
const trigger = useTriggerOpen<PopoverPrimitive.TriggerRef>({
|
|
114
|
+
open,
|
|
115
|
+
defaultOpen,
|
|
116
|
+
onOpenChange,
|
|
117
|
+
})
|
|
118
|
+
const [current, setCurrent] = useControllableState<unknown>({
|
|
119
|
+
prop: value,
|
|
120
|
+
defaultProp: defaultValue ?? null,
|
|
121
|
+
// The one place the values, untyped inside, meet the caller's own type.
|
|
122
|
+
onChange: (next) => onValueChange?.(next as never),
|
|
123
|
+
})
|
|
124
|
+
const [labels, setLabels] = React.useState<ReadonlyMap<unknown, string>>(
|
|
125
|
+
() => new Map()
|
|
126
|
+
)
|
|
127
|
+
const registerLabel = React.useCallback((entry: unknown, label: string) => {
|
|
128
|
+
setLabels((previous) =>
|
|
129
|
+
previous.get(entry) === label
|
|
130
|
+
? previous
|
|
131
|
+
: new Map(previous).set(entry, label)
|
|
132
|
+
)
|
|
133
|
+
}, [])
|
|
134
|
+
const isMultiple = Boolean(multiple)
|
|
135
|
+
const { isOpen, setIsOpen, triggerRef } = trigger
|
|
136
|
+
const context: SelectContextValue = {
|
|
137
|
+
value: current,
|
|
138
|
+
items,
|
|
139
|
+
labels,
|
|
140
|
+
multiple: isMultiple,
|
|
141
|
+
disabled,
|
|
142
|
+
isOpen,
|
|
143
|
+
setIsOpen,
|
|
144
|
+
triggerRef,
|
|
145
|
+
registerLabel,
|
|
146
|
+
choose: (next) => {
|
|
147
|
+
setCurrent(toggleSelectValue(current, next, isMultiple))
|
|
148
|
+
if (!isMultiple) setIsOpen(false)
|
|
149
|
+
},
|
|
150
|
+
}
|
|
151
|
+
return (
|
|
152
|
+
<SelectContext value={context}>
|
|
153
|
+
<PopoverPrimitive.Root
|
|
154
|
+
data-slot="select"
|
|
155
|
+
onOpenChange={trigger.onOpenChange}
|
|
156
|
+
{...props}
|
|
157
|
+
/>
|
|
158
|
+
</SelectContext>
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function SelectGroup({
|
|
163
|
+
className,
|
|
164
|
+
children,
|
|
165
|
+
...props
|
|
166
|
+
}: React.ComponentProps<typeof View>) {
|
|
167
|
+
return (
|
|
168
|
+
<View
|
|
169
|
+
data-slot="select-group"
|
|
170
|
+
role="group"
|
|
171
|
+
className={cn("w-full", className)}
|
|
172
|
+
{...props}
|
|
173
|
+
>
|
|
174
|
+
{renderTextChildren(children)}
|
|
175
|
+
</View>
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function SelectValue({
|
|
180
|
+
className,
|
|
181
|
+
children,
|
|
182
|
+
placeholder,
|
|
183
|
+
...props
|
|
184
|
+
}: Omit<React.ComponentProps<typeof Text>, "children"> & {
|
|
185
|
+
children?: React.ReactNode | ((value: unknown) => React.ReactNode)
|
|
186
|
+
placeholder?: React.ReactNode
|
|
187
|
+
}) {
|
|
188
|
+
const { items, labels, value } = useSelect()
|
|
189
|
+
const isEmpty = isSelectValueEmpty(value)
|
|
190
|
+
const labelOf = (entry: unknown) =>
|
|
191
|
+
getSelectLabel(items, entry) ?? labels.get(entry) ?? String(entry)
|
|
192
|
+
const label = Array.isArray(value)
|
|
193
|
+
? value.map(labelOf).join(", ")
|
|
194
|
+
: labelOf(value)
|
|
195
|
+
const content =
|
|
196
|
+
typeof children === "function"
|
|
197
|
+
? children(value)
|
|
198
|
+
: (children ??
|
|
199
|
+
(isEmpty ? (getSelectLabel(items, null) ?? placeholder) : label))
|
|
200
|
+
return (
|
|
201
|
+
<Text
|
|
202
|
+
data-slot="select-value"
|
|
203
|
+
data-placeholder={isEmpty}
|
|
204
|
+
numberOfLines={1}
|
|
205
|
+
className={cn("text-start data-[placeholder=true]:text-muted-foreground shrink grow", className)}
|
|
206
|
+
{...props}
|
|
207
|
+
>
|
|
208
|
+
{content}
|
|
209
|
+
</Text>
|
|
210
|
+
)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function SelectTrigger({
|
|
214
|
+
className,
|
|
215
|
+
size = "default",
|
|
216
|
+
disabled,
|
|
217
|
+
"aria-invalid": isInvalid,
|
|
218
|
+
children,
|
|
219
|
+
...props
|
|
220
|
+
}: Omit<PopoverPrimitive.TriggerProps, "children"> & {
|
|
221
|
+
size?: "sm" | "default"
|
|
222
|
+
"aria-invalid"?: boolean
|
|
223
|
+
children?: React.ReactNode
|
|
224
|
+
}) {
|
|
225
|
+
const chevron = useChevronIcon()
|
|
226
|
+
const select = useSelect()
|
|
227
|
+
const { density, height } = useControlSize(size)
|
|
228
|
+
return (
|
|
229
|
+
<DensityScope density={density}>
|
|
230
|
+
<TextStyle className={"fab:text-foreground fab:text-(length:--density-text-13)"}>
|
|
231
|
+
<PopoverPrimitive.Trigger
|
|
232
|
+
ref={select.triggerRef}
|
|
233
|
+
data-slot="select-trigger"
|
|
234
|
+
data-size={size}
|
|
235
|
+
data-invalid={Boolean(isInvalid)}
|
|
236
|
+
role="combobox"
|
|
237
|
+
aria-invalid={isInvalid}
|
|
238
|
+
disabled={disabled ?? select.disabled}
|
|
239
|
+
hitSlop={getTouchSlop(height)}
|
|
240
|
+
className={cn(
|
|
241
|
+
"border-border active:bg-muted/50 data-[invalid=true]:border-destructive/50 data-[invalid=true]:active:bg-destructive/5 h-(--density-36) gap-(--density-8) rounded-(--radius-control) border bg-transparent py-0 pr-(--density-8) pl-(--density-10) corner-curve flex-row items-center justify-between disabled:opacity-50",
|
|
242
|
+
className
|
|
243
|
+
)}
|
|
244
|
+
{...props}
|
|
245
|
+
>
|
|
246
|
+
{renderTextChildren(children)}
|
|
247
|
+
<View className={"fab:size-(--density-icon-16) fab:shrink-0"}>
|
|
248
|
+
<TextStyle className={"fab:text-muted-foreground"}>
|
|
249
|
+
<ChevronDownIcon {...chevron} />
|
|
250
|
+
</TextStyle>
|
|
251
|
+
</View>
|
|
252
|
+
</PopoverPrimitive.Trigger>
|
|
253
|
+
</TextStyle>
|
|
254
|
+
</DensityScope>
|
|
255
|
+
)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// The primitive's portal renders this only while the popover is open.
|
|
259
|
+
function SelectFeedback() {
|
|
260
|
+
useMountFeedback("popup")
|
|
261
|
+
return null
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* The list: FluidHoverScrollList's drag and its scroll view, with the selection
|
|
266
|
+
* sliding under the rows as on the website, which that list doesn't draw.
|
|
267
|
+
*/
|
|
268
|
+
function SelectList({
|
|
269
|
+
ScrollComponent = ScrollView,
|
|
270
|
+
onLayout,
|
|
271
|
+
onContentSizeChange,
|
|
272
|
+
children,
|
|
273
|
+
...props
|
|
274
|
+
}: React.ComponentProps<typeof ScrollView> & {
|
|
275
|
+
ScrollComponent?: React.ComponentType<React.ComponentProps<typeof ScrollView>>
|
|
276
|
+
}) {
|
|
277
|
+
const [selected, setSelected] = React.useState<string>()
|
|
278
|
+
const [viewport, setViewport] = React.useState(0)
|
|
279
|
+
const [content, setContent] = React.useState(0)
|
|
280
|
+
const fluid = useFluidHover({
|
|
281
|
+
selected,
|
|
282
|
+
track: content > viewport + 1 ? "hold" : "drag",
|
|
283
|
+
})
|
|
284
|
+
return (
|
|
285
|
+
<ScrollComponent
|
|
286
|
+
alwaysBounceVertical={false}
|
|
287
|
+
keyboardShouldPersistTaps="handled"
|
|
288
|
+
onLayout={(event) => {
|
|
289
|
+
setViewport(event.nativeEvent.layout.height)
|
|
290
|
+
onLayout?.(event)
|
|
291
|
+
}}
|
|
292
|
+
onContentSizeChange={(width, height) => {
|
|
293
|
+
setContent(height)
|
|
294
|
+
onContentSizeChange?.(width, height)
|
|
295
|
+
}}
|
|
296
|
+
{...props}
|
|
297
|
+
>
|
|
298
|
+
<FluidHoverProvider fluid={fluid}>
|
|
299
|
+
<FluidHoverArea fluid={fluid}>
|
|
300
|
+
<View ref={fluid.attach} className={"fab:relative"}>
|
|
301
|
+
<FluidHoverSelection selection={fluid.selection} />
|
|
302
|
+
<FluidHoverHighlight hover={fluid.hover} />
|
|
303
|
+
<SelectSelectedRowContext value={setSelected}>
|
|
304
|
+
{children}
|
|
305
|
+
</SelectSelectedRowContext>
|
|
306
|
+
</View>
|
|
307
|
+
</FluidHoverArea>
|
|
308
|
+
</FluidHoverProvider>
|
|
309
|
+
</ScrollComponent>
|
|
310
|
+
)
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function SelectContent({
|
|
314
|
+
className,
|
|
315
|
+
children,
|
|
316
|
+
side = "bottom",
|
|
317
|
+
sideOffset = 4,
|
|
318
|
+
align = "center",
|
|
319
|
+
alignOffset = 0,
|
|
320
|
+
alignItemWithTrigger = true,
|
|
321
|
+
insets = COLLISION_INSETS,
|
|
322
|
+
onLayout,
|
|
323
|
+
...props
|
|
324
|
+
}: Omit<PopoverPrimitive.ContentProps, "side"> & {
|
|
325
|
+
side?: "top" | "right" | "bottom" | "left"
|
|
326
|
+
/** On the website this lines the selected item up with the trigger. */
|
|
327
|
+
alignItemWithTrigger?: boolean
|
|
328
|
+
}) {
|
|
329
|
+
const select = useSelect()
|
|
330
|
+
const density = useDensity()
|
|
331
|
+
const { width, height } = useWindowDimensions()
|
|
332
|
+
const { triggerPosition } = PopoverPrimitive.useRootContext()
|
|
333
|
+
const [contentHeight, setContentHeight] = React.useState<number | null>(null)
|
|
334
|
+
const verticalSide = getFittedSide({
|
|
335
|
+
side: getVerticalSide(side),
|
|
336
|
+
triggerY: triggerPosition?.pageY,
|
|
337
|
+
triggerHeight: triggerPosition?.height,
|
|
338
|
+
contentHeight,
|
|
339
|
+
offset: sideOffset,
|
|
340
|
+
windowHeight: height,
|
|
341
|
+
insets,
|
|
342
|
+
})
|
|
343
|
+
const { entering, exiting, origin } = useSurfaceAnimation("popup", {
|
|
344
|
+
side: verticalSide,
|
|
345
|
+
align,
|
|
346
|
+
})
|
|
347
|
+
const presentation = getSelectPresentation(width)
|
|
348
|
+
|
|
349
|
+
if (presentation === "sheet") {
|
|
350
|
+
return (
|
|
351
|
+
<SheetSurface
|
|
352
|
+
data-slot="select-content"
|
|
353
|
+
data-presentation={presentation}
|
|
354
|
+
open={select.isOpen}
|
|
355
|
+
onOpenChange={select.setIsOpen}
|
|
356
|
+
side="bottom"
|
|
357
|
+
className={cn("bg-surface-3 shadow-surface-3 rounded-(--radius-surface) p-1 data-[presentation=sheet]:max-h-[80%] data-[presentation=sheet]:rounded-b-none data-[presentation=sheet]:px-(--density-8) corner-curve min-w-36", className)}
|
|
358
|
+
>
|
|
359
|
+
<SelectContext value={select}>
|
|
360
|
+
<TextStyle className={"fab:text-popover-foreground fab:text-(length:--density-text-13)"}>
|
|
361
|
+
<View className={"fab:py-(--density-8) fab:items-center"}>
|
|
362
|
+
<View className={"fab:bg-active fab:h-1 fab:w-12 fab:rounded-full"} />
|
|
363
|
+
</View>
|
|
364
|
+
<SelectList ScrollComponent={SheetSurfaceScrollView} role="list">
|
|
365
|
+
{renderTextChildren(children)}
|
|
366
|
+
</SelectList>
|
|
367
|
+
</TextStyle>
|
|
368
|
+
</SelectContext>
|
|
369
|
+
</SheetSurface>
|
|
370
|
+
)
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
return (
|
|
374
|
+
<PopoverPrimitive.Portal>
|
|
375
|
+
<DensityScope density={density}>
|
|
376
|
+
<PopoverPrimitive.Overlay aria-modal className={"fab:absolute fab:inset-0"}>
|
|
377
|
+
<PopoverPrimitive.Content
|
|
378
|
+
side={verticalSide}
|
|
379
|
+
sideOffset={sideOffset}
|
|
380
|
+
align={align}
|
|
381
|
+
alignOffset={alignOffset}
|
|
382
|
+
insets={insets}
|
|
383
|
+
{...props}
|
|
384
|
+
onLayout={(event) => {
|
|
385
|
+
setContentHeight(event.nativeEvent.layout.height)
|
|
386
|
+
onLayout?.(event)
|
|
387
|
+
}}
|
|
388
|
+
>
|
|
389
|
+
<Animated.View
|
|
390
|
+
data-slot="select-content"
|
|
391
|
+
data-presentation={presentation}
|
|
392
|
+
data-align-trigger={alignItemWithTrigger}
|
|
393
|
+
entering={entering}
|
|
394
|
+
exiting={exiting}
|
|
395
|
+
style={[
|
|
396
|
+
origin,
|
|
397
|
+
{ minWidth: getMenuMinWidth(triggerPosition?.width, width) },
|
|
398
|
+
]}
|
|
399
|
+
className={cn(
|
|
400
|
+
"bg-surface-3 shadow-surface-3 rounded-(--radius-surface) p-1 data-[presentation=sheet]:max-h-[80%] data-[presentation=sheet]:rounded-b-none data-[presentation=sheet]:px-(--density-8) corner-curve min-w-36",
|
|
401
|
+
className
|
|
402
|
+
)}
|
|
403
|
+
>
|
|
404
|
+
<SelectFeedback />
|
|
405
|
+
<SelectContext value={select}>
|
|
406
|
+
<TextStyle className={"fab:text-popover-foreground fab:text-(length:--density-text-13)"}>
|
|
407
|
+
<SelectList
|
|
408
|
+
role="list"
|
|
409
|
+
style={{ maxHeight: getMenuMaxHeight(height, width) }}
|
|
410
|
+
>
|
|
411
|
+
{renderTextChildren(children)}
|
|
412
|
+
</SelectList>
|
|
413
|
+
</TextStyle>
|
|
414
|
+
</SelectContext>
|
|
415
|
+
</Animated.View>
|
|
416
|
+
</PopoverPrimitive.Content>
|
|
417
|
+
</PopoverPrimitive.Overlay>
|
|
418
|
+
</DensityScope>
|
|
419
|
+
</PopoverPrimitive.Portal>
|
|
420
|
+
)
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function SelectLabel({
|
|
424
|
+
className,
|
|
425
|
+
...props
|
|
426
|
+
}: React.ComponentProps<typeof Text>) {
|
|
427
|
+
return (
|
|
428
|
+
<Text
|
|
429
|
+
data-slot="select-label"
|
|
430
|
+
className={cn("text-muted-foreground px-(--density-8) py-(--density-6) text-(length:--density-text-12)", className)}
|
|
431
|
+
{...props}
|
|
432
|
+
/>
|
|
433
|
+
)
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// A selected row reads foreground and semibold; a lit one foreground, with a heavier icon.
|
|
437
|
+
function SelectItemText({
|
|
438
|
+
isSelected,
|
|
439
|
+
isLit,
|
|
440
|
+
children,
|
|
441
|
+
}: {
|
|
442
|
+
isSelected: boolean
|
|
443
|
+
isLit: boolean
|
|
444
|
+
children?: React.ReactNode
|
|
445
|
+
}) {
|
|
446
|
+
return (
|
|
447
|
+
<TextStyle
|
|
448
|
+
eases
|
|
449
|
+
className={
|
|
450
|
+
isSelected
|
|
451
|
+
? cn("text-(length:--density-text-13) text-foreground font-semibold")
|
|
452
|
+
: isLit
|
|
453
|
+
? cn("text-(length:--density-text-13) text-foreground")
|
|
454
|
+
: cn("text-muted-foreground text-(length:--density-text-13)")
|
|
455
|
+
}
|
|
456
|
+
>
|
|
457
|
+
<IconProvider strokeWidth={useIconStroke(isLit)}>{children}</IconProvider>
|
|
458
|
+
</TextStyle>
|
|
459
|
+
)
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
function SelectItem({
|
|
463
|
+
className,
|
|
464
|
+
children,
|
|
465
|
+
value = null,
|
|
466
|
+
label,
|
|
467
|
+
disabled,
|
|
468
|
+
onPress,
|
|
469
|
+
...props
|
|
470
|
+
}: Omit<React.ComponentProps<typeof Pressable>, "children" | "onPress"> & {
|
|
471
|
+
value?: unknown
|
|
472
|
+
/** What the trigger shows when the children aren't plain text. */
|
|
473
|
+
label?: string
|
|
474
|
+
/** After a drag, letting go over the row runs this with no press to pass on. */
|
|
475
|
+
onPress?: (event?: GestureResponderEvent) => void
|
|
476
|
+
children?: React.ReactNode
|
|
477
|
+
}) {
|
|
478
|
+
const { choose, multiple, registerLabel, value: current } = useSelect()
|
|
479
|
+
const isSelected = isValueSelected(current, value, multiple)
|
|
480
|
+
const text = label ?? getTextContent(children)
|
|
481
|
+
const feedback = useFeedback()
|
|
482
|
+
const setSelectedRow = React.use(SelectSelectedRowContext)
|
|
483
|
+
const { key, isLit, rowProps } = useFluidRow({
|
|
484
|
+
...props,
|
|
485
|
+
disabled,
|
|
486
|
+
onActivate: () => {
|
|
487
|
+
feedback("pick")
|
|
488
|
+
choose(value)
|
|
489
|
+
onPress?.()
|
|
490
|
+
},
|
|
491
|
+
})
|
|
492
|
+
React.useEffect(() => {
|
|
493
|
+
registerLabel(value, text)
|
|
494
|
+
}, [registerLabel, text, value])
|
|
495
|
+
// One selection slides between rows. With several chosen, each row fills itself.
|
|
496
|
+
const isSlidingSelection = isSelected && !multiple
|
|
497
|
+
React.useLayoutEffect(() => {
|
|
498
|
+
if (!isSlidingSelection) return
|
|
499
|
+
setSelectedRow?.(key)
|
|
500
|
+
return () => setSelectedRow?.(undefined)
|
|
501
|
+
}, [isSlidingSelection, key, setSelectedRow])
|
|
502
|
+
return (
|
|
503
|
+
<SelectItemText isSelected={isSelected} isLit={isLit}>
|
|
504
|
+
<Pressable
|
|
505
|
+
data-slot="select-item"
|
|
506
|
+
data-selected={isSelected}
|
|
507
|
+
data-multiple={multiple}
|
|
508
|
+
role="option"
|
|
509
|
+
aria-selected={isSelected}
|
|
510
|
+
aria-disabled={disabled ?? undefined}
|
|
511
|
+
disabled={disabled}
|
|
512
|
+
className={cn(
|
|
513
|
+
"h-(--density-36) gap-(--density-8) rounded-(--radius-nested) py-0 pr-[calc(var(--density-8)*2+var(--density-icon-16))] pl-(--density-8) data-[multiple=true]:data-[selected=true]:bg-active corner-curve relative w-full flex-row items-center disabled:opacity-50",
|
|
514
|
+
className
|
|
515
|
+
)}
|
|
516
|
+
onPress={(event: GestureResponderEvent) => {
|
|
517
|
+
feedback("pick")
|
|
518
|
+
choose(value)
|
|
519
|
+
onPress?.(event)
|
|
520
|
+
}}
|
|
521
|
+
{...props}
|
|
522
|
+
{...rowProps}
|
|
523
|
+
>
|
|
524
|
+
<View className={"fab:gap-(--density-8) fab:shrink fab:flex-row fab:items-center"}>
|
|
525
|
+
{renderTextChildren(children)}
|
|
526
|
+
</View>
|
|
527
|
+
{isSelected ? (
|
|
528
|
+
<View
|
|
529
|
+
pointerEvents="none"
|
|
530
|
+
className={"fab:right-(--density-8) fab:size-(--density-icon-16) fab:absolute fab:items-center fab:justify-center"}
|
|
531
|
+
>
|
|
532
|
+
<TextStyle className={"fab:text-foreground"}>
|
|
533
|
+
<CheckIcon />
|
|
534
|
+
</TextStyle>
|
|
535
|
+
</View>
|
|
536
|
+
) : null}
|
|
537
|
+
</Pressable>
|
|
538
|
+
</SelectItemText>
|
|
539
|
+
)
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
function SelectSeparator({
|
|
543
|
+
className,
|
|
544
|
+
...props
|
|
545
|
+
}: React.ComponentProps<typeof View>) {
|
|
546
|
+
return (
|
|
547
|
+
<View
|
|
548
|
+
data-slot="select-separator"
|
|
549
|
+
role="separator"
|
|
550
|
+
pointerEvents="none"
|
|
551
|
+
className={cn("bg-border/60 -mx-1 my-1 h-px", className)}
|
|
552
|
+
{...props}
|
|
553
|
+
/>
|
|
554
|
+
)
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* On the website these scroll a long list under a pointer. A touch list scrolls
|
|
559
|
+
* itself, so SelectContent doesn't render them; they show an arrow if placed.
|
|
560
|
+
*/
|
|
561
|
+
function SelectScrollUpButton({
|
|
562
|
+
className,
|
|
563
|
+
children,
|
|
564
|
+
...props
|
|
565
|
+
}: React.ComponentProps<typeof View>) {
|
|
566
|
+
return (
|
|
567
|
+
<TextStyle className={"fab:text-muted-foreground"}>
|
|
568
|
+
<View
|
|
569
|
+
data-slot="select-scroll-up-button"
|
|
570
|
+
aria-hidden
|
|
571
|
+
className={cn(
|
|
572
|
+
"py-1 w-full items-center justify-center",
|
|
573
|
+
className
|
|
574
|
+
)}
|
|
575
|
+
{...props}
|
|
576
|
+
>
|
|
577
|
+
{children ?? <ChevronUpIcon />}
|
|
578
|
+
</View>
|
|
579
|
+
</TextStyle>
|
|
580
|
+
)
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
function SelectScrollDownButton({
|
|
584
|
+
className,
|
|
585
|
+
children,
|
|
586
|
+
...props
|
|
587
|
+
}: React.ComponentProps<typeof View>) {
|
|
588
|
+
return (
|
|
589
|
+
<TextStyle className={"fab:text-muted-foreground"}>
|
|
590
|
+
<View
|
|
591
|
+
data-slot="select-scroll-down-button"
|
|
592
|
+
aria-hidden
|
|
593
|
+
className={cn(
|
|
594
|
+
"py-1 w-full items-center justify-center",
|
|
595
|
+
className
|
|
596
|
+
)}
|
|
597
|
+
{...props}
|
|
598
|
+
>
|
|
599
|
+
{children ?? <ChevronDownIcon />}
|
|
600
|
+
</View>
|
|
601
|
+
</TextStyle>
|
|
602
|
+
)
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
export {
|
|
606
|
+
Select,
|
|
607
|
+
SelectContent,
|
|
608
|
+
SelectGroup,
|
|
609
|
+
SelectItem,
|
|
610
|
+
SelectLabel,
|
|
611
|
+
SelectScrollDownButton,
|
|
612
|
+
SelectScrollUpButton,
|
|
613
|
+
SelectSeparator,
|
|
614
|
+
SelectTrigger,
|
|
615
|
+
SelectValue,
|
|
616
|
+
}
|