Skip to content

Commit 7487b1d

Browse files
authored
[Feature] to-flutter: text styles and types (#197)
* feat(to-flutter): Added text styles and variables types * doc(to-flutter): Updated the doc to add textStyle * fix(to-flutter): Fixed typo in doc * fix(to-flutter): generating const for fonts and removing useless line break * doc(to-flutter): Fixed textStyles generation
1 parent d1de669 commit 7487b1d

File tree

7 files changed

+404
-88
lines changed

7 files changed

+404
-88
lines changed

parsers/to-flutter/README.md

Lines changed: 120 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,18 @@ interface parser {
1616
color?: {
1717
className?: string;
1818
fileName?: string;
19+
classType?: string;
1920
};
2021
measurement?: {
2122
devicePixelRatio?: number;
2223
className?: string;
2324
fileName?: string;
25+
classType?: string;
26+
};
27+
textStyle?: {
28+
className?: string;
29+
fileName?: string;
30+
classType?: string;
2431
};
2532
};
2633
};
@@ -29,13 +36,18 @@ interface parser {
2936

3037
### Options
3138

32-
| Parameter | Required | Type | Default | Description |
33-
| ------------------------------------------- | -------- | -------- | -------------------- | ---------------------------------------------------------------- |
34-
| `formatByType.color.className` | optional | `string` | `SpecifyColor` | Name of the class encapsulating your color design tokens. |
35-
| `formatByType.color.fileName` | optional | `string` | `colors.dart` | Name of the Dart file containing your color design tokens. |
36-
| `formatByType.measurement.devicePixelRatio` | optional | `number` | `2` | Default pixel ratio use to scale your measurement design tokens. |
37-
| `formatByType.measurement.className` | optional | `string` | `SpecifyMeasurement` | Name of the class encapsulating your measurement design tokens. |
38-
| `formatByType.measurement.fileName` | optional | `string` | `measurements.dart` | Name of the Dart file containing your measurement design tokens. |
39+
| Parameter | Required | Type | Default | Description |
40+
| ------------------------------------------- | -------- | -------- | -------------------- | ------------------------------------------------------------------ |
41+
| `formatByType.color.className` | optional | `string` | `SpecifyColor` | Name of the class encapsulating your color design tokens. |
42+
| `formatByType.color.fileName` | optional | `string` | `colors.dart` | Name of the Dart file containing your color design tokens. |
43+
| `formatByType.color.classType` | optional | `string` | `Color` | Type that will be assigned to the generated color variables. |
44+
| `formatByType.measurement.devicePixelRatio` | optional | `number` | `2` | Default pixel ratio use to scale your measurement design tokens. |
45+
| `formatByType.measurement.className` | optional | `string` | `SpecifyMeasurement` | Name of the class encapsulating your measurement design tokens. |
46+
| `formatByType.measurement.fileName` | optional | `string` | `measurements.dart` | Name of the Dart file containing your measurement design tokens. |
47+
| `formatByType.measurement.classType` | optional | `string` | `double` | Type that will be assigned to the generated measurement variables. |
48+
| `formatByType.textStyle.className` | optional | `string` | `SpecifyTextStyle` | Name of the class encapsulating your textStyle design tokens. |
49+
| `formatByType.textStyle.fileName` | optional | `string` | `text-styles.dart` | Name of the Dart file containing your textStyle design tokens. |
50+
| `formatByType.textStyle.classType` | optional | `string` | `TextStyle` | Type that will be assigned to the generated textStyle variables. |
3951

4052
## Types
4153

@@ -93,6 +105,39 @@ type output = string;
93105
"measure": 4
94106
},
95107
"type": "measurement"
108+
},
109+
{
110+
"name": "heading",
111+
"value": {
112+
"font": {
113+
"value": {
114+
"fontFamilly": "Roboto",
115+
"isItalic": true,
116+
"fontWeight": 500
117+
}
118+
},
119+
"fontSize": {
120+
"value": {
121+
"measure": 12,
122+
"unit": "px"
123+
}
124+
},
125+
"textDecoration": ["line-through"],
126+
"letterSpacing": {
127+
"value": {
128+
"measure": 10
129+
}
130+
},
131+
"color": {
132+
"value": {
133+
"a": 1,
134+
"b": 255,
135+
"g": 255,
136+
"r": 0
137+
}
138+
}
139+
},
140+
"type": "textStyle"
96141
}
97142
]
98143
```
@@ -106,7 +151,7 @@ import 'dart:ui';
106151
class SpecifyColor {
107152
SpecifyColor._();
108153
109-
static const colorsBlack = Color(0x1E212BFF);
154+
static const Color colorsBlack = Color(0x1E212BFF);
110155
}
111156
```
112157

@@ -117,10 +162,28 @@ import 'dart:ui';
117162
class SpecifyMeasurement {
118163
SpecifyMeasurement._();
119164
120-
static const baseSpace01 = 8.00;
165+
static const double baseSpace01 = 8.00;
121166
}
122167
```
123168

169+
```dart
170+
// textStyles.dart
171+
import 'dart:ui';
172+
173+
class SpecifyTextStyle {
174+
SpecifyTextStyle._();
175+
176+
static const TextStyle heading = TextStyle(
177+
fontFamily: 'Roboto',
178+
fontSize: 12.00,
179+
fontStyle: FontStyle.italic,
180+
fontWeight: FontWeight.w500,
181+
decoration: TextDecoration.lineThrough,
182+
letterSpacing: 10.00,
183+
color: Color(0xFFFFFF00),
184+
);
185+
```
186+
124187
## Complex usage - with options
125188

126189
### Config
@@ -133,13 +196,20 @@ class SpecifyMeasurement {
133196
"formatByType": {
134197
"color": {
135198
"className": "LightTheme",
136-
"fileName": "custom-colors-file-name.dart"
199+
"fileName": "custom-colors-file-name.dart",
200+
"classType": "MyColor"
137201
},
138202
"measurement": {
139203
"devicePixelRatio": 3.0,
140204
"className": "CustomTheme",
141-
"fileName": "custom-measurement-file-name.dart"
142-
}
205+
"fileName": "custom-measurement-file-name.dart",
206+
"classType": "twice"
207+
},
208+
"textStyle": {
209+
"className": "CustomStyle",
210+
"fileName": "custom-text-styles-file-name.dart",
211+
"classType": "CoolText"
212+
},
143213
}
144214
}
145215
}
@@ -170,6 +240,26 @@ class SpecifyMeasurement {
170240
"measure": 4
171241
},
172242
"type": "measurement"
243+
},
244+
{
245+
"name": "body",
246+
"value": {
247+
"font": {
248+
"value": {
249+
"fontFamilly": "Inter",
250+
"isItalic": false,
251+
"fontWeight": 100
252+
}
253+
},
254+
"fontSize": {
255+
"value": {
256+
"measure": 1,
257+
"unit": "px"
258+
}
259+
},
260+
"textDecoration": ["underline"]
261+
},
262+
"type": "textStyle"
173263
}
174264
]
175265
```
@@ -183,7 +273,7 @@ import 'dart:ui';
183273
class LightTheme {
184274
LightTheme._();
185275
186-
static const colorsBlack = Color(0x1E212BFF);
276+
static const MyColor colorsBlack = Color(0x1E212BFF);
187277
}
188278
```
189279

@@ -194,6 +284,22 @@ import 'dart:ui';
194284
class CustomTheme {
195285
CustomTheme._();
196286
197-
static const baseSpace01 = 12.00;
287+
static const twice baseSpace01 = 12.00;
198288
}
199289
```
290+
291+
```dart
292+
// custom-text-styles-file-name.dart
293+
import 'dart:ui';
294+
295+
class CustomStyle {
296+
CustomStyle._();
297+
298+
static const CoolText body = TextStyle(
299+
fontFamily: 'Inter',
300+
fontSize: 1.00,
301+
fontStyle: FontStyle.normal,
302+
fontWeight: FontWeight.w100,
303+
decoration: TextDecoration.underline,
304+
);
305+
```

0 commit comments

Comments
 (0)