radix-native-ui 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.
package/README.md ADDED
@@ -0,0 +1,352 @@
1
+ # radix-native-ui
2
+
3
+ Radix Themes for React Native and Expo. A port of the popular `radix-native-ui` component library to support mobile development with React Native.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install radix-native-ui
9
+ # or
10
+ yarn add radix-native-ui
11
+ # or
12
+ pnpm add radix-native-ui
13
+ ```
14
+
15
+ ## Peer Dependencies
16
+
17
+ This package requires the following peer dependencies:
18
+
19
+ - `react` >= 18
20
+ - `react-native` >= 0.70
21
+ - `@radix-ui/react-slot` >= 1.0.0
22
+ - `react-native-safe-area-context` >= 4.0.0 (optional, for safe area support)
23
+
24
+ ## Usage
25
+
26
+ ### Basic Setup
27
+
28
+ Wrap your app with the ThemeProvider to enable theming:
29
+
30
+ ```tsx
31
+ import { ThemeProvider, useTheme, useThemeMode, useThemeActions } from 'radix-native-ui';
32
+
33
+ export default function App() {
34
+ return (
35
+ <ThemeProvider>
36
+ {/* Your app content */}
37
+ </ThemeProvider>
38
+ );
39
+ }
40
+ ```
41
+
42
+ ### Theme Provider Options
43
+
44
+ ```tsx
45
+ <ThemeProvider
46
+ mode="light" // 'light' | 'dark' | undefined (follows device)
47
+ forcedMode="dark" // Force specific mode (overrides device settings)
48
+ themeOptions={{}} // Customize theme colors, typography, etc.
49
+ onModeChange={(mode) => console.log('Theme mode changed:', mode)}
50
+ >
51
+ {children}
52
+ </ThemeProvider>
53
+ ```
54
+
55
+ ### Using Theme in Components
56
+
57
+ Access theme values using the `useTheme` hook:
58
+
59
+ ```tsx
60
+ import { useTheme, useThemeMode, useThemeActions } from 'radix-native-ui';
61
+
62
+ function MyComponent() {
63
+ const theme = useTheme();
64
+ const mode = useThemeMode();
65
+ const { setMode, toggleMode } = useThemeActions();
66
+
67
+ // Access theme values
68
+ const colors = mode === 'dark' ? theme.colors.gray.dark : theme.colors.gray;
69
+ const spacing = theme.space[4];
70
+ const radii = theme.radii[2];
71
+
72
+ return (
73
+ <View style={{ backgroundColor: colors[1], padding: spacing }}>
74
+ <Text style={{ color: colors[12] }}>Current mode: {mode}</Text>
75
+ <Button onPress={toggleMode}>Toggle Theme</Button>
76
+ </View>
77
+ );
78
+ }
79
+ ```
80
+
81
+ ## Available Components
82
+
83
+ ### Layout Components
84
+
85
+ - **Box** - Primitive container component with styling props
86
+ - **Flex** - Flexbox layout component
87
+ - **Grid** - CSS Grid layout component
88
+ - **Container** - Responsive container with max-width
89
+ - **Inset** - Padding component for consistent spacing
90
+
91
+ ### Typography Components
92
+
93
+ - **Text** - Versatile text component with size, weight, color props
94
+ - **Heading** - Semantic heading component (h1-h5)
95
+ - **Strong** - Bold text
96
+ - **Em** - Italic text
97
+ - **Code** - Inline code styling
98
+ - **Kbd** - Keyboard shortcut styling
99
+ - **Blockquote** - Quote block styling
100
+ - **Link** - Pressable link component
101
+
102
+ ### Form Components
103
+
104
+ - **Button** - Interactive button with variants (classic, solid, soft, outline, ghost)
105
+ - **IconButton** - Button with icon support
106
+ - **TextField** - Text input component
107
+ - **TextArea** - Multi-line text input
108
+ - **Switch** - Toggle switch component
109
+ - **Radio** - Radio button component
110
+ - **RadioGroup** - Group of radio buttons
111
+ - **Select** - Dropdown select component
112
+
113
+ ### Data Display Components
114
+
115
+ - **Avatar** - User avatar with image support
116
+ - **Badge** - Status badge component
117
+ - **Card** - Card container component
118
+ - **Table** - Data table component
119
+ - **DataList** - Key-value list component
120
+ - **Spinner** - Loading indicator
121
+ - **Progress** - Progress bar component
122
+
123
+ ### Navigation Components
124
+
125
+ - **Tabs** - Tab navigation component
126
+ - **TabNav** - Tab navigation with router support
127
+ - **SegmentedControl** - iOS-style segmented control
128
+
129
+ ### Overlay Components
130
+
131
+ - **Dialog** - Modal dialog component
132
+ - **AlertDialog** - Confirmation dialog
133
+ - **Popover** - Popover tooltip component
134
+ - **Tooltip** - Tooltip component
135
+ - **DropdownMenu** - Dropdown menu component
136
+ - **ContextMenu** - Context menu component
137
+ - **Portal** - Render content outside component hierarchy
138
+
139
+ ## Example: Button Component
140
+
141
+ ```tsx
142
+ import { Button } from 'radix-native-ui';
143
+
144
+ // Variants
145
+ <Button>Default (Classic)</Button>
146
+ <Button variant="solid">Solid</Button>
147
+ <Button variant="soft">Soft</Button>
148
+ <Button variant="outline">Outline</Button>
149
+ <Button variant="ghost">Ghost</Button>
150
+
151
+ // Sizes
152
+ <Button size={1}>Small</Button>
153
+ <Button size={2}>Medium (Default)</Button>
154
+ <Button size={3}>Large</Button>
155
+
156
+ // States
157
+ <Button disabled>Disabled</Button>
158
+ <Button loading>Loading...</Button>
159
+
160
+ // With onPress
161
+ <Button onPress={() => console.log('Pressed!')}>Click Me</Button>
162
+
163
+ // High contrast for accessibility
164
+ <Button highContrast>High Contrast</Button>
165
+ ```
166
+
167
+ ## Example: Text and Typography
168
+
169
+ ```tsx
170
+ import { Text, Heading, Code, Kbd } from 'radix-native-ui';
171
+
172
+ // Text with size
173
+ <Text size={1}>Small text</Text>
174
+ <Text size={3}>Regular text (default)</Text>
175
+ <Text size={5}>Large text</Text>
176
+
177
+ // Text with weight
178
+ <Text weight="light">Light</Text>
179
+ <Text weight="regular">Regular</Text>
180
+ <Text weight="medium">Medium</Text>
181
+ <Text weight="bold">Bold</Text>
182
+
183
+ // Heading
184
+ <Heading size={1}>H1 Heading</Heading>
185
+ <Heading size={3}>H3 Heading</Heading>
186
+ <Heading size={5}>H5 Heading</Heading>
187
+
188
+ // Code and Kbd
189
+ <Code>const value = 42;</Code>
190
+ <Kbd>Cmd + C</Kbd>
191
+ ```
192
+
193
+ ## Example: Layout with Box and Flex
194
+
195
+ ```tsx
196
+ import { Box, Flex, Grid, Container } from 'radix-native-ui';
197
+
198
+ // Box with styling
199
+ <Box backgroundColor="gray.2" padding={4} borderRadius={2}>
200
+ <Text>Content</Text>
201
+ </Box>
202
+
203
+ // Flex layout
204
+ <Flex direction="row" align="center" justify="between" gap={2}>
205
+ <Text>Left</Text>
206
+ <Text>Right</Text>
207
+ </Flex>
208
+
209
+ // Grid layout
210
+ <Grid columns={3} gap={4}>
211
+ <Box>Item 1</Box>
212
+ <Box>Item 2</Box>
213
+ <Box>Item 3</Box>
214
+ </Grid>
215
+
216
+ // Responsive container
217
+ <Container size={3} responsive>
218
+ <Text>Centered content with max-width</Text>
219
+ </Container>
220
+ ```
221
+
222
+ ## Theming Guide
223
+
224
+ ### Custom Theme Options
225
+
226
+ ```tsx
227
+ <ThemeProvider
228
+ themeOptions={{
229
+ accentColor: '#6366f1', // Custom accent color
230
+ grayColor: '#78716c', // Custom gray scale
231
+ fonts: {
232
+ heading: { // Custom heading font
233
+ fontFamily: 'YourFont-Bold',
234
+ fontWeight: '700',
235
+ },
236
+ body: { // Custom body font
237
+ fontFamily: 'YourFont-Regular',
238
+ fontWeight: '400',
239
+ },
240
+ },
241
+ }}
242
+ >
243
+ {children}
244
+ </ThemeProvider>
245
+ ```
246
+
247
+ ### Theme Colors
248
+
249
+ The theme provides a comprehensive color palette:
250
+
251
+ ```tsx
252
+ const colors = {
253
+ gray: {
254
+ light: ['#fafafa', '#f5f5f5', '#e5e5e5', '#d4d4d4', '#a3a3a3', '#737373', '#525252', '#404040', '#262626', '#171717', '#0a0a0a'],
255
+ dark: ['#0a0a0a', '#171717', '#262626', '#404040', '#525252', '#737373', '#a3a3a3', '#d4d4d4', '#e5e5f5', '#f5f5f5', '#fafafa'],
256
+ },
257
+ // ... more colors
258
+ };
259
+ ```
260
+
261
+ ### Theme Spacing
262
+
263
+ ```tsx
264
+ const spacing = theme.space; // [0, 4, 8, 12, 16, 20, 24, 32, 40, 48, 64, 80, 96, 128]
265
+ ```
266
+
267
+ ### Theme Typography
268
+
269
+ ```tsx
270
+ const typography = {
271
+ fontSizes: {
272
+ 1: { fontSize: 11, lineHeight: 16, letterSpacing: 0.5 },
273
+ 2: { fontSize: 12, lineHeight: 18, letterSpacing: 0.5 },
274
+ 3: { fontSize: 14, lineHeight: 20, letterSpacing: 0.25 },
275
+ // ... more sizes
276
+ },
277
+ fontWeights: {
278
+ light: '300',
279
+ regular: '400',
280
+ medium: '500',
281
+ bold: '700',
282
+ },
283
+ };
284
+ ```
285
+
286
+ ## Migration Guide from Web Radix Themes
287
+
288
+ ### Key Differences
289
+
290
+ 1. **No CSS-in-JS** - React Native uses StyleSheet instead of CSS
291
+ 2. **Box Model** - Use `padding` and `margin` props instead of CSS shorthand
292
+ 3. **Colors** - Color scales are arrays, not CSS variables
293
+ 4. **Responsive** - Media queries work differently in React Native
294
+
295
+ ### Web to Native Mapping
296
+
297
+ ```tsx
298
+ // Web Radix Themes
299
+ <Box css={{ p: '$4', bg: '$gray2' }} />
300
+
301
+ // React Native (our package)
302
+ <Box padding={4} backgroundColor="gray.2" />
303
+ ```
304
+
305
+ ### Common Props Mapping
306
+
307
+ | Web CSS | React Native |
308
+ |---------|-------------|
309
+ | `display: flex` | `display="flex"` |
310
+ | `flexDirection: row` | `flexDirection="row"` |
311
+ | `justifyContent: center` | `justifyContent="center"` |
312
+ | `alignItems: center` | `alignItems="center"` |
313
+ | `gap: 16` | `gap={4}` (uses theme scale) |
314
+ | `padding: 20` | `padding={5}` (uses theme scale) |
315
+ | `backgroundColor: #fff` | `backgroundColor="#ffffff"` or `backgroundColor="gray.1"` |
316
+
317
+ ### Event Handlers
318
+
319
+ ```tsx
320
+ // Web: onClick
321
+ <Button onClick={handleClick} />
322
+
323
+ // React Native: onPress
324
+ <Button onPress={handlePress} />
325
+ ```
326
+
327
+ ## Testing
328
+
329
+ This package includes Jest configuration for testing:
330
+
331
+ ```bash
332
+ # Run tests
333
+ npm test
334
+
335
+ # Run tests with coverage
336
+ npm test -- --coverage
337
+
338
+ # Run specific test file
339
+ npm test -- Box.test.tsx
340
+ ```
341
+
342
+ ## Performance
343
+
344
+ All components are optimized with React.memo() and useMemo/useCallback hooks to minimize unnecessary re-renders. Custom areEqual functions are provided for complex components to ensure optimal performance.
345
+
346
+ ## Contributing
347
+
348
+ Contributions are welcome! Please read our contributing guidelines in the main repository.
349
+
350
+ ## License
351
+
352
+ MIT