Skip to content

Commit 261a2cb

Browse files
authoredJun 4, 2024··
timingFunction and fontFamily props, optional border props (#1229)
* fix: support optional props border tokens * fix: handle timingFunction and fontFamily props in transforms
1 parent 04c3377 commit 261a2cb

File tree

8 files changed

+196
-72
lines changed

8 files changed

+196
-72
lines changed
 

‎.changeset/strong-tools-draw.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'style-dictionary': minor
3+
---
4+
5+
Handle transition timingFunction prop in cubicBezier/css transform. Handle typography fontFamily prop in fontFamily/css transform.

‎.changeset/witty-glasses-hear.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'style-dictionary': patch
3+
---
4+
5+
Allow border type tokens to be empty, every property is optional.

‎__tests__/cleanDir.test.js

-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ import StyleDictionary from '../lib/StyleDictionary.js';
1616
import cleanFile from '../lib/cleanFile.js';
1717
import cleanDir from '../lib/cleanDir.js';
1818

19-
function format() {
20-
return 'hi';
21-
}
22-
2319
describe('cleanDir', () => {
2420
beforeEach(() => {
2521
clearOutput();

‎__tests__/common/transforms.test.js

+111-36
Original file line numberDiff line numberDiff line change
@@ -1049,39 +1049,132 @@ describe('common', () => {
10491049
});
10501050

10511051
describe('fontFamily/css', () => {
1052-
const fontFamilyTransform = (value) =>
1053-
transforms['fontFamily/css'].transform({ value }, {}, {});
1052+
const fontFamilyTransform = (token) => transforms['fontFamily/css'].transform(token, {}, {});
10541053

10551054
it('should handle simple fontFamily as is', () => {
1056-
expect(fontFamilyTransform('Arial')).to.equal('Arial');
1055+
expect(fontFamilyTransform({ value: 'Arial', type: 'fontFamily' })).to.equal('Arial');
10571056
});
10581057

10591058
it('should comma separated type fontFamily values', () => {
1060-
expect(fontFamilyTransform('Arial, sans-serif')).to.equal('Arial, sans-serif');
1059+
expect(fontFamilyTransform({ value: 'Arial, sans-serif', type: 'fontFamily' })).to.equal(
1060+
'Arial, sans-serif',
1061+
);
10611062
});
10621063

10631064
it('should handle array type fontFamily values', () => {
1064-
expect(fontFamilyTransform(['Arial', 'sans-serif'])).to.equal('Arial, sans-serif');
1065+
expect(
1066+
fontFamilyTransform({ value: ['Arial', 'sans-serif'], type: 'fontFamily' }),
1067+
).to.equal('Arial, sans-serif');
10651068
});
10661069

10671070
it('should wrap fontFamily values with spaces in quotes', () => {
1068-
expect(fontFamilyTransform('Gill Sans')).to.equal("'Gill Sans'");
1069-
expect(fontFamilyTransform('Gill Sans, Arial, Comic Sans, Open Sans, sans-serif')).to.equal(
1070-
"'Gill Sans', Arial, 'Comic Sans', 'Open Sans', sans-serif",
1071+
expect(fontFamilyTransform({ value: 'Gill Sans', type: 'fontFamily' })).to.equal(
1072+
"'Gill Sans'",
10711073
);
10721074
expect(
1073-
fontFamilyTransform(['Gill Sans', 'Arial', 'Comic Sans', 'Open Sans', 'sans-serif']),
1075+
fontFamilyTransform({
1076+
value: 'Gill Sans, Arial, Comic Sans, Open Sans, sans-serif',
1077+
type: 'fontFamily',
1078+
}),
1079+
).to.equal("'Gill Sans', Arial, 'Comic Sans', 'Open Sans', sans-serif");
1080+
expect(
1081+
fontFamilyTransform({
1082+
value: ['Gill Sans', 'Arial', 'Comic Sans', 'Open Sans', 'sans-serif'],
1083+
type: 'fontFamily',
1084+
}),
10741085
).to.equal("'Gill Sans', Arial, 'Comic Sans', 'Open Sans', sans-serif");
10751086
});
1087+
1088+
it('should handle fontFamily prop within typography tokens', () => {
1089+
expect(
1090+
fontFamilyTransform({
1091+
value: {
1092+
fontFamily: ['Gill Sans', 'sans-serif'],
1093+
fontWeight: 300,
1094+
fontSize: '20px',
1095+
lineHeight: '1.5',
1096+
},
1097+
type: 'typography',
1098+
}),
1099+
).to.eql({
1100+
fontFamily: "'Gill Sans', sans-serif",
1101+
fontWeight: 300,
1102+
fontSize: '20px',
1103+
lineHeight: '1.5',
1104+
});
1105+
1106+
expect(
1107+
fontFamilyTransform({
1108+
value: {
1109+
fontWeight: 300,
1110+
fontSize: '20px',
1111+
lineHeight: '1.5',
1112+
},
1113+
type: 'typography',
1114+
}),
1115+
).to.eql({
1116+
fontWeight: 300,
1117+
fontSize: '20px',
1118+
lineHeight: '1.5',
1119+
});
1120+
});
10761121
});
10771122

10781123
describe('cubicBezier/css', () => {
1079-
const cubicBezierTransform = (value) =>
1080-
transforms['cubicBezier/css'].transform({ value }, {}, {});
1124+
const cubicBezierTransform = (token) =>
1125+
transforms['cubicBezier/css'].transform(token, {}, {});
10811126

10821127
it('should stringify cubicBezier values to cubicBezier() CSS function', () => {
1083-
expect(cubicBezierTransform([0.5, 0, 1, 1])).to.equal('cubic-bezier(0.5, 0, 1, 1)');
1084-
expect('ease-in-out').to.equal('ease-in-out');
1128+
expect(cubicBezierTransform({ value: [0.5, 0, 1, 1], type: 'cubicBezier' })).to.equal(
1129+
'cubic-bezier(0.5, 0, 1, 1)',
1130+
);
1131+
expect(cubicBezierTransform({ value: 'ease-in-out', type: 'cubicBezier' })).to.equal(
1132+
'ease-in-out',
1133+
);
1134+
});
1135+
1136+
it('should stringify transition token cubicBezier properties to cubicBezier() CSS function', () => {
1137+
expect(
1138+
cubicBezierTransform({
1139+
value: {
1140+
duration: '200ms',
1141+
delay: '0ms',
1142+
timingFunction: [0.5, 0, 1, 1],
1143+
},
1144+
type: 'transition',
1145+
}),
1146+
).to.eql({
1147+
duration: '200ms',
1148+
delay: '0ms',
1149+
timingFunction: 'cubic-bezier(0.5, 0, 1, 1)',
1150+
});
1151+
expect(
1152+
cubicBezierTransform({
1153+
value: {
1154+
duration: '200ms',
1155+
delay: '0ms',
1156+
timingFunction: 'ease-in-out',
1157+
},
1158+
type: 'transition',
1159+
}),
1160+
).to.eql({
1161+
duration: '200ms',
1162+
delay: '0ms',
1163+
timingFunction: 'ease-in-out',
1164+
});
1165+
1166+
expect(
1167+
cubicBezierTransform({
1168+
value: {
1169+
duration: '200ms',
1170+
delay: '0ms',
1171+
},
1172+
type: 'transition',
1173+
}),
1174+
).to.eql({
1175+
duration: '200ms',
1176+
delay: '0ms',
1177+
});
10851178
});
10861179
});
10871180

@@ -1118,28 +1211,6 @@ describe('common', () => {
11181211
expect(typographyTransform({})).to.equal('16px sans-serif');
11191212
expect(typographyTransform({}, { basePxFontSize: 12 })).to.equal('12px sans-serif');
11201213
});
1121-
1122-
it('sets quotes around fontFamily if it has white-spaces in name', () => {
1123-
expect(
1124-
typographyTransform({
1125-
fontWeight: 300,
1126-
fontSize: '20px',
1127-
lineHeight: '1.5',
1128-
fontFamily: 'Arial Narrow, Arial, sans-serif',
1129-
}),
1130-
).to.equal("300 20px/1.5 'Arial Narrow', Arial, sans-serif");
1131-
});
1132-
1133-
it('handles array fontFamily values', () => {
1134-
expect(
1135-
typographyTransform({
1136-
fontWeight: 300,
1137-
fontSize: '20px',
1138-
lineHeight: '1.5',
1139-
fontFamily: ['Arial Narrow', 'Arial', 'sans-serif'],
1140-
}),
1141-
).to.equal("300 20px/1.5 'Arial Narrow', Arial, sans-serif");
1142-
});
11431214
});
11441215

11451216
// https://design-tokens.github.io/community-group/format/#border
@@ -1170,6 +1241,10 @@ describe('common', () => {
11701241
}),
11711242
).to.equal('5px dashed #000000');
11721243
});
1244+
1245+
it('allows every property to be optional', () => {
1246+
expect(borderTransform({})).to.equal('none');
1247+
});
11731248
});
11741249

11751250
describe('strokeStyle/css/shorthand', () => {
@@ -1197,7 +1272,7 @@ describe('common', () => {
11971272
transitionTransform({
11981273
duration: '200ms',
11991274
delay: '0ms',
1200-
timingFunction: [0.5, 0, 1, 1],
1275+
timingFunction: 'cubic-bezier(0.5, 0, 1, 1)',
12011276
}),
12021277
).to.equal('200ms cubic-bezier(0.5, 0, 1, 1) 0ms');
12031278

‎__tests__/exportPlatform.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ Use log.verbosity "verbose" or use CLI option --verbose for more details.
651651
},
652652
platforms: {
653653
css: {
654-
transforms: ['transition/css/shorthand'],
654+
transforms: ['cubicBezier/css', 'transition/css/shorthand'],
655655
},
656656
},
657657
});
@@ -678,7 +678,7 @@ Use log.verbosity "verbose" or use CLI option --verbose for more details.
678678
},
679679
platforms: {
680680
css: {
681-
transforms: ['transition/css/shorthand'],
681+
transforms: ['cubicBezier/css', 'transition/css/shorthand'],
682682
},
683683
},
684684
});

‎docs/src/content/docs/reference/Hooks/Transforms/predefined.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -519,12 +519,13 @@ Assumes a time in miliseconds and transforms it into a decimal
519519
### fontFamily/css
520520

521521
Transforms `fontFamily` type token (which can be an array) into a CSS string, putting single quotes around font names that contain spaces where necessary.
522+
Also handles the `fontFamily` property inside `typography` type object-values.
522523

523524
[DTCG definition](https://design-tokens.github.io/community-group/format/#font-family)
524525

525526
```css
526527
/**
527-
* Matches: token.type === 'fontFamily'
528+
* Matches: token.type === 'fontFamily' || token.type === 'typography'
528529
* Returns:
529530
*/
530531
:root {
@@ -537,12 +538,13 @@ Transforms `fontFamily` type token (which can be an array) into a CSS string, pu
537538
### cubicBezier/css
538539

539540
Transforms `cubicBezier` type token into a CSS string, using the CSS `cubic-bezier` function.
541+
Also handles the `timingFunction` property inside `transition` type object-values.
540542

541543
[DTCG definition](https://design-tokens.github.io/community-group/format/#cubic-bezier)
542544

543545
```css
544546
/**
545-
* Matches: token.type === 'cubicBezier'
547+
* Matches: token.type === 'cubicBezier' || token.type === 'transition'
546548
* Returns:
547549
*/
548550
:root {

0 commit comments

Comments
 (0)
Please sign in to comment.