@knitui/components 0.12.1 → 0.13.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/lib/commonjs/Avatar/Avatar.js +4 -0
- package/lib/commonjs/Avatar/Avatar.js.map +1 -1
- package/lib/commonjs/Card/Card.js +8 -3
- package/lib/commonjs/Card/Card.js.map +1 -1
- package/lib/commonjs/Image/createImage.js +75 -2
- package/lib/commonjs/Image/createImage.js.map +1 -1
- package/lib/commonjs/Input/Input.js +14 -0
- package/lib/commonjs/Input/Input.js.map +1 -1
- package/lib/commonjs/Input/Input.native.js +13 -1
- package/lib/commonjs/Input/Input.native.js.map +1 -1
- package/lib/commonjs/Input/shared.js +54 -11
- package/lib/commonjs/Input/shared.js.map +1 -1
- package/lib/commonjs/NativeSelect/NativeSelect.js +11 -0
- package/lib/commonjs/NativeSelect/NativeSelect.js.map +1 -1
- package/lib/commonjs/PinInput/PinInput.js +59 -11
- package/lib/commonjs/PinInput/PinInput.js.map +1 -1
- package/lib/commonjs/SimpleGrid/SimpleGrid.js +47 -27
- package/lib/commonjs/SimpleGrid/SimpleGrid.js.map +1 -1
- package/lib/commonjs/Tabs/Tabs.js +56 -11
- package/lib/commonjs/Tabs/Tabs.js.map +1 -1
- package/lib/commonjs/Transition/Transition.native.js +33 -16
- package/lib/commonjs/Transition/Transition.native.js.map +1 -1
- package/lib/module/Avatar/Avatar.js +4 -0
- package/lib/module/Avatar/Avatar.js.map +1 -1
- package/lib/module/Card/Card.js +8 -3
- package/lib/module/Card/Card.js.map +1 -1
- package/lib/module/Image/createImage.js +74 -1
- package/lib/module/Image/createImage.js.map +1 -1
- package/lib/module/Input/Input.js +15 -1
- package/lib/module/Input/Input.js.map +1 -1
- package/lib/module/Input/Input.native.js +14 -2
- package/lib/module/Input/Input.native.js.map +1 -1
- package/lib/module/Input/shared.js +53 -11
- package/lib/module/Input/shared.js.map +1 -1
- package/lib/module/NativeSelect/NativeSelect.js +12 -1
- package/lib/module/NativeSelect/NativeSelect.js.map +1 -1
- package/lib/module/PinInput/PinInput.js +61 -13
- package/lib/module/PinInput/PinInput.js.map +1 -1
- package/lib/module/SimpleGrid/SimpleGrid.js +48 -28
- package/lib/module/SimpleGrid/SimpleGrid.js.map +1 -1
- package/lib/module/Tabs/Tabs.js +56 -11
- package/lib/module/Tabs/Tabs.js.map +1 -1
- package/lib/module/Transition/Transition.native.js +33 -16
- package/lib/module/Transition/Transition.native.js.map +1 -1
- package/lib/typescript/Avatar/Avatar.d.ts.map +1 -1
- package/lib/typescript/Card/Card.d.ts.map +1 -1
- package/lib/typescript/Image/createImage.d.ts.map +1 -1
- package/lib/typescript/Input/Input.d.ts.map +1 -1
- package/lib/typescript/Input/Input.native.d.ts.map +1 -1
- package/lib/typescript/Input/shared.d.ts +22 -7
- package/lib/typescript/Input/shared.d.ts.map +1 -1
- package/lib/typescript/NativeSelect/NativeSelect.d.ts.map +1 -1
- package/lib/typescript/PinInput/PinInput.d.ts +9 -0
- package/lib/typescript/PinInput/PinInput.d.ts.map +1 -1
- package/lib/typescript/SimpleGrid/SimpleGrid.d.ts +10 -4
- package/lib/typescript/SimpleGrid/SimpleGrid.d.ts.map +1 -1
- package/lib/typescript/Tabs/Tabs.d.ts.map +1 -1
- package/lib/typescript/Transition/Transition.native.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/Avatar/Avatar.tsx +4 -0
- package/src/Card/Card.tsx +12 -5
- package/src/Image/createImage.tsx +85 -1
- package/src/Input/Input.native.tsx +13 -0
- package/src/Input/Input.tsx +15 -0
- package/src/Input/shared.tsx +62 -11
- package/src/NativeSelect/NativeSelect.tsx +12 -0
- package/src/PinInput/PinInput.tsx +72 -8
- package/src/SimpleGrid/SimpleGrid.tsx +42 -20
- package/src/Tabs/Tabs.tsx +67 -13
- package/src/Transition/Transition.native.tsx +36 -20
package/src/Input/shared.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
|
|
3
3
|
import type { GetProps, TamaguiElement } from "@knitui/core";
|
|
4
|
-
import {
|
|
4
|
+
import { getTokenValue, styled, Theme } from "@knitui/core";
|
|
5
5
|
import { useCallbackRef, useId } from "@knitui/hooks";
|
|
6
6
|
|
|
7
7
|
import { Box } from "../Box";
|
|
@@ -185,49 +185,51 @@ export const getTextareaPaddingVertical = (size: InputSize | undefined): number
|
|
|
185
185
|
// field grows. Without it Tamagui's font pairing resolves the SAME line height
|
|
186
186
|
// (the `md` step, 27px) for every `fontSize` token, so changing `size` only changed
|
|
187
187
|
// the text size while the box height stayed put — i.e. `size` looked ignored on web.
|
|
188
|
-
//
|
|
189
|
-
//
|
|
190
|
-
//
|
|
188
|
+
// It names the line-height TOKEN of the same step as the clamped per-size
|
|
189
|
+
// `fontSize` (the value `getLineHeight` computes, `round(fontSize × ratio)`), so it
|
|
190
|
+
// matches the native host's `getNativeLineHeight` and a textarea row is the same
|
|
191
|
+
// height on web, iOS and Android — and, being a token, it is `rem` on the web, so
|
|
192
|
+
// browser text zoom grows the line box together with the text.
|
|
191
193
|
const textareaHostSizeVariant = {
|
|
192
194
|
xxs: {
|
|
193
195
|
fontSize: M.xxs.fontSize,
|
|
194
|
-
lineHeight:
|
|
196
|
+
lineHeight: M.xxs.fontSize,
|
|
195
197
|
paddingHorizontal: M.xxs.paddingHorizontal,
|
|
196
198
|
paddingVertical: TEXTAREA_INSET_TOKEN.xxs,
|
|
197
199
|
},
|
|
198
200
|
xs: {
|
|
199
201
|
fontSize: M.xs.fontSize,
|
|
200
|
-
lineHeight:
|
|
202
|
+
lineHeight: M.xs.fontSize,
|
|
201
203
|
paddingHorizontal: M.xs.paddingHorizontal,
|
|
202
204
|
paddingVertical: TEXTAREA_INSET_TOKEN.xs,
|
|
203
205
|
},
|
|
204
206
|
sm: {
|
|
205
207
|
fontSize: M.sm.fontSize,
|
|
206
|
-
lineHeight:
|
|
208
|
+
lineHeight: M.sm.fontSize,
|
|
207
209
|
paddingHorizontal: M.sm.paddingHorizontal,
|
|
208
210
|
paddingVertical: TEXTAREA_INSET_TOKEN.sm,
|
|
209
211
|
},
|
|
210
212
|
md: {
|
|
211
213
|
fontSize: M.md.fontSize,
|
|
212
|
-
lineHeight:
|
|
214
|
+
lineHeight: M.md.fontSize,
|
|
213
215
|
paddingHorizontal: M.md.paddingHorizontal,
|
|
214
216
|
paddingVertical: TEXTAREA_INSET_TOKEN.md,
|
|
215
217
|
},
|
|
216
218
|
lg: {
|
|
217
219
|
fontSize: M.lg.fontSize,
|
|
218
|
-
lineHeight:
|
|
220
|
+
lineHeight: M.lg.fontSize,
|
|
219
221
|
paddingHorizontal: M.lg.paddingHorizontal,
|
|
220
222
|
paddingVertical: TEXTAREA_INSET_TOKEN.lg,
|
|
221
223
|
},
|
|
222
224
|
xl: {
|
|
223
225
|
fontSize: M.xl.fontSize,
|
|
224
|
-
lineHeight:
|
|
226
|
+
lineHeight: M.xl.fontSize,
|
|
225
227
|
paddingHorizontal: M.xl.paddingHorizontal,
|
|
226
228
|
paddingVertical: TEXTAREA_INSET_TOKEN.xl,
|
|
227
229
|
},
|
|
228
230
|
xxl: {
|
|
229
231
|
fontSize: M.xxl.fontSize,
|
|
230
|
-
lineHeight:
|
|
232
|
+
lineHeight: M.xxl.fontSize,
|
|
231
233
|
paddingHorizontal: M.xxl.paddingHorizontal,
|
|
232
234
|
paddingVertical: TEXTAREA_INSET_TOKEN.xxl,
|
|
233
235
|
},
|
|
@@ -433,6 +435,55 @@ const getSectionContent = (options: SectionContentOptions) => {
|
|
|
433
435
|
return section ?? (position === "right" ? defaultSection : null);
|
|
434
436
|
};
|
|
435
437
|
|
|
438
|
+
type InputSectionInsetOptions = Pick<
|
|
439
|
+
InputChromeProps,
|
|
440
|
+
| "leftSection"
|
|
441
|
+
| "rightSection"
|
|
442
|
+
| "loading"
|
|
443
|
+
| "loadingPosition"
|
|
444
|
+
| "__clearSection"
|
|
445
|
+
| "__clearable"
|
|
446
|
+
| "__clearSectionMode"
|
|
447
|
+
| "__defaultRightSection"
|
|
448
|
+
>;
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Host padding overrides for the sides that carry an adornment section.
|
|
452
|
+
*
|
|
453
|
+
* A section is a control-height square with its content centered, so it already
|
|
454
|
+
* holds the content→edge gap on BOTH of its sides (`(height − icon) / 2`). The
|
|
455
|
+
* host's own `paddingHorizontal` on that side would stack on top of it and push
|
|
456
|
+
* the text ~2.5× further from the icon than the icon sits from the border, so it
|
|
457
|
+
* is zeroed there. Resolved through `getSectionContent` — the same rule
|
|
458
|
+
* `InputChrome` renders by — so the inset can't drift from what is on screen.
|
|
459
|
+
*/
|
|
460
|
+
export const getInputSectionInsets = (
|
|
461
|
+
options: InputSectionInsetOptions,
|
|
462
|
+
): { paddingLeft?: 0; paddingRight?: 0 } => {
|
|
463
|
+
const { loading = false, loadingPosition = "right" } = options;
|
|
464
|
+
const left = getSectionContent({
|
|
465
|
+
loading,
|
|
466
|
+
loadingPosition,
|
|
467
|
+
position: "left",
|
|
468
|
+
section: options.leftSection,
|
|
469
|
+
});
|
|
470
|
+
const right = getSectionContent({
|
|
471
|
+
loading,
|
|
472
|
+
loadingPosition,
|
|
473
|
+
position: "right",
|
|
474
|
+
section: options.rightSection,
|
|
475
|
+
clearSection: options.__clearSection,
|
|
476
|
+
clearable: options.__clearable,
|
|
477
|
+
clearSectionMode: options.__clearSectionMode,
|
|
478
|
+
defaultSection: options.__defaultRightSection,
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
return {
|
|
482
|
+
...(left ? { paddingLeft: 0 as const } : null),
|
|
483
|
+
...(right ? { paddingRight: 0 as const } : null),
|
|
484
|
+
};
|
|
485
|
+
};
|
|
486
|
+
|
|
436
487
|
const getSectionPointerEvents = (
|
|
437
488
|
value: InputSectionPointerEvents,
|
|
438
489
|
): InputSectionFrameProps["sectionPointerEvents"] => (value === "all" ? "all" : "none");
|
|
@@ -4,6 +4,7 @@ import { isWeb, registerFocusable, styled, type TamaguiElement, useWebRef } from
|
|
|
4
4
|
|
|
5
5
|
import { Combobox } from "../Combobox";
|
|
6
6
|
import {
|
|
7
|
+
getInputSectionInsets,
|
|
7
8
|
INPUT_CHROME_SLOTS,
|
|
8
9
|
InputChrome,
|
|
9
10
|
inputHostSizeVariant,
|
|
@@ -247,6 +248,17 @@ const NativeSelectControl = React.forwardRef<NativeSelectRef, NativeSelectContro
|
|
|
247
248
|
flex={1}
|
|
248
249
|
minWidth={0}
|
|
249
250
|
size={effectiveSize}
|
|
251
|
+
{...getInputSectionInsets({
|
|
252
|
+
leftSection,
|
|
253
|
+
rightSection,
|
|
254
|
+
loading,
|
|
255
|
+
loadingPosition,
|
|
256
|
+
__clearSection,
|
|
257
|
+
__clearable,
|
|
258
|
+
__clearSectionMode,
|
|
259
|
+
// The chevron is always there unless a section replaces it.
|
|
260
|
+
__defaultRightSection: true,
|
|
261
|
+
})}
|
|
250
262
|
{...selectHostProps}
|
|
251
263
|
style={mergedStyle}
|
|
252
264
|
>
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
|
|
3
|
-
import { type GetProps, styled, withStaticProperties } from "@knitui/core";
|
|
3
|
+
import { type GetProps, isAndroid, styled, withStaticProperties } from "@knitui/core";
|
|
4
4
|
import { useCallbackRef, useId, useMergedRef, useUncontrolled } from "@knitui/hooks";
|
|
5
5
|
|
|
6
6
|
import { Box } from "../Box";
|
|
7
7
|
import { Input, type InputProps, type InputSize } from "../Input";
|
|
8
|
+
import { HiddenInput } from "../internal/hidden-input";
|
|
8
9
|
import { gapVariant, type SizeKey, squareSizeVariant } from "../internal/style-props";
|
|
9
10
|
import { slotStyles, type SlotStyles } from "../internal/styles";
|
|
10
11
|
|
|
@@ -94,6 +95,20 @@ export interface PinInputStyles {
|
|
|
94
95
|
|
|
95
96
|
const PIN_INPUT_SLOT_KEYS = ["field"] as const satisfies readonly (keyof PinInputStyles)[];
|
|
96
97
|
|
|
98
|
+
/**
|
|
99
|
+
* What a focused EMPTY field holds on Android: a zero-width space.
|
|
100
|
+
*
|
|
101
|
+
* Android's soft keyboards (Gboard) send no key event for Backspace in an empty
|
|
102
|
+
* `EditText`, and with nothing to delete there is no text change either, so the
|
|
103
|
+
* field never hears the press: a wrong digit could not be walked back to with
|
|
104
|
+
* the keyboard at all (measured on an emulator: three digits in, Backspace in
|
|
105
|
+
* the fourth field did nothing). With one invisible character in the field,
|
|
106
|
+
* Backspace has something to delete, `onChangeText("")` arrives, and
|
|
107
|
+
* `handleChange` reads it as "Backspace in an empty field". Only the focused
|
|
108
|
+
* field carries it, so placeholders and the reported value are untouched.
|
|
109
|
+
*/
|
|
110
|
+
const EMPTY_SENTINEL = "\u200B";
|
|
111
|
+
|
|
97
112
|
export interface PinInputProps extends Omit<
|
|
98
113
|
PinInputRowProps,
|
|
99
114
|
"onChange" | "children" | "mask" | "inputMode" | "size"
|
|
@@ -161,6 +176,17 @@ export interface PinInputProps extends Omit<
|
|
|
161
176
|
/** Base id used to generate per-input ids. */
|
|
162
177
|
id?: string;
|
|
163
178
|
|
|
179
|
+
/**
|
|
180
|
+
* Web only: form field name. When set, one `<input type="hidden">` carries the
|
|
181
|
+
* joined code, so a surrounding `<form>` (and password managers / one-time-code
|
|
182
|
+
* autofill, which look for a single named field) see the whole value. The
|
|
183
|
+
* per-character boxes themselves stay nameless. Ignored on native.
|
|
184
|
+
*/
|
|
185
|
+
name?: string;
|
|
186
|
+
|
|
187
|
+
/** Web only: id of the `<form>` the hidden `name` input belongs to. */
|
|
188
|
+
form?: string;
|
|
189
|
+
|
|
164
190
|
/** Props applied to each input, by index. */
|
|
165
191
|
getInputProps?: (index: number) => Partial<InputProps>;
|
|
166
192
|
|
|
@@ -174,8 +200,9 @@ export interface PinInputProps extends Omit<
|
|
|
174
200
|
* (`mask` → `type="password"` → native `secureTextEntry`) and focus advance work
|
|
175
201
|
* cross-platform. Accent/theme comes from the Tamagui `theme` prop + palette ramp.
|
|
176
202
|
*
|
|
177
|
-
* Web
|
|
178
|
-
*
|
|
203
|
+
* Web forms: `name` (and `form`) render one hidden input carrying the joined code.
|
|
204
|
+
* Multi-field paste distribution is deferred; single-field paste of a full code is
|
|
205
|
+
* handled.
|
|
179
206
|
*/
|
|
180
207
|
const PinInputComponent = PinInputRow.styleable<PinInputProps>(function PinInput(props, ref) {
|
|
181
208
|
const {
|
|
@@ -200,6 +227,8 @@ const PinInputComponent = PinInputRow.styleable<PinInputProps>(function PinInput
|
|
|
200
227
|
oneTimeCode = true,
|
|
201
228
|
ariaLabel = "PinInput",
|
|
202
229
|
id,
|
|
230
|
+
name,
|
|
231
|
+
form,
|
|
203
232
|
getInputProps,
|
|
204
233
|
styles,
|
|
205
234
|
...others
|
|
@@ -242,7 +271,23 @@ const PinInputComponent = PinInputRow.styleable<PinInputProps>(function PinInput
|
|
|
242
271
|
// Event handlers keep a STABLE identity across renders (so per-field props and
|
|
243
272
|
// ref callbacks below never churn) while always reading the latest state via
|
|
244
273
|
// `useCallbackRef`. No manual dependency lists, no stale closures.
|
|
245
|
-
const handleChange = useCallbackRef((
|
|
274
|
+
const handleChange = useCallbackRef((raw: string, index: number) => {
|
|
275
|
+
// Android: the focused empty field holds `EMPTY_SENTINEL` (see there).
|
|
276
|
+
const text = raw.split(EMPTY_SENTINEL).join("");
|
|
277
|
+
if (isAndroid && raw === "" && (currentValue[index] ?? "") === "") {
|
|
278
|
+
// The sentinel itself was deleted: Backspace in an EMPTY field. Step back
|
|
279
|
+
// and clear the previous character, as a hardware Backspace does on web.
|
|
280
|
+
if (index > 0) {
|
|
281
|
+
const next = [...currentValue];
|
|
282
|
+
next[index - 1] = "";
|
|
283
|
+
setValues(next);
|
|
284
|
+
if (manageFocus) inputsRef.current[index - 1]?.focus?.();
|
|
285
|
+
} else {
|
|
286
|
+
// Nowhere to go: a new array re-asserts the sentinel in this field.
|
|
287
|
+
setValues([...currentValue]);
|
|
288
|
+
}
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
246
291
|
const setFieldValue = (val: string) => {
|
|
247
292
|
const next = [...currentValue];
|
|
248
293
|
next[index] = val;
|
|
@@ -332,6 +377,8 @@ const PinInputComponent = PinInputRow.styleable<PinInputProps>(function PinInput
|
|
|
332
377
|
[inputMode, type],
|
|
333
378
|
);
|
|
334
379
|
|
|
380
|
+
const perField = (index: number) => getInputProps?.(index);
|
|
381
|
+
|
|
335
382
|
return (
|
|
336
383
|
<PinInputRow gap={gap} {...others}>
|
|
337
384
|
{fields.map((field, index) => (
|
|
@@ -348,7 +395,10 @@ const PinInputComponent = PinInputRow.styleable<PinInputProps>(function PinInput
|
|
|
348
395
|
inputMode={resolvedInputMode}
|
|
349
396
|
textAlign="center"
|
|
350
397
|
paddingHorizontal={0}
|
|
351
|
-
value={
|
|
398
|
+
value={
|
|
399
|
+
(currentValue[index] ?? "") ||
|
|
400
|
+
(isAndroid && focusedIndex === index ? EMPTY_SENTINEL : "")
|
|
401
|
+
}
|
|
352
402
|
placeholder={focusedIndex === index ? "" : placeholder}
|
|
353
403
|
autoFocus={autoFocus && index === 0}
|
|
354
404
|
autoComplete={oneTimeCode ? "one-time-code" : "off"}
|
|
@@ -356,14 +406,28 @@ const PinInputComponent = PinInputRow.styleable<PinInputProps>(function PinInput
|
|
|
356
406
|
wrapperProps={wrapperProps}
|
|
357
407
|
onChangeText={field.onChangeText}
|
|
358
408
|
onKeyDown={field.onKeyDown}
|
|
359
|
-
onFocus={field.onFocus}
|
|
360
|
-
onBlur={field.onBlur}
|
|
361
409
|
// The `field` style slot is sugar under the per-index `getInputProps`,
|
|
362
410
|
// which is more explicit and wins where the two overlap.
|
|
363
411
|
{...s.get("field")}
|
|
364
|
-
{...
|
|
412
|
+
{...perField(index)}
|
|
413
|
+
// After the spreads: a consumer's `onFocus`/`onBlur` is CALLED, never a
|
|
414
|
+
// replacement. The row needs its own to know which field has the caret.
|
|
415
|
+
onFocus={(event: unknown) => {
|
|
416
|
+
field.onFocus();
|
|
417
|
+
(perField(index)?.onFocus as ((e: unknown) => void) | undefined)?.(event);
|
|
418
|
+
}}
|
|
419
|
+
onBlur={(event: unknown) => {
|
|
420
|
+
field.onBlur();
|
|
421
|
+
(perField(index)?.onBlur as ((e: unknown) => void) | undefined)?.(event);
|
|
422
|
+
}}
|
|
365
423
|
/>
|
|
366
424
|
))}
|
|
425
|
+
<HiddenInput
|
|
426
|
+
name={name}
|
|
427
|
+
form={form}
|
|
428
|
+
disabled={disabled}
|
|
429
|
+
value={currentValue.join("").trim()}
|
|
430
|
+
/>
|
|
367
431
|
</PinInputRow>
|
|
368
432
|
);
|
|
369
433
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
|
|
3
|
-
import { type GetProps, getTokenValue, type SpaceTokens, styled } from "@knitui/core";
|
|
3
|
+
import { type GetProps, getTokenValue, isWeb, type SpaceTokens, styled } from "@knitui/core";
|
|
4
4
|
|
|
5
5
|
import { Box, type BoxProps } from "../Box";
|
|
6
6
|
import { slotStyles, type SlotStyles } from "../internal/styles";
|
|
@@ -34,12 +34,18 @@ const resolveSpacing = (spacing: SimpleGridSpacing): number => {
|
|
|
34
34
|
* Equal-width column grid — mirrors Mantine's `SimpleGrid` (every column the same
|
|
35
35
|
* width, unlike `Grid`'s 12-column spans). Cross-platform: there is no CSS grid on
|
|
36
36
|
* native, so each child is wrapped in a cell `Box` and laid out with a flex-wrap
|
|
37
|
-
* row
|
|
37
|
+
* row. Rows are spaced with `rowGap`. The grid never reaches past its own box (no
|
|
38
|
+
* negative-margin track), so it cannot overflow a fixed-width scrolling parent.
|
|
38
39
|
*
|
|
39
40
|
* Two modes:
|
|
40
|
-
* - default `cols` mode — N equal columns (`width: 100/cols %`).
|
|
41
|
-
*
|
|
42
|
-
*
|
|
41
|
+
* - default `cols` mode — N equal columns (`width: 100/cols %`). The column gap
|
|
42
|
+
* is split across each cell's inline padding by column index (column `c` of
|
|
43
|
+
* `N` gets `c·g/N` before and `(N-1-c)·g/N` after), so every column's content
|
|
44
|
+
* is equally wide, adjacent columns sit exactly `g` apart, and the outer
|
|
45
|
+
* columns are flush with the grid's edges.
|
|
46
|
+
* - `minColWidth` mode — columns auto-fill at ≥ that width (`flexBasis`/`minWidth`
|
|
47
|
+
* less one gap, plus `columnGap`), a cross-platform approximation of CSS
|
|
48
|
+
* `repeat(auto-fill/fit, minmax(min, 1fr))`.
|
|
43
49
|
*
|
|
44
50
|
* Responsive per-breakpoint values are intentionally deferred (single values only),
|
|
45
51
|
* matching `Grid`. Accent/theme is inherited; no Mantine `color` prop.
|
|
@@ -93,9 +99,20 @@ const SIMPLE_GRID_SLOT_KEYS = ["cell"] as const satisfies readonly (keyof Simple
|
|
|
93
99
|
/** Cell layout narrowed to the exact Box style props it targets. */
|
|
94
100
|
type CellLayout = Pick<
|
|
95
101
|
BoxProps,
|
|
96
|
-
"width" | "flexBasis" | "flexGrow" | "minWidth" | "
|
|
102
|
+
"width" | "flexBasis" | "flexGrow" | "minWidth" | "paddingLeft" | "paddingRight"
|
|
97
103
|
>;
|
|
98
104
|
|
|
105
|
+
/**
|
|
106
|
+
* `minColWidth` less one column gap, so a cell plus its trailing gap packs like
|
|
107
|
+
* the old half-gap-padded cell did (same column count and content width).
|
|
108
|
+
*/
|
|
109
|
+
const minLessGap = (min: number | string, gap: number): BoxProps["flexBasis"] => {
|
|
110
|
+
if (typeof min === "number") return Math.max(0, min - gap);
|
|
111
|
+
if (!gap) return min as BoxProps["flexBasis"];
|
|
112
|
+
// Web resolves the subtraction in CSS; native takes the string as given.
|
|
113
|
+
return (isWeb ? `calc(${min} - ${gap}px)` : min) as BoxProps["flexBasis"];
|
|
114
|
+
};
|
|
115
|
+
|
|
99
116
|
export const SimpleGrid = SimpleGridFrame.styleable<SimpleGridProps>(
|
|
100
117
|
function SimpleGrid(props, ref) {
|
|
101
118
|
const {
|
|
@@ -116,31 +133,36 @@ export const SimpleGrid = SimpleGridFrame.styleable<SimpleGridProps>(
|
|
|
116
133
|
const sx = resolveSpacing(spacing);
|
|
117
134
|
const sy = resolveSpacing(verticalSpacing ?? spacing);
|
|
118
135
|
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
136
|
+
const minMode = minColWidth !== undefined;
|
|
137
|
+
const cellLayout = (index: number): CellLayout => {
|
|
138
|
+
if (minMode) {
|
|
139
|
+
const basis = minLessGap(minColWidth, sx);
|
|
140
|
+
return {
|
|
141
|
+
flexBasis: basis,
|
|
142
|
+
minWidth: basis as BoxProps["minWidth"],
|
|
143
|
+
flexGrow: autoFlow === "auto-fit" ? 1 : 0,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
const column = index % cols;
|
|
147
|
+
return {
|
|
148
|
+
width: `${100 / cols}%` as BoxProps["width"],
|
|
149
|
+
paddingLeft: (column * sx) / cols,
|
|
150
|
+
paddingRight: ((cols - 1 - column) * sx) / cols,
|
|
151
|
+
};
|
|
122
152
|
};
|
|
123
|
-
if (minColWidth !== undefined) {
|
|
124
|
-
cell.flexBasis = minColWidth as BoxProps["flexBasis"];
|
|
125
|
-
cell.minWidth = minColWidth as BoxProps["minWidth"];
|
|
126
|
-
cell.flexGrow = autoFlow === "auto-fit" ? 1 : 0;
|
|
127
|
-
} else {
|
|
128
|
-
cell.width = `${100 / cols}%` as BoxProps["width"];
|
|
129
|
-
}
|
|
130
153
|
|
|
131
154
|
const cells = React.Children.toArray(children)
|
|
132
155
|
.filter(Boolean)
|
|
133
156
|
.map((child, index) => (
|
|
134
|
-
// `styles.cell` is lower-precedence sugar; the computed
|
|
157
|
+
// `styles.cell` is lower-precedence sugar; the computed cell layout
|
|
135
158
|
// (width/flexBasis/gap padding) is owned by `SimpleGrid` and wins.
|
|
136
|
-
<Box key={index} {...s.get("cell")} {...
|
|
159
|
+
<Box key={index} {...s.get("cell")} {...cellLayout(index)}>
|
|
137
160
|
{child}
|
|
138
161
|
</Box>
|
|
139
162
|
));
|
|
140
163
|
|
|
141
164
|
return (
|
|
142
|
-
|
|
143
|
-
<SimpleGridFrame ref={ref} marginHorizontal={-sx / 2} marginVertical={-sy / 2} {...rest}>
|
|
165
|
+
<SimpleGridFrame ref={ref} rowGap={sy} {...(minMode && { columnGap: sx })} {...rest}>
|
|
144
166
|
{cells}
|
|
145
167
|
</SimpleGridFrame>
|
|
146
168
|
);
|
package/src/Tabs/Tabs.tsx
CHANGED
|
@@ -59,6 +59,40 @@ const TabsContext = React.createContext<TabsContextValue>({
|
|
|
59
59
|
id: "",
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Which panels are mounted right now. A `Tabs.Panel` registers its value while it
|
|
64
|
+
* renders; a `Tabs.Tab` points `aria-controls` at its panel only while that panel
|
|
65
|
+
* exists, so a strip without panels (a segmented switcher) or a panel unmounted by
|
|
66
|
+
* `keepMounted={false}` leaves no dangling id reference. Kept apart from
|
|
67
|
+
* `TabsContext` so a registration re-renders only the tabs.
|
|
68
|
+
*/
|
|
69
|
+
interface TabsPanelRegistry {
|
|
70
|
+
mounted: ReadonlyMap<string, number>;
|
|
71
|
+
register: (value: string) => () => void;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const TabsPanelRegistryContext = React.createContext<TabsPanelRegistry>({
|
|
75
|
+
mounted: new Map(),
|
|
76
|
+
register: () => () => {},
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
function useTabsPanelRegistry(): TabsPanelRegistry {
|
|
80
|
+
const [mounted, setMounted] = React.useState<ReadonlyMap<string, number>>(() => new Map());
|
|
81
|
+
const register = React.useCallback((value: string) => {
|
|
82
|
+
const bump = (delta: number) =>
|
|
83
|
+
setMounted((prev) => {
|
|
84
|
+
const next = new Map(prev);
|
|
85
|
+
const count = (next.get(value) ?? 0) + delta;
|
|
86
|
+
if (count > 0) next.set(value, count);
|
|
87
|
+
else next.delete(value);
|
|
88
|
+
return next;
|
|
89
|
+
});
|
|
90
|
+
bump(1);
|
|
91
|
+
return () => bump(-1);
|
|
92
|
+
}, []);
|
|
93
|
+
return React.useMemo(() => ({ mounted, register }), [mounted, register]);
|
|
94
|
+
}
|
|
95
|
+
|
|
62
96
|
const TabsStyleContext = createStyledContext<{
|
|
63
97
|
size: TabsSize;
|
|
64
98
|
variant: TabsVariant;
|
|
@@ -391,10 +425,20 @@ const TabsTab = TabTabFrame.styleable<TabsTabProps>(function TabsTab(props, ref)
|
|
|
391
425
|
const press = usePressScale();
|
|
392
426
|
const { value, children, leftSection, rightSection, disabled, ...rest } = props;
|
|
393
427
|
const ctx = React.useContext(TabsContext);
|
|
428
|
+
const panels = React.useContext(TabsPanelRegistryContext);
|
|
394
429
|
const s = useTabsSlots();
|
|
395
430
|
const isActive = ctx.value === value;
|
|
396
431
|
const panelId = `${ctx.id}-panel-${value}`;
|
|
397
432
|
const tabId = `${ctx.id}-tab-${value}`;
|
|
433
|
+
// Point at the panel only while it is mounted (an id reference to a missing
|
|
434
|
+
// element is invalid ARIA); a caller's own `aria-controls` wins either way.
|
|
435
|
+
const restProps = rest as typeof rest & { "aria-controls"?: string };
|
|
436
|
+
const ariaControls =
|
|
437
|
+
"aria-controls" in restProps
|
|
438
|
+
? restProps["aria-controls"]
|
|
439
|
+
: panels.mounted.has(value)
|
|
440
|
+
? panelId
|
|
441
|
+
: undefined;
|
|
398
442
|
|
|
399
443
|
const handlePress = React.useCallback(() => {
|
|
400
444
|
if (disabled) return;
|
|
@@ -475,7 +519,7 @@ const TabsTab = TabTabFrame.styleable<TabsTabProps>(function TabsTab(props, ref)
|
|
|
475
519
|
id={tabId}
|
|
476
520
|
aria-selected={isActive}
|
|
477
521
|
aria-disabled={disabled || undefined}
|
|
478
|
-
aria-controls={
|
|
522
|
+
aria-controls={ariaControls}
|
|
479
523
|
{...keyboardProps}
|
|
480
524
|
>
|
|
481
525
|
{leftSection ? <TabSection {...s.get("section")}>{leftSection}</TabSection> : null}
|
|
@@ -506,6 +550,7 @@ export interface TabsPanelProps extends GetProps<typeof TabsPanelFrame> {
|
|
|
506
550
|
const TabsPanel = TabsPanelFrame.styleable<TabsPanelProps>(function TabsPanel(props, ref) {
|
|
507
551
|
const { value, children, keepMounted: keepMountedProp, ...rest } = props;
|
|
508
552
|
const ctx = React.useContext(TabsContext);
|
|
553
|
+
const { register } = React.useContext(TabsPanelRegistryContext);
|
|
509
554
|
const s = useTabsSlots();
|
|
510
555
|
|
|
511
556
|
const isActive = ctx.value === value;
|
|
@@ -513,6 +558,12 @@ const TabsPanel = TabsPanelFrame.styleable<TabsPanelProps>(function TabsPanel(pr
|
|
|
513
558
|
const tabId = `${ctx.id}-tab-${value}`;
|
|
514
559
|
const panelId = `${ctx.id}-panel-${value}`;
|
|
515
560
|
|
|
561
|
+
// Tell the tabs this panel exists, so its tab may name it in `aria-controls`.
|
|
562
|
+
React.useLayoutEffect(
|
|
563
|
+
() => (shouldMount ? register(value) : undefined),
|
|
564
|
+
[register, shouldMount, value],
|
|
565
|
+
);
|
|
566
|
+
|
|
516
567
|
if (!shouldMount) return null;
|
|
517
568
|
|
|
518
569
|
return (
|
|
@@ -634,6 +685,7 @@ const TabsComponent = TabsFrame.styleable<TabsProps>(function Tabs(props, ref) {
|
|
|
634
685
|
} = props;
|
|
635
686
|
|
|
636
687
|
const autoId = useId(id);
|
|
688
|
+
const panelRegistry = useTabsPanelRegistry();
|
|
637
689
|
|
|
638
690
|
const [currentValue, setCurrentValue] = useUncontrolled<string | null>({
|
|
639
691
|
value,
|
|
@@ -686,18 +738,20 @@ const TabsComponent = TabsFrame.styleable<TabsProps>(function Tabs(props, ref) {
|
|
|
686
738
|
|
|
687
739
|
return (
|
|
688
740
|
<TabsContext.Provider value={ctx}>
|
|
689
|
-
<
|
|
690
|
-
<
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
741
|
+
<TabsPanelRegistryContext.Provider value={panelRegistry}>
|
|
742
|
+
<TabsSlotStylesContext.Provider value={styles}>
|
|
743
|
+
<TabsFrame
|
|
744
|
+
ref={ref}
|
|
745
|
+
orientation={orientation}
|
|
746
|
+
variant={variant}
|
|
747
|
+
size={size}
|
|
748
|
+
flexDirection={flexDirection}
|
|
749
|
+
{...rest}
|
|
750
|
+
>
|
|
751
|
+
{children}
|
|
752
|
+
</TabsFrame>
|
|
753
|
+
</TabsSlotStylesContext.Provider>
|
|
754
|
+
</TabsPanelRegistryContext.Provider>
|
|
701
755
|
</TabsContext.Provider>
|
|
702
756
|
);
|
|
703
757
|
});
|
|
@@ -38,6 +38,37 @@ export interface TransitionProps {
|
|
|
38
38
|
exitDelay?: number;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
/** The style keys every native transition animates; the hidden frame names them all. */
|
|
42
|
+
const ALL_ANIMATED_KEYS = ["transform", "opacity"];
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Hand `child` the Tamagui `transition` prop (and what it animates).
|
|
46
|
+
*
|
|
47
|
+
* EVERY element this component returns goes through here, the hidden
|
|
48
|
+
* `keepMounted` frame and the reduced-motion frames included, with `null` when
|
|
49
|
+
* there is nothing to animate. Tamagui decides whether a view is animated by the
|
|
50
|
+
* PRESENCE of the `transition` key, and runs extra hooks (`usePresence`, the
|
|
51
|
+
* driver's) for an animated one. A child that mounted without the key and got it
|
|
52
|
+
* a render later — `keepMounted` with `mounted={false}`, then `mounted` — changed
|
|
53
|
+
* its hook order: React threw "Rendered more hooks than during the previous
|
|
54
|
+
* render" on native. With the key always there the hooks never change.
|
|
55
|
+
*/
|
|
56
|
+
const withTransition = (
|
|
57
|
+
child: React.ReactElement,
|
|
58
|
+
value: unknown,
|
|
59
|
+
keys: string[] = ALL_ANIMATED_KEYS,
|
|
60
|
+
): React.ReactElement => {
|
|
61
|
+
if (!React.isValidElement(child) || child.type === React.Fragment) return child;
|
|
62
|
+
const childProps = child.props as {
|
|
63
|
+
transition?: unknown;
|
|
64
|
+
animateOnly?: string[];
|
|
65
|
+
};
|
|
66
|
+
return React.cloneElement(child, {
|
|
67
|
+
transition: "transition" in childProps ? childProps.transition : value,
|
|
68
|
+
animateOnly: childProps.animateOnly ?? keys,
|
|
69
|
+
} as Partial<typeof childProps>);
|
|
70
|
+
};
|
|
71
|
+
|
|
41
72
|
/**
|
|
42
73
|
* Native counterpart to the web Transition. It keeps the render-prop contract,
|
|
43
74
|
* but injects Tamagui's `transition` prop into the child so RN animates the
|
|
@@ -72,14 +103,15 @@ export function Transition({
|
|
|
72
103
|
});
|
|
73
104
|
|
|
74
105
|
if (transitionDuration === 0) {
|
|
75
|
-
if (mounted) return children({});
|
|
76
|
-
return keepMounted ? children({ display: "none" }) : null;
|
|
106
|
+
if (mounted) return withTransition(children({}), null);
|
|
107
|
+
return keepMounted ? withTransition(children({ display: "none" }), null) : null;
|
|
77
108
|
}
|
|
78
109
|
|
|
110
|
+
const timed = [resolveTransition(transitionTimingFunction), { duration: transitionDuration }];
|
|
79
111
|
const isExited = transitionStatus === "exited";
|
|
80
112
|
|
|
81
113
|
if (isExited && !mounted) {
|
|
82
|
-
return keepMounted ? children({ display: "none" }) : null;
|
|
114
|
+
return keepMounted ? withTransition(children({ display: "none" }), timed) : null;
|
|
83
115
|
}
|
|
84
116
|
|
|
85
117
|
const styles = getTransitionStyles({
|
|
@@ -88,23 +120,7 @@ export function Transition({
|
|
|
88
120
|
state: transitionStatus,
|
|
89
121
|
timingFunction: transitionTimingFunction,
|
|
90
122
|
});
|
|
91
|
-
const child = children(styles);
|
|
92
123
|
const keys = animatedKeys(styles);
|
|
93
124
|
|
|
94
|
-
|
|
95
|
-
return child;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const childProps = child.props as {
|
|
99
|
-
transition?: unknown;
|
|
100
|
-
animateOnly?: string[];
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
return React.cloneElement(child, {
|
|
104
|
-
transition: childProps.transition ?? [
|
|
105
|
-
resolveTransition(transitionTimingFunction),
|
|
106
|
-
{ duration: transitionDuration },
|
|
107
|
-
],
|
|
108
|
-
animateOnly: childProps.animateOnly ?? keys,
|
|
109
|
-
} as Partial<typeof childProps>);
|
|
125
|
+
return withTransition(children(styles), timed, keys.length > 0 ? keys : ALL_ANIMATED_KEYS);
|
|
110
126
|
}
|