@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.
Files changed (201) hide show
  1. package/.ai/guidelines/core.md +1 -1
  2. package/README.md +17 -8
  3. package/dist/ActionSheet.d.ts +3 -3
  4. package/dist/ActionSheet.js +2 -2
  5. package/dist/ActionSheet.js.map +1 -1
  6. package/dist/Box.d.ts +1 -1
  7. package/dist/Box.js +219 -177
  8. package/dist/Box.js.map +1 -1
  9. package/dist/Button.js +101 -34
  10. package/dist/Button.js.map +1 -1
  11. package/dist/Common.d.ts +119 -9
  12. package/dist/Common.js.map +1 -1
  13. package/dist/ConsentFormScreen.js +46 -12
  14. package/dist/ConsentFormScreen.js.map +1 -1
  15. package/dist/ConsentNavigator.d.ts +5 -1
  16. package/dist/ConsentNavigator.js.map +1 -1
  17. package/dist/DataTable.d.ts +2 -2
  18. package/dist/DataTable.js +203 -44
  19. package/dist/DataTable.js.map +1 -1
  20. package/dist/DataTableHeaderInfoMarkdown.d.ts +6 -0
  21. package/dist/DataTableHeaderInfoMarkdown.js +7 -0
  22. package/dist/DataTableHeaderInfoMarkdown.js.map +1 -0
  23. package/dist/EmojiSelector.d.ts +2 -46
  24. package/dist/EmojiSelector.js +46 -56
  25. package/dist/EmojiSelector.js.map +1 -1
  26. package/dist/GPTChat.js +1 -1
  27. package/dist/GPTChat.js.map +1 -1
  28. package/dist/Heading.d.ts +5 -2
  29. package/dist/Heading.js +6 -8
  30. package/dist/Heading.js.map +1 -1
  31. package/dist/Hyperlink.js.map +1 -1
  32. package/dist/Icon.d.ts +1 -2
  33. package/dist/Icon.js +4 -1
  34. package/dist/Icon.js.map +1 -1
  35. package/dist/MarkdownView.d.ts +6 -3
  36. package/dist/MarkdownView.js +45 -43
  37. package/dist/MarkdownView.js.map +1 -1
  38. package/dist/MediaQuery.d.ts +5 -3
  39. package/dist/MediaQuery.js +9 -40
  40. package/dist/MediaQuery.js.map +1 -1
  41. package/dist/OpenAPIContext.js +7 -6
  42. package/dist/OpenAPIContext.js.map +1 -1
  43. package/dist/Page.js +7 -1
  44. package/dist/Page.js.map +1 -1
  45. package/dist/PickerSelect.js +8 -1
  46. package/dist/PickerSelect.js.map +1 -1
  47. package/dist/Popover.d.ts +12 -0
  48. package/dist/Popover.js +37 -0
  49. package/dist/Popover.js.map +1 -0
  50. package/dist/PortalHost.js +10 -1
  51. package/dist/PortalHost.js.map +1 -1
  52. package/dist/ResponsiveBreakpoint.d.ts +65 -0
  53. package/dist/ResponsiveBreakpoint.js +111 -0
  54. package/dist/ResponsiveBreakpoint.js.map +1 -0
  55. package/dist/SplitPage.d.ts +2 -2
  56. package/dist/SplitPage.js +7 -12
  57. package/dist/SplitPage.js.map +1 -1
  58. package/dist/SplitPage.native.d.ts +2 -2
  59. package/dist/SplitPage.native.js +1 -6
  60. package/dist/SplitPage.native.js.map +1 -1
  61. package/dist/TapToEdit.js +12 -10
  62. package/dist/TapToEdit.js.map +1 -1
  63. package/dist/TerrenoFontProvider.d.ts +7 -0
  64. package/dist/TerrenoFontProvider.js +27 -0
  65. package/dist/TerrenoFontProvider.js.map +1 -0
  66. package/dist/TerrenoProvider.js +4 -2
  67. package/dist/TerrenoProvider.js.map +1 -1
  68. package/dist/Text.d.ts +5 -2
  69. package/dist/Text.js +6 -11
  70. package/dist/Text.js.map +1 -1
  71. package/dist/TextFieldNumberActionSheet.js +9 -2
  72. package/dist/TextFieldNumberActionSheet.js.map +1 -1
  73. package/dist/Theme.js +10 -8
  74. package/dist/Theme.js.map +1 -1
  75. package/dist/ToastNotifications.d.ts +4 -2
  76. package/dist/ToastNotifications.js.map +1 -1
  77. package/dist/Tooltip.d.ts +4 -3
  78. package/dist/Tooltip.js +14 -3
  79. package/dist/Tooltip.js.map +1 -1
  80. package/dist/Unifier.d.ts +26 -1
  81. package/dist/Unifier.js.map +1 -1
  82. package/dist/WebAddressAutocomplete.js +6 -1
  83. package/dist/WebAddressAutocomplete.js.map +1 -1
  84. package/dist/emojiCategories.d.ts +46 -0
  85. package/dist/emojiCategories.js +47 -0
  86. package/dist/emojiCategories.js.map +1 -0
  87. package/dist/index.d.ts +13 -13
  88. package/dist/index.js +2 -13
  89. package/dist/index.js.map +1 -1
  90. package/dist/lazyBoundaries/createLazyComponentExport.d.ts +6 -0
  91. package/dist/lazyBoundaries/createLazyComponentExport.js +35 -0
  92. package/dist/lazyBoundaries/createLazyComponentExport.js.map +1 -0
  93. package/dist/lazyBoundaries/heavyOptionalExports.d.ts +41 -0
  94. package/dist/lazyBoundaries/heavyOptionalExports.js +43 -0
  95. package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -0
  96. package/dist/login/LoginScreen.d.ts +1 -0
  97. package/dist/login/LoginScreen.js +4 -2
  98. package/dist/login/LoginScreen.js.map +1 -1
  99. package/dist/login/loginTypes.d.ts +2 -0
  100. package/package.json +41 -2
  101. package/src/AIRequestExplorer.test.tsx +141 -0
  102. package/src/ActionSheet.tsx +9 -7
  103. package/src/AttachmentPreview.test.tsx +80 -0
  104. package/src/Box.test.tsx +97 -10
  105. package/src/Box.tsx +263 -200
  106. package/src/Button.test.tsx +207 -0
  107. package/src/Button.tsx +146 -48
  108. package/src/Common.ts +124 -25
  109. package/src/ConsentFormScreen.markdownGate.test.tsx +129 -0
  110. package/src/ConsentFormScreen.test.tsx +145 -8
  111. package/src/ConsentFormScreen.tsx +74 -25
  112. package/src/ConsentNavigator.tsx +13 -5
  113. package/src/DataTable.tsx +418 -147
  114. package/src/DataTableHeaderInfoMarkdown.test.tsx +21 -0
  115. package/src/DataTableHeaderInfoMarkdown.tsx +17 -0
  116. package/src/DataTableVirtualizationRegression.test.tsx +266 -0
  117. package/src/DateTimeField.test.tsx +54 -0
  118. package/src/EmojiSelector.test.tsx +33 -42
  119. package/src/EmojiSelector.tsx +60 -57
  120. package/src/FilePickerButton.test.tsx +167 -0
  121. package/src/FilterAccordion.test.tsx +37 -0
  122. package/src/FilterBoolean.test.tsx +96 -0
  123. package/src/FilterSelectMenu.test.tsx +23 -0
  124. package/src/GPTChat.test.tsx +696 -0
  125. package/src/GPTChat.tsx +2 -2
  126. package/src/GPTMemoryModal.test.tsx +67 -0
  127. package/src/Heading.tsx +8 -14
  128. package/src/HeightActionSheet.test.tsx +6 -9
  129. package/src/Hyperlink.tsx +5 -18
  130. package/src/Icon.tsx +6 -2
  131. package/src/MarkdownEditor.test.tsx +134 -0
  132. package/src/MarkdownEditorField.test.tsx +124 -0
  133. package/src/MarkdownView.test.tsx +55 -11
  134. package/src/MarkdownView.tsx +149 -150
  135. package/src/MediaQuery.ts +30 -34
  136. package/src/OpenAPIContext.tsx +36 -29
  137. package/src/OpenAPIRenderRegression.test.tsx +200 -0
  138. package/src/P0RenderRegression.test.tsx +214 -0
  139. package/src/P1RenderRegression.test.tsx +141 -0
  140. package/src/P2ButtonRenderRegression.test.tsx +158 -0
  141. package/src/Page.test.tsx +13 -0
  142. package/src/Page.tsx +25 -5
  143. package/src/PickerSelect.test.tsx +38 -0
  144. package/src/PickerSelect.tsx +7 -0
  145. package/src/Popover.test.tsx +151 -0
  146. package/src/Popover.tsx +211 -0
  147. package/src/PortalHost.tsx +12 -6
  148. package/src/ResponsiveBreakpoint.test.tsx +184 -0
  149. package/src/ResponsiveBreakpoint.tsx +195 -0
  150. package/src/RootImportRegression.test.tsx +62 -0
  151. package/src/SplitPage.native.tsx +5 -9
  152. package/src/SplitPage.tsx +16 -19
  153. package/src/TapToEdit.test.tsx +45 -0
  154. package/src/TapToEdit.tsx +23 -18
  155. package/src/TerrenoFontProvider.test.tsx +38 -0
  156. package/src/TerrenoFontProvider.tsx +50 -0
  157. package/src/TerrenoProvider.tsx +6 -1
  158. package/src/Text.tsx +8 -21
  159. package/src/TextFieldNumberActionSheet.test.tsx +100 -0
  160. package/src/TextFieldNumberActionSheet.tsx +11 -2
  161. package/src/Theme.test.tsx +27 -0
  162. package/src/Theme.tsx +15 -10
  163. package/src/Toast.tsx +1 -1
  164. package/src/ToastNotifications.tsx +4 -4
  165. package/src/Tooltip.test.tsx +64 -0
  166. package/src/Tooltip.tsx +18 -4
  167. package/src/Unifier.ts +26 -3
  168. package/src/WebAddressAutocomplete.tsx +6 -2
  169. package/src/__snapshots__/ActionSheet.test.tsx.snap +0 -36
  170. package/src/__snapshots__/AddressField.test.tsx.snap +1 -0
  171. package/src/__snapshots__/AttachmentPreview.test.tsx.snap +225 -0
  172. package/src/__snapshots__/CustomSelectField.test.tsx.snap +7 -0
  173. package/src/__snapshots__/DataTable.test.tsx.snap +793 -250
  174. package/src/__snapshots__/DecimalRangeActionSheet.test.tsx.snap +0 -8
  175. package/src/__snapshots__/EmojiSelector.test.tsx.snap +35555 -30
  176. package/src/__snapshots__/Field.test.tsx.snap +7 -0
  177. package/src/__snapshots__/FilterSelectMenu.test.tsx.snap +1 -0
  178. package/src/__snapshots__/HeightActionSheet.test.tsx.snap +0 -8
  179. package/src/__snapshots__/HeightField.test.tsx.snap +0 -20
  180. package/src/__snapshots__/NumberPickerActionSheet.test.tsx.snap +0 -8
  181. package/src/__snapshots__/Page.test.tsx.snap +13 -1
  182. package/src/__snapshots__/PickerSelect.test.tsx.snap +7 -0
  183. package/src/__snapshots__/SelectField.test.tsx.snap +6 -0
  184. package/src/__snapshots__/TimezonePicker.test.tsx.snap +6 -0
  185. package/src/benchmarks/importGraph.test.ts +71 -0
  186. package/src/benchmarks/importGraph.ts +136 -0
  187. package/src/benchmarks/importTiming.test.ts +42 -0
  188. package/src/benchmarks/importTiming.ts +86 -0
  189. package/src/bunSetup.ts +174 -32
  190. package/src/emojiCategories.test.ts +23 -0
  191. package/src/emojiCategories.ts +46 -0
  192. package/src/index.tsx +27 -13
  193. package/src/lazyBoundaries/createLazyComponentExport.test.tsx +104 -0
  194. package/src/lazyBoundaries/createLazyComponentExport.tsx +63 -0
  195. package/src/lazyBoundaries/heavyOptionalExports.test.tsx +33 -0
  196. package/src/lazyBoundaries/heavyOptionalExports.tsx +106 -0
  197. package/src/login/LoginScreen.test.tsx +9 -2
  198. package/src/login/LoginScreen.tsx +6 -2
  199. package/src/login/loginTypes.ts +2 -0
  200. package/src/table/TableDate.test.tsx +35 -1
  201. 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 {mediaQueryLargerThan} from "./MediaQuery";
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
- export const Box = React.forwardRef((props: BoxProps, ref) => {
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
- const BOX_STYLE_MAP: {
115
- [prop: string]: (
116
- // noExplicitAny: Box's style mapper accepts heterogeneous prop values (spacing, colors, dimensions, theme tokens, booleans) that cannot be enumerated in a single union; the mapper functions narrow at call site
117
- // biome-ignore lint/suspicious/noExplicitAny: Box's style mapper accepts heterogeneous prop values (spacing, colors, dimensions, theme tokens, booleans) that cannot be enumerated in a single union; the mapper functions narrow at call site
118
- value: any,
119
- // noExplicitAny: see above - heterogeneous prop values
120
- // biome-ignore lint/suspicious/noExplicitAny: see above - heterogeneous prop values
121
- all: {[prop: string]: any}
122
- ) => {[style: string]: string | number} | {};
123
- } = {
124
- alignContent: (value: AlignContent) => ({alignContent: ALIGN_CONTENT[value]}),
125
- alignItems: (value: AlignItems) => ({alignItems: ALIGN_ITEMS[value]}),
126
- alignSelf: (value: AlignSelf) => ({alignSelf: ALIGN_SELF[value]}),
127
- border: (value: keyof BorderTheme) => {
128
- if (!value) {
129
- return {};
130
- }
131
- return {borderColor: theme.border[value], borderWidth: BORDER_WIDTH};
132
- },
133
- borderBottom: (value: keyof BorderTheme) => {
134
- if (!value) {
135
- return {};
136
- }
137
- return {borderBottomColor: theme.border[value], borderBottomWidth: BORDER_WIDTH};
138
- },
139
- borderLeft: (value: keyof BorderTheme) => {
140
- if (!value) {
141
- return {};
142
- }
143
- return {borderLeftColor: theme.border[value], borderLeftWidth: BORDER_WIDTH};
144
- },
145
- borderRight: (value: keyof BorderTheme) => {
146
- if (!value) {
147
- return {};
148
- }
149
- return {borderRightColor: theme.border[value], borderRightWidth: BORDER_WIDTH};
150
- },
151
- borderTop: (value: keyof BorderTheme) => {
152
- if (!value) {
153
- return {};
154
- }
155
- return {borderTopColor: theme.border[value], borderTopWidth: BORDER_WIDTH};
156
- },
157
- bottom: (bottom) => ({bottom: bottom ? 0 : undefined}),
158
- color: (value: keyof SurfaceTheme) => ({backgroundColor: theme.surface[value]}),
159
- direction: (value: "row" | "column") => ({display: "flex", flexDirection: value}),
160
- display: (value: "none" | "flex" | "block" | "inlineBlock" | "visuallyHidden") => {
161
- if (value === "none") {
162
- return {display: "none"};
163
- }
164
- return value === "flex" ? {flex: undefined} : {flex: 0, flexDirection: "row"};
165
- },
166
- flex: (value: string) => {
167
- if (value === "grow") {
168
- return {display: "flex", flexGrow: 1, flexShrink: 1};
169
- } else if (value === "shrink") {
170
- return {display: "flex", flexShrink: 1};
171
- } else {
172
- return {display: "flex", flex: 0};
173
- }
174
- },
175
- gap: (value) => ({gap: getSpacing(value)}),
176
- height: (value) => {
177
- if (!isValidWidthHeight(value)) {
178
- console.warn(
179
- `Box: height prop must be a number or percentage string (e.g., "50%"), received: ${value}`
180
- );
181
- return {};
182
- }
183
- if (props.border && !Number.isNaN(Number(value))) {
184
- return {height: Number(value) + 2 * 2};
185
- } else {
186
- return {height: value};
187
- }
188
- },
189
- justifyContent: (value: JustifyContent) => ({justifyContent: ALIGN_CONTENT[value]}),
190
- left: (left) => ({left: left ? 0 : undefined}),
191
- lgDirection: (value: "row" | "column") =>
192
- mediaQueryLargerThan("lg") ? {display: "flex", flexDirection: value} : {},
193
- margin: (value) => ({margin: getSpacing(value)}),
194
- marginBottom: (value) => ({marginBottom: getSpacing(value)}),
195
- marginLeft: (value) => ({marginLeft: getSpacing(value)}),
196
- marginRight: (value) => ({marginRight: getSpacing(value)}),
197
- marginTop: (value) => ({marginTop: getSpacing(value)}),
198
- maxHeight: (value) => {
199
- if (!isValidWidthHeight(value)) {
200
- console.warn(
201
- `Box: maxHeight prop must be a number or percentage string (e.g., "50%"), received: ${value}`
202
- );
203
- return {};
204
- }
205
- return {maxHeight: value};
206
- },
207
- maxWidth: (value) => {
208
- if (!isValidWidthHeight(value)) {
209
- console.warn(
210
- `Box: maxWidth prop must be a number or percentage string (e.g., "50%"), received: ${value}`
211
- );
212
- return {};
213
- }
214
- return {maxWidth: value};
215
- },
216
- mdDirection: (value: "row" | "column") =>
217
- mediaQueryLargerThan("md") ? {display: "flex", flexDirection: value} : {},
218
- minHeight: (value) => {
219
- if (!isValidWidthHeight(value)) {
220
- console.warn(
221
- `Box: minHeight prop must be a number or percentage string (e.g., "50%"), received: ${value}`
222
- );
223
- return {};
224
- }
225
- return {minHeight: value};
226
- },
227
- minWidth: (value) => {
228
- if (!isValidWidthHeight(value)) {
229
- console.warn(
230
- `Box: minWidth prop must be a number or percentage string (e.g., "50%"), received: ${value}`
231
- );
232
- return {};
233
- }
234
- return {minWidth: value};
235
- },
236
- overflow: (value) => {
237
- if (value === "scrollY" || value === "scroll") {
238
- return {overflow: "scroll"};
239
- }
240
- return {overflow: value};
241
- },
242
- padding: (value) => ({padding: getSpacing(value)}),
243
- paddingX: (value) => ({paddingLeft: getSpacing(value), paddingRight: getSpacing(value)}),
244
- paddingY: (value) => ({paddingBottom: getSpacing(value), paddingTop: getSpacing(value)}),
245
- position: (value) => ({position: value}),
246
- right: (right) => ({right: right ? 0 : undefined}),
247
- rounding: (rounding, allProps) => {
248
- if (rounding === "circle") {
249
- if (!allProps.height && !allProps.width) {
250
- console.warn("Cannot use Box rounding='circle' without height or width.");
251
- return {borderRadius: undefined};
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
- if (rounding) {
257
- return {borderRadius: getRounding(rounding)};
258
- }
291
+ if (rounding) {
292
+ return {borderRadius: getRounding(rounding as Rounding)};
293
+ }
259
294
 
260
- return {borderRadius: undefined};
261
- },
262
- shadow: (value) => {
263
- if (!value) {
264
- return {};
265
- }
266
- if (Platform.OS === "ios" || Platform.OS === "web") {
267
- return {
268
- boxShadow: "2px 2px 2px rgba(153, 153, 153, 1.0)",
269
- };
270
- } else {
271
- return {elevation: 4};
272
- }
273
- },
274
- smDirection: (value: "row" | "column") =>
275
- mediaQueryLargerThan("sm") ? {display: "flex", flexDirection: value} : {},
276
- top: (top) => ({top: top ? 0 : undefined}),
277
- width: (value) => {
278
- if (!isValidWidthHeight(value)) {
279
- console.warn(
280
- `Box: width prop must be a number or percentage string (e.g., "50%"), received: ${value}`
281
- );
282
- return {};
283
- }
284
- if (props.border && !Number.isNaN(Number(value))) {
285
- return {width: Number(value) + 2 * 2};
286
- } else {
287
- return {width: value};
288
- }
289
- },
290
- // Defaults to alignItems: "flex-start" so wrapped lines size to their content instead of
291
- // stretching, but never overrides an explicit alignItems (prop order would decide the winner).
292
- wrap: (value, allProps) => ({
293
- alignItems: allProps.alignItems
294
- ? ALIGN_ITEMS[allProps.alignItems as AlignItems]
295
- : "flex-start",
296
- flexWrap: value ? "wrap" : "nowrap",
297
- }),
298
- zIndex: (value) => ({zIndex: value ? value : undefined}),
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 scrollRef = props.scrollRef ?? React.createRef();
347
+ const propsAsRecord = props as Readonly<Record<string, unknown>>;
302
348
 
303
- // noExplicitAny: the style object is assembled from heterogeneous mapper outputs and consumed by RN ViewStyle which has narrow union types per property
304
- // biome-ignore lint/suspicious/noExplicitAny: the style object is assembled from heterogeneous mapper outputs and consumed by RN ViewStyle which has narrow union types per property
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 (BOX_STYLE_MAP[prop]) {
312
- Object.assign(style, BOX_STYLE_MAP[prop](value, props));
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={propsToStyle()}
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={propsToStyle()}
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} = propsToStyle();
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);