panelui-native 0.108.0 → 0.110.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/module/components/avatar-cropper/avatar-cropper-math.js +320 -0
- package/lib/module/components/avatar-cropper/avatar-cropper-math.js.map +1 -0
- package/lib/module/components/avatar-cropper/index.js +656 -0
- package/lib/module/components/avatar-cropper/index.js.map +1 -0
- package/lib/module/components/badge/index.js +85 -4
- package/lib/module/components/badge/index.js.map +1 -1
- package/lib/module/components/button/index.js +12 -0
- package/lib/module/components/button/index.js.map +1 -1
- package/lib/module/components/button-group/index.js +3 -0
- package/lib/module/components/button-group/index.js.map +1 -1
- package/lib/module/components/checkbox/index.js +54 -4
- package/lib/module/components/checkbox/index.js.map +1 -1
- package/lib/module/components/chip/index.js +23 -1
- package/lib/module/components/chip/index.js.map +1 -1
- package/lib/module/components/input/index.js +14 -0
- package/lib/module/components/input/index.js.map +1 -1
- package/lib/module/components/map/index.js +157 -5
- package/lib/module/components/map/index.js.map +1 -1
- package/lib/module/components/map/map-insets.js +174 -0
- package/lib/module/components/map/map-insets.js.map +1 -0
- package/lib/module/components/radio-group/index.js +49 -3
- package/lib/module/components/radio-group/index.js.map +1 -1
- package/lib/module/components/select/index.js +54 -2
- package/lib/module/components/select/index.js.map +1 -1
- package/lib/module/components/switch/index.js +42 -3
- package/lib/module/components/switch/index.js.map +1 -1
- package/lib/module/components/tabs/index.js +147 -1
- package/lib/module/components/tabs/index.js.map +1 -1
- package/lib/module/components/textarea/index.js +18 -0
- package/lib/module/components/textarea/index.js.map +1 -1
- package/lib/module/components/toggle-button/index.js +34 -2
- package/lib/module/components/toggle-button/index.js.map +1 -1
- package/lib/module/icons/index.js +6 -0
- package/lib/module/icons/index.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/providers/panel-ui-provider.js +22 -10
- package/lib/module/providers/panel-ui-provider.js.map +1 -1
- package/lib/typescript/src/components/avatar-cropper/avatar-cropper-math.d.ts +98 -0
- package/lib/typescript/src/components/avatar-cropper/avatar-cropper-math.d.ts.map +1 -0
- package/lib/typescript/src/components/avatar-cropper/index.d.ts +168 -0
- package/lib/typescript/src/components/avatar-cropper/index.d.ts.map +1 -0
- package/lib/typescript/src/components/badge/index.d.ts +68 -0
- package/lib/typescript/src/components/badge/index.d.ts.map +1 -1
- package/lib/typescript/src/components/button/index.d.ts +12 -0
- package/lib/typescript/src/components/button/index.d.ts.map +1 -1
- package/lib/typescript/src/components/button-group/index.d.ts +9 -0
- package/lib/typescript/src/components/button-group/index.d.ts.map +1 -1
- package/lib/typescript/src/components/checkbox/index.d.ts +89 -0
- package/lib/typescript/src/components/checkbox/index.d.ts.map +1 -1
- package/lib/typescript/src/components/chip/index.d.ts +24 -0
- package/lib/typescript/src/components/chip/index.d.ts.map +1 -1
- package/lib/typescript/src/components/input/index.d.ts +30 -0
- package/lib/typescript/src/components/input/index.d.ts.map +1 -1
- package/lib/typescript/src/components/map/index.d.ts +67 -1
- package/lib/typescript/src/components/map/index.d.ts.map +1 -1
- package/lib/typescript/src/components/map/map-insets.d.ts +80 -0
- package/lib/typescript/src/components/map/map-insets.d.ts.map +1 -0
- package/lib/typescript/src/components/radio-group/index.d.ts +188 -1
- package/lib/typescript/src/components/radio-group/index.d.ts.map +1 -1
- package/lib/typescript/src/components/select/index.d.ts +9 -1
- package/lib/typescript/src/components/select/index.d.ts.map +1 -1
- package/lib/typescript/src/components/switch/index.d.ts +38 -0
- package/lib/typescript/src/components/switch/index.d.ts.map +1 -1
- package/lib/typescript/src/components/tabs/index.d.ts +10 -1
- package/lib/typescript/src/components/tabs/index.d.ts.map +1 -1
- package/lib/typescript/src/components/textarea/index.d.ts +18 -0
- package/lib/typescript/src/components/textarea/index.d.ts.map +1 -1
- package/lib/typescript/src/components/toggle-button/index.d.ts +24 -0
- package/lib/typescript/src/components/toggle-button/index.d.ts.map +1 -1
- package/lib/typescript/src/icons/index.d.ts +2 -0
- package/lib/typescript/src/icons/index.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +8 -7
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/providers/panel-ui-provider.d.ts.map +1 -1
- package/package.json +9 -1
- package/src/components/avatar-cropper/avatar-cropper-math.ts +311 -0
- package/src/components/avatar-cropper/index.tsx +808 -0
- package/src/components/badge/index.tsx +30 -4
- package/src/components/button/index.tsx +9 -2
- package/src/components/button-group/index.tsx +1 -0
- package/src/components/checkbox/index.tsx +47 -3
- package/src/components/chip/index.tsx +5 -1
- package/src/components/input/index.tsx +6 -0
- package/src/components/map/index.tsx +215 -5
- package/src/components/map/map-insets.ts +169 -0
- package/src/components/radio-group/index.tsx +56 -4
- package/src/components/select/index.tsx +50 -1
- package/src/components/switch/index.tsx +16 -4
- package/src/components/tabs/index.tsx +61 -0
- package/src/components/textarea/index.tsx +6 -0
- package/src/components/toggle-button/index.tsx +16 -1
- package/src/icons/index.tsx +3 -0
- package/src/index.ts +24 -3
- package/src/providers/panel-ui-provider.tsx +21 -11
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where things sit once something else is drawn over the map.
|
|
3
|
+
*
|
|
4
|
+
* A map that fills the screen usually has chrome on top of it: a card of
|
|
5
|
+
* figures along the top, a summary along the bottom, the status bar, a
|
|
6
|
+
* floating tab bar. The controls belong in a corner, and a corner is exactly
|
|
7
|
+
* where that chrome goes, so left alone they end up underneath it.
|
|
8
|
+
*
|
|
9
|
+
* Everything drawn over the map therefore says how far in from its edge it
|
|
10
|
+
* reaches, and the controls take the largest claim on their corner and sit
|
|
11
|
+
* past it. This file is that arithmetic and nothing else, kept apart from the
|
|
12
|
+
* views so it can be checked without a device.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export type MapCorner = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
|
16
|
+
|
|
17
|
+
/** A band across the whole of one edge, or a single corner. */
|
|
18
|
+
export type MapOverlayPosition = 'top' | 'bottom' | MapCorner;
|
|
19
|
+
|
|
20
|
+
/** A distance from each edge of the map, in points. */
|
|
21
|
+
export interface MapInsets {
|
|
22
|
+
top: number;
|
|
23
|
+
right: number;
|
|
24
|
+
bottom: number;
|
|
25
|
+
left: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** One number for every side, or only the sides that need one. */
|
|
29
|
+
export type MapInsetsInput = number | Partial<MapInsets>;
|
|
30
|
+
|
|
31
|
+
/** What one overlay takes: where it is, and how far in from that edge it reaches. */
|
|
32
|
+
export interface MapReservation {
|
|
33
|
+
position: MapOverlayPosition;
|
|
34
|
+
/** Points from the map's top or bottom edge to the overlay's far side. */
|
|
35
|
+
extent: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The style offsets that pin a view: one vertical side and, for a corner, one horizontal. */
|
|
39
|
+
export type MapOffsets = Partial<MapInsets>;
|
|
40
|
+
|
|
41
|
+
/** A negative or missing inset is no inset. A view pushed off the map helps nobody. */
|
|
42
|
+
function clean(value: number | undefined): number {
|
|
43
|
+
return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Expands the `inset` shorthand to four sides. */
|
|
47
|
+
export function toMapInsets(inset: MapInsetsInput | undefined): MapInsets {
|
|
48
|
+
if (typeof inset === 'number') {
|
|
49
|
+
const value = clean(inset);
|
|
50
|
+
return { top: value, right: value, bottom: value, left: value };
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
top: clean(inset?.top),
|
|
54
|
+
right: clean(inset?.right),
|
|
55
|
+
bottom: clean(inset?.bottom),
|
|
56
|
+
left: clean(inset?.left),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Two sets of insets, side by side. */
|
|
61
|
+
export function addMapInsets(a: MapInsets, b: MapInsets): MapInsets {
|
|
62
|
+
return {
|
|
63
|
+
top: a.top + b.top,
|
|
64
|
+
right: a.right + b.right,
|
|
65
|
+
bottom: a.bottom + b.bottom,
|
|
66
|
+
left: a.left + b.left,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** The corners a position covers. A band covers both corners of its edge. */
|
|
71
|
+
export function cornersOf(position: MapOverlayPosition): MapCorner[] {
|
|
72
|
+
if (position === 'top') return ['top-left', 'top-right'];
|
|
73
|
+
if (position === 'bottom') return ['bottom-left', 'bottom-right'];
|
|
74
|
+
return [position];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** The furthest any overlay reaches into a corner. 0 when nothing is there. */
|
|
78
|
+
export function reservedAt(
|
|
79
|
+
corner: MapCorner,
|
|
80
|
+
reservations: Iterable<MapReservation>
|
|
81
|
+
): number {
|
|
82
|
+
let reserved = 0;
|
|
83
|
+
for (const { position, extent } of reservations) {
|
|
84
|
+
if (extent > reserved && cornersOf(position).includes(corner)) reserved = extent;
|
|
85
|
+
}
|
|
86
|
+
return reserved;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Where an overlay is pinned, and how far it reaches once it has a height.
|
|
91
|
+
*
|
|
92
|
+
* A band is pinned on three sides so it spans the map between its insets. A
|
|
93
|
+
* corner is pinned on two and is as wide as what is inside it.
|
|
94
|
+
*/
|
|
95
|
+
export function overlayOffsets(position: MapOverlayPosition, inset: MapInsets): MapOffsets {
|
|
96
|
+
const vertical = position.startsWith('top') ? { top: inset.top } : { bottom: inset.bottom };
|
|
97
|
+
if (position === 'top' || position === 'bottom') {
|
|
98
|
+
return { ...vertical, left: inset.left, right: inset.right };
|
|
99
|
+
}
|
|
100
|
+
return position.endsWith('left')
|
|
101
|
+
? { ...vertical, left: inset.left }
|
|
102
|
+
: { ...vertical, right: inset.right };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The reservation an overlay makes once it has been measured.
|
|
107
|
+
*
|
|
108
|
+
* Nothing until it has a height. An overlay that is empty, or has not been
|
|
109
|
+
* laid out yet, would otherwise claim its inset alone and nudge the controls
|
|
110
|
+
* by a gap for a frame before moving them to where they belong.
|
|
111
|
+
*/
|
|
112
|
+
export function overlayReservation(
|
|
113
|
+
position: MapOverlayPosition,
|
|
114
|
+
inset: MapInsets,
|
|
115
|
+
height: number
|
|
116
|
+
): MapReservation | null {
|
|
117
|
+
if (clean(height) === 0) return null;
|
|
118
|
+
const edge = position.startsWith('top') ? inset.top : inset.bottom;
|
|
119
|
+
return { position, extent: edge + height };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The distance a part keeps from each edge of the map.
|
|
124
|
+
*
|
|
125
|
+
* `inset` means the same thing on `Map.Controls` and `Map.Overlay`: how far
|
|
126
|
+
* from the edge, with the standard gap on any side it leaves out. The safe
|
|
127
|
+
* area is added on top, because a card 12 points from the edge of the screen
|
|
128
|
+
* and a card 12 points below the status bar are both "12 points in" to the
|
|
129
|
+
* person looking at them.
|
|
130
|
+
*/
|
|
131
|
+
export function resolveMapInsets(
|
|
132
|
+
inset: MapInsetsInput | undefined,
|
|
133
|
+
gap: number,
|
|
134
|
+
safeArea: MapInsets
|
|
135
|
+
): MapInsets {
|
|
136
|
+
const own =
|
|
137
|
+
typeof inset === 'number'
|
|
138
|
+
? toMapInsets(inset)
|
|
139
|
+
: toMapInsets({
|
|
140
|
+
top: inset?.top ?? gap,
|
|
141
|
+
right: inset?.right ?? gap,
|
|
142
|
+
bottom: inset?.bottom ?? gap,
|
|
143
|
+
left: inset?.left ?? gap,
|
|
144
|
+
});
|
|
145
|
+
return addMapInsets(own, toMapInsets(safeArea));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Where a control stack in `corner` goes.
|
|
150
|
+
*
|
|
151
|
+
* `inset` is the stack's own distance from the map's edges. `reserved` is what
|
|
152
|
+
* an overlay has taken from the same edge, and the stack sits one `gap` past
|
|
153
|
+
* it. The two are not added: an overlay that already clears the status bar has
|
|
154
|
+
* cleared it for the controls too, so whichever reaches further decides.
|
|
155
|
+
*/
|
|
156
|
+
export function controlsOffsets(
|
|
157
|
+
corner: MapCorner,
|
|
158
|
+
{ gap, inset, reserved }: { gap: number; inset: MapInsets; reserved: number }
|
|
159
|
+
): MapOffsets {
|
|
160
|
+
const top = corner.startsWith('top');
|
|
161
|
+
const left = corner.endsWith('left');
|
|
162
|
+
const past = clean(reserved) > 0 ? clean(reserved) + gap : 0;
|
|
163
|
+
const vertical = Math.max(top ? inset.top : inset.bottom, past);
|
|
164
|
+
const horizontal = left ? inset.left : inset.right;
|
|
165
|
+
return {
|
|
166
|
+
...(top ? { top: vertical } : { bottom: vertical }),
|
|
167
|
+
...(left ? { left: horizontal } : { right: horizontal }),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
@@ -49,10 +49,49 @@ const itemVariants = tv({
|
|
|
49
49
|
row: 'min-h-12 min-w-12 flex-row items-center gap-2.5 self-start',
|
|
50
50
|
indicator:
|
|
51
51
|
'h-5 w-5 items-center justify-center rounded-full border border-input bg-background',
|
|
52
|
+
// Half the disc it sits in, at every size.
|
|
53
|
+
dot: 'h-2.5 w-2.5 rounded-full bg-primary',
|
|
52
54
|
label: 'text-sm text-foreground',
|
|
53
55
|
description: 'text-xs text-muted-foreground',
|
|
54
56
|
},
|
|
55
57
|
variants: {
|
|
58
|
+
/*
|
|
59
|
+
* The disc, its dot and the text beside it move together, on the same
|
|
60
|
+
* steps as Checkbox so the two line up in one form. The row stays 48
|
|
61
|
+
* points tall at every size, because that is the touch target.
|
|
62
|
+
*
|
|
63
|
+
* Listed before `variant` so the card keeps the label weight it sets.
|
|
64
|
+
*/
|
|
65
|
+
size: {
|
|
66
|
+
xs: {
|
|
67
|
+
row: 'gap-2',
|
|
68
|
+
indicator: 'h-3.5 w-3.5',
|
|
69
|
+
dot: 'h-1.5 w-1.5',
|
|
70
|
+
label: 'text-xs',
|
|
71
|
+
description: 'text-[11px]',
|
|
72
|
+
},
|
|
73
|
+
sm: {
|
|
74
|
+
row: 'gap-2',
|
|
75
|
+
indicator: 'h-4 w-4',
|
|
76
|
+
dot: 'h-2 w-2',
|
|
77
|
+
label: 'text-[13px]',
|
|
78
|
+
},
|
|
79
|
+
md: {},
|
|
80
|
+
lg: {
|
|
81
|
+
row: 'gap-3',
|
|
82
|
+
indicator: 'h-6 w-6',
|
|
83
|
+
dot: 'h-3 w-3',
|
|
84
|
+
label: 'text-base',
|
|
85
|
+
description: 'text-sm',
|
|
86
|
+
},
|
|
87
|
+
xl: {
|
|
88
|
+
row: 'gap-3',
|
|
89
|
+
indicator: 'h-7 w-7',
|
|
90
|
+
dot: 'h-3.5 w-3.5',
|
|
91
|
+
label: 'text-lg',
|
|
92
|
+
description: 'text-sm',
|
|
93
|
+
},
|
|
94
|
+
},
|
|
56
95
|
variant: {
|
|
57
96
|
dot: {},
|
|
58
97
|
card: {
|
|
@@ -85,14 +124,19 @@ const itemVariants = tv({
|
|
|
85
124
|
],
|
|
86
125
|
defaultVariants: {
|
|
87
126
|
variant: 'dot',
|
|
127
|
+
size: 'md',
|
|
88
128
|
},
|
|
89
129
|
});
|
|
90
130
|
|
|
131
|
+
/** How big a group's discs and labels are. */
|
|
132
|
+
type RadioSize = NonNullable<VariantProps<typeof itemVariants>['size']>;
|
|
133
|
+
|
|
91
134
|
interface RadioGroupContextValue {
|
|
92
135
|
value: string | undefined;
|
|
93
136
|
onValueChange: (value: string) => void;
|
|
94
137
|
disabled?: boolean;
|
|
95
138
|
variant: RadioVariant;
|
|
139
|
+
size: RadioSize;
|
|
96
140
|
orientation: RadioOrientation;
|
|
97
141
|
}
|
|
98
142
|
|
|
@@ -109,6 +153,12 @@ export interface RadioGroupProps extends ViewProps {
|
|
|
109
153
|
* settings choice where each option carries a description.
|
|
110
154
|
*/
|
|
111
155
|
variant?: RadioVariant;
|
|
156
|
+
/**
|
|
157
|
+
* How big every option's disc and label are. Set on the group rather than
|
|
158
|
+
* per option, because options of different sizes read as though one of them
|
|
159
|
+
* matters more. The row keeps a 48-point target at every size.
|
|
160
|
+
*/
|
|
161
|
+
size?: RadioSize;
|
|
112
162
|
/**
|
|
113
163
|
* `horizontal` lays the options out along a row that wraps — for two or
|
|
114
164
|
* three short choices, where a stacked list wastes the width and reads as
|
|
@@ -126,6 +176,7 @@ const RadioGroupRoot = forwardRef<View, RadioGroupProps>(
|
|
|
126
176
|
onValueChange,
|
|
127
177
|
disabled,
|
|
128
178
|
variant = 'dot',
|
|
179
|
+
size = 'md',
|
|
129
180
|
orientation = 'vertical',
|
|
130
181
|
children,
|
|
131
182
|
...props
|
|
@@ -133,8 +184,8 @@ const RadioGroupRoot = forwardRef<View, RadioGroupProps>(
|
|
|
133
184
|
ref
|
|
134
185
|
) => {
|
|
135
186
|
const context = useMemo(
|
|
136
|
-
() => ({ value, onValueChange, disabled, variant, orientation }),
|
|
137
|
-
[value, onValueChange, disabled, variant, orientation]
|
|
187
|
+
() => ({ value, onValueChange, disabled, variant, size, orientation }),
|
|
188
|
+
[value, onValueChange, disabled, variant, size, orientation]
|
|
138
189
|
);
|
|
139
190
|
|
|
140
191
|
return (
|
|
@@ -220,6 +271,7 @@ const RadioGroupItem = forwardRef<View, RadioGroupItemProps>(
|
|
|
220
271
|
|
|
221
272
|
const slots = itemVariants({
|
|
222
273
|
variant,
|
|
274
|
+
size: context.size,
|
|
223
275
|
selected,
|
|
224
276
|
disabled: !!disabled,
|
|
225
277
|
horizontal: context.orientation === 'horizontal',
|
|
@@ -227,7 +279,7 @@ const RadioGroupItem = forwardRef<View, RadioGroupItemProps>(
|
|
|
227
279
|
|
|
228
280
|
const indicator = hideIndicator ? null : (
|
|
229
281
|
<View className={slots.indicator()}>
|
|
230
|
-
<Animated.View style={dotStyle} className=
|
|
282
|
+
<Animated.View style={dotStyle} className={slots.dot()} />
|
|
231
283
|
</View>
|
|
232
284
|
);
|
|
233
285
|
|
|
@@ -287,4 +339,4 @@ export const RadioGroup = Object.assign(RadioGroupRoot, {
|
|
|
287
339
|
Item: RadioGroupItem,
|
|
288
340
|
});
|
|
289
341
|
|
|
290
|
-
export type { RadioVariant };
|
|
342
|
+
export type { RadioVariant, RadioSize };
|
|
@@ -94,6 +94,33 @@ const selectVariants = tv({
|
|
|
94
94
|
groupLabel: 'px-3 pb-1 pt-2',
|
|
95
95
|
},
|
|
96
96
|
variants: {
|
|
97
|
+
/*
|
|
98
|
+
* The trigger only. The options are read in a sheet or a list of their
|
|
99
|
+
* own, at one size, however compact the field that opened them is.
|
|
100
|
+
*/
|
|
101
|
+
size: {
|
|
102
|
+
xs: {
|
|
103
|
+
trigger: 'gap-2 px-2.5 py-1.5',
|
|
104
|
+
triggerLabel: 'text-[13px]',
|
|
105
|
+
placeholder: 'text-[13px]',
|
|
106
|
+
},
|
|
107
|
+
sm: {
|
|
108
|
+
trigger: 'gap-2 px-3 py-2.5',
|
|
109
|
+
triggerLabel: 'text-sm',
|
|
110
|
+
placeholder: 'text-sm',
|
|
111
|
+
},
|
|
112
|
+
md: {},
|
|
113
|
+
lg: {
|
|
114
|
+
trigger: 'py-4',
|
|
115
|
+
triggerLabel: 'text-lg',
|
|
116
|
+
placeholder: 'text-lg',
|
|
117
|
+
},
|
|
118
|
+
xl: {
|
|
119
|
+
trigger: 'px-5 py-5',
|
|
120
|
+
triggerLabel: 'text-lg',
|
|
121
|
+
placeholder: 'text-lg',
|
|
122
|
+
},
|
|
123
|
+
},
|
|
97
124
|
selected: {
|
|
98
125
|
true: { item: 'bg-accent' },
|
|
99
126
|
},
|
|
@@ -111,11 +138,24 @@ const selectVariants = tv({
|
|
|
111
138
|
},
|
|
112
139
|
defaultVariants: {
|
|
113
140
|
presentation: 'sheet',
|
|
141
|
+
size: 'md',
|
|
114
142
|
},
|
|
115
143
|
});
|
|
116
144
|
|
|
117
145
|
export type SelectPresentation = 'sheet' | 'inline' | 'overlay';
|
|
118
146
|
|
|
147
|
+
/** How big the trigger is. */
|
|
148
|
+
export type SelectSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
149
|
+
|
|
150
|
+
/** The chevron keeps step with the label beside it. */
|
|
151
|
+
const CHEVRON_SIZE: Record<SelectSize, number> = { xs: 12, sm: 14, md: 16, lg: 18, xl: 20 };
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* What the `xs` trigger is short of a 44pt target, above and below. The
|
|
155
|
+
* trigger is as wide as its container, so there is nothing to add at the sides.
|
|
156
|
+
*/
|
|
157
|
+
const XS_TRIGGER_HIT_SLOP = { top: 7, bottom: 7 };
|
|
158
|
+
|
|
119
159
|
interface SelectContextValue {
|
|
120
160
|
value: string | undefined;
|
|
121
161
|
onSelect: (value: string) => void;
|
|
@@ -399,6 +439,12 @@ export interface SelectProps {
|
|
|
399
439
|
placeholder?: string;
|
|
400
440
|
/** Refuses the trigger and dims it. The options cannot be opened. */
|
|
401
441
|
disabled?: boolean;
|
|
442
|
+
/**
|
|
443
|
+
* How big the trigger is: its padding, its text and its chevron. The options
|
|
444
|
+
* it opens are not resized. Ignored in `native` mode, where the platform
|
|
445
|
+
* draws the picker. For the height of the sheet, see `sheetProps.size`.
|
|
446
|
+
*/
|
|
447
|
+
size?: SelectSize;
|
|
402
448
|
/** Extra classes for the trigger — the field you press to open the list. */
|
|
403
449
|
triggerClassName?: string;
|
|
404
450
|
/** Extra classes for the selected option's text on the trigger. */
|
|
@@ -490,6 +536,7 @@ function SelectRoot({
|
|
|
490
536
|
searchContainerClassName,
|
|
491
537
|
emptyClassName,
|
|
492
538
|
presentation = 'sheet',
|
|
539
|
+
size = 'md',
|
|
493
540
|
title,
|
|
494
541
|
sheetProps,
|
|
495
542
|
contentWidth = 'trigger',
|
|
@@ -604,7 +651,7 @@ function SelectRoot({
|
|
|
604
651
|
[value, onValueChange, close, query]
|
|
605
652
|
);
|
|
606
653
|
|
|
607
|
-
const slots = selectVariants({ disabled: !!disabled, presentation });
|
|
654
|
+
const slots = selectVariants({ disabled: !!disabled, presentation, size });
|
|
608
655
|
const chevronColor = useCSSVariable('--color-muted-foreground');
|
|
609
656
|
|
|
610
657
|
const chevronStyle = useAnimatedStyle(() => ({
|
|
@@ -646,6 +693,7 @@ function SelectRoot({
|
|
|
646
693
|
*/
|
|
647
694
|
accessibilityRole="combobox"
|
|
648
695
|
accessibilityState={{ disabled: !!disabled, expanded: open }}
|
|
696
|
+
hitSlop={size === 'xs' ? XS_TRIGGER_HIT_SLOP : undefined}
|
|
649
697
|
disabled={disabled}
|
|
650
698
|
onPress={toggle}
|
|
651
699
|
className={slots.trigger({ className: triggerClassName })}
|
|
@@ -657,6 +705,7 @@ function SelectRoot({
|
|
|
657
705
|
)}
|
|
658
706
|
<Animated.View style={chevronStyle}>
|
|
659
707
|
<ChevronDownIcon
|
|
708
|
+
size={CHEVRON_SIZE[size]}
|
|
660
709
|
color={typeof chevronColor === 'string' ? chevronColor : '#737373'}
|
|
661
710
|
/>
|
|
662
711
|
</Animated.View>
|
|
@@ -21,9 +21,15 @@ const switchVariants = tv({
|
|
|
21
21
|
thumb: 'rounded-full bg-white shadow-sm',
|
|
22
22
|
},
|
|
23
23
|
variants: {
|
|
24
|
+
// Each track is its thumb plus the 3pt of padding and 1pt of border on
|
|
25
|
+
// either side, and twice as wide as it is tall. `TRAVEL` below is what is
|
|
26
|
+
// left of that width once the thumb is in it.
|
|
24
27
|
size: {
|
|
28
|
+
xs: { track: 'h-5 w-8', thumb: 'h-3 w-3' },
|
|
25
29
|
sm: { track: 'h-6 w-10', thumb: 'h-4 w-4' },
|
|
26
30
|
md: { track: 'h-7 w-12', thumb: 'h-5 w-5' },
|
|
31
|
+
lg: { track: 'h-8 w-14', thumb: 'h-6 w-6' },
|
|
32
|
+
xl: { track: 'h-9 w-16', thumb: 'h-7 w-7' },
|
|
27
33
|
},
|
|
28
34
|
disabled: {
|
|
29
35
|
true: { track: 'opacity-50' },
|
|
@@ -34,19 +40,25 @@ const switchVariants = tv({
|
|
|
34
40
|
},
|
|
35
41
|
});
|
|
36
42
|
|
|
37
|
-
|
|
43
|
+
/** How big a switch is. */
|
|
44
|
+
export type SwitchSize = NonNullable<VariantProps<typeof switchVariants>['size']>;
|
|
45
|
+
|
|
46
|
+
const TRAVEL: Record<SwitchSize, number> = { xs: 12, sm: 16, md: 20, lg: 24, xl: 28 };
|
|
38
47
|
|
|
39
48
|
/**
|
|
40
49
|
* Room around each track so the target reaches 48dp on both axes.
|
|
41
50
|
*
|
|
42
51
|
* Slop rather than a bigger box, because a box is layout: a switch sized to
|
|
43
52
|
* its target would stand 48dp tall in every row it has ever been placed in,
|
|
44
|
-
* and the tracks are
|
|
45
|
-
* which is why the
|
|
53
|
+
* and the tracks are 20 to 36 tall. From `md` up the track is already 48 wide,
|
|
54
|
+
* which is why only the two smallest have horizontal figures.
|
|
46
55
|
*/
|
|
47
|
-
const SWITCH_HIT_SLOP: Record<
|
|
56
|
+
const SWITCH_HIT_SLOP: Record<SwitchSize, { top: number; bottom: number; left: number; right: number }> = {
|
|
57
|
+
xs: { top: 14, bottom: 14, left: 8, right: 8 },
|
|
48
58
|
sm: { top: 12, bottom: 12, left: 4, right: 4 },
|
|
49
59
|
md: { top: 10, bottom: 10, left: 0, right: 0 },
|
|
60
|
+
lg: { top: 8, bottom: 8, left: 0, right: 0 },
|
|
61
|
+
xl: { top: 6, bottom: 6, left: 0, right: 0 },
|
|
50
62
|
};
|
|
51
63
|
|
|
52
64
|
export interface SwitchProps
|
|
@@ -119,6 +119,21 @@ const MEASURE_WIDTH = 400;
|
|
|
119
119
|
|
|
120
120
|
export type TabsVariant = 'segmented' | 'underline' | 'pill' | 'expanding';
|
|
121
121
|
|
|
122
|
+
/** How big the triggers and their labels are. */
|
|
123
|
+
export type TabsSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Room above and below the two smallest sizes, so a row that is drawn 20 or 24
|
|
127
|
+
* points tall is still pressed like one that is 44.
|
|
128
|
+
*
|
|
129
|
+
* Vertical only. The triggers sit edge to edge in a row, and slop to the side
|
|
130
|
+
* would reach into the neighbouring tab and take its presses.
|
|
131
|
+
*/
|
|
132
|
+
const TRIGGER_HIT_SLOP: Partial<Record<TabsSize, { top: number; bottom: number }>> = {
|
|
133
|
+
xs: { top: 12, bottom: 12 },
|
|
134
|
+
sm: { top: 8, bottom: 8 },
|
|
135
|
+
};
|
|
136
|
+
|
|
122
137
|
/**
|
|
123
138
|
* How much of an inactive panel survives a switch away from it.
|
|
124
139
|
*
|
|
@@ -187,6 +202,21 @@ const tabsVariants = tv({
|
|
|
187
202
|
trigger: 'rounded-full bg-muted px-3.5 py-2.5',
|
|
188
203
|
},
|
|
189
204
|
},
|
|
205
|
+
/*
|
|
206
|
+
* The label's type size. `md` adds nothing, so it is whatever the label
|
|
207
|
+
* was drawn at before sizes existed.
|
|
208
|
+
*
|
|
209
|
+
* How tall a trigger is depends on the variant as well, since each draws
|
|
210
|
+
* its tab differently, so the padding per size is in the compound variants
|
|
211
|
+
* below rather than here.
|
|
212
|
+
*/
|
|
213
|
+
size: {
|
|
214
|
+
xs: { label: 'text-xs' },
|
|
215
|
+
sm: { label: 'text-[13px]' },
|
|
216
|
+
md: {},
|
|
217
|
+
lg: { label: 'text-base' },
|
|
218
|
+
xl: { label: 'text-lg' },
|
|
219
|
+
},
|
|
190
220
|
active: {
|
|
191
221
|
true: { label: 'text-foreground' },
|
|
192
222
|
false: { label: 'text-muted-foreground' },
|
|
@@ -207,9 +237,27 @@ const tabsVariants = tv({
|
|
|
207
237
|
// exists to avoid.
|
|
208
238
|
{ variant: 'expanding', class: { trigger: 'flex-none' } },
|
|
209
239
|
{ variant: 'expanding', active: true, class: { trigger: 'bg-surface-tertiary' } },
|
|
240
|
+
// Half a step of padding per size, either side of the variant's own.
|
|
241
|
+
{ variant: 'segmented', size: 'xs', class: { trigger: 'py-0.5' } },
|
|
242
|
+
{ variant: 'segmented', size: 'sm', class: { trigger: 'py-1' } },
|
|
243
|
+
{ variant: 'segmented', size: 'lg', class: { trigger: 'py-2' } },
|
|
244
|
+
{ variant: 'segmented', size: 'xl', class: { trigger: 'py-2.5' } },
|
|
245
|
+
{ variant: 'underline', size: 'xs', class: { trigger: 'py-1.5' } },
|
|
246
|
+
{ variant: 'underline', size: 'sm', class: { trigger: 'py-2' } },
|
|
247
|
+
{ variant: 'underline', size: 'lg', class: { trigger: 'py-3' } },
|
|
248
|
+
{ variant: 'underline', size: 'xl', class: { trigger: 'py-3.5' } },
|
|
249
|
+
{ variant: 'pill', size: 'xs', class: { trigger: 'py-1' } },
|
|
250
|
+
{ variant: 'pill', size: 'sm', class: { trigger: 'py-1.5' } },
|
|
251
|
+
{ variant: 'pill', size: 'lg', class: { trigger: 'py-2.5' } },
|
|
252
|
+
{ variant: 'pill', size: 'xl', class: { trigger: 'py-3' } },
|
|
253
|
+
{ variant: 'expanding', size: 'xs', class: { trigger: 'px-2.5 py-1.5' } },
|
|
254
|
+
{ variant: 'expanding', size: 'sm', class: { trigger: 'px-3 py-2' } },
|
|
255
|
+
{ variant: 'expanding', size: 'lg', class: { trigger: 'px-4 py-3' } },
|
|
256
|
+
{ variant: 'expanding', size: 'xl', class: { trigger: 'px-5 py-3.5' } },
|
|
210
257
|
],
|
|
211
258
|
defaultVariants: {
|
|
212
259
|
variant: 'segmented',
|
|
260
|
+
size: 'md',
|
|
213
261
|
scrollable: false,
|
|
214
262
|
},
|
|
215
263
|
});
|
|
@@ -225,6 +273,7 @@ interface TabsContextValue {
|
|
|
225
273
|
registerLayout: (value: string, layout: TabLayout) => void;
|
|
226
274
|
layouts: Record<string, TabLayout>;
|
|
227
275
|
variant: TabsVariant;
|
|
276
|
+
size: TabsSize;
|
|
228
277
|
keepMounted: TabsKeepMounted;
|
|
229
278
|
/**
|
|
230
279
|
* Whether the panels are in a strip rather than stacked in place.
|
|
@@ -280,6 +329,13 @@ export interface TabsProps extends ViewProps {
|
|
|
280
329
|
* every trigger an `icon` — a closed tab has nothing else.
|
|
281
330
|
*/
|
|
282
331
|
variant?: TabsVariant;
|
|
332
|
+
/**
|
|
333
|
+
* How big the triggers and their labels are. `xs` and `sm` are for a tab set
|
|
334
|
+
* inside something else, such as a card or a toolbar; `lg` and `xl` are for
|
|
335
|
+
* one that is the main navigation of a screen. Icons and badges you pass are
|
|
336
|
+
* not resized.
|
|
337
|
+
*/
|
|
338
|
+
size?: TabsSize;
|
|
283
339
|
/**
|
|
284
340
|
* Mount every panel up front instead of only the ones that have been
|
|
285
341
|
* reached, so a scroll position or a half-filled form is there from the
|
|
@@ -378,6 +434,7 @@ function TabsRoot({
|
|
|
378
434
|
onValueChange,
|
|
379
435
|
defaultValue,
|
|
380
436
|
variant = 'segmented',
|
|
437
|
+
size = 'md',
|
|
381
438
|
keepMounted = false,
|
|
382
439
|
swipeable = false,
|
|
383
440
|
animation,
|
|
@@ -427,6 +484,7 @@ function TabsRoot({
|
|
|
427
484
|
registerLayout,
|
|
428
485
|
layouts,
|
|
429
486
|
variant,
|
|
487
|
+
size,
|
|
430
488
|
keepMounted,
|
|
431
489
|
pager: paged,
|
|
432
490
|
animationDisabled,
|
|
@@ -437,6 +495,7 @@ function TabsRoot({
|
|
|
437
495
|
registerLayout,
|
|
438
496
|
layouts,
|
|
439
497
|
variant,
|
|
498
|
+
size,
|
|
440
499
|
keepMounted,
|
|
441
500
|
paged,
|
|
442
501
|
animationDisabled,
|
|
@@ -901,6 +960,7 @@ function TabsTrigger({
|
|
|
901
960
|
const active = context.value === value;
|
|
902
961
|
const slots = tabsVariants({
|
|
903
962
|
variant: context.variant,
|
|
963
|
+
size: context.size,
|
|
904
964
|
active,
|
|
905
965
|
disabled,
|
|
906
966
|
scrollable,
|
|
@@ -948,6 +1008,7 @@ function TabsTrigger({
|
|
|
948
1008
|
disabled={disabled}
|
|
949
1009
|
onPress={() => context.setValue(value)}
|
|
950
1010
|
onLayout={handleLayout}
|
|
1011
|
+
hitSlop={TRIGGER_HIT_SLOP[context.size]}
|
|
951
1012
|
className={cn(slots.trigger(), (icon || badge) && 'flex-row gap-1.5', className)}
|
|
952
1013
|
>
|
|
953
1014
|
{icon}
|
|
@@ -53,9 +53,11 @@ const FOCUS_DURATION = 150;
|
|
|
53
53
|
* them here as well is what lets `rows` and `size` compose.
|
|
54
54
|
*/
|
|
55
55
|
const METRICS = {
|
|
56
|
+
xs: { fontSize: 13, lineHeight: 18, padding: 8 },
|
|
56
57
|
sm: { fontSize: 14, lineHeight: 20, padding: 10 },
|
|
57
58
|
md: { fontSize: 16, lineHeight: 22, padding: 12 },
|
|
58
59
|
lg: { fontSize: 16, lineHeight: 24, padding: 14 },
|
|
60
|
+
xl: { fontSize: 18, lineHeight: 26, padding: 16 },
|
|
59
61
|
} as const;
|
|
60
62
|
|
|
61
63
|
const textareaVariants = tv({
|
|
@@ -82,10 +84,14 @@ const textareaVariants = tv({
|
|
|
82
84
|
outline: { field: 'bg-background' },
|
|
83
85
|
filled: { field: 'bg-muted' },
|
|
84
86
|
},
|
|
87
|
+
// The same horizontal padding and type size as Input at each step, so a
|
|
88
|
+
// one-line field and a multi-line one stacked in a form share an edge.
|
|
85
89
|
size: {
|
|
90
|
+
xs: { field: 'px-2.5 text-[13px]' },
|
|
86
91
|
sm: { field: 'px-3 text-[14px]' },
|
|
87
92
|
md: { field: 'px-3.5 text-[16px]' },
|
|
88
93
|
lg: { field: 'px-4 text-[16px]' },
|
|
94
|
+
xl: { field: 'px-5 text-[18px]' },
|
|
89
95
|
},
|
|
90
96
|
disabled: {
|
|
91
97
|
true: { field: 'opacity-[0.64]' },
|
|
@@ -58,10 +58,14 @@ const toggleVariants = tv({
|
|
|
58
58
|
/** Nothing at rest — for a dense toolbar where six fills would be noise. */
|
|
59
59
|
ghost: { root: 'bg-transparent' },
|
|
60
60
|
},
|
|
61
|
+
// The same five heights as Button, so a toggle and a button side by side
|
|
62
|
+
// in a toolbar are one row rather than two.
|
|
61
63
|
size: {
|
|
64
|
+
xs: { root: 'h-7 gap-1 rounded-md px-2', label: 'text-xs' },
|
|
62
65
|
sm: { root: 'h-9 gap-1.5 px-2.5', label: 'text-sm' },
|
|
63
66
|
md: { root: 'h-11 px-4', label: 'text-base' },
|
|
64
67
|
lg: { root: 'h-12 px-6', label: 'text-lg' },
|
|
68
|
+
xl: { root: 'h-14 px-8', label: 'text-lg' },
|
|
65
69
|
},
|
|
66
70
|
selected: {
|
|
67
71
|
true: { root: 'border-primary/24 bg-accent', label: 'text-accent-foreground' },
|
|
@@ -76,9 +80,11 @@ const toggleVariants = tv({
|
|
|
76
80
|
},
|
|
77
81
|
compoundVariants: [
|
|
78
82
|
// Square, and sized from the height so the icon sits in the middle.
|
|
83
|
+
{ iconOnly: true, size: 'xs', class: { root: 'w-7' } },
|
|
79
84
|
{ iconOnly: true, size: 'sm', class: { root: 'w-9' } },
|
|
80
85
|
{ iconOnly: true, size: 'md', class: { root: 'w-11' } },
|
|
81
86
|
{ iconOnly: true, size: 'lg', class: { root: 'w-12' } },
|
|
87
|
+
{ iconOnly: true, size: 'xl', class: { root: 'w-14' } },
|
|
82
88
|
],
|
|
83
89
|
defaultVariants: {
|
|
84
90
|
variant: 'default',
|
|
@@ -86,6 +92,9 @@ const toggleVariants = tv({
|
|
|
86
92
|
},
|
|
87
93
|
});
|
|
88
94
|
|
|
95
|
+
/** What `xs` is short of a 44pt target on each side. */
|
|
96
|
+
const XS_HIT_SLOP = 8;
|
|
97
|
+
|
|
89
98
|
type ToggleVariantProps = VariantProps<typeof toggleVariants>;
|
|
90
99
|
export type ToggleButtonSize = NonNullable<ToggleVariantProps['size']>;
|
|
91
100
|
export type ToggleButtonVariant = NonNullable<ToggleVariantProps['variant']>;
|
|
@@ -274,6 +283,7 @@ const ToggleButtonRoot = forwardRef<View, ToggleButtonProps>(
|
|
|
274
283
|
selectedClassName,
|
|
275
284
|
unselectedClassName,
|
|
276
285
|
onPress,
|
|
286
|
+
hitSlop,
|
|
277
287
|
...props
|
|
278
288
|
},
|
|
279
289
|
ref
|
|
@@ -291,9 +301,10 @@ const ToggleButtonRoot = forwardRef<View, ToggleButtonProps>(
|
|
|
291
301
|
const isDisabled = disabled || (group?.disabled ?? false);
|
|
292
302
|
const enableHaptics = haptics ?? group?.haptics ?? false;
|
|
293
303
|
|
|
304
|
+
const resolvedSize = size ?? group?.size;
|
|
294
305
|
const slots = toggleVariants({
|
|
295
306
|
variant: variant ?? group?.variant,
|
|
296
|
-
size:
|
|
307
|
+
size: resolvedSize,
|
|
297
308
|
selected,
|
|
298
309
|
iconOnly,
|
|
299
310
|
disabled: isDisabled,
|
|
@@ -342,6 +353,10 @@ const ToggleButtonRoot = forwardRef<View, ToggleButtonProps>(
|
|
|
342
353
|
aria-pressed={selected}
|
|
343
354
|
disabled={isDisabled}
|
|
344
355
|
onPress={handlePress}
|
|
356
|
+
// A 28pt toggle standing alone is given the rest of a 44pt target.
|
|
357
|
+
// Not inside a group, where the slop would reach into its
|
|
358
|
+
// neighbours and take their presses. A caller's own figure wins.
|
|
359
|
+
hitSlop={hitSlop ?? (!group && resolvedSize === 'xs' ? XS_HIT_SLOP : undefined)}
|
|
345
360
|
className={cn(
|
|
346
361
|
slots.root({ className }),
|
|
347
362
|
selected ? selectedClassName : unselectedClassName
|
package/src/icons/index.tsx
CHANGED
|
@@ -113,6 +113,7 @@ import HgQuoteDownIcon from '@hugeicons/core-free-icons/QuoteDownIcon';
|
|
|
113
113
|
import HgReceiptIcon from '@hugeicons/core-free-icons/ReceiptIcon';
|
|
114
114
|
import HgRefreshCcwIcon from '@hugeicons/core-free-icons/RefreshCcwIcon';
|
|
115
115
|
import HgRefreshCwIcon from '@hugeicons/core-free-icons/RefreshCwIcon';
|
|
116
|
+
import HgRotateCwSquareIcon from '@hugeicons/core-free-icons/RotateCwSquareIcon';
|
|
116
117
|
import HgRepeatIcon from '@hugeicons/core-free-icons/RepeatIcon';
|
|
117
118
|
import HgSearch01Icon from '@hugeicons/core-free-icons/Search01Icon';
|
|
118
119
|
import HgSent02Icon from '@hugeicons/core-free-icons/Sent02Icon';
|
|
@@ -379,6 +380,8 @@ export const SendArrowIcon = icon(HgSent02Icon, {
|
|
|
379
380
|
export const TrashIcon = icon(HgDelete02Icon, { size: 16, color: '#737373' });
|
|
380
381
|
export const RotateCcwIcon = icon(HgRefreshCcwIcon, { size: 16, color: '#737373' });
|
|
381
382
|
export const RotateCwIcon = icon(HgRefreshCwIcon, { size: 16, color: '#737373' });
|
|
383
|
+
/** A square with an arrow turning round it — turn an image, rather than refresh. */
|
|
384
|
+
export const RotateSquareIcon = icon(HgRotateCwSquareIcon, { size: 16, color: '#737373' });
|
|
382
385
|
export const RepeatIcon = icon(HgRepeatIcon, { size: 16, color: '#737373' });
|
|
383
386
|
export const PlusSquareIcon = icon(HgPlusSignSquareIcon, { size: 16, color: '#737373' });
|
|
384
387
|
export const EyeIcon = icon(HgEyeIcon, { size: 16, color: '#737373' });
|