@terreno/ui 57.1.0 → 57.3.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/.ai/guidelines/core.md +1 -1
- package/README.md +17 -8
- package/dist/ActionSheet.d.ts +3 -3
- package/dist/ActionSheet.js +2 -2
- package/dist/ActionSheet.js.map +1 -1
- package/dist/Box.d.ts +1 -1
- package/dist/Box.js +219 -177
- package/dist/Box.js.map +1 -1
- package/dist/Button.js +101 -34
- package/dist/Button.js.map +1 -1
- package/dist/Common.d.ts +119 -9
- package/dist/Common.js.map +1 -1
- package/dist/ConsentFormScreen.js +46 -12
- package/dist/ConsentFormScreen.js.map +1 -1
- package/dist/ConsentNavigator.d.ts +5 -1
- package/dist/ConsentNavigator.js.map +1 -1
- package/dist/DataTable.d.ts +2 -2
- package/dist/DataTable.js +203 -44
- package/dist/DataTable.js.map +1 -1
- package/dist/DataTableHeaderInfoMarkdown.d.ts +6 -0
- package/dist/DataTableHeaderInfoMarkdown.js +7 -0
- package/dist/DataTableHeaderInfoMarkdown.js.map +1 -0
- package/dist/EmojiSelector.d.ts +2 -46
- package/dist/EmojiSelector.js +46 -56
- package/dist/EmojiSelector.js.map +1 -1
- package/dist/GPTChat.js +1 -1
- package/dist/GPTChat.js.map +1 -1
- package/dist/Heading.d.ts +5 -2
- package/dist/Heading.js +6 -8
- package/dist/Heading.js.map +1 -1
- package/dist/Hyperlink.js.map +1 -1
- package/dist/Icon.d.ts +1 -2
- package/dist/Icon.js +4 -1
- package/dist/Icon.js.map +1 -1
- package/dist/MarkdownView.d.ts +6 -3
- package/dist/MarkdownView.js +45 -43
- package/dist/MarkdownView.js.map +1 -1
- package/dist/MediaQuery.d.ts +5 -3
- package/dist/MediaQuery.js +9 -40
- package/dist/MediaQuery.js.map +1 -1
- package/dist/OpenAPIContext.js +7 -6
- package/dist/OpenAPIContext.js.map +1 -1
- package/dist/Page.js +7 -1
- package/dist/Page.js.map +1 -1
- package/dist/PickerSelect.js +8 -1
- package/dist/PickerSelect.js.map +1 -1
- package/dist/Popover.d.ts +12 -0
- package/dist/Popover.js +37 -0
- package/dist/Popover.js.map +1 -0
- package/dist/PortalHost.js +10 -1
- package/dist/PortalHost.js.map +1 -1
- package/dist/ResponsiveBreakpoint.d.ts +65 -0
- package/dist/ResponsiveBreakpoint.js +111 -0
- package/dist/ResponsiveBreakpoint.js.map +1 -0
- package/dist/SplitPage.d.ts +2 -2
- package/dist/SplitPage.js +7 -12
- package/dist/SplitPage.js.map +1 -1
- package/dist/SplitPage.native.d.ts +2 -2
- package/dist/SplitPage.native.js +1 -6
- package/dist/SplitPage.native.js.map +1 -1
- package/dist/TapToEdit.js +12 -10
- package/dist/TapToEdit.js.map +1 -1
- package/dist/TerrenoFontProvider.d.ts +7 -0
- package/dist/TerrenoFontProvider.js +27 -0
- package/dist/TerrenoFontProvider.js.map +1 -0
- package/dist/TerrenoProvider.js +4 -2
- package/dist/TerrenoProvider.js.map +1 -1
- package/dist/Text.d.ts +5 -2
- package/dist/Text.js +6 -11
- package/dist/Text.js.map +1 -1
- package/dist/TextFieldNumberActionSheet.js +9 -2
- package/dist/TextFieldNumberActionSheet.js.map +1 -1
- package/dist/Theme.js +10 -8
- package/dist/Theme.js.map +1 -1
- package/dist/ToastNotifications.d.ts +4 -2
- package/dist/ToastNotifications.js.map +1 -1
- package/dist/Tooltip.d.ts +4 -3
- package/dist/Tooltip.js +14 -3
- package/dist/Tooltip.js.map +1 -1
- package/dist/Unifier.d.ts +26 -1
- package/dist/Unifier.js.map +1 -1
- package/dist/WebAddressAutocomplete.js +6 -1
- package/dist/WebAddressAutocomplete.js.map +1 -1
- package/dist/emojiCategories.d.ts +46 -0
- package/dist/emojiCategories.js +47 -0
- package/dist/emojiCategories.js.map +1 -0
- package/dist/index.d.ts +13 -13
- package/dist/index.js +2 -13
- package/dist/index.js.map +1 -1
- package/dist/lazyBoundaries/createLazyComponentExport.d.ts +6 -0
- package/dist/lazyBoundaries/createLazyComponentExport.js +35 -0
- package/dist/lazyBoundaries/createLazyComponentExport.js.map +1 -0
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts +41 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js +43 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -0
- package/dist/login/LoginScreen.d.ts +1 -0
- package/dist/login/LoginScreen.js +4 -2
- package/dist/login/LoginScreen.js.map +1 -1
- package/dist/login/loginTypes.d.ts +2 -0
- package/package.json +41 -2
- package/src/AIRequestExplorer.test.tsx +141 -0
- package/src/ActionSheet.tsx +9 -7
- package/src/AttachmentPreview.test.tsx +80 -0
- package/src/Box.test.tsx +97 -10
- package/src/Box.tsx +263 -200
- package/src/Button.test.tsx +207 -0
- package/src/Button.tsx +146 -48
- package/src/Common.ts +124 -25
- package/src/ConsentFormScreen.markdownGate.test.tsx +129 -0
- package/src/ConsentFormScreen.test.tsx +145 -8
- package/src/ConsentFormScreen.tsx +74 -25
- package/src/ConsentNavigator.tsx +13 -5
- package/src/DataTable.tsx +418 -147
- package/src/DataTableHeaderInfoMarkdown.test.tsx +21 -0
- package/src/DataTableHeaderInfoMarkdown.tsx +17 -0
- package/src/DataTableVirtualizationRegression.test.tsx +266 -0
- package/src/DateTimeField.test.tsx +54 -0
- package/src/EmojiSelector.test.tsx +33 -42
- package/src/EmojiSelector.tsx +60 -57
- package/src/FilePickerButton.test.tsx +167 -0
- package/src/FilterAccordion.test.tsx +37 -0
- package/src/FilterBoolean.test.tsx +96 -0
- package/src/FilterSelectMenu.test.tsx +23 -0
- package/src/GPTChat.test.tsx +696 -0
- package/src/GPTChat.tsx +2 -2
- package/src/GPTMemoryModal.test.tsx +67 -0
- package/src/Heading.tsx +8 -14
- package/src/HeightActionSheet.test.tsx +6 -9
- package/src/Hyperlink.tsx +5 -18
- package/src/Icon.tsx +6 -2
- package/src/MarkdownEditor.test.tsx +134 -0
- package/src/MarkdownEditorField.test.tsx +124 -0
- package/src/MarkdownView.test.tsx +55 -11
- package/src/MarkdownView.tsx +149 -150
- package/src/MediaQuery.ts +30 -34
- package/src/OpenAPIContext.tsx +36 -29
- package/src/OpenAPIRenderRegression.test.tsx +200 -0
- package/src/P0RenderRegression.test.tsx +214 -0
- package/src/P1RenderRegression.test.tsx +141 -0
- package/src/P2ButtonRenderRegression.test.tsx +158 -0
- package/src/Page.test.tsx +13 -0
- package/src/Page.tsx +25 -5
- package/src/PickerSelect.test.tsx +38 -0
- package/src/PickerSelect.tsx +7 -0
- package/src/Popover.test.tsx +151 -0
- package/src/Popover.tsx +211 -0
- package/src/PortalHost.tsx +12 -6
- package/src/ResponsiveBreakpoint.test.tsx +184 -0
- package/src/ResponsiveBreakpoint.tsx +195 -0
- package/src/RootImportRegression.test.tsx +62 -0
- package/src/SplitPage.native.tsx +5 -9
- package/src/SplitPage.tsx +16 -19
- package/src/TapToEdit.test.tsx +45 -0
- package/src/TapToEdit.tsx +23 -18
- package/src/TerrenoFontProvider.test.tsx +38 -0
- package/src/TerrenoFontProvider.tsx +50 -0
- package/src/TerrenoProvider.tsx +6 -1
- package/src/Text.tsx +8 -21
- package/src/TextFieldNumberActionSheet.test.tsx +100 -0
- package/src/TextFieldNumberActionSheet.tsx +11 -2
- package/src/Theme.test.tsx +27 -0
- package/src/Theme.tsx +15 -10
- package/src/Toast.tsx +1 -1
- package/src/ToastNotifications.tsx +4 -4
- package/src/Tooltip.test.tsx +64 -0
- package/src/Tooltip.tsx +18 -4
- package/src/Unifier.ts +26 -3
- package/src/WebAddressAutocomplete.tsx +6 -2
- package/src/__snapshots__/ActionSheet.test.tsx.snap +0 -36
- package/src/__snapshots__/AddressField.test.tsx.snap +1 -0
- package/src/__snapshots__/AttachmentPreview.test.tsx.snap +225 -0
- package/src/__snapshots__/CustomSelectField.test.tsx.snap +7 -0
- package/src/__snapshots__/DataTable.test.tsx.snap +793 -250
- package/src/__snapshots__/DecimalRangeActionSheet.test.tsx.snap +0 -8
- package/src/__snapshots__/EmojiSelector.test.tsx.snap +35555 -30
- package/src/__snapshots__/Field.test.tsx.snap +7 -0
- package/src/__snapshots__/FilterSelectMenu.test.tsx.snap +1 -0
- package/src/__snapshots__/HeightActionSheet.test.tsx.snap +0 -8
- package/src/__snapshots__/HeightField.test.tsx.snap +0 -20
- package/src/__snapshots__/NumberPickerActionSheet.test.tsx.snap +0 -8
- package/src/__snapshots__/Page.test.tsx.snap +13 -1
- package/src/__snapshots__/PickerSelect.test.tsx.snap +7 -0
- package/src/__snapshots__/SelectField.test.tsx.snap +6 -0
- package/src/__snapshots__/TimezonePicker.test.tsx.snap +6 -0
- package/src/benchmarks/importGraph.test.ts +71 -0
- package/src/benchmarks/importGraph.ts +136 -0
- package/src/benchmarks/importTiming.test.ts +42 -0
- package/src/benchmarks/importTiming.ts +86 -0
- package/src/bunSetup.ts +174 -32
- package/src/emojiCategories.test.ts +23 -0
- package/src/emojiCategories.ts +46 -0
- package/src/index.tsx +27 -13
- package/src/lazyBoundaries/createLazyComponentExport.test.tsx +104 -0
- package/src/lazyBoundaries/createLazyComponentExport.tsx +63 -0
- package/src/lazyBoundaries/heavyOptionalExports.test.tsx +33 -0
- package/src/lazyBoundaries/heavyOptionalExports.tsx +106 -0
- package/src/login/LoginScreen.test.tsx +9 -2
- package/src/login/LoginScreen.tsx +6 -2
- package/src/login/loginTypes.ts +2 -0
- package/src/table/TableDate.test.tsx +35 -1
- package/src/table/__snapshots__/TableBadge.test.tsx.snap +1 -0
package/src/Box.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {useImperativeHandle} from "react";
|
|
1
|
+
import React, {useImperativeHandle, useRef} from "react";
|
|
2
2
|
import {
|
|
3
3
|
type AccessibilityProps,
|
|
4
4
|
KeyboardAvoidingView,
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
SafeAreaView,
|
|
8
8
|
ScrollView,
|
|
9
9
|
View,
|
|
10
|
+
type ViewStyle,
|
|
10
11
|
} from "react-native";
|
|
11
12
|
import type {
|
|
12
13
|
AlignContent,
|
|
@@ -15,10 +16,17 @@ import type {
|
|
|
15
16
|
BorderTheme,
|
|
16
17
|
BoxProps,
|
|
17
18
|
JustifyContent,
|
|
19
|
+
NumberOrPercentage,
|
|
20
|
+
Rounding,
|
|
21
|
+
SignedUpTo12,
|
|
18
22
|
SurfaceTheme,
|
|
19
23
|
} from "./Common";
|
|
20
24
|
import {getRounding, getSpacing} from "./Common";
|
|
21
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
isBreakpointAtLeast,
|
|
27
|
+
type ResponsiveBreakpoint,
|
|
28
|
+
useResponsiveBreakpoint,
|
|
29
|
+
} from "./ResponsiveBreakpoint";
|
|
22
30
|
import {useTheme} from "./Theme";
|
|
23
31
|
import {Unifier} from "./Unifier";
|
|
24
32
|
|
|
@@ -86,9 +94,33 @@ const NON_STYLE_BOX_PROPS = new Set<string>([
|
|
|
86
94
|
"testIDs",
|
|
87
95
|
]);
|
|
88
96
|
|
|
89
|
-
|
|
97
|
+
const RESPONSIVE_DIRECTION_PROPS = [
|
|
98
|
+
"smDirection",
|
|
99
|
+
"mdDirection",
|
|
100
|
+
"lgDirection",
|
|
101
|
+
"xlDirection",
|
|
102
|
+
] as const;
|
|
103
|
+
const RESPONSIVE_DIRECTION_PROP_SET = new Set<string>(RESPONSIVE_DIRECTION_PROPS);
|
|
104
|
+
|
|
105
|
+
interface BoxStyleMap {
|
|
106
|
+
[prop: string]: (
|
|
107
|
+
value: unknown,
|
|
108
|
+
all: Readonly<Record<string, unknown>>,
|
|
109
|
+
breakpoint: ResponsiveBreakpoint
|
|
110
|
+
) => ViewStyle;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const boxStyleMapCache = new WeakMap<object, BoxStyleMap>();
|
|
114
|
+
|
|
115
|
+
const BoxComponent = React.forwardRef((props: BoxProps, ref) => {
|
|
90
116
|
const {theme} = useTheme();
|
|
91
117
|
const resolvedTestID = props.testID;
|
|
118
|
+
const internalScrollRef = useRef<ScrollView>(null);
|
|
119
|
+
const scrollRef = props.scrollRef ?? internalScrollRef;
|
|
120
|
+
const hasResponsiveDirection = Boolean(
|
|
121
|
+
props.smDirection || props.mdDirection || props.lgDirection || props.xlDirection
|
|
122
|
+
);
|
|
123
|
+
const breakpoint = useResponsiveBreakpoint({enabled: hasResponsiveDirection});
|
|
92
124
|
|
|
93
125
|
useImperativeHandle(ref, () => ({
|
|
94
126
|
scrollTo: (y: number) => {
|
|
@@ -111,219 +143,245 @@ export const Box = React.forwardRef((props: BoxProps, ref) => {
|
|
|
111
143
|
},
|
|
112
144
|
}));
|
|
113
145
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
value:
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
146
|
+
let cachedBoxStyleMap = boxStyleMapCache.get(theme);
|
|
147
|
+
if (!cachedBoxStyleMap) {
|
|
148
|
+
cachedBoxStyleMap = {
|
|
149
|
+
alignContent: (value: AlignContent) => ({alignContent: ALIGN_CONTENT[value]}),
|
|
150
|
+
alignItems: (value: AlignItems) => ({alignItems: ALIGN_ITEMS[value]}),
|
|
151
|
+
alignSelf: (value: AlignSelf) => ({alignSelf: ALIGN_SELF[value]}),
|
|
152
|
+
border: (value: keyof BorderTheme) => {
|
|
153
|
+
if (!value) {
|
|
154
|
+
return {};
|
|
155
|
+
}
|
|
156
|
+
return {borderColor: theme.border[value], borderWidth: BORDER_WIDTH};
|
|
157
|
+
},
|
|
158
|
+
borderBottom: (value: keyof BorderTheme) => {
|
|
159
|
+
if (!value) {
|
|
160
|
+
return {};
|
|
161
|
+
}
|
|
162
|
+
return {borderBottomColor: theme.border[value], borderBottomWidth: BORDER_WIDTH};
|
|
163
|
+
},
|
|
164
|
+
borderLeft: (value: keyof BorderTheme) => {
|
|
165
|
+
if (!value) {
|
|
166
|
+
return {};
|
|
167
|
+
}
|
|
168
|
+
return {borderLeftColor: theme.border[value], borderLeftWidth: BORDER_WIDTH};
|
|
169
|
+
},
|
|
170
|
+
borderRight: (value: keyof BorderTheme) => {
|
|
171
|
+
if (!value) {
|
|
172
|
+
return {};
|
|
173
|
+
}
|
|
174
|
+
return {borderRightColor: theme.border[value], borderRightWidth: BORDER_WIDTH};
|
|
175
|
+
},
|
|
176
|
+
borderTop: (value: keyof BorderTheme) => {
|
|
177
|
+
if (!value) {
|
|
178
|
+
return {};
|
|
179
|
+
}
|
|
180
|
+
return {borderTopColor: theme.border[value], borderTopWidth: BORDER_WIDTH};
|
|
181
|
+
},
|
|
182
|
+
bottom: (bottom) => ({bottom: bottom ? 0 : undefined}),
|
|
183
|
+
color: (value: keyof SurfaceTheme) => ({backgroundColor: theme.surface[value]}),
|
|
184
|
+
direction: (value: "row" | "column") => ({display: "flex", flexDirection: value}),
|
|
185
|
+
display: (value: "none" | "flex" | "block" | "inlineBlock" | "visuallyHidden") => {
|
|
186
|
+
if (value === "none") {
|
|
187
|
+
return {display: "none"};
|
|
188
|
+
}
|
|
189
|
+
return value === "flex" ? {flex: undefined} : {flex: 0, flexDirection: "row"};
|
|
190
|
+
},
|
|
191
|
+
flex: (value: string) => {
|
|
192
|
+
if (value === "grow") {
|
|
193
|
+
return {display: "flex", flexGrow: 1, flexShrink: 1};
|
|
194
|
+
} else if (value === "shrink") {
|
|
195
|
+
return {display: "flex", flexShrink: 1};
|
|
196
|
+
} else {
|
|
197
|
+
return {display: "flex", flex: 0};
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
gap: (value) => ({gap: getSpacing(value as SignedUpTo12)}),
|
|
201
|
+
height: (value, allProps) => {
|
|
202
|
+
if (!isValidWidthHeight(value as NumberOrPercentage)) {
|
|
203
|
+
console.warn(
|
|
204
|
+
`Box: height prop must be a number or percentage string (e.g., "50%"), received: ${value}`
|
|
205
|
+
);
|
|
206
|
+
return {};
|
|
207
|
+
}
|
|
208
|
+
const heightValue = value as NumberOrPercentage;
|
|
209
|
+
if (allProps.border && !Number.isNaN(Number(heightValue))) {
|
|
210
|
+
return {height: Number(heightValue) + 2 * 2};
|
|
211
|
+
}
|
|
212
|
+
return {height: heightValue};
|
|
213
|
+
},
|
|
214
|
+
justifyContent: (value: JustifyContent) => ({justifyContent: ALIGN_CONTENT[value]}),
|
|
215
|
+
left: (left) => ({left: left ? 0 : undefined}),
|
|
216
|
+
lgDirection: (value: "row" | "column", _allProps, responsiveBreakpoint) =>
|
|
217
|
+
isBreakpointAtLeast({breakpoint: responsiveBreakpoint, minimum: "lg"})
|
|
218
|
+
? {display: "flex", flexDirection: value}
|
|
219
|
+
: {},
|
|
220
|
+
margin: (value) => ({margin: getSpacing(value as SignedUpTo12)}),
|
|
221
|
+
marginBottom: (value) => ({marginBottom: getSpacing(value as SignedUpTo12)}),
|
|
222
|
+
marginLeft: (value) => ({marginLeft: getSpacing(value as SignedUpTo12)}),
|
|
223
|
+
marginRight: (value) => ({marginRight: getSpacing(value as SignedUpTo12)}),
|
|
224
|
+
marginTop: (value) => ({marginTop: getSpacing(value as SignedUpTo12)}),
|
|
225
|
+
maxHeight: (value) => {
|
|
226
|
+
if (!isValidWidthHeight(value as NumberOrPercentage)) {
|
|
227
|
+
console.warn(
|
|
228
|
+
`Box: maxHeight prop must be a number or percentage string (e.g., "50%"), received: ${value}`
|
|
229
|
+
);
|
|
230
|
+
return {};
|
|
231
|
+
}
|
|
232
|
+
return {maxHeight: value as NumberOrPercentage};
|
|
233
|
+
},
|
|
234
|
+
maxWidth: (value) => {
|
|
235
|
+
if (!isValidWidthHeight(value as NumberOrPercentage)) {
|
|
236
|
+
console.warn(
|
|
237
|
+
`Box: maxWidth prop must be a number or percentage string (e.g., "50%"), received: ${value}`
|
|
238
|
+
);
|
|
239
|
+
return {};
|
|
240
|
+
}
|
|
241
|
+
return {maxWidth: value as NumberOrPercentage};
|
|
242
|
+
},
|
|
243
|
+
mdDirection: (value: "row" | "column", _allProps, responsiveBreakpoint) =>
|
|
244
|
+
isBreakpointAtLeast({breakpoint: responsiveBreakpoint, minimum: "md"})
|
|
245
|
+
? {display: "flex", flexDirection: value}
|
|
246
|
+
: {},
|
|
247
|
+
minHeight: (value) => {
|
|
248
|
+
if (!isValidWidthHeight(value as NumberOrPercentage)) {
|
|
249
|
+
console.warn(
|
|
250
|
+
`Box: minHeight prop must be a number or percentage string (e.g., "50%"), received: ${value}`
|
|
251
|
+
);
|
|
252
|
+
return {};
|
|
253
|
+
}
|
|
254
|
+
return {minHeight: value as NumberOrPercentage};
|
|
255
|
+
},
|
|
256
|
+
minWidth: (value) => {
|
|
257
|
+
if (!isValidWidthHeight(value as NumberOrPercentage)) {
|
|
258
|
+
console.warn(
|
|
259
|
+
`Box: minWidth prop must be a number or percentage string (e.g., "50%"), received: ${value}`
|
|
260
|
+
);
|
|
261
|
+
return {};
|
|
262
|
+
}
|
|
263
|
+
return {minWidth: value as NumberOrPercentage};
|
|
264
|
+
},
|
|
265
|
+
overflow: (value) => {
|
|
266
|
+
if (value === "scrollY" || value === "scroll") {
|
|
267
|
+
return {overflow: "scroll"};
|
|
268
|
+
}
|
|
269
|
+
return {overflow: value};
|
|
270
|
+
},
|
|
271
|
+
padding: (value) => ({padding: getSpacing(value as SignedUpTo12)}),
|
|
272
|
+
paddingX: (value) => ({
|
|
273
|
+
paddingLeft: getSpacing(value as SignedUpTo12),
|
|
274
|
+
paddingRight: getSpacing(value as SignedUpTo12),
|
|
275
|
+
}),
|
|
276
|
+
paddingY: (value) => ({
|
|
277
|
+
paddingBottom: getSpacing(value as SignedUpTo12),
|
|
278
|
+
paddingTop: getSpacing(value as SignedUpTo12),
|
|
279
|
+
}),
|
|
280
|
+
position: (value) => ({position: value}),
|
|
281
|
+
right: (right) => ({right: right ? 0 : undefined}),
|
|
282
|
+
rounding: (rounding, allProps) => {
|
|
283
|
+
if (rounding === "circle") {
|
|
284
|
+
if (!allProps.height && !allProps.width) {
|
|
285
|
+
console.warn("Cannot use Box rounding='circle' without height or width.");
|
|
286
|
+
return {borderRadius: undefined};
|
|
287
|
+
}
|
|
288
|
+
return {borderRadius: (allProps.height ?? allProps.width) as NumberOrPercentage};
|
|
252
289
|
}
|
|
253
|
-
return {borderRadius: allProps.height || allProps.width};
|
|
254
|
-
}
|
|
255
290
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
291
|
+
if (rounding) {
|
|
292
|
+
return {borderRadius: getRounding(rounding as Rounding)};
|
|
293
|
+
}
|
|
259
294
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
alignItems
|
|
294
|
-
|
|
295
|
-
:
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
295
|
+
return {borderRadius: undefined};
|
|
296
|
+
},
|
|
297
|
+
shadow: (value) => {
|
|
298
|
+
if (!value) {
|
|
299
|
+
return {};
|
|
300
|
+
}
|
|
301
|
+
if (Platform.OS === "ios" || Platform.OS === "web") {
|
|
302
|
+
return {
|
|
303
|
+
boxShadow: "2px 2px 2px rgba(153, 153, 153, 1.0)",
|
|
304
|
+
};
|
|
305
|
+
} else {
|
|
306
|
+
return {elevation: 4};
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
smDirection: (value: "row" | "column", _allProps, responsiveBreakpoint) =>
|
|
310
|
+
isBreakpointAtLeast({breakpoint: responsiveBreakpoint, minimum: "sm"})
|
|
311
|
+
? {display: "flex", flexDirection: value}
|
|
312
|
+
: {},
|
|
313
|
+
top: (top) => ({top: top ? 0 : undefined}),
|
|
314
|
+
width: (value, allProps) => {
|
|
315
|
+
if (!isValidWidthHeight(value as NumberOrPercentage)) {
|
|
316
|
+
console.warn(
|
|
317
|
+
`Box: width prop must be a number or percentage string (e.g., "50%"), received: ${value}`
|
|
318
|
+
);
|
|
319
|
+
return {};
|
|
320
|
+
}
|
|
321
|
+
const widthValue = value as NumberOrPercentage;
|
|
322
|
+
if (allProps.border && !Number.isNaN(Number(widthValue))) {
|
|
323
|
+
return {width: Number(widthValue) + 2 * 2};
|
|
324
|
+
}
|
|
325
|
+
return {width: widthValue};
|
|
326
|
+
},
|
|
327
|
+
// Defaults to alignItems: "flex-start" so wrapped lines size to their content instead of
|
|
328
|
+
// stretching, but never overrides an explicit alignItems (prop order would decide the winner).
|
|
329
|
+
wrap: (value, allProps) => ({
|
|
330
|
+
alignItems: allProps.alignItems
|
|
331
|
+
? ALIGN_ITEMS[allProps.alignItems as AlignItems]
|
|
332
|
+
: "flex-start",
|
|
333
|
+
flexWrap: value ? "wrap" : "nowrap",
|
|
334
|
+
}),
|
|
335
|
+
xlDirection: (value: "row" | "column", _allProps, responsiveBreakpoint) =>
|
|
336
|
+
isBreakpointAtLeast({breakpoint: responsiveBreakpoint, minimum: "xl"})
|
|
337
|
+
? {display: "flex", flexDirection: value}
|
|
338
|
+
: {},
|
|
339
|
+
zIndex: (value) => ({
|
|
340
|
+
zIndex: typeof value === "number" || value === "auto" ? value : undefined,
|
|
341
|
+
}),
|
|
342
|
+
} as BoxStyleMap;
|
|
343
|
+
boxStyleMapCache.set(theme, cachedBoxStyleMap);
|
|
344
|
+
}
|
|
345
|
+
const boxStyleMap = cachedBoxStyleMap;
|
|
300
346
|
|
|
301
|
-
const
|
|
347
|
+
const propsAsRecord = props as Readonly<Record<string, unknown>>;
|
|
302
348
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
const propsToStyle = (): any => {
|
|
306
|
-
// noExplicitAny: same as above - heterogeneous style assembly
|
|
307
|
-
// biome-ignore lint/suspicious/noExplicitAny: same as above - heterogeneous style assembly
|
|
308
|
-
let style: any = {};
|
|
349
|
+
const propsToStyle = (): ViewStyle => {
|
|
350
|
+
let style: ViewStyle = {};
|
|
309
351
|
for (const prop of Object.keys(props) as Array<keyof typeof props>) {
|
|
310
352
|
const value = props[prop];
|
|
311
|
-
if (
|
|
312
|
-
|
|
353
|
+
if (RESPONSIVE_DIRECTION_PROP_SET.has(prop as string)) {
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
if (boxStyleMap[prop]) {
|
|
357
|
+
Object.assign(style, boxStyleMap[prop](value, propsAsRecord, breakpoint));
|
|
313
358
|
} else if (!NON_STYLE_BOX_PROPS.has(prop as string)) {
|
|
314
|
-
style[prop] = value;
|
|
359
|
+
(style as Record<string, unknown>)[prop as string] = value;
|
|
315
360
|
// console.warn(`Box: unknown property ${prop}`);
|
|
316
361
|
}
|
|
317
362
|
}
|
|
318
363
|
|
|
364
|
+
// Responsive direction specificity is deterministic and independent of JSX prop order.
|
|
365
|
+
for (const responsiveProp of RESPONSIVE_DIRECTION_PROPS) {
|
|
366
|
+
const responsiveValue = props[responsiveProp];
|
|
367
|
+
if (responsiveValue) {
|
|
368
|
+
Object.assign(
|
|
369
|
+
style,
|
|
370
|
+
boxStyleMap[responsiveProp](responsiveValue, propsAsRecord, breakpoint)
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
319
375
|
// Finally, dangerously set overrides.
|
|
320
376
|
if (props.dangerouslySetInlineStyle) {
|
|
321
|
-
style = {...style, ...props.dangerouslySetInlineStyle.__style};
|
|
377
|
+
style = {...style, ...(props.dangerouslySetInlineStyle.__style as ViewStyle)};
|
|
322
378
|
}
|
|
323
379
|
|
|
324
380
|
return style;
|
|
325
381
|
};
|
|
326
382
|
|
|
383
|
+
const boxStyle = propsToStyle();
|
|
384
|
+
|
|
327
385
|
const onHoverIn = async () => {
|
|
328
386
|
await props.onHoverStart?.();
|
|
329
387
|
};
|
|
@@ -355,7 +413,7 @@ export const Box = React.forwardRef((props: BoxProps, ref) => {
|
|
|
355
413
|
await Unifier.utils.haptic();
|
|
356
414
|
await props.onClick?.();
|
|
357
415
|
}}
|
|
358
|
-
style={
|
|
416
|
+
style={boxStyle}
|
|
359
417
|
testID={resolvedTestID ? `${resolvedTestID}-clickable` : undefined}
|
|
360
418
|
>
|
|
361
419
|
{props.children}
|
|
@@ -368,9 +426,10 @@ export const Box = React.forwardRef((props: BoxProps, ref) => {
|
|
|
368
426
|
<View
|
|
369
427
|
{...(accessibilityHint ? {accessibilityHint} : {})}
|
|
370
428
|
{...(accessibilityLabel ? {accessibilityLabel} : {})}
|
|
429
|
+
{...(props.onLayout ? {onLayout: props.onLayout} : {})}
|
|
371
430
|
onPointerEnter={onHoverIn}
|
|
372
431
|
onPointerLeave={onHoverOut}
|
|
373
|
-
style={
|
|
432
|
+
style={boxStyle}
|
|
374
433
|
testID={resolvedTestID}
|
|
375
434
|
>
|
|
376
435
|
{props.children}
|
|
@@ -379,7 +438,7 @@ export const Box = React.forwardRef((props: BoxProps, ref) => {
|
|
|
379
438
|
}
|
|
380
439
|
|
|
381
440
|
if (props.scroll) {
|
|
382
|
-
const {justifyContent, alignContent, alignItems, ...scrollStyle} =
|
|
441
|
+
const {justifyContent, alignContent, alignItems, ...scrollStyle} = boxStyle;
|
|
383
442
|
|
|
384
443
|
box = (
|
|
385
444
|
<ScrollView
|
|
@@ -414,3 +473,7 @@ export const Box = React.forwardRef((props: BoxProps, ref) => {
|
|
|
414
473
|
}
|
|
415
474
|
return box;
|
|
416
475
|
});
|
|
476
|
+
|
|
477
|
+
BoxComponent.displayName = "Box";
|
|
478
|
+
|
|
479
|
+
export const Box = React.memo(BoxComponent);
|