@@ -1049,39 +1049,132 @@ describe('common', () => {
1049
1049
} ) ;
1050
1050
1051
1051
describe ( 'fontFamily/css' , ( ) => {
1052
- const fontFamilyTransform = ( value ) =>
1053
- transforms [ 'fontFamily/css' ] . transform ( { value } , { } , { } ) ;
1052
+ const fontFamilyTransform = ( token ) => transforms [ 'fontFamily/css' ] . transform ( token , { } , { } ) ;
1054
1053
1055
1054
it ( 'should handle simple fontFamily as is' , ( ) => {
1056
- expect ( fontFamilyTransform ( 'Arial' ) ) . to . equal ( 'Arial' ) ;
1055
+ expect ( fontFamilyTransform ( { value : 'Arial' , type : 'fontFamily' } ) ) . to . equal ( 'Arial' ) ;
1057
1056
} ) ;
1058
1057
1059
1058
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
+ ) ;
1061
1062
} ) ;
1062
1063
1063
1064
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' ) ;
1065
1068
} ) ;
1066
1069
1067
1070
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'" ,
1071
1073
) ;
1072
1074
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
+ } ) ,
1074
1085
) . to . equal ( "'Gill Sans', Arial, 'Comic Sans', 'Open Sans', sans-serif" ) ;
1075
1086
} ) ;
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
+ } ) ;
1076
1121
} ) ;
1077
1122
1078
1123
describe ( 'cubicBezier/css' , ( ) => {
1079
- const cubicBezierTransform = ( value ) =>
1080
- transforms [ 'cubicBezier/css' ] . transform ( { value } , { } , { } ) ;
1124
+ const cubicBezierTransform = ( token ) =>
1125
+ transforms [ 'cubicBezier/css' ] . transform ( token , { } , { } ) ;
1081
1126
1082
1127
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
+ } ) ;
1085
1178
} ) ;
1086
1179
} ) ;
1087
1180
@@ -1118,28 +1211,6 @@ describe('common', () => {
1118
1211
expect ( typographyTransform ( { } ) ) . to . equal ( '16px sans-serif' ) ;
1119
1212
expect ( typographyTransform ( { } , { basePxFontSize : 12 } ) ) . to . equal ( '12px sans-serif' ) ;
1120
1213
} ) ;
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
- } ) ;
1143
1214
} ) ;
1144
1215
1145
1216
// https://design-tokens.github.io/community-group/format/#border
@@ -1170,6 +1241,10 @@ describe('common', () => {
1170
1241
} ) ,
1171
1242
) . to . equal ( '5px dashed #000000' ) ;
1172
1243
} ) ;
1244
+
1245
+ it ( 'allows every property to be optional' , ( ) => {
1246
+ expect ( borderTransform ( { } ) ) . to . equal ( 'none' ) ;
1247
+ } ) ;
1173
1248
} ) ;
1174
1249
1175
1250
describe ( 'strokeStyle/css/shorthand' , ( ) => {
@@ -1197,7 +1272,7 @@ describe('common', () => {
1197
1272
transitionTransform ( {
1198
1273
duration : '200ms' ,
1199
1274
delay : '0ms' ,
1200
- timingFunction : [ 0.5 , 0 , 1 , 1 ] ,
1275
+ timingFunction : 'cubic-bezier( 0.5, 0, 1, 1)' ,
1201
1276
} ) ,
1202
1277
) . to . equal ( '200ms cubic-bezier(0.5, 0, 1, 1) 0ms' ) ;
1203
1278
0 commit comments