@recursica/mantine-adapter 0.9.1 → 0.9.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.
Files changed (2) hide show
  1. package/README.md +335 -80
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,121 +1,376 @@
1
- # Recursica
1
+ # Recursica Mantine Adapter
2
2
 
3
- This is the Recursica design system. More details can be found at [Recursica](https://recursica.com/).
3
+ A design token adapter that converts Figma design tokens exported via the Recursica Figma plugin into Mantine theme files, TypeScript types, and Vanilla Extract CSS-in-JS themes.
4
4
 
5
- ## What is Recursica
5
+ ## What is Recursica Mantine Adapter
6
6
 
7
- ### Variable parser
7
+ The Recursica Mantine Adapter processes design token JSON files and generates:
8
8
 
9
- Recursica parses the variables from the JSON files exported by the design system.
10
- All your files can be at the root of the project, or if you prefer, you can put them in a folder. You just need to specify the path to the files in the `recursica.json` file.
9
+ - **Mantine Theme**: Complete Mantine theme configuration with colors, typography, spacing, and more
10
+ - **Vanilla Extract Themes**: CSS-in-JS theme files with contract-based theme switching
11
+ - **TypeScript Types**: Type-safe interfaces for colors, spacers, border radius, and other tokens
12
+ - **React Components**: Ready-to-use Icon components with proper TypeScript definitions
13
+ - **UI Kit Objects**: Structured objects containing all design system primitives
11
14
 
12
- ### Icon parser
15
+ ## Installation
13
16
 
14
- Recursica parses `recursica-icons.json` file to get the icons names and their respective paths.
15
- The output will be at `src/components/Icons/`
17
+ ```bash
18
+ npm install @recursica/mantine-adapter
19
+ ```
16
20
 
17
- - `svg` folder with the svg icon files
18
- - `icon_exports.ts` parses the svg files and exports them as React components
19
- - `icon_resource_map.ts` maps the icon names to the React components
20
- - `Icon.tsx` is the main component that renders the icon
21
+ ## Usage
21
22
 
22
- The `svg` folder, `icon_exports.ts` and `icon_resource_map.ts` are auto-generated. You don't need to do anything with them.
23
- For the `Icon.tsx` file, you can customize the `Icon` component to your needs, here's the default implementation:
23
+ ### Option 1: Using npx (Recommended)
24
24
 
25
- ```tsx
26
- import type { RecursicaColors } from "../../recursica/RecursicaColorsType";
27
- import { IconResourceMap } from "./icon_resource_map";
28
- import { recursica } from "../../recursica/Recursica";
29
- const DEFAULT_SIZE = 24;
25
+ Run the adapter directly without installation:
30
26
 
31
- export type IconImport = React.SVGProps<SVGSVGElement> & {
32
- title?: string | undefined;
33
- };
27
+ ```bash
28
+ npx @recursica/mantine-adapter
29
+ ```
30
+
31
+ ### Option 2: Adding a script to package.json
34
32
 
35
- export type IconName = keyof typeof IconResourceMap;
36
- export const IconNames = Object.keys(IconResourceMap);
37
-
38
- export interface IconProps {
39
- name: IconName;
40
- /** Icon size @default 24 */
41
- size?: 16 | 20 | 24 | 32 | 40 | 48 | "100%";
42
- /** The title to apply to the icon. If not set, it inherits from the parent */
43
- title?: string;
44
- /** The color to apply to the icon. If not set, it inherits from the parent */
45
- color?: RecursicaColors;
33
+ Add the recursica command to your package.json scripts:
34
+
35
+ ```json
36
+ {
37
+ "scripts": {
38
+ "recursica": "recursica"
39
+ }
46
40
  }
41
+ ```
47
42
 
48
- export const Icon = (props: IconProps) => {
49
- const SvgComponent = IconResourceMap[props.name];
50
- const colorStyles = {
51
- fill: props.color ? recursica[props.color] : "currentColor",
52
- color: props.color ? recursica[props.color] : "currentColor",
53
- };
54
- return (
55
- <SvgComponent
56
- width={props.size ?? DEFAULT_SIZE}
57
- height={props.size ?? DEFAULT_SIZE}
58
- title={props.title}
59
- style={props.color ? colorStyles : undefined}
60
- viewBox="0 0 24 24"
61
- preserveAspectRatio="xMidYMid meet"
62
- />
63
- );
64
- };
43
+ Then run:
44
+
45
+ ```bash
46
+ npm run recursica
65
47
  ```
66
48
 
67
- ### Theme generator
49
+ ### Option 3: Programmatic Usage
68
50
 
69
- Recursica generates a vanilla extract theme based on the variables. Then creates a mantine theme from the vanilla extract theme.
70
- Here's a list of the generated files:
51
+ ```typescript
52
+ import { runMain } from "@recursica/mantine-adapter";
71
53
 
72
- - `RecursicaCymbiotikaTokens.ts` contains the basic tokens for the theme
73
- - `RecursicaCymbiotikaContractTheme.css` contains the contract theme for the vanilla extract theme, these variables will switch automatically based on the selected theme
74
- - `RecursicaColorsType.ts` exposes all the colors available coming from the design system
75
- - `Recursica.ts` is the main file that exports the theme available variables.
76
- - `RecursicaCymbiotikaMantineTheme.ts` is the mantine theme generated from the vanilla extract theme
77
- - `RecursicaCymbiotikaThemes.css.ts` contains all the themes available, also exposes a `Themes` object that can be used to switch between themes
54
+ await runMain();
55
+ ```
78
56
 
79
- ## How to use
57
+ ## Configuration
80
58
 
81
- Create a recursica.json file in the root of the project.
59
+ Create a `recursica.json` file in your project root:
82
60
 
83
- ```
61
+ ```json
84
62
  {
85
- "$schema": "./recursica/schemas/config-schema.json",
86
- "project": "Cymbiotika"
63
+ "$schema": "node_modules/@recursica/schemas/RecursicaConfiguration.json",
64
+ "project": "YourProjectName",
65
+ "srcPath": "./src",
66
+ "bundledJson": "./design-tokens.json",
67
+ "iconsJson": "./icons.json",
68
+ "overrides": {
69
+ "mantineTheme": {
70
+ "1-scale": "rem",
71
+ "background": "white"
72
+ },
73
+ "fontWeight": [
74
+ {
75
+ "fontFamily": "Inter",
76
+ "value": 400,
77
+ "alias": "regular"
78
+ }
79
+ ]
80
+ },
81
+ "iconsConfig": {
82
+ "include": {
83
+ "variants": ["Filled", "Outlined"]
84
+ },
85
+ "exclude": {
86
+ "names": ["deprecated_icon"]
87
+ }
88
+ }
87
89
  }
88
90
  ```
89
91
 
90
- [!NOTE]
91
- The `project` field must match the name of the project in the JSON files.
92
+ ### Configuration Options
93
+
94
+ - `project`: Must match the project name in your exported JSON files
95
+ - `srcPath`: Output directory for generated files (default: `./src`)
96
+ - `bundledJson`: Path to your design tokens JSON file
97
+ - `iconsJson`: Path to your icons JSON file (optional)
98
+ - `overrides`: Custom overrides for theme generation
99
+ - `iconsConfig`: Configuration for icon filtering and processing
92
100
 
93
- Modify your package.json to include the recursica command.
101
+ ## Generated Files
94
102
 
103
+ The adapter generates the following file structure in `{srcPath}/recursica/`:
104
+
105
+ ```
106
+ src/
107
+ └── recursica/
108
+ ├── Recursica.ts # Main theme object
109
+ ├── RecursicaTokens.ts # Base design tokens
110
+ ├── RecursicaContractTheme.css.ts # Vanilla Extract contract
111
+ ├── RecursicaThemes.css.ts # Theme implementations
112
+ ├── RecursicaMantineTheme.ts # Mantine theme config
113
+ ├── RecursicaColorsType.ts # Color type definitions
114
+ ├── RecursicaSpacersType.ts # Spacing type definitions
115
+ ├── RecursicaBorderRadiusType.ts # Border radius types
116
+ ├── RecursicaUiKit.ts # UI Kit components object
117
+ └── components/
118
+ └── Icons/
119
+ ├── Icon.tsx # Main Icon component
120
+ ├── icon_exports.ts # React icon components
121
+ ├── icon_resource_map.ts # Icon name mappings
122
+ └── Svg/ # SVG icon files
123
+ ├── icon1.svg
124
+ └── icon2.svg
95
125
  ```
96
- "scripts": {
97
- "recursica": "tsx recursica/main.ts"
126
+
127
+ ## Icon Component Usage
128
+
129
+ The generated Icon component provides type-safe icon usage:
130
+
131
+ ```tsx
132
+ import { Icon } from './recursica/components/Icons/Icon';
133
+ import type { RecursicaColors } from './recursica/RecursicaColorsType';
134
+
135
+ // Basic usage
136
+ <Icon name="check_Filled" />
137
+
138
+ // With custom size and color
139
+ <Icon
140
+ name="arrow_back_ios_new_Outlined"
141
+ size={32}
142
+ color="primary-500"
143
+ />
144
+
145
+ // Available props
146
+ interface IconProps {
147
+ name: IconName; // Autocompleted icon names
148
+ size?: 16 | 20 | 24 | 32 | 40 | 48 | "100%"; // Predefined sizes
149
+ title?: string; // Accessibility title
150
+ color?: RecursicaColors; // Theme colors
98
151
  }
99
152
  ```
100
153
 
101
- Run the recursica command.
154
+ ## Using with Webworker
155
+
156
+ For browser-based token processing, use the webworker implementation:
102
157
 
158
+ ### 1. Setup the Worker
159
+
160
+ ```typescript
161
+ // worker.ts
162
+ import "@recursica/mantine-adapter/dist/webworker.js";
103
163
  ```
104
- npm run recursica
164
+
165
+ ### 2. Process Tokens in Main Thread
166
+
167
+ ```typescript
168
+ // main.ts
169
+ interface WorkerMessage {
170
+ bundledJson: string; // JSON content as string
171
+ iconsJson?: string; // Icons JSON content as string
172
+ project: string; // Project name
173
+ srcPath: string; // Output path
174
+ rootPath: string; // Root project path
175
+ overrides?: any; // Theme overrides
176
+ iconsConfig?: any; // Icons configuration
177
+ }
178
+
179
+ // Create and use worker
180
+ const worker = new Worker("./worker.js");
181
+
182
+ worker.postMessage({
183
+ bundledJson: jsonFileContent,
184
+ iconsJson: iconsJsonContent,
185
+ project: "YourProject",
186
+ srcPath: "./src",
187
+ rootPath: "./",
188
+ overrides: undefined,
189
+ iconsConfig: undefined,
190
+ });
191
+
192
+ worker.onmessage = (event) => {
193
+ const files = event.data;
194
+ // Process generated files
195
+ console.log("Generated files:", files);
196
+
197
+ // Files structure matches the CLI output:
198
+ // - files.recursicaTokens
199
+ // - files.vanillaExtractThemes
200
+ // - files.mantineTheme
201
+ // - files.uiKitObject
202
+ // - files.recursicaObject
203
+ // - files.colorsType
204
+ // - files.iconsObject
205
+ // etc.
206
+ };
105
207
  ```
106
208
 
107
- ## How to change the adapter
209
+ ### 3. Handle Worker Response
108
210
 
109
- The adapter is the script that converts the JSON files into a theme.
110
- The current adapter is the Mantine adapter.
111
- To change the adapter, you need to go to the [adapter folder](recursica/adapter) and modify the adapter to your needs.
112
- In case you wanna create a new adapter you must export a function named `generateThemeFile` that will receive the following parameters:
211
+ ```typescript
212
+ interface WorkerResponse {
213
+ recursicaTokens: ExportingResult;
214
+ vanillaExtractThemes: VanillaExtractThemesOutput;
215
+ mantineTheme: GenerateMantineThemeOutput;
216
+ uiKitObject: ExportingResult;
217
+ recursicaObject: ExportingResult;
218
+ colorsType: ExportingResult;
219
+ spacersType: ExportingResult;
220
+ borderRadiusType: ExportingResult;
221
+ iconsObject?: GenerateIconsOutput;
222
+ recursicaThemes: ExportingResult;
223
+ prettierignore: ExportingResult;
224
+ }
113
225
 
226
+ interface ExportingResult {
227
+ content: string; // File content
228
+ path: string; // Full file path
229
+ filename: string; // Filename only
230
+ }
114
231
  ```
115
- interface GenerateThemeFileParams {
232
+
233
+ ## Creating Custom Adapters
234
+
235
+ To create your own adapter, you need to implement the core generator functions. The adapter architecture is modular and extensible.
236
+
237
+ ### 1. Adapter Structure
238
+
239
+ ```typescript
240
+ // your-adapter/index.ts
241
+ import type {
242
+ RecursicaConfigOverrides,
243
+ RecursicaConfigIcons,
244
+ ExportingResult,
245
+ } from "@recursica/mantine-adapter";
246
+
247
+ interface CustomAdapterParams {
248
+ overrides: RecursicaConfigOverrides | undefined;
249
+ rootPath: string;
116
250
  srcPath: string;
117
- baseTokens: ThemeTokens;
118
- themes: Themes;
119
251
  project: string;
252
+ icons: Record<string, string>;
253
+ iconsConfig: RecursicaConfigIcons | undefined;
254
+ processTokens: ProcessTokens;
255
+ }
256
+
257
+ export function runCustomAdapter(params: CustomAdapterParams) {
258
+ // Your custom generation logic here
259
+ return {
260
+ // Return ExportingResult objects for each file you want to generate
261
+ customTheme: generateCustomTheme(params),
262
+ customTypes: generateCustomTypes(params),
263
+ // ... other generators
264
+ };
120
265
  }
121
266
  ```
267
+
268
+ ### 2. Individual Generators
269
+
270
+ Each generator should follow this pattern:
271
+
272
+ ```typescript
273
+ // generateCustomTheme.ts
274
+ import type {
275
+ ExportingResult,
276
+ ExportingProps,
277
+ } from "@recursica/mantine-adapter";
278
+
279
+ export function generateCustomTheme(
280
+ tokens: Record<string, any>,
281
+ exportingProps: ExportingProps,
282
+ ): ExportingResult {
283
+ const { outputPath, project } = exportingProps;
284
+
285
+ const filename = `${project}CustomTheme.ts`;
286
+ const path = `${outputPath}/${filename}`;
287
+
288
+ const content = `
289
+ // Auto-generated custom theme
290
+ export const customTheme = ${JSON.stringify(tokens, null, 2)};
291
+ `.trim();
292
+
293
+ return {
294
+ content,
295
+ path,
296
+ filename,
297
+ };
298
+ }
299
+ ```
300
+
301
+ ### 3. Available Generator Templates
302
+
303
+ The mantine-adapter provides several generator templates you can extend:
304
+
305
+ - `generateRecursicaTokens`: Base token generation
306
+ - `generateVanillaExtractThemes`: CSS-in-JS theme generation
307
+ - `generateMantineTheme`: Mantine-specific theme generation
308
+ - `generateColorTypes`: TypeScript color type generation
309
+ - `generateIcons`: React icon component generation
310
+ - `generateUiKit`: UI component object generation
311
+
312
+ ### 4. Token Processing
313
+
314
+ Use the `ProcessTokens` class to handle token transformation:
315
+
316
+ ```typescript
317
+ import { ProcessTokens } from "@recursica/mantine-adapter";
318
+
319
+ const processTokens = new ProcessTokens(overrides);
320
+ processTokens.processTokens(jsonContent.tokens);
321
+
322
+ // Access processed tokens
323
+ const colors = processTokens.colors;
324
+ const spacers = processTokens.spacers;
325
+ const typography = processTokens.typography;
326
+ const themes = processTokens.themes;
327
+ ```
328
+
329
+ ### 5. Integration
330
+
331
+ Replace the default adapter by modifying the `runAdapter` function or create a separate CLI that uses your custom adapter:
332
+
333
+ ```typescript
334
+ // custom-cli.ts
335
+ import { processJsonContent, processIcons } from "@recursica/mantine-adapter";
336
+ import { runCustomAdapter } from "./your-adapter";
337
+
338
+ // Use the same processing logic but with your custom adapter
339
+ const processTokens = processJsonContent(bundledJsonContent, {
340
+ project,
341
+ overrides,
342
+ });
343
+ const icons = processIcons(iconsJsonContent);
344
+
345
+ const files = runCustomAdapter({
346
+ rootPath,
347
+ overrides,
348
+ srcPath,
349
+ icons,
350
+ processTokens,
351
+ project,
352
+ iconsConfig,
353
+ });
354
+ ```
355
+
356
+ ## API Reference
357
+
358
+ ### Core Functions
359
+
360
+ - `runMain()`: Main CLI execution function
361
+ - `processJsonContent()`: Process design token JSON
362
+ - `processIcons()`: Process icons JSON
363
+ - `processAdapter()`: Core adapter processing logic
364
+ - `runAdapter()`: Execute the Mantine adapter
365
+
366
+ ### Types
367
+
368
+ - `ExportingResult`: File output interface
369
+ - `RecursicaConfigOverrides`: Theme override configuration
370
+ - `RecursicaConfigIcons`: Icon processing configuration
371
+ - `ThemeTokens`: Theme token structure
372
+ - `Themes`: Multi-theme structure
373
+
374
+ ## License
375
+
376
+ MIT
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@recursica/mantine-adapter",
3
3
  "description": "Recursica Design Token Adapter - Convert design tokens to code",
4
- "version": "0.9.1",
4
+ "version": "0.9.2",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/borderux/recursica#readme",
7
7
  "author": "hi@borderux.com",