@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,68 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { PortalHost } from "@rn-primitives/portal"
|
|
3
|
+
import { useWindowDimensions } from "react-native"
|
|
4
|
+
import { GestureHandlerRootView } from "react-native-gesture-handler"
|
|
5
|
+
import { SafeAreaListener } from "react-native-safe-area-context"
|
|
6
|
+
import { ScopedVariables, Uniwind, useCSSVariable } from "uniwind"
|
|
7
|
+
|
|
8
|
+
import { getDensityVariables } from "../lib/fabricator/density-variables"
|
|
9
|
+
import {
|
|
10
|
+
getDensityName,
|
|
11
|
+
getDensityTokens,
|
|
12
|
+
getDeviceDensity,
|
|
13
|
+
} from "../lib/density-scale"
|
|
14
|
+
import { markGesture } from "../lib/feedback"
|
|
15
|
+
import { parseNumber } from "../lib/motion-tokens"
|
|
16
|
+
|
|
17
|
+
const NO_VARIABLES = {}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The sizes for this window: a tablet's rung where the look has a phone's base,
|
|
21
|
+
* and on a phone whose look is Default, which is sized for a pointer. The
|
|
22
|
+
* scope stays mounted with nothing in it: a wrapper that came and went with a density
|
|
23
|
+
* change or a resized window would remount the whole app, and lose its state.
|
|
24
|
+
*/
|
|
25
|
+
function DeviceDensity({ children }: { children?: React.ReactNode }) {
|
|
26
|
+
const { width } = useWindowDimensions()
|
|
27
|
+
const base = getDensityName(parseNumber(useCSSVariable("--density-36"), 36))
|
|
28
|
+
const density = getDeviceDensity(base, width)
|
|
29
|
+
const variables = React.useMemo(
|
|
30
|
+
() =>
|
|
31
|
+
density ? getDensityVariables(getDensityTokens(density)) : NO_VARIABLES,
|
|
32
|
+
[density]
|
|
33
|
+
)
|
|
34
|
+
return <ScopedVariables variables={variables}>{children}</ScopedVariables>
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* What a React Native app needs once at its root, where a web page has the
|
|
39
|
+
* document: gestures, safe-area classes, the sizes for this device, and the place
|
|
40
|
+
* overlays render.
|
|
41
|
+
*/
|
|
42
|
+
function FabricatorRoot({ children }: { children?: React.ReactNode }) {
|
|
43
|
+
return (
|
|
44
|
+
<GestureHandlerRootView
|
|
45
|
+
data-slot="fabricator-root"
|
|
46
|
+
style={{ flex: 1 }}
|
|
47
|
+
// Sees every touch on its way down, and takes none of them.
|
|
48
|
+
onStartShouldSetResponderCapture={() => {
|
|
49
|
+
markGesture()
|
|
50
|
+
return false
|
|
51
|
+
}}
|
|
52
|
+
>
|
|
53
|
+
<SafeAreaListener
|
|
54
|
+
onChange={({ insets }) => {
|
|
55
|
+
Uniwind.updateInsets(insets)
|
|
56
|
+
}}
|
|
57
|
+
style={{ flex: 1 }}
|
|
58
|
+
>
|
|
59
|
+
<DeviceDensity>
|
|
60
|
+
{children}
|
|
61
|
+
<PortalHost />
|
|
62
|
+
</DeviceDensity>
|
|
63
|
+
</SafeAreaListener>
|
|
64
|
+
</GestureHandlerRootView>
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export { FabricatorRoot }
|
|
@@ -0,0 +1,63 @@
|
|
|
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 inputRestVariants = cva("border-border bg-card/0")
|
|
14
|
+
const inputFocusVariants = cva("border-foreground/25 bg-card")
|
|
15
|
+
|
|
16
|
+
function Input({
|
|
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: inputRestVariants(),
|
|
39
|
+
focusClassName: inputFocusVariants(),
|
|
40
|
+
isInvalid: Boolean(isFieldInvalid),
|
|
41
|
+
onFocus,
|
|
42
|
+
onBlur,
|
|
43
|
+
})
|
|
44
|
+
return (
|
|
45
|
+
<AnimatedTextInput
|
|
46
|
+
ref={composedRef}
|
|
47
|
+
data-slot="input"
|
|
48
|
+
data-invalid={Boolean(isFieldInvalid)}
|
|
49
|
+
aria-invalid={isFieldInvalid}
|
|
50
|
+
aria-disabled={!isEditable}
|
|
51
|
+
editable={isEditable}
|
|
52
|
+
placeholderTextColorClassName="accent-muted-foreground"
|
|
53
|
+
selectionColorClassName="accent-primary"
|
|
54
|
+
className={cn("shrink min-h-(--density-36) font-sans text-foreground border-border data-[invalid=true]:border-destructive/50 h-(--density-36) rounded-(--radius-control) border bg-transparent px-(--density-10) py-1 text-(length:--density-text-13) corner-curve w-full disabled:opacity-50", className)}
|
|
55
|
+
style={[frame.frameStyle, style]}
|
|
56
|
+
onFocus={frame.onFocus}
|
|
57
|
+
onBlur={frame.onBlur}
|
|
58
|
+
{...props}
|
|
59
|
+
/>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { Input }
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { cn } from "cn"
|
|
3
|
+
|
|
4
|
+
import { Text } from "./text"
|
|
5
|
+
|
|
6
|
+
function Label({
|
|
7
|
+
className,
|
|
8
|
+
disabled,
|
|
9
|
+
...props
|
|
10
|
+
}: React.ComponentProps<typeof Text>) {
|
|
11
|
+
return (
|
|
12
|
+
<Text
|
|
13
|
+
data-slot="label"
|
|
14
|
+
data-disabled={Boolean(disabled)}
|
|
15
|
+
disabled={disabled}
|
|
16
|
+
className={cn("text-foreground text-(length:--density-text-13) leading-tight font-medium data-[disabled=true]:opacity-50", className)}
|
|
17
|
+
{...props}
|
|
18
|
+
/>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export { Label }
|