@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.
Files changed (111) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +198 -2
  3. package/dist/accordion.d.ts +29 -0
  4. package/dist/accordion.js +137 -0
  5. package/dist/alert.d.ts +30 -0
  6. package/dist/alert.js +95 -0
  7. package/dist/avatar.d.ts +36 -0
  8. package/dist/avatar.js +91 -0
  9. package/dist/bars.d.ts +44 -0
  10. package/dist/bars.js +74 -0
  11. package/dist/button.d.ts +30 -0
  12. package/dist/button.js +90 -0
  13. package/dist/calendar.d.ts +71 -0
  14. package/dist/calendar.js +276 -0
  15. package/dist/card.d.ts +41 -0
  16. package/dist/card.js +139 -0
  17. package/dist/choices.d.ts +87 -0
  18. package/dist/choices.js +228 -0
  19. package/dist/collections.d.ts +131 -0
  20. package/dist/collections.js +230 -0
  21. package/dist/color-code.d.ts +37 -0
  22. package/dist/color-code.js +158 -0
  23. package/dist/compositions.d.ts +110 -0
  24. package/dist/compositions.js +190 -0
  25. package/dist/controls.d.ts +85 -0
  26. package/dist/controls.js +221 -0
  27. package/dist/drag-drop.d.ts +65 -0
  28. package/dist/drag-drop.js +482 -0
  29. package/dist/feedback.d.ts +30 -0
  30. package/dist/feedback.js +81 -0
  31. package/dist/file-upload.d.ts +67 -0
  32. package/dist/file-upload.js +251 -0
  33. package/dist/generated/icons.d.ts +1037 -0
  34. package/dist/generated/icons.js +3 -0
  35. package/dist/generated/tokens.d.ts +64 -0
  36. package/dist/generated/tokens.js +65 -0
  37. package/dist/icon.d.ts +31 -0
  38. package/dist/icon.js +28 -0
  39. package/dist/index.d.ts +43 -0
  40. package/dist/index.js +43 -0
  41. package/dist/input.d.ts +43 -0
  42. package/dist/input.js +115 -0
  43. package/dist/interactive-layout.d.ts +26 -0
  44. package/dist/interactive-layout.js +117 -0
  45. package/dist/internal/content.d.ts +17 -0
  46. package/dist/internal/content.js +24 -0
  47. package/dist/internal/drag-geometry.d.ts +16 -0
  48. package/dist/internal/drag-geometry.js +25 -0
  49. package/dist/internal/keyboard.d.ts +20 -0
  50. package/dist/internal/keyboard.js +101 -0
  51. package/dist/internal/motion.d.ts +1 -0
  52. package/dist/internal/motion.js +24 -0
  53. package/dist/internal/number-format.d.ts +4 -0
  54. package/dist/internal/number-format.js +25 -0
  55. package/dist/internal/pointer-capture.d.ts +1 -0
  56. package/dist/internal/pointer-capture.js +16 -0
  57. package/dist/internal/state.d.ts +6 -0
  58. package/dist/internal/state.js +28 -0
  59. package/dist/internal/system-drag.d.ts +48 -0
  60. package/dist/internal/system-drag.js +93 -0
  61. package/dist/internal/table-drag.d.ts +56 -0
  62. package/dist/internal/table-drag.js +237 -0
  63. package/dist/internal/table-editing.d.ts +49 -0
  64. package/dist/internal/table-editing.js +278 -0
  65. package/dist/internal/table-editor.d.ts +11 -0
  66. package/dist/internal/table-editor.js +31 -0
  67. package/dist/internal/table-grid.d.ts +44 -0
  68. package/dist/internal/table-grid.js +153 -0
  69. package/dist/internal/table-model.d.ts +132 -0
  70. package/dist/internal/table-model.js +231 -0
  71. package/dist/internal/table-source.d.ts +9 -0
  72. package/dist/internal/table-source.js +80 -0
  73. package/dist/internal/tour-target.d.ts +23 -0
  74. package/dist/internal/tour-target.js +81 -0
  75. package/dist/keyboard.d.ts +14 -0
  76. package/dist/keyboard.js +27 -0
  77. package/dist/layout.d.ts +35 -0
  78. package/dist/layout.js +77 -0
  79. package/dist/loader.d.ts +18 -0
  80. package/dist/loader.js +79 -0
  81. package/dist/localization.d.ts +106 -0
  82. package/dist/localization.js +310 -0
  83. package/dist/media.d.ts +35 -0
  84. package/dist/media.js +96 -0
  85. package/dist/menus.d.ts +103 -0
  86. package/dist/menus.js +422 -0
  87. package/dist/navigation.d.ts +111 -0
  88. package/dist/navigation.js +255 -0
  89. package/dist/overlays.d.ts +97 -0
  90. package/dist/overlays.js +364 -0
  91. package/dist/pill.d.ts +33 -0
  92. package/dist/pill.js +90 -0
  93. package/dist/progress.d.ts +27 -0
  94. package/dist/progress.js +154 -0
  95. package/dist/responsive.d.ts +15 -0
  96. package/dist/responsive.js +27 -0
  97. package/dist/select.d.ts +74 -0
  98. package/dist/select.js +181 -0
  99. package/dist/separator.d.ts +13 -0
  100. package/dist/separator.js +34 -0
  101. package/dist/switch.d.ts +26 -0
  102. package/dist/switch.js +69 -0
  103. package/dist/table.d.ts +122 -0
  104. package/dist/table.js +928 -0
  105. package/dist/text-fields.d.ts +39 -0
  106. package/dist/text-fields.js +134 -0
  107. package/dist/theme.d.ts +47 -0
  108. package/dist/theme.js +71 -0
  109. package/dist/transient.d.ts +80 -0
  110. package/dist/transient.js +273 -0
  111. package/package.json +50 -4
