@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,177 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { useControllableState } from "@rn-primitives/hooks"
|
|
3
|
+
import { cn } from "cn"
|
|
4
|
+
import { Pressable } from "react-native"
|
|
5
|
+
import Animated, {
|
|
6
|
+
ReduceMotion,
|
|
7
|
+
useAnimatedStyle,
|
|
8
|
+
useSharedValue,
|
|
9
|
+
withSpring,
|
|
10
|
+
withTiming,
|
|
11
|
+
} from "react-native-reanimated"
|
|
12
|
+
import { useCSSVariable } from "uniwind"
|
|
13
|
+
|
|
14
|
+
import { useFeedback } from "../lib/feedback"
|
|
15
|
+
import { useFieldControl } from "../lib/field-model"
|
|
16
|
+
import { useMotion, useMotionSprings } from "../lib/motion"
|
|
17
|
+
import { parseNumber } from "../lib/motion-tokens"
|
|
18
|
+
import { DensityScope, useControlSize } from "./density"
|
|
19
|
+
|
|
20
|
+
// A press stretches the knob 4pt toward the centre and squashes it by the same.
|
|
21
|
+
const PRESS_STRETCH = 4
|
|
22
|
+
const TRACK_INSET = 2
|
|
23
|
+
|
|
24
|
+
function SwitchControl({
|
|
25
|
+
className,
|
|
26
|
+
size,
|
|
27
|
+
checked,
|
|
28
|
+
defaultChecked = false,
|
|
29
|
+
onCheckedChange,
|
|
30
|
+
disabled,
|
|
31
|
+
readOnly = false,
|
|
32
|
+
"aria-invalid": isInvalid,
|
|
33
|
+
onPress,
|
|
34
|
+
onPressIn,
|
|
35
|
+
onPressOut,
|
|
36
|
+
...props
|
|
37
|
+
}: Omit<React.ComponentProps<typeof Pressable>, "children"> & {
|
|
38
|
+
size: "sm" | "default"
|
|
39
|
+
checked?: boolean
|
|
40
|
+
defaultChecked?: boolean
|
|
41
|
+
onCheckedChange?: (checked: boolean) => void
|
|
42
|
+
readOnly?: boolean
|
|
43
|
+
"aria-invalid"?: boolean
|
|
44
|
+
}) {
|
|
45
|
+
const [isChecked = false, setIsChecked] = useControllableState({
|
|
46
|
+
prop: checked,
|
|
47
|
+
defaultProp: defaultChecked,
|
|
48
|
+
onChange: onCheckedChange,
|
|
49
|
+
})
|
|
50
|
+
const feedback = useFeedback()
|
|
51
|
+
const toggle = () => {
|
|
52
|
+
feedback(isChecked ? "toggle-off" : "toggle-on")
|
|
53
|
+
setIsChecked(!isChecked)
|
|
54
|
+
}
|
|
55
|
+
const field = useFieldControl({
|
|
56
|
+
activate: () => {
|
|
57
|
+
if (!isDisabled && !readOnly) toggle()
|
|
58
|
+
},
|
|
59
|
+
isChecked,
|
|
60
|
+
})
|
|
61
|
+
const isDisabled = disabled ?? field.isDisabled
|
|
62
|
+
const isFieldInvalid = isInvalid ?? field.isInvalid
|
|
63
|
+
const state = isChecked ? "checked" : "unchecked"
|
|
64
|
+
|
|
65
|
+
// Height and travel read the density this switch is in, for the knob's numbers.
|
|
66
|
+
const [height, travelToken] = useCSSVariable(["--density-20", "--density-14"])
|
|
67
|
+
const knob = parseNumber(height, 20) - TRACK_INSET * 2
|
|
68
|
+
const travel = parseNumber(travelToken, 14)
|
|
69
|
+
|
|
70
|
+
const slideMotion = useMotion("move")
|
|
71
|
+
const colorMotion = useMotion("feedback")
|
|
72
|
+
const slide = useSharedValue(isChecked ? 1 : 0)
|
|
73
|
+
const fill = useSharedValue(isChecked ? 1 : 0)
|
|
74
|
+
const press = useSharedValue(0)
|
|
75
|
+
// The thumb lands on the settle spring and the knob rounds back up on the
|
|
76
|
+
// pop spring, as on the website; motion off jumps.
|
|
77
|
+
const { springs } = useMotionSprings()
|
|
78
|
+
React.useEffect(() => {
|
|
79
|
+
const target = isChecked ? 1 : 0
|
|
80
|
+
slide.value = springs
|
|
81
|
+
? withSpring(target, { ...springs.settle, mass: 1 })
|
|
82
|
+
: target
|
|
83
|
+
// A fade: Reduce Motion keeps it, and Reanimated would jump it to the end.
|
|
84
|
+
fill.value = withTiming(isChecked ? 1 : 0, {
|
|
85
|
+
duration: colorMotion.enterMs,
|
|
86
|
+
easing: colorMotion.feedbackEasing,
|
|
87
|
+
reduceMotion: ReduceMotion.Never,
|
|
88
|
+
})
|
|
89
|
+
}, [colorMotion, fill, isChecked, slide, springs])
|
|
90
|
+
|
|
91
|
+
const fillStyle = useAnimatedStyle(() => ({ opacity: fill.value }))
|
|
92
|
+
// The knob's colour turns as it travels, on the move timing.
|
|
93
|
+
const knobStyle = useAnimatedStyle(() => ({ opacity: slide.value }))
|
|
94
|
+
const canStretch = !slideMotion.isReduced && !slideMotion.isOff
|
|
95
|
+
const thumbStyle = useAnimatedStyle(() => ({
|
|
96
|
+
width: knob + press.value * PRESS_STRETCH,
|
|
97
|
+
height: knob - press.value * PRESS_STRETCH,
|
|
98
|
+
transform: [
|
|
99
|
+
{
|
|
100
|
+
translateX: slide.value * (travel - press.value * PRESS_STRETCH),
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
}))
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<Pressable
|
|
107
|
+
data-slot="switch"
|
|
108
|
+
data-size={size}
|
|
109
|
+
data-state={state}
|
|
110
|
+
data-invalid={isFieldInvalid}
|
|
111
|
+
role="switch"
|
|
112
|
+
aria-checked={isChecked}
|
|
113
|
+
aria-disabled={isDisabled}
|
|
114
|
+
aria-invalid={isFieldInvalid}
|
|
115
|
+
disabled={isDisabled}
|
|
116
|
+
hitSlop={14}
|
|
117
|
+
className={cn(
|
|
118
|
+
"bg-accent data-[invalid=true]:outline-destructive/50 h-(--density-20) w-[calc(var(--density-20)+var(--density-14))] shrink-0 rounded-full px-0.5 data-[invalid=true]:outline-1 data-[invalid=true]:outline-offset-2 relative flex-row items-center disabled:opacity-50",
|
|
119
|
+
className
|
|
120
|
+
)}
|
|
121
|
+
onPress={(event) => {
|
|
122
|
+
if (!readOnly) toggle()
|
|
123
|
+
onPress?.(event)
|
|
124
|
+
}}
|
|
125
|
+
onPressIn={(event) => {
|
|
126
|
+
if (canStretch) {
|
|
127
|
+
press.value = withTiming(1, {
|
|
128
|
+
duration: slideMotion.enterMs,
|
|
129
|
+
easing: slideMotion.moveEasing,
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
onPressIn?.(event)
|
|
133
|
+
}}
|
|
134
|
+
onPressOut={(event) => {
|
|
135
|
+
press.value = springs ? withSpring(0, { ...springs.pop, mass: 1 }) : 0
|
|
136
|
+
onPressOut?.(event)
|
|
137
|
+
}}
|
|
138
|
+
{...props}
|
|
139
|
+
>
|
|
140
|
+
<Animated.View
|
|
141
|
+
pointerEvents="none"
|
|
142
|
+
className={"fab:bg-primary fab:rounded-full fab:absolute fab:inset-0"}
|
|
143
|
+
style={fillStyle}
|
|
144
|
+
/>
|
|
145
|
+
<Animated.View
|
|
146
|
+
data-slot="switch-thumb"
|
|
147
|
+
data-state={state}
|
|
148
|
+
pointerEvents="none"
|
|
149
|
+
className={"fab:shadow-surface-2 fab:rounded-full fab:bg-white"}
|
|
150
|
+
style={thumbStyle}
|
|
151
|
+
>
|
|
152
|
+
<Animated.View
|
|
153
|
+
className={"fab:bg-primary-foreground fab:rounded-full fab:absolute fab:inset-0"}
|
|
154
|
+
style={knobStyle}
|
|
155
|
+
/>
|
|
156
|
+
</Animated.View>
|
|
157
|
+
</Pressable>
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function Switch({
|
|
162
|
+
size = "default",
|
|
163
|
+
...props
|
|
164
|
+
}: Omit<React.ComponentProps<typeof SwitchControl>, "size"> & {
|
|
165
|
+
size?: "sm" | "default"
|
|
166
|
+
}) {
|
|
167
|
+
// size="sm" takes a step down the scale, so the knob's numbers must be read
|
|
168
|
+
// inside the scope.
|
|
169
|
+
const { density } = useControlSize(size)
|
|
170
|
+
return (
|
|
171
|
+
<DensityScope density={density}>
|
|
172
|
+
<SwitchControl size={size} {...props} />
|
|
173
|
+
</DensityScope>
|
|
174
|
+
)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export { Switch }
|
package/dist/ui/tabs.tsx
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { IconProvider } from "@fabricator-ui/icons-react-native"
|
|
3
|
+
import { useControllableState } from "@rn-primitives/hooks"
|
|
4
|
+
import * as TabsPrimitive from "@rn-primitives/tabs"
|
|
5
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
6
|
+
import { cn } from "cn"
|
|
7
|
+
|
|
8
|
+
import { noteStep } from "../lib/sound-recipes"
|
|
9
|
+
import { useFeedback } from "../lib/feedback"
|
|
10
|
+
import {
|
|
11
|
+
FluidHoverArea,
|
|
12
|
+
FluidHoverHighlight,
|
|
13
|
+
FluidHoverProvider,
|
|
14
|
+
FluidHoverSelection,
|
|
15
|
+
useFluidHover,
|
|
16
|
+
useFluidRow,
|
|
17
|
+
} from "../lib/fluid-hover"
|
|
18
|
+
import { useIconStroke } from "../lib/icon-stroke"
|
|
19
|
+
import {
|
|
20
|
+
getTextContent,
|
|
21
|
+
wrapTextChildren,
|
|
22
|
+
} from "../lib/text-children"
|
|
23
|
+
import { renderTextChildren, Text, TextStyle } from "./text"
|
|
24
|
+
|
|
25
|
+
type TabsOrientation = "horizontal" | "vertical"
|
|
26
|
+
|
|
27
|
+
const TabsContext = React.createContext<TabsOrientation>("horizontal")
|
|
28
|
+
|
|
29
|
+
const TabsListContext = React.createContext<"default" | "subtle">("default")
|
|
30
|
+
|
|
31
|
+
// Each tab rings a step higher along the track.
|
|
32
|
+
const TabIndexContext = React.createContext(0)
|
|
33
|
+
|
|
34
|
+
// The lit tab and the active one turn foreground; the weight never changes.
|
|
35
|
+
const tabsTriggerTextVariants = cva("text-foreground/65 dark:text-muted-foreground text-(length:--density-text-13) font-normal")
|
|
36
|
+
const tabsTriggerLitTextVariants = cva("text-foreground dark:text-foreground")
|
|
37
|
+
const tabsTriggerActiveTextVariants = cva("text-foreground dark:text-foreground")
|
|
38
|
+
|
|
39
|
+
// Each run of text becomes a label, as on the website.
|
|
40
|
+
function renderLabels(children: React.ReactNode) {
|
|
41
|
+
return wrapTextChildren(children, (text, key) => (
|
|
42
|
+
<Text
|
|
43
|
+
key={key}
|
|
44
|
+
data-slot="tabs-trigger-label"
|
|
45
|
+
className={"fab:shrink"}
|
|
46
|
+
>
|
|
47
|
+
{text}
|
|
48
|
+
</Text>
|
|
49
|
+
))
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function Tabs({
|
|
53
|
+
className,
|
|
54
|
+
orientation = "horizontal",
|
|
55
|
+
value,
|
|
56
|
+
defaultValue,
|
|
57
|
+
onValueChange,
|
|
58
|
+
children,
|
|
59
|
+
...props
|
|
60
|
+
}: Omit<TabsPrimitive.RootProps, "value" | "onValueChange"> & {
|
|
61
|
+
value?: string
|
|
62
|
+
defaultValue?: string
|
|
63
|
+
onValueChange?: (value: string) => void
|
|
64
|
+
}) {
|
|
65
|
+
const [current, setCurrent] = useControllableState({
|
|
66
|
+
prop: value,
|
|
67
|
+
defaultProp: defaultValue,
|
|
68
|
+
onChange: (next) => {
|
|
69
|
+
if (next !== undefined) onValueChange?.(next)
|
|
70
|
+
},
|
|
71
|
+
})
|
|
72
|
+
return (
|
|
73
|
+
<TabsContext value={orientation}>
|
|
74
|
+
<TabsPrimitive.Root
|
|
75
|
+
data-slot="tabs"
|
|
76
|
+
data-orientation={orientation}
|
|
77
|
+
orientation={orientation}
|
|
78
|
+
value={current ?? ""}
|
|
79
|
+
onValueChange={setCurrent}
|
|
80
|
+
className={cn(
|
|
81
|
+
"gap-(--density-8) data-[orientation=horizontal]:flex-col data-[orientation=vertical]:flex-row",
|
|
82
|
+
className
|
|
83
|
+
)}
|
|
84
|
+
{...props}
|
|
85
|
+
>
|
|
86
|
+
{renderTextChildren(children)}
|
|
87
|
+
</TabsPrimitive.Root>
|
|
88
|
+
</TabsContext>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const tabsListVariants = cva(
|
|
93
|
+
"rounded-(--radius-wrap) p-(--density-4) data-[orientation=horizontal]:h-(--density-36) data-[orientation=vertical]:gap-(--density-4) corner-curve flex-row items-center justify-center self-start data-[orientation=vertical]:flex-col data-[orientation=vertical]:items-stretch",
|
|
94
|
+
{
|
|
95
|
+
variants: {
|
|
96
|
+
variant: {
|
|
97
|
+
default: "bg-foreground/5",
|
|
98
|
+
// Only the active tab shows its label; the others show their icon.
|
|
99
|
+
subtle: "bg-transparent",
|
|
100
|
+
/** @deprecated Kept for compatibility; renders as `default`. */
|
|
101
|
+
line: "",
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
defaultVariants: {
|
|
105
|
+
variant: "default",
|
|
106
|
+
},
|
|
107
|
+
}
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
function TabsList({
|
|
111
|
+
className,
|
|
112
|
+
variant = "default",
|
|
113
|
+
children,
|
|
114
|
+
...props
|
|
115
|
+
}: TabsPrimitive.ListProps & VariantProps<typeof tabsListVariants>) {
|
|
116
|
+
const { value } = TabsPrimitive.useRootContext()
|
|
117
|
+
const orientation = React.use(TabsContext)
|
|
118
|
+
const resolvedVariant = variant === "subtle" ? "subtle" : "default"
|
|
119
|
+
// Dragging across the tabs moves the highlight; letting go selects, as a
|
|
120
|
+
// segmented control does.
|
|
121
|
+
const fluid = useFluidHover({
|
|
122
|
+
selected: value,
|
|
123
|
+
axis: orientation === "vertical" ? "y" : "x",
|
|
124
|
+
track: orientation === "vertical" ? "hold" : "drag",
|
|
125
|
+
previewsSelection: true,
|
|
126
|
+
})
|
|
127
|
+
const { attach } = fluid
|
|
128
|
+
return (
|
|
129
|
+
<FluidHoverProvider fluid={fluid}>
|
|
130
|
+
<FluidHoverArea fluid={fluid}>
|
|
131
|
+
<TabsPrimitive.List
|
|
132
|
+
ref={attach}
|
|
133
|
+
data-slot="tabs-list"
|
|
134
|
+
data-variant={resolvedVariant}
|
|
135
|
+
data-orientation={orientation}
|
|
136
|
+
className={cn(tabsListVariants({ variant }), className)}
|
|
137
|
+
{...props}
|
|
138
|
+
>
|
|
139
|
+
<FluidHoverSelection
|
|
140
|
+
data-variant={resolvedVariant}
|
|
141
|
+
selection={fluid.selection}
|
|
142
|
+
className={"fab:bg-surface-4 fab:dark:bg-foreground/14 fab:shadow-surface-4 fab:rounded-(--radius-control) fab:corner-curve"}
|
|
143
|
+
/>
|
|
144
|
+
<FluidHoverHighlight
|
|
145
|
+
data-variant={resolvedVariant}
|
|
146
|
+
hover={fluid.hover}
|
|
147
|
+
className={"fab:bg-hover/60 fab:rounded-(--radius-control) fab:corner-curve"}
|
|
148
|
+
/>
|
|
149
|
+
<TabsListContext value={resolvedVariant}>
|
|
150
|
+
{React.Children.map(
|
|
151
|
+
React.Children.toArray(children),
|
|
152
|
+
(child, index) => (
|
|
153
|
+
<TabIndexContext value={index}>{child}</TabIndexContext>
|
|
154
|
+
)
|
|
155
|
+
)}
|
|
156
|
+
</TabsListContext>
|
|
157
|
+
</TabsPrimitive.List>
|
|
158
|
+
</FluidHoverArea>
|
|
159
|
+
</FluidHoverProvider>
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function TabsTrigger({
|
|
164
|
+
className,
|
|
165
|
+
value,
|
|
166
|
+
children,
|
|
167
|
+
onPress,
|
|
168
|
+
onPressIn,
|
|
169
|
+
onPressOut,
|
|
170
|
+
onHoverIn,
|
|
171
|
+
onHoverOut,
|
|
172
|
+
onLayout,
|
|
173
|
+
...props
|
|
174
|
+
}: Omit<TabsPrimitive.TriggerProps, "children"> & {
|
|
175
|
+
children?: React.ReactNode
|
|
176
|
+
}) {
|
|
177
|
+
const { value: selected, onValueChange } = TabsPrimitive.useRootContext()
|
|
178
|
+
const orientation = React.use(TabsContext)
|
|
179
|
+
const variant = React.use(TabsListContext)
|
|
180
|
+
const index = React.use(TabIndexContext)
|
|
181
|
+
const feedback = useFeedback()
|
|
182
|
+
const isActive = selected === value
|
|
183
|
+
// A subtle list draws only the active tab's label; the others keep it as
|
|
184
|
+
// their accessible name.
|
|
185
|
+
const isIconOnly = variant === "subtle" && !isActive
|
|
186
|
+
const { isLit, rowProps } = useFluidRow({
|
|
187
|
+
itemKey: value,
|
|
188
|
+
disabled: props.disabled,
|
|
189
|
+
onActivate: () => {
|
|
190
|
+
feedback("note", { pitch: noteStep(index) })
|
|
191
|
+
onValueChange(value)
|
|
192
|
+
},
|
|
193
|
+
onLayout,
|
|
194
|
+
onPressIn,
|
|
195
|
+
onPressOut,
|
|
196
|
+
onHoverIn,
|
|
197
|
+
onHoverOut,
|
|
198
|
+
})
|
|
199
|
+
return (
|
|
200
|
+
<TextStyle
|
|
201
|
+
eases
|
|
202
|
+
className={cn(
|
|
203
|
+
tabsTriggerTextVariants(),
|
|
204
|
+
isActive
|
|
205
|
+
? tabsTriggerActiveTextVariants()
|
|
206
|
+
: isLit
|
|
207
|
+
? tabsTriggerLitTextVariants()
|
|
208
|
+
: undefined
|
|
209
|
+
)}
|
|
210
|
+
>
|
|
211
|
+
<IconProvider strokeWidth={useIconStroke(isActive || isLit)}>
|
|
212
|
+
<TabsPrimitive.Trigger
|
|
213
|
+
data-slot="tabs-trigger"
|
|
214
|
+
data-state={isActive ? "active" : "inactive"}
|
|
215
|
+
data-orientation={orientation}
|
|
216
|
+
data-variant={variant}
|
|
217
|
+
value={value}
|
|
218
|
+
// Up and down only: sideways it would take a neighbour's press.
|
|
219
|
+
hitSlop={{ top: 8, bottom: 8 }}
|
|
220
|
+
// Not flex-1: its zero basis collapses a tab in a list that fits its tabs.
|
|
221
|
+
className={cn(
|
|
222
|
+
"h-(--density-28) gap-(--density-6) rounded-(--radius-control) px-(--density-12) data-[orientation=vertical]:h-(--density-32) data-[variant=subtle]:grow-0 data-[variant=subtle]:px-(--density-8) data-[variant=subtle]:data-[state=active]:ps-(--density-10) data-[variant=subtle]:data-[state=active]:pe-(--density-12) corner-curve relative grow flex-row items-center justify-center disabled:opacity-50 data-[orientation=vertical]:flex-none data-[orientation=vertical]:justify-start",
|
|
223
|
+
className
|
|
224
|
+
)}
|
|
225
|
+
onPress={(event) => {
|
|
226
|
+
feedback("note", { pitch: noteStep(index) })
|
|
227
|
+
onPress?.(event)
|
|
228
|
+
}}
|
|
229
|
+
accessibilityLabel={isIconOnly ? getTextContent(children) : undefined}
|
|
230
|
+
{...rowProps}
|
|
231
|
+
{...props}
|
|
232
|
+
>
|
|
233
|
+
{isIconOnly
|
|
234
|
+
? React.Children.toArray(children).filter(React.isValidElement)
|
|
235
|
+
: renderLabels(children)}
|
|
236
|
+
</TabsPrimitive.Trigger>
|
|
237
|
+
</IconProvider>
|
|
238
|
+
</TextStyle>
|
|
239
|
+
)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function TabsContent({
|
|
243
|
+
className,
|
|
244
|
+
value,
|
|
245
|
+
keepMounted = false,
|
|
246
|
+
children,
|
|
247
|
+
...props
|
|
248
|
+
}: Omit<TabsPrimitive.ContentProps, "children" | "forceMount"> & {
|
|
249
|
+
keepMounted?: boolean
|
|
250
|
+
children?: React.ReactNode
|
|
251
|
+
}) {
|
|
252
|
+
const { value: selected } = TabsPrimitive.useRootContext()
|
|
253
|
+
return (
|
|
254
|
+
<TextStyle className={"fab:text-(length:--density-text-13)"}>
|
|
255
|
+
<TabsPrimitive.Content
|
|
256
|
+
data-slot="tabs-content"
|
|
257
|
+
value={value}
|
|
258
|
+
forceMount={keepMounted ? true : undefined}
|
|
259
|
+
className={cn(
|
|
260
|
+
"gap-(--density-8) flex-1",
|
|
261
|
+
selected !== value && "hidden",
|
|
262
|
+
className
|
|
263
|
+
)}
|
|
264
|
+
{...props}
|
|
265
|
+
>
|
|
266
|
+
{renderTextChildren(children)}
|
|
267
|
+
</TabsPrimitive.Content>
|
|
268
|
+
</TextStyle>
|
|
269
|
+
)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export { Tabs, TabsContent, TabsList, tabsListVariants, TabsTrigger }
|
package/dist/ui/text.tsx
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { IconProvider } from "@fabricator-ui/icons-react-native"
|
|
3
|
+
import { cva } from "class-variance-authority"
|
|
4
|
+
import { cn } from "cn"
|
|
5
|
+
import { Text as TextPrimitive } from "react-native"
|
|
6
|
+
import Animated from "react-native-reanimated"
|
|
7
|
+
import { useCSSVariable, useResolveClassNames } from "uniwind"
|
|
8
|
+
|
|
9
|
+
import { applyDataVariants } from "../lib/data-variants"
|
|
10
|
+
import { useMotion } from "../lib/motion"
|
|
11
|
+
import { parseNumber } from "../lib/motion-tokens"
|
|
12
|
+
import { wrapTextChildren } from "../lib/text-children"
|
|
13
|
+
|
|
14
|
+
const TextClassContext = React.createContext<string | undefined>(undefined)
|
|
15
|
+
|
|
16
|
+
// How long this control's text takes to change colour, when it eases at all.
|
|
17
|
+
const TextEaseContext = React.createContext<number | null>(null)
|
|
18
|
+
|
|
19
|
+
const AnimatedTextPrimitive = Animated.createAnimatedComponent(TextPrimitive)
|
|
20
|
+
|
|
21
|
+
const textVariants = cva("text-foreground font-sans text-(length:--density-text-13)")
|
|
22
|
+
|
|
23
|
+
// Named sizes bring their own line height; `leading-*` chooses one.
|
|
24
|
+
const SETS_LINE_HEIGHT = /(^|\s)(leading-|text-(xs|sm|base|lg|xl|\dxl)(\s|$))/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Text the website gives 1.5 of line height by inheritance. Inter's own is 1.21,
|
|
28
|
+
* which sets paragraphs tighter than the design. `cn` drops a line height when a
|
|
29
|
+
* font size follows it, so it goes on after the merge.
|
|
30
|
+
*/
|
|
31
|
+
function withLineHeight(className: string) {
|
|
32
|
+
return SETS_LINE_HEIGHT.test(className)
|
|
33
|
+
? className
|
|
34
|
+
: `${className} leading-normal`
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Text whose colour follows its control's state on the feedback timing. */
|
|
38
|
+
function EasedText({
|
|
39
|
+
className,
|
|
40
|
+
duration,
|
|
41
|
+
style,
|
|
42
|
+
...props
|
|
43
|
+
}: React.ComponentProps<typeof TextPrimitive> & { duration: number }) {
|
|
44
|
+
// The colour goes inline for the transition to see, and there it beats the
|
|
45
|
+
// class, so it has to be the one this element's state picks.
|
|
46
|
+
const { color } = useResolveClassNames(
|
|
47
|
+
cn(applyDataVariants(className ?? "", props))
|
|
48
|
+
)
|
|
49
|
+
return (
|
|
50
|
+
<AnimatedTextPrimitive
|
|
51
|
+
data-slot="text"
|
|
52
|
+
className={className}
|
|
53
|
+
style={[
|
|
54
|
+
typeof color === "string"
|
|
55
|
+
? {
|
|
56
|
+
color,
|
|
57
|
+
transitionProperty: "color",
|
|
58
|
+
transitionDuration: duration,
|
|
59
|
+
transitionTimingFunction: "ease",
|
|
60
|
+
}
|
|
61
|
+
: undefined,
|
|
62
|
+
style,
|
|
63
|
+
]}
|
|
64
|
+
{...props}
|
|
65
|
+
/>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function Text({
|
|
70
|
+
className,
|
|
71
|
+
...props
|
|
72
|
+
}: React.ComponentProps<typeof TextPrimitive>) {
|
|
73
|
+
const inherited = React.use(TextClassContext)
|
|
74
|
+
const duration = React.use(TextEaseContext)
|
|
75
|
+
const merged = withLineHeight(cn(textVariants(), inherited, className))
|
|
76
|
+
if (duration !== null) {
|
|
77
|
+
return <EasedText className={merged} duration={duration} {...props} />
|
|
78
|
+
}
|
|
79
|
+
return <TextPrimitive data-slot="text" className={merged} {...props} />
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function TextEase({ children }: { children?: React.ReactNode }) {
|
|
83
|
+
const motion = useMotion("feedback")
|
|
84
|
+
return <TextEaseContext value={motion.enterMs}>{children}</TextEaseContext>
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* What a web element's text and icons inherit from it: React Native has no
|
|
89
|
+
* cascade, so a control passes its text classes and icon colour down.
|
|
90
|
+
*/
|
|
91
|
+
function TextStyle({
|
|
92
|
+
className,
|
|
93
|
+
eases = false,
|
|
94
|
+
children,
|
|
95
|
+
}: {
|
|
96
|
+
className?: string
|
|
97
|
+
/** Its colour changes with state: the text eases there, as on the website. */
|
|
98
|
+
eases?: boolean
|
|
99
|
+
children?: React.ReactNode
|
|
100
|
+
}) {
|
|
101
|
+
const inherited = React.use(TextClassContext)
|
|
102
|
+
const merged = cn(inherited, className)
|
|
103
|
+
const { color } = useResolveClassNames(merged)
|
|
104
|
+
const iconSize = parseNumber(useCSSVariable("--density-icon-16"), 16)
|
|
105
|
+
const inner = (
|
|
106
|
+
<TextClassContext value={merged}>
|
|
107
|
+
<IconProvider
|
|
108
|
+
size={iconSize}
|
|
109
|
+
{...(typeof color === "string" ? { color } : {})}
|
|
110
|
+
>
|
|
111
|
+
{children}
|
|
112
|
+
</IconProvider>
|
|
113
|
+
</TextClassContext>
|
|
114
|
+
)
|
|
115
|
+
return eases ? <TextEase>{inner}</TextEase> : inner
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Children as React Native can draw them: every bare string in a `Text`. */
|
|
119
|
+
function renderTextChildren(children: React.ReactNode) {
|
|
120
|
+
return wrapTextChildren(children, (text, key) => (
|
|
121
|
+
<Text key={key}>{text}</Text>
|
|
122
|
+
))
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export { renderTextChildren, Text, TextClassContext, TextStyle }
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { useComposedRefs } from "@rn-primitives/hooks"
|
|
3
|
+
import { cva } from "class-variance-authority"
|
|
4
|
+
import { cn } from "cn"
|
|
5
|
+
import { TextInput } from "react-native"
|
|
6
|
+
import Animated from "react-native-reanimated"
|
|
7
|
+
|
|
8
|
+
import { useFieldFrame } from "../lib/field-frame"
|
|
9
|
+
import { useFieldControl } from "../lib/field-model"
|
|
10
|
+
|
|
11
|
+
const AnimatedTextInput = Animated.createAnimatedComponent(TextInput)
|
|
12
|
+
|
|
13
|
+
const textareaRestVariants = cva("border-border bg-card/0")
|
|
14
|
+
const textareaFocusVariants = cva("border-foreground/25 bg-card")
|
|
15
|
+
|
|
16
|
+
function Textarea({
|
|
17
|
+
className,
|
|
18
|
+
"aria-invalid": isInvalid,
|
|
19
|
+
disabled,
|
|
20
|
+
editable,
|
|
21
|
+
ref,
|
|
22
|
+
style,
|
|
23
|
+
onFocus,
|
|
24
|
+
onBlur,
|
|
25
|
+
...props
|
|
26
|
+
}: React.ComponentProps<typeof TextInput> & {
|
|
27
|
+
"aria-invalid"?: boolean
|
|
28
|
+
disabled?: boolean
|
|
29
|
+
}) {
|
|
30
|
+
const inputRef = React.useRef<React.ComponentRef<typeof TextInput>>(null)
|
|
31
|
+
const composedRef = useComposedRefs(inputRef, ref)
|
|
32
|
+
const field = useFieldControl({
|
|
33
|
+
activate: () => inputRef.current?.focus(),
|
|
34
|
+
})
|
|
35
|
+
const isFieldInvalid = isInvalid ?? field.isInvalid
|
|
36
|
+
const isEditable = editable ?? !(disabled ?? field.isDisabled)
|
|
37
|
+
const frame = useFieldFrame({
|
|
38
|
+
restClassName: textareaRestVariants(),
|
|
39
|
+
focusClassName: textareaFocusVariants(),
|
|
40
|
+
isInvalid: Boolean(isFieldInvalid),
|
|
41
|
+
onFocus,
|
|
42
|
+
onBlur,
|
|
43
|
+
})
|
|
44
|
+
return (
|
|
45
|
+
<AnimatedTextInput
|
|
46
|
+
ref={composedRef}
|
|
47
|
+
data-slot="textarea"
|
|
48
|
+
data-invalid={isFieldInvalid}
|
|
49
|
+
aria-invalid={isFieldInvalid}
|
|
50
|
+
aria-disabled={!isEditable}
|
|
51
|
+
editable={isEditable}
|
|
52
|
+
multiline
|
|
53
|
+
textAlignVertical="top"
|
|
54
|
+
placeholderTextColorClassName="accent-muted-foreground"
|
|
55
|
+
selectionColorClassName="accent-primary"
|
|
56
|
+
className={cn("font-sans text-foreground border-border data-[invalid=true]:border-destructive/50 min-h-16 rounded-(--radius-control) border bg-transparent px-(--density-10) py-(--density-8) text-(length:--density-text-13) corner-curve w-full disabled:opacity-50", className)}
|
|
57
|
+
style={[frame.frameStyle, style]}
|
|
58
|
+
onFocus={frame.onFocus}
|
|
59
|
+
onBlur={frame.onBlur}
|
|
60
|
+
{...props}
|
|
61
|
+
/>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { Textarea }
|
package/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabricator-ui/react-native",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.10.0",
|
|
4
|
+
"description": "Fabricator UI components for Expo and React Native.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"sideEffects": [
|
|
11
|
+
"**/*.css"
|
|
12
|
+
],
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
"./badge": "./dist/ui/badge.tsx",
|
|
18
|
+
"./button": "./dist/ui/button.tsx",
|
|
19
|
+
"./card": "./dist/ui/card.tsx",
|
|
20
|
+
"./checkbox": "./dist/ui/checkbox.tsx",
|
|
21
|
+
"./dialog": "./dist/ui/dialog.tsx",
|
|
22
|
+
"./dropdown-menu": "./dist/ui/dropdown-menu.tsx",
|
|
23
|
+
"./fabricator-root": "./dist/ui/fabricator-root.tsx",
|
|
24
|
+
"./input": "./dist/ui/input.tsx",
|
|
25
|
+
"./label": "./dist/ui/label.tsx",
|
|
26
|
+
"./select": "./dist/ui/select.tsx",
|
|
27
|
+
"./switch": "./dist/ui/switch.tsx",
|
|
28
|
+
"./tabs": "./dist/ui/tabs.tsx",
|
|
29
|
+
"./textarea": "./dist/ui/textarea.tsx",
|
|
30
|
+
"./styles.css": "./dist/styles.css"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@fabricator-ui/icons-react-native": "0.10.0",
|
|
34
|
+
"@rn-primitives/collapsible": "1.5.2",
|
|
35
|
+
"@rn-primitives/dialog": "1.5.2",
|
|
36
|
+
"@rn-primitives/dropdown-menu": "1.5.2",
|
|
37
|
+
"@rn-primitives/hooks": "1.5.2",
|
|
38
|
+
"@rn-primitives/popover": "1.5.2",
|
|
39
|
+
"@rn-primitives/portal": "1.5.3",
|
|
40
|
+
"@rn-primitives/slot": "1.5.2",
|
|
41
|
+
"@rn-primitives/tabs": "1.5.2",
|
|
42
|
+
"class-variance-authority": "0.7.1",
|
|
43
|
+
"cn": "0.5.2"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"react": "19.3.0",
|
|
47
|
+
"react-native": "0.88.1",
|
|
48
|
+
"react-native-gesture-handler": "~3.3.0",
|
|
49
|
+
"react-native-reanimated": "4.7.1",
|
|
50
|
+
"react-native-safe-area-context": "~5.11.1",
|
|
51
|
+
"react-native-svg": "15.16.0",
|
|
52
|
+
"react-native-worklets": "0.13.0",
|
|
53
|
+
"tailwindcss": "^4.0.0",
|
|
54
|
+
"uniwind": "1.14.0"
|
|
55
|
+
}
|
|
56
|
+
}
|