@vvedantb/native-ui 0.24.0 → 0.24.1
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/dist/CaptureButton.jsx +67 -46
- package/dist/Chip.jsx +42 -34
- package/dist/ColorSwatches.jsx +169 -45
- package/dist/Dialog.jsx +16 -3
- package/dist/FloatingFAB.jsx +71 -55
- package/dist/IconButton.jsx +62 -48
- package/dist/PinnedBotTile.jsx +87 -72
- package/dist/SearchInput.jsx +313 -50
- package/dist/ai/card-button.jsx +116 -147
- package/dist/ai/file-chip.jsx +46 -22
- package/dist/pressScale.js +131 -0
- package/dist/primitives/select.jsx +5 -1
- package/package.json +1 -1
- package/src/CaptureButton.tsx +15 -9
- package/src/Chip.tsx +9 -4
- package/src/ColorSwatches.tsx +74 -29
- package/src/Dialog.tsx +16 -7
- package/src/FloatingFAB.tsx +20 -13
- package/src/IconButton.tsx +8 -6
- package/src/PinnedBotTile.tsx +9 -5
- package/src/SearchInput.tsx +40 -12
- package/src/ai/card-button.tsx +17 -11
- package/src/ai/file-chip.tsx +13 -4
- package/src/pressScale.ts +72 -0
- package/src/primitives/select.tsx +7 -2
package/src/SearchInput.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { useWindowDimensions, View } from "react-native";
|
|
3
3
|
import { IconSearch, IconX } from "@tabler/icons-react-native";
|
|
4
4
|
import { Input as PrimitiveInput } from "./primitives/input";
|
|
5
5
|
import { cn } from "./cn";
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
typeStyle,
|
|
14
14
|
type SearchInputSize,
|
|
15
15
|
} from "./controlStyles";
|
|
16
|
+
import { AnimatedPressable, usePressScale } from "./pressScale";
|
|
16
17
|
import { palette } from "./palette";
|
|
17
18
|
import { tokens } from "./tokens";
|
|
18
19
|
import { useLargerText } from "./theme";
|
|
@@ -138,18 +139,13 @@ const SearchInput = React.forwardRef<
|
|
|
138
139
|
className="absolute bottom-0 top-0 justify-center"
|
|
139
140
|
style={{ right: metrics.clearRight }}
|
|
140
141
|
>
|
|
141
|
-
<
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
<ClearButton
|
|
143
|
+
label={clearLabel}
|
|
144
|
+
size={metrics.clear}
|
|
145
|
+
iconSize={metrics.clearIcon}
|
|
146
|
+
color={muted}
|
|
146
147
|
onPress={() => change("")}
|
|
147
|
-
|
|
148
|
-
style={{ width: metrics.clear, height: metrics.clear }}
|
|
149
|
-
>
|
|
150
|
-
{/* `strokeWidth`, not the web `stroke`: here `stroke` is the colour. */}
|
|
151
|
-
<IconX size={metrics.clearIcon} color={muted} strokeWidth={1.75} />
|
|
152
|
-
</Pressable>
|
|
148
|
+
/>
|
|
153
149
|
</View>
|
|
154
150
|
) : null}
|
|
155
151
|
</View>
|
|
@@ -159,5 +155,37 @@ const SearchInput = React.forwardRef<
|
|
|
159
155
|
|
|
160
156
|
SearchInput.displayName = "SearchInput";
|
|
161
157
|
|
|
158
|
+
function ClearButton({
|
|
159
|
+
label,
|
|
160
|
+
size,
|
|
161
|
+
iconSize,
|
|
162
|
+
color,
|
|
163
|
+
onPress,
|
|
164
|
+
}: {
|
|
165
|
+
label: string;
|
|
166
|
+
size: number;
|
|
167
|
+
iconSize: number;
|
|
168
|
+
color: string;
|
|
169
|
+
onPress: () => void;
|
|
170
|
+
}) {
|
|
171
|
+
const press = usePressScale();
|
|
172
|
+
return (
|
|
173
|
+
<AnimatedPressable
|
|
174
|
+
testID="search-input-clear"
|
|
175
|
+
accessibilityRole="button"
|
|
176
|
+
accessibilityLabel={label}
|
|
177
|
+
hitSlop={touchSlop(size)}
|
|
178
|
+
onPress={onPress}
|
|
179
|
+
onPressIn={press.onPressIn}
|
|
180
|
+
onPressOut={press.onPressOut}
|
|
181
|
+
className="items-center justify-center rounded-md"
|
|
182
|
+
style={[{ width: size, height: size }, press.style]}
|
|
183
|
+
>
|
|
184
|
+
{/* `strokeWidth`, not the web `stroke`: here `stroke` is the colour. */}
|
|
185
|
+
<IconX size={iconSize} color={color} strokeWidth={1.75} />
|
|
186
|
+
</AnimatedPressable>
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
162
190
|
export { SearchInput };
|
|
163
191
|
export type { SearchInputProps };
|
package/src/ai/card-button.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Text } from "react-native";
|
|
2
2
|
import { cn } from "../cn";
|
|
3
3
|
import { buttonColors, MIN_TOUCH_TARGET, sizeStyle, touchSlop, typeStyle, type ButtonVariant } from "../controlStyles";
|
|
4
|
+
import { AnimatedPressable, usePressScale } from "../pressScale";
|
|
4
5
|
import { useLargerText } from "../theme";
|
|
5
6
|
import { useScheme } from "../useScheme";
|
|
6
7
|
import { chatTextSize } from "./chat-text";
|
|
@@ -23,8 +24,9 @@ export function CardButton({ label, variant, onPress, disabled, accessibilityLab
|
|
|
23
24
|
const largerText = useLargerText();
|
|
24
25
|
const size = chatTextSize("small", largerText);
|
|
25
26
|
const colors = buttonColors(variant, scheme)!;
|
|
27
|
+
const press = usePressScale({ restOpacity: disabled ? 0.5 : 1, disabled: !!disabled });
|
|
26
28
|
return (
|
|
27
|
-
<
|
|
29
|
+
<AnimatedPressable
|
|
28
30
|
testID={testID}
|
|
29
31
|
accessibilityRole="button"
|
|
30
32
|
accessibilityLabel={accessibilityLabel ?? label}
|
|
@@ -32,18 +34,22 @@ export function CardButton({ label, variant, onPress, disabled, accessibilityLab
|
|
|
32
34
|
disabled={disabled}
|
|
33
35
|
onPress={onPress}
|
|
34
36
|
hitSlop={touchSlop(MIN_TOUCH_TARGET)}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
onPressIn={press.onPressIn}
|
|
38
|
+
onPressOut={press.onPressOut}
|
|
39
|
+
className="items-center justify-center rounded-full border px-4"
|
|
40
|
+
style={[
|
|
41
|
+
{
|
|
42
|
+
minHeight: MIN_TOUCH_TARGET,
|
|
43
|
+
minWidth: MIN_TOUCH_TARGET,
|
|
44
|
+
backgroundColor: colors.backgroundColor,
|
|
45
|
+
borderColor: colors.borderColor,
|
|
46
|
+
},
|
|
47
|
+
press.style,
|
|
48
|
+
]}
|
|
43
49
|
>
|
|
44
50
|
<Text className={cn(size, "font-instrument-sans-semibold")} style={[sizeStyle(size), typeStyle("semibold"), { color: colors.color }]}>
|
|
45
51
|
{label}
|
|
46
52
|
</Text>
|
|
47
|
-
</
|
|
53
|
+
</AnimatedPressable>
|
|
48
54
|
);
|
|
49
55
|
}
|
package/src/ai/file-chip.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Text, View } from "react-native";
|
|
2
2
|
import { IconFile } from "@tabler/icons-react-native";
|
|
3
3
|
import { cn } from "../cn";
|
|
4
4
|
import { MIN_TOUCH_TARGET, sizeStyle, textStyle, touchSlop } from "../controlStyles";
|
|
5
|
+
import { AnimatedPressable, usePressScale } from "../pressScale";
|
|
5
6
|
import { palette } from "../palette";
|
|
6
7
|
import { useLargerText } from "../theme";
|
|
7
8
|
import { tokens } from "../tokens";
|
|
@@ -51,16 +52,24 @@ export type FileChipProps = {
|
|
|
51
52
|
*/
|
|
52
53
|
export function FileChip({ name, path, onOpenFile }: FileChipProps) {
|
|
53
54
|
if (!path || !onOpenFile) return <FileChipLabel name={name} />;
|
|
55
|
+
return <FileChipButton name={name} path={path} onOpenFile={onOpenFile} />;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function FileChipButton({ name, path, onOpenFile }: { name: string; path: string; onOpenFile: (path: string) => void }) {
|
|
59
|
+
const press = usePressScale();
|
|
54
60
|
return (
|
|
55
|
-
<
|
|
61
|
+
<AnimatedPressable
|
|
56
62
|
accessibilityRole="button"
|
|
57
63
|
accessibilityLabel={name}
|
|
58
64
|
accessibilityHint={path}
|
|
59
65
|
hitSlop={touchSlop(MIN_TOUCH_TARGET, CHIP_HEIGHT)}
|
|
60
66
|
onPress={() => onOpenFile(path)}
|
|
61
|
-
|
|
67
|
+
onPressIn={press.onPressIn}
|
|
68
|
+
onPressOut={press.onPressOut}
|
|
69
|
+
style={press.style}
|
|
70
|
+
className="min-w-0 max-w-full"
|
|
62
71
|
>
|
|
63
72
|
<FileChipLabel name={name} />
|
|
64
|
-
</
|
|
73
|
+
</AnimatedPressable>
|
|
65
74
|
);
|
|
66
75
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { cssInterop } from "nativewind";
|
|
2
|
+
import { useCallback, useEffect } from "react";
|
|
3
|
+
import { Pressable } from "react-native";
|
|
4
|
+
import Animated, { useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated";
|
|
5
|
+
import { EASE_OUT } from "./motion";
|
|
6
|
+
import { useReduceMotion } from "./useReduceMotion";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A `Pressable` whose `style` can take the style from `usePressScale`.
|
|
10
|
+
* NativeWind maps `className` only for components it knows, so it is told
|
|
11
|
+
* about this one, or the classes would be dropped.
|
|
12
|
+
*/
|
|
13
|
+
export const AnimatedPressable = Animated.createAnimatedComponent(Pressable);
|
|
14
|
+
cssInterop(AnimatedPressable, { className: "style" });
|
|
15
|
+
|
|
16
|
+
export type PressScaleOptions = {
|
|
17
|
+
/** Scale while pressed. Default 0.97. */
|
|
18
|
+
scale?: number;
|
|
19
|
+
/** Opacity while pressed, a light dim. Default 0.7, the dim these controls had before the scale. */
|
|
20
|
+
dim?: number;
|
|
21
|
+
/** Dim used instead under Reduce Motion. Default `dim`. */
|
|
22
|
+
reducedDim?: number;
|
|
23
|
+
/** Opacity at rest, such as 0.5 when disabled. The press dims from here. Default 1. */
|
|
24
|
+
restOpacity?: number;
|
|
25
|
+
/** Press-in duration in ms. Default 120. */
|
|
26
|
+
pressInMs?: number;
|
|
27
|
+
/** Release duration in ms. Default 160. */
|
|
28
|
+
pressOutMs?: number;
|
|
29
|
+
/** A disabled control lets go at once, so it cannot stay pressed. */
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Press feedback for a small control: a scale and a light dim that ease in on
|
|
35
|
+
* press-in and ease back on release. Pass `onPressIn` and `onPressOut` to the
|
|
36
|
+
* `Pressable` and `style` to the animated view that should scale (an
|
|
37
|
+
* `AnimatedPressable`, or an `Animated.View` inside the `Pressable`). One
|
|
38
|
+
* shared value on the UI thread drives transform and opacity only. A new press
|
|
39
|
+
* or release starts from the current value, so a fast tap never sticks. With
|
|
40
|
+
* Reduce Motion nothing animates and nothing scales: the dim switches on and
|
|
41
|
+
* off at once.
|
|
42
|
+
*/
|
|
43
|
+
export function usePressScale({
|
|
44
|
+
scale = 0.97,
|
|
45
|
+
dim = 0.7,
|
|
46
|
+
reducedDim = dim,
|
|
47
|
+
restOpacity = 1,
|
|
48
|
+
pressInMs = 120,
|
|
49
|
+
pressOutMs = 160,
|
|
50
|
+
disabled = false,
|
|
51
|
+
}: PressScaleOptions = {}) {
|
|
52
|
+
const reduceMotion = useReduceMotion();
|
|
53
|
+
const progress = useSharedValue(0);
|
|
54
|
+
const target = reduceMotion ? reducedDim : dim;
|
|
55
|
+
const onPressIn = useCallback(() => {
|
|
56
|
+
progress.set(reduceMotion ? 1 : withTiming(1, { duration: pressInMs, easing: EASE_OUT }));
|
|
57
|
+
}, [progress, reduceMotion, pressInMs]);
|
|
58
|
+
const onPressOut = useCallback(() => {
|
|
59
|
+
progress.set(reduceMotion ? 0 : withTiming(0, { duration: pressOutMs, easing: EASE_OUT }));
|
|
60
|
+
}, [progress, reduceMotion, pressOutMs]);
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (disabled) progress.set(0);
|
|
63
|
+
}, [disabled, progress]);
|
|
64
|
+
const style = useAnimatedStyle(() => {
|
|
65
|
+
const p = progress.get();
|
|
66
|
+
return {
|
|
67
|
+
opacity: restOpacity * (1 - p * (1 - target)),
|
|
68
|
+
transform: [{ scale: reduceMotion ? 1 : 1 - p * (1 - scale) }],
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
return { style, onPressIn, onPressOut };
|
|
72
|
+
}
|
|
@@ -5,6 +5,7 @@ import { IconCheck, IconChevronDown, IconChevronUp } from "@tabler/icons-react-n
|
|
|
5
5
|
import * as React from "react";
|
|
6
6
|
import { Platform, ScrollView, StyleSheet, Text, View } from "react-native";
|
|
7
7
|
import { FadeIn, FadeOut } from "react-native-reanimated";
|
|
8
|
+
import { EASE_OUT } from "../motion";
|
|
8
9
|
import { NativeOnlyAnimatedView } from "./native-only-animated-view";
|
|
9
10
|
import { SelectHost } from "./select-host";
|
|
10
11
|
import { TextClassContext } from "./text";
|
|
@@ -80,6 +81,10 @@ type SelectContentProps = React.ComponentPropsWithoutRef<
|
|
|
80
81
|
portalHost?: string;
|
|
81
82
|
};
|
|
82
83
|
|
|
84
|
+
/** The popover fades in and out on the strong ease-out. */
|
|
85
|
+
const SELECT_ENTER = FadeIn.duration(150).easing(EASE_OUT);
|
|
86
|
+
const SELECT_EXIT = FadeOut.duration(100).easing(EASE_OUT);
|
|
87
|
+
|
|
83
88
|
const SelectContent = React.forwardRef<
|
|
84
89
|
React.ElementRef<typeof SelectPrimitive.Content>,
|
|
85
90
|
SelectContentProps
|
|
@@ -89,8 +94,8 @@ const SelectContent = React.forwardRef<
|
|
|
89
94
|
<SelectPrimitive.Overlay style={overlayFill}>
|
|
90
95
|
<TextClassContext.Provider value="text-popover-foreground">
|
|
91
96
|
<NativeOnlyAnimatedView
|
|
92
|
-
entering={
|
|
93
|
-
exiting={
|
|
97
|
+
entering={SELECT_ENTER}
|
|
98
|
+
exiting={SELECT_EXIT}
|
|
94
99
|
className="z-50"
|
|
95
100
|
// Content is absolutely positioned, so a bare wrapper has zero height
|
|
96
101
|
// and UI tests drop its children as invisible. Fill the overlay and
|