@onlynative/components 0.1.0-alpha.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 (87) hide show
  1. package/README.md +99 -0
  2. package/dist/appbar/index.d.ts +71 -0
  3. package/dist/appbar/index.js +952 -0
  4. package/dist/button/index.d.ts +41 -0
  5. package/dist/button/index.js +454 -0
  6. package/dist/card/index.d.ts +31 -0
  7. package/dist/card/index.js +264 -0
  8. package/dist/checkbox/index.d.ts +25 -0
  9. package/dist/checkbox/index.js +291 -0
  10. package/dist/chip/index.d.ts +62 -0
  11. package/dist/chip/index.js +452 -0
  12. package/dist/icon-button/index.d.ts +10 -0
  13. package/dist/icon-button/index.js +575 -0
  14. package/dist/index.d.ts +19 -0
  15. package/dist/index.js +3374 -0
  16. package/dist/layout/index.d.ts +98 -0
  17. package/dist/layout/index.js +282 -0
  18. package/dist/list/index.d.ts +60 -0
  19. package/dist/list/index.js +300 -0
  20. package/dist/radio/index.d.ts +25 -0
  21. package/dist/radio/index.js +250 -0
  22. package/dist/switch/index.d.ts +37 -0
  23. package/dist/switch/index.js +315 -0
  24. package/dist/text-field/index.d.ts +52 -0
  25. package/dist/text-field/index.js +496 -0
  26. package/dist/types-D3hlyvz-.d.ts +51 -0
  27. package/dist/typography/index.d.ts +28 -0
  28. package/dist/typography/index.js +69 -0
  29. package/package.json +166 -0
  30. package/src/appbar/AppBar.tsx +302 -0
  31. package/src/appbar/index.ts +2 -0
  32. package/src/appbar/styles.ts +92 -0
  33. package/src/appbar/types.ts +67 -0
  34. package/src/button/Button.tsx +130 -0
  35. package/src/button/index.ts +2 -0
  36. package/src/button/styles.ts +288 -0
  37. package/src/button/types.ts +42 -0
  38. package/src/card/Card.tsx +69 -0
  39. package/src/card/index.ts +2 -0
  40. package/src/card/styles.ts +151 -0
  41. package/src/card/types.ts +27 -0
  42. package/src/checkbox/Checkbox.tsx +109 -0
  43. package/src/checkbox/index.ts +2 -0
  44. package/src/checkbox/styles.ts +155 -0
  45. package/src/checkbox/types.ts +20 -0
  46. package/src/chip/Chip.tsx +182 -0
  47. package/src/chip/index.ts +2 -0
  48. package/src/chip/styles.ts +240 -0
  49. package/src/chip/types.ts +58 -0
  50. package/src/icon-button/IconButton.tsx +358 -0
  51. package/src/icon-button/index.ts +6 -0
  52. package/src/icon-button/styles.ts +259 -0
  53. package/src/icon-button/types.ts +55 -0
  54. package/src/index.ts +51 -0
  55. package/src/layout/Box.tsx +99 -0
  56. package/src/layout/Column.tsx +16 -0
  57. package/src/layout/Grid.tsx +49 -0
  58. package/src/layout/Layout.tsx +81 -0
  59. package/src/layout/Row.tsx +22 -0
  60. package/src/layout/index.ts +13 -0
  61. package/src/layout/resolveSpacing.ts +11 -0
  62. package/src/layout/types.ts +82 -0
  63. package/src/list/List.tsx +17 -0
  64. package/src/list/ListDivider.tsx +20 -0
  65. package/src/list/ListItem.tsx +128 -0
  66. package/src/list/index.ts +9 -0
  67. package/src/list/styles.ts +132 -0
  68. package/src/list/types.ts +54 -0
  69. package/src/radio/Radio.tsx +103 -0
  70. package/src/radio/index.ts +2 -0
  71. package/src/radio/styles.ts +139 -0
  72. package/src/radio/types.ts +20 -0
  73. package/src/switch/Switch.tsx +118 -0
  74. package/src/switch/index.ts +2 -0
  75. package/src/switch/styles.ts +172 -0
  76. package/src/switch/types.ts +32 -0
  77. package/src/test-utils/render-with-theme.tsx +13 -0
  78. package/src/text-field/TextField.tsx +298 -0
  79. package/src/text-field/index.ts +2 -0
  80. package/src/text-field/styles.ts +240 -0
  81. package/src/text-field/types.ts +49 -0
  82. package/src/typography/Typography.tsx +65 -0
  83. package/src/typography/index.ts +3 -0
  84. package/src/typography/types.ts +17 -0
  85. package/src/utils/color.ts +64 -0
  86. package/src/utils/elevation.ts +33 -0
  87. package/src/utils/rtl.ts +19 -0
