@trama-ui/react-native 0.0.0-stage → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +198 -2
- package/dist/accordion.d.ts +29 -0
- package/dist/accordion.js +137 -0
- package/dist/alert.d.ts +30 -0
- package/dist/alert.js +95 -0
- package/dist/avatar.d.ts +36 -0
- package/dist/avatar.js +91 -0
- package/dist/bars.d.ts +44 -0
- package/dist/bars.js +74 -0
- package/dist/button.d.ts +30 -0
- package/dist/button.js +90 -0
- package/dist/calendar.d.ts +71 -0
- package/dist/calendar.js +276 -0
- package/dist/card.d.ts +41 -0
- package/dist/card.js +139 -0
- package/dist/choices.d.ts +87 -0
- package/dist/choices.js +228 -0
- package/dist/collections.d.ts +131 -0
- package/dist/collections.js +230 -0
- package/dist/color-code.d.ts +37 -0
- package/dist/color-code.js +158 -0
- package/dist/compositions.d.ts +110 -0
- package/dist/compositions.js +190 -0
- package/dist/controls.d.ts +85 -0
- package/dist/controls.js +221 -0
- package/dist/drag-drop.d.ts +65 -0
- package/dist/drag-drop.js +482 -0
- package/dist/feedback.d.ts +30 -0
- package/dist/feedback.js +81 -0
- package/dist/file-upload.d.ts +67 -0
- package/dist/file-upload.js +251 -0
- package/dist/generated/icons.d.ts +1037 -0
- package/dist/generated/icons.js +3 -0
- package/dist/generated/tokens.d.ts +64 -0
- package/dist/generated/tokens.js +65 -0
- package/dist/icon.d.ts +31 -0
- package/dist/icon.js +28 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +43 -0
- package/dist/input.d.ts +43 -0
- package/dist/input.js +115 -0
- package/dist/interactive-layout.d.ts +26 -0
- package/dist/interactive-layout.js +117 -0
- package/dist/internal/content.d.ts +17 -0
- package/dist/internal/content.js +24 -0
- package/dist/internal/drag-geometry.d.ts +16 -0
- package/dist/internal/drag-geometry.js +25 -0
- package/dist/internal/keyboard.d.ts +20 -0
- package/dist/internal/keyboard.js +101 -0
- package/dist/internal/motion.d.ts +1 -0
- package/dist/internal/motion.js +24 -0
- package/dist/internal/number-format.d.ts +4 -0
- package/dist/internal/number-format.js +25 -0
- package/dist/internal/pointer-capture.d.ts +1 -0
- package/dist/internal/pointer-capture.js +16 -0
- package/dist/internal/state.d.ts +6 -0
- package/dist/internal/state.js +28 -0
- package/dist/internal/system-drag.d.ts +48 -0
- package/dist/internal/system-drag.js +93 -0
- package/dist/internal/table-drag.d.ts +56 -0
- package/dist/internal/table-drag.js +237 -0
- package/dist/internal/table-editing.d.ts +49 -0
- package/dist/internal/table-editing.js +278 -0
- package/dist/internal/table-editor.d.ts +11 -0
- package/dist/internal/table-editor.js +31 -0
- package/dist/internal/table-grid.d.ts +44 -0
- package/dist/internal/table-grid.js +153 -0
- package/dist/internal/table-model.d.ts +132 -0
- package/dist/internal/table-model.js +231 -0
- package/dist/internal/table-source.d.ts +9 -0
- package/dist/internal/table-source.js +80 -0
- package/dist/internal/tour-target.d.ts +23 -0
- package/dist/internal/tour-target.js +81 -0
- package/dist/keyboard.d.ts +14 -0
- package/dist/keyboard.js +27 -0
- package/dist/layout.d.ts +35 -0
- package/dist/layout.js +77 -0
- package/dist/loader.d.ts +18 -0
- package/dist/loader.js +79 -0
- package/dist/localization.d.ts +106 -0
- package/dist/localization.js +310 -0
- package/dist/media.d.ts +35 -0
- package/dist/media.js +96 -0
- package/dist/menus.d.ts +103 -0
- package/dist/menus.js +422 -0
- package/dist/navigation.d.ts +111 -0
- package/dist/navigation.js +255 -0
- package/dist/overlays.d.ts +97 -0
- package/dist/overlays.js +364 -0
- package/dist/pill.d.ts +33 -0
- package/dist/pill.js +90 -0
- package/dist/progress.d.ts +27 -0
- package/dist/progress.js +154 -0
- package/dist/responsive.d.ts +15 -0
- package/dist/responsive.js +27 -0
- package/dist/select.d.ts +74 -0
- package/dist/select.js +181 -0
- package/dist/separator.d.ts +13 -0
- package/dist/separator.js +34 -0
- package/dist/switch.d.ts +26 -0
- package/dist/switch.js +69 -0
- package/dist/table.d.ts +122 -0
- package/dist/table.js +928 -0
- package/dist/text-fields.d.ts +39 -0
- package/dist/text-fields.js +134 -0
- package/dist/theme.d.ts +47 -0
- package/dist/theme.js +71 -0
- package/dist/transient.d.ts +80 -0
- package/dist/transient.js +273 -0
- package/package.json +50 -4
package/dist/progress.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { Animated, Easing, Text, View } from 'react-native';
|
|
4
|
+
import { useReducedMotion } from './internal/motion.js';
|
|
5
|
+
import { useTramaLocale, useTramaMessages } from './localization.js';
|
|
6
|
+
import { getTone, sizeStep, useTramaAppearance } from './theme.js';
|
|
7
|
+
function ProgressArc({ dimension, thickness, fill, buffer, dashboard, rtl, ink, track, secondary, variant, rotating, }) {
|
|
8
|
+
const reduced = useReducedMotion();
|
|
9
|
+
const phase = useRef(new Animated.Value(0)).current;
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (!rotating || reduced)
|
|
12
|
+
return;
|
|
13
|
+
phase.setValue(0);
|
|
14
|
+
const spin = Animated.loop(Animated.timing(phase, { toValue: 1, duration: 1300, easing: Easing.linear, useNativeDriver: true }));
|
|
15
|
+
spin.start();
|
|
16
|
+
return () => {
|
|
17
|
+
spin.stop();
|
|
18
|
+
phase.setValue(0);
|
|
19
|
+
};
|
|
20
|
+
}, [phase, reduced, rotating]);
|
|
21
|
+
const count = dashboard ? 36 : 48;
|
|
22
|
+
const radius = (dimension - thickness) / 2;
|
|
23
|
+
const degrees = dashboard ? 270 : 360;
|
|
24
|
+
const step = degrees / count;
|
|
25
|
+
const length = Math.max(1, ((radius * step) / 180) * Math.PI + 0.9);
|
|
26
|
+
const interval = (from, to) => Array.from({ length: count }, (_, index) => {
|
|
27
|
+
const start = index / count;
|
|
28
|
+
const end = (index + 1) / count;
|
|
29
|
+
const part = Math.max(0, Math.min(end, to) - Math.max(start, from)) * count;
|
|
30
|
+
if (part <= 0)
|
|
31
|
+
return null;
|
|
32
|
+
const angle = (((dashboard ? 135 : -90) + (index + 0.5) * step) * Math.PI) / 180;
|
|
33
|
+
const segmentWidth = length * part;
|
|
34
|
+
const tone = variant === 'soft' ? secondary : ink;
|
|
35
|
+
return (_jsx(View, { style: {
|
|
36
|
+
position: 'absolute',
|
|
37
|
+
top: dimension / 2 + Math.sin(angle) * radius - thickness / 2,
|
|
38
|
+
left: dimension / 2 + Math.cos(angle) * radius - segmentWidth / 2,
|
|
39
|
+
width: segmentWidth,
|
|
40
|
+
height: thickness,
|
|
41
|
+
transform: [{ rotate: (angle * 180) / Math.PI + 90 + 'deg' }],
|
|
42
|
+
backgroundColor: from === -1 ? track : variant === 'striped' && index % 4 >= 2 ? secondary : tone,
|
|
43
|
+
} }, index));
|
|
44
|
+
});
|
|
45
|
+
const scale = rtl ? -1 : 1;
|
|
46
|
+
return (_jsxs(View, { pointerEvents: "none", style: { width: dimension, height: dimension, transform: [{ scaleX: scale }] }, children: [interval(-1, 1), buffer > fill && (_jsx(View, { style: { position: 'absolute', width: dimension, height: dimension, opacity: 0.35 }, children: interval(0, buffer) })), _jsx(Animated.View, { style: {
|
|
47
|
+
width: dimension,
|
|
48
|
+
height: dimension,
|
|
49
|
+
transform: [
|
|
50
|
+
{
|
|
51
|
+
rotate: phase.interpolate({ inputRange: [0, 1], outputRange: ['0deg', '360deg'] }),
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
}, children: interval(0, rotating ? 0.22 : fill) })] }));
|
|
55
|
+
}
|
|
56
|
+
function IndeterminateBar({ ink, rtl }) {
|
|
57
|
+
const reduced = useReducedMotion();
|
|
58
|
+
const phase = useRef(new Animated.Value(0)).current;
|
|
59
|
+
const [extent, setExtent] = useState(0);
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (reduced)
|
|
62
|
+
return;
|
|
63
|
+
phase.setValue(0);
|
|
64
|
+
const loop = Animated.loop(Animated.timing(phase, { toValue: 1, duration: 1500, easing: Easing.inOut(Easing.ease), useNativeDriver: true }));
|
|
65
|
+
loop.start();
|
|
66
|
+
return () => {
|
|
67
|
+
loop.stop();
|
|
68
|
+
phase.setValue(0);
|
|
69
|
+
};
|
|
70
|
+
}, [reduced, phase]);
|
|
71
|
+
return (_jsx(View, { onLayout: (event) => setExtent(event.nativeEvent.layout.width), style: { width: '100%', height: '100%' }, children: _jsx(Animated.View, { style: {
|
|
72
|
+
width: '33%',
|
|
73
|
+
height: '100%',
|
|
74
|
+
backgroundColor: ink,
|
|
75
|
+
borderRadius: 9999,
|
|
76
|
+
transform: [
|
|
77
|
+
{
|
|
78
|
+
translateX: reduced
|
|
79
|
+
? 0
|
|
80
|
+
: phase.interpolate({
|
|
81
|
+
inputRange: [0, 1],
|
|
82
|
+
outputRange: rtl ? [extent / 3, -extent] : [-extent / 3, extent],
|
|
83
|
+
}),
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
} }) }));
|
|
87
|
+
}
|
|
88
|
+
export function Progress({ value = 0, min = 0, max = 100, bufferValue, label, description, valueText, hideLabel, showValue, indeterminate, size, color, geometry, variant, radius, valuePosition, format, thickness, style, accessibilityLabel, accessibilityHint, ...props }) {
|
|
89
|
+
const { theme, direction, resolve } = useTramaAppearance();
|
|
90
|
+
const messages = useTramaMessages();
|
|
91
|
+
const locale = useTramaLocale();
|
|
92
|
+
const low = Number.isFinite(min) ? min : 0;
|
|
93
|
+
const high = Number.isFinite(max) && max > low ? max : low + 100;
|
|
94
|
+
const amount = Math.min(high, Math.max(low, Number.isFinite(value) ? value : low));
|
|
95
|
+
const fraction = (amount - low) / (high - low);
|
|
96
|
+
const width = `${100 * fraction}%`;
|
|
97
|
+
const buffer = Number.isFinite(bufferValue) ? Math.min(high, Math.max(amount, bufferValue ?? amount)) : amount;
|
|
98
|
+
const tone = getTone(theme, resolve(color, 'accent'));
|
|
99
|
+
const scale = resolve(size, 'md');
|
|
100
|
+
const step = sizeStep[scale];
|
|
101
|
+
const actualLabel = label ?? messages.progress;
|
|
102
|
+
const position = resolve(valuePosition, 'top');
|
|
103
|
+
const shape = resolve(geometry, 'linear');
|
|
104
|
+
const treatment = resolve(variant, 'solid');
|
|
105
|
+
const treatmentInk = treatment === 'soft' ? tone.soft : tone.solid;
|
|
106
|
+
const dimension = 60 + step * 12;
|
|
107
|
+
const resolution = resolve(thickness, theme.space * (shape === 'linear' ? 2 + step * 0.5 : 1.5));
|
|
108
|
+
const weight = Number.isFinite(resolution) ? Math.min(dimension / 3, Math.max(1, resolution)) : 6;
|
|
109
|
+
const rounding = { none: 0, sm: theme.radius / 2, md: theme.radius, full: 9999 }[resolve(radius, 'full')];
|
|
110
|
+
const number = new Intl.NumberFormat(locale);
|
|
111
|
+
const pattern = resolve(format, 'percent');
|
|
112
|
+
const text = valueText ??
|
|
113
|
+
(pattern === 'value-max'
|
|
114
|
+
? number.format(amount) + ' / ' + number.format(high)
|
|
115
|
+
: pattern === 'value'
|
|
116
|
+
? number.format(amount)
|
|
117
|
+
: new Intl.NumberFormat(locale, { style: 'percent', maximumFractionDigits: 0 }).format(fraction));
|
|
118
|
+
const show = !indeterminate && resolve(showValue, false);
|
|
119
|
+
const textStyle = { color: theme.colors.text, fontSize: theme.fontSize, fontFamily: theme.fontFamily };
|
|
120
|
+
return (_jsxs(View, { ...props, accessible: true, accessibilityRole: "progressbar", accessibilityLabel: accessibilityLabel ?? actualLabel, accessibilityHint: accessibilityHint ?? description, "aria-valuemin": indeterminate ? undefined : low, "aria-valuemax": indeterminate ? undefined : high, "aria-valuenow": indeterminate ? undefined : amount, "aria-valuetext": indeterminate ? undefined : valueText, "aria-busy": Boolean(indeterminate), accessibilityValue: indeterminate ? undefined : valueText ? { text: valueText } : { min: low, max: high, now: amount }, accessibilityState: { busy: Boolean(indeterminate) }, style: [{ direction, gap: theme.space }, style], children: [(!hideLabel || (show && position === 'top')) && (_jsxs(View, { style: { flexDirection: 'row', flexWrap: 'wrap', justifyContent: 'space-between', gap: theme.space }, children: [!hideLabel && _jsx(Text, { style: textStyle, children: actualLabel }), show && position === 'top' && _jsx(Text, { style: textStyle, children: text })] })), shape !== 'linear' ? (_jsxs(View, { style: {
|
|
121
|
+
width: dimension,
|
|
122
|
+
height: dimension,
|
|
123
|
+
alignSelf: 'flex-start',
|
|
124
|
+
alignItems: 'center',
|
|
125
|
+
justifyContent: 'center',
|
|
126
|
+
}, children: [_jsx(ProgressArc, { dimension: dimension, thickness: weight, fill: indeterminate ? 0.25 : fraction, buffer: (buffer - low) / (high - low), dashboard: shape === 'dashboard', rtl: direction === 'rtl', ink: tone.solid, secondary: tone.soft, track: theme.colors.border, variant: treatment, rotating: Boolean(indeterminate && shape !== 'dashboard') }), show && position === 'inside' && (_jsx(Text, { style: [textStyle, { position: 'absolute', fontSize: theme.fontSize - 2 }], children: text }))] })) : (_jsxs(View, { style: {
|
|
127
|
+
height: show && position === 'inside' ? Math.max(weight, theme.fontSize + theme.space) : weight,
|
|
128
|
+
borderRadius: rounding,
|
|
129
|
+
backgroundColor: theme.colors.subtle,
|
|
130
|
+
overflow: 'hidden',
|
|
131
|
+
justifyContent: 'center',
|
|
132
|
+
alignItems: 'flex-start',
|
|
133
|
+
}, children: [!indeterminate && buffer > amount && (_jsx(View, { style: {
|
|
134
|
+
height: '100%',
|
|
135
|
+
width: `${(100 * (buffer - low)) / (high - low)}%`,
|
|
136
|
+
backgroundColor: tone.solid,
|
|
137
|
+
opacity: 0.25,
|
|
138
|
+
position: 'absolute',
|
|
139
|
+
start: 0,
|
|
140
|
+
} })), indeterminate ? (_jsx(IndeterminateBar, { ink: treatmentInk, rtl: direction === 'rtl' })) : (_jsx(View, { style: {
|
|
141
|
+
height: '100%',
|
|
142
|
+
width,
|
|
143
|
+
backgroundColor: treatmentInk,
|
|
144
|
+
borderRadius: rounding,
|
|
145
|
+
overflow: 'hidden',
|
|
146
|
+
}, children: treatment === 'striped' && (_jsx(View, { pointerEvents: "none", style: { position: 'absolute', inset: 0, flexDirection: 'row', opacity: 0.3 }, children: Array.from({ length: 36 }, (_, index) => (_jsx(View, { style: { flex: 1, backgroundColor: index % 2 ? tone.ink : 'transparent' } }, index))) })) })), show && position === 'inside' && (_jsx(Text, { style: [
|
|
147
|
+
textStyle,
|
|
148
|
+
{
|
|
149
|
+
position: 'absolute',
|
|
150
|
+
alignSelf: 'center',
|
|
151
|
+
color: fraction >= 0.63 && treatment !== 'soft' ? tone.ink : theme.colors.text,
|
|
152
|
+
},
|
|
153
|
+
], children: text }))] })), show && position === 'bottom' && _jsx(Text, { style: textStyle, children: text }), description && _jsx(Text, { style: { ...textStyle, color: theme.colors.muted }, children: description })] }));
|
|
154
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const defaultTramaBreakpoints: {
|
|
2
|
+
readonly sm: 640;
|
|
3
|
+
readonly md: 768;
|
|
4
|
+
readonly lg: 1024;
|
|
5
|
+
readonly xl: 1280;
|
|
6
|
+
readonly "2xl": 1536;
|
|
7
|
+
};
|
|
8
|
+
declare const breakpoints: readonly ["sm", "md", "lg", "xl", "2xl"];
|
|
9
|
+
export type TramaBreakpoint = (typeof breakpoints)[number];
|
|
10
|
+
export type TramaBreakpoints = Readonly<Record<TramaBreakpoint, number>>;
|
|
11
|
+
export type TramaResponsiveMap<T> = Readonly<Partial<Record<'base' | TramaBreakpoint, T>>>;
|
|
12
|
+
export type TramaResponsive<T> = T | TramaResponsiveMap<T>;
|
|
13
|
+
export declare function resolveResponsive<T extends string | number | boolean>(value: TramaResponsive<T> | undefined, fallback: T, width: number, minimums?: TramaBreakpoints): T;
|
|
14
|
+
export declare function resolveBreakpoints(overrides: Partial<TramaBreakpoints>, inherited: TramaBreakpoints): TramaBreakpoints;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { tokens } from './generated/tokens.js';
|
|
2
|
+
export const defaultTramaBreakpoints = tokens.breakpoints;
|
|
3
|
+
const breakpoints = ['sm', 'md', 'lg', 'xl', '2xl'];
|
|
4
|
+
export function resolveResponsive(value, fallback, width, minimums = defaultTramaBreakpoints) {
|
|
5
|
+
if (value == null)
|
|
6
|
+
return fallback;
|
|
7
|
+
if (typeof value !== 'object')
|
|
8
|
+
return value;
|
|
9
|
+
let resolved = value.base ?? fallback;
|
|
10
|
+
for (const key of breakpoints) {
|
|
11
|
+
const override = value[key];
|
|
12
|
+
if (width >= minimums[key] && override !== undefined)
|
|
13
|
+
resolved = override;
|
|
14
|
+
}
|
|
15
|
+
return resolved;
|
|
16
|
+
}
|
|
17
|
+
export function resolveBreakpoints(overrides, inherited) {
|
|
18
|
+
const resolved = { ...inherited, ...overrides };
|
|
19
|
+
let previous = -1;
|
|
20
|
+
for (const key of breakpoints) {
|
|
21
|
+
if (!Number.isFinite(resolved[key]) || resolved[key] < 0 || resolved[key] <= previous) {
|
|
22
|
+
throw new RangeError('Trama breakpoints must be non-negative and increase from sm through 2xl.');
|
|
23
|
+
}
|
|
24
|
+
previous = resolved[key];
|
|
25
|
+
}
|
|
26
|
+
return resolved;
|
|
27
|
+
}
|
package/dist/select.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type ViewProps } from 'react-native';
|
|
3
|
+
import { type FieldHandle } from './input.js';
|
|
4
|
+
import { type TramaSize } from './theme.js';
|
|
5
|
+
import type { TramaResponsive } from './responsive.js';
|
|
6
|
+
export type SelectSelection = string | readonly string[];
|
|
7
|
+
export interface SelectOptionData {
|
|
8
|
+
value: string;
|
|
9
|
+
label: string;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
group?: string;
|
|
12
|
+
content?: ReactNode;
|
|
13
|
+
}
|
|
14
|
+
export interface SelectProps extends ViewProps {
|
|
15
|
+
label?: string;
|
|
16
|
+
placeholder?: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
hint?: string;
|
|
19
|
+
required?: boolean;
|
|
20
|
+
readOnly?: boolean;
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
invalid?: boolean;
|
|
23
|
+
error?: string;
|
|
24
|
+
options?: readonly SelectOptionData[];
|
|
25
|
+
value?: SelectSelection;
|
|
26
|
+
defaultValue?: SelectSelection;
|
|
27
|
+
onValueChange?: (value: SelectSelection) => void | false;
|
|
28
|
+
multiple?: boolean;
|
|
29
|
+
searchable?: boolean;
|
|
30
|
+
freeSolo?: boolean;
|
|
31
|
+
clearable?: boolean;
|
|
32
|
+
autoHighlight?: boolean;
|
|
33
|
+
closeOnSelect?: boolean;
|
|
34
|
+
open?: boolean;
|
|
35
|
+
defaultOpen?: boolean;
|
|
36
|
+
onOpenChange?: (open: boolean) => void | false;
|
|
37
|
+
query?: string;
|
|
38
|
+
defaultQuery?: string;
|
|
39
|
+
onQueryChange?: (query: string) => void;
|
|
40
|
+
filterOption?: (option: SelectOptionData, query: string) => boolean;
|
|
41
|
+
renderOption?: (option: SelectOptionData) => ReactNode;
|
|
42
|
+
renderValue?: (option: SelectOptionData) => ReactNode;
|
|
43
|
+
loading?: boolean;
|
|
44
|
+
noResults?: string;
|
|
45
|
+
size?: TramaResponsive<TramaSize>;
|
|
46
|
+
variant?: TramaResponsive<'outlined' | 'filled' | 'flushed'>;
|
|
47
|
+
}
|
|
48
|
+
export interface SelectOptionProps extends SelectOptionData {
|
|
49
|
+
children?: ReactNode;
|
|
50
|
+
}
|
|
51
|
+
export declare function SelectOption({ children, label }: SelectOptionProps): import("react").JSX.Element;
|
|
52
|
+
export interface SelectGroupProps extends ViewProps {
|
|
53
|
+
label: string;
|
|
54
|
+
}
|
|
55
|
+
export declare function SelectGroup({ children, label, ...props }: SelectGroupProps): import("react").JSX.Element;
|
|
56
|
+
export interface SelectValueProps extends ViewProps {
|
|
57
|
+
value: string;
|
|
58
|
+
}
|
|
59
|
+
export declare function SelectValue({ value: _value, ...props }: SelectValueProps): import("react").JSX.Element;
|
|
60
|
+
export declare function SelectStart(props: ViewProps): import("react").JSX.Element;
|
|
61
|
+
export declare const Select: import("react").ForwardRefExoticComponent<SelectProps & import("react").RefAttributes<FieldHandle>>;
|
|
62
|
+
export declare const Combobox: import("react").ForwardRefExoticComponent<SelectProps & import("react").RefAttributes<FieldHandle>>;
|
|
63
|
+
export declare const MultiSelect: import("react").ForwardRefExoticComponent<SelectProps & import("react").RefAttributes<FieldHandle>>;
|
|
64
|
+
export interface MentionOptionProps extends ViewProps {
|
|
65
|
+
value: string;
|
|
66
|
+
label: string;
|
|
67
|
+
}
|
|
68
|
+
export declare function MentionOption({ children, label }: MentionOptionProps): import("react").JSX.Element;
|
|
69
|
+
export interface MentionFieldProps extends Omit<import('./input.js').InputProps, 'children'> {
|
|
70
|
+
children?: ReactNode;
|
|
71
|
+
options?: readonly SelectOptionData[];
|
|
72
|
+
onMention?: (value: string) => void;
|
|
73
|
+
}
|
|
74
|
+
export declare const MentionField: import("react").ForwardRefExoticComponent<MentionFieldProps & import("react").RefAttributes<import("./input.js").InputHandle>>;
|
package/dist/select.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Children, forwardRef, isValidElement, useImperativeHandle } from 'react';
|
|
3
|
+
import { Pressable, Text, View } from 'react-native';
|
|
4
|
+
import { Button } from './button.js';
|
|
5
|
+
import { Input } from './input.js';
|
|
6
|
+
import { FieldMessage, splitContent, TextContent } from './internal/content.js';
|
|
7
|
+
import { useControllableValue, useFieldValidation } from './internal/state.js';
|
|
8
|
+
import { Stack } from './layout.js';
|
|
9
|
+
import { Loader } from './loader.js';
|
|
10
|
+
import { useTramaMessages } from './localization.js';
|
|
11
|
+
import { Dialog, DialogClose, DialogFooter } from './overlays.js';
|
|
12
|
+
import { Pill } from './pill.js';
|
|
13
|
+
import { getTone, useTramaAppearance, useTramaTheme } from './theme.js';
|
|
14
|
+
export function SelectOption({ children, label }) {
|
|
15
|
+
return _jsx(TextContent, { children: children ?? label });
|
|
16
|
+
}
|
|
17
|
+
export function SelectGroup({ children, label, ...props }) {
|
|
18
|
+
const theme = useTramaTheme();
|
|
19
|
+
return (_jsxs(Stack, { ...props, gap: "xs", children: [_jsx(Text, { style: { color: theme.colors.muted }, children: label }), children] }));
|
|
20
|
+
}
|
|
21
|
+
export function SelectValue({ value: _value, ...props }) {
|
|
22
|
+
return _jsx(View, { ...props });
|
|
23
|
+
}
|
|
24
|
+
export function SelectStart(props) {
|
|
25
|
+
return _jsx(View, { ...props });
|
|
26
|
+
}
|
|
27
|
+
function optionRecords(children, group) {
|
|
28
|
+
return Children.toArray(children).flatMap((child) => {
|
|
29
|
+
if (isValidElement(child) && child.type === SelectOption) {
|
|
30
|
+
return [
|
|
31
|
+
{
|
|
32
|
+
value: child.props.value,
|
|
33
|
+
label: child.props.label,
|
|
34
|
+
disabled: child.props.disabled,
|
|
35
|
+
group: child.props.group ?? group,
|
|
36
|
+
content: child.props.children ?? child.props.content,
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
if (isValidElement(child) && child.type === SelectGroup)
|
|
41
|
+
return optionRecords(child.props.children, child.props.label);
|
|
42
|
+
return [];
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
export const Select = forwardRef(function Select({ label, placeholder, description, hint, required, readOnly, disabled, invalid, error, options, value, defaultValue, onValueChange, multiple, searchable, freeSolo, clearable, autoHighlight, closeOnSelect, open, defaultOpen, onOpenChange, query, defaultQuery, onQueryChange, filterOption, renderOption, renderValue, loading, noResults, size, variant, children, ...props }, ref) {
|
|
46
|
+
const { theme, direction, resolve } = useTramaAppearance();
|
|
47
|
+
const messages = useTramaMessages();
|
|
48
|
+
const [owned, change] = useControllableValue(value, defaultValue ?? (multiple ? [] : ''));
|
|
49
|
+
const [visible, setOpen] = useControllableValue(open, defaultOpen ?? false);
|
|
50
|
+
const [search, setSearch] = useControllableValue(query, defaultQuery ?? '', onQueryChange);
|
|
51
|
+
const { body, named } = splitContent(children, { values: SelectValue, start: SelectStart });
|
|
52
|
+
const distinct = new Map();
|
|
53
|
+
for (const option of options ?? optionRecords(body))
|
|
54
|
+
if (option.value && !distinct.has(option.value))
|
|
55
|
+
distinct.set(option.value, option);
|
|
56
|
+
const list = [...distinct.values()];
|
|
57
|
+
const desired = typeof owned === 'string' ? (owned ? [owned] : []) : owned;
|
|
58
|
+
const deduped = [...new Set(desired)];
|
|
59
|
+
const picked = multiple ? deduped : deduped.slice(0, 1);
|
|
60
|
+
const filter = search.trim();
|
|
61
|
+
const filtered = !filter
|
|
62
|
+
? list
|
|
63
|
+
: list.filter((option) => filterOption?.(option, filter) ?? option.label.toLocaleLowerCase().includes(filter.toLocaleLowerCase()));
|
|
64
|
+
const first = autoHighlight && filter ? filtered.find((option) => !option.disabled)?.value : undefined;
|
|
65
|
+
const candidate = freeSolo && filter && !list.some((item) => item.value.toLocaleLowerCase() === filter.toLocaleLowerCase())
|
|
66
|
+
? filter
|
|
67
|
+
: '';
|
|
68
|
+
const locked = Boolean(disabled || readOnly);
|
|
69
|
+
const validation = useFieldValidation(error?.trim() || (invalid ? messages.reviewField : ''), required && !picked.length ? messages.chooseOption : '', locked);
|
|
70
|
+
const fieldLabel = label ?? placeholder ?? messages.chooseOption;
|
|
71
|
+
const appearance = resolve(variant, 'outlined');
|
|
72
|
+
const step = resolve(size, 'md');
|
|
73
|
+
const enabled = (option) => !option.disabled && !locked;
|
|
74
|
+
useImperativeHandle(ref, () => ({
|
|
75
|
+
checkValidity: validation.checkValidity,
|
|
76
|
+
reportValidity: validation.reportValidity,
|
|
77
|
+
}));
|
|
78
|
+
function setVisible(next) {
|
|
79
|
+
if (next === visible || (next && locked) || onOpenChange?.(next) === false)
|
|
80
|
+
return;
|
|
81
|
+
setOpen(next);
|
|
82
|
+
if (!next)
|
|
83
|
+
setSearch('');
|
|
84
|
+
}
|
|
85
|
+
function commit(next) {
|
|
86
|
+
if (locked)
|
|
87
|
+
return false;
|
|
88
|
+
const output = multiple ? next : (next[0] ?? '');
|
|
89
|
+
if (onValueChange?.(output) === false)
|
|
90
|
+
return false;
|
|
91
|
+
change(output);
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
function choose(option) {
|
|
95
|
+
if (!enabled(option))
|
|
96
|
+
return;
|
|
97
|
+
const next = !multiple
|
|
98
|
+
? [option.value]
|
|
99
|
+
: picked.includes(option.value)
|
|
100
|
+
? picked.filter((id) => id !== option.value)
|
|
101
|
+
: [...picked, option.value];
|
|
102
|
+
if (commit(next) && (closeOnSelect ?? !multiple))
|
|
103
|
+
setVisible(false);
|
|
104
|
+
}
|
|
105
|
+
function getDisplay(id) {
|
|
106
|
+
const choice = distinct.get(id) ?? { value: id, label: id };
|
|
107
|
+
const replacement = named.values?.find((part) => isValidElement(part) && part.props.value === id);
|
|
108
|
+
return replacement ?? renderValue?.(choice) ?? choice.label;
|
|
109
|
+
}
|
|
110
|
+
return (_jsxs(Stack, { ...props, gap: "xs", children: [label && (_jsxs(Text, { style: { color: theme.colors.text, fontWeight: '600' }, children: [label, required ? ' *' : ''] })), description && _jsx(Text, { style: { color: theme.colors.muted }, children: description }), _jsxs(View, { style: {
|
|
111
|
+
direction,
|
|
112
|
+
flexDirection: 'row',
|
|
113
|
+
alignItems: 'center',
|
|
114
|
+
flexWrap: 'wrap',
|
|
115
|
+
padding: theme.space * 2,
|
|
116
|
+
borderColor: validation.message ? theme.colors.danger : theme.colors.border,
|
|
117
|
+
borderWidth: appearance === 'flushed' ? 0 : 1,
|
|
118
|
+
borderBottomWidth: 1,
|
|
119
|
+
borderRadius: appearance === 'flushed' ? 0 : theme.radius,
|
|
120
|
+
backgroundColor: appearance === 'filled' ? theme.colors.subtle : theme.colors.surface,
|
|
121
|
+
gap: theme.space,
|
|
122
|
+
}, children: [named.start, multiple &&
|
|
123
|
+
picked.map((id) => (_jsx(Pill, { size: step, onRemove: locked ? undefined : () => commit(picked.filter((entry) => entry !== id)), removeLabel: `${messages.removeItem}: ${distinct.get(id)?.label ?? id}`, children: getDisplay(id) }, id))), _jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: fieldLabel, accessibilityHint: validation.message ||
|
|
124
|
+
hint ||
|
|
125
|
+
(picked.length && !multiple ? (distinct.get(picked[0])?.label ?? picked[0]) : undefined), accessibilityState: { expanded: visible, disabled: locked }, "aria-expanded": visible, "aria-disabled": locked, disabled: locked, onPress: () => setVisible(true), style: {
|
|
126
|
+
minHeight: 44,
|
|
127
|
+
flex: 1,
|
|
128
|
+
minWidth: 44,
|
|
129
|
+
flexDirection: 'row',
|
|
130
|
+
alignItems: 'center',
|
|
131
|
+
gap: theme.space * 2,
|
|
132
|
+
justifyContent: 'space-between',
|
|
133
|
+
}, children: [_jsx(TextContent, { style: { color: picked.length ? theme.colors.text : theme.colors.muted, flexShrink: 1 }, children: !multiple && picked.length ? getDisplay(picked[0]) : (placeholder ?? messages.chooseOption) }), _jsx(Text, { accessible: false, style: { color: theme.colors.text }, children: "\u2304" })] }), clearable && picked.length > 0 && !locked && (_jsx(Button, { variant: "text", size: "sm", accessibilityLabel: messages.clearSelection, onPress: () => commit([]), children: "\u00D7" }))] }), _jsx(FieldMessage, { message: validation.message || hint || '', invalid: Boolean(validation.message), theme: theme }), _jsxs(Dialog, { heading: fieldLabel, placement: "bottom", open: visible && !locked, onOpenChange: setVisible, children: [(searchable || freeSolo) && (_jsx(Input, { label: messages.search, autoFocus: true, value: search, onChangeText: setSearch, onSubmitEditing: () => {
|
|
134
|
+
const option = filtered.find((entry) => entry.value === first || entry.label.toLocaleLowerCase() === filter.toLocaleLowerCase());
|
|
135
|
+
if (option)
|
|
136
|
+
choose(option);
|
|
137
|
+
else if (candidate)
|
|
138
|
+
choose({ value: candidate, label: candidate });
|
|
139
|
+
} })), loading && _jsx(Loader, { showLabel: true }), !loading && !filtered.length && !candidate && (_jsx(Text, { style: { color: theme.colors.muted }, children: noResults ?? messages.noResults })), !loading &&
|
|
140
|
+
filtered.map((option, index) => {
|
|
141
|
+
const checked = picked.includes(option.value);
|
|
142
|
+
const showGroup = option.group && option.group !== filtered[index - 1]?.group;
|
|
143
|
+
return (_jsxs(View, { children: [showGroup && (_jsx(Text, { accessibilityRole: "header", style: { color: theme.colors.muted, padding: theme.space * 2 }, children: option.group })), _jsxs(Pressable, { accessibilityRole: multiple ? 'checkbox' : 'radio', accessibilityLabel: option.label, accessibilityState: { checked, disabled: !enabled(option) }, "aria-checked": checked, "aria-disabled": !enabled(option), disabled: !enabled(option), onPress: () => choose(option), style: {
|
|
144
|
+
minHeight: 44,
|
|
145
|
+
padding: theme.space * 2,
|
|
146
|
+
flexDirection: 'row',
|
|
147
|
+
alignItems: 'center',
|
|
148
|
+
justifyContent: 'space-between',
|
|
149
|
+
borderRadius: theme.radius,
|
|
150
|
+
backgroundColor: checked || first === option.value ? theme.colors.subtle : theme.colors.surface,
|
|
151
|
+
opacity: enabled(option) ? 1 : 0.55,
|
|
152
|
+
}, children: [_jsx(TextContent, { style: { color: theme.colors.text }, children: renderOption?.(option) ?? option.content ?? option.label }), checked && (_jsx(Text, { accessible: false, style: { color: getTone(theme, 'accent').text }, children: "\u2713" }))] })] }, option.value));
|
|
153
|
+
}), !loading && candidate && (_jsx(Button, { variant: "text", onPress: () => choose({ value: candidate, label: candidate }), children: messages.addOption(candidate) })), _jsx(DialogFooter, { children: _jsx(DialogClose, {}) })] })] }));
|
|
154
|
+
});
|
|
155
|
+
export const Combobox = forwardRef(function Combobox(props, ref) {
|
|
156
|
+
return _jsx(Select, { searchable: true, ...props, ref: ref });
|
|
157
|
+
});
|
|
158
|
+
export const MultiSelect = forwardRef(function MultiSelect(props, ref) {
|
|
159
|
+
return _jsx(Select, { ...props, multiple: true, ref: ref });
|
|
160
|
+
});
|
|
161
|
+
export function MentionOption({ children, label }) {
|
|
162
|
+
return _jsx(TextContent, { children: children ?? label });
|
|
163
|
+
}
|
|
164
|
+
export const MentionField = forwardRef(function MentionField({ value, defaultValue, onChangeText, options, onMention, children, ...props }, ref) {
|
|
165
|
+
const [text, request] = useControllableValue(value, defaultValue ?? '', onChangeText);
|
|
166
|
+
const theme = useTramaTheme();
|
|
167
|
+
const match = /(?:^|\s)@([^\s@]*)$/u.exec(text);
|
|
168
|
+
const list = options ??
|
|
169
|
+
Children.toArray(children).flatMap((part) => isValidElement(part) && part.type === MentionOption
|
|
170
|
+
? [{ value: part.props.value, label: part.props.label, content: part.props.children }]
|
|
171
|
+
: []);
|
|
172
|
+
const choices = match
|
|
173
|
+
? list.filter((option) => option.label.toLocaleLowerCase().includes(match[1].toLocaleLowerCase())).slice(0, 10)
|
|
174
|
+
: [];
|
|
175
|
+
return (_jsxs(Stack, { gap: "xs", children: [_jsx(Input, { ...props, ref: ref, value: text, onChangeText: request }), !props.disabled &&
|
|
176
|
+
!props.readOnly &&
|
|
177
|
+
choices.map((option) => (_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: option.label, style: { minHeight: 44, justifyContent: 'center' }, onPress: () => {
|
|
178
|
+
request(text.slice(0, -((match?.[1].length ?? 0) + 1)) + `@${option.value} `);
|
|
179
|
+
onMention?.(option.value);
|
|
180
|
+
}, children: _jsx(TextContent, { style: { color: theme.colors.accent }, children: option.content ?? option.label }) }, option.value)))] }));
|
|
181
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ViewProps } from 'react-native';
|
|
2
|
+
import type { TramaResponsive } from './responsive.js';
|
|
3
|
+
import { type TramaSize } from './theme.js';
|
|
4
|
+
export interface SeparatorProps extends Omit<ViewProps, 'children'> {
|
|
5
|
+
orientation?: TramaResponsive<'horizontal' | 'vertical'>;
|
|
6
|
+
variant?: TramaResponsive<'solid' | 'dashed' | 'dotted'>;
|
|
7
|
+
size?: TramaResponsive<TramaSize>;
|
|
8
|
+
color?: TramaResponsive<'subtle' | 'neutral' | 'accent'>;
|
|
9
|
+
spacing?: TramaResponsive<'none' | TramaSize>;
|
|
10
|
+
label?: string;
|
|
11
|
+
labelPosition?: TramaResponsive<'start' | 'center' | 'end'>;
|
|
12
|
+
}
|
|
13
|
+
export declare function Separator({ orientation, variant, size, color, spacing, label, labelPosition, style, ...props }: SeparatorProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Text, View } from 'react-native';
|
|
3
|
+
import { useTramaAppearance } from './theme.js';
|
|
4
|
+
export function Separator({ orientation, variant, size, color, spacing, label, labelPosition, style, ...props }) {
|
|
5
|
+
const { theme, direction, resolve } = useTramaAppearance();
|
|
6
|
+
const vertical = resolve(orientation, 'horizontal') === 'vertical';
|
|
7
|
+
const stroke = { sm: 1, md: 2, lg: 3 }[resolve(size, 'sm')];
|
|
8
|
+
const borderColor = { subtle: theme.colors.border, neutral: theme.colors.muted, accent: theme.colors.accent }[resolve(color, 'subtle')];
|
|
9
|
+
const margin = theme.space * { none: 0, sm: 1, md: 2, lg: 4 }[resolve(spacing, 'none')];
|
|
10
|
+
const position = resolve(labelPosition, 'center');
|
|
11
|
+
const line = {
|
|
12
|
+
flexGrow: 1,
|
|
13
|
+
minWidth: vertical ? 0 : theme.space * 2,
|
|
14
|
+
minHeight: vertical ? theme.space * 2 : 0,
|
|
15
|
+
borderColor,
|
|
16
|
+
borderStyle: resolve(variant, 'solid'),
|
|
17
|
+
// Draw the far edge outside the clipped line. Android otherwise renders
|
|
18
|
+
// dashed and dotted styles as solid on a single border.
|
|
19
|
+
borderWidth: stroke,
|
|
20
|
+
};
|
|
21
|
+
const renderLine = () => (_jsx(View, { style: { flex: 1, overflow: 'hidden', ...(vertical ? { width: stroke } : { height: stroke }) }, children: _jsx(View, { style: [line, vertical ? { width: stroke * 3 } : { height: stroke * 3 }] }) }));
|
|
22
|
+
return (_jsxs(View, { ...props, accessible: false, style: [
|
|
23
|
+
{
|
|
24
|
+
direction,
|
|
25
|
+
flexDirection: vertical ? 'column' : 'row',
|
|
26
|
+
alignItems: 'center',
|
|
27
|
+
alignSelf: 'stretch',
|
|
28
|
+
gap: label ? theme.space * 2 : 0,
|
|
29
|
+
marginHorizontal: vertical ? margin : 0,
|
|
30
|
+
marginVertical: vertical ? 0 : margin,
|
|
31
|
+
},
|
|
32
|
+
style,
|
|
33
|
+
], children: [(!label || position !== 'start') && renderLine(), label && (_jsx(Text, { style: { fontSize: theme.fontSize, fontFamily: theme.fontFamily, color: theme.colors.muted }, children: label })), label && position !== 'end' && renderLine()] }));
|
|
34
|
+
}
|
package/dist/switch.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type PressableProps, type ViewProps } from 'react-native';
|
|
2
|
+
import type { FieldHandle } from './input.js';
|
|
3
|
+
import type { TramaResponsive } from './responsive.js';
|
|
4
|
+
import { type TramaColor, type TramaShape, type TramaSize } from './theme.js';
|
|
5
|
+
export type SwitchVariant = 'solid' | 'soft' | 'outlined';
|
|
6
|
+
export interface SwitchProps extends Omit<PressableProps, 'children' | 'onPress'> {
|
|
7
|
+
indicator?: React.ReactNode | ((checked: boolean) => React.ReactNode);
|
|
8
|
+
label?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
hint?: string;
|
|
11
|
+
error?: string;
|
|
12
|
+
invalid?: boolean;
|
|
13
|
+
required?: boolean;
|
|
14
|
+
readOnly?: boolean;
|
|
15
|
+
checked?: boolean;
|
|
16
|
+
defaultChecked?: boolean;
|
|
17
|
+
onCheckedChange?: (checked: boolean) => void;
|
|
18
|
+
labelPlacement?: TramaResponsive<'start' | 'end'>;
|
|
19
|
+
size?: TramaResponsive<TramaSize>;
|
|
20
|
+
variant?: TramaResponsive<SwitchVariant>;
|
|
21
|
+
color?: TramaResponsive<TramaColor>;
|
|
22
|
+
shape?: TramaResponsive<TramaShape>;
|
|
23
|
+
containerStyle?: ViewProps['style'];
|
|
24
|
+
}
|
|
25
|
+
export declare const Switch: import("react").ForwardRefExoticComponent<SwitchProps & import("react").RefAttributes<FieldHandle>>;
|
|
26
|
+
export declare function SwitchIndicator(props: ViewProps): import("react").JSX.Element;
|
package/dist/switch.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useImperativeHandle, useState } from 'react';
|
|
3
|
+
import { Pressable, Text, View } from 'react-native';
|
|
4
|
+
import { FieldMessage } from './internal/content.js';
|
|
5
|
+
import { useControllableValue, useFieldValidation } from './internal/state.js';
|
|
6
|
+
import { useTramaMessages } from './localization.js';
|
|
7
|
+
import { getTone, shapeRadius, sizeStep, useTramaAppearance, } from './theme.js';
|
|
8
|
+
export const Switch = forwardRef(function Switch({ label, description, hint, invalid, error, disabled, readOnly, required, checked, indicator, defaultChecked, onCheckedChange, labelPlacement, size, variant, color, shape, style, containerStyle, accessibilityLabel, accessibilityHint, accessibilityState, onFocus, onBlur, ...props }, ref) {
|
|
9
|
+
const { theme, direction, resolve } = useTramaAppearance();
|
|
10
|
+
const messages = useTramaMessages();
|
|
11
|
+
const [active, request] = useControllableValue(checked, defaultChecked ?? false, onCheckedChange);
|
|
12
|
+
const [focused, setFocused] = useState(false);
|
|
13
|
+
const explicit = error?.trim() || (invalid ? messages.reviewField : '');
|
|
14
|
+
const validation = useFieldValidation(explicit, required && !active ? messages.turnOn : '', Boolean(disabled || readOnly));
|
|
15
|
+
const shownMessage = validation.message || hint;
|
|
16
|
+
const step = sizeStep[resolve(size, 'md')];
|
|
17
|
+
const trackHeight = theme.space * (6 + step);
|
|
18
|
+
const trackWidth = theme.space * (11 + step);
|
|
19
|
+
const tone = getTone(theme, resolve(color, 'accent'));
|
|
20
|
+
const appearance = resolve(variant, 'solid');
|
|
21
|
+
const radius = shapeRadius(theme, resolve(shape, 'pill'));
|
|
22
|
+
const filled = appearance === 'solid' && active;
|
|
23
|
+
const line = validation.message ? theme.colors.danger : active || focused ? tone.solid : theme.colors.border;
|
|
24
|
+
useImperativeHandle(ref, () => ({
|
|
25
|
+
checkValidity: validation.checkValidity,
|
|
26
|
+
reportValidity: validation.reportValidity,
|
|
27
|
+
}));
|
|
28
|
+
return (_jsxs(View, { style: [{ direction, gap: theme.space }, containerStyle], children: [_jsxs(Pressable, { ...props, accessibilityRole: "switch", accessibilityLabel: accessibilityLabel ?? label, "aria-checked": active, "aria-disabled": Boolean(disabled || readOnly), accessibilityHint: [required && messages.requiredLabel, description, shownMessage, accessibilityHint]
|
|
29
|
+
.filter(Boolean)
|
|
30
|
+
.join('. ') || undefined, accessibilityState: { ...accessibilityState, checked: active, disabled: Boolean(disabled || readOnly) }, disabled: disabled || readOnly, onPress: () => {
|
|
31
|
+
if (!disabled && !readOnly)
|
|
32
|
+
request(!active);
|
|
33
|
+
}, onFocus: (event) => {
|
|
34
|
+
setFocused(true);
|
|
35
|
+
onFocus?.(event);
|
|
36
|
+
}, onBlur: (event) => {
|
|
37
|
+
setFocused(false);
|
|
38
|
+
onBlur?.(event);
|
|
39
|
+
}, style: (state) => [
|
|
40
|
+
{
|
|
41
|
+
flexDirection: resolve(labelPlacement, 'end') === 'start' ? 'row-reverse' : 'row',
|
|
42
|
+
alignItems: 'center',
|
|
43
|
+
alignSelf: 'flex-start',
|
|
44
|
+
gap: theme.space * 3,
|
|
45
|
+
minHeight: Math.max(44, theme.controlHeight),
|
|
46
|
+
minWidth: 44,
|
|
47
|
+
opacity: disabled ? 0.55 : state.pressed ? 0.85 : 1,
|
|
48
|
+
},
|
|
49
|
+
typeof style === 'function' ? style(state) : style,
|
|
50
|
+
], children: [_jsx(View, { accessible: false, style: {
|
|
51
|
+
width: trackWidth,
|
|
52
|
+
height: trackHeight,
|
|
53
|
+
borderRadius: radius,
|
|
54
|
+
borderColor: line,
|
|
55
|
+
borderWidth: 2,
|
|
56
|
+
justifyContent: 'center',
|
|
57
|
+
alignItems: active ? 'flex-end' : 'flex-start',
|
|
58
|
+
paddingHorizontal: 2,
|
|
59
|
+
backgroundColor: filled ? tone.solid : appearance === 'outlined' ? theme.colors.surface : tone.soft,
|
|
60
|
+
}, children: _jsx(View, { style: {
|
|
61
|
+
width: trackHeight - 8,
|
|
62
|
+
height: trackHeight - 8,
|
|
63
|
+
borderRadius: radius,
|
|
64
|
+
backgroundColor: filled ? tone.ink : active ? tone.text : theme.colors.muted,
|
|
65
|
+
}, children: typeof indicator === 'function' ? indicator(active) : indicator }) }), label && (_jsxs(Text, { style: { color: theme.colors.text, flexShrink: 1, fontFamily: theme.fontFamily, fontSize: theme.fontSize }, children: [label, required && _jsx(Text, { style: { color: theme.colors.danger }, children: " *" })] }))] }), description && (_jsx(Text, { accessible: false, style: { color: theme.colors.muted, fontFamily: theme.fontFamily }, children: description })), _jsx(FieldMessage, { message: shownMessage ?? '', invalid: Boolean(validation.message), theme: theme })] }));
|
|
66
|
+
});
|
|
67
|
+
export function SwitchIndicator(props) {
|
|
68
|
+
return _jsx(View, { ...props, accessibilityElementsHidden: true, pointerEvents: "none" });
|
|
69
|
+
}
|