@entropix/react-native 0.1.0 → 0.1.1
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 +354 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
# @entropix/react-native
|
|
2
|
+
|
|
3
|
+
React Native components for the Entropix design system — iOS and Android with shared headless core and built-in theming.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@entropix/react-native)
|
|
6
|
+
[](https://github.com/dev-manindepth/entropix/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @entropix/react-native @entropix/tokens
|
|
12
|
+
# or
|
|
13
|
+
pnpm add @entropix/react-native @entropix/tokens
|
|
14
|
+
# or
|
|
15
|
+
yarn add @entropix/react-native @entropix/tokens
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
**Peer dependencies:** `react` (^18 or ^19) and `react-native` (>=0.72).
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
**1. Wrap your app with `EntropixProvider`:**
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { EntropixProvider } from "@entropix/react-native";
|
|
26
|
+
|
|
27
|
+
export default function App() {
|
|
28
|
+
return (
|
|
29
|
+
<EntropixProvider mode="light">
|
|
30
|
+
<HomeScreen />
|
|
31
|
+
</EntropixProvider>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
**2. Use components:**
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
import {
|
|
40
|
+
Button,
|
|
41
|
+
Toggle,
|
|
42
|
+
Switch,
|
|
43
|
+
Tabs,
|
|
44
|
+
TabList,
|
|
45
|
+
Tab,
|
|
46
|
+
TabPanel,
|
|
47
|
+
Stack,
|
|
48
|
+
Container,
|
|
49
|
+
} from "@entropix/react-native";
|
|
50
|
+
|
|
51
|
+
function HomeScreen() {
|
|
52
|
+
return (
|
|
53
|
+
<Container maxWidth="md" center>
|
|
54
|
+
<Stack gap="md">
|
|
55
|
+
<Button variant="primary" size="md" onPress={() => alert("Pressed!")}>
|
|
56
|
+
Get Started
|
|
57
|
+
</Button>
|
|
58
|
+
|
|
59
|
+
<Toggle onChange={(checked) => console.log(checked)} label="Notifications" />
|
|
60
|
+
|
|
61
|
+
<Switch onChange={(on) => console.log(on)} label="Dark mode" />
|
|
62
|
+
|
|
63
|
+
<Tabs defaultSelectedKey="tab1">
|
|
64
|
+
<TabList>
|
|
65
|
+
<Tab value="tab1">Overview</Tab>
|
|
66
|
+
<Tab value="tab2">Details</Tab>
|
|
67
|
+
</TabList>
|
|
68
|
+
<TabPanel value="tab1">Overview content</TabPanel>
|
|
69
|
+
<TabPanel value="tab2">Details content</TabPanel>
|
|
70
|
+
</Tabs>
|
|
71
|
+
</Stack>
|
|
72
|
+
</Container>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Theme Provider
|
|
78
|
+
|
|
79
|
+
### EntropixProvider
|
|
80
|
+
|
|
81
|
+
Wraps your app to provide theme tokens to all components.
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
<EntropixProvider mode="light"> {/* "light" | "dark" */}
|
|
85
|
+
{children}
|
|
86
|
+
</EntropixProvider>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### useTheme
|
|
90
|
+
|
|
91
|
+
Access the current theme inside any component:
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
import { useTheme } from "@entropix/react-native";
|
|
95
|
+
|
|
96
|
+
function MyComponent() {
|
|
97
|
+
const { mode, tokens, baseTokens } = useTheme();
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<View style={{ backgroundColor: tokens.color.bg.primary }}>
|
|
101
|
+
<Text style={{ color: tokens.color.text.primary }}>
|
|
102
|
+
Current theme: {mode}
|
|
103
|
+
</Text>
|
|
104
|
+
</View>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
| Return | Type | Description |
|
|
110
|
+
|--------|------|-------------|
|
|
111
|
+
| `mode` | `"light" \| "dark"` | Current theme mode |
|
|
112
|
+
| `tokens` | `EntropixTheme` | Theme-specific token values |
|
|
113
|
+
| `baseTokens` | `object` | Base (non-themed) token values |
|
|
114
|
+
|
|
115
|
+
## Components
|
|
116
|
+
|
|
117
|
+
### Button
|
|
118
|
+
|
|
119
|
+
```tsx
|
|
120
|
+
<Button
|
|
121
|
+
variant="primary" // "primary" | "secondary" | "outline" | "ghost" | "danger"
|
|
122
|
+
size="md" // "sm" | "md" | "lg"
|
|
123
|
+
disabled={false}
|
|
124
|
+
loading={false}
|
|
125
|
+
onPress={() => {}}
|
|
126
|
+
style={customViewStyle}
|
|
127
|
+
textStyle={customTextStyle}
|
|
128
|
+
>
|
|
129
|
+
Press me
|
|
130
|
+
</Button>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
| Prop | Type | Default | Description |
|
|
134
|
+
|------|------|---------|-------------|
|
|
135
|
+
| `variant` | `ButtonVariant` | `"primary"` | Visual variant |
|
|
136
|
+
| `size` | `ButtonSize` | `"md"` | Size preset |
|
|
137
|
+
| `disabled` | `boolean` | `false` | Disables the button |
|
|
138
|
+
| `loading` | `boolean` | `false` | Shows loading state |
|
|
139
|
+
| `onPress` | `() => void` | — | Press handler |
|
|
140
|
+
| `style` | `StyleProp<ViewStyle>` | — | Container style overrides |
|
|
141
|
+
| `textStyle` | `TextStyle` | — | Label text style overrides |
|
|
142
|
+
|
|
143
|
+
### Toggle
|
|
144
|
+
|
|
145
|
+
```tsx
|
|
146
|
+
<Toggle
|
|
147
|
+
checked={isChecked}
|
|
148
|
+
defaultChecked={false}
|
|
149
|
+
onChange={(checked) => setChecked(checked)}
|
|
150
|
+
disabled={false}
|
|
151
|
+
label="Enable feature"
|
|
152
|
+
style={customStyle}
|
|
153
|
+
/>
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
| Prop | Type | Default | Description |
|
|
157
|
+
|------|------|---------|-------------|
|
|
158
|
+
| `checked` | `boolean` | — | Controlled checked state |
|
|
159
|
+
| `defaultChecked` | `boolean` | `false` | Initial state (uncontrolled) |
|
|
160
|
+
| `onChange` | `(checked: boolean) => void` | — | Change handler |
|
|
161
|
+
| `disabled` | `boolean` | `false` | Disables the toggle |
|
|
162
|
+
| `label` | `string` | — | Accessible label |
|
|
163
|
+
|
|
164
|
+
### Switch
|
|
165
|
+
|
|
166
|
+
Same API as Toggle but renders with `role="switch"` and track/thumb visual styling.
|
|
167
|
+
|
|
168
|
+
```tsx
|
|
169
|
+
<Switch onChange={(on) => console.log(on)} label="Dark mode" />
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Dialog
|
|
173
|
+
|
|
174
|
+
Compound component using React Native `Modal`.
|
|
175
|
+
|
|
176
|
+
```tsx
|
|
177
|
+
<Dialog closeOnOverlayPress modal role="dialog">
|
|
178
|
+
<DialogTrigger>
|
|
179
|
+
<Text>Open Dialog</Text>
|
|
180
|
+
</DialogTrigger>
|
|
181
|
+
<DialogOverlay />
|
|
182
|
+
<DialogContent>
|
|
183
|
+
<DialogTitle>Confirm</DialogTitle>
|
|
184
|
+
<DialogDescription>Are you sure?</DialogDescription>
|
|
185
|
+
<DialogClose>
|
|
186
|
+
<Text>Close</Text>
|
|
187
|
+
</DialogClose>
|
|
188
|
+
</DialogContent>
|
|
189
|
+
</Dialog>
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
| Prop (Dialog) | Type | Default | Description |
|
|
193
|
+
|---------------|------|---------|-------------|
|
|
194
|
+
| `isOpen` | `boolean` | — | Controlled open state |
|
|
195
|
+
| `defaultOpen` | `boolean` | `false` | Initial state |
|
|
196
|
+
| `onOpenChange` | `(open: boolean) => void` | — | State change handler |
|
|
197
|
+
| `closeOnOverlayPress` | `boolean` | `true` | Close on overlay tap |
|
|
198
|
+
| `modal` | `boolean` | `true` | Modal presentation |
|
|
199
|
+
| `role` | `"dialog" \| "alertdialog"` | `"dialog"` | Accessibility role |
|
|
200
|
+
|
|
201
|
+
### Tabs
|
|
202
|
+
|
|
203
|
+
```tsx
|
|
204
|
+
<Tabs defaultSelectedKey="tab1" orientation="horizontal">
|
|
205
|
+
<TabList>
|
|
206
|
+
<Tab value="tab1">Tab 1</Tab>
|
|
207
|
+
<Tab value="tab2">Tab 2</Tab>
|
|
208
|
+
</TabList>
|
|
209
|
+
<TabPanel value="tab1">Content 1</TabPanel>
|
|
210
|
+
<TabPanel value="tab2">Content 2</TabPanel>
|
|
211
|
+
</Tabs>
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Accordion
|
|
215
|
+
|
|
216
|
+
```tsx
|
|
217
|
+
<Accordion defaultExpandedKeys={["item1"]} allowMultiple={false} collapsible>
|
|
218
|
+
<AccordionItem value="item1">
|
|
219
|
+
<AccordionTrigger>Section 1</AccordionTrigger>
|
|
220
|
+
<AccordionPanel>Content 1</AccordionPanel>
|
|
221
|
+
</AccordionItem>
|
|
222
|
+
</Accordion>
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Menu
|
|
226
|
+
|
|
227
|
+
```tsx
|
|
228
|
+
<Menu closeOnSelect>
|
|
229
|
+
<MenuTrigger>
|
|
230
|
+
<Text>Actions</Text>
|
|
231
|
+
</MenuTrigger>
|
|
232
|
+
<MenuContent>
|
|
233
|
+
<MenuItem index={0} onSelect={() => console.log("Edit")}>Edit</MenuItem>
|
|
234
|
+
<MenuItem index={1} onSelect={() => console.log("Delete")}>Delete</MenuItem>
|
|
235
|
+
</MenuContent>
|
|
236
|
+
</Menu>
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## Layout Primitives
|
|
240
|
+
|
|
241
|
+
### Stack
|
|
242
|
+
|
|
243
|
+
Vertical flex container.
|
|
244
|
+
|
|
245
|
+
```tsx
|
|
246
|
+
<Stack gap="md" align="center" fullWidth>
|
|
247
|
+
<Button>First</Button>
|
|
248
|
+
<Button>Second</Button>
|
|
249
|
+
</Stack>
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
| Prop | Type | Default | Description |
|
|
253
|
+
|------|------|---------|-------------|
|
|
254
|
+
| `gap` | `"none" \| "xs" \| "sm" \| "md" \| "lg" \| "xl" \| "2xl"` | token default | Vertical spacing |
|
|
255
|
+
| `align` | `"start" \| "center" \| "end" \| "stretch"` | — | Cross-axis alignment |
|
|
256
|
+
| `fullWidth` | `boolean` | `false` | Stretch to full width |
|
|
257
|
+
|
|
258
|
+
### Inline
|
|
259
|
+
|
|
260
|
+
Horizontal flex container.
|
|
261
|
+
|
|
262
|
+
```tsx
|
|
263
|
+
<Inline gap="sm" align="center" justify="between" wrap>
|
|
264
|
+
<Button>Save</Button>
|
|
265
|
+
<Button variant="outline">Cancel</Button>
|
|
266
|
+
</Inline>
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Container
|
|
270
|
+
|
|
271
|
+
Centered max-width container with responsive padding that adapts at tablet (768px) and desktop (1024px) breakpoints.
|
|
272
|
+
|
|
273
|
+
```tsx
|
|
274
|
+
<Container maxWidth="lg" center>
|
|
275
|
+
<Text>Page content</Text>
|
|
276
|
+
</Container>
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### Divider
|
|
280
|
+
|
|
281
|
+
```tsx
|
|
282
|
+
<Divider orientation="horizontal" spacing="md" />
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## Responsive Hooks
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
import {
|
|
289
|
+
useBreakpoint,
|
|
290
|
+
useBreakpointValue,
|
|
291
|
+
useScreenDimensions,
|
|
292
|
+
BREAKPOINTS,
|
|
293
|
+
} from "@entropix/react-native";
|
|
294
|
+
|
|
295
|
+
// Current breakpoint
|
|
296
|
+
const bp = useBreakpoint(); // "base" | "sm" | "md" | "lg" | "xl" | "2xl"
|
|
297
|
+
|
|
298
|
+
// Check breakpoint threshold
|
|
299
|
+
const isTablet = useBreakpointValue("md");
|
|
300
|
+
|
|
301
|
+
// Raw screen dimensions
|
|
302
|
+
const { width, height } = useScreenDimensions();
|
|
303
|
+
|
|
304
|
+
// Breakpoint values
|
|
305
|
+
console.log(BREAKPOINTS); // { sm: 640, md: 768, lg: 1024, xl: 1280, "2xl": 1536 }
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
## Styling
|
|
309
|
+
|
|
310
|
+
All components are pre-styled using design tokens from `@entropix/tokens/native`. Styles are applied via `StyleSheet.create()` and adapt to the current theme via `EntropixProvider`.
|
|
311
|
+
|
|
312
|
+
To customize styles, use the `style` prop (and `textStyle` for text-containing components):
|
|
313
|
+
|
|
314
|
+
```tsx
|
|
315
|
+
<Button
|
|
316
|
+
variant="primary"
|
|
317
|
+
style={{ marginTop: 20 }}
|
|
318
|
+
textStyle={{ letterSpacing: 1 }}
|
|
319
|
+
>
|
|
320
|
+
Custom styled
|
|
321
|
+
</Button>
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
For full control over colors, access tokens directly via `useTheme()`:
|
|
325
|
+
|
|
326
|
+
```tsx
|
|
327
|
+
const { tokens } = useTheme();
|
|
328
|
+
|
|
329
|
+
<View style={{ backgroundColor: tokens.color.bg.secondary, padding: tokens.space.md }}>
|
|
330
|
+
<Text style={{ color: tokens.color.text.primary }}>Themed content</Text>
|
|
331
|
+
</View>
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
## Architecture
|
|
335
|
+
|
|
336
|
+
`@entropix/react-native` shares the same headless hooks as `@entropix/react`:
|
|
337
|
+
|
|
338
|
+
```
|
|
339
|
+
@entropix/core (shared hooks)
|
|
340
|
+
├── @entropix/react (web: HTML + CSS)
|
|
341
|
+
└── @entropix/react-native (mobile: RN Views + StyleSheet)
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
Same API surface, same accessibility behavior, different renderers.
|
|
345
|
+
|
|
346
|
+
## Related Packages
|
|
347
|
+
|
|
348
|
+
- [`@entropix/tokens`](https://www.npmjs.com/package/@entropix/tokens) — Design tokens (required peer)
|
|
349
|
+
- [`@entropix/core`](https://www.npmjs.com/package/@entropix/core) — Headless hooks (bundled dependency)
|
|
350
|
+
- [`@entropix/react`](https://www.npmjs.com/package/@entropix/react) — React web components
|
|
351
|
+
|
|
352
|
+
## License
|
|
353
|
+
|
|
354
|
+
MIT
|