@strata-ds/core 2.1.0 → 2.1.2
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 +541 -438
- package/dist/components/DynamicComponentDebug.d.ts +0 -1
- package/dist/components/DynamicComponents.d.ts +0 -1
- package/dist/components/StrataErrorBoundary.d.ts +37 -0
- package/dist/components/card-ui/Card.d.ts +0 -1
- package/dist/components/card-ui/DefaultCard.d.ts +0 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/data/index.d.ts +0 -1
- package/dist/data/mock.types.d.ts +2 -1
- package/dist/hook/useCardData.d.ts +0 -1
- package/dist/hook/useComponent.d.ts +0 -1
- package/dist/hook/useComponents.d.ts +0 -1
- package/dist/hook/useDynamicComponents.d.ts +0 -1
- package/dist/index.d.ts +414 -1
- package/dist/index.esm.js +298 -70
- package/dist/index.js +301 -68
- package/dist/providers/StrataProvider.d.ts +5 -1
- package/dist/providers/index.d.ts +0 -1
- package/dist/registry/ComponentFactory.d.ts +0 -1
- package/dist/registry/ComponentRegistry.d.ts +0 -1
- package/dist/types/card-types.d.ts +0 -1
- package/dist/utils/normalize-component.d.ts +14 -0
- package/package.json +74 -74
- package/dist/components/DynamicComponentDebug.d.ts.map +0 -1
- package/dist/components/DynamicComponents.d.ts.map +0 -1
- package/dist/components/card-ui/Card.d.ts.map +0 -1
- package/dist/components/card-ui/DefaultCard.d.ts.map +0 -1
- package/dist/components/index.d.ts.map +0 -1
- package/dist/data/index.d.ts.map +0 -1
- package/dist/data/mock.types.d.ts.map +0 -1
- package/dist/hook/useCardData.d.ts.map +0 -1
- package/dist/hook/useComponent.d.ts.map +0 -1
- package/dist/hook/useComponents.d.ts.map +0 -1
- package/dist/hook/useDesignSystemSync.d.ts +0 -1
- package/dist/hook/useDesignSystemSync.d.ts.map +0 -1
- package/dist/hook/useDynamicComponents.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.esm.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/providers/StrataProvider.d.ts.map +0 -1
- package/dist/providers/index.d.ts.map +0 -1
- package/dist/registry/ComponentFactory.d.ts.map +0 -1
- package/dist/registry/ComponentRegistry.d.ts.map +0 -1
- package/dist/types/card-types.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,438 +1,541 @@
|
|
|
1
|
-
# @strata-ds/core
|
|
2
|
-
|
|
3
|
-
> The runtime component library for [Strata](https://strata.charisol.io) — connect your React app to your design system and ship updates live.
|
|
4
|
-
|
|
5
|
-
`@strata-ds/core` is a dynamic React component library and stylesheet runtime. It enables teams to consume design tokens and components directly from a centralised Strata design system, ensuring that what designers create is exactly what developers ship — consistently, across platforms, and in real time.
|
|
6
|
-
|
|
7
|
-
> Design once in Strata. Ship everywhere.
|
|
8
|
-
|
|
9
|
-
##
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
###
|
|
37
|
-
|
|
38
|
-
`@strata-ds/core`
|
|
39
|
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
"
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
```tsx
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
import {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
-
|
|
429
|
-
-
|
|
430
|
-
-
|
|
431
|
-
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
1
|
+
# @strata-ds/core
|
|
2
|
+
|
|
3
|
+
> The runtime component library for [Strata](https://strata.charisol.io) — connect your React app to your design system and ship updates live.
|
|
4
|
+
|
|
5
|
+
`@strata-ds/core` is a dynamic React component library and stylesheet runtime. It enables teams to consume design tokens and components directly from a centralised Strata design system, ensuring that what designers create is exactly what developers ship — consistently, across platforms, and in real time.
|
|
6
|
+
|
|
7
|
+
> Design once in Strata. Ship everywhere.
|
|
8
|
+
|
|
9
|
+
## Table of Contents
|
|
10
|
+
|
|
11
|
+
- [Why @strata-ds/core?](#why-strata-dscore)
|
|
12
|
+
- [Quick Start (< 5 Minutes)](#quick-start--5-minutes)
|
|
13
|
+
- [5-Minute Integration Checklist](#5-minute-integration-checklist)
|
|
14
|
+
- [Project Setup (React)](#project-setup-react)
|
|
15
|
+
- [Using Design System Components](#using-design-system-components)
|
|
16
|
+
- [Debugging and Troubleshooting](#debugging-and-troubleshooting)
|
|
17
|
+
- [Customisation and Overrides](#customisation-and-overrides)
|
|
18
|
+
- [Dynamic Updates (Hot-Reloading)](#dynamic-updates-hot-reloading)
|
|
19
|
+
- [Registry API](#registry-api)
|
|
20
|
+
- [Component Factory](#component-factory)
|
|
21
|
+
- [Key Features](#key-features)
|
|
22
|
+
|
|
23
|
+
## Why @strata-ds/core?
|
|
24
|
+
|
|
25
|
+
### The Problem
|
|
26
|
+
|
|
27
|
+
Design and engineering teams often drift apart:
|
|
28
|
+
|
|
29
|
+
- Designers update Figma files
|
|
30
|
+
- Developers re-implement styles manually
|
|
31
|
+
- Components slowly diverge from the original design
|
|
32
|
+
- Consistency breaks across products and platforms
|
|
33
|
+
|
|
34
|
+
This results in duplicate work, inconsistent UI, broken design intent, and slow iteration.
|
|
35
|
+
|
|
36
|
+
### The Solution
|
|
37
|
+
|
|
38
|
+
`@strata-ds/core` bridges this gap by acting as:
|
|
39
|
+
|
|
40
|
+
- A component library
|
|
41
|
+
- A stylesheet generator runtime
|
|
42
|
+
- A live consumer of design tokens and components
|
|
43
|
+
|
|
44
|
+
All powered by your **Strata** project.
|
|
45
|
+
|
|
46
|
+
Instead of hardcoding styles, **components dynamically reference design tokens** fetched from the design system. This establishes a single **source of truth** for design.
|
|
47
|
+
|
|
48
|
+
### Who Is This For?
|
|
49
|
+
|
|
50
|
+
| Persona | Value |
|
|
51
|
+
|---------|-------|
|
|
52
|
+
| **Solopreneurs** | "I don't need a designer — I can sync from Figma and ship brand-consistent UI myself." |
|
|
53
|
+
| **Frontend Engineers** | "Design tokens live in one place. No more manual style updates across 10 repositories." |
|
|
54
|
+
| **Entrepreneurs** | "My team ships faster because design changes propagate automatically." |
|
|
55
|
+
| **Designers** | "What I create in Strata is exactly what users see — no 'lost in translation' moments." |
|
|
56
|
+
|
|
57
|
+
## Core Principles
|
|
58
|
+
|
|
59
|
+
### 1. Separation of Concerns
|
|
60
|
+
|
|
61
|
+
`@strata-ds/core` strictly separates:
|
|
62
|
+
|
|
63
|
+
- **Variables (Design Tokens)** — Colors, spacing, typography, radii, shadows, etc.
|
|
64
|
+
- **Components** — Buttons, Cards, Forms, Navbars, etc.
|
|
65
|
+
|
|
66
|
+
Components never own styles directly — they reference tokens.
|
|
67
|
+
|
|
68
|
+
### 2. Single Source of Truth
|
|
69
|
+
|
|
70
|
+
Design tokens live in your Strata project, not inside applications.
|
|
71
|
+
|
|
72
|
+
- Tokens are defined once
|
|
73
|
+
- Components reference them dynamically
|
|
74
|
+
- Updates propagate automatically
|
|
75
|
+
|
|
76
|
+
### 3. Dynamic & Real-Time Sync
|
|
77
|
+
|
|
78
|
+
`@strata-ds/core` can:
|
|
79
|
+
|
|
80
|
+
- Fetch updated tokens and components from the Strata backend
|
|
81
|
+
- Detect changes via checksum
|
|
82
|
+
- Rebuild styles automatically
|
|
83
|
+
- Fall back to cached data when offline
|
|
84
|
+
|
|
85
|
+
## Architecture Overview
|
|
86
|
+
|
|
87
|
+
```text
|
|
88
|
+
Figma / Style Dictionary
|
|
89
|
+
↓
|
|
90
|
+
Strata Design System
|
|
91
|
+
↓
|
|
92
|
+
Machine-parseable JSON
|
|
93
|
+
↓
|
|
94
|
+
@strata-ds/core Component Library
|
|
95
|
+
↓
|
|
96
|
+
Your React Application
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Quick Start (< 5 Minutes)
|
|
100
|
+
|
|
101
|
+
> 🚀 **New to Strata?** Get your first component rendering in 4 steps.
|
|
102
|
+
|
|
103
|
+
### Step 1: Install
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
npm install @strata-ds/core
|
|
107
|
+
# or
|
|
108
|
+
yarn add @strata-ds/core
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Step 2: Get Your Credentials
|
|
112
|
+
|
|
113
|
+
Go to [strata.charisol.io](https://strata.charisol.io) → **Your Project** → **Publish & Sync** tab:
|
|
114
|
+
|
|
115
|
+
- Copy your **Project ID** (e.g., `abc123def456`)
|
|
116
|
+
- Copy your **Sync Token** (starts with `pt_live_`)
|
|
117
|
+
|
|
118
|
+
### Step 3: Wrap Your App
|
|
119
|
+
|
|
120
|
+
**✅ Recommended: CDN Snapshot Sync** (1 request per poll, edge-cached)
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
"use client"; // Next.js App Router only
|
|
124
|
+
import { StrataProvider } from "@strata-ds/core";
|
|
125
|
+
|
|
126
|
+
export default function RootLayout({
|
|
127
|
+
children,
|
|
128
|
+
}: {
|
|
129
|
+
children: React.ReactNode;
|
|
130
|
+
}) {
|
|
131
|
+
return (
|
|
132
|
+
<StrataProvider
|
|
133
|
+
syncEnabled={true}
|
|
134
|
+
projectId="YOUR_PROJECT_ID"
|
|
135
|
+
snapshotCdnBase="https://cdn.strata.charisol.io"
|
|
136
|
+
syncToken="pt_live_your_token_here"
|
|
137
|
+
syncInterval={5000}
|
|
138
|
+
>
|
|
139
|
+
{children}
|
|
140
|
+
</StrataProvider>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
> 💡 Replace `YOUR_PROJECT_ID` and `pt_live_your_token_here` with values from **Step 2**.
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
<details>
|
|
150
|
+
<summary><strong>⚠️ Legacy Sync</strong> (3 requests per poll — for migration only)</summary>
|
|
151
|
+
|
|
152
|
+
```tsx
|
|
153
|
+
"use client";
|
|
154
|
+
import { StrataProvider } from "@strata-ds/core";
|
|
155
|
+
|
|
156
|
+
export default function RootLayout({
|
|
157
|
+
children,
|
|
158
|
+
}: {
|
|
159
|
+
children: React.ReactNode;
|
|
160
|
+
}) {
|
|
161
|
+
return (
|
|
162
|
+
<StrataProvider
|
|
163
|
+
syncEnabled={true}
|
|
164
|
+
syncUrl="https://api-production-charisol-design-system-be.aws.charisol.io/v1/project/YOUR_PROJECT_ID/data"
|
|
165
|
+
syncToken="pt_live_your_token_here"
|
|
166
|
+
syncInterval={3000}
|
|
167
|
+
>
|
|
168
|
+
{children}
|
|
169
|
+
</StrataProvider>
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**Why CDN is better:**
|
|
175
|
+
|
|
176
|
+
- ✅ 1 request instead of 3 (faster, cheaper)
|
|
177
|
+
- ✅ Edge-cached for global performance
|
|
178
|
+
- ✅ Atomic updates (no partial states)
|
|
179
|
+
|
|
180
|
+
</details>
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
### Step 4: Use Your Components
|
|
185
|
+
|
|
186
|
+
```tsx
|
|
187
|
+
"use client";
|
|
188
|
+
import { useComponents } from "@strata-ds/core";
|
|
189
|
+
|
|
190
|
+
function App() {
|
|
191
|
+
const { Button, Navbar } = useComponents();
|
|
192
|
+
|
|
193
|
+
return (
|
|
194
|
+
<>
|
|
195
|
+
{Button && (
|
|
196
|
+
<Button onClick={() => console.log("clicked")}>Click me</Button>
|
|
197
|
+
)}
|
|
198
|
+
{Navbar && <Navbar />}
|
|
199
|
+
</>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**Not seeing components?** → Jump to [Debugging and Troubleshooting](#debugging-and-troubleshooting).
|
|
205
|
+
|
|
206
|
+
## 5-Minute Integration Checklist
|
|
207
|
+
|
|
208
|
+
Use this checklist to verify your setup after following [Quick Start](#quick-start--5-minutes) above.
|
|
209
|
+
|
|
210
|
+
**Before you start:**
|
|
211
|
+
|
|
212
|
+
- [ ] Created a project at [strata.charisol.io](https://strata.charisol.io)
|
|
213
|
+
- [ ] Imported your design tokens (Style Dictionary JSON or Figma)
|
|
214
|
+
- [ ] Published your project (dashboard shows "✅ Published")
|
|
215
|
+
|
|
216
|
+
**Integration:**
|
|
217
|
+
|
|
218
|
+
- [ ] Installed `@strata-ds/core` via npm/yarn
|
|
219
|
+
- [ ] Copied `projectId` from dashboard URL or project settings
|
|
220
|
+
- [ ] Copied `syncToken` from **Publish & Sync** tab (starts with `pt_live_`)
|
|
221
|
+
- [ ] Wrapped app with `<StrataProvider>` using **CDN Snapshot Sync** (recommended)
|
|
222
|
+
- [ ] Imported `@strata-ds/core/dist/styles.css` in root layout
|
|
223
|
+
- [ ] Rendered first component with `useComponents()`
|
|
224
|
+
|
|
225
|
+
**Verification:**
|
|
226
|
+
|
|
227
|
+
- [ ] Opened DevTools → Console and saw `🔄 Starting design system sync...`
|
|
228
|
+
- [ ] Console shows `📊 Components available: ...`
|
|
229
|
+
- [ ] Component renders on screen with correct styles
|
|
230
|
+
- [ ] Added `<StrataDebug />` and verified connection status is **✅ Connected**
|
|
231
|
+
|
|
232
|
+
**Stuck?** → Jump to [Debugging and Troubleshooting](#debugging-and-troubleshooting).
|
|
233
|
+
|
|
234
|
+
## Project Setup (React)
|
|
235
|
+
|
|
236
|
+
`@strata-ds/core` works with React 18+, Next.js (App Router or Pages Router), and any standard React setup.
|
|
237
|
+
|
|
238
|
+
### 1. Create a new project
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
npx create-next-app@latest my-strata-app --typescript
|
|
242
|
+
cd my-strata-app
|
|
243
|
+
npm install @strata-ds/core
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### 2. Integrate the StrataProvider
|
|
247
|
+
|
|
248
|
+
Wrap your application's root component with `StrataProvider`. This provider manages the connection to the Strata backend.
|
|
249
|
+
|
|
250
|
+
| Prop | Type | Description |
|
|
251
|
+
| :----------------- | :------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
252
|
+
| `syncEnabled` | `boolean` | If `true`, the library will fetch and sync tokens/components from the server. |
|
|
253
|
+
| `snapshotCdnBase` | `string` | **Recommended.** Base CDN URL for snapshot files (e.g. `"https://cdn.strata.charisol.io"`). When set together with `projectId`, the provider fetches a single `strata.json` snapshot per poll cycle instead of 3 API calls. Takes precedence over `syncUrl`. |
|
|
254
|
+
| `projectId` | `string` | Your Strata project ID (shown in the dashboard URL and project settings). Required when using `snapshotCdnBase`. |
|
|
255
|
+
| `syncUrl` | `string` | Legacy base sync URL. `StrataProvider` will append `/variables`, `/components`, and `/custom` to this URL. Ignored when `snapshotCdnBase` + `projectId` are provided. |
|
|
256
|
+
| `syncInterval` | `number` | Polling interval in milliseconds to check for design system updates. Default: `3000`. |
|
|
257
|
+
| `syncToken` | `string` | Sync token from your project dashboard. When set, all sync requests carry `Authorization: Bearer <token>`. Required if your project is not fully public. |
|
|
258
|
+
| `initialData` | `DesignSystemData` | Initial design system data to use before the first sync. |
|
|
259
|
+
| `userDesignSystem` | `DesignSystemData` | Override design system data — useful for storybook, testing, or static mode. Takes precedence over `initialData`. |
|
|
260
|
+
| `onSyncError` | `(error: { code: number; message: string; source: string }) => void` | Callback invoked when a sync cycle fails. `code` is the HTTP status (0 for non-HTTP errors), `message` is a human-readable description, and `source` is `"cdn"` or `"sync"`. |
|
|
261
|
+
| `onSyncSuccess` | `(data: DesignSystemData) => void` | Callback invoked whenever a sync cycle succeeds with new data. |
|
|
262
|
+
|
|
263
|
+
```tsx
|
|
264
|
+
// app/layout.tsx (Next.js App Router)
|
|
265
|
+
"use client";
|
|
266
|
+
import { StrataProvider } from "@strata-ds/core";
|
|
267
|
+
|
|
268
|
+
export default function RootLayout({
|
|
269
|
+
children,
|
|
270
|
+
}: {
|
|
271
|
+
children: React.ReactNode;
|
|
272
|
+
}) {
|
|
273
|
+
return (
|
|
274
|
+
<html lang="en">
|
|
275
|
+
<body>
|
|
276
|
+
<StrataProvider
|
|
277
|
+
syncEnabled={true}
|
|
278
|
+
projectId="YOUR_PROJECT_ID"
|
|
279
|
+
snapshotCdnBase="https://cdn.strata.charisol.io"
|
|
280
|
+
syncInterval={5000}
|
|
281
|
+
>
|
|
282
|
+
{children}
|
|
283
|
+
</StrataProvider>
|
|
284
|
+
</body>
|
|
285
|
+
</html>
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
> 💡 Replace `YOUR_PROJECT_ID` with the ID from your Strata project dashboard. For private projects, add `syncToken="pt_live_your_token_here"` (get it from the **Publish & Sync** tab).
|
|
291
|
+
|
|
292
|
+
### Sync token authentication
|
|
293
|
+
|
|
294
|
+
If your project has a sync token set in the Strata dashboard, pass it as `syncToken`. Every polling request will automatically include `Authorization: Bearer <token>`.
|
|
295
|
+
|
|
296
|
+
Projects with `syncToken` set are only readable by clients that present the correct token. This is the recommended way to gate read access to your design system without managing user accounts.
|
|
297
|
+
|
|
298
|
+
```tsx
|
|
299
|
+
<StrataProvider
|
|
300
|
+
syncEnabled={true}
|
|
301
|
+
projectId="YOUR_PROJECT_ID"
|
|
302
|
+
snapshotCdnBase="https://cdn.strata.charisol.io"
|
|
303
|
+
syncToken="pt_live_your_token_here"
|
|
304
|
+
syncInterval={5000}
|
|
305
|
+
>
|
|
306
|
+
{children}
|
|
307
|
+
</StrataProvider>
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
## Using Design System Components
|
|
311
|
+
|
|
312
|
+
`@strata-ds/core` provides dynamic access to your components defined in Strata.
|
|
313
|
+
|
|
314
|
+
### Accessing Components with `useComponents`
|
|
315
|
+
|
|
316
|
+
```tsx
|
|
317
|
+
"use client";
|
|
318
|
+
import { useComponents } from "@strata-ds/core";
|
|
319
|
+
|
|
320
|
+
function AppContent() {
|
|
321
|
+
// Components are named exactly as you defined them in your Strata project
|
|
322
|
+
const { Button, Navbar, Card } = useComponents();
|
|
323
|
+
|
|
324
|
+
return (
|
|
325
|
+
<>
|
|
326
|
+
{/* Render conditionally while components are loading */}
|
|
327
|
+
{Button && (
|
|
328
|
+
<Button onClick={() => console.log("clicked")}>Click me</Button>
|
|
329
|
+
)}
|
|
330
|
+
|
|
331
|
+
{Card && <Card style={{ padding: "20px" }}>Card content here</Card>}
|
|
332
|
+
</>
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### Accessing Design System Context with `useStrata`
|
|
338
|
+
|
|
339
|
+
```tsx
|
|
340
|
+
"use client";
|
|
341
|
+
import { useStrata } from "@strata-ds/core";
|
|
342
|
+
|
|
343
|
+
function StatusBar() {
|
|
344
|
+
const { designSystem, syncStatus, lastSynced } = useStrata();
|
|
345
|
+
|
|
346
|
+
return (
|
|
347
|
+
<div>
|
|
348
|
+
<p>Sync status: {syncStatus}</p>
|
|
349
|
+
<p>Last synced: {lastSynced?.toLocaleTimeString() || "Never"}</p>
|
|
350
|
+
<p>Components: {Object.keys(designSystem.components).join(", ")}</p>
|
|
351
|
+
</div>
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
## Debugging and Troubleshooting
|
|
357
|
+
|
|
358
|
+
### Quick Debug Panel
|
|
359
|
+
|
|
360
|
+
Add `<StrataDebug />` anywhere inside `<StrataProvider>` to inspect:
|
|
361
|
+
|
|
362
|
+
- ✅ Active sync mode (CDN vs Legacy)
|
|
363
|
+
- ✅ Connection status
|
|
364
|
+
- ✅ Loaded components
|
|
365
|
+
- ✅ Sync token presence (never shows the actual token)
|
|
366
|
+
|
|
367
|
+
```tsx
|
|
368
|
+
"use client";
|
|
369
|
+
import { StrataDebug } from "@strata-ds/core";
|
|
370
|
+
|
|
371
|
+
function App() {
|
|
372
|
+
return (
|
|
373
|
+
<>
|
|
374
|
+
<StrataDebug />
|
|
375
|
+
{/* Your app content */}
|
|
376
|
+
</>
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
The panel automatically displays the relevant fields for the active sync mode:
|
|
382
|
+
|
|
383
|
+
- **CDN mode** (`snapshotCdnBase` + `projectId` set): shows `✅ CDN Snapshot`, Project ID, resolved Snapshot URL, token presence, and sync interval.
|
|
384
|
+
- **Legacy mode** (`syncUrl` set): shows `⚠️ Legacy (3 requests/poll)`, Sync URL, token presence, and sync interval.
|
|
385
|
+
- **Disabled**: shows `❌ Disabled`.
|
|
386
|
+
|
|
387
|
+
> 🔒 The `syncToken` value is **never** rendered — the panel only shows `✅ Present` or `❌ None`.
|
|
388
|
+
|
|
389
|
+
---
|
|
390
|
+
|
|
391
|
+
### Common Issues
|
|
392
|
+
|
|
393
|
+
| Problem | Solution |
|
|
394
|
+
|---------|----------|
|
|
395
|
+
| **401 Unauthorized** | Your `syncToken` is invalid or expired. Go to **Publish & Sync** tab in your Strata project and copy a fresh token. |
|
|
396
|
+
| **403 Forbidden** | Your project has CORS restrictions. Add your domain to `allowedOrigins` in your Strata project settings. |
|
|
397
|
+
| **Components not rendering** | 1. Check `projectId` matches your dashboard URL<br>2. Verify components exist in your Strata project<br>3. Open DevTools → Console and look for `🔄 Starting design system sync...` |
|
|
398
|
+
| **Styles broken / unstyled** | You forgot to import CSS! Add to your root layout: `import "@strata-ds/core/dist/styles.css";` |
|
|
399
|
+
| **TypeScript errors** | Your component names must match exactly (case-sensitive). Check `useComponents()` return type in DevTools. |
|
|
400
|
+
|
|
401
|
+
---
|
|
402
|
+
|
|
403
|
+
### Network Debugging
|
|
404
|
+
|
|
405
|
+
Open **DevTools → Network tab** and filter by:
|
|
406
|
+
|
|
407
|
+
**CDN Mode** (`snapshotCdnBase` + `projectId` set):
|
|
408
|
+
|
|
409
|
+
- Look for: `https://cdn.strata.charisol.io/snapshots/YOUR_PROJECT_ID/strata.json`
|
|
410
|
+
- Status should be **200 OK** or **304 Not Modified**
|
|
411
|
+
- Response should be a JSON object with `variables`, `components`, `custom`
|
|
412
|
+
|
|
413
|
+
**Legacy Mode** (`syncUrl` set):
|
|
414
|
+
|
|
415
|
+
- Look for 3 requests:
|
|
416
|
+
- `${syncUrl}/variables` → returns `{}`
|
|
417
|
+
- `${syncUrl}/components` → returns `{}`
|
|
418
|
+
- `${syncUrl}/custom` → returns `{}`
|
|
419
|
+
- All should return **200 OK**
|
|
420
|
+
|
|
421
|
+
---
|
|
422
|
+
|
|
423
|
+
### Console Debugging
|
|
424
|
+
|
|
425
|
+
Check for these messages:
|
|
426
|
+
|
|
427
|
+
- ✅ `🔄 Starting design system sync...` → Sync is working
|
|
428
|
+
- ✅ `📊 Components available: Button, Navbar, Card` → Components loaded
|
|
429
|
+
- ✅ `🎨 Variables available: colors, spacing, typography` → Tokens loaded
|
|
430
|
+
- ❌ `❌ Sync failed: 401` → Token issue (see table above)
|
|
431
|
+
- ❌ `❌ Sync failed: 403` → CORS issue (see table above)
|
|
432
|
+
|
|
433
|
+
---
|
|
434
|
+
|
|
435
|
+
### Programmatic Inspection
|
|
436
|
+
|
|
437
|
+
```tsx
|
|
438
|
+
"use client";
|
|
439
|
+
import { useStrata } from "@strata-ds/core";
|
|
440
|
+
|
|
441
|
+
function DebugPanel() {
|
|
442
|
+
const { designSystem, syncStatus, lastSynced, projectId, syncEnabled } =
|
|
443
|
+
useStrata();
|
|
444
|
+
|
|
445
|
+
return (
|
|
446
|
+
<div style={{ padding: "1rem", background: "#f9fafb", borderRadius: 8 }}>
|
|
447
|
+
<h3>🔍 Strata Debug Info</h3>
|
|
448
|
+
<pre>
|
|
449
|
+
{JSON.stringify(
|
|
450
|
+
{
|
|
451
|
+
syncStatus,
|
|
452
|
+
syncEnabled,
|
|
453
|
+
projectId,
|
|
454
|
+
lastSynced: lastSynced?.toLocaleTimeString() || "Never",
|
|
455
|
+
componentsLoaded: Object.keys(designSystem.components),
|
|
456
|
+
variablesLoaded: Object.keys(designSystem.variables),
|
|
457
|
+
},
|
|
458
|
+
null,
|
|
459
|
+
2,
|
|
460
|
+
)}
|
|
461
|
+
</pre>
|
|
462
|
+
</div>
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
### Hooks Reference
|
|
468
|
+
|
|
469
|
+
| Hook / Property | Description |
|
|
470
|
+
| :----------------------- | :--------------------------------------------------------------------------------------------------------------------------------------- |
|
|
471
|
+
| `useStrata()` | Returns full context: `designSystem`, `syncStatus`, `lastSynced`, `syncUrl`, `snapshotCdnBase`, `projectId`, `syncEnabled`, `forceSync`. |
|
|
472
|
+
| `useComponents()` | Returns ready-to-use React components by PascalCase name. |
|
|
473
|
+
| `useDynamicComponents()` | Returns the raw component registry map. |
|
|
474
|
+
|
|
475
|
+
## Customisation and Overrides
|
|
476
|
+
|
|
477
|
+
By default, all components are styled based on the latest tokens fetched from your Strata project. This ensures perfect design-to-code fidelity.
|
|
478
|
+
|
|
479
|
+
**Local Overrides**
|
|
480
|
+
|
|
481
|
+
Override any style locally using standard React props:
|
|
482
|
+
|
|
483
|
+
```tsx
|
|
484
|
+
<Button
|
|
485
|
+
style={{ backgroundColor: "#007bff", color: "white" }}
|
|
486
|
+
className="my-custom-class"
|
|
487
|
+
>
|
|
488
|
+
Custom styled button
|
|
489
|
+
</Button>
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
## Dynamic Updates (Hot-Reloading)
|
|
493
|
+
|
|
494
|
+
`@strata-ds/core` intelligently handles design updates:
|
|
495
|
+
|
|
496
|
+
1. A designer makes a change in Strata (e.g., updates a colour token or modifies a component).
|
|
497
|
+
2. Strata generates a new checksum.
|
|
498
|
+
3. Your `StrataProvider` (via `syncInterval`) polls the `syncUrl`.
|
|
499
|
+
4. If the checksum has changed, the library fetches new design tokens and component configurations, and your app's components are dynamically restyled — without a page refresh.
|
|
500
|
+
|
|
501
|
+
## Registry API
|
|
502
|
+
|
|
503
|
+
`strataRegistry` is the underlying singleton registry that stores all registered components.
|
|
504
|
+
|
|
505
|
+
```tsx
|
|
506
|
+
import { strataRegistry } from "@strata-ds/core";
|
|
507
|
+
|
|
508
|
+
// Check if a component is registered
|
|
509
|
+
strataRegistry.hasComponent("Button");
|
|
510
|
+
|
|
511
|
+
// Get a component by name
|
|
512
|
+
const ButtonComponent = strataRegistry.getComponent("Button");
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
## Component Factory
|
|
516
|
+
|
|
517
|
+
`StrataComponentFactory` creates React components from Strata component definitions.
|
|
518
|
+
|
|
519
|
+
```tsx
|
|
520
|
+
import { StrataComponentFactory } from "@strata-ds/core";
|
|
521
|
+
|
|
522
|
+
const MyComponent = StrataComponentFactory.createComponent(
|
|
523
|
+
"MyComponent",
|
|
524
|
+
componentData,
|
|
525
|
+
designSystem,
|
|
526
|
+
);
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
## Key Features
|
|
530
|
+
|
|
531
|
+
- 🔁 Live sync with Strata backend
|
|
532
|
+
- 🧠 Token-driven styling
|
|
533
|
+
- 🧩 Dynamic component registry
|
|
534
|
+
- 🛠 Inline style overrides supported
|
|
535
|
+
- 📦 Installable via npm
|
|
536
|
+
- 📴 Offline-first fallback
|
|
537
|
+
- 🧪 Debug tools included (`StrataDebug`)
|
|
538
|
+
|
|
539
|
+
## License
|
|
540
|
+
|
|
541
|
+
MIT © [Charisol](https://strata.charisol.io)
|