@delacour/react-native-ui 0.6.0-alpha.20261102152310 → 0.6.0-alpha.20261103104147
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/package.json +3 -3
- package/src/components/bottom-sheet/AGENTS.md +2 -1
- package/src/components/bottom-sheet/bottom-sheet.tsx +6 -9
- package/src/components/bottom-sheet/bottom-sheet.variants.test.ts +19 -1
- package/src/components/bottom-sheet/bottom-sheet.variants.ts +4 -1
- package/src/components/select/AGENTS.md +1 -0
- package/src/components/select/select.tsx +26 -6
- package/src/lib/merge-props.test.ts +16 -0
- package/src/lib/merge-props.ts +10 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@delacour/react-native-ui",
|
|
3
|
-
"version": "0.6.0-alpha.
|
|
3
|
+
"version": "0.6.0-alpha.20261103104147",
|
|
4
4
|
"description": "React Native UI components — Uniwind, Reanimated, Gesture Handler",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -181,8 +181,8 @@
|
|
|
181
181
|
"expo-blur": ">=15",
|
|
182
182
|
"@maplibre/maplibre-react-native": "^11.5.0",
|
|
183
183
|
"@central-icons-react-native/round-outlined-radius-1-stroke-1.5": "^1.1",
|
|
184
|
-
"@delacour/react-native-bottom-sheet": "0.6.0-alpha.
|
|
185
|
-
"@delacour/react-native-charts": "0.6.0-alpha.
|
|
184
|
+
"@delacour/react-native-bottom-sheet": "0.6.0-alpha.20261103104147",
|
|
185
|
+
"@delacour/react-native-charts": "0.6.0-alpha.20261103104147",
|
|
186
186
|
"@legendapp/list": ">=3.3",
|
|
187
187
|
"react-native-skia": ">=3.7.3",
|
|
188
188
|
"expo-linear-gradient": ">=15",
|
|
@@ -112,7 +112,8 @@ read those before touching behaviour, because behaviour is not here.
|
|
|
112
112
|
The engine's press handler is donated to the pressable rather than wrapping
|
|
113
113
|
it, because two tap gestures in an ancestor/descendant pair give the touch to
|
|
114
114
|
the descendant and a wrapping trigger never fires. `Close` presses with
|
|
115
|
-
`fade` and
|
|
115
|
+
`fade` and a 12pt slop, for `Badge.CloseButton`'s and `Checkbox`'s reasons:
|
|
116
|
+
a 20pt icon plus 12pt on each side is the 44pt minimum.
|
|
116
117
|
- **The root fills in three defaults.** `bottomInset` is `useSafeAreaInsets().bottom`,
|
|
117
118
|
so the engine reserves the home-indicator band and nobody pads for it by
|
|
118
119
|
hand. `onSnapPointHaptic` is `Presets.System.selection` and `onCloseHaptic` is
|
|
@@ -65,21 +65,18 @@ const closeHaptic = Presets.System.impactLight;
|
|
|
65
65
|
* `topInset` is left at the engine's zero, so a `%` snap point is a fraction of the
|
|
66
66
|
* whole window — the same fraction it was before this rewrite.
|
|
67
67
|
*/
|
|
68
|
-
function BottomSheetRoot({
|
|
69
|
-
bottomInset,
|
|
70
|
-
onSnapPointHaptic = snapPointHaptic,
|
|
71
|
-
onCloseHaptic = closeHaptic,
|
|
72
|
-
...props
|
|
73
|
-
}: BottomSheetProps): ReactElement {
|
|
68
|
+
function BottomSheetRoot({ bottomInset, ...props }: BottomSheetProps): ReactElement {
|
|
74
69
|
const insets = useSafeAreaInsets();
|
|
75
70
|
useKeyboardAnimationGuard();
|
|
76
71
|
|
|
72
|
+
// The haptics go before the spread, not into destructuring defaults: a
|
|
73
|
+
// default also replaces an explicit `undefined`, which is the opt-out.
|
|
77
74
|
return (
|
|
78
75
|
<Headless
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
onSnapPointHaptic={onSnapPointHaptic}
|
|
76
|
+
onCloseHaptic={closeHaptic}
|
|
77
|
+
onSnapPointHaptic={snapPointHaptic}
|
|
82
78
|
{...props}
|
|
79
|
+
bottomInset={bottomInset ?? insets.bottom}
|
|
83
80
|
/>
|
|
84
81
|
);
|
|
85
82
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
2
|
import { resolveSheetBottomInset, resolveSheetScrollEndPadding } from "@delacour/react-native-bottom-sheet/core";
|
|
3
|
-
import { declaredTokens, tokenValue } from "../../styles/theme-tokens.test";
|
|
3
|
+
import { declaredTokens, THEME_CSS, tokenValue } from "../../styles/theme-tokens.test";
|
|
4
|
+
import { ICON_FALLBACK_SIZE_CLASS } from "../icon/icon.variants";
|
|
4
5
|
import {
|
|
5
6
|
BOTTOM_SHEET_BACKDROP_INDICES,
|
|
6
7
|
BOTTOM_SHEET_CLOSE_HIT_SLOP,
|
|
@@ -12,6 +13,17 @@ import {
|
|
|
12
13
|
} from "./bottom-sheet.variants";
|
|
13
14
|
|
|
14
15
|
const LIGHT = declaredTokens("light");
|
|
16
|
+
|
|
17
|
+
/** The smallest touch target the library allows, in points. */
|
|
18
|
+
const MIN_TOUCH_TARGET = 44;
|
|
19
|
+
|
|
20
|
+
/** The pixel edge of the icon `BottomSheet.Close` renders when no size is passed. */
|
|
21
|
+
function fallbackIconEdge(): number {
|
|
22
|
+
const token = ICON_FALLBACK_SIZE_CLASS.replace(/^size-/, "");
|
|
23
|
+
const match = THEME_CSS.match(new RegExp(`--spacing-${token}:\\s*(\\d+)px;`));
|
|
24
|
+
if (!match?.[1]) throw new Error(`no --spacing-${token} in theme.css`);
|
|
25
|
+
return Number(match[1]);
|
|
26
|
+
}
|
|
15
27
|
const DARK = declaredTokens("dark");
|
|
16
28
|
|
|
17
29
|
/** `border-t` and friends set a width, not a colour, and name no token. */
|
|
@@ -244,6 +256,12 @@ describe("bottomSheetVariants slots", () => {
|
|
|
244
256
|
expect(BOTTOM_SHEET_CLOSE_HIT_SLOP).toBeGreaterThan(0);
|
|
245
257
|
});
|
|
246
258
|
|
|
259
|
+
test("the close control's default icon plus its slop reaches the 44pt minimum", () => {
|
|
260
|
+
// The pressable has no padding or size of its own, so the icon and the
|
|
261
|
+
// slop are the whole target.
|
|
262
|
+
expect(fallbackIconEdge() + 2 * BOTTOM_SHEET_CLOSE_HIT_SLOP).toBeGreaterThanOrEqual(MIN_TOUCH_TARGET);
|
|
263
|
+
});
|
|
264
|
+
|
|
247
265
|
test("the grabber is a pill with both dimensions set", () => {
|
|
248
266
|
const indicator = SLOTS.handleIndicator();
|
|
249
267
|
expect(indicator).toMatch(/\bh-[\d.]+\b/);
|
|
@@ -36,8 +36,11 @@ export const BOTTOM_SHEET_BACKDROP_INDICES = { appearsOnIndex: 0, disappearsOnIn
|
|
|
36
36
|
* The glyph is a bare icon in a corner with no padded capsule to absorb the
|
|
37
37
|
* difference against the 44pt minimum — the case `Checkbox` mints slop for and
|
|
38
38
|
* `Badge.CloseButton` does not need.
|
|
39
|
+
*
|
|
40
|
+
* **12** per side: the default icon is 20pt (`size-icon-lg`), and 20 + 2 × 12
|
|
41
|
+
* is the 44pt minimum. The pressable has no padding or size of its own to count.
|
|
39
42
|
*/
|
|
40
|
-
export const BOTTOM_SHEET_CLOSE_HIT_SLOP =
|
|
43
|
+
export const BOTTOM_SHEET_CLOSE_HIT_SLOP = 12;
|
|
41
44
|
|
|
42
45
|
/**
|
|
43
46
|
* The padding a pinned footer's measured box carries.
|
|
@@ -71,6 +71,7 @@ engine. An app that imports no picker still never resolves it.
|
|
|
71
71
|
disables a chosen row for `maxSelected`, or the selection could not be undone.
|
|
72
72
|
A row disabled by the limit with no description of its own says "Limit
|
|
73
73
|
reached" (`limitReachedText`).
|
|
74
|
+
- **`onClose` is the sheet's, not the state's.** It is passed straight to `BottomSheet` and runs once the sheet has finished sliding down, later than `onValueChange` or the open state turning false. Move focus from here, never from the pick.
|
|
74
75
|
- **Multiple never closes on a pick.** A sticky `Done` footer closes it; every
|
|
75
76
|
close path — a pick, Done, a swipe, the overlay, the close button — runs
|
|
76
77
|
through one `handleOpenChange`, which is where the query is cleared.
|
|
@@ -61,6 +61,14 @@ type SelectBaseProps = {
|
|
|
61
61
|
emptyText?: string;
|
|
62
62
|
/** Where the options open. Only `sheet` today. */
|
|
63
63
|
presentation?: SelectPresentation;
|
|
64
|
+
/** Whether the sheet is open. Pair with `onOpenChange` to control it, for a form that opens the select when focus moves to it. */
|
|
65
|
+
isOpen?: boolean;
|
|
66
|
+
/** Whether the sheet starts open, while `isOpen` is left off. @default false */
|
|
67
|
+
defaultOpen?: boolean;
|
|
68
|
+
/** Called with the sheet's next open state, from a press on the trigger, a pick, or any dismissal. */
|
|
69
|
+
onOpenChange?: (isOpen: boolean) => void;
|
|
70
|
+
/** Runs once the sheet has slid fully closed, after any pick or dismissal. */
|
|
71
|
+
onClose?: () => void;
|
|
64
72
|
/** Forwarded to the sheet. Leave it off and the sheet sizes to its rows — or, searchable, opens at its cap and holds it while you type. */
|
|
65
73
|
snapPoints?: BottomSheetProps["snapPoints"];
|
|
66
74
|
/** Custom trigger content for a non-empty selection. */
|
|
@@ -117,6 +125,10 @@ function SelectRoot(props: SelectProps): ReactElement {
|
|
|
117
125
|
isSearchable = false,
|
|
118
126
|
searchPlaceholder = "Search",
|
|
119
127
|
emptyText = "No results",
|
|
128
|
+
onClose,
|
|
129
|
+
isOpen: isOpenProp,
|
|
130
|
+
defaultOpen = false,
|
|
131
|
+
onOpenChange,
|
|
120
132
|
snapPoints,
|
|
121
133
|
renderValue,
|
|
122
134
|
maxLabels,
|
|
@@ -153,20 +165,27 @@ function SelectRoot(props: SelectProps): ReactElement {
|
|
|
153
165
|
value: controlled,
|
|
154
166
|
});
|
|
155
167
|
|
|
156
|
-
const [isOpen, setOpen] =
|
|
168
|
+
const [isOpen, setOpen] = useControllableState<boolean>({
|
|
169
|
+
defaultValue: defaultOpen,
|
|
170
|
+
onChange: onOpenChange,
|
|
171
|
+
value: isOpenProp,
|
|
172
|
+
});
|
|
157
173
|
const [query, setQuery] = useState("");
|
|
158
174
|
const canOpen = !resolvedIsDisabled && !isReadOnly;
|
|
159
175
|
|
|
160
176
|
const open = useCallback(() => {
|
|
161
177
|
if (canOpen) setOpen(true);
|
|
162
|
-
}, [canOpen]);
|
|
178
|
+
}, [canOpen, setOpen]);
|
|
163
179
|
|
|
164
180
|
// One path for every close — a pick, Done, a swipe, the overlay, the close
|
|
165
181
|
// button — and each one clears the search, so the next open starts whole.
|
|
166
|
-
const handleOpenChange = useCallback(
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
182
|
+
const handleOpenChange = useCallback(
|
|
183
|
+
(next: boolean) => {
|
|
184
|
+
setOpen(next);
|
|
185
|
+
if (!next) setQuery("");
|
|
186
|
+
},
|
|
187
|
+
[setOpen]
|
|
188
|
+
);
|
|
170
189
|
const close = useCallback(() => handleOpenChange(false), [handleOpenChange]);
|
|
171
190
|
|
|
172
191
|
const maxSelected = multiple?.maxSelected;
|
|
@@ -308,6 +327,7 @@ function SelectRoot(props: SelectProps): ReactElement {
|
|
|
308
327
|
isOpen={isOpen}
|
|
309
328
|
keyboardLiftLimit="maxDynamicContentSize"
|
|
310
329
|
maxDynamicContentSize={sheetMaxHeight}
|
|
330
|
+
onClose={onClose}
|
|
311
331
|
onOpenChange={handleOpenChange}
|
|
312
332
|
snapPoints={snapPoints}
|
|
313
333
|
>
|
|
@@ -54,6 +54,22 @@ describe("mergeProps", () => {
|
|
|
54
54
|
expect(hit).toBe(true);
|
|
55
55
|
});
|
|
56
56
|
|
|
57
|
+
test("keeps the slot's handler when the child forwards an undefined one", () => {
|
|
58
|
+
// `<Trigger asChild><Button onPress={maybe} /></Trigger>`: an optional
|
|
59
|
+
// handler the child passes on unset must not remove the one the slot donates.
|
|
60
|
+
let hit = false;
|
|
61
|
+
const merged = mergeProps<{ onPress?: () => void }>(
|
|
62
|
+
{
|
|
63
|
+
onPress: () => {
|
|
64
|
+
hit = true;
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
{ onPress: undefined }
|
|
68
|
+
);
|
|
69
|
+
merged.onPress?.();
|
|
70
|
+
expect(hit).toBe(true);
|
|
71
|
+
});
|
|
72
|
+
|
|
57
73
|
test("merges className through cn so the child wins conflicts", () => {
|
|
58
74
|
const merged = mergeProps({ className: "p-2 bg-primary" }, { className: "bg-secondary" });
|
|
59
75
|
expect(merged.className).toBe("p-2 bg-secondary");
|
package/src/lib/merge-props.ts
CHANGED
|
@@ -10,10 +10,12 @@ function isEventHandlerKey(key: string): boolean {
|
|
|
10
10
|
* Merges a slot's own props with those of the element it renders into.
|
|
11
11
|
*
|
|
12
12
|
* Child props win, with three exceptions: event handlers are chained
|
|
13
|
-
* slot-first-then-child so neither side is silently dropped
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
13
|
+
* slot-first-then-child so neither side is silently dropped (a child's unset
|
|
14
|
+
* handler keeps the slot's: `<Button onPress={maybe}>` forwarding `undefined`
|
|
15
|
+
* is not a request to remove one), `className` is merged through
|
|
16
|
+
* {@link cn} so the child's utilities beat conflicting slot ones, and `style`
|
|
17
|
+
* is flattened into an array with the child last (React Native resolves style
|
|
18
|
+
* arrays left to right).
|
|
17
19
|
*/
|
|
18
20
|
export function mergeProps<T extends UnknownProps>(slotProps: UnknownProps, childProps: UnknownProps): T {
|
|
19
21
|
const merged: UnknownProps = { ...slotProps };
|
|
@@ -30,6 +32,10 @@ export function mergeProps<T extends UnknownProps>(slotProps: UnknownProps, chil
|
|
|
30
32
|
continue;
|
|
31
33
|
}
|
|
32
34
|
|
|
35
|
+
if (isEventHandlerKey(key) && typeof slotValue === "function" && childValue == null) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
|
|
33
39
|
if (key === "className") {
|
|
34
40
|
merged[key] = cn(slotValue as string, childValue as string);
|
|
35
41
|
continue;
|