@ankhorage/surface 5.0.1 → 6.0.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 (195) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +1 -2
  3. package/dist/components/field/Field.d.ts +1 -0
  4. package/dist/components/field/Field.d.ts.map +1 -1
  5. package/dist/components/field/Field.js +5 -4
  6. package/dist/components/field/Field.js.map +1 -1
  7. package/dist/components/list-item/ListItem.d.ts +1 -0
  8. package/dist/components/list-item/ListItem.d.ts.map +1 -1
  9. package/dist/components/list-item/ListItem.js +13 -12
  10. package/dist/components/list-item/ListItem.js.map +1 -1
  11. package/dist/components/switch/Switch.d.ts +1 -0
  12. package/dist/components/switch/Switch.d.ts.map +1 -1
  13. package/dist/components/switch/Switch.js +10 -13
  14. package/dist/components/switch/Switch.js.map +1 -1
  15. package/dist/{layout → core/responsive}/Show.d.ts +2 -1
  16. package/dist/core/responsive/Show.d.ts.map +1 -0
  17. package/dist/{layout → core/responsive}/Show.js +3 -1
  18. package/dist/core/responsive/Show.js.map +1 -0
  19. package/dist/core/responsive/index.d.ts +1 -0
  20. package/dist/core/responsive/index.d.ts.map +1 -1
  21. package/dist/core/responsive/index.js +1 -0
  22. package/dist/core/responsive/index.js.map +1 -1
  23. package/dist/features/app-bar/adapters/inbound/AppBar.d.ts +5 -0
  24. package/dist/features/app-bar/adapters/inbound/AppBar.d.ts.map +1 -0
  25. package/dist/features/app-bar/adapters/inbound/AppBar.js +40 -0
  26. package/dist/features/app-bar/adapters/inbound/AppBar.js.map +1 -0
  27. package/dist/features/app-bar/public.d.ts +3 -0
  28. package/dist/features/app-bar/public.d.ts.map +1 -0
  29. package/dist/features/app-bar/public.js +2 -0
  30. package/dist/features/app-bar/public.js.map +1 -0
  31. package/dist/features/badge/adapters/inbound/Badge.js +3 -3
  32. package/dist/features/badge/adapters/inbound/Badge.js.map +1 -1
  33. package/dist/features/button/adapters/inbound/Button.js +8 -8
  34. package/dist/features/button/adapters/inbound/Button.js.map +1 -1
  35. package/dist/features/button/adapters/inbound/IconButton.js +3 -3
  36. package/dist/features/button/adapters/inbound/IconButton.js.map +1 -1
  37. package/dist/features/form/checkbox/adapters/inbound/Checkbox.js +7 -7
  38. package/dist/features/form/checkbox/adapters/inbound/Checkbox.js.map +1 -1
  39. package/dist/features/form/radio/adapters/inbound/Radio.js +8 -8
  40. package/dist/features/form/radio/adapters/inbound/Radio.js.map +1 -1
  41. package/dist/features/layout/adapters/inbound/Divider.js +2 -2
  42. package/dist/features/layout/adapters/inbound/Divider.js.map +1 -1
  43. package/dist/features/layout/adapters/inbound/Grid.d.ts.map +1 -1
  44. package/dist/features/layout/adapters/inbound/Grid.js +7 -9
  45. package/dist/features/layout/adapters/inbound/Grid.js.map +1 -1
  46. package/dist/features/layout/adapters/inbound/ScrollView.d.ts +5 -0
  47. package/dist/features/layout/adapters/inbound/ScrollView.d.ts.map +1 -0
  48. package/dist/features/layout/adapters/inbound/ScrollView.js +69 -0
  49. package/dist/features/layout/adapters/inbound/ScrollView.js.map +1 -0
  50. package/dist/features/layout/adapters/inbound/View.d.ts +5 -0
  51. package/dist/features/layout/adapters/inbound/View.d.ts.map +1 -0
  52. package/dist/features/layout/adapters/inbound/View.js +17 -0
  53. package/dist/features/layout/adapters/inbound/View.js.map +1 -0
  54. package/dist/features/layout/public.d.ts +3 -4
  55. package/dist/features/layout/public.d.ts.map +1 -1
  56. package/dist/features/layout/public.js +2 -3
  57. package/dist/features/layout/public.js.map +1 -1
  58. package/dist/features/modal/adapters/inbound/Modal.d.ts.map +1 -1
  59. package/dist/features/modal/adapters/inbound/Modal.js +8 -8
  60. package/dist/features/modal/adapters/inbound/Modal.js.map +1 -1
  61. package/dist/features/popover-menu/adapters/inbound/PopoverMenu.d.ts.map +1 -1
  62. package/dist/features/popover-menu/adapters/inbound/PopoverMenu.js +11 -12
  63. package/dist/features/popover-menu/adapters/inbound/PopoverMenu.js.map +1 -1
  64. package/dist/features/surface/adapters/inbound/Surface.d.ts +1 -1
  65. package/dist/features/surface/adapters/inbound/Surface.d.ts.map +1 -1
  66. package/dist/features/surface/adapters/inbound/Surface.js +3 -3
  67. package/dist/features/surface/adapters/inbound/Surface.js.map +1 -1
  68. package/dist/features/tabs/adapters/inbound/Tab.js +3 -3
  69. package/dist/features/tabs/adapters/inbound/Tab.js.map +1 -1
  70. package/dist/features/tabs/adapters/inbound/TabList.d.ts.map +1 -1
  71. package/dist/features/tabs/adapters/inbound/TabList.js +3 -5
  72. package/dist/features/tabs/adapters/inbound/TabList.js.map +1 -1
  73. package/dist/features/tabs/adapters/inbound/Tabs.js +2 -2
  74. package/dist/features/tabs/adapters/inbound/Tabs.js.map +1 -1
  75. package/dist/features/toast/adapters/inbound/Toast.js +5 -5
  76. package/dist/features/toast/adapters/inbound/Toast.js.map +1 -1
  77. package/dist/features/toast/adapters/inbound/ToastProvider.js +3 -3
  78. package/dist/features/toast/adapters/inbound/ToastProvider.js.map +1 -1
  79. package/dist/index.d.ts +4 -3
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +2 -2
  82. package/dist/index.js.map +1 -1
  83. package/dist/primitives/button-base/ButtonBase.d.ts +1 -0
  84. package/dist/primitives/button-base/ButtonBase.d.ts.map +1 -1
  85. package/dist/primitives/button-base/ButtonBase.js +6 -5
  86. package/dist/primitives/button-base/ButtonBase.js.map +1 -1
  87. package/dist/primitives/button-base/types.d.ts +2 -2
  88. package/dist/primitives/button-base/types.d.ts.map +1 -1
  89. package/dist/primitives/button-base/types.js.map +1 -1
  90. package/dist/types/app-bar.d.ts +12 -0
  91. package/dist/types/app-bar.d.ts.map +1 -0
  92. package/dist/types/app-bar.js +2 -0
  93. package/dist/types/app-bar.js.map +1 -0
  94. package/dist/types/layout.d.ts +15 -17
  95. package/dist/types/layout.d.ts.map +1 -1
  96. package/dist/types/layout.js.map +1 -1
  97. package/dist/types/surface.d.ts +2 -2
  98. package/dist/types/surface.d.ts.map +1 -1
  99. package/dist/types/surface.js.map +1 -1
  100. package/dist/utils/resolveViewStyles.d.ts +7 -0
  101. package/dist/utils/resolveViewStyles.d.ts.map +1 -0
  102. package/dist/utils/{resolveBoxStyles.js → resolveViewStyles.js} +11 -4
  103. package/dist/utils/resolveViewStyles.js.map +1 -0
  104. package/package.json +1 -1
  105. package/src/components/field/Field.tsx +5 -4
  106. package/src/components/list-item/ListItem.tsx +17 -13
  107. package/src/components/switch/Switch.tsx +10 -15
  108. package/src/{layout → core/responsive}/Show.tsx +4 -1
  109. package/src/core/responsive/index.ts +1 -0
  110. package/src/features/app-bar/adapters/inbound/AppBar.tsx +69 -0
  111. package/src/features/app-bar/public.ts +2 -0
  112. package/src/features/badge/adapters/inbound/Badge.tsx +3 -3
  113. package/src/features/button/adapters/inbound/Button.tsx +8 -8
  114. package/src/features/button/adapters/inbound/IconButton.tsx +3 -3
  115. package/src/features/form/checkbox/adapters/inbound/Checkbox.tsx +7 -7
  116. package/src/features/form/radio/adapters/inbound/Radio.tsx +8 -8
  117. package/src/features/layout/adapters/inbound/Divider.tsx +2 -2
  118. package/src/features/layout/adapters/inbound/Grid.tsx +12 -14
  119. package/src/features/layout/adapters/inbound/ScrollView.tsx +102 -0
  120. package/src/features/layout/adapters/inbound/{Box.tsx → View.tsx} +9 -9
  121. package/src/features/layout/public.ts +3 -10
  122. package/src/features/modal/adapters/inbound/Modal.tsx +11 -8
  123. package/src/features/popover-menu/adapters/inbound/PopoverMenu.tsx +11 -14
  124. package/src/features/surface/adapters/inbound/Surface.tsx +3 -3
  125. package/src/features/tabs/adapters/inbound/Tab.tsx +3 -3
  126. package/src/features/tabs/adapters/inbound/TabList.tsx +3 -6
  127. package/src/features/tabs/adapters/inbound/Tabs.tsx +2 -2
  128. package/src/features/toast/adapters/inbound/Toast.tsx +5 -5
  129. package/src/features/toast/adapters/inbound/ToastProvider.tsx +3 -3
  130. package/src/index.test.ts +12 -38
  131. package/src/index.ts +4 -9
  132. package/src/primitives/button-base/ButtonBase.tsx +6 -8
  133. package/src/primitives/button-base/types.ts +2 -2
  134. package/src/types/app-bar.ts +13 -0
  135. package/src/types/layout.ts +25 -20
  136. package/src/types/surface.ts +2 -2
  137. package/src/utils/resolveViewStyles.test.ts +71 -0
  138. package/src/utils/{resolveBoxStyles.ts → resolveViewStyles.ts} +16 -9
  139. package/src/webAcceptance.test.tsx +8 -9
  140. package/dist/features/layout/adapters/inbound/Box.d.ts +0 -5
  141. package/dist/features/layout/adapters/inbound/Box.d.ts.map +0 -1
  142. package/dist/features/layout/adapters/inbound/Box.js +0 -17
  143. package/dist/features/layout/adapters/inbound/Box.js.map +0 -1
  144. package/dist/features/layout/adapters/inbound/Container.d.ts +0 -5
  145. package/dist/features/layout/adapters/inbound/Container.d.ts.map +0 -1
  146. package/dist/features/layout/adapters/inbound/Container.js +0 -28
  147. package/dist/features/layout/adapters/inbound/Container.js.map +0 -1
  148. package/dist/features/layout/adapters/inbound/Stack.d.ts +0 -5
  149. package/dist/features/layout/adapters/inbound/Stack.d.ts.map +0 -1
  150. package/dist/features/layout/adapters/inbound/Stack.js +0 -27
  151. package/dist/features/layout/adapters/inbound/Stack.js.map +0 -1
  152. package/dist/layout/AppBar.d.ts +0 -13
  153. package/dist/layout/AppBar.d.ts.map +0 -1
  154. package/dist/layout/AppBar.js +0 -30
  155. package/dist/layout/AppBar.js.map +0 -1
  156. package/dist/layout/Center.d.ts +0 -7
  157. package/dist/layout/Center.d.ts.map +0 -1
  158. package/dist/layout/Center.js +0 -12
  159. package/dist/layout/Center.js.map +0 -1
  160. package/dist/layout/Inline.d.ts +0 -5
  161. package/dist/layout/Inline.d.ts.map +0 -1
  162. package/dist/layout/Inline.js +0 -6
  163. package/dist/layout/Inline.js.map +0 -1
  164. package/dist/layout/ScrollArea.d.ts +0 -9
  165. package/dist/layout/ScrollArea.d.ts.map +0 -1
  166. package/dist/layout/ScrollArea.js +0 -52
  167. package/dist/layout/ScrollArea.js.map +0 -1
  168. package/dist/layout/Show.d.ts.map +0 -1
  169. package/dist/layout/Show.js.map +0 -1
  170. package/dist/layout/Spacer.d.ts +0 -9
  171. package/dist/layout/Spacer.d.ts.map +0 -1
  172. package/dist/layout/Spacer.js +0 -12
  173. package/dist/layout/Spacer.js.map +0 -1
  174. package/dist/layout/Template.d.ts +0 -18
  175. package/dist/layout/Template.d.ts.map +0 -1
  176. package/dist/layout/Template.js +0 -36
  177. package/dist/layout/Template.js.map +0 -1
  178. package/dist/layout/index.d.ts +0 -15
  179. package/dist/layout/index.d.ts.map +0 -1
  180. package/dist/layout/index.js +0 -8
  181. package/dist/layout/index.js.map +0 -1
  182. package/dist/utils/resolveBoxStyles.d.ts +0 -7
  183. package/dist/utils/resolveBoxStyles.d.ts.map +0 -1
  184. package/dist/utils/resolveBoxStyles.js.map +0 -1
  185. package/src/features/layout/adapters/inbound/Container.tsx +0 -43
  186. package/src/features/layout/adapters/inbound/Stack.test.ts +0 -13
  187. package/src/features/layout/adapters/inbound/Stack.tsx +0 -44
  188. package/src/layout/AppBar.tsx +0 -60
  189. package/src/layout/Center.tsx +0 -22
  190. package/src/layout/Inline.tsx +0 -9
  191. package/src/layout/ScrollArea.tsx +0 -116
  192. package/src/layout/Spacer.tsx +0 -22
  193. package/src/layout/Template.tsx +0 -86
  194. package/src/layout/index.ts +0 -14
  195. package/src/utils/resolveBoxStyles.test.ts +0 -54
