@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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Trama UI contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,199 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Trama UI for React Native
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Use Trama components in an iOS or Android screen built with React Native or Expo.
|
|
4
|
+
This preview uses native views, text, press handling, images and text inputs.
|
|
5
|
+
|
|
6
|
+
## Install a preview archive
|
|
7
|
+
|
|
8
|
+
Build the archive from a Trama checkout with `bun install --frozen-lockfile`
|
|
9
|
+
and `bun run native:pack`. Copy the resulting
|
|
10
|
+
`trama-ui-react-native-0.7.0.tgz` into your React Native or Expo app, then run:
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
bun add ./trama-ui-react-native-0.7.0.tgz
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
The app supplies React 19.2.3 or later within React 19 and React Native
|
|
17
|
+
0.86–0.88. Expo manages its own matching React and React Native versions.
|
|
18
|
+
The package uses the app's standard Metro configuration. The preview archive
|
|
19
|
+
is the installation source until an npm version is published.
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { useState } from 'react';
|
|
23
|
+
import { View } from 'react-native';
|
|
24
|
+
import { Button, Input, ThemeProvider } from '@trama-ui/react-native';
|
|
25
|
+
|
|
26
|
+
export default function App() {
|
|
27
|
+
const [name, setName] = useState('');
|
|
28
|
+
const [saved, setSaved] = useState(false);
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<ThemeProvider mode="system">
|
|
32
|
+
<View style={{ padding: 24, gap: 12 }}>
|
|
33
|
+
<Input label="Display name" value={name} onChangeText={setName} />
|
|
34
|
+
<Button
|
|
35
|
+
variant={{ base: 'contained', md: 'outlined' }}
|
|
36
|
+
disabled={!name.trim()}
|
|
37
|
+
onPress={() => setSaved(true)}
|
|
38
|
+
>
|
|
39
|
+
{saved ? 'Saved' : 'Save profile'}
|
|
40
|
+
</Button>
|
|
41
|
+
</View>
|
|
42
|
+
</ThemeProvider>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`ThemeProvider` is optional. Customize tokens with `theme`, scope a particular
|
|
48
|
+
direction with `direction`, or supply a measured view width with `width`.
|
|
49
|
+
Responsive values start at `base` and switch at the corresponding minimum
|
|
50
|
+
width in React Native layout units. With no width override, components use
|
|
51
|
+
the app window.
|
|
52
|
+
|
|
53
|
+
For the full Trama icon set, install `react-native-svg` in your app and import
|
|
54
|
+
`Icon` from `@trama-ui/react-native/icon`. In Expo, use
|
|
55
|
+
`bun expo install react-native-svg` so Expo chooses the matching native version.
|
|
56
|
+
The main package entry works without this dependency.
|
|
57
|
+
|
|
58
|
+
## Disclosure, feedback and cards
|
|
59
|
+
|
|
60
|
+
Use Accordion for related sections. Add direct `AccordionItem` children with
|
|
61
|
+
unique values. Use `defaultValue` to open sections on arrival, or use `value`
|
|
62
|
+
and accept requests in `onValueChange`. `multiple` lets more than one section
|
|
63
|
+
stay open. Panels keep their internal state while closed by default, including
|
|
64
|
+
text typed into a field. Set `panelPersistence="unmount"` for panels that should
|
|
65
|
+
start fresh when reopened.
|
|
66
|
+
|
|
67
|
+
```tsx
|
|
68
|
+
import { Accordion, AccordionItem, AccordionPanel } from '@trama-ui/react-native';
|
|
69
|
+
|
|
70
|
+
<Accordion multiple defaultValue={['visibility', 'notifications']}>
|
|
71
|
+
<AccordionItem value="visibility" label="Workspace visibility">
|
|
72
|
+
<AccordionPanel>Everyone in your workspace can see your name and avatar.</AccordionPanel>
|
|
73
|
+
</AccordionItem>
|
|
74
|
+
<AccordionItem value="notifications" label="Notifications">
|
|
75
|
+
<AccordionPanel>Workspace updates are sent to your primary email.</AccordionPanel>
|
|
76
|
+
</AccordionItem>
|
|
77
|
+
</Accordion>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Place an Alert beside the result it describes. `dismissible` allows local
|
|
81
|
+
dismissal. If the screen owns visibility through `open`, update it in
|
|
82
|
+
`onDismiss`. Use `announcement="polite"` for confirmation and reserve
|
|
83
|
+
`assertive` for urgent updates. Supply `announcementText` when a rich React
|
|
84
|
+
child needs a spoken summary. A full-width Alert stretches to its parent.
|
|
85
|
+
Place sticky notices in the screen's scroll header or in a fixed footer.
|
|
86
|
+
|
|
87
|
+
Use Card to show a self-contained item. Supply `imageSource` for a bundled
|
|
88
|
+
image, `image` for a URL, or `CardMedia` for custom media. Use responsive
|
|
89
|
+
`orientation` to keep the media above the content on narrow screens. Put
|
|
90
|
+
interactive children in `CardHeaderActions` or `CardActions` when the main
|
|
91
|
+
Card has an `onPress` handler or is selectable. Each action can then handle
|
|
92
|
+
presses and accessibility focus independently.
|
|
93
|
+
|
|
94
|
+
## Preview API
|
|
95
|
+
|
|
96
|
+
| Export | Available in the preview |
|
|
97
|
+
| --- | --- |
|
|
98
|
+
| `Accordion`, `AccordionItem`, `AccordionSummary`, `AccordionIcon`, `AccordionPanel`, `AccordionActions` | `value`, `defaultValue`, `onValueChange`, multiple expansion, group and item disabled state, variant, collapse policy and panel persistence |
|
|
99
|
+
| `Alert`, `AlertActions` | Severity and palette, variant and width, custom or hidden icon, heading and actions, `open`, `defaultOpen`, `onDismiss`, localized close label and announcement controls |
|
|
100
|
+
| `Avatar` | `source` or `src`, label, accessible name, initials, fallback, badge content, size, shape, image callbacks |
|
|
101
|
+
| `Button`, `ButtonGroup` | `onPress`, disabled and loading, color, variant, shape, size, elevation, leading and trailing content, optional pressed state, shared group defaults |
|
|
102
|
+
| `Card`, `CardMedia`, `CardHeader`, `CardHeaderActions`, `CardFooter`, `CardActions` | Size, spacing, surface, elevation, media placement and image fallback, `onPress`, `selected`, `defaultSelected`, `onSelectedChange` and action alignment |
|
|
103
|
+
| `Input` | Native text input props, label, description, hint, invalid and error messages, read-only and disabled states, length and required validation, size, shape and variant |
|
|
104
|
+
| `Icon` (from `/icon`) | The full shared glyph catalog, numeric and preset sizes, stroke weight, color, logical RTL mirroring, custom artwork and accessible labels |
|
|
105
|
+
| `Loader` | Ring, animated dots or bars, custom visual, delay, active state, accessible label, visible label position, size and color |
|
|
106
|
+
| `Pill`, `PillAction` | Label, leading and trailing content, separate actions or removal button, optional selection, and visual variants |
|
|
107
|
+
| `Progress` | Linear, circular and dashboard progress, range and buffer, determinate and indeterminate states, value wording, and value placement |
|
|
108
|
+
| `Separator` | Horizontal or vertical layouts, spacing, line weight, color and optional label |
|
|
109
|
+
| `Switch` | Checked and initial checked values, required check, description and errors, disabled and read-only states, variant, shape and label position |
|
|
110
|
+
| `Table`, `DataGrid` | Typed inline editors, selection and clipboard adapters, multi-sort, grouped and pinned columns, row and column virtualization, and pageable data sources |
|
|
111
|
+
| `Tour`, `TourStep` | Controlled steps, measured targets, spotlight, and custom indicator |
|
|
112
|
+
| `ThemeProvider`, `LocalizationProvider` | Theme token and breakpoint overrides, light and dark modes, RTL, and English, Italian or German validation messages with overrides |
|
|
113
|
+
|
|
114
|
+
Use `value`, `checked`, `pressed`, or `selected` for component state owned
|
|
115
|
+
by the app. Use the corresponding `default*` prop for internal state.
|
|
116
|
+
The `Input` and `Switch` refs expose `checkValidity()` and `reportValidity()`.
|
|
117
|
+
Call the latter from your screen's submit action to reveal a required or
|
|
118
|
+
length error and decide whether to save. Keep app errors in `error` until
|
|
119
|
+
the app accepts a correction.
|
|
120
|
+
|
|
121
|
+
## Catalog coverage
|
|
122
|
+
|
|
123
|
+
The native package includes preview exports for the full Trama catalog.
|
|
124
|
+
Run `bun run native:coverage --list` from the Trama checkout to see the
|
|
125
|
+
status of each family and dedicated part. Native examples use ordinary React
|
|
126
|
+
children, native styles and callbacks. File Upload takes an application file
|
|
127
|
+
picker via `chooseFiles`, and Code Block takes a clipboard adapter via
|
|
128
|
+
`onCopy`.
|
|
129
|
+
|
|
130
|
+
The DataGrid uses `defaultRows` for local edits and `rows` with
|
|
131
|
+
`onRowsChange` for app-owned data. Clipboard actions use the app's
|
|
132
|
+
`readText` and `writeText` adapter. Give large reading tables an exact
|
|
133
|
+
`rowHeight` with `virtualized`, `columnVirtualized`, and a bounded
|
|
134
|
+
`height` for both scroll axes. Remote queries receive an abort signal
|
|
135
|
+
through `dataSource`.
|
|
136
|
+
|
|
137
|
+
A column can return `rowSpan(row)` to merge a cell down across its part of
|
|
138
|
+
the current page. `colSpan(row)` works alongside it. Add an `editor` to the
|
|
139
|
+
column to edit the merged cell's anchor. The other covered values stay in
|
|
140
|
+
the source rows. Give each row a stable `rowId` and use `rowHeight` when the
|
|
141
|
+
merged content needs more space.
|
|
142
|
+
|
|
143
|
+
Use `cellSelection="range"` with `dragSelection` to select cells with a
|
|
144
|
+
mouse or with **Drag to select cells** on touch. The grid previews the range
|
|
145
|
+
and calls `onCellRangeChange` on release. The edge of a bounded grid scrolls
|
|
146
|
+
more cells into view. **Extend selection** works with two taps, and Shift
|
|
147
|
+
plus an arrow key extends the range when keyboard navigation is enabled.
|
|
148
|
+
Copy leaves covered positions blank. Keep those positions blank when pasting
|
|
149
|
+
a range across a merge.
|
|
150
|
+
|
|
151
|
+
Use `keyboardNavigation` for arrow, Home, End and Page navigation. On iOS and
|
|
152
|
+
Android, provide a focusable keyboard adapter through `keyboardCell`. This
|
|
153
|
+
example uses `react-native-external-keyboard` in an Expo development build or a
|
|
154
|
+
bare React Native app. Use its 2.x series on React Native 0.87–0.88 and 1.2.2 on
|
|
155
|
+
React Native 0.86. Rebuild the app after adding the native module. The adapter
|
|
156
|
+
handles Control chords with that module. Command chords require an event
|
|
157
|
+
source that reports Meta on iOS.
|
|
158
|
+
|
|
159
|
+
```tsx
|
|
160
|
+
import { createTableKeyboardCell, DataGrid } from '@trama-ui/react-native';
|
|
161
|
+
import { KeyboardExtendedPressable } from 'react-native-external-keyboard';
|
|
162
|
+
|
|
163
|
+
const GridKeyboardCell = createTableKeyboardCell(KeyboardExtendedPressable);
|
|
164
|
+
|
|
165
|
+
export function ProjectGrid() {
|
|
166
|
+
return (
|
|
167
|
+
<DataGrid
|
|
168
|
+
rows={[{ id: 'release', task: 'Prepare release' }]}
|
|
169
|
+
columns={[{ id: 'task', heading: 'Task' }]}
|
|
170
|
+
rowId={(row) => row.id}
|
|
171
|
+
keyboardNavigation
|
|
172
|
+
keyboardCell={GridKeyboardCell}
|
|
173
|
+
/>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
`CommandMenu` scrolls results independently of search. Use `listHeight` to
|
|
179
|
+
set the maximum results height. Forward normalized hardware keys to
|
|
180
|
+
`CommandMenuHandle.handleKey` from your app to use an `openShortcut`. Enable
|
|
181
|
+
`shortcuts` to run a matching visible command while the menu is open. The
|
|
182
|
+
method reports whether the menu handled the event.
|
|
183
|
+
|
|
184
|
+
`FileUpload` passes an `AbortSignal` to `chooseFiles`. Calling `cancelBrowse()`
|
|
185
|
+
or clearing the field discards late results. The Browse action is available
|
|
186
|
+
again after the picker settles. Return `null` when the system picker is dismissed.
|
|
187
|
+
|
|
188
|
+
Inside `DragDropProvider`, wrap a long list of `DropZone` destinations in a
|
|
189
|
+
bounded `DragScrollArea` to scroll near its edges during a drag. Use `style`
|
|
190
|
+
to set its height, or give it a bounded parent with flex layout. Include a
|
|
191
|
+
`MoveMenu` that names the same destinations for selection with a tap.
|
|
192
|
+
|
|
193
|
+
Install the optional `trama-ui-react-native-system-drag-0.7.0.tgz` archive
|
|
194
|
+
to exchange links, text and files with other apps on iOS and Android. Rebuild
|
|
195
|
+
the app and pass its `SystemDragSurface` export to `DragDropProvider` as
|
|
196
|
+
`systemSurface`. The companion's README covers source and destination setup.
|
|
197
|
+
|
|
198
|
+
The [native architecture and porting sequence](../../docs/react-native-architecture.md)
|
|
199
|
+
define the conditions for marking an element verified.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type ViewProps } from 'react-native';
|
|
2
|
+
import type { TramaResponsive } from './responsive.js';
|
|
3
|
+
export type AccordionVariant = 'bordered' | 'borderless' | 'card';
|
|
4
|
+
export type AccordionPanelPersistence = 'mounted' | 'unmount';
|
|
5
|
+
export interface AccordionChangeDetail {
|
|
6
|
+
item: string;
|
|
7
|
+
expanded: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface AccordionProps extends ViewProps {
|
|
10
|
+
value?: readonly string[];
|
|
11
|
+
defaultValue?: readonly string[];
|
|
12
|
+
onValueChange?: (value: readonly string[], detail: AccordionChangeDetail) => void | false;
|
|
13
|
+
multiple?: TramaResponsive<boolean>;
|
|
14
|
+
collapsible?: TramaResponsive<boolean>;
|
|
15
|
+
disabled?: TramaResponsive<boolean>;
|
|
16
|
+
variant?: TramaResponsive<AccordionVariant>;
|
|
17
|
+
panelPersistence?: TramaResponsive<AccordionPanelPersistence>;
|
|
18
|
+
}
|
|
19
|
+
export declare function Accordion({ value, defaultValue, onValueChange, multiple, collapsible, disabled, variant, panelPersistence, style, children, ...props }: AccordionProps): import("react").JSX.Element;
|
|
20
|
+
export interface AccordionItemProps extends ViewProps {
|
|
21
|
+
value: string;
|
|
22
|
+
label: TramaResponsive<string>;
|
|
23
|
+
disabled?: TramaResponsive<boolean>;
|
|
24
|
+
}
|
|
25
|
+
export declare function AccordionItem({ value, label, disabled, children, style, ...props }: AccordionItemProps): import("react").JSX.Element | null;
|
|
26
|
+
export declare function AccordionSummary({ children, ...props }: ViewProps): import("react").JSX.Element;
|
|
27
|
+
export declare function AccordionIcon({ children, ...props }: ViewProps): import("react").JSX.Element;
|
|
28
|
+
export declare function AccordionPanel({ children, ...props }: ViewProps): import("react").JSX.Element;
|
|
29
|
+
export declare function AccordionActions({ children, style, ...props }: ViewProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Children, createContext, isValidElement, useContext, useId, useState } from 'react';
|
|
3
|
+
import { Pressable, StyleSheet, Text, View } from 'react-native';
|
|
4
|
+
import { splitContent, TextContent } from './internal/content.js';
|
|
5
|
+
import { useTramaAppearance, useTramaTheme } from './theme.js';
|
|
6
|
+
const AccordionContext = createContext(null);
|
|
7
|
+
function sameValues(left, right) {
|
|
8
|
+
return left.length === right.length && left.every((value, index) => value === right[index]);
|
|
9
|
+
}
|
|
10
|
+
export function Accordion({ value, defaultValue, onValueChange, multiple, collapsible, disabled, variant, panelPersistence, style, children, ...props }) {
|
|
11
|
+
const { theme, direction, resolve } = useTramaAppearance();
|
|
12
|
+
const layout = resolve(variant, 'bordered');
|
|
13
|
+
const allowsMultiple = resolve(multiple, false);
|
|
14
|
+
const allowsCollapse = resolve(collapsible, true);
|
|
15
|
+
const groupDisabled = resolve(disabled, false);
|
|
16
|
+
const persistence = resolve(panelPersistence, 'mounted');
|
|
17
|
+
const seen = new Set();
|
|
18
|
+
const items = Children.toArray(children).flatMap((child) => {
|
|
19
|
+
if (!isValidElement(child) || child.type !== AccordionItem)
|
|
20
|
+
return [];
|
|
21
|
+
const id = child.props.value;
|
|
22
|
+
if (!id.trim() || !resolve(child.props.label, '').trim() || seen.has(id))
|
|
23
|
+
return [];
|
|
24
|
+
seen.add(id);
|
|
25
|
+
return [child];
|
|
26
|
+
});
|
|
27
|
+
const [internalValue, setInternalValue] = useState(() => defaultValue ?? []);
|
|
28
|
+
const known = [...new Set((value ?? internalValue).filter((id) => seen.has(id)))];
|
|
29
|
+
const expanded = allowsMultiple ? known : known.slice(0, 1);
|
|
30
|
+
// Keep the last effective value when leaving controlled mode. Prune removed
|
|
31
|
+
// items and the extra values when an uncontrolled group becomes single.
|
|
32
|
+
if (!sameValues(internalValue, expanded))
|
|
33
|
+
setInternalValue(expanded);
|
|
34
|
+
function toggle(item) {
|
|
35
|
+
if (groupDisabled || !seen.has(item))
|
|
36
|
+
return;
|
|
37
|
+
const isOpen = expanded.includes(item);
|
|
38
|
+
if (isOpen && !allowsCollapse && expanded.length === 1)
|
|
39
|
+
return;
|
|
40
|
+
const next = isOpen ? expanded.filter((id) => id !== item) : allowsMultiple ? [...expanded, item] : [item];
|
|
41
|
+
if (onValueChange?.(next, { item, expanded: !isOpen }) === false)
|
|
42
|
+
return;
|
|
43
|
+
if (value === undefined)
|
|
44
|
+
setInternalValue(next);
|
|
45
|
+
}
|
|
46
|
+
return (_jsx(AccordionContext.Provider, { value: {
|
|
47
|
+
values: expanded,
|
|
48
|
+
disabled: groupDisabled,
|
|
49
|
+
collapsible: allowsCollapse,
|
|
50
|
+
variant: layout,
|
|
51
|
+
panelPersistence: persistence,
|
|
52
|
+
toggle,
|
|
53
|
+
}, children: _jsx(View, { ...props, style: [
|
|
54
|
+
{
|
|
55
|
+
direction,
|
|
56
|
+
gap: layout === 'card' ? theme.space * 2 : 0,
|
|
57
|
+
borderWidth: layout === 'bordered' ? 1 : 0,
|
|
58
|
+
borderRadius: theme.radius,
|
|
59
|
+
borderColor: theme.colors.border,
|
|
60
|
+
},
|
|
61
|
+
style,
|
|
62
|
+
], children: items.map((item, index) => (_jsx(View, { style: {
|
|
63
|
+
borderTopWidth: index > 0 && layout === 'bordered' ? StyleSheet.hairlineWidth : 0,
|
|
64
|
+
borderColor: theme.colors.border,
|
|
65
|
+
}, children: item }, item.props.value))) }) }));
|
|
66
|
+
}
|
|
67
|
+
export function AccordionItem({ value, label, disabled, children, style, ...props }) {
|
|
68
|
+
const accordion = useContext(AccordionContext);
|
|
69
|
+
const { theme, direction, resolve } = useTramaAppearance();
|
|
70
|
+
const [focused, setFocused] = useState(false);
|
|
71
|
+
const panelId = useId();
|
|
72
|
+
const { body, named } = splitContent(children, {
|
|
73
|
+
summary: AccordionSummary,
|
|
74
|
+
icon: AccordionIcon,
|
|
75
|
+
actions: AccordionActions,
|
|
76
|
+
});
|
|
77
|
+
if (!accordion)
|
|
78
|
+
return null;
|
|
79
|
+
const expanded = accordion.values.includes(value);
|
|
80
|
+
const unavailable = accordion.disabled || resolve(disabled, false);
|
|
81
|
+
const locked = expanded && !accordion.collapsible && accordion.values.length === 1;
|
|
82
|
+
const title = resolve(label, '');
|
|
83
|
+
const renderPanel = expanded || accordion.panelPersistence === 'mounted';
|
|
84
|
+
return (_jsxs(View, { ...props, style: [
|
|
85
|
+
{
|
|
86
|
+
borderWidth: accordion.variant === 'card' ? 1 : 0,
|
|
87
|
+
borderColor: theme.colors.border,
|
|
88
|
+
borderRadius: theme.radius,
|
|
89
|
+
backgroundColor: accordion.variant === 'card' ? theme.colors.surface : 'transparent',
|
|
90
|
+
},
|
|
91
|
+
style,
|
|
92
|
+
], children: [_jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: title, accessibilityState: { expanded, disabled: unavailable || locked }, "aria-expanded": expanded, "aria-disabled": unavailable || locked, "aria-controls": renderPanel ? panelId : undefined, disabled: unavailable, onPress: () => accordion.toggle(value), onFocus: () => setFocused(true), onBlur: () => setFocused(false), style: ({ pressed }) => ({
|
|
93
|
+
direction,
|
|
94
|
+
flexDirection: 'row',
|
|
95
|
+
alignItems: 'center',
|
|
96
|
+
gap: theme.space * 3,
|
|
97
|
+
minHeight: Math.max(44, theme.controlHeight),
|
|
98
|
+
padding: theme.space * 3,
|
|
99
|
+
borderRadius: theme.radius,
|
|
100
|
+
borderWidth: 2,
|
|
101
|
+
borderColor: focused ? theme.colors.accent : 'transparent',
|
|
102
|
+
backgroundColor: pressed ? theme.colors.subtle : 'transparent',
|
|
103
|
+
opacity: unavailable ? 0.55 : 1,
|
|
104
|
+
}), children: [_jsx(View, { style: { flex: 1 }, children: named.summary ?? (_jsx(Text, { style: {
|
|
105
|
+
color: theme.colors.text,
|
|
106
|
+
fontSize: theme.fontSize,
|
|
107
|
+
fontFamily: theme.fontFamily,
|
|
108
|
+
fontWeight: '600',
|
|
109
|
+
}, children: title })) }), named.icon ?? (_jsx(AccordionIcon, { children: _jsx(View, { style: {
|
|
110
|
+
width: 8,
|
|
111
|
+
height: 8,
|
|
112
|
+
borderBottomWidth: 2,
|
|
113
|
+
borderRightWidth: 2,
|
|
114
|
+
borderColor: theme.colors.text,
|
|
115
|
+
transform: [{ rotate: expanded ? '225deg' : '45deg' }],
|
|
116
|
+
} }) }))] }), renderPanel && (_jsxs(View, { nativeID: panelId, accessibilityElementsHidden: !expanded, importantForAccessibility: expanded ? 'auto' : 'no-hide-descendants', style: {
|
|
117
|
+
display: expanded ? 'flex' : 'none',
|
|
118
|
+
paddingHorizontal: theme.space * 3,
|
|
119
|
+
paddingBottom: theme.space * 3,
|
|
120
|
+
gap: theme.space * 2,
|
|
121
|
+
}, children: [_jsx(TextContent, { style: { color: theme.colors.text, fontSize: theme.fontSize, fontFamily: theme.fontFamily }, children: body }), named.actions] }))] }));
|
|
122
|
+
}
|
|
123
|
+
export function AccordionSummary({ children, ...props }) {
|
|
124
|
+
const theme = useTramaTheme();
|
|
125
|
+
return (_jsx(View, { ...props, children: _jsx(TextContent, { style: { color: theme.colors.text, fontSize: theme.fontSize, fontFamily: theme.fontFamily, fontWeight: '600' }, children: children }) }));
|
|
126
|
+
}
|
|
127
|
+
export function AccordionIcon({ children, ...props }) {
|
|
128
|
+
return (_jsx(View, { ...props, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", pointerEvents: "none", children: children }));
|
|
129
|
+
}
|
|
130
|
+
export function AccordionPanel({ children, ...props }) {
|
|
131
|
+
const theme = useTramaTheme();
|
|
132
|
+
return (_jsx(View, { ...props, children: _jsx(TextContent, { style: { color: theme.colors.text, fontSize: theme.fontSize, fontFamily: theme.fontFamily }, children: children }) }));
|
|
133
|
+
}
|
|
134
|
+
export function AccordionActions({ children, style, ...props }) {
|
|
135
|
+
const { direction, theme } = useTramaAppearance();
|
|
136
|
+
return (_jsx(View, { ...props, style: [{ direction, flexDirection: 'row', flexWrap: 'wrap', gap: theme.space * 2 }, style], children: children }));
|
|
137
|
+
}
|
package/dist/alert.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type ViewProps } from 'react-native';
|
|
3
|
+
import type { TramaResponsive } from './responsive.js';
|
|
4
|
+
import { type TramaColor } from './theme.js';
|
|
5
|
+
export type AlertSeverity = 'neutral' | 'info' | 'success' | 'warning' | 'danger';
|
|
6
|
+
export type AlertVariant = 'soft' | 'filled' | 'outlined' | 'dashed';
|
|
7
|
+
export type AlertAnnouncement = 'off' | 'polite' | 'assertive';
|
|
8
|
+
export type AlertAppearance = 'floating' | 'full-width';
|
|
9
|
+
export interface AlertDismissDetail {
|
|
10
|
+
open: false;
|
|
11
|
+
reason: 'close-button';
|
|
12
|
+
}
|
|
13
|
+
export interface AlertProps extends ViewProps {
|
|
14
|
+
severity?: TramaResponsive<AlertSeverity>;
|
|
15
|
+
color?: TramaResponsive<TramaColor | 'auto'>;
|
|
16
|
+
variant?: TramaResponsive<AlertVariant>;
|
|
17
|
+
appearance?: TramaResponsive<AlertAppearance>;
|
|
18
|
+
heading?: TramaResponsive<string>;
|
|
19
|
+
icon?: ReactNode;
|
|
20
|
+
hideIcon?: TramaResponsive<boolean>;
|
|
21
|
+
dismissible?: TramaResponsive<boolean>;
|
|
22
|
+
closeLabel?: TramaResponsive<string>;
|
|
23
|
+
open?: boolean;
|
|
24
|
+
defaultOpen?: boolean;
|
|
25
|
+
onDismiss?: (detail: AlertDismissDetail) => void | false;
|
|
26
|
+
announcement?: TramaResponsive<AlertAnnouncement>;
|
|
27
|
+
announcementText?: string;
|
|
28
|
+
}
|
|
29
|
+
export declare function Alert({ severity, color, variant, appearance, heading, icon, hideIcon, dismissible, closeLabel, open, defaultOpen, onDismiss, announcement, announcementText, children, style, ...props }: AlertProps): import("react").JSX.Element | null;
|
|
30
|
+
export declare function AlertActions({ children, style, ...props }: ViewProps): import("react").JSX.Element;
|
package/dist/alert.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
import { AccessibilityInfo, Platform, Pressable, Text, 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, useTramaAppearance } from './theme.js';
|
|
8
|
+
const bySeverity = {
|
|
9
|
+
neutral: { color: 'neutral', icon: 'i' },
|
|
10
|
+
info: { color: 'accent', icon: 'i' },
|
|
11
|
+
success: { color: 'green', icon: '✓' },
|
|
12
|
+
warning: { color: 'yellow', icon: '!' },
|
|
13
|
+
danger: { color: 'red', icon: '!' },
|
|
14
|
+
};
|
|
15
|
+
export function Alert({ severity, color, variant, appearance, heading, icon, hideIcon, dismissible, closeLabel, open, defaultOpen, onDismiss, announcement, announcementText, children, style, ...props }) {
|
|
16
|
+
const { theme, direction, resolve } = useTramaAppearance();
|
|
17
|
+
const messages = useTramaMessages();
|
|
18
|
+
const [visible, request] = useControllableValue(open, defaultOpen ?? true);
|
|
19
|
+
const { body, named } = splitContent(children, { actions: AlertActions });
|
|
20
|
+
const title = resolve(heading, '');
|
|
21
|
+
const live = resolve(announcement, 'off');
|
|
22
|
+
const message = announcementText?.trim() ||
|
|
23
|
+
[title, ...body.filter((child) => typeof child === 'string' || typeof child === 'number')]
|
|
24
|
+
.map(String)
|
|
25
|
+
.map((text) => text.trim())
|
|
26
|
+
.filter(Boolean)
|
|
27
|
+
.join('. ');
|
|
28
|
+
const lastAnnouncement = useRef('');
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (!visible || live === 'off' || !message) {
|
|
31
|
+
lastAnnouncement.current = '';
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (lastAnnouncement.current === message)
|
|
35
|
+
return;
|
|
36
|
+
lastAnnouncement.current = message;
|
|
37
|
+
if (Platform.OS === 'ios')
|
|
38
|
+
AccessibilityInfo.announceForAccessibilityWithOptions(message, { queue: live === 'polite' });
|
|
39
|
+
else if (Platform.OS === 'android')
|
|
40
|
+
AccessibilityInfo.announceForAccessibility(message);
|
|
41
|
+
}, [live, message, visible]);
|
|
42
|
+
if (!visible)
|
|
43
|
+
return null;
|
|
44
|
+
const status = bySeverity[resolve(severity, 'info')];
|
|
45
|
+
const palette = resolve(color, 'auto');
|
|
46
|
+
const tone = getTone(theme, palette === 'auto' ? status.color : palette);
|
|
47
|
+
const treatment = resolve(variant, 'soft');
|
|
48
|
+
const filled = treatment === 'filled';
|
|
49
|
+
const border = treatment === 'outlined' || treatment === 'dashed';
|
|
50
|
+
const full = resolve(appearance, 'floating') === 'full-width';
|
|
51
|
+
const foreground = filled ? tone.ink : theme.colors.text;
|
|
52
|
+
const iconColor = filled ? tone.ink : tone.text;
|
|
53
|
+
const textStyle = { color: foreground, fontFamily: theme.fontFamily, fontSize: theme.fontSize };
|
|
54
|
+
return (_jsxs(View, { ...props, style: [
|
|
55
|
+
{
|
|
56
|
+
direction,
|
|
57
|
+
flexDirection: 'row',
|
|
58
|
+
alignItems: 'flex-start',
|
|
59
|
+
alignSelf: 'stretch',
|
|
60
|
+
gap: theme.space * 3,
|
|
61
|
+
padding: theme.space * 3,
|
|
62
|
+
borderWidth: border ? 1 : 0,
|
|
63
|
+
borderColor: tone.text,
|
|
64
|
+
borderStyle: treatment === 'dashed' ? 'dashed' : 'solid',
|
|
65
|
+
borderRadius: full ? 0 : theme.radius,
|
|
66
|
+
backgroundColor: filled ? tone.solid : treatment === 'soft' ? tone.soft : theme.colors.surface,
|
|
67
|
+
},
|
|
68
|
+
style,
|
|
69
|
+
], children: [!resolve(hideIcon, false) && icon !== null && (_jsx(View, { accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", pointerEvents: "none", children: icon ?? (_jsx(Text, { allowFontScaling: false, style: {
|
|
70
|
+
width: theme.space * 5,
|
|
71
|
+
height: theme.space * 5,
|
|
72
|
+
lineHeight: theme.space * 5 - 2,
|
|
73
|
+
textAlign: 'center',
|
|
74
|
+
color: iconColor,
|
|
75
|
+
borderWidth: 1,
|
|
76
|
+
borderColor: iconColor,
|
|
77
|
+
borderRadius: theme.space * 3,
|
|
78
|
+
fontSize: theme.fontSize - 1,
|
|
79
|
+
fontWeight: '700',
|
|
80
|
+
}, children: status.icon })) })), _jsxs(View, { style: { flex: 1, gap: theme.space * 2 }, children: [_jsxs(View, { "aria-live": Platform.OS === 'web' ? live : undefined, style: { gap: theme.space }, children: [title ? _jsx(Text, { style: { ...textStyle, fontWeight: '700' }, children: title }) : null, _jsx(TextContent, { style: textStyle, children: body })] }), named.actions] }), resolve(dismissible, false) && (_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: resolve(closeLabel, messages.dismissMessage).trim() || messages.dismissMessage, onPress: () => {
|
|
81
|
+
if (onDismiss?.({ open: false, reason: 'close-button' }) !== false)
|
|
82
|
+
request(false);
|
|
83
|
+
}, style: ({ pressed }) => ({
|
|
84
|
+
alignItems: 'center',
|
|
85
|
+
justifyContent: 'center',
|
|
86
|
+
minWidth: 44,
|
|
87
|
+
minHeight: 44,
|
|
88
|
+
borderRadius: theme.radius,
|
|
89
|
+
opacity: pressed ? 0.6 : 1,
|
|
90
|
+
}), children: _jsx(Text, { style: { color: iconColor, fontSize: theme.fontSize + 6 }, children: "\u00D7" }) }))] }));
|
|
91
|
+
}
|
|
92
|
+
export function AlertActions({ children, style, ...props }) {
|
|
93
|
+
const { direction, theme } = useTramaAppearance();
|
|
94
|
+
return (_jsx(View, { ...props, style: [{ direction, flexDirection: 'row', flexWrap: 'wrap', gap: theme.space * 2 }, style], children: children }));
|
|
95
|
+
}
|
package/dist/avatar.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type ImageProps, type ViewProps } from 'react-native';
|
|
3
|
+
import type { TramaResponsive } from './responsive.js';
|
|
4
|
+
export type AvatarSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
5
|
+
export type AvatarShape = 'circle' | 'rounded' | 'square';
|
|
6
|
+
export interface AvatarProps extends Omit<ViewProps, 'children'> {
|
|
7
|
+
src?: string;
|
|
8
|
+
source?: ImageProps['source'];
|
|
9
|
+
alt?: string;
|
|
10
|
+
label?: string;
|
|
11
|
+
initials?: string;
|
|
12
|
+
fallback?: ReactNode;
|
|
13
|
+
badge?: ReactNode;
|
|
14
|
+
size?: TramaResponsive<AvatarSize>;
|
|
15
|
+
shape?: TramaResponsive<AvatarShape>;
|
|
16
|
+
onImageError?: ImageProps['onError'];
|
|
17
|
+
onImageLoad?: ImageProps['onLoad'];
|
|
18
|
+
}
|
|
19
|
+
export declare function Avatar({ src, source, alt, label, initials, fallback, badge, size, shape, accessibilityLabel, style, onImageError, onImageLoad, ...props }: AvatarProps): import("react").JSX.Element;
|
|
20
|
+
export interface AvatarGroupProps extends ViewProps {
|
|
21
|
+
max?: TramaResponsive<number>;
|
|
22
|
+
total?: number;
|
|
23
|
+
size?: TramaResponsive<AvatarSize>;
|
|
24
|
+
shape?: TramaResponsive<AvatarShape>;
|
|
25
|
+
overlap?: TramaResponsive<number>;
|
|
26
|
+
stacking?: 'first-on-top' | 'last-on-top';
|
|
27
|
+
overflowLabel?: (remaining: number) => string;
|
|
28
|
+
}
|
|
29
|
+
export declare function AvatarGroup({ max, total, size, shape, overlap, stacking, overflowLabel, children, style, ...props }: AvatarGroupProps): import("react").JSX.Element;
|
|
30
|
+
export interface AvatarGroupOverflowProps extends ViewProps {
|
|
31
|
+
count?: number;
|
|
32
|
+
size?: AvatarSize;
|
|
33
|
+
shape?: AvatarShape;
|
|
34
|
+
label?: string;
|
|
35
|
+
}
|
|
36
|
+
export declare function AvatarGroupOverflow({ count, size, shape, label, children, style, ...props }: AvatarGroupOverflowProps): import("react").JSX.Element;
|
package/dist/avatar.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Children, cloneElement, isValidElement, useState } from 'react';
|
|
3
|
+
import { Image, StyleSheet, Text, View } from 'react-native';
|
|
4
|
+
import { TextContent } from './internal/content.js';
|
|
5
|
+
import { useTramaAppearance } from './theme.js';
|
|
6
|
+
const sizeSteps = { xs: 6, sm: 8, md: 10, lg: 12, xl: 16 };
|
|
7
|
+
function initialsFor(label) {
|
|
8
|
+
return label
|
|
9
|
+
.trim()
|
|
10
|
+
.split(/\s+/u)
|
|
11
|
+
.slice(0, 2)
|
|
12
|
+
.map((part) => Array.from(part)[0] ?? '')
|
|
13
|
+
.join('')
|
|
14
|
+
.toLocaleUpperCase();
|
|
15
|
+
}
|
|
16
|
+
export function Avatar({ src, source, alt, label, initials, fallback, badge, size, shape, accessibilityLabel, style, onImageError, onImageLoad, ...props }) {
|
|
17
|
+
const { theme, direction, resolve } = useTramaAppearance();
|
|
18
|
+
const extent = sizeSteps[resolve(size, 'md')] * theme.space;
|
|
19
|
+
const roundness = { circle: extent / 2, rounded: theme.radius, square: 0 }[resolve(shape, 'circle')];
|
|
20
|
+
const image = source ?? (src ? { uri: src } : undefined);
|
|
21
|
+
const identity = accessibilityLabel ?? (label ? undefined : alt);
|
|
22
|
+
const visual = fallback ?? initials ?? initialsFor(label ?? alt ?? '');
|
|
23
|
+
return (_jsxs(View, { ...props, style: [
|
|
24
|
+
{ direction, flexDirection: 'row', alignItems: 'center', gap: theme.space * 2, alignSelf: 'flex-start' },
|
|
25
|
+
style,
|
|
26
|
+
], children: [_jsxs(View, { accessible: Boolean(identity), accessibilityRole: identity ? 'image' : undefined, accessibilityLabel: identity, importantForAccessibility: identity ? 'yes' : 'no-hide-descendants', accessibilityElementsHidden: !identity, style: { width: extent, height: extent }, children: [_jsxs(View, { style: {
|
|
27
|
+
borderRadius: roundness,
|
|
28
|
+
flex: 1,
|
|
29
|
+
overflow: 'hidden',
|
|
30
|
+
justifyContent: 'center',
|
|
31
|
+
alignItems: 'center',
|
|
32
|
+
backgroundColor: theme.colors.subtle,
|
|
33
|
+
}, children: [_jsx(TextContent, { style: {
|
|
34
|
+
color: theme.colors.accent,
|
|
35
|
+
fontSize: extent * 0.33,
|
|
36
|
+
fontWeight: '700',
|
|
37
|
+
fontFamily: theme.fontFamily,
|
|
38
|
+
}, children: visual }), image && (_jsx(AvatarImage, { source: image, onError: onImageError, onLoad: onImageLoad }, JSON.stringify(image)))] }), badge && _jsx(View, { style: { position: 'absolute', end: -theme.space, bottom: -theme.space }, children: badge })] }), label && (_jsx(Text, { style: { color: theme.colors.text, fontSize: theme.fontSize, fontFamily: theme.fontFamily, flexShrink: 1 }, children: label }))] }));
|
|
39
|
+
}
|
|
40
|
+
function AvatarImage({ source, onLoad, onError }) {
|
|
41
|
+
const [status, setStatus] = useState('loading');
|
|
42
|
+
if (status === 'error')
|
|
43
|
+
return null;
|
|
44
|
+
return (_jsx(Image, { source: source, accessible: false, resizeMode: "cover", fadeDuration: 0, style: [StyleSheet.absoluteFill, { width: '100%', height: '100%', opacity: status === 'loaded' ? 1 : 0 }], onLoad: (event) => {
|
|
45
|
+
setStatus('loaded');
|
|
46
|
+
onLoad?.(event);
|
|
47
|
+
}, onError: (event) => {
|
|
48
|
+
setStatus('error');
|
|
49
|
+
onError?.(event);
|
|
50
|
+
} }));
|
|
51
|
+
}
|
|
52
|
+
export function AvatarGroup({ max, total, size, shape, overlap, stacking = 'first-on-top', overflowLabel, children, style, ...props }) {
|
|
53
|
+
const { theme, direction, resolve } = useTramaAppearance();
|
|
54
|
+
const sizeValue = resolve(size, 'md');
|
|
55
|
+
const shapeValue = resolve(shape, 'circle');
|
|
56
|
+
const entries = Children.toArray(children);
|
|
57
|
+
const items = entries.flatMap((item) => (isValidElement(item) && item.type === Avatar ? [item] : []));
|
|
58
|
+
const overflow = entries.find((item) => isValidElement(item) && item.type === AvatarGroupOverflow);
|
|
59
|
+
const limit = resolve(max, 5);
|
|
60
|
+
const visible = items.slice(0, Number.isFinite(limit) ? Math.max(0, Math.floor(limit)) : 5);
|
|
61
|
+
const count = total !== undefined && Number.isFinite(total) ? Math.max(items.length, Math.floor(total)) : items.length;
|
|
62
|
+
const remaining = count - visible.length;
|
|
63
|
+
const amount = resolve(overlap, 25);
|
|
64
|
+
const offset = theme.space * sizeSteps[sizeValue] * (Number.isFinite(amount) ? Math.min(75, Math.max(0, amount)) / 100 : 0.25);
|
|
65
|
+
return (_jsxs(View, { ...props, style: [{ direction, flexDirection: 'row', alignItems: 'center', alignSelf: 'flex-start' }, style], children: [visible.map((item, index) => (_jsx(View, { style: {
|
|
66
|
+
marginStart: index ? -offset : 0,
|
|
67
|
+
zIndex: stacking === 'first-on-top' ? visible.length - index : index,
|
|
68
|
+
}, children: cloneElement(item, { size: item.props.size ?? sizeValue, shape: item.props.shape ?? shapeValue }) }, item.key ?? index))), remaining > 0 && (_jsx(View, { style: { marginStart: visible.length ? -offset : 0 }, children: isValidElement(overflow) ? (cloneElement(overflow, {
|
|
69
|
+
count: remaining,
|
|
70
|
+
size: sizeValue,
|
|
71
|
+
shape: shapeValue,
|
|
72
|
+
label: overflow.props.label ?? overflowLabel?.(remaining),
|
|
73
|
+
})) : (_jsx(AvatarGroupOverflow, { count: remaining, size: sizeValue, shape: shapeValue, label: overflowLabel?.(remaining) })) }))] }));
|
|
74
|
+
}
|
|
75
|
+
export function AvatarGroupOverflow({ count = 0, size = 'md', shape = 'circle', label, children, style, ...props }) {
|
|
76
|
+
const { theme } = useTramaAppearance();
|
|
77
|
+
const extent = sizeSteps[size] * theme.space;
|
|
78
|
+
return (_jsx(View, { ...props, accessible: true, accessibilityLabel: label ?? `+${count}`, style: [
|
|
79
|
+
{
|
|
80
|
+
width: extent,
|
|
81
|
+
height: extent,
|
|
82
|
+
alignItems: 'center',
|
|
83
|
+
justifyContent: 'center',
|
|
84
|
+
backgroundColor: theme.colors.subtle,
|
|
85
|
+
borderRadius: shape === 'circle' ? extent / 2 : shape === 'rounded' ? theme.radius : 0,
|
|
86
|
+
borderColor: theme.colors.surface,
|
|
87
|
+
borderWidth: 1,
|
|
88
|
+
},
|
|
89
|
+
style,
|
|
90
|
+
], children: _jsx(TextContent, { style: { fontSize: theme.fontSize - 2, color: theme.colors.text }, children: children ?? `+${count}` }) }));
|
|
91
|
+
}
|