Skip to content

Commit

Permalink
fix radii export
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasoppermann committed Sep 29, 2020
1 parent ad506f6 commit 23b3408
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 48 deletions.
69 changes: 22 additions & 47 deletions src/extractor/extractRadii.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,59 +14,34 @@ const extractRadii: extractorInterface = (tokenNodes: customTokenNodes[]): radiu
return 'mixed'
}
// get the individual radii
const getRadii = (node) => {
if (typeof node.cornerRadius !== 'number') {
return {
topLeft: {
value: node.topLeftRadius || 0,
unit: 'pixel' as UnitTypePixel,
type: 'number' as propertyType
},
topRight: {
value: node.topRightRadius || 0,
unit: 'pixel' as UnitTypePixel,
type: 'number' as propertyType
},
bottomRight: {
value: node.bottomRightRadius || 0,
unit: 'pixel' as UnitTypePixel,
type: 'number' as propertyType
},
bottomLeft: {
value: node.bottomLeftRadius || 0,
unit: 'pixel' as UnitTypePixel,
type: 'number' as propertyType
}
}
const getRadii = (node) => ({
topLeft: {
value: node.topLeftRadius || 0,
unit: 'pixel' as UnitTypePixel,
type: 'number' as propertyType
},
topRight: {
value: node.topRightRadius || 0,
unit: 'pixel' as UnitTypePixel,
type: 'number' as propertyType
},
bottomRight: {
value: node.bottomRightRadius || 0,
unit: 'pixel' as UnitTypePixel,
type: 'number' as propertyType
},
bottomLeft: {
value: node.bottomLeftRadius || 0,
unit: 'pixel' as UnitTypePixel,
type: 'number' as propertyType
}
return {
topLeft: {
value: node.cornerRadius,
unit: 'pixel' as UnitTypePixel,
type: 'number' as propertyType
},
topRight: {
value: node.cornerRadius,
unit: 'pixel' as UnitTypePixel,
type: 'number' as propertyType
},
bottomRight: {
value: node.cornerRadius,
unit: 'pixel' as UnitTypePixel,
type: 'number' as propertyType
},
bottomLeft: {
value: node.cornerRadius,
unit: 'pixel' as UnitTypePixel,
type: 'number' as propertyType
}
}
}
})
// return as object
return tokenNodes.filter(node => node.name.substr(0, nodeName.length) === nodeName ).map(node => ({
name: node.name,
// @ts-ignore
description: node.description || null,
category: 'radius',
values: {
...(typeof node.cornerRadius === "number" && {
radius: {
Expand Down
20 changes: 19 additions & 1 deletion src/transformer/amazonStyleDictionaryTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const sizeTransformer = propertyGroupValues => {
const colorTransformer = propertyGroupValues => {
return amazonFormat(propertyGroupValues['fill'])
}

const gradientTransformer = propertyGroupValues => {
const transformedProperties = {
gradientType: amazonFormat(propertyGroupValues.gradientType),
Expand All @@ -44,6 +45,22 @@ const gradientTransformer = propertyGroupValues => {
return transformedProperties
}

const radiusTransformer = propertyGroupValues => {
const transformedProperties = {}
// prepare radii
Object.entries(propertyGroupValues.radii).forEach(entry => {
const [key, value] = entry
transformedProperties[`radius-${key}`] = amazonFormat(value)
});
delete propertyGroupValues.radii
// transform rest of properties
Object.keys(propertyGroupValues).forEach(function (key) {
transformedProperties[key] = amazonFormat(propertyGroupValues[key])
})

return transformedProperties
}

const arrayTransformer = propertyGroupValueGroups => {
if (propertyGroupValueGroups.length === 1) {
return defaultTransformer(propertyGroupValueGroups[0])
Expand All @@ -57,7 +74,8 @@ const categoryTransformer = {
color: colorTransformer,
gradient: gradientTransformer,
grid: arrayTransformer,
effect: arrayTransformer
effect: arrayTransformer,
radius: radiusTransformer
}

const amazonConvertValue = (value, type: string) => {
Expand Down

0 comments on commit 23b3408

Please sign in to comment.