@@ -0,0 +1,259 @@
1
+ import { StyleSheet } from 'react-native'
2
+ import type { Theme } from '@onlynative/core'
3
+ import { alphaColor, blendColor } from '../utils/color'
4
+
5
+ export function createStyles(theme: Theme) {
6
+ const disabledContainerColor = alphaColor(theme.colors.onSurface, 0.12)
7
+ const disabledOutlineColor = alphaColor(theme.colors.onSurface, 0.12)
8
+ const toggleUnselectedContainerColor = theme.colors.surfaceContainerHighest
9
+
10
+ return StyleSheet.create({
11
+ container: {
12
+ borderRadius: theme.shape.cornerFull,
13
+ alignItems: 'center',
14
+ justifyContent: 'center',
15
+ cursor: 'pointer',
16
+ },
17
+ sizeSmall: {
18
+ width: 32,
19
+ height: 32,
20
+ },
21
+ sizeMedium: {
22
+ width: 40,
23
+ height: 40,
24
+ },
25
+ sizeLarge: {
26
+ width: 48,
27
+ height: 48,
28
+ },
29
+ colorFilled: {
30
+ backgroundColor: theme.colors.primary,
31
+ borderColor: theme.colors.primary,
32
+ borderWidth: 0,
33
+ },
34
+ colorFilledToggleUnselected: {
35
+ backgroundColor: toggleUnselectedContainerColor,
36
+ borderColor: toggleUnselectedContainerColor,
37
+ borderWidth: 0,
38
+ },
39
+ colorFilledToggleSelected: {
40
+ backgroundColor: theme.colors.primary,
41
+ borderColor: theme.colors.primary,
42
+ borderWidth: 0,
43
+ },
44
+ colorTonal: {
45
+ backgroundColor: theme.colors.secondaryContainer,
46
+ borderColor: theme.colors.secondaryContainer,
47
+ borderWidth: 0,
48
+ },
49
+ colorTonalToggleUnselected: {
50
+ backgroundColor: toggleUnselectedContainerColor,
51
+ borderColor: toggleUnselectedContainerColor,
52
+ borderWidth: 0,
53
+ },
54
+ colorTonalToggleSelected: {
55
+ backgroundColor: theme.colors.secondaryContainer,
56
+ borderColor: theme.colors.secondaryContainer,
57
+ borderWidth: 0,
58
+ },
59
+ colorOutlined: {
60
+ borderColor: theme.colors.outline,
61
+ borderWidth: 1,
62
+ },
63
+ colorOutlinedToggleSelected: {
64
+ backgroundColor: theme.colors.inverseSurface,
65
+ borderColor: theme.colors.inverseSurface,
66
+ borderWidth: 0,
67
+ },
68
+ colorStandard: {
69
+ borderWidth: 0,
70
+ },
71
+ colorStandardToggleSelected: {
72
+ borderWidth: 0,
73
+ },
74
+
75
+ // Hover states (M3: 8% state layer)
76
+ hoveredFilled: {
77
+ backgroundColor: blendColor(
78
+ theme.colors.primary,
79
+ theme.colors.onPrimary,
80
+ theme.stateLayer.hoveredOpacity,
81
+ ),
82
+ },
83
+ hoveredFilledToggleUnselected: {
84
+ backgroundColor: blendColor(
85
+ toggleUnselectedContainerColor,
86
+ theme.colors.primary,
87
+ theme.stateLayer.hoveredOpacity,
88
+ ),
89
+ },
90
+ hoveredFilledToggleSelected: {
91
+ backgroundColor: blendColor(
92
+ theme.colors.primary,
93
+ theme.colors.onPrimary,
94
+ theme.stateLayer.hoveredOpacity,
95
+ ),
96
+ },
97
+ hoveredTonal: {
98
+ backgroundColor: blendColor(
99
+ theme.colors.secondaryContainer,
100
+ theme.colors.onSecondaryContainer,
101
+ theme.stateLayer.hoveredOpacity,
102
+ ),
103
+ },
104
+ hoveredTonalToggleUnselected: {
105
+ backgroundColor: blendColor(
106
+ toggleUnselectedContainerColor,
107
+ theme.colors.onSurfaceVariant,
108
+ theme.stateLayer.hoveredOpacity,
109
+ ),
110
+ },
111
+ hoveredTonalToggleSelected: {
112
+ backgroundColor: blendColor(
113
+ theme.colors.secondaryContainer,
114
+ theme.colors.onSecondaryContainer,
115
+ theme.stateLayer.hoveredOpacity,
116
+ ),
117
+ },
118
+ hoveredOutlined: {
119
+ backgroundColor: alphaColor(
120
+ theme.colors.onSurfaceVariant,
121
+ theme.stateLayer.hoveredOpacity,
122
+ ),
123
+ },
124
+ hoveredOutlinedToggleUnselected: {
125
+ backgroundColor: alphaColor(
126
+ theme.colors.onSurfaceVariant,
127
+ theme.stateLayer.hoveredOpacity,
128
+ ),
129
+ },
130
+ hoveredOutlinedToggleSelected: {
131
+ backgroundColor: blendColor(
132
+ theme.colors.inverseSurface,
133
+ theme.colors.inverseOnSurface,
134
+ theme.stateLayer.hoveredOpacity,
135
+ ),
136
+ },
137
+ hoveredStandard: {
138
+ backgroundColor: alphaColor(
139
+ theme.colors.onSurfaceVariant,
140
+ theme.stateLayer.hoveredOpacity,
141
+ ),
142
+ },
143
+ hoveredStandardToggleUnselected: {
144
+ backgroundColor: alphaColor(
145
+ theme.colors.onSurfaceVariant,
146
+ theme.stateLayer.hoveredOpacity,
147
+ ),
148
+ },
149
+ hoveredStandardToggleSelected: {
150
+ backgroundColor: alphaColor(
151
+ theme.colors.primary,
152
+ theme.stateLayer.hoveredOpacity,
153
+ ),
154
+ },
155
+
156
+ // Pressed states (M3: 12% state layer)
157
+ pressedFilled: {
158
+ backgroundColor: blendColor(
159
+ theme.colors.primary,
160
+ theme.colors.onPrimary,
161
+ theme.stateLayer.pressedOpacity,
162
+ ),
163
+ },
164
+ pressedFilledToggleUnselected: {
165
+ backgroundColor: blendColor(
166
+ toggleUnselectedContainerColor,
167
+ theme.colors.primary,
168
+ theme.stateLayer.pressedOpacity,
169
+ ),
170
+ },
171
+ pressedFilledToggleSelected: {
172
+ backgroundColor: blendColor(
173
+ theme.colors.primary,
174
+ theme.colors.onPrimary,
175
+ theme.stateLayer.pressedOpacity,
176
+ ),
177
+ },
178
+ pressedTonal: {
179
+ backgroundColor: blendColor(
180
+ theme.colors.secondaryContainer,
181
+ theme.colors.onSecondaryContainer,
182
+ theme.stateLayer.pressedOpacity,
183
+ ),
184
+ },
185
+ pressedTonalToggleUnselected: {
186
+ backgroundColor: blendColor(
187
+ toggleUnselectedContainerColor,
188
+ theme.colors.onSurfaceVariant,
189
+ theme.stateLayer.pressedOpacity,
190
+ ),
191
+ },
192
+ pressedTonalToggleSelected: {
193
+ backgroundColor: blendColor(
194
+ theme.colors.secondaryContainer,
195
+ theme.colors.onSecondaryContainer,
196
+ theme.stateLayer.pressedOpacity,
197
+ ),
198
+ },
199
+ pressedOutlined: {
200
+ backgroundColor: alphaColor(
201
+ theme.colors.onSurfaceVariant,
202
+ theme.stateLayer.pressedOpacity,
203
+ ),
204
+ },
205
+ pressedOutlinedToggleUnselected: {
206
+ backgroundColor: alphaColor(
207
+ theme.colors.onSurfaceVariant,
208
+ theme.stateLayer.pressedOpacity,
209
+ ),
210
+ },
211
+ pressedOutlinedToggleSelected: {
212
+ backgroundColor: blendColor(
213
+ theme.colors.inverseSurface,
214
+ theme.colors.inverseOnSurface,
215
+ theme.stateLayer.pressedOpacity,
216
+ ),
217
+ },
218
+ pressedStandard: {
219
+ backgroundColor: alphaColor(
220
+ theme.colors.onSurfaceVariant,
221
+ theme.stateLayer.pressedOpacity,
222
+ ),
223
+ },
224
+ pressedStandardToggleUnselected: {
225
+ backgroundColor: alphaColor(
226
+ theme.colors.onSurfaceVariant,
227
+ theme.stateLayer.pressedOpacity,
228
+ ),
229
+ },
230
+ pressedStandardToggleSelected: {
231
+ backgroundColor: alphaColor(
232
+ theme.colors.primary,
233
+ theme.stateLayer.pressedOpacity,
234
+ ),
235
+ },
236
+
237
+ // Disabled states
238
+ disabledFilled: {
239
+ backgroundColor: disabledContainerColor,
240
+ borderColor: disabledContainerColor,
241
+ cursor: 'auto',
242
+ },
243
+ disabledTonal: {
244
+ backgroundColor: disabledContainerColor,
245
+ borderColor: disabledContainerColor,
246
+ cursor: 'auto',
247
+ },
248
+ disabledOutlined: {
249
+ backgroundColor: 'transparent',
250
+ borderColor: disabledOutlineColor,
251
+ cursor: 'auto',
252
+ },
253
+ disabledStandard: {
254
+ backgroundColor: 'transparent',
255
+ borderColor: 'transparent',
256
+ cursor: 'auto',
257
+ },
258
+ })
259
+ }
@@ -0,0 +1,55 @@
1
+ import type MaterialCommunityIcons from '@expo/vector-icons/MaterialCommunityIcons'
2
+ import type { ComponentProps } from 'react'
3
+ import type { PressableProps } from 'react-native'
4
+
5
+ /** Visual fill style of the icon button. */
6
+ export type IconButtonVariant = 'filled' | 'tonal' | 'outlined' | 'standard'
7
+
8
+ /** Touch target size of the icon button. */
9
+ export type IconButtonSize = 'small' | 'medium' | 'large'
10
+
11
+ export interface IconButtonProps
12
+ extends Omit<
13
+ PressableProps,
14
+ 'children' | 'onPress' | 'style' | 'accessibilityLabel'
15
+ > {
16
+ /** MaterialCommunityIcons icon name to display. */
17
+ icon: ComponentProps<typeof MaterialCommunityIcons>['name']
18
+ /** Icon to display when `selected` is `true` (toggle mode). */
19
+ selectedIcon?: ComponentProps<typeof MaterialCommunityIcons>['name']
20
+ /** Overrides the automatic icon color derived from the variant and state. */
21
+ iconColor?: string
22
+ /**
23
+ * Override the content (icon) color.
24
+ * Takes precedence over `iconColor` when both are provided.
25
+ */
26
+ contentColor?: string
27
+ /**
28
+ * Override the container (background) color.
29
+ * State-layer colors (hover, press) are derived automatically.
30
+ */
31
+ containerColor?: string
32
+ /** Custom style applied to the root container. */
33
+ style?: PressableProps['style']
34
+ /** Called when the button is pressed. */
35
+ onPress?: () => void
36
+ /**
37
+ * Disables the button.
38
+ * @default false
39
+ */
40
+ disabled?: boolean
41
+ /**
42
+ * Visual style variant.
43
+ * @default 'filled'
44
+ */
45
+ variant?: IconButtonVariant
46
+ /** Enables toggle mode. The button changes appearance based on selected/unselected state. */
47
+ selected?: boolean
48
+ /**
49
+ * Physical size of the touch target and icon container.
50
+ * @default 'medium'
51
+ */
52
+ size?: IconButtonSize
53
+ /** Required — icon-only buttons must have a label for screen readers. */
54
+ accessibilityLabel: string
55
+ }
package/src/index.ts ADDED
@@ -0,0 +1,51 @@
1
+ export { Typography } from './typography'
2
+ export type { TypographyProps, TypographyVariant } from './typography'
3
+
4
+ export { Layout, Box, Column, Grid, Row } from './layout'
5
+ export type {
6
+ LayoutProps,
7
+ BoxProps,
8
+ ColumnProps,
9
+ GridProps,
10
+ RowProps,
11
+ SpacingValue,
12
+ } from './layout'
13
+
14
+ export { Button } from './button'
15
+ export type { ButtonProps, ButtonVariant } from './button'
16
+
17
+ export { IconButton } from './icon-button'
18
+ export type {
19
+ IconButtonProps,
20
+ IconButtonSize,
21
+ IconButtonVariant,
22
+ } from './icon-button'
23
+
24
+ export { AppBar } from './appbar'
25
+ export type { AppBarAction, AppBarProps, AppBarVariant } from './appbar'
26
+
27
+ export { Card } from './card'
28
+ export type { CardProps, CardVariant } from './card'
29
+
30
+ export { Chip } from './chip'
31
+ export type { ChipProps, ChipVariant } from './chip'
32
+
33
+ export { Checkbox } from './checkbox'
34
+ export type { CheckboxProps } from './checkbox'
35
+
36
+ export { Radio } from './radio'
37
+ export type { RadioProps } from './radio'
38
+
39
+ export { Switch } from './switch'
40
+ export type { SwitchProps } from './switch'
41
+
42
+ export { TextField } from './text-field'
43
+ export type { TextFieldProps, TextFieldVariant } from './text-field'
44
+
45
+ export { List, ListItem, ListDivider } from './list'
46
+ export type {
47
+ ListProps,
48
+ ListItemLines,
49
+ ListItemProps,
50
+ ListDividerProps,
51
+ } from './list'
@@ -0,0 +1,99 @@
1
+ import { useMemo } from 'react'
2
+ import type { ViewStyle } from 'react-native'
3
+ import { View } from 'react-native'
4
+ import { useTheme } from '@onlynative/core'
5
+
6
+ import type { BoxProps, SpacingValue } from './types'
7
+ import { resolveSpacing } from './resolveSpacing'
8
+
9
+ export function Box({
10
+ p,
11
+ px,
12
+ py,
13
+ pt,
14
+ pb,
15
+ ps,
16
+ pe,
17
+ m,
18
+ mx,
19
+ my,
20
+ mt,
21
+ mb,
22
+ ms,
23
+ me,
24
+ gap,
25
+ rowGap,
26
+ columnGap,
27
+ flex,
28
+ align,
29
+ justify,
30
+ bg,
31
+ style,
32
+ ...viewProps
33
+ }: BoxProps) {
34
+ const { spacing } = useTheme()
35
+
36
+ const layoutStyle = useMemo<ViewStyle>(() => {
37
+ const s = (v: SpacingValue | undefined) => resolveSpacing(spacing, v)
38
+ return {
39
+ ...(p !== undefined && { padding: s(p) }),
40
+ ...(px !== undefined && {
41
+ paddingStart: s(px),
42
+ paddingEnd: s(px),
43
+ }),
44
+ ...(py !== undefined && {
45
+ paddingTop: s(py),
46
+ paddingBottom: s(py),
47
+ }),
48
+ ...(pt !== undefined && { paddingTop: s(pt) }),
49
+ ...(pb !== undefined && { paddingBottom: s(pb) }),
50
+ ...(ps !== undefined && { paddingStart: s(ps) }),
51
+ ...(pe !== undefined && { paddingEnd: s(pe) }),
52
+ ...(m !== undefined && { margin: s(m) }),
53
+ ...(mx !== undefined && {
54
+ marginStart: s(mx),
55
+ marginEnd: s(mx),
56
+ }),
57
+ ...(my !== undefined && {
58
+ marginTop: s(my),
59
+ marginBottom: s(my),
60
+ }),
61
+ ...(mt !== undefined && { marginTop: s(mt) }),
62
+ ...(mb !== undefined && { marginBottom: s(mb) }),
63
+ ...(ms !== undefined && { marginStart: s(ms) }),
64
+ ...(me !== undefined && { marginEnd: s(me) }),
65
+ ...(gap !== undefined && { gap: s(gap) }),
66
+ ...(rowGap !== undefined && { rowGap: s(rowGap) }),
67
+ ...(columnGap !== undefined && { columnGap: s(columnGap) }),
68
+ ...(flex !== undefined && { flex }),
69
+ ...(align !== undefined && { alignItems: align }),
70
+ ...(justify !== undefined && { justifyContent: justify }),
71
+ ...(bg !== undefined && { backgroundColor: bg }),
72
+ }
73
+ }, [
74
+ spacing,
75
+ p,
76
+ px,
77
+ py,
78
+ pt,
79
+ pb,
80
+ ps,
81
+ pe,
82
+ m,
83
+ mx,
84
+ my,
85
+ mt,
86
+ mb,
87
+ ms,
88
+ me,
89
+ gap,
90
+ rowGap,
91
+ columnGap,
92
+ flex,
93
+ align,
94
+ justify,
95
+ bg,
96
+ ])
97
+
98
+ return <View {...viewProps} style={[layoutStyle, style]} />
99
+ }
@@ -0,0 +1,16 @@
1
+ import { useMemo } from 'react'
2
+ import type { ViewStyle } from 'react-native'
3
+
4
+ import { Box } from './Box'
5
+ import type { ColumnProps } from './types'
6
+
7
+ export function Column({ inverted = false, style, ...boxProps }: ColumnProps) {
8
+ const directionStyle = useMemo<ViewStyle>(
9
+ () => ({
10
+ flexDirection: inverted ? 'column-reverse' : 'column',
11
+ }),
12
+ [inverted],
13
+ )
14
+
15
+ return <Box {...boxProps} style={[directionStyle, style]} />
16
+ }
@@ -0,0 +1,49 @@
1
+ import React, { useMemo } from 'react'
2
+ import type { ViewStyle } from 'react-native'
3
+ import { View } from 'react-native'
4
+ import { useTheme } from '@onlynative/core'
5
+
6
+ import { Row } from './Row'
7
+ import { resolveSpacing } from './resolveSpacing'
8
+ import type { GridProps } from './types'
9
+
10
+ export function Grid({
11
+ columns,
12
+ gap,
13
+ columnGap,
14
+ rowGap,
15
+ children,
16
+ style,
17
+ ...rowProps
18
+ }: GridProps) {
19
+ const { spacing } = useTheme()
20
+ const resolvedColumnGap = resolveSpacing(spacing, columnGap ?? gap)
21
+ const resolvedRowGap = resolveSpacing(spacing, rowGap ?? gap)
22
+ const halfGap = resolvedColumnGap ? resolvedColumnGap / 2 : 0
23
+
24
+ const cellStyle = useMemo<ViewStyle>(
25
+ () => ({
26
+ flexBasis: `${100 / columns}%` as unknown as number,
27
+ flexShrink: 1,
28
+ paddingLeft: halfGap,
29
+ paddingRight: halfGap,
30
+ }),
31
+ [columns, halfGap],
32
+ )
33
+
34
+ const rowStyle = useMemo<ViewStyle>(
35
+ () => ({
36
+ marginLeft: -halfGap,
37
+ marginRight: -halfGap,
38
+ }),
39
+ [halfGap],
40
+ )
41
+
42
+ return (
43
+ <Row wrap rowGap={resolvedRowGap} {...rowProps} style={[rowStyle, style]}>
44
+ {React.Children.map(children, (child) =>
45
+ child != null ? <View style={cellStyle}>{child}</View> : null,
46
+ )}
47
+ </Row>
48
+ )
49
+ }
@@ -0,0 +1,81 @@
1
+ import { useMemo } from 'react'
2
+ import type { PropsWithChildren } from 'react'
3
+ import type { StyleProp, ViewStyle } from 'react-native'
4
+ import { StyleSheet } from 'react-native'
5
+ import { SafeAreaView } from 'react-native-safe-area-context'
6
+ import type { Edge } from 'react-native-safe-area-context'
7
+ import { useTheme } from '@onlynative/core'
8
+
9
+ export interface LayoutProps extends PropsWithChildren {
10
+ /**
11
+ * When `true`, removes all safe area insets for full-screen layout.
12
+ * @default false
13
+ */
14
+ immersive?: boolean
15
+ /** Explicit set of safe-area edges to apply. Overrides `immersive` when provided. */
16
+ edges?: Edge[]
17
+ /** Additional styles applied to the SafeAreaView container. */
18
+ style?: StyleProp<ViewStyle>
19
+ }
20
+
21
+ const defaultEdges: Edge[] = ['bottom']
22
+
23
+ function resolveEdges(immersive?: boolean, edges?: Edge[]): Edge[] {
24
+ if (edges) {
25
+ return edges
26
+ }
27
+
28
+ if (immersive) {
29
+ return []
30
+ }
31
+
32
+ return defaultEdges
33
+ }
34
+
35
+ const styles = StyleSheet.create({
36
+ root: {
37
+ flex: 1,
38
+ },
39
+ })
40
+
41
+ function removeBackgroundColor(style?: StyleProp<ViewStyle>) {
42
+ if (!style) {
43
+ return undefined
44
+ }
45
+
46
+ const flattenedStyle = StyleSheet.flatten(style)
47
+
48
+ if (!flattenedStyle || flattenedStyle.backgroundColor === undefined) {
49
+ return style
50
+ }
51
+
52
+ const styleWithoutBackground = { ...flattenedStyle }
53
+ delete styleWithoutBackground.backgroundColor
54
+
55
+ return styleWithoutBackground
56
+ }
57
+
58
+ export function Layout({ immersive, edges, children, style }: LayoutProps) {
59
+ const theme = useTheme()
60
+ const themeBackgroundStyle = useMemo(
61
+ () => ({ backgroundColor: theme.colors.background }),
62
+ [theme.colors.background],
63
+ )
64
+ const styleWithoutBackground = useMemo(
65
+ () => removeBackgroundColor(style),
66
+ [style],
67
+ )
68
+ const safeAreaEdges = useMemo(
69
+ () => resolveEdges(immersive, edges),
70
+ [immersive, edges],
71
+ )
72
+
73
+ return (
74
+ <SafeAreaView
75
+ style={[styles.root, themeBackgroundStyle, styleWithoutBackground]}
76
+ edges={safeAreaEdges}
77
+ >
78
+ {children}
79
+ </SafeAreaView>
80
+ )
81
+ }
@@ -0,0 +1,22 @@
1
+ import { useMemo } from 'react'
2
+ import type { ViewStyle } from 'react-native'
3
+
4
+ import { Box } from './Box'
5
+ import type { RowProps } from './types'
6
+
7
+ export function Row({
8
+ wrap = false,
9
+ inverted = false,
10
+ style,
11
+ ...boxProps
12
+ }: RowProps) {
13
+ const directionStyle = useMemo<ViewStyle>(
14
+ () => ({
15
+ flexDirection: inverted ? 'row-reverse' : 'row',
16
+ ...(wrap && { flexWrap: 'wrap' }),
17
+ }),
18
+ [wrap, inverted],
19
+ )
20
+
21
+ return <Box {...boxProps} style={[directionStyle, style]} />
22
+ }
@@ -0,0 +1,13 @@
1
+ export { Layout } from './Layout'
2
+ export type { LayoutProps } from './Layout'
3
+ export { Box } from './Box'
4
+ export { Column } from './Column'
5
+ export { Grid } from './Grid'
6
+ export { Row } from './Row'
7
+ export type {
8
+ BoxProps,
9
+ ColumnProps,
10
+ GridProps,
11
+ RowProps,
12
+ SpacingValue,
13
+ } from './types'
@@ -0,0 +1,11 @@
1
+ import type { Theme } from '@onlynative/core'
2
+ import type { SpacingValue } from './types'
3
+
4
+ export function resolveSpacing(
5
+ spacing: Theme['spacing'],
6
+ value: SpacingValue | undefined,
7
+ ): number | undefined {
8
+ if (value === undefined) return undefined
9
+ if (typeof value === 'number') return value
10
+ return spacing[value]
11
+ }