Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tahul committed Oct 4, 2023
2 parents 658ca5c + 53edf84 commit ccb7c6e
Show file tree
Hide file tree
Showing 26 changed files with 380 additions and 153 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# See https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners
* @amzn/style-dictionary
2 changes: 0 additions & 2 deletions __integration__/__snapshots__/compose.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ exports[`integration > compose > compose/object > should match snapshot 1`] = `
package com.example.tokens;
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.*
Expand Down Expand Up @@ -191,7 +190,6 @@ exports[`integration > compose > compose/object > with references > should match
package com.example.tokens;
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.*
Expand Down
15 changes: 9 additions & 6 deletions __integration__/__snapshots__/customFileHeader.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ exports[`integration > valid custom file headers > platform options > file heade
* Header overridden
*/
export default {
module.exports = {
\\"color\\": {
\\"red\\": {
\\"value\\": \\"#ff0000\\",
Expand All @@ -60,7 +60,8 @@ export default {
]
}
}
};"
};
"
`;

exports[`integration > valid custom file headers > platform options > no file options should match snapshot 1`] = `
Expand All @@ -70,7 +71,7 @@ exports[`integration > valid custom file headers > platform options > no file op
* hello, world!
*/
export default {
module.exports = {
\\"color\\": {
\\"red\\": {
\\"value\\": \\"#ff0000\\",
Expand All @@ -88,11 +89,12 @@ export default {
]
}
}
};"
};
"
`;

exports[`integration > valid custom file headers > platform options > showFileHeader should match snapshot 1`] = `
"export default {
"module.exports = {
\\"color\\": {
\\"red\\": {
\\"value\\": \\"#ff0000\\",
Expand All @@ -110,5 +112,6 @@ exports[`integration > valid custom file headers > platform options > showFileHe
]
}
}
};"
};
"
`;
9 changes: 6 additions & 3 deletions __integration__/__snapshots__/flutter.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ class StyleDictionaryColor {
static const fontSuccess = Color(0xFF08422F);
static const fontTertiary = Color(0xFF364141);
static const fontWarning = Color(0xFF601700);
}"
}
"
`;

exports[`integration > flutter > flutter/class.dart > should match snapshot 1`] = `
Expand Down Expand Up @@ -350,7 +351,8 @@ class StyleDictionary {
static const sizePaddingMedium = 16.00;
static const sizePaddingSmall = 8.00;
static const sizePaddingXl = 16.00;
}"
}
"
`;

exports[`integration > flutter > flutter/class.dart > with references > should match snapshot 1`] = `
Expand Down Expand Up @@ -531,5 +533,6 @@ class StyleDictionary {
static const colorFontInteractiveActive = colorBrandSecondary;
static const colorFontInteractiveHover = colorBrandPrimary;
static const colorFontInteractive = colorBrandPrimary;
}"
}
"
`;
6 changes: 4 additions & 2 deletions __integration__/__snapshots__/objectValues.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,15 @@ exports[`integration > object values > scss/variables > should match snapshot 1`
// Do not edit directly
// Generated on Sat, 01 Jan 2000 00:00:00 GMT
$border-primary: 0.125rem solid #ff0000;"
$border-primary: 0.125rem solid #ff0000;
"
`;

exports[`integration > object values > scss/variables > with references > should match snapshot 1`] = `
"
// Do not edit directly
// Generated on Sat, 01 Jan 2000 00:00:00 GMT
$border-primary: $size-border solid $color-red;"
$border-primary: $size-border solid $color-red;
"
`;
12 changes: 8 additions & 4 deletions __integration__/__snapshots__/scss.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1507,7 +1507,8 @@ $color-background-danger: #ffeae9;
$color-background-warning: #ffede3;
$color-background-success: #ebf9eb;
$color-background-info: #e9f8ff;
$color-background-disabled: #dee1e1;"
$color-background-disabled: #dee1e1;
"
`;

exports[`integration > scss > scss/variables > with filter and output references > should match snapshot 1`] = `
Expand All @@ -1522,7 +1523,8 @@ $color-background-danger: $color-core-red-0;
$color-background-tertiary: $color-core-neutral-200;
$color-background-secondary: $color-core-neutral-100;
$color-background-primary: $color-core-neutral-0 !default;
$color-background-disabled: $color-background-tertiary;"
$color-background-disabled: $color-background-tertiary;
"
`;

exports[`integration > scss > scss/variables > with outputReferences > should match snapshot 1`] = `
Expand Down Expand Up @@ -1691,7 +1693,8 @@ $color-background-disabled: $color-background-tertiary;
$color-font-interactive-disabled: $color-font-tertiary;
$color-font-interactive-active: $color-brand-secondary;
$color-font-interactive-hover: $color-brand-primary;
$color-font-interactive: $color-brand-primary;"
$color-font-interactive: $color-brand-primary;
"
`;

exports[`integration > scss > scss/variables > with themeable > should match snapshot 1`] = `
Expand Down Expand Up @@ -1860,5 +1863,6 @@ $color-background-danger: #ffeae9 !default;
$color-background-warning: #ffede3 !default;
$color-background-success: #ebf9eb !default;
$color-background-info: #e9f8ff !default;
$color-background-disabled: #dee1e1 !default;"
$color-background-disabled: #dee1e1 !default;
"
`;
103 changes: 103 additions & 0 deletions __tests__/common/formatHelpers/createPropertyFormatter.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* 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 createPropertyFormatter from '../../../src/common/formatHelpers/createPropertyFormatter'
import createDictionary from '../../../src/utils/createDictionary'

const dictionary = createDictionary({
properties: {
tokens: {
foo: {
original: {
value: '5px',
type: 'spacing',
},
attributes: {
category: 'tokens',
type: 'foo',
},
name: 'tokens-foo',
path: ['tokens', 'foo'],
value: '5px',
type: 'spacing',
},
bar: {
original: {
value: '{tokens.foo}',
type: 'spacing',
},
attributes: {
category: 'tokens',
type: 'bar',
},
name: 'tokens-bar',
path: ['tokens', 'bar'],
value: '5px',
type: 'spacing',
},
},
},
})

const transformedDictionary = createDictionary({
properties: {
tokens: {
foo: {
original: {
value: '5px',
type: 'spacing',
},
attributes: {
category: 'tokens',
type: 'foo',
},
name: 'tokens-foo',
path: ['tokens', 'foo'],
value: '5px',
type: 'spacing',
},
bar: {
original: {
value: '{tokens.foo}',
type: 'spacing',
},
attributes: {
category: 'tokens',
type: 'bar',
},
name: 'tokens-bar',
path: ['tokens', 'bar'],
value: 'changed by transitive transform',
type: 'spacing',
},
},
},
})

describe('common', () => {
describe('formatHelpers', () => {
describe('createPropertyFormatter', () => {
it('should support outputReferences', () => {
const propFormatter = createPropertyFormatter({ outputReferences: true, dictionary, format: 'css' })
expect(propFormatter(dictionary.tokens.tokens.foo)).toEqual(' --tokens-foo: 5px;')
expect(propFormatter(dictionary.tokens.tokens.bar)).toEqual(' --tokens-bar: var(--tokens-foo);')
})

it('should support outputReferences when values are transformed by (transitive) "value" transforms', () => {
const propFormatter = createPropertyFormatter({ outputReferences: true, dictionary, format: 'css' })
expect(propFormatter(transformedDictionary.tokens.tokens.foo)).toEqual(' --tokens-foo: 5px;')
expect(propFormatter(transformedDictionary.tokens.tokens.bar)).toEqual(' --tokens-bar: var(--tokens-foo);')
})
})
})
})
Loading

0 comments on commit ccb7c6e

Please sign in to comment.