Created
November 18, 2020 23:31
-
-
Save dbanksdesign/24ba5a2a8651998c76403507ab4e7cf7 to your computer and use it in GitHub Desktop.
Style Dictionary Custom attribute/cti
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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