@vvedantb/native-ui 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +89 -2
- package/package.json +72 -3
- package/src/AmbientBackground.tsx +29 -0
- package/src/BottomSheetContainer.tsx +92 -0
- package/src/Button.tsx +111 -0
- package/src/Card.tsx +64 -0
- package/src/Chip.tsx +49 -0
- package/src/DateTimeField.tsx +78 -0
- package/src/EmptyState.tsx +51 -0
- package/src/FloatingFAB.tsx +62 -0
- package/src/FloatingSurface.tsx +114 -0
- package/src/FloatingTabBar.tsx +107 -0
- package/src/HeaderIconButton.tsx +29 -0
- package/src/Input.tsx +32 -0
- package/src/LiquidGlass.tsx +14 -0
- package/src/ListRow.tsx +85 -0
- package/src/PillTabs.tsx +51 -0
- package/src/SafeAreaContainer.tsx +26 -0
- package/src/ScreenContainer.tsx +36 -0
- package/src/Select.tsx +132 -0
- package/src/Skeleton.tsx +37 -0
- package/src/Switch.tsx +45 -0
- package/src/cn.ts +6 -0
- package/src/colors.ts +17 -0
- package/src/floating.ts +40 -0
- package/src/haptics.ts +9 -0
- package/src/index.ts +58 -0
- package/src/primitives/button.tsx +101 -0
- package/src/primitives/card.tsx +102 -0
- package/src/primitives/icon.tsx +14 -0
- package/src/primitives/input.tsx +37 -0
- package/src/primitives/native-only-animated-view.tsx +33 -0
- package/src/primitives/select.tsx +265 -0
- package/src/primitives/switch.tsx +77 -0
- package/src/primitives/text.tsx +95 -0
- package/src/settings/SettingsField.tsx +33 -0
- package/src/settings/SettingsSection.tsx +75 -0
- package/src/settings/SettingsStack.tsx +5 -0
- package/src/settings/SettingsToggleRow.tsx +58 -0
- package/src/theme.tsx +44 -0
- package/src/tokens.ts +43 -0
- package/src/useReduceTransparency.ts +24 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 vvedantb
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,90 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@vvedantb/native-ui`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React Native + Expo primitives extracted from a React Native app. Floating pill chrome, Android-safe shadows, forms, list rows, and settings sections.
|
|
4
|
+
|
|
5
|
+
Web apps should keep using `@vvedantb/ui`. This package is native-only.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @vvedantb/native-ui
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Peers the app must already have (Expo SDK 57 / RN 0.76+):
|
|
14
|
+
|
|
15
|
+
- `react`, `react-native`
|
|
16
|
+
- `nativewind` `>=4`
|
|
17
|
+
- `expo-blur`, `expo-haptics`, `expo-linear-gradient`
|
|
18
|
+
- `react-native-reanimated`, `react-native-safe-area-context`, `react-native-screens`
|
|
19
|
+
- `@rn-primitives/slot`, `@rn-primitives/switch`, `@rn-primitives/select`
|
|
20
|
+
- `@expo/vector-icons`, `@tabler/icons-react-native`, `lucide-react-native`
|
|
21
|
+
- `class-variance-authority`, `clsx`, `tailwind-merge`
|
|
22
|
+
|
|
23
|
+
Optional, only if you import those components:
|
|
24
|
+
|
|
25
|
+
- `expo-router` — `FloatingTabBar`
|
|
26
|
+
- `@gorhom/bottom-sheet` — `BottomSheetContainer`
|
|
27
|
+
- `@react-native-community/datetimepicker` and `dayjs` — `DateTimeField`
|
|
28
|
+
|
|
29
|
+
## Expo / NativeWind
|
|
30
|
+
|
|
31
|
+
Source-exported. Point Tailwind at the package so class names are generated:
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
// tailwind.config.js
|
|
35
|
+
content: [
|
|
36
|
+
"./app/**/*.{js,ts,tsx}",
|
|
37
|
+
"./components/**/*.{js,ts,tsx}",
|
|
38
|
+
"./node_modules/@vvedantb/native-ui/src/**/*.{js,ts,tsx}",
|
|
39
|
+
],
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Metro already resolves `node_modules`. In a pnpm monorepo, if a peer resolves to the wrong copy, add:
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
const path = require("node:path");
|
|
46
|
+
config.watchFolders = [path.resolve(__dirname, "../..")];
|
|
47
|
+
config.resolver.nodeModulesPaths = [
|
|
48
|
+
path.resolve(__dirname, "node_modules"),
|
|
49
|
+
path.resolve(__dirname, "../../node_modules"),
|
|
50
|
+
];
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
The app must define NativeWind tokens (`bg-surface`, `bg-secondary`, `text-foreground`, pink utilities) and Instrument Sans font classes (`font-instrument-sans-*`). Accent pink stays in the app stylesheet.
|
|
54
|
+
|
|
55
|
+
## Theme
|
|
56
|
+
|
|
57
|
+
Wrap the tree (inside your colour-scheme provider):
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
import { NativeUiProvider, Button, Card } from "@vvedantb/native-ui";
|
|
61
|
+
|
|
62
|
+
<NativeUiProvider largerText={false} accentColor="#db2777">
|
|
63
|
+
<Card title="Today">
|
|
64
|
+
<Button onPress={() => {}}>Record a dose</Button>
|
|
65
|
+
</Card>
|
|
66
|
+
</NativeUiProvider>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`useLargerText()` steps type and tap targets up. `accentColor` tints FABs and card icons. Surfaces use the tokens in `src/tokens.ts` for fill, radius (card 24, row 20, pill 999) and spacing (16).
|
|
70
|
+
|
|
71
|
+
## Floating UI / Android shadows
|
|
72
|
+
|
|
73
|
+
Do not put `elevation` or NativeWind `shadow-*` on nested or translucent chrome. `floatingShadow` is iOS `shadow*` and Android/web `boxShadow`. `FloatingSurface` paints an opaque fill on Android and clips on an inner view. Blur is iOS-only.
|
|
74
|
+
|
|
75
|
+
## Tokens
|
|
76
|
+
|
|
77
|
+
The JS tokens (colours, radii, spacing) live in `src/tokens.ts`. It is a copy of `@vvedantb/ui/tokens/native`, kept inside this package so React Native apps do not install `@vvedantb/ui` (Radix, react-dom and the rest of the web stack) for colour values. A test in `@vvedantb/ui` fails when the two files differ, so change both together.
|
|
78
|
+
|
|
79
|
+
Apps that already depend on `@vvedantb/ui` can import the same values from `@vvedantb/ui/tokens/native`.
|
|
80
|
+
|
|
81
|
+
## Publish
|
|
82
|
+
|
|
83
|
+
There is no CI publish workflow. From a machine with npm access:
|
|
84
|
+
|
|
85
|
+
```sh
|
|
86
|
+
export NPM_CONFIG_USERCONFIG="$HOME/.npmrc" # if you keep the token there
|
|
87
|
+
cd packages/native-ui && npm publish --access public
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
`@vvedantb/native-ui` `0.2.0` has no `@vvedantb/tokens` peer. See `MIGRATION.md` at the repository root.
|
package/package.json
CHANGED
|
@@ -1,6 +1,75 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/native-ui",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "Shared React Native / Expo UI primitives. Floating surfaces, forms, settings chrome, and tab bar.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/vvedantb/ui.git",
|
|
13
|
+
"directory": "packages/native-ui"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./src/index.ts",
|
|
18
|
+
"default": "./src/index.ts"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"types": "./src/index.ts",
|
|
22
|
+
"files": [
|
|
23
|
+
"src",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@expo/vector-icons": "*",
|
|
29
|
+
"@gorhom/bottom-sheet": ">=5",
|
|
30
|
+
"@react-native-community/datetimepicker": "*",
|
|
31
|
+
"@rn-primitives/select": "*",
|
|
32
|
+
"@rn-primitives/slot": "*",
|
|
33
|
+
"@rn-primitives/switch": "*",
|
|
34
|
+
"@tabler/icons-react-native": "*",
|
|
35
|
+
"class-variance-authority": ">=0.7.0",
|
|
36
|
+
"clsx": ">=2.0.0",
|
|
37
|
+
"dayjs": ">=1.11.0",
|
|
38
|
+
"expo-blur": "*",
|
|
39
|
+
"expo-haptics": "*",
|
|
40
|
+
"expo-linear-gradient": "*",
|
|
41
|
+
"expo-router": "*",
|
|
42
|
+
"lucide-react-native": "*",
|
|
43
|
+
"nativewind": ">=4.0.0",
|
|
44
|
+
"react": ">=19.0.0",
|
|
45
|
+
"react-native": ">=0.76.0",
|
|
46
|
+
"react-native-reanimated": "*",
|
|
47
|
+
"react-native-safe-area-context": "*",
|
|
48
|
+
"react-native-screens": "*",
|
|
49
|
+
"tailwind-merge": ">=2.0.0"
|
|
50
|
+
},
|
|
51
|
+
"peerDependenciesMeta": {
|
|
52
|
+
"@gorhom/bottom-sheet": {
|
|
53
|
+
"optional": true
|
|
54
|
+
},
|
|
55
|
+
"@react-native-community/datetimepicker": {
|
|
56
|
+
"optional": true
|
|
57
|
+
},
|
|
58
|
+
"dayjs": {
|
|
59
|
+
"optional": true
|
|
60
|
+
},
|
|
61
|
+
"expo-router": {
|
|
62
|
+
"optional": true
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@types/react": "^19.1.0",
|
|
67
|
+
"react": "^19.1.0",
|
|
68
|
+
"typescript": "^5.9.0",
|
|
69
|
+
"vitest": "^3.2.0"
|
|
70
|
+
},
|
|
71
|
+
"scripts": {
|
|
72
|
+
"build": "node -e \"require('node:fs').accessSync('src/index.ts')\"",
|
|
73
|
+
"test": "vitest run"
|
|
74
|
+
}
|
|
6
75
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { StyleSheet, View, type ViewProps } from "react-native";
|
|
2
|
+
import { LinearGradient } from "expo-linear-gradient";
|
|
3
|
+
import { useColorScheme } from "nativewind";
|
|
4
|
+
import { cn } from "./cn";
|
|
5
|
+
|
|
6
|
+
const LIGHT = ["#f6f6f7", "#fde8f0", "#f4f5f7"] as const;
|
|
7
|
+
const DARK = ["#1c1c1e", "#2a1820", "#1a1a1c"] as const;
|
|
8
|
+
|
|
9
|
+
export function AmbientBackground({
|
|
10
|
+
children,
|
|
11
|
+
className,
|
|
12
|
+
...props
|
|
13
|
+
}: ViewProps & { className?: string }) {
|
|
14
|
+
const { colorScheme } = useColorScheme();
|
|
15
|
+
const colors = colorScheme === "dark" ? DARK : LIGHT;
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<View className={cn("flex-1", className)} {...props}>
|
|
19
|
+
<LinearGradient
|
|
20
|
+
pointerEvents="none"
|
|
21
|
+
colors={[...colors]}
|
|
22
|
+
start={{ x: 0.05, y: 0 }}
|
|
23
|
+
end={{ x: 0.95, y: 1 }}
|
|
24
|
+
style={StyleSheet.absoluteFill}
|
|
25
|
+
/>
|
|
26
|
+
{children}
|
|
27
|
+
</View>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BottomSheetBackdrop,
|
|
3
|
+
BottomSheetModal,
|
|
4
|
+
BottomSheetView,
|
|
5
|
+
} from "@gorhom/bottom-sheet";
|
|
6
|
+
import { View, Text, TouchableOpacity } from "react-native";
|
|
7
|
+
import { useRef, useEffect, useCallback, JSX } from "react";
|
|
8
|
+
import { useColorScheme } from "nativewind";
|
|
9
|
+
import { Colors } from "./colors";
|
|
10
|
+
import { IconX } from "@tabler/icons-react-native";
|
|
11
|
+
import { BottomSheetDefaultBackdropProps } from "@gorhom/bottom-sheet/lib/typescript/components/bottomSheetBackdrop/types";
|
|
12
|
+
import { GlassSheetBackground } from "./LiquidGlass";
|
|
13
|
+
import { useLargerText } from "./theme";
|
|
14
|
+
|
|
15
|
+
export function BottomSheetContainer({
|
|
16
|
+
visible,
|
|
17
|
+
onClose,
|
|
18
|
+
title,
|
|
19
|
+
children,
|
|
20
|
+
closeTestID,
|
|
21
|
+
}: {
|
|
22
|
+
visible: boolean;
|
|
23
|
+
onClose: () => void;
|
|
24
|
+
title: string;
|
|
25
|
+
children: React.ReactNode;
|
|
26
|
+
closeTestID?: string;
|
|
27
|
+
}) {
|
|
28
|
+
const bottomSheetModalRef = useRef<BottomSheetModal>(null);
|
|
29
|
+
const largerText = useLargerText();
|
|
30
|
+
const { colorScheme } = useColorScheme();
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (visible) {
|
|
34
|
+
bottomSheetModalRef.current?.present();
|
|
35
|
+
} else {
|
|
36
|
+
bottomSheetModalRef.current?.dismiss();
|
|
37
|
+
}
|
|
38
|
+
}, [visible]);
|
|
39
|
+
|
|
40
|
+
const renderBackdrop = useCallback(
|
|
41
|
+
(props: JSX.IntrinsicAttributes & BottomSheetDefaultBackdropProps) => (
|
|
42
|
+
<BottomSheetBackdrop
|
|
43
|
+
{...props}
|
|
44
|
+
disappearsOnIndex={-1}
|
|
45
|
+
appearsOnIndex={0}
|
|
46
|
+
opacity={0.5}
|
|
47
|
+
/>
|
|
48
|
+
),
|
|
49
|
+
[],
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<BottomSheetModal
|
|
54
|
+
ref={bottomSheetModalRef}
|
|
55
|
+
backdropComponent={renderBackdrop}
|
|
56
|
+
onDismiss={onClose}
|
|
57
|
+
backgroundComponent={GlassSheetBackground}
|
|
58
|
+
handleIndicatorStyle={{
|
|
59
|
+
backgroundColor:
|
|
60
|
+
colorScheme === "dark" ? Colors.white : Colors.neutral[800],
|
|
61
|
+
}}
|
|
62
|
+
enableContentPanningGesture={false}
|
|
63
|
+
enableHandlePanningGesture={true}
|
|
64
|
+
keyboardBehavior="interactive"
|
|
65
|
+
>
|
|
66
|
+
<BottomSheetView className="p-5 pb-12">
|
|
67
|
+
<View className="mb-4 flex-row items-center justify-between gap-3">
|
|
68
|
+
<Text
|
|
69
|
+
className={`${largerText ? "text-2xl" : "text-xl"} flex-1 font-instrument-sans-bold text-foreground`}
|
|
70
|
+
>
|
|
71
|
+
{title}
|
|
72
|
+
</Text>
|
|
73
|
+
<TouchableOpacity
|
|
74
|
+
testID={closeTestID}
|
|
75
|
+
accessibilityRole="button"
|
|
76
|
+
accessibilityLabel="Close"
|
|
77
|
+
onPress={() => bottomSheetModalRef.current?.dismiss()}
|
|
78
|
+
className="-mr-2 h-12 w-12 items-center justify-center"
|
|
79
|
+
hitSlop={8}
|
|
80
|
+
activeOpacity={0.7}
|
|
81
|
+
>
|
|
82
|
+
<IconX
|
|
83
|
+
size={largerText ? 32 : 28}
|
|
84
|
+
color={colorScheme === "dark" ? "white" : "black"}
|
|
85
|
+
/>
|
|
86
|
+
</TouchableOpacity>
|
|
87
|
+
</View>
|
|
88
|
+
{children}
|
|
89
|
+
</BottomSheetView>
|
|
90
|
+
</BottomSheetModal>
|
|
91
|
+
);
|
|
92
|
+
}
|
package/src/Button.tsx
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { MaterialIcons } from "@expo/vector-icons";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { PINK_600 } from "./colors";
|
|
4
|
+
import { ActivityIndicator, View } from "react-native";
|
|
5
|
+
import { Button as PrimitiveButton } from "./primitives/button";
|
|
6
|
+
import { Text as PrimitiveText } from "./primitives/text";
|
|
7
|
+
import { cn } from "./cn";
|
|
8
|
+
import { floatingShadow } from "./floating";
|
|
9
|
+
import { useLargerText } from "./theme";
|
|
10
|
+
|
|
11
|
+
interface ButtonProps extends Omit<
|
|
12
|
+
React.ComponentPropsWithoutRef<typeof PrimitiveButton>,
|
|
13
|
+
"variant" | "size" | "children" | "onPress"
|
|
14
|
+
> {
|
|
15
|
+
onPress?: () => void;
|
|
16
|
+
variant?: "primary" | "secondary" | "outline";
|
|
17
|
+
icon?: keyof typeof MaterialIcons.glyphMap;
|
|
18
|
+
leftIcon?: React.ReactNode;
|
|
19
|
+
loading?: boolean;
|
|
20
|
+
size?: "small" | "medium" | "large";
|
|
21
|
+
fullWidth?: boolean;
|
|
22
|
+
children: React.ReactNode;
|
|
23
|
+
shadowType?: "flat" | "shadow";
|
|
24
|
+
className?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const HEIGHT = {
|
|
28
|
+
regular: { small: "h-12 px-5", medium: "h-14 px-6", large: "h-16 px-6" },
|
|
29
|
+
larger: { small: "h-14 px-5", medium: "h-16 px-6", large: "h-[72px] px-6" },
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const TEXT = {
|
|
33
|
+
regular: { small: "text-sm", medium: "text-lg", large: "text-xl" },
|
|
34
|
+
larger: { small: "text-base", medium: "text-xl", large: "text-2xl" },
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type { ButtonProps };
|
|
38
|
+
|
|
39
|
+
export function Button({
|
|
40
|
+
onPress,
|
|
41
|
+
variant = "primary",
|
|
42
|
+
icon,
|
|
43
|
+
leftIcon,
|
|
44
|
+
loading,
|
|
45
|
+
size = "medium",
|
|
46
|
+
fullWidth = true,
|
|
47
|
+
children,
|
|
48
|
+
shadowType = "shadow",
|
|
49
|
+
className,
|
|
50
|
+
...props
|
|
51
|
+
}: ButtonProps) {
|
|
52
|
+
const scale = useLargerText() ? "larger" : "regular";
|
|
53
|
+
const isTinted = variant === "outline" || variant === "secondary";
|
|
54
|
+
const contentColor = isTinted ? PINK_600 : "#fff";
|
|
55
|
+
const elevate = shadowType === "shadow" && variant === "primary";
|
|
56
|
+
|
|
57
|
+
const variantClassName =
|
|
58
|
+
variant === "outline"
|
|
59
|
+
? "border-0 bg-pink-50 dark:bg-pink-900/20"
|
|
60
|
+
: variant === "secondary"
|
|
61
|
+
? "bg-neutral-100 dark:bg-neutral-800"
|
|
62
|
+
: "";
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<PrimitiveButton
|
|
66
|
+
onPress={onPress}
|
|
67
|
+
variant={variant === "primary" ? "default" : "secondary"}
|
|
68
|
+
hitSlop={size === "small" ? 8 : undefined}
|
|
69
|
+
className={cn(
|
|
70
|
+
"relative rounded-full border border-white/40 dark:border-white/10",
|
|
71
|
+
HEIGHT[scale][size],
|
|
72
|
+
fullWidth && "w-full",
|
|
73
|
+
variantClassName,
|
|
74
|
+
className,
|
|
75
|
+
)}
|
|
76
|
+
{...props}
|
|
77
|
+
disabled={loading || props.disabled}
|
|
78
|
+
style={elevate ? floatingShadow : props.style}
|
|
79
|
+
>
|
|
80
|
+
<View className="flex-row items-center justify-center gap-2">
|
|
81
|
+
{loading ? (
|
|
82
|
+
<ActivityIndicator size="small" color={contentColor} />
|
|
83
|
+
) : (
|
|
84
|
+
<>
|
|
85
|
+
{leftIcon ??
|
|
86
|
+
(icon ? (
|
|
87
|
+
<MaterialIcons
|
|
88
|
+
name={icon}
|
|
89
|
+
size={scale === "larger" ? 26 : 22}
|
|
90
|
+
color={contentColor}
|
|
91
|
+
/>
|
|
92
|
+
) : null)}
|
|
93
|
+
{typeof children === "string" || typeof children === "number" ? (
|
|
94
|
+
<PrimitiveText
|
|
95
|
+
className={cn(
|
|
96
|
+
TEXT[scale][size],
|
|
97
|
+
"font-instrument-sans-semibold",
|
|
98
|
+
isTinted ? "text-pink-700 dark:text-pink-300" : "text-white",
|
|
99
|
+
)}
|
|
100
|
+
>
|
|
101
|
+
{children}
|
|
102
|
+
</PrimitiveText>
|
|
103
|
+
) : (
|
|
104
|
+
children
|
|
105
|
+
)}
|
|
106
|
+
</>
|
|
107
|
+
)}
|
|
108
|
+
</View>
|
|
109
|
+
</PrimitiveButton>
|
|
110
|
+
);
|
|
111
|
+
}
|
package/src/Card.tsx
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { ComponentType, ReactNode } from "react";
|
|
2
|
+
import type { IconProps } from "@tabler/icons-react-native";
|
|
3
|
+
import { View } from "react-native";
|
|
4
|
+
import {
|
|
5
|
+
Card as PrimitiveCard,
|
|
6
|
+
CardContent,
|
|
7
|
+
CardHeader,
|
|
8
|
+
CardTitle,
|
|
9
|
+
} from "./primitives/card";
|
|
10
|
+
import { FloatingSurface } from "./FloatingSurface";
|
|
11
|
+
import { cn } from "./cn";
|
|
12
|
+
import { useAccentColor, useLargerText } from "./theme";
|
|
13
|
+
|
|
14
|
+
export function Card({
|
|
15
|
+
children,
|
|
16
|
+
title,
|
|
17
|
+
action,
|
|
18
|
+
leftIcon: Icon,
|
|
19
|
+
testID,
|
|
20
|
+
}: {
|
|
21
|
+
children: ReactNode;
|
|
22
|
+
title?: string;
|
|
23
|
+
action?: ReactNode;
|
|
24
|
+
leftIcon?: ComponentType<IconProps>;
|
|
25
|
+
testID?: string;
|
|
26
|
+
}) {
|
|
27
|
+
const largerText = useLargerText();
|
|
28
|
+
const accentColor = useAccentColor();
|
|
29
|
+
const hasHeader = Boolean(title || action);
|
|
30
|
+
return (
|
|
31
|
+
<FloatingSurface>
|
|
32
|
+
<PrimitiveCard
|
|
33
|
+
testID={testID}
|
|
34
|
+
className="gap-4 rounded-none border-0 bg-transparent py-4"
|
|
35
|
+
>
|
|
36
|
+
{hasHeader && (
|
|
37
|
+
<CardHeader className="px-4 py-0">
|
|
38
|
+
<View className="flex-row items-center justify-between">
|
|
39
|
+
<View className="flex-row items-center gap-2">
|
|
40
|
+
{Icon && (
|
|
41
|
+
<Icon size={largerText ? 28 : 24} color={accentColor} />
|
|
42
|
+
)}
|
|
43
|
+
{title ? (
|
|
44
|
+
<CardTitle
|
|
45
|
+
className={cn(
|
|
46
|
+
"font-instrument-sans-bold text-foreground",
|
|
47
|
+
largerText ? "text-2xl" : "text-xl",
|
|
48
|
+
)}
|
|
49
|
+
>
|
|
50
|
+
{title}
|
|
51
|
+
</CardTitle>
|
|
52
|
+
) : null}
|
|
53
|
+
</View>
|
|
54
|
+
{action}
|
|
55
|
+
</View>
|
|
56
|
+
</CardHeader>
|
|
57
|
+
)}
|
|
58
|
+
<CardContent className={cn(hasHeader && "pt-0", "px-4")}>
|
|
59
|
+
{children}
|
|
60
|
+
</CardContent>
|
|
61
|
+
</PrimitiveCard>
|
|
62
|
+
</FloatingSurface>
|
|
63
|
+
);
|
|
64
|
+
}
|
package/src/Chip.tsx
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Pressable, Text } from "react-native";
|
|
2
|
+
import { useLargerText } from "./theme";
|
|
3
|
+
|
|
4
|
+
export function Chip({
|
|
5
|
+
label,
|
|
6
|
+
selected,
|
|
7
|
+
onPress,
|
|
8
|
+
testID,
|
|
9
|
+
round = false,
|
|
10
|
+
}: {
|
|
11
|
+
label: string;
|
|
12
|
+
selected: boolean;
|
|
13
|
+
onPress: () => void;
|
|
14
|
+
testID?: string;
|
|
15
|
+
round?: boolean;
|
|
16
|
+
}) {
|
|
17
|
+
const largerText = useLargerText();
|
|
18
|
+
const size = round
|
|
19
|
+
? largerText
|
|
20
|
+
? "h-14 w-14"
|
|
21
|
+
: "h-12 w-12"
|
|
22
|
+
: largerText
|
|
23
|
+
? "min-h-14 px-5 py-3"
|
|
24
|
+
: "min-h-12 px-4 py-2";
|
|
25
|
+
return (
|
|
26
|
+
<Pressable
|
|
27
|
+
testID={testID}
|
|
28
|
+
accessibilityRole="button"
|
|
29
|
+
accessibilityLabel={label}
|
|
30
|
+
accessibilityState={{ selected }}
|
|
31
|
+
onPress={onPress}
|
|
32
|
+
className={`items-center justify-center rounded-full border border-white/40 active:opacity-70 dark:border-white/10 ${
|
|
33
|
+
size
|
|
34
|
+
} ${selected ? "bg-pink-100 dark:bg-pink-900/40" : "bg-secondary"}`}
|
|
35
|
+
>
|
|
36
|
+
<Text
|
|
37
|
+
className={`font-instrument-sans-semibold ${
|
|
38
|
+
largerText ? "text-xl" : "text-lg"
|
|
39
|
+
} ${
|
|
40
|
+
selected
|
|
41
|
+
? "text-pink-700 dark:text-pink-300"
|
|
42
|
+
: "text-muted-foreground"
|
|
43
|
+
}`}
|
|
44
|
+
>
|
|
45
|
+
{label}
|
|
46
|
+
</Text>
|
|
47
|
+
</Pressable>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { Platform, Pressable, Text, View } from "react-native";
|
|
3
|
+
import DateTimePicker, {
|
|
4
|
+
type DateTimePickerEvent,
|
|
5
|
+
} from "@react-native-community/datetimepicker";
|
|
6
|
+
import dayjs from "dayjs";
|
|
7
|
+
import { useLargerText } from "./theme";
|
|
8
|
+
|
|
9
|
+
type PickerMode = "date" | "time";
|
|
10
|
+
type PickerButton = { mode: PickerMode; label: string };
|
|
11
|
+
|
|
12
|
+
export function DateTimeField({
|
|
13
|
+
value,
|
|
14
|
+
onChange,
|
|
15
|
+
mode = "datetime",
|
|
16
|
+
maximumDate,
|
|
17
|
+
testID,
|
|
18
|
+
}: {
|
|
19
|
+
value: Date;
|
|
20
|
+
onChange: (value: Date) => void;
|
|
21
|
+
mode?: "datetime" | "time";
|
|
22
|
+
maximumDate?: Date;
|
|
23
|
+
testID?: string;
|
|
24
|
+
}) {
|
|
25
|
+
const largerText = useLargerText();
|
|
26
|
+
const [picker, setPicker] = useState<PickerMode | null>(null);
|
|
27
|
+
|
|
28
|
+
const handleChange = (event: DateTimePickerEvent, next?: Date) => {
|
|
29
|
+
if (Platform.OS === "android") setPicker(null);
|
|
30
|
+
if (event.type === "set" && next) onChange(next);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const timeButton: PickerButton = {
|
|
34
|
+
mode: "time",
|
|
35
|
+
label: dayjs(value).format("HH:mm"),
|
|
36
|
+
};
|
|
37
|
+
const buttons: PickerButton[] =
|
|
38
|
+
mode === "datetime"
|
|
39
|
+
? [{ mode: "date", label: dayjs(value).format("D MMM YYYY") }, timeButton]
|
|
40
|
+
: [timeButton];
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<View className="gap-2">
|
|
44
|
+
<View className="flex-row gap-3">
|
|
45
|
+
{buttons.map((button) => (
|
|
46
|
+
<Pressable
|
|
47
|
+
key={button.mode}
|
|
48
|
+
testID={testID ? `${testID}-${button.mode}` : undefined}
|
|
49
|
+
accessibilityRole="button"
|
|
50
|
+
accessibilityLabel={button.label}
|
|
51
|
+
onPress={() =>
|
|
52
|
+
setPicker((current) =>
|
|
53
|
+
current === button.mode ? null : button.mode,
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
className={`${largerText ? "h-16" : "h-14"} flex-1 justify-center rounded-lg bg-secondary px-4 active:opacity-70`}
|
|
57
|
+
>
|
|
58
|
+
<Text
|
|
59
|
+
className={`${largerText ? "text-xl" : "text-lg"} font-instrument-sans-semibold text-foreground`}
|
|
60
|
+
>
|
|
61
|
+
{button.label}
|
|
62
|
+
</Text>
|
|
63
|
+
</Pressable>
|
|
64
|
+
))}
|
|
65
|
+
</View>
|
|
66
|
+
{picker ? (
|
|
67
|
+
<DateTimePicker
|
|
68
|
+
value={value}
|
|
69
|
+
mode={picker}
|
|
70
|
+
is24Hour
|
|
71
|
+
maximumDate={picker === "date" ? maximumDate : undefined}
|
|
72
|
+
display={Platform.OS === "ios" ? "spinner" : "default"}
|
|
73
|
+
onChange={handleChange}
|
|
74
|
+
/>
|
|
75
|
+
) : null}
|
|
76
|
+
</View>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ComponentType, ReactNode } from "react";
|
|
2
|
+
import { View, Text } from "react-native";
|
|
3
|
+
import { IconInbox, type IconProps } from "@tabler/icons-react-native";
|
|
4
|
+
import { NEUTRAL_500 } from "./colors";
|
|
5
|
+
import { cn } from "./cn";
|
|
6
|
+
import { useLargerText } from "./theme";
|
|
7
|
+
|
|
8
|
+
export function EmptyState({
|
|
9
|
+
title,
|
|
10
|
+
description,
|
|
11
|
+
icon: Icon = IconInbox,
|
|
12
|
+
action,
|
|
13
|
+
compact = false,
|
|
14
|
+
testID,
|
|
15
|
+
}: {
|
|
16
|
+
title: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
icon?: ComponentType<IconProps>;
|
|
19
|
+
action?: ReactNode;
|
|
20
|
+
compact?: boolean;
|
|
21
|
+
testID?: string;
|
|
22
|
+
}) {
|
|
23
|
+
const largerText = useLargerText();
|
|
24
|
+
return (
|
|
25
|
+
<View
|
|
26
|
+
testID={testID}
|
|
27
|
+
className={`items-center px-4 ${compact ? "py-6" : "py-16"}`}
|
|
28
|
+
>
|
|
29
|
+
<Icon size={largerText ? 44 : 40} color={NEUTRAL_500} />
|
|
30
|
+
<Text
|
|
31
|
+
className={cn(
|
|
32
|
+
"mt-4 text-center font-instrument-sans-semibold text-foreground",
|
|
33
|
+
largerText ? "text-xl" : "text-lg",
|
|
34
|
+
)}
|
|
35
|
+
>
|
|
36
|
+
{title}
|
|
37
|
+
</Text>
|
|
38
|
+
{description ? (
|
|
39
|
+
<Text
|
|
40
|
+
className={cn(
|
|
41
|
+
"mt-2 max-w-sm text-center font-instrument-sans text-muted-foreground",
|
|
42
|
+
largerText ? "text-lg" : "text-base",
|
|
43
|
+
)}
|
|
44
|
+
>
|
|
45
|
+
{description}
|
|
46
|
+
</Text>
|
|
47
|
+
) : null}
|
|
48
|
+
{action ? <View className="mt-6">{action}</View> : null}
|
|
49
|
+
</View>
|
|
50
|
+
);
|
|
51
|
+
}
|