@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/bars.d.ts ADDED
@@ -0,0 +1,44 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type ViewProps } from 'react-native';
3
+ import { type LayoutSpace } from './layout.js';
4
+ import type { TramaResponsive } from './responsive.js';
5
+ import { type TramaSize } from './theme.js';
6
+ type Axis = 'horizontal' | 'vertical';
7
+ export interface ToolbarProps extends ViewProps {
8
+ label?: string;
9
+ orientation?: TramaResponsive<Axis>;
10
+ size?: TramaResponsive<TramaSize>;
11
+ variant?: TramaResponsive<'plain' | 'soft' | 'outlined'>;
12
+ shape?: TramaResponsive<'square' | 'rounded'>;
13
+ gap?: TramaResponsive<LayoutSpace>;
14
+ overflow?: TramaResponsive<'wrap' | 'scroll'>;
15
+ }
16
+ export declare function Toolbar({ label, orientation, size, variant, shape, gap, overflow, children, style, ...props }: ToolbarProps): import("react").JSX.Element;
17
+ export declare function ToolbarGroup(props: ViewProps): import("react").JSX.Element;
18
+ export declare function ToolbarSeparator(props: ViewProps & {
19
+ orientation?: Axis;
20
+ }): import("react").JSX.Element;
21
+ export interface ActionBarProps extends ViewProps {
22
+ selectionCount?: number;
23
+ selectionLabel?: (count: number) => string;
24
+ showClear?: boolean;
25
+ clearLabel?: string;
26
+ onClear?: () => void;
27
+ disabled?: boolean;
28
+ position?: TramaResponsive<'inline' | 'fixed'>;
29
+ placement?: TramaResponsive<'top' | 'bottom'>;
30
+ variant?: TramaResponsive<'plain' | 'outlined' | 'floating'>;
31
+ size?: TramaResponsive<TramaSize>;
32
+ }
33
+ export declare function ActionBar({ selectionCount, selectionLabel, showClear, clearLabel, onClear, disabled, position, placement, variant, size, children, style, ...props }: ActionBarProps): import("react").JSX.Element;
34
+ export declare function ActionBarContent({ children, ...props }: ViewProps): import("react").JSX.Element;
35
+ export declare function ActionBarActions(props: ViewProps): import("react").JSX.Element;
36
+ export interface EmptyStateProps extends ViewProps {
37
+ heading?: string;
38
+ description?: string;
39
+ align?: 'center' | 'start';
40
+ icon?: ReactNode;
41
+ actions?: ReactNode;
42
+ }
43
+ export declare function EmptyState({ heading, description, align, icon, actions, children, style, ...props }: EmptyStateProps): import("react").JSX.Element;
44
+ export {};
package/dist/bars.js ADDED
@@ -0,0 +1,74 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ScrollView, Text, View } from 'react-native';
3
+ import { Button } from './button.js';
4
+ import { splitContent, TextContent } from './internal/content.js';
5
+ import { Cluster, Stack } from './layout.js';
6
+ import { useTramaMessages } from './localization.js';
7
+ import { Separator } from './separator.js';
8
+ import { sizeStep, useTramaAppearance } from './theme.js';
9
+ export function Toolbar({ label, orientation, size, variant, shape, gap, overflow, children, style, ...props }) {
10
+ const { theme, direction, resolve } = useTramaAppearance();
11
+ const treatment = resolve(variant, 'plain');
12
+ const vertical = resolve(orientation, 'horizontal') === 'vertical';
13
+ const scrolling = resolve(overflow, 'wrap') === 'scroll';
14
+ const body = (_jsx(Stack, { align: vertical ? 'stretch' : 'center', direction: vertical ? 'column' : 'row', wrap: scrolling || vertical ? 'nowrap' : 'wrap', gap: gap ?? 'xs', children: children }));
15
+ return (_jsx(View, { ...props, accessibilityLabel: props.accessibilityLabel ?? label, style: [
16
+ {
17
+ direction,
18
+ padding: theme.space * (2 + sizeStep[resolve(size, 'md')]),
19
+ borderRadius: resolve(shape, 'rounded') === 'square' ? 0 : theme.radius,
20
+ borderColor: theme.colors.border,
21
+ borderWidth: treatment === 'outlined' ? 1 : 0,
22
+ backgroundColor: treatment === 'soft' ? theme.colors.subtle : 'transparent',
23
+ },
24
+ style,
25
+ ], children: scrolling ? (_jsx(ScrollView, { horizontal: !vertical, keyboardShouldPersistTaps: "handled", children: body })) : (body) }));
26
+ }
27
+ export function ToolbarGroup(props) {
28
+ return _jsx(Cluster, { gap: "xs", ...props });
29
+ }
30
+ export function ToolbarSeparator(props) {
31
+ return _jsx(Separator, { orientation: "vertical", ...props });
32
+ }
33
+ export function ActionBar({ selectionCount, selectionLabel, showClear, clearLabel, onClear, disabled, position, placement, variant, size, children, style, ...props }) {
34
+ const { theme, direction, resolve } = useTramaAppearance();
35
+ const messages = useTramaMessages();
36
+ const { body, named } = splitContent(children, { actions: ActionBarActions, content: ActionBarContent });
37
+ const treatment = resolve(variant, 'outlined');
38
+ const fixed = resolve(position, 'inline') === 'fixed';
39
+ const top = resolve(placement, 'bottom') === 'top';
40
+ const count = Math.max(0, Math.floor(selectionCount ?? 0));
41
+ const summary = selectionCount === undefined ? undefined : (selectionLabel ?? messages.selectedCount)(count);
42
+ return (_jsx(View, { ...props, style: [
43
+ {
44
+ direction,
45
+ padding: theme.space * (3 + sizeStep[resolve(size, 'md')]),
46
+ borderColor: theme.colors.border,
47
+ borderWidth: treatment === 'plain' ? 0 : 1,
48
+ backgroundColor: theme.colors.surface,
49
+ borderRadius: treatment === 'floating' ? theme.radius : 0,
50
+ elevation: treatment === 'floating' ? 4 : 0,
51
+ },
52
+ fixed && {
53
+ position: 'absolute',
54
+ start: 0,
55
+ end: 0,
56
+ top: top ? 0 : undefined,
57
+ bottom: top ? undefined : 0,
58
+ zIndex: 10,
59
+ },
60
+ style,
61
+ ], children: _jsxs(Cluster, { justify: "between", children: [_jsx(View, { style: { flexShrink: 1 }, children: named.content ?? (_jsxs(ActionBarContent, { children: [summary, body] })) }), _jsxs(Cluster, { children: [named.actions, showClear && (_jsx(Button, { variant: "text", disabled: disabled || !onClear, onPress: onClear, children: clearLabel ?? messages.clearSelection }))] })] }) }));
62
+ }
63
+ export function ActionBarContent({ children, ...props }) {
64
+ const { theme } = useTramaAppearance();
65
+ return (_jsx(View, { ...props, children: _jsx(TextContent, { style: { color: theme.colors.text, fontSize: theme.fontSize, fontFamily: theme.fontFamily }, children: children }) }));
66
+ }
67
+ export function ActionBarActions(props) {
68
+ return _jsx(Cluster, { ...props });
69
+ }
70
+ export function EmptyState({ heading, description, align = 'center', icon, actions, children, style, ...props }) {
71
+ const { theme, direction } = useTramaAppearance();
72
+ const textAlign = align === 'center' ? 'center' : direction === 'rtl' ? 'right' : 'left';
73
+ return (_jsxs(Stack, { ...props, align: align, gap: "sm", style: [{ padding: theme.space * 4 }, style], children: [icon, heading && (_jsx(Text, { accessibilityRole: "header", style: { textAlign, fontSize: theme.fontSize + 4, color: theme.colors.text, fontWeight: '700' }, children: heading })), description && (_jsx(Text, { style: { textAlign, fontSize: theme.fontSize, color: theme.colors.muted }, children: description })), _jsx(TextContent, { style: { textAlign, color: theme.colors.text }, children: children }), actions] }));
74
+ }
@@ -0,0 +1,30 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type PressableProps, type ViewProps } from 'react-native';
3
+ import type { TramaResponsive } from './responsive.js';
4
+ import { type TramaColor, type TramaShape, type TramaSize } from './theme.js';
5
+ export type ButtonVariant = 'contained' | 'outlined' | 'text';
6
+ interface ButtonAppearance {
7
+ variant?: TramaResponsive<ButtonVariant>;
8
+ size?: TramaResponsive<TramaSize>;
9
+ color?: TramaResponsive<TramaColor>;
10
+ disabled?: boolean;
11
+ }
12
+ export interface ButtonProps extends Omit<PressableProps, 'children' | 'disabled'>, ButtonAppearance {
13
+ children?: ReactNode;
14
+ shape?: TramaResponsive<TramaShape>;
15
+ loading?: boolean;
16
+ loadingLabel?: string;
17
+ elevation?: boolean;
18
+ leading?: ReactNode;
19
+ trailing?: ReactNode;
20
+ pressed?: boolean;
21
+ defaultPressed?: boolean;
22
+ onPressedChange?: (pressed: boolean) => void;
23
+ }
24
+ export declare function Button({ variant, size, color, shape, disabled, loading, loadingLabel, elevation, leading, trailing, children, pressed, defaultPressed, onPressedChange, onPress, onFocus, onBlur, style, accessibilityState, accessibilityLabel, ...props }: ButtonProps): import("react").JSX.Element;
25
+ export interface ButtonGroupProps extends ViewProps, ButtonAppearance {
26
+ orientation?: TramaResponsive<'horizontal' | 'vertical'>;
27
+ }
28
+ export declare function ButtonLoading(props: ViewProps): import("react").JSX.Element;
29
+ export declare function ButtonGroup({ children, orientation, size, variant, color, disabled, style, ...props }: ButtonGroupProps): import("react").JSX.Element;
30
+ export {};
package/dist/button.js ADDED
@@ -0,0 +1,90 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createContext, useContext, useState } from 'react';
3
+ import { ActivityIndicator, Pressable, StyleSheet, View } from 'react-native';
4
+ import { splitContent, TextContent } from './internal/content.js';
5
+ import { useControllableValue } from './internal/state.js';
6
+ import { useTramaMessages } from './localization.js';
7
+ import { getTone, shapeRadius, sizeStep, useTramaAppearance, } from './theme.js';
8
+ const ButtonGroupContext = createContext({});
9
+ export function Button({ variant, size, color, shape, disabled, loading, loadingLabel, elevation, leading, trailing, children, pressed, defaultPressed, onPressedChange, onPress, onFocus, onBlur, style, accessibilityState, accessibilityLabel, ...props }) {
10
+ const { theme, direction, resolve } = useTramaAppearance();
11
+ const messages = useTramaMessages();
12
+ const group = useContext(ButtonGroupContext);
13
+ const { body, named } = splitContent(children, { loading: ButtonLoading });
14
+ const tone = getTone(theme, resolve(color ?? group.color, 'accent'));
15
+ const appearance = resolve(variant ?? group.variant, 'contained');
16
+ const step = sizeStep[resolve(size ?? group.size, 'md')];
17
+ const contained = appearance === 'contained';
18
+ const [focused, setFocused] = useState(false);
19
+ const [active, request] = useControllableValue(pressed, defaultPressed ?? false, onPressedChange);
20
+ const toggle = pressed !== undefined || defaultPressed !== undefined || onPressedChange !== undefined;
21
+ const unavailable = Boolean(disabled || group.disabled || loading);
22
+ const textColor = contained ? tone.ink : tone.text;
23
+ return (_jsxs(Pressable, { ...props, accessibilityRole: toggle ? 'togglebutton' : 'button', accessibilityLabel: loading ? (loadingLabel ?? accessibilityLabel ?? messages.loading) : accessibilityLabel, "aria-checked": toggle ? active : (props['aria-checked'] ?? accessibilityState?.checked), "aria-expanded": props['aria-expanded'] ?? accessibilityState?.expanded, "aria-selected": props['aria-selected'] ?? accessibilityState?.selected, "aria-busy": Boolean(loading), "aria-disabled": unavailable, accessibilityState: {
24
+ ...accessibilityState,
25
+ disabled: unavailable,
26
+ busy: Boolean(loading),
27
+ ...(toggle ? { checked: active } : {}),
28
+ }, disabled: unavailable, onPress: (event) => {
29
+ if (unavailable)
30
+ return;
31
+ if (toggle)
32
+ request(!active);
33
+ onPress?.(event);
34
+ }, onFocus: (event) => {
35
+ setFocused(true);
36
+ onFocus?.(event);
37
+ }, onBlur: (event) => {
38
+ setFocused(false);
39
+ onBlur?.(event);
40
+ }, style: (state) => [
41
+ styles.button,
42
+ {
43
+ direction,
44
+ gap: theme.space * 2,
45
+ minHeight: Math.max(44, theme.controlHeight + Math.max(0, step) * theme.space * 2),
46
+ minWidth: 44,
47
+ paddingHorizontal: theme.space * (4 + step),
48
+ paddingVertical: theme.space,
49
+ borderRadius: shapeRadius(theme, resolve(shape, 'rounded')),
50
+ borderColor: contained && active ? tone.ink : focused || appearance === 'outlined' ? tone.solid : 'transparent',
51
+ backgroundColor: contained ? tone.solid : active || state.pressed ? tone.soft : 'transparent',
52
+ opacity: disabled || group.disabled ? 0.55 : state.pressed && contained ? 0.82 : 1,
53
+ },
54
+ elevation && contained && styles.elevation,
55
+ typeof style === 'function' ? style(state) : style,
56
+ ], children: [loading ? (named.loading ?? _jsx(ActivityIndicator, { accessible: false, color: textColor })) : leading, _jsx(TextContent, { style: { color: textColor, fontFamily: theme.fontFamily, fontSize: theme.fontSize + step, fontWeight: '600' }, children: loading ? (loadingLabel ?? body) : body }), trailing] }));
57
+ }
58
+ export function ButtonLoading(props) {
59
+ return _jsx(View, { ...props, accessibilityElementsHidden: true, pointerEvents: "none" });
60
+ }
61
+ export function ButtonGroup({ children, orientation, size, variant, color, disabled, style, ...props }) {
62
+ const { direction, theme, resolve } = useTramaAppearance();
63
+ const vertical = resolve(orientation, 'horizontal') === 'vertical';
64
+ return (_jsx(ButtonGroupContext.Provider, { value: { size, variant, color, disabled }, children: _jsx(View, { ...props, style: [
65
+ {
66
+ direction,
67
+ flexDirection: vertical ? 'column' : 'row',
68
+ flexWrap: vertical ? 'nowrap' : 'wrap',
69
+ gap: theme.space * 2,
70
+ },
71
+ style,
72
+ ], children: children }) }));
73
+ }
74
+ const styles = StyleSheet.create({
75
+ button: {
76
+ alignItems: 'center',
77
+ alignSelf: 'flex-start',
78
+ borderWidth: 2,
79
+ flexDirection: 'row',
80
+ flexShrink: 1,
81
+ justifyContent: 'center',
82
+ },
83
+ elevation: {
84
+ elevation: 3,
85
+ shadowColor: '#000000',
86
+ shadowOffset: { width: 0, height: 2 },
87
+ shadowOpacity: 0.22,
88
+ shadowRadius: 4,
89
+ },
90
+ });
@@ -0,0 +1,71 @@
1
+ import { type CalendarIdentifier } from '@internationalized/date';
2
+ import { type ReactNode } from 'react';
3
+ import { type ViewProps } from 'react-native';
4
+ import { type ButtonProps } from './button.js';
5
+ import type { FieldHandle } from './input.js';
6
+ export interface DateRange {
7
+ start: string;
8
+ end: string;
9
+ }
10
+ export type CalendarValue = string | DateRange;
11
+ interface DayState {
12
+ date: string;
13
+ selected: boolean;
14
+ unavailable: boolean;
15
+ outside: boolean;
16
+ today: boolean;
17
+ }
18
+ export interface CalendarProps extends ViewProps {
19
+ selection?: 'single' | 'range';
20
+ value?: CalendarValue;
21
+ defaultValue?: CalendarValue;
22
+ onValueChange?: (value: CalendarValue) => void | false;
23
+ month?: string;
24
+ defaultMonth?: string;
25
+ onMonthChange?: (month: string) => void;
26
+ min?: string;
27
+ max?: string;
28
+ unavailableDates?: readonly string[];
29
+ isDateUnavailable?: (date: string) => boolean;
30
+ allowUnavailableInRange?: boolean;
31
+ locale?: string;
32
+ calendar?: CalendarIdentifier;
33
+ firstDayOfWeek?: number;
34
+ navigation?: 'arrows' | 'select';
35
+ showOutsideDays?: boolean;
36
+ disabled?: boolean;
37
+ readOnly?: boolean;
38
+ renderDay?: (day: DayState) => ReactNode;
39
+ }
40
+ export declare function Calendar({ selection, value, defaultValue, onValueChange, month, defaultMonth, onMonthChange, min, max, unavailableDates, isDateUnavailable, allowUnavailableInRange, locale, calendar, firstDayOfWeek, navigation, showOutsideDays, disabled, readOnly, renderDay, style, children, ...props }: CalendarProps): import("react").JSX.Element;
41
+ export interface CalendarDayProps extends ViewProps {
42
+ date: string;
43
+ color?: string;
44
+ unavailable?: boolean;
45
+ }
46
+ export declare function CalendarDay({ children, style }: CalendarDayProps): import("react").JSX.Element;
47
+ export declare function CalendarDayDetail({ children, style }: CalendarDayProps): import("react").JSX.Element;
48
+ export interface DatePickerProps extends CalendarProps {
49
+ label?: string;
50
+ placeholder?: string;
51
+ required?: boolean;
52
+ invalid?: boolean;
53
+ error?: string;
54
+ presentation?: 'date' | 'datetime';
55
+ time?: string;
56
+ defaultTime?: string;
57
+ onTimeChange?: (value: string) => void;
58
+ open?: boolean;
59
+ defaultOpen?: boolean;
60
+ onOpenChange?: (value: boolean) => void;
61
+ commitMode?: 'immediate' | 'confirm';
62
+ }
63
+ export declare const DatePicker: import("react").ForwardRefExoticComponent<DatePickerProps & import("react").RefAttributes<FieldHandle>>;
64
+ export declare function DatePickerActions({ style, ...props }: ViewProps): import("react").JSX.Element;
65
+ export declare function DatePickerCancel({ children, onPress, ...props }: ButtonProps): import("react").JSX.Element;
66
+ export declare function DatePickerConfirm({ children, onPress, ...props }: ButtonProps): import("react").JSX.Element;
67
+ export interface DatePresetProps extends ButtonProps {
68
+ value: CalendarValue;
69
+ }
70
+ export declare function DatePreset({ value, onPress, ...props }: DatePresetProps): import("react").JSX.Element;
71
+ export {};
@@ -0,0 +1,276 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createCalendar, getDayOfWeek, parseDate, startOfMonth, toCalendar, today, } from '@internationalized/date';
3
+ import { Children, createContext, forwardRef, isValidElement, useContext, useImperativeHandle, useRef, useState, } from 'react';
4
+ import { Pressable, Text, View } from 'react-native';
5
+ import { Button } from './button.js';
6
+ import { FieldMessage, splitContent, TextContent } from './internal/content.js';
7
+ import { useControllableValue, useFieldValidation } from './internal/state.js';
8
+ import { Cluster } from './layout.js';
9
+ import { useTramaLocale, useTramaMessages } from './localization.js';
10
+ import { Dialog } from './overlays.js';
11
+ import { Select } from './select.js';
12
+ import { TimeField } from './text-fields.js';
13
+ import { useTramaAppearance, useTramaTheme } from './theme.js';
14
+ function parse(value) {
15
+ try {
16
+ return value ? parseDate(value) : undefined;
17
+ }
18
+ catch {
19
+ return undefined;
20
+ }
21
+ }
22
+ function startValue(value) {
23
+ return typeof value === 'string' ? value : value?.start;
24
+ }
25
+ function formatter(locale, calendar, options) {
26
+ return new Intl.DateTimeFormat(locale, { ...options, calendar, timeZone: 'UTC' });
27
+ }
28
+ function dayParts(children) {
29
+ return Children.toArray(children).flatMap((child) => isValidElement(child) && (child.type === CalendarDay || child.type === CalendarDayDetail)
30
+ ? [child.props]
31
+ : []);
32
+ }
33
+ function rangeAvailable(start, end, unavailable, allowUnavailable) {
34
+ const first = parse(start);
35
+ const last = parse(end);
36
+ if (!first || !last || first.compare(last) > 0 || unavailable(start) || unavailable(end))
37
+ return false;
38
+ if (allowUnavailable)
39
+ return true;
40
+ for (let day = first.add({ days: 1 }); day.compare(last) < 0; day = day.add({ days: 1 })) {
41
+ if (unavailable(day.toString()))
42
+ return false;
43
+ }
44
+ return true;
45
+ }
46
+ export function Calendar({ selection = 'single', value, defaultValue, onValueChange, month, defaultMonth, onMonthChange, min, max, unavailableDates, isDateUnavailable, allowUnavailableInRange, locale, calendar, firstDayOfWeek, navigation = 'arrows', showOutsideDays, disabled, readOnly, renderDay, style, children, ...props }) {
47
+ const { theme, direction } = useTramaAppearance();
48
+ const defaultLocale = useTramaLocale();
49
+ const messages = useTramaMessages();
50
+ const language = locale ?? defaultLocale;
51
+ const calendarName = calendar ?? new Intl.DateTimeFormat(language).resolvedOptions().calendar;
52
+ const system = createCalendar(calendarName);
53
+ const actualToday = today(Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC');
54
+ const todayKey = actualToday.toString();
55
+ const [selected, setSelected] = useControllableValue(value, defaultValue ?? (selection === 'range' ? { start: '', end: '' } : ''));
56
+ const [cursorValue, setCursor] = useControllableValue(month, defaultMonth ?? startValue(value ?? defaultValue) ?? todayKey, onMonthChange);
57
+ const first = startOfMonth(toCalendar(parse(cursorValue) ?? actualToday, system));
58
+ const firstIndex = firstDayOfWeek === undefined
59
+ ? getDayOfWeek(first, language)
60
+ : (getDayOfWeek(first, 'en-US') - firstDayOfWeek + 7) % 7;
61
+ const dayFormat = formatter(language, system.identifier, { dateStyle: 'full' });
62
+ const headingFormat = formatter(language, system.identifier, { month: 'long', year: 'numeric' });
63
+ const weekdayFormat = formatter(language, system.identifier, { weekday: 'short' });
64
+ const dayNumber = new Intl.NumberFormat(language);
65
+ const selectedStart = startValue(selected);
66
+ const selectedEnd = typeof selected === 'string' ? selected : selected.end;
67
+ const named = dayParts(children);
68
+ const months = Array.from({ length: system.getMonthsInYear(first) }, (_, index) => {
69
+ const date = first.set({ month: index + 1 });
70
+ return {
71
+ value: String(index + 1),
72
+ label: formatter(language, system.identifier, { month: 'long' }).format(date.toDate('UTC')),
73
+ };
74
+ });
75
+ const years = Array.from({ length: 25 }, (_, index) => first.add({ years: index - 12 })).map((date) => ({
76
+ value: date.toString(),
77
+ label: formatter(language, system.identifier, { year: 'numeric' }).format(date.toDate('UTC')),
78
+ }));
79
+ function move(change) {
80
+ if (change.compare(first) !== 0)
81
+ setCursor(change.toString());
82
+ }
83
+ function unavailable(date) {
84
+ return Boolean((min && date < min) ||
85
+ (max && date > max) ||
86
+ unavailableDates?.includes(date) ||
87
+ isDateUnavailable?.(date) ||
88
+ named.some((entry) => entry.date === date && entry.unavailable));
89
+ }
90
+ function choose(candidate) {
91
+ const date = candidate.toString();
92
+ if (disabled || readOnly || unavailable(date))
93
+ return;
94
+ let next = date;
95
+ if (selection === 'range') {
96
+ if (!selectedStart || selectedEnd)
97
+ next = { start: date, end: '' };
98
+ else {
99
+ const [start, end] = [selectedStart, date].sort();
100
+ if (!rangeAvailable(start, end, unavailable, allowUnavailableInRange))
101
+ return;
102
+ next = { start, end };
103
+ }
104
+ }
105
+ if (onValueChange?.(next) !== false) {
106
+ setSelected(next);
107
+ if (candidate.month !== first.month || candidate.year !== first.year)
108
+ move(startOfMonth(candidate));
109
+ }
110
+ }
111
+ return (_jsxs(View, { ...props, style: [{ direction, gap: theme.space * 2, padding: theme.space * 2 }, style], children: [_jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: theme.space }, children: [_jsx(Button, { disabled: disabled || Boolean(min && first.subtract({ days: 1 }).toString() < min), variant: "text", accessibilityLabel: messages.previousMonth, onPress: () => move(first.subtract({ months: 1 })), children: direction === 'rtl' ? '›' : '‹' }), _jsx(Text, { accessibilityRole: "header", accessibilityLiveRegion: "polite", style: { flex: 1, textAlign: 'center', color: theme.colors.text, fontWeight: '700' }, children: headingFormat.format(first.toDate('UTC')) }), _jsx(Button, { disabled: disabled || Boolean(max && first.add({ months: 1 }).toString() > max), variant: "text", accessibilityLabel: messages.nextMonth, onPress: () => move(first.add({ months: 1 })), children: direction === 'rtl' ? '‹' : '›' })] }), navigation === 'select' && (_jsxs(View, { style: { flexDirection: 'row', gap: theme.space }, children: [_jsx(View, { style: { flex: 1 }, children: _jsx(Select, { label: messages.month, disabled: disabled, options: months, value: String(first.month), onValueChange: (next) => move(first.set({ month: Number(next) })) }) }), _jsx(View, { style: { flex: 1 }, children: _jsx(Select, { label: messages.year, disabled: disabled, options: years, value: first.toString(), onValueChange: (next) => move(toCalendar(parse(String(next)) ?? first, system)) }) })] })), _jsx(View, { style: { flexDirection: 'row' }, children: Array.from({ length: 7 }, (_, index) => (_jsx(Text, { accessible: false, numberOfLines: 1, style: { flex: 1, textAlign: 'center', color: theme.colors.muted }, children: weekdayFormat.format(first.add({ days: index - firstIndex }).toDate('UTC')) }, index))) }), Array.from({ length: 6 }, (_, week) => (_jsx(View, { style: { flexDirection: 'row' }, children: Array.from({ length: 7 }, (_, index) => {
112
+ const offset = week * 7 + index - firstIndex;
113
+ const date = first.add({ days: offset });
114
+ const key = date.toString();
115
+ const outside = offset < 0 || offset >= system.getDaysInMonth(first);
116
+ const offCalendar = system.toJulianDay(date) - system.toJulianDay(first) !== offset;
117
+ if (offCalendar || (outside && !showOutsideDays))
118
+ return _jsx(View, { style: { flex: 1 } }, index);
119
+ const override = named.find((entry) => entry.date === key);
120
+ const blocked = unavailable(key);
121
+ const active = selectedStart === key || selectedEnd === key;
122
+ const inRange = Boolean(selectedStart && selectedEnd && key > selectedStart && key < selectedEnd);
123
+ const state = {
124
+ date: key,
125
+ selected: active || inRange,
126
+ unavailable: blocked,
127
+ outside,
128
+ today: todayKey === key,
129
+ };
130
+ const label = dayFormat.format(date.toDate('UTC'));
131
+ const detail = override?.children ?? renderDay?.(state);
132
+ const text = active ? theme.colors.onAccent : outside || blocked ? theme.colors.muted : theme.colors.text;
133
+ return (_jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: detail && typeof detail === 'string' ? label + ', ' + detail : label, accessibilityState: { selected: state.selected, disabled: Boolean(disabled || readOnly || blocked) }, "aria-selected": state.selected, "aria-disabled": Boolean(disabled || readOnly || blocked), disabled: disabled || readOnly || blocked, onPress: () => choose(date), style: ({ pressed }) => [
134
+ {
135
+ flex: 1,
136
+ minHeight: 44,
137
+ paddingVertical: theme.space,
138
+ alignItems: 'center',
139
+ justifyContent: 'center',
140
+ borderRadius: theme.radius / 2,
141
+ borderWidth: 1,
142
+ borderColor: state.today ? theme.colors.accent : 'transparent',
143
+ opacity: blocked ? 0.6 : pressed ? 0.75 : 1,
144
+ backgroundColor: override?.color ?? (active ? theme.colors.accent : inRange ? theme.colors.subtle : 'transparent'),
145
+ },
146
+ override?.style,
147
+ ], children: [_jsx(Text, { style: {
148
+ color: text,
149
+ textDecorationLine: blocked ? 'line-through' : 'none',
150
+ fontSize: theme.fontSize,
151
+ }, children: dayNumber.format(date.day) }), _jsx(TextContent, { style: { color: text, fontSize: theme.fontSize - 3 }, children: detail })] }, index));
152
+ }) }, week)))] }));
153
+ }
154
+ export function CalendarDay({ children, style }) {
155
+ return _jsx(View, { style: style, children: children });
156
+ }
157
+ export function CalendarDayDetail({ children, style }) {
158
+ return _jsx(View, { style: style, children: children });
159
+ }
160
+ const PickerContext = createContext(null);
161
+ function complete(value) {
162
+ return typeof value === 'string'
163
+ ? Boolean(parse(value))
164
+ : Boolean(parse(value.start) && parse(value.end) && value.start <= value.end);
165
+ }
166
+ export const DatePicker = forwardRef(function DatePicker({ label, placeholder, required, invalid, error, presentation = 'date', time, defaultTime, onTimeChange, open, defaultOpen, onOpenChange, commitMode, value, defaultValue, onValueChange, children, style, ...calendar }, ref) {
167
+ const { theme, direction } = useTramaAppearance();
168
+ const messages = useTramaMessages();
169
+ const nativeLocale = useTramaLocale();
170
+ const language = calendar.locale ?? nativeLocale;
171
+ const confirmMode = commitMode ? commitMode === 'confirm' : presentation === 'datetime';
172
+ const empty = calendar.selection === 'range' ? { start: '', end: '' } : '';
173
+ const initial = value ?? defaultValue ?? empty;
174
+ const [committed, setCommitted] = useControllableValue(value, initial);
175
+ const [committedTime, setCommittedTime] = useControllableValue(time, defaultTime ?? '', onTimeChange);
176
+ const [visible, show] = useControllableValue(open, defaultOpen ?? false, onOpenChange);
177
+ const [draft, setDraft] = useState(initial);
178
+ const [draftTime, setDraftTime] = useState(time ?? defaultTime ?? '');
179
+ const [wasVisible, setWasVisible] = useState(visible);
180
+ if (visible !== wasVisible) {
181
+ setWasVisible(visible);
182
+ if (visible) {
183
+ setDraft(committed);
184
+ setDraftTime(committedTime);
185
+ }
186
+ }
187
+ const timeControl = useRef(null);
188
+ const { named, body } = splitContent(children, { actions: DatePickerActions, presets: DatePreset });
189
+ const parts = dayParts(body);
190
+ const calendarName = calendar.calendar ?? new Intl.DateTimeFormat(language).resolvedOptions().calendar;
191
+ const dateFormat = formatter(language, calendarName, { dateStyle: 'medium' });
192
+ const renderedValue = typeof committed === 'string' ? [committed].filter(Boolean) : [committed.start, committed.end].filter(Boolean);
193
+ const text = renderedValue
194
+ .map((date) => {
195
+ const parsed = parse(date);
196
+ return parsed ? dateFormat.format(parsed.toDate('UTC')) : date;
197
+ })
198
+ .join(' – ');
199
+ const invalidDate = (date) => Boolean((calendar.min && date < calendar.min) ||
200
+ (calendar.max && date > calendar.max) ||
201
+ calendar.unavailableDates?.includes(date) ||
202
+ calendar.isDateUnavailable?.(date) ||
203
+ parts.some((entry) => entry.date === date && entry.unavailable));
204
+ const valid = (candidate) => complete(candidate) &&
205
+ (typeof candidate === 'string'
206
+ ? !invalidDate(candidate)
207
+ : rangeAvailable(candidate.start, candidate.end, invalidDate, calendar.allowUnavailableInRange));
208
+ const dateIsValid = valid(committed);
209
+ const needsDate = (required || renderedValue.length > 0) && !dateIsValid;
210
+ const needsTime = presentation === 'datetime' &&
211
+ (required || renderedValue.length > 0) &&
212
+ !/^(?:[01][0-9]|2[0-3]):[0-5][0-9]$/u.test(committedTime);
213
+ const validation = useFieldValidation(error?.trim() || (invalid ? messages.reviewField : ''), needsDate ? messages.chooseDate : needsTime ? messages.enterTime : '', Boolean(calendar.disabled || calendar.readOnly));
214
+ useImperativeHandle(ref, () => validation);
215
+ const ready = valid(draft);
216
+ function commit(candidate) {
217
+ if ((typeof candidate !== 'string' &&
218
+ typeof committed !== 'string' &&
219
+ candidate.start === committed.start &&
220
+ candidate.end === committed.end) ||
221
+ candidate === committed)
222
+ return true;
223
+ if (onValueChange?.(candidate) === false)
224
+ return false;
225
+ setCommitted(candidate);
226
+ return true;
227
+ }
228
+ function choose(candidate) {
229
+ setDraft(candidate);
230
+ if (!confirmMode && valid(candidate) && commit(candidate) && presentation === 'date')
231
+ show(false);
232
+ }
233
+ function confirm() {
234
+ if (!ready || (presentation === 'datetime' && !timeControl.current?.reportValidity()))
235
+ return;
236
+ if (commit(draft)) {
237
+ if (presentation === 'datetime')
238
+ setCommittedTime(draftTime);
239
+ show(false);
240
+ }
241
+ }
242
+ return (_jsxs(View, { style: [{ direction, gap: theme.space }, style], children: [label && (_jsxs(Text, { style: { color: theme.colors.text, fontWeight: '600' }, children: [label, required ? ' *' : ''] })), _jsx(Button, { variant: "outlined", disabled: calendar.disabled || calendar.readOnly, "aria-expanded": visible, accessibilityLabel: label ? label + (text ? ', ' + text : '') : text || placeholder || messages.chooseDate, accessibilityHint: validation.message || undefined, onPress: () => show(true), children: text
243
+ ? text + (presentation === 'datetime' && committedTime ? ' ' + committedTime : '')
244
+ : (placeholder ?? messages.chooseDate) }), _jsx(FieldMessage, { message: validation.message, invalid: Boolean(validation.message), theme: theme }), _jsx(Dialog, { open: visible && !calendar.disabled && !calendar.readOnly, onOpenChange: show, heading: label ?? messages.chooseDate, children: _jsxs(PickerContext.Provider, { value: { confirm, close: () => show(false), preset: choose, ready }, children: [named.presets?.length ? _jsx(Cluster, { gap: "xs", children: named.presets }) : null, _jsx(Calendar, { ...calendar, value: draft, onValueChange: choose, children: body }), presentation === 'datetime' && (_jsx(TimeField, { label: messages.time, value: draftTime, onValueChange: (next) => {
245
+ setDraftTime(next);
246
+ if (!confirmMode)
247
+ setCommittedTime(next);
248
+ }, required: true, ref: timeControl })), named.actions ?? (_jsxs(DatePickerActions, { children: [_jsx(DatePickerCancel, {}), (confirmMode || presentation === 'datetime') && _jsx(DatePickerConfirm, {})] }))] }) })] }));
249
+ });
250
+ export function DatePickerActions({ style, ...props }) {
251
+ const theme = useTramaTheme();
252
+ return (_jsx(View, { ...props, style: [{ flexDirection: 'row', flexWrap: 'wrap', justifyContent: 'flex-end', gap: theme.space }, style] }));
253
+ }
254
+ export function DatePickerCancel({ children, onPress, ...props }) {
255
+ const state = useContext(PickerContext);
256
+ const messages = useTramaMessages();
257
+ return (_jsx(Button, { variant: "text", ...props, onPress: (event) => {
258
+ onPress?.(event);
259
+ state?.close();
260
+ }, children: children ?? messages.cancel }));
261
+ }
262
+ export function DatePickerConfirm({ children, onPress, ...props }) {
263
+ const state = useContext(PickerContext);
264
+ const messages = useTramaMessages();
265
+ return (_jsx(Button, { ...props, disabled: props.disabled || !state?.ready, onPress: (event) => {
266
+ onPress?.(event);
267
+ state?.confirm();
268
+ }, children: children ?? messages.saveValue }));
269
+ }
270
+ export function DatePreset({ value, onPress, ...props }) {
271
+ const state = useContext(PickerContext);
272
+ return (_jsx(Button, { variant: "outlined", ...props, onPress: (event) => {
273
+ onPress?.(event);
274
+ state?.preset(value);
275
+ } }));
276
+ }
package/dist/card.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type ImageProps, type PressableProps, type ViewProps } from 'react-native';
3
+ import type { TramaResponsive } from './responsive.js';
4
+ export type CardSize = 'sm' | 'md' | 'lg' | 'full';
5
+ export type CardSpacing = 'none' | 'sm' | 'md' | 'lg';
6
+ export type CardVariant = 'outlined' | 'filled' | 'dashed';
7
+ export type CardOrientation = 'vertical' | 'horizontal';
8
+ export interface CardProps extends ViewProps {
9
+ heading?: TramaResponsive<string>;
10
+ description?: TramaResponsive<string>;
11
+ size?: TramaResponsive<CardSize>;
12
+ padding?: TramaResponsive<CardSpacing>;
13
+ gap?: TramaResponsive<CardSpacing>;
14
+ elevation?: TramaResponsive<CardSpacing>;
15
+ variant?: TramaResponsive<CardVariant>;
16
+ orientation?: TramaResponsive<CardOrientation>;
17
+ mediaPlacement?: TramaResponsive<'start' | 'end'>;
18
+ actionsAlign?: TramaResponsive<'start' | 'end' | 'between'>;
19
+ divided?: TramaResponsive<boolean>;
20
+ image?: TramaResponsive<string>;
21
+ imageSource?: ImageProps['source'];
22
+ imageAlt?: TramaResponsive<string>;
23
+ imageAspectRatio?: TramaResponsive<number>;
24
+ imageFit?: TramaResponsive<'cover' | 'contain'>;
25
+ imageFallback?: ReactNode;
26
+ onImageError?: ImageProps['onError'];
27
+ onImageLoad?: ImageProps['onLoad'];
28
+ onPress?: PressableProps['onPress'];
29
+ selectable?: TramaResponsive<boolean>;
30
+ selected?: boolean;
31
+ defaultSelected?: boolean;
32
+ onSelectedChange?: (selected: boolean) => void | false;
33
+ disabled?: TramaResponsive<boolean>;
34
+ actionLabel?: TramaResponsive<string>;
35
+ }
36
+ export declare 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 }: CardProps): import("react").JSX.Element;
37
+ export declare function CardHeader({ children, style, ...props }: ViewProps): import("react").JSX.Element;
38
+ export declare function CardMedia(props: ViewProps): import("react").JSX.Element;
39
+ export declare function CardFooter({ children, ...props }: ViewProps): import("react").JSX.Element;
40
+ export declare function CardHeaderActions({ children, style, ...props }: ViewProps): import("react").JSX.Element;
41
+ export declare function CardActions({ children, style, ...props }: ViewProps): import("react").JSX.Element;