@@ -1,60 +0,0 @@
1
- import React from 'react';
2
- import { type StyleProp, View, type ViewStyle } from 'react-native';
3
- import { SafeAreaInsetsContext } from 'react-native-safe-area-context';
4
-
5
- import { Box, type BoxProps, Divider } from '../features/layout/public';
6
- import { useTheme } from '../theme/ThemeContext';
7
-
8
- export interface AppBarProps extends Omit<BoxProps, 'children'> {
9
- leading?: React.ReactNode;
10
- trailing?: React.ReactNode;
11
- children?: React.ReactNode;
12
- safeAreaTop?: boolean;
13
- divider?: boolean;
14
- contentStyle?: StyleProp<ViewStyle>;
15
- }
16
-
17
- export function AppBar({
18
- leading,
19
- trailing,
20
- children,
21
- safeAreaTop = true,
22
- divider = false,
23
- contentStyle,
24
- bg,
25
- style,
26
- ...props
27
- }: AppBarProps) {
28
- const { theme } = useTheme();
29
- const insets = React.use(SafeAreaInsetsContext);
30
- const topInset = safeAreaTop ? (insets?.top ?? 0) : 0;
31
- const safeAreaStyle: ViewStyle | undefined =
32
- topInset === 0 ? undefined : { paddingTop: topInset };
33
-
34
- return (
35
- <Box {...props} bg={bg ?? theme.semantics.surface.default} style={style}>
36
- <View style={safeAreaStyle}>
37
- <View
38
- style={[
39
- {
40
- minHeight: 56,
41
- flexDirection: 'row',
42
- alignItems: 'center',
43
- paddingHorizontal: theme.spacing.m,
44
- },
45
- contentStyle,
46
- ]}
47
- >
48
- {leading ? (
49
- <View style={{ marginRight: theme.spacing.s, flexShrink: 0 }}>{leading}</View>
50
- ) : null}
51
- <View style={{ flex: 1, minWidth: 0 }}>{children}</View>
52
- {trailing ? (
53
- <View style={{ marginLeft: theme.spacing.s, flexShrink: 0 }}>{trailing}</View>
54
- ) : null}
55
- </View>
56
- {divider ? <Divider color={theme.semantics.neutral.divider} thickness={1} /> : null}
57
- </View>
58
- </Box>
59
- );
60
- }
@@ -1,22 +0,0 @@
1
- import React from 'react';
2
-
3
- import { Box, type BoxProps } from '../features/layout/public';
4
-
5
- export interface CenterProps extends BoxProps {
6
- axis?: 'horizontal' | 'vertical' | 'both';
7
- }
8
-
9
- export function Center({ axis = 'both', style, ...props }: CenterProps) {
10
- return (
11
- <Box
12
- {...props}
13
- style={[
14
- {
15
- alignItems: axis === 'both' || axis === 'horizontal' ? 'center' : undefined,
16
- justifyContent: axis === 'both' || axis === 'vertical' ? 'center' : undefined,
17
- },
18
- style,
19
- ]}
20
- />
21
- );
22
- }
@@ -1,9 +0,0 @@
1
- import React from 'react';
2
-
3
- import { Stack, type StackProps } from '../features/layout/public';
4
-
5
- export type InlineProps = Omit<StackProps, 'direction'>;
6
-
7
- export function Inline({ wrap = 'wrap', align = 'center', ...props }: InlineProps) {
8
- return <Stack {...props} align={align} direction="row" wrap={wrap} />;
9
- }
@@ -1,116 +0,0 @@
1
- import React from 'react';
2
- import {
3
- ScrollView,
4
- type ScrollViewProps as ReactNativeScrollViewProps,
5
- type StyleProp,
6
- type ViewStyle,
7
- } from 'react-native';
8
-
9
- import { useResponsiveRuntime } from '../core/responsive';
10
- import { useTheme } from '../theme/ThemeContext';
11
- import type { BoxStyleProps } from '../types/layout';
12
- import { resolveBoxStyles } from '../utils/resolveBoxStyles';
13
-
14
- export interface ScrollAreaProps
15
- extends
16
- BoxStyleProps,
17
- Omit<ReactNativeScrollViewProps, 'children' | 'contentContainerStyle' | 'style'> {
18
- children?: React.ReactNode;
19
- contentContainerStyle?: StyleProp<ViewStyle>;
20
- }
21
-
22
- export function ScrollArea({
23
- children,
24
- contentContainerStyle,
25
- p,
26
- px,
27
- py,
28
- pt,
29
- pb,
30
- pl,
31
- pr,
32
- m,
33
- mx,
34
- my,
35
- mt,
36
- mb,
37
- ml,
38
- mr,
39
- bg,
40
- radius,
41
- borderWidth,
42
- borderColor,
43
- width,
44
- height,
45
- minWidth,
46
- maxWidth,
47
- minHeight,
48
- maxHeight,
49
- flex,
50
- flexGrow,
51
- flexShrink,
52
- flexBasis,
53
- alignSelf,
54
- position,
55
- top,
56
- bottom,
57
- left,
58
- right,
59
- overflow,
60
- zIndex,
61
- opacity,
62
- style,
63
- ...scrollProps
64
- }: ScrollAreaProps) {
65
- const { theme } = useTheme();
66
- const { breakpoint } = useResponsiveRuntime();
67
- const resolved = resolveBoxStyles(theme, breakpoint, {
68
- p,
69
- px,
70
- py,
71
- pt,
72
- pb,
73
- pl,
74
- pr,
75
- m,
76
- mx,
77
- my,
78
- mt,
79
- mb,
80
- ml,
81
- mr,
82
- bg,
83
- radius,
84
- borderWidth,
85
- borderColor,
86
- width,
87
- height,
88
- minWidth,
89
- maxWidth,
90
- minHeight,
91
- maxHeight,
92
- flex,
93
- flexGrow,
94
- flexShrink,
95
- flexBasis,
96
- alignSelf,
97
- position,
98
- top,
99
- bottom,
100
- left,
101
- right,
102
- overflow,
103
- zIndex,
104
- opacity,
105
- });
106
-
107
- return (
108
- <ScrollView
109
- {...scrollProps}
110
- contentContainerStyle={contentContainerStyle}
111
- style={[resolved, style]}
112
- >
113
- {children}
114
- </ScrollView>
115
- );
116
- }
@@ -1,22 +0,0 @@
1
- import React from 'react';
2
-
3
- import { Box } from '../features/layout/public';
4
- import type { SpaceValue } from '../types/layout';
5
-
6
- export interface SpacerProps {
7
- size?: SpaceValue;
8
- axis?: 'horizontal' | 'vertical' | 'both';
9
- testID?: string;
10
- }
11
-
12
- export function Spacer({ size = 'm', axis = 'vertical', testID }: SpacerProps) {
13
- if (axis === 'horizontal') {
14
- return <Box testID={testID} width={size} />;
15
- }
16
-
17
- if (axis === 'both') {
18
- return <Box testID={testID} height={size} width={size} />;
19
- }
20
-
21
- return <Box testID={testID} height={size} />;
22
- }
@@ -1,86 +0,0 @@
1
- import React from 'react';
2
- import { View } from 'react-native';
3
-
4
- import {
5
- type Breakpoint,
6
- resolveResponsive,
7
- type Responsive,
8
- useResponsiveRuntime,
9
- } from '../core/responsive';
10
- import { Box, type BoxProps } from '../features/layout/public';
11
- import { useTheme } from '../theme/ThemeContext';
12
- import type { SpaceValue } from '../types/layout';
13
- import { resolveSpacing } from '../utils/resolveSpacing';
14
-
15
- type SlotMap = Record<string, React.ReactNode>;
16
- type TemplateMap = Partial<Record<Breakpoint, string[][]>>;
17
- type ColumnsMap = Partial<Record<Breakpoint, number[]>>;
18
-
19
- export interface TemplateProps extends Omit<BoxProps, 'children'> {
20
- slots: SlotMap;
21
- templates: TemplateMap;
22
- columns?: ColumnsMap;
23
- gap?: Responsive<SpaceValue>;
24
- rowGap?: Responsive<SpaceValue>;
25
- colGap?: Responsive<SpaceValue>;
26
- }
27
-
28
- function resolveByBreakpointMap<T>(
29
- map: Partial<Record<Breakpoint, T>> | undefined,
30
- breakpoint: Breakpoint,
31
- ): T | undefined {
32
- return resolveResponsive(map, breakpoint);
33
- }
34
-
35
- export function Template({
36
- slots,
37
- templates,
38
- columns,
39
- gap = 0,
40
- rowGap,
41
- colGap,
42
- ...props
43
- }: TemplateProps) {
44
- const { theme } = useTheme();
45
- const { breakpoint } = useResponsiveRuntime();
46
-
47
- const resolvedTemplate = resolveByBreakpointMap(templates, breakpoint) ?? [];
48
- const resolvedColumns = resolveByBreakpointMap(columns, breakpoint);
49
- const defaultGap = resolveResponsive(gap, breakpoint) ?? 0;
50
- const rowSpacing = Number(
51
- resolveSpacing(theme, resolveResponsive(rowGap, breakpoint) ?? defaultGap) ?? 0,
52
- );
53
- const colSpacing = Number(
54
- resolveSpacing(theme, resolveResponsive(colGap, breakpoint) ?? defaultGap) ?? 0,
55
- );
56
-
57
- return (
58
- <Box {...props}>
59
- {resolvedTemplate.map((row, rowIndex) => (
60
- <View
61
- key={`row-${String(rowIndex)}`}
62
- style={{
63
- flexDirection: 'row',
64
- marginTop: rowIndex === 0 ? 0 : rowSpacing,
65
- }}
66
- >
67
- {row.map((slotId, cellIndex) => {
68
- const weight = resolvedColumns?.[cellIndex] ?? 1;
69
- const node = slots[slotId];
70
- return (
71
- <View
72
- key={`${slotId}-${String(rowIndex)}-${String(cellIndex)}`}
73
- style={{
74
- flex: weight,
75
- marginLeft: cellIndex === 0 ? 0 : colSpacing,
76
- }}
77
- >
78
- {node}
79
- </View>
80
- );
81
- })}
82
- </View>
83
- ))}
84
- </Box>
85
- );
86
- }
@@ -1,14 +0,0 @@
1
- export type { AppBarProps } from './AppBar';
2
- export { AppBar } from './AppBar';
3
- export type { CenterProps } from './Center';
4
- export { Center } from './Center';
5
- export type { InlineProps } from './Inline';
6
- export { Inline } from './Inline';
7
- export type { ScrollAreaProps } from './ScrollArea';
8
- export { ScrollArea } from './ScrollArea';
9
- export type { ShowProps } from './Show';
10
- export { Show } from './Show';
11
- export type { SpacerProps } from './Spacer';
12
- export { Spacer } from './Spacer';
13
- export type { TemplateProps } from './Template';
14
- export { Template } from './Template';
@@ -1,54 +0,0 @@
1
- import { describe, expect, test } from 'bun:test';
2
-
3
- import type { SurfaceTheme } from '../theme/types';
4
- import { resolveBoxStyles } from './resolveBoxStyles';
5
-
6
- const mockTheme = {
7
- spacing: { s: 4, m: 8, l: 16 },
8
- radii: { m: 8 },
9
- colors: { primary: '#007AFF', surface: '#FFFFFF' },
10
- } as unknown as SurfaceTheme;
11
-
12
- describe('resolveBoxStyles', () => {
13
- test('resolves padding and margins correctly', () => {
14
- const styles = resolveBoxStyles(mockTheme, 'base', { p: 's', m: 8 });
15
- expect(styles.padding).toBe(4);
16
- expect(styles.margin).toBe(8);
17
- });
18
-
19
- test('resolves responsive properties', () => {
20
- const props = { p: { base: 's', lg: 'l' } } as const;
21
- expect(resolveBoxStyles(mockTheme, 'base', props).padding).toBe(4);
22
- expect(resolveBoxStyles(mockTheme, 'lg', props).padding).toBe(16);
23
- });
24
-
25
- test('resolves colors and border styles', () => {
26
- const styles = resolveBoxStyles(mockTheme, 'base', {
27
- bg: 'primary',
28
- radius: 'm',
29
- borderWidth: 1,
30
- borderColor: 'surface',
31
- });
32
- expect(styles.backgroundColor).toBe('#007AFF');
33
- expect(styles.borderRadius).toBe(8);
34
- expect(styles.borderWidth).toBe(1);
35
- expect(styles.borderColor).toBe('#FFFFFF');
36
- });
37
-
38
- test('resolves spacing tokens for dimension props and preserves raw strings', () => {
39
- const styles = resolveBoxStyles(mockTheme, 'base', {
40
- width: 'm',
41
- minHeight: 'l',
42
- maxWidth: '50%',
43
- });
44
- expect(styles.width).toBe(8);
45
- expect(styles.minHeight).toBe(16);
46
- expect(styles.maxWidth).toBe('50%');
47
- });
48
-
49
- test('handles undefined props gracefully', () => {
50
- const styles = resolveBoxStyles(mockTheme, 'base', {});
51
- expect(styles.padding).toBeUndefined();
52
- expect(styles.margin).toBeUndefined();
53
- });
54
- });