Skip to content

Commit a4bf0ee

Browse files
authored
design tokens : fix documentation and unit conversion (#799)
1 parent 0cbc1b1 commit a4bf0ee

File tree

12 files changed

+25
-17
lines changed

12 files changed

+25
-17
lines changed

plugins/postcss-design-tokens/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changes to PostCSS Design Tokens
22

3+
### Unreleased
4+
5+
- Fix unit conversion
6+
37
### 2.0.0 (January 24, 2023)
48

59
- Updated: Support for Node v14+ (major).

plugins/postcss-design-tokens/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"size": {
1515
"spacing": {
1616
"small": { "value": "16px" },
17-
"medium": { "value": "18px" }
17+
"medium": { "value": "18px" },
18+
"medium-alias": { "value": "{size.spacing.medium}" }
1819
}
1920
},
2021
"viewport": {
@@ -35,7 +36,7 @@
3536
3637
@media (min-width: design-token('viewport.medium')) {
3738
.foo {
38-
padding-bottom: design-token('size.spacing.medium' to rem);
39+
padding-bottom: design-token('size.spacing.medium-alias' to rem);
3940
}
4041
}
4142
@@ -50,7 +51,7 @@
5051
5152
@media (min-width: 35rem) {
5253
.foo {
53-
padding-bottom: 1.1rem;
54+
padding-bottom: 1.125rem;
5455
}
5556
}
5657
```
@@ -212,7 +213,7 @@ postcssDesignTokens({
212213
213214
@media (min-width: design-token('viewport.medium')) {
214215
.foo {
215-
padding-bottom: design-token('size.spacing.medium' to rem);
216+
padding-bottom: design-token('size.spacing.medium-alias' to rem);
216217
}
217218
}
218219
@@ -227,7 +228,7 @@ postcssDesignTokens({
227228
228229
@media (min-width: 35rem) {
229230
.foo {
230-
padding-bottom: 0.9rem;
231+
padding-bottom: 0.9rem;
231232
}
232233
}
233234
```

plugins/postcss-design-tokens/dist/index.cjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

plugins/postcss-design-tokens/dist/index.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

plugins/postcss-design-tokens/src/data-formats/style-dictionary/v3/value.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,17 @@ function formatFloat(value: number): string {
131131
}
132132

133133
let fixedPrecision = value.toFixed(5);
134-
for (let i = fixedPrecision.length; i > 0; i--) {
134+
for (let i = fixedPrecision.length - 1; i >= 0; i--) {
135135
if (fixedPrecision[i] === '.') {
136136
break;
137137
}
138138

139-
if (fixedPrecision[i] !== '0') {
140-
fixedPrecision = fixedPrecision.slice(0, i + 1);
139+
if (fixedPrecision[i] === '0') {
140+
fixedPrecision = fixedPrecision.slice(0, i);
141141
continue;
142142
}
143+
144+
break;
143145
}
144146

145147
return fixedPrecision;

plugins/postcss-design-tokens/test/examples/example.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
@media (min-width: design-token('viewport.medium')) {
1111
.foo {
12-
padding-bottom: design-token('size.spacing.medium' to rem);
12+
padding-bottom: design-token('size.spacing.medium-alias' to rem);
1313
}
1414
}

plugins/postcss-design-tokens/test/examples/example.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77

88
@media (min-width: 35rem) {
99
.foo {
10-
padding-bottom: 1.1rem;
10+
padding-bottom: 1.125rem;
1111
}
1212
}

plugins/postcss-design-tokens/test/examples/example.rootFontSize-20.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77

88
@media (min-width: 35rem) {
99
.foo {
10-
padding-bottom: 0.9rem;
10+
padding-bottom: 0.9rem;
1111
}
1212
}

plugins/postcss-design-tokens/test/examples/tokens.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"size": {
88
"spacing": {
99
"small": { "value": "16px" },
10-
"medium": { "value": "18px" }
10+
"medium": { "value": "18px" },
11+
"medium-alias": { "value": "{size.spacing.medium}" }
1112
}
1213
},
1314
"viewport": {

plugins/postcss-design-tokens/test/units.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
.px-to-rem {
1010
padding-bottom: 0.5rem;
11-
padding-bottom: 1.1rem;
11+
padding-bottom: 1.125rem;
1212
padding-bottom: 2rem;
1313
}
1414

plugins/postcss-design-tokens/test/units.rootFontSize-NaN.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
.px-to-rem {
1010
padding-bottom: 0.5rem;
11-
padding-bottom: 1.1rem;
11+
padding-bottom: 1.125rem;
1212
padding-bottom: 2rem;
1313
}
1414

plugins/postcss-design-tokens/test/units.rootFontSize-invalid.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
.px-to-rem {
1010
padding-bottom: 0.5rem;
11-
padding-bottom: 1.1rem;
11+
padding-bottom: 1.125rem;
1212
padding-bottom: 2rem;
1313
}
1414

0 commit comments

Comments
 (0)