package/dist/card.js ADDED
@@ -0,0 +1,139 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createContext, useContext, useState } from 'react';
3
+ import { Image, Pressable, Text, View } from 'react-native';
4
+ import { splitContent, TextContent } from './internal/content.js';
5
+ import { useControllableValue } from './internal/state.js';
6
+ import { useTramaAppearance, useTramaTheme } from './theme.js';
7
+ const spaceSteps = { none: 0, sm: 2, md: 4, lg: 6 };
8
+ const maxWidths = { sm: 320, md: 480, lg: 640, full: undefined };
9
+ const elevations = { none: 0, sm: 2, md: 4, lg: 8 };
10
+ const alignments = { start: 'flex-start', end: 'flex-end', between: 'space-between' };
11
+ const CardActionsAlignment = createContext('flex-end');
12
+ export function Card({ heading, description, size, padding, gap, elevation, variant, orientation, mediaPlacement, actionsAlign, divided, image, imageSource, imageAlt, imageAspectRatio, imageFit, imageFallback, onImageError, onImageLoad, onPress, selectable, selected, defaultSelected, onSelectedChange, disabled, actionLabel, children, style, ...props }) {
13
+ const { theme, direction, resolve } = useTramaAppearance();
14
+ const [active, request] = useControllableValue(selected, defaultSelected ?? false);
15
+ const [focused, setFocused] = useState(false);
16
+ const { body, named } = splitContent(children, {
17
+ header: CardHeader,
18
+ media: CardMedia,
19
+ headerActions: CardHeaderActions,
20
+ footer: CardFooter,
21
+ actions: CardActions,
22
+ });
23
+ const title = resolve(heading, '');
24
+ const subtitle = resolve(description, '');
25
+ const treatment = resolve(variant, 'outlined');
26
+ const spacing = theme.space * spaceSteps[resolve(gap, 'md')];
27
+ const lift = elevations[resolve(elevation, 'none')];
28
+ const horizontal = resolve(orientation, 'vertical') === 'horizontal';
29
+ const trailingMedia = resolve(mediaPlacement, 'start') === 'end';
30
+ const canSelect = resolve(selectable, selected !== undefined || defaultSelected !== undefined || onSelectedChange !== undefined);
31
+ const unavailable = resolve(disabled, false);
32
+ const interactive = Boolean(canSelect || onPress);
33
+ const withActiveStyle = canSelect && active;
34
+ const imageUrl = resolve(image, '');
35
+ const source = imageSource ?? (imageUrl ? { uri: imageUrl } : undefined);
36
+ const ratio = resolve(imageAspectRatio, 16 / 9);
37
+ const media = named.media ??
38
+ (source && (_jsx(CardImage, { source: source, alt: resolve(imageAlt, ''), ratio: Number.isFinite(ratio) && ratio > 0 ? ratio : 16 / 9, fit: resolve(imageFit, 'cover'), fallback: imageFallback, onLoad: onImageLoad, onError: onImageError }, JSON.stringify(source))));
39
+ const textStyle = { color: theme.colors.text, fontSize: theme.fontSize, fontFamily: theme.fontFamily };
40
+ const withDivider = resolve(divided, false);
41
+ const primary = (_jsxs(View, { style: {
42
+ flexDirection: horizontal
43
+ ? trailingMedia
44
+ ? 'row-reverse'
45
+ : 'row'
46
+ : trailingMedia
47
+ ? 'column-reverse'
48
+ : 'column',
49
+ gap: spacing,
50
+ alignItems: horizontal ? 'flex-start' : 'stretch',
51
+ }, children: [media && _jsx(View, { style: { width: horizontal ? '38%' : '100%', minWidth: 0 }, children: media }), _jsxs(View, { style: [{ gap: spacing, minWidth: 0 }, horizontal && { flex: 1 }], children: [named.header ??
52
+ (title || subtitle ? (_jsxs(CardHeader, { children: [title ? (_jsx(Text, { accessibilityRole: interactive ? undefined : 'header', style: {
53
+ ...textStyle,
54
+ fontWeight: '700',
55
+ fontSize: theme.fontSize + 4,
56
+ }, children: title })) : null, subtitle ? _jsx(Text, { style: { ...textStyle, color: theme.colors.muted }, children: subtitle }) : null] })) : null), body.length > 0 && (_jsx(View, { style: { gap: theme.space * 2 }, children: _jsx(TextContent, { style: textStyle, children: body }) }))] })] }));
57
+ return (_jsxs(View, { ...props, style: [
58
+ {
59
+ direction,
60
+ width: '100%',
61
+ maxWidth: maxWidths[resolve(size, 'full')],
62
+ padding: theme.space * spaceSteps[resolve(padding, 'md')],
63
+ gap: spacing,
64
+ borderRadius: theme.radius,
65
+ borderWidth: treatment === 'filled' && !withActiveStyle && !focused ? 0 : 1,
66
+ borderStyle: treatment === 'dashed' ? 'dashed' : 'solid',
67
+ borderColor: withActiveStyle || focused ? theme.colors.accent : theme.colors.border,
68
+ backgroundColor: treatment === 'filled' || withActiveStyle ? theme.colors.subtle : theme.colors.surface,
69
+ elevation: lift,
70
+ },
71
+ lift > 0 && {
72
+ shadowColor: '#000000',
73
+ shadowOpacity: 0.17,
74
+ shadowRadius: lift * 2,
75
+ shadowOffset: { width: 0, height: lift },
76
+ },
77
+ style,
78
+ ], children: [_jsxs(View, { style: { flexDirection: 'row', alignItems: 'flex-start', gap: named.headerActions ? spacing : 0 }, children: [interactive ? (_jsx(Pressable, { accessibilityRole: canSelect ? 'togglebutton' : 'button', accessibilityLabel: resolve(actionLabel, title) || undefined, accessibilityHint: subtitle || undefined, accessibilityState: { disabled: unavailable, ...(canSelect ? { checked: active } : {}) }, "aria-checked": canSelect ? active : undefined, "aria-disabled": unavailable, disabled: unavailable, onFocus: () => setFocused(true), onBlur: () => setFocused(false), onPress: (event) => {
79
+ if (unavailable)
80
+ return;
81
+ if (canSelect && onSelectedChange?.(!active) !== false)
82
+ request(!active);
83
+ onPress?.(event);
84
+ }, style: ({ pressed }) => ({
85
+ flex: 1,
86
+ minWidth: 44,
87
+ minHeight: 44,
88
+ justifyContent: 'center',
89
+ opacity: unavailable ? 0.55 : pressed ? 0.78 : 1,
90
+ }), children: primary })) : (_jsx(View, { style: { flex: 1, minWidth: 0 }, children: primary })), named.headerActions] }), (named.footer || named.actions) && (_jsxs(View, { style: {
91
+ gap: spacing,
92
+ borderTopWidth: withDivider ? 1 : 0,
93
+ borderColor: theme.colors.border,
94
+ paddingTop: withDivider ? spacing : 0,
95
+ }, children: [named.footer, named.actions && (_jsx(CardActionsAlignment.Provider, { value: alignments[resolve(actionsAlign, 'end')], children: named.actions }))] }))] }));
96
+ }
97
+ function CardImage({ source, alt, fit, ratio, fallback, onLoad, onError }) {
98
+ const { theme } = useTramaAppearance();
99
+ const [failed, setFailed] = useState(false);
100
+ if (failed) {
101
+ return (_jsx(View, { style: {
102
+ aspectRatio: ratio,
103
+ width: '100%',
104
+ borderRadius: theme.radius,
105
+ backgroundColor: theme.colors.subtle,
106
+ alignItems: 'center',
107
+ justifyContent: 'center',
108
+ }, children: _jsx(TextContent, { style: { color: theme.colors.muted, fontFamily: theme.fontFamily }, children: fallback ?? alt }) }));
109
+ }
110
+ return (_jsx(Image, { source: source, resizeMode: fit, accessible: Boolean(alt), accessibilityLabel: alt || undefined, style: { aspectRatio: ratio, width: '100%', borderRadius: theme.radius, backgroundColor: theme.colors.subtle }, onLoad: onLoad, onError: (event) => {
111
+ setFailed(true);
112
+ onError?.(event);
113
+ } }));
114
+ }
115
+ export function CardHeader({ children, style, ...props }) {
116
+ const theme = useTramaTheme();
117
+ return (_jsx(View, { ...props, style: [{ gap: theme.space }, style], children: _jsx(TextContent, { style: {
118
+ color: theme.colors.text,
119
+ fontSize: theme.fontSize + 4,
120
+ fontFamily: theme.fontFamily,
121
+ fontWeight: '700',
122
+ }, children: children }) }));
123
+ }
124
+ export function CardMedia(props) {
125
+ return _jsx(View, { ...props });
126
+ }
127
+ export function CardFooter({ children, ...props }) {
128
+ const theme = useTramaTheme();
129
+ return (_jsx(View, { ...props, children: _jsx(TextContent, { style: { color: theme.colors.muted, fontSize: theme.fontSize, fontFamily: theme.fontFamily }, children: children }) }));
130
+ }
131
+ export function CardHeaderActions({ children, style, ...props }) {
132
+ const theme = useTramaTheme();
133
+ return (_jsx(View, { ...props, style: [{ gap: theme.space * 2, flexShrink: 1 }, style], children: children }));
134
+ }
135
+ export function CardActions({ children, style, ...props }) {
136
+ const theme = useTramaTheme();
137
+ const justifyContent = useContext(CardActionsAlignment);
138
+ return (_jsx(View, { ...props, style: [{ justifyContent, gap: theme.space * 2, flexDirection: 'row', flexWrap: 'wrap' }, style], children: children }));
139
+ }
@@ -0,0 +1,87 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type PressableProps, type ViewProps } from 'react-native';
3
+ import { type ButtonProps } from './button.js';
4
+ import type { FieldHandle } from './input.js';
5
+ import type { TramaResponsive } from './responsive.js';
6
+ import { type TramaColor, type TramaShape, type TramaSize } from './theme.js';
7
+ type ChoiceVariant = 'plain' | 'soft' | 'outlined' | 'filled';
8
+ type ChoiceOrientation = 'vertical' | 'horizontal';
9
+ interface ChoiceAppearance {
10
+ size?: TramaResponsive<TramaSize>;
11
+ color?: TramaResponsive<TramaColor>;
12
+ shape?: TramaResponsive<TramaShape>;
13
+ variant?: TramaResponsive<ChoiceVariant>;
14
+ labelPlacement?: TramaResponsive<'start' | 'end'>;
15
+ }
16
+ interface FieldLabels {
17
+ label?: string;
18
+ description?: string;
19
+ hint?: string;
20
+ error?: string;
21
+ invalid?: boolean;
22
+ required?: boolean;
23
+ disabled?: boolean;
24
+ readOnly?: boolean;
25
+ }
26
+ interface GroupProps extends ViewProps, FieldLabels, ChoiceAppearance {
27
+ orientation?: TramaResponsive<ChoiceOrientation>;
28
+ }
29
+ interface ChoiceOptionProps extends Omit<PressableProps, 'children' | 'onPress'>, ChoiceAppearance {
30
+ label?: string;
31
+ description?: string;
32
+ children?: ReactNode;
33
+ }
34
+ export interface CheckboxProps extends ChoiceOptionProps, Omit<FieldLabels, 'label' | 'description' | 'disabled'> {
35
+ value?: string;
36
+ checked?: boolean;
37
+ defaultChecked?: boolean;
38
+ indeterminate?: boolean;
39
+ defaultIndeterminate?: boolean;
40
+ onCheckedChange?: (checked: boolean, detail: {
41
+ indeterminate: false;
42
+ value: string;
43
+ }) => void | false;
44
+ onIndeterminateChange?: (indeterminate: boolean) => void;
45
+ indicator?: 'box' | 'icon';
46
+ checkedIcon?: ReactNode;
47
+ uncheckedIcon?: ReactNode;
48
+ indeterminateIcon?: ReactNode;
49
+ containerStyle?: ViewProps['style'];
50
+ }
51
+ export declare const Checkbox: import("react").ForwardRefExoticComponent<CheckboxProps & import("react").RefAttributes<FieldHandle>>;
52
+ export declare function CheckboxIcon(props: ViewProps): import("react").JSX.Element;
53
+ export interface CheckboxGroupProps extends GroupProps {
54
+ value?: readonly string[];
55
+ defaultValue?: readonly string[];
56
+ onValueChange?: (value: readonly string[]) => void | false;
57
+ minSelected?: number;
58
+ maxSelected?: number;
59
+ }
60
+ export declare const CheckboxGroup: import("react").ForwardRefExoticComponent<CheckboxGroupProps & import("react").RefAttributes<FieldHandle>>;
61
+ export interface RadioGroupProps extends GroupProps {
62
+ value?: string;
63
+ defaultValue?: string;
64
+ onValueChange?: (value: string) => void | false;
65
+ }
66
+ export declare const RadioGroup: import("react").ForwardRefExoticComponent<RadioGroupProps & import("react").RefAttributes<FieldHandle>>;
67
+ export interface RadioGroupItemProps extends ChoiceOptionProps {
68
+ value: string;
69
+ }
70
+ export declare function RadioGroupItem({ value, children, disabled, size, color, shape, variant, labelPlacement, ...props }: RadioGroupItemProps): import("react").JSX.Element | null;
71
+ export declare function RadioGroupItemAddon(props: ViewProps): import("react").JSX.Element;
72
+ export declare function RadioGroupItemMedia(props: ViewProps): import("react").JSX.Element;
73
+ export interface ToggleProps extends ButtonProps {
74
+ value?: string;
75
+ }
76
+ export declare function Toggle({ value, defaultPressed, pressed, onPressedChange, variant, ...props }: ToggleProps): import("react").JSX.Element;
77
+ export interface ToggleGroupProps extends ViewProps {
78
+ value?: readonly string[];
79
+ defaultValue?: readonly string[];
80
+ mode?: 'single' | 'multiple';
81
+ allowEmpty?: boolean;
82
+ orientation?: TramaResponsive<ChoiceOrientation>;
83
+ disabled?: boolean;
84
+ onValueChange?: (value: readonly string[]) => void | false;
85
+ }
86
+ export declare function ToggleGroup({ value, defaultValue, mode, allowEmpty, onValueChange, disabled, children, ...props }: ToggleGroupProps): import("react").JSX.Element;
87
+ export {};
@@ -0,0 +1,228 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Children, createContext, forwardRef, isValidElement, useContext, useImperativeHandle, useState, } from 'react';
3
+ import { Pressable, Text, View } from 'react-native';
4
+ import { Button, ButtonGroup } from './button.js';
5
+ import { FieldMessage, splitContent, TextContent } from './internal/content.js';
6
+ import { useControllableValue, useFieldValidation } from './internal/state.js';
7
+ import { Stack } from './layout.js';
8
+ import { useTramaMessages } from './localization.js';
9
+ import { getTone, shapeRadius, sizeStep, useTramaAppearance, } from './theme.js';
10
+ function ChoiceSurface({ checked, kind, invalid, required, readOnly, message, indicator, onChoose, label, description, children, disabled, size, shape, color, variant, labelPlacement, style, onFocus, onBlur, accessibilityHint, accessibilityLabel, accessibilityState, ...props }) {
11
+ const { theme, direction, resolve } = useTramaAppearance();
12
+ const messages = useTramaMessages();
13
+ const [focused, setFocused] = useState(false);
14
+ const tone = getTone(theme, resolve(color, 'accent'));
15
+ const treatment = resolve(variant, 'plain');
16
+ const step = sizeStep[resolve(size, 'md')];
17
+ const selected = checked === true || checked === 'mixed';
18
+ const radius = shapeRadius(theme, resolve(shape, 'rounded'));
19
+ const stroke = invalid ? theme.colors.danger : selected || focused ? tone.solid : theme.colors.border;
20
+ const unavailable = Boolean(disabled || readOnly);
21
+ const labelHint = [required && messages.requiredLabel, description, message, accessibilityHint].filter(Boolean).join('. ') ||
22
+ undefined;
23
+ const selectedFill = treatment === 'filled' && selected;
24
+ const textColor = selectedFill ? tone.ink : theme.colors.text;
25
+ const controlSize = theme.space * (5 + step);
26
+ return (_jsxs(Pressable, { ...props, accessibilityRole: kind, accessibilityLabel: accessibilityLabel ?? label, accessibilityHint: labelHint, accessibilityState: { ...accessibilityState, checked, disabled: unavailable }, "aria-checked": checked, "aria-disabled": unavailable, disabled: unavailable, onPress: onChoose, onFocus: (event) => {
27
+ setFocused(true);
28
+ onFocus?.(event);
29
+ }, onBlur: (event) => {
30
+ setFocused(false);
31
+ onBlur?.(event);
32
+ }, style: (state) => [
33
+ {
34
+ direction,
35
+ flexDirection: resolve(labelPlacement, 'end') === 'start' ? 'row-reverse' : 'row',
36
+ gap: theme.space * 2,
37
+ alignItems: 'center',
38
+ minHeight: Math.max(44, theme.controlHeight),
39
+ minWidth: 44,
40
+ padding: theme.space * (treatment === 'plain' ? 1 : 2),
41
+ borderRadius: radius,
42
+ borderWidth: treatment === 'outlined' || focused || invalid ? 1 : 0,
43
+ borderColor: stroke,
44
+ backgroundColor: selectedFill
45
+ ? tone.solid
46
+ : treatment === 'soft' || state.pressed
47
+ ? tone.soft
48
+ : 'transparent',
49
+ opacity: disabled ? 0.55 : 1,
50
+ },
51
+ typeof style === 'function' ? style(state) : style,
52
+ ], children: [_jsx(View, { accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", pointerEvents: "none", children: indicator === undefined ? (_jsxs(View, { style: {
53
+ width: controlSize,
54
+ height: controlSize,
55
+ borderRadius: kind === 'radio' ? controlSize / 2 : Math.min(radius, controlSize / 2),
56
+ alignItems: 'center',
57
+ justifyContent: 'center',
58
+ borderWidth: 1.5,
59
+ borderColor: selectedFill ? tone.ink : stroke,
60
+ backgroundColor: kind === 'checkbox' && selected ? tone.solid : theme.colors.surface,
61
+ }, children: [kind === 'radio' && selected && (_jsx(View, { style: {
62
+ width: controlSize / 2,
63
+ height: controlSize / 2,
64
+ borderRadius: controlSize / 4,
65
+ backgroundColor: tone.solid,
66
+ } })), kind === 'checkbox' && selected && (_jsx(Text, { allowFontScaling: false, style: { color: tone.ink, fontWeight: '700', fontSize: theme.fontSize }, children: checked === 'mixed' ? '−' : '✓' }))] })) : (indicator) }), (label || description || children) && (_jsxs(View, { style: { flexShrink: 1, gap: theme.space }, children: [label && (_jsxs(Text, { style: { color: textColor, fontFamily: theme.fontFamily, fontSize: theme.fontSize + step }, children: [label, required && _jsx(Text, { style: { color: selectedFill ? tone.ink : theme.colors.danger }, children: " *" })] })), description && (_jsx(Text, { style: { color: selectedFill ? tone.ink : theme.colors.muted, fontFamily: theme.fontFamily }, children: description })), _jsx(TextContent, { style: { color: textColor }, children: children })] }))] }));
67
+ }
68
+ const CheckboxContext = createContext(null);
69
+ const RadioContext = createContext(null);
70
+ export const Checkbox = forwardRef(function Checkbox({ value = 'on', checked, defaultChecked, indeterminate, defaultIndeterminate, onCheckedChange, onIndeterminateChange, hint, error, invalid, required, disabled, readOnly, children, indicator, checkedIcon, uncheckedIcon, indeterminateIcon, size, shape, color, variant, labelPlacement, containerStyle, ...props }, ref) {
71
+ const group = useContext(CheckboxContext);
72
+ const messages = useTramaMessages();
73
+ const { theme } = useTramaAppearance();
74
+ const [checkedValue, requestChecked] = useControllableValue(checked, defaultChecked ?? false);
75
+ const [mixed, requestMixed] = useControllableValue(indeterminate, defaultIndeterminate ?? false, onIndeterminateChange);
76
+ const current = group ? group.values.includes(value) : checkedValue;
77
+ const unavailable = Boolean(disabled || group?.disabled);
78
+ const immutable = Boolean(readOnly || group?.readOnly);
79
+ const validation = useFieldValidation(group ? '' : error?.trim() || (invalid ? messages.reviewField : ''), !group && required && (!current || mixed) ? messages.chooseOption : '', unavailable || immutable);
80
+ const { body, named } = splitContent(children, { icon: CheckboxIcon });
81
+ const custom = mixed ? indeterminateIcon : current ? checkedIcon : uncheckedIcon;
82
+ const mark = named.icon ??
83
+ custom ??
84
+ (indicator === 'icon' ? (_jsx(Text, { allowFontScaling: false, style: { color: theme.colors.accent, fontSize: theme.fontSize + 6 }, children: mixed ? '−' : current ? '✓' : '○' })) : undefined);
85
+ useImperativeHandle(ref, () => ({
86
+ checkValidity: validation.checkValidity,
87
+ reportValidity: validation.reportValidity,
88
+ }));
89
+ return (_jsxs(View, { style: containerStyle, children: [_jsx(ChoiceSurface, { ...props, kind: "checkbox", checked: mixed ? 'mixed' : current, disabled: unavailable, readOnly: immutable, required: !group && required, invalid: Boolean(validation.message), message: validation.message || hint, size: size ?? group?.size, color: color ?? group?.color, shape: shape ?? group?.shape, variant: variant ?? group?.variant, labelPlacement: labelPlacement ?? group?.labelPlacement, indicator: mark, onChoose: () => {
90
+ if (unavailable || immutable)
91
+ return;
92
+ if (group) {
93
+ group.choose(value);
94
+ return;
95
+ }
96
+ const next = mixed || !current;
97
+ if (onCheckedChange?.(next, { indeterminate: false, value }) === false)
98
+ return;
99
+ requestChecked(next);
100
+ if (mixed)
101
+ requestMixed(false);
102
+ }, children: body }), _jsx(FieldMessage, { message: validation.message || hint || '', invalid: Boolean(validation.message), theme: theme })] }));
103
+ });
104
+ export function CheckboxIcon(props) {
105
+ return _jsx(View, { ...props });
106
+ }
107
+ export const CheckboxGroup = forwardRef(function CheckboxGroup({ value, defaultValue, onValueChange, minSelected, maxSelected, orientation, size, color, shape, variant, labelPlacement, label, description, hint, error, invalid, required, disabled, readOnly, children, ...props }, ref) {
108
+ const [owned, request] = useControllableValue(value, defaultValue ?? []);
109
+ const choices = getChoices(children, Checkbox);
110
+ const current = [...new Set(owned.filter((id) => choices.has(id)))];
111
+ const count = current.filter((id) => !choices.get(id)).length;
112
+ const minimum = Math.max(required ? 1 : 0, minSelected ?? 0);
113
+ const maximum = Math.max(minimum, maxSelected ?? Infinity);
114
+ const messages = useTramaMessages();
115
+ const validation = useFieldValidation(error?.trim() || (invalid ? messages.reviewField : ''), count < minimum ? messages.chooseOption : count > maximum ? messages.reviewField : '', Boolean(disabled || readOnly));
116
+ useImperativeHandle(ref, () => ({
117
+ checkValidity: validation.checkValidity,
118
+ reportValidity: validation.reportValidity,
119
+ }));
120
+ return (_jsx(CheckboxContext.Provider, { value: {
121
+ values: current,
122
+ disabled: Boolean(disabled),
123
+ readOnly: Boolean(readOnly),
124
+ size,
125
+ color,
126
+ shape,
127
+ variant,
128
+ labelPlacement,
129
+ choose(id) {
130
+ if (disabled || readOnly || !choices.has(id) || choices.get(id))
131
+ return;
132
+ const selected = current.includes(id);
133
+ if (!selected && count >= maximum)
134
+ return;
135
+ const next = selected ? current.filter((entry) => entry !== id) : [...current, id];
136
+ if (onValueChange?.(next) !== false)
137
+ request(next);
138
+ },
139
+ }, children: _jsx(ChoiceGroupLayout, { ...props, label: label, description: description, required: required, orientation: orientation, message: validation.message || hint, messageInvalid: Boolean(validation.message), children: children }) }));
140
+ });
141
+ function getChoices(children, type) {
142
+ const choices = new Map();
143
+ for (const child of Children.toArray(children)) {
144
+ if (!isValidElement(child) ||
145
+ child.type !== type ||
146
+ child.props.value === undefined)
147
+ continue;
148
+ if (!choices.has(child.props.value))
149
+ choices.set(child.props.value, Boolean(child.props.disabled));
150
+ }
151
+ return choices;
152
+ }
153
+ function ChoiceGroupLayout({ label, description, required, orientation, message, messageInvalid, children, ...props }) {
154
+ const { theme, resolve } = useTramaAppearance();
155
+ const horizontal = resolve(orientation, 'vertical') === 'horizontal';
156
+ return (_jsxs(Stack, { ...props, gap: "xs", accessibilityLabel: props.accessibilityLabel ?? label, children: [label && (_jsxs(Text, { style: { color: theme.colors.text, fontSize: theme.fontSize, fontWeight: '600' }, children: [label, required && _jsx(Text, { style: { color: theme.colors.danger }, children: " *" })] })), description && _jsx(Text, { style: { color: theme.colors.muted }, children: description }), _jsx(Stack, { direction: horizontal ? 'row' : 'column', wrap: horizontal ? 'wrap' : 'nowrap', gap: "xs", children: children }), _jsx(FieldMessage, { message: message ?? '', invalid: messageInvalid, theme: theme })] }));
157
+ }
158
+ export const RadioGroup = forwardRef(function RadioGroup({ value, defaultValue, onValueChange, orientation, size, color, shape, variant, labelPlacement, label, description, hint, required, error, invalid, disabled, readOnly, children, ...props }, ref) {
159
+ const [current, request] = useControllableValue(value, defaultValue ?? '');
160
+ const choices = getChoices(children, RadioGroupItem);
161
+ const messages = useTramaMessages();
162
+ const validation = useFieldValidation(error?.trim() || (invalid ? messages.reviewField : ''), required && (!choices.has(current) || choices.get(current)) ? messages.chooseOption : '', Boolean(disabled || readOnly));
163
+ useImperativeHandle(ref, () => ({
164
+ checkValidity: validation.checkValidity,
165
+ reportValidity: validation.reportValidity,
166
+ }));
167
+ return (_jsx(RadioContext.Provider, { value: {
168
+ values: [current],
169
+ disabled: Boolean(disabled),
170
+ readOnly: Boolean(readOnly),
171
+ size,
172
+ color,
173
+ shape,
174
+ variant,
175
+ labelPlacement,
176
+ choose(id) {
177
+ if (disabled || readOnly || current === id || !choices.has(id) || choices.get(id))
178
+ return;
179
+ if (onValueChange?.(id) !== false)
180
+ request(id);
181
+ },
182
+ }, children: _jsx(ChoiceGroupLayout, { ...props, accessibilityRole: "radiogroup", label: label, description: description, required: required, orientation: orientation, message: validation.message || hint, messageInvalid: Boolean(validation.message), children: children }) }));
183
+ });
184
+ export function RadioGroupItem({ value, children, disabled, size, color, shape, variant, labelPlacement, ...props }) {
185
+ const group = useContext(RadioContext);
186
+ const { body, named } = splitContent(children, { media: RadioGroupItemMedia, addon: RadioGroupItemAddon });
187
+ if (!group)
188
+ return null;
189
+ return (_jsxs(ChoiceSurface, { ...props, kind: "radio", checked: group.values.includes(value), disabled: disabled || group.disabled, readOnly: group.readOnly, indicator: named.media, size: size ?? group.size, color: color ?? group.color, shape: shape ?? group.shape, variant: variant ?? group.variant, labelPlacement: labelPlacement ?? group.labelPlacement, onChoose: () => group.choose(value), children: [body, named.addon] }));
190
+ }
191
+ export function RadioGroupItemAddon(props) {
192
+ return _jsx(View, { ...props });
193
+ }
194
+ export function RadioGroupItemMedia(props) {
195
+ return _jsx(View, { ...props });
196
+ }
197
+ const ToggleContext = createContext(null);
198
+ export function Toggle({ value, defaultPressed, pressed, onPressedChange, variant, ...props }) {
199
+ const group = useContext(ToggleContext);
200
+ return (_jsx(Button, { ...props, variant: variant ?? 'outlined', defaultPressed: defaultPressed ?? false, pressed: group && value ? group.values.includes(value) : pressed, onPressedChange: (next) => {
201
+ if (group && value)
202
+ group.choose(value, next);
203
+ else
204
+ onPressedChange?.(next);
205
+ } }));
206
+ }
207
+ export function ToggleGroup({ value, defaultValue, mode = 'single', allowEmpty = true, onValueChange, disabled, children, ...props }) {
208
+ const [owned, request] = useControllableValue(value, defaultValue ?? []);
209
+ const choices = getChoices(children, Toggle);
210
+ const selected = [...new Set(owned.filter((id) => choices.has(id)))];
211
+ const current = mode === 'single' ? selected.slice(0, 1) : selected;
212
+ return (_jsx(ToggleContext.Provider, { value: {
213
+ values: current,
214
+ choose(id, pressed) {
215
+ if (disabled || !choices.has(id) || choices.get(id))
216
+ return;
217
+ if (!pressed && !allowEmpty && current.length === 1)
218
+ return;
219
+ const next = pressed
220
+ ? mode === 'single'
221
+ ? [id]
222
+ : [...current, id]
223
+ : current.filter((entry) => entry !== id);
224
+ if (onValueChange?.(next) !== false)
225
+ request(next);
226
+ },
227
+ }, children: _jsx(ButtonGroup, { ...props, disabled: disabled, children: children }) }));
228
+ }
@@ -0,0 +1,131 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type PressableProps, type ViewProps } from 'react-native';
3
+ import { type GridColumns } from './layout.js';
4
+ import type { TramaResponsive } from './responsive.js';
5
+ import { type TramaSize } from './theme.js';
6
+ type SelectionMode = 'none' | 'single' | 'multiple';
7
+ type CollectionVariant = 'plain' | 'soft' | 'outlined';
8
+ export interface ListItemData {
9
+ value: string;
10
+ label: string;
11
+ description?: string;
12
+ disabled?: boolean;
13
+ media?: ReactNode;
14
+ }
15
+ export interface ListProps extends ViewProps {
16
+ items?: readonly ListItemData[];
17
+ selection?: SelectionMode;
18
+ value?: string | readonly string[];
19
+ defaultValue?: string | readonly string[];
20
+ onValueChange?: (value: string | readonly string[]) => void | false;
21
+ disabled?: boolean;
22
+ variant?: TramaResponsive<CollectionVariant>;
23
+ layout?: TramaResponsive<'stack' | 'grid'>;
24
+ columns?: TramaResponsive<GridColumns>;
25
+ virtualized?: boolean;
26
+ height?: number;
27
+ renderItem?: (item: ListItemData) => ReactNode;
28
+ }
29
+ export declare function List({ items, selection, value, defaultValue, onValueChange, disabled, variant, layout, columns, virtualized, height, renderItem, children, style, ...props }: ListProps): import("react").JSX.Element;
30
+ export interface ListItemProps extends ListItemData, ViewProps {
31
+ onPress?: PressableProps['onPress'];
32
+ }
33
+ export declare function ListItem({ value, label, description, media, disabled, onPress, children, style, ...props }: ListItemProps): import("react").JSX.Element;
34
+ export declare function ListItemMedia(props: ViewProps): import("react").JSX.Element;
35
+ export declare function ListItemActions(props: ViewProps): import("react").JSX.Element;
36
+ export interface DescriptionListItemProps extends ViewProps {
37
+ term: string;
38
+ description?: string;
39
+ }
40
+ export interface DescriptionListProps extends ViewProps {
41
+ layout?: TramaResponsive<'stacked' | 'split' | 'grid'>;
42
+ columns?: TramaResponsive<GridColumns>;
43
+ }
44
+ export declare function DescriptionList({ layout, columns, children, ...props }: DescriptionListProps): import("react").JSX.Element;
45
+ export declare function DescriptionListItem({ term, description, children, ...props }: DescriptionListItemProps): import("react").JSX.Element;
46
+ export declare function DescriptionListActions(props: ViewProps): import("react").JSX.Element;
47
+ export interface TimelineProps extends ViewProps {
48
+ orientation?: TramaResponsive<'horizontal' | 'vertical'>;
49
+ }
50
+ export declare function Timeline({ orientation, children, ...props }: TimelineProps): import("react").JSX.Element;
51
+ export interface TimelineItemProps extends ViewProps {
52
+ heading?: string;
53
+ description?: string;
54
+ time?: string;
55
+ status?: 'pending' | 'current' | 'complete' | 'error';
56
+ }
57
+ export declare function TimelineItem({ heading, description, time, status, children, style, ...props }: TimelineItemProps): import("react").JSX.Element;
58
+ export declare function TimelineItemActions(props: ViewProps): import("react").JSX.Element;
59
+ export declare function TimelineItemMedia(props: ViewProps): import("react").JSX.Element;
60
+ export interface ActivityEntry {
61
+ id: string;
62
+ actor?: string;
63
+ title: string;
64
+ description?: string;
65
+ time?: string;
66
+ image?: string;
67
+ }
68
+ export interface ActivityFeedProps extends TimelineProps {
69
+ items?: readonly ActivityEntry[];
70
+ }
71
+ export declare function ActivityFeed({ items, children, ...props }: ActivityFeedProps): import("react").JSX.Element;
72
+ export interface TransferItemData {
73
+ value: string;
74
+ label: string;
75
+ disabled?: boolean;
76
+ media?: ReactNode;
77
+ }
78
+ export interface TransferItemProps extends ViewProps, TransferItemData {
79
+ }
80
+ export declare function TransferItem({ value: _value, disabled: _disabled, label, media, children, ...props }: TransferItemProps): import("react").JSX.Element;
81
+ export declare function TransferItemMedia(props: ViewProps): import("react").JSX.Element;
82
+ export interface TransferListProps extends ViewProps {
83
+ items?: readonly TransferItemData[];
84
+ value?: readonly string[];
85
+ defaultValue?: readonly string[];
86
+ onValueChange?: (value: readonly string[]) => void | false;
87
+ sourceLabel?: string;
88
+ targetLabel?: string;
89
+ disabled?: boolean;
90
+ }
91
+ export declare function TransferList({ items, value, defaultValue, onValueChange, sourceLabel, targetLabel, disabled, children, ...props }: TransferListProps): import("react").JSX.Element;
92
+ export interface TreeNode {
93
+ value: string;
94
+ label: string;
95
+ description?: string;
96
+ disabled?: boolean;
97
+ media?: ReactNode;
98
+ badge?: ReactNode;
99
+ children?: readonly TreeNode[];
100
+ }
101
+ export interface TreeItemProps extends ViewProps, Omit<TreeNode, 'children'> {
102
+ }
103
+ export declare function TreeItem({ children }: TreeItemProps): import("react").JSX.Element;
104
+ export declare function TreeItemMedia(props: ViewProps): import("react").JSX.Element;
105
+ export declare function TreeItemBadge(props: ViewProps): import("react").JSX.Element;
106
+ export declare function TreeItemDescription(props: ViewProps): import("react").JSX.Element;
107
+ export declare function TreeItemLabel(props: ViewProps): import("react").JSX.Element;
108
+ export interface TreeViewProps extends ViewProps {
109
+ items?: readonly TreeNode[];
110
+ expanded?: readonly string[];
111
+ defaultExpanded?: readonly string[];
112
+ onExpandedChange?: (value: readonly string[]) => void | false;
113
+ value?: readonly string[];
114
+ defaultValue?: readonly string[];
115
+ onValueChange?: (value: readonly string[]) => void | false;
116
+ selection?: SelectionMode;
117
+ selectionStyle?: 'highlight' | 'checkbox';
118
+ size?: TramaResponsive<TramaSize>;
119
+ }
120
+ export declare function TreeView({ items, expanded, defaultExpanded, onExpandedChange, value, defaultValue, onValueChange, selection, selectionStyle, size, children, ...props }: TreeViewProps): import("react").JSX.Element;
121
+ export interface ErrorSummaryProps extends ViewProps {
122
+ heading?: string;
123
+ announcement?: 'off' | 'polite' | 'assertive';
124
+ }
125
+ export declare function ErrorSummary({ heading, announcement, children, ...props }: ErrorSummaryProps): import("react").JSX.Element;
126
+ export interface ErrorSummaryItemProps extends ViewProps {
127
+ label: string;
128
+ onActivate?: () => void;
129
+ }
130
+ export declare function ErrorSummaryItem({ label, onActivate, children, ...props }: ErrorSummaryItemProps): import("react").JSX.Element;
131
+ export {};