-
Notifications
You must be signed in to change notification settings - Fork 569
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support w3c special properties (#1081)
- Loading branch information
1 parent
3138313
commit 294fd0e
Showing
55 changed files
with
879 additions
and
431 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 @@ | ||
--- | ||
'style-dictionary': minor | ||
--- | ||
|
||
Support W3C Draft specification for Design Tokens, by adding support for $value, $type and $description properties. |
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
16 changes: 16 additions & 0 deletions
16
__integration__/__snapshots__/w3c-forward-compat.test.snap.js
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,16 @@ | ||
/* @web/test-runner snapshot v1 */ | ||
export const snapshots = {}; | ||
|
||
snapshots["should match snapshot"] = | ||
`/** | ||
* Do not edit directly | ||
* Generated on Sat, 01 Jan 2000 00:00:00 GMT | ||
*/ | ||
:root { | ||
--colors-black-500: rgb(0, 0, 0); | ||
--colors-black-dimension: 5px; /* Some description */ | ||
} | ||
`; | ||
/* end snapshot should match snapshot */ | ||
|
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,92 @@ | ||
/* | ||
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with | ||
* the License. A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions | ||
* and limitations under the License. | ||
*/ | ||
import { expect } from 'chai'; | ||
import StyleDictionary from 'style-dictionary'; | ||
import { fs } from 'style-dictionary/fs'; | ||
import Color from 'tinycolor2'; | ||
import { resolve } from '../lib/resolve.js'; | ||
import { buildPath } from './_constants.js'; | ||
import { clearOutput } from '../__tests__/__helpers.js'; | ||
|
||
describe('integration', () => { | ||
afterEach(() => { | ||
clearOutput(buildPath); | ||
}); | ||
|
||
/** | ||
* Integration test for forward compatibility with https://design-tokens.github.io/community-group/format/ | ||
* - $value special property | ||
* - $type special property & inherits from ancestors | ||
* - $description special property | ||
*/ | ||
describe('W3C DTCG draft spec forward compatibility', async () => { | ||
const sd = new StyleDictionary({ | ||
tokens: { | ||
colors: { | ||
$type: 'color', // $type should be inherited by the children | ||
black: { | ||
500: { | ||
$value: '#000000', // $value should work | ||
value: {}, // should be allowed as $ prop takes precedence -> bad practice though | ||
type: 'dimension', // should be allowed as the inherited $type takes precedence -> bad practice though | ||
}, | ||
dimension: { | ||
$value: '5', | ||
value: 'something else', // should be allowed as $ prop takes precedence -> bad practice though | ||
$type: 'dimension', | ||
type: 'color', // should be allowed as $ prop takes precedence -> bad practice though | ||
$description: 'Some description', | ||
}, | ||
}, | ||
}, | ||
}, | ||
transform: { | ||
'custom/css/color': { | ||
type: 'value', | ||
matcher: (token) => token.$type === 'color', | ||
transformer: (token) => { | ||
return Color(token.$value).toRgbString(); | ||
}, | ||
}, | ||
'custom/add/px': { | ||
type: 'value', | ||
matcher: (token) => token.$type === 'dimension', | ||
transformer: (token) => { | ||
return `${token.$value}px`; | ||
}, | ||
}, | ||
}, | ||
platforms: { | ||
css: { | ||
transforms: ['name/cti/kebab', 'custom/css/color', 'custom/add/px'], | ||
buildPath, | ||
files: [ | ||
{ | ||
destination: 'vars.css', | ||
format: 'css/variables', | ||
}, | ||
], | ||
}, | ||
}, | ||
}); | ||
await sd.buildAllPlatforms(); | ||
|
||
const output = fs.readFileSync(resolve(`${buildPath}vars.css`), { | ||
encoding: `UTF-8`, | ||
}); | ||
|
||
it(`should match snapshot`, async () => { | ||
await expect(output).to.matchSnapshot(); | ||
}); | ||
}); | ||
}); |
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
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
Oops, something went wrong.