-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add support for UIColor format in ts/color/modifiers
- Loading branch information
1 parent
e3d89fe
commit 67b9171
Showing
7 changed files
with
166 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@tokens-studio/sd-transforms': patch | ||
--- | ||
|
||
Workaround fix in color modifiers transform to allow UIColor format. This workaround should be removed (in a breaking change) if https://github.com/amzn/style-dictionary/issues/1063 gets resolved and post-transitive transforms become a thing. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { expect } from '@esm-bundle/chai'; | ||
import StyleDictionary from 'style-dictionary'; | ||
import Color from 'tinycolor2'; | ||
import { promises } from 'fs'; | ||
import path from 'path'; | ||
import { cleanup, init } from './utils.js'; | ||
|
||
const outputDir = 'test/integration/tokens/'; | ||
const outputFileName = 'vars.css'; | ||
const outputFilePath = path.resolve(outputDir, outputFileName); | ||
|
||
StyleDictionary.registerTransform({ | ||
name: 'transitive/color/UIColorSwift', | ||
type: 'value', | ||
transitive: true, | ||
transformer: token => { | ||
const { r, g, b, a } = Color(token.value).toRgb(); | ||
const rFixed = (r / 255.0).toFixed(3); | ||
const gFixed = (g / 255.0).toFixed(3); | ||
const bFixed = (b / 255.0).toFixed(3); | ||
return `UIColor(red: ${rFixed}, green: ${gFixed}, blue: ${bFixed}, alpha: ${a})`; | ||
}, | ||
}); | ||
|
||
const cfg = { | ||
source: ['test/integration/tokens/swift-UI-colors.tokens.json'], | ||
platforms: { | ||
css: { | ||
transforms: [ | ||
'ts/color/modifiers', | ||
'attribute/cti', | ||
'transitive/color/UIColorSwift', | ||
'name/cti/camel', | ||
], | ||
buildPath: outputDir, | ||
files: [ | ||
{ | ||
destination: outputFileName, | ||
format: 'ios-swift/class.swift', | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
|
||
let dict: StyleDictionary.Core | undefined; | ||
|
||
describe('outputReferences integration', () => { | ||
beforeEach(() => { | ||
if (dict) { | ||
cleanup(dict); | ||
} | ||
dict = init(cfg, { 'ts/color/modifiers': { format: 'hex' } }); | ||
}); | ||
|
||
afterEach(() => { | ||
if (dict) { | ||
cleanup(dict); | ||
} | ||
}); | ||
|
||
it('supports UIColor with color modifiers', async () => { | ||
const file = await promises.readFile(outputFilePath, 'utf-8'); | ||
console.log(file); | ||
expect(file).to | ||
.include(` public static let colorDanger = UIColor(red: 0.251, green: 0.000, blue: 0.000, alpha: 1) | ||
public static let colorError = UIColor(red: 0.125, green: 0.000, blue: 0.000, alpha: 1) | ||
public static let colorRed = UIColor(red: 1.000, green: 0.000, blue: 0.000, alpha: 1)`); | ||
}); | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"color": { | ||
"red": { | ||
"value": "#f00", | ||
"type": "color" | ||
}, | ||
"danger": { | ||
"value": "{color.red}", | ||
"type": "color", | ||
"$extensions": { | ||
"studio.tokens": { | ||
"modify": { | ||
"type": "darken", | ||
"value": "0.75", | ||
"space": "hsl" | ||
} | ||
} | ||
} | ||
}, | ||
"error": { | ||
"value": "{color.danger}", | ||
"type": "color", | ||
"$extensions": { | ||
"studio.tokens": { | ||
"modify": { | ||
"type": "darken", | ||
"value": "0.5", | ||
"space": "hsl" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains 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