Skip to content

Instantly share code, notes, and snippets.

@dbanksdesign
Created November 18, 2020 23:31
Show Gist options
  • Save dbanksdesign/24ba5a2a8651998c76403507ab4e7cf7 to your computer and use it in GitHub Desktop.
Save dbanksdesign/24ba5a2a8651998c76403507ab4e7cf7 to your computer and use it in GitHub Desktop.
Style Dictionary Custom attribute/cti
const StyleDictionary = require('style-dictionary');
const attributeCTI = StyleDictionary.transform['attribute/cti'].transformer;
const cssToCTIMap = {
'width': {category: 'size', type: 'dimension'},
'min-width': {category: 'size', type: 'dimension'},
'max-width': {category: 'size', type: 'dimension'},
'height': {category: 'size', type: 'dimension'},
'min-height': {category: 'size', type: 'dimension'},
'max-height': {category: 'size', type: 'dimension'},
'border-width': {category: 'size', type: 'border', item: 'width'},
'border-color': {category: 'color', type: 'border'},
'background-color': {category: 'color', type: 'background'},
'color': {category: 'color', type: 'font'},
'padding': {category: 'size', type: 'padding'},
'padding-vertical': {category: 'size', type: 'padding'},
'padding-horziontal': {category: 'size', type: 'padding'},
'padding-top': {category: 'size', type: 'padding'},
'padding-right': {category: 'size', type: 'padding'},
'padding-bottom': {category: 'size', type: 'padding'},
'padding-left': {category: 'size', type: 'padding'},
'icon': {category: 'content', type: 'icon'},
'font-size': {category: 'size', type: 'font'},
'font-color': {category: 'color', type: 'font'}
}
StyleDictionary.registerTransform({
type: 'attribute',
name: 'attribute/cti',
transformer: function(prop) {
if (prop.path[0] === 'component') {
return cssToCTIMap[prop.name];
} else {
return attributeCTI(prop);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment