Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tokens: Add XFN Component Tokens #3793

Merged
merged 37 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6e079de
Example badge tokens for testing
aarshap Sep 10, 2024
320e966
Explicitly named a set of test tokens for platform testing
aarshap Sep 10, 2024
8e6cf29
Merge pull request #5 from aarshap/component-token-test
rlingineni Sep 27, 2024
9424f71
fix formatting
rlingineni Sep 27, 2024
8ffdc63
wip: move files around
rlingineni Sep 27, 2024
c784070
working
rlingineni Sep 27, 2024
aef5e8b
wip: investigate missing tokens
rlingineni Sep 28, 2024
800f048
working web refactor
rlingineni Sep 28, 2024
436d769
fix token name
rlingineni Sep 28, 2024
29bf184
rename
rlingineni Sep 28, 2024
cc77e84
working overrides web
rlingineni Sep 28, 2024
e326094
clean file filter
rlingineni Sep 28, 2024
227be83
move android code
rlingineni Sep 28, 2024
aa3d718
make consistent with other files
rlingineni Sep 28, 2024
cdbc95c
clean
rlingineni Sep 28, 2024
0b2f4cc
working iOS config
rlingineni Sep 28, 2024
9c07fdf
fix all other files
rlingineni Sep 28, 2024
f63191a
move to src folder
rlingineni Sep 28, 2024
70a80f6
working android component tokens
rlingineni Sep 28, 2024
7a939bc
update iso file structure
rlingineni Sep 28, 2024
1756a12
working ios component tokens
rlingineni Sep 28, 2024
f9c3b12
Update getSources.js
rlingineni Sep 28, 2024
852152f
remove unused comp tokens
rlingineni Sep 30, 2024
18846cd
Merge branch 'master' into ravi-refactor-tokenscript
rlingineni Oct 1, 2024
24b618c
move fileheader
rlingineni Oct 2, 2024
f414eaa
typo
rlingineni Oct 2, 2024
00f5bf9
Merge branch 'master' into ravi-refactor-tokenscript
rlingineni Oct 2, 2024
8ac4f73
Update getSources.js
rlingineni Oct 2, 2024
5bc36be
Merge branch 'master' into ravi-refactor-tokenscript
rlingineni Oct 2, 2024
dd2982c
add XFN component tokens
rlingineni Oct 2, 2024
d0ab7c0
Update getSources.js
rlingineni Oct 8, 2024
a448a80
Merge branch 'master' into ravi-refactor-tokenscript
rlingineni Oct 8, 2024
39e9b63
Update web.test.js.snap
rlingineni Oct 8, 2024
3a80760
remove badge comp testing tokens
rlingineni Oct 8, 2024
03c133a
Merge branch 'master' into ravi-refactor-tokenscript
rlingineni Oct 16, 2024
5b819ef
move radiobutton comp tokens
rlingineni Oct 16, 2024
a6a7c11
Update ColorSchemeProvider.jsdom.test.tsx.snap
rlingineni Oct 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/gestalt-design-tokens/src/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ const filterColor = {
},
};

const filterComponentToken = (component) => ({
'filter': {
'attributes': {
'category': `${component}`,
},
},
});

const filterRounding = {
'filter': {
'attributes': {
Expand Down Expand Up @@ -176,4 +184,5 @@ module.exports = {
filterLineHeight,
filterMotionDuration,
filterMotionEasing,
filterComponentToken,
};
60 changes: 58 additions & 2 deletions packages/gestalt-design-tokens/src/getSources.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,57 @@
const fs = require('fs');

const getListOfComponents = (theme) => {
try {
const folders = fs.readdirSync(`tokens/${theme}/comp`);

const components = folders.filter((file) => !file.includes('.json'));
return components;
} catch (ex) {
// if this fails, it means there are no components
// eslint-disable-next-line no-console
console.log(`No component tokens found for theme ${theme}`);
return [];
}
};

const filterComponentTokenFiles = (theme, components, prefix) =>
components
.map((component) => {
const files = fs.readdirSync(`tokens/${theme}/comp/${component}`);
return files
.filter((file) => file.startsWith(prefix))
.map((file) => `tokens/${theme}/comp/${component}/${file}`);
})
.flat();

/**
* Gets the available files for component tokens
*/
function getComponentTokenSources(platform) {
const theme = 'vr-theme';
const components = getListOfComponents(theme);

const files = filterComponentTokenFiles(theme, components, 'default');

if (platform !== 'web') {
const mobileFiles = filterComponentTokenFiles(theme, components, 'mobile');
files.push(...mobileFiles);
}

return files;
}

/**
* Gets platform-specific component token files
* @param {*} platform - ios, android, web
* @returns
*/
function getComponentTokenOverrides(platform) {
const theme = 'vr-theme';
const components = getListOfComponents(theme);
return filterComponentTokenFiles(theme, components, platform);
}

function getSources({ theme, modeTheme, platform, language }) {
if (theme === 'classic') {
return [
Expand Down Expand Up @@ -32,6 +86,7 @@ function getSources({ theme, modeTheme, platform, language }) {
`tokens/vr-theme/sema/color/${modeTheme}/default.json`,
`tokens/vr-theme/sema/elevation/${modeTheme}.json`,
'tokens/vr-theme/sema/text/font.json',
...getComponentTokenSources(),
...(platform === 'web'
? [
'tokens/vr-theme/base/color/pressed.json',
Expand All @@ -46,8 +101,6 @@ function getSources({ theme, modeTheme, platform, language }) {
'tokens/vr-theme/sema/space.json',
`tokens/vr-theme/sema/text/language/${language}.json`,
'tokens/vr-theme/sema/motion.json',
'tokens/vr-theme/comp/spinner.json',
'tokens/vr-theme/comp/radiogroupbutton.json',
...(theme === 'vr-theme-web-mapping'
? [
`tokens/vr-theme-web-mapping/base-color-dataviz-${modeTheme}.json`,
Expand All @@ -69,4 +122,7 @@ function getSources({ theme, modeTheme, platform, language }) {

module.exports = {
getSources,
getComponentTokenSources,
getComponentTokenOverrides,
getListOfComponents,
};
28 changes: 25 additions & 3 deletions packages/gestalt-design-tokens/src/platforms/android.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { getSources } = require('../getSources');
const { optionsFileHeaderOutputReferences } = require('../headers/fileheader');
const { getSources, getComponentTokenOverrides, getListOfComponents } = require('../getSources');

const {
filterColor,
Expand All @@ -11,6 +11,7 @@ const {
filterFontWeight,
filterMotionDuration,
filterMotionEasing,
filterComponentToken,
} = require('../filters');

const androidTransformGroup = {
Expand All @@ -34,7 +35,7 @@ const composeObject = {
'_format_comment': 'https://amzn.github.io/style-dictionary/#/formats?id=composeobject',
};

const getFiles = ({ modeTheme, language }) => {
const getFiles = ({ theme, modeTheme, language }) => {
if (modeTheme === 'dark') {
return [
{
Expand All @@ -48,6 +49,18 @@ const getFiles = ({ modeTheme, language }) => {

const files = [];

if (theme === 'vr-theme') {
// add component token files
getListOfComponents(theme).forEach((component) => {
files.push({
'destination': `component/${component}.xml`,
...androidResources,
...dimenResource,
...filterComponentToken(component),
});
});
}

if (language) {
files.push({
'destination': `font-lineheight-${language}.xml`,
Expand Down Expand Up @@ -115,11 +128,20 @@ const getFiles = ({ modeTheme, language }) => {
return files.flat();
};

const getComponentTokenFiles = ({ theme }) => {
if (theme !== 'vr-theme') {
return [];
}

return getComponentTokenOverrides('android');
};

function getAndroidConfiguration({ theme, mode, language }) {
const modeTheme = mode === 'dark' ? 'dark' : 'light';

return {
'source': getSources({ theme, modeTheme, language }),
'include': getSources({ theme, modeTheme, language }),
'source': getComponentTokenFiles({ theme }),
'platforms': {
'android': {
...androidTransformGroup,
Expand Down
34 changes: 31 additions & 3 deletions packages/gestalt-design-tokens/src/platforms/ios.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
const { optionsFileHeader, optionsFileHeaderOutputReferences } = require('../headers/fileheader');

const { getFilter } = require('../utils/getFilter');
const { filterLineHeight, filterColor, filterElevation } = require('../filters');
const { getSources } = require('../getSources');
const {
filterLineHeight,
filterColor,
filterElevation,
filterComponentToken,
} = require('../filters');
const { getSources, getListOfComponents, getComponentTokenOverrides } = require('../getSources');

const toPascal = (str) => str.charAt(0).toUpperCase() + str.slice(1);

function getTheme(theme) {
return theme === 'vr-theme' ? 'VR' : '';
Expand Down Expand Up @@ -137,6 +144,18 @@ function getFiles({ theme, modeTheme, language, fileType }) {
});
}

if (theme === 'vr-theme') {
iOSSwiftFiles.push(
...getListOfComponents(theme).map((component) => ({
'destination': `components/GestaltTokens${toPascal(component)}.swift`,
...iosSwiftEnumSwift,
'className': `GestaltTokens${toPascal(component)}`,
...filterComponentToken(component),
fileHeader: `// ${language} specific tokens`,
})),
);
}

if (fileType === 'swift') {
if (modeTheme === 'dark') {
return [
Expand Down Expand Up @@ -196,11 +215,20 @@ function getFiles({ theme, modeTheme, language, fileType }) {
return [];
}

const getComponentTokenFiles = ({ theme }) => {
if (theme !== 'vr-theme') {
return [];
}

return getComponentTokenOverrides('ios');
};

function getIOSConfiguration({ theme, mode, language }) {
const modeTheme = mode === 'dark' ? 'dark' : 'light';

return {
'source': getSources({ theme, modeTheme, language }),
'include': getSources({ theme, modeTheme, language }),
'source': getComponentTokenFiles({ theme }),
'platforms': {
'ios': {
...iOSTransformGroup,
Expand Down
13 changes: 11 additions & 2 deletions packages/gestalt-design-tokens/src/platforms/web.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { getSources } = require('../getSources');
const { optionsFileHeader, optionsFileHeaderOutputReferences } = require('../headers/fileheader');
const { getSources, getComponentTokenOverrides } = require('../getSources');
const {
dataVisualizationFilter,
colorElevationFilter,
Expand Down Expand Up @@ -122,11 +122,20 @@ const getFiles = ({ theme, modeTheme, language, fileType }) => {
return files.flat();
};

const getComponentTokenFiles = ({ theme }) => {
if (theme === 'classic') {
return [];
}

return getComponentTokenOverrides('web');
};

function getWebConfig({ theme, mode, language }) {
const modeTheme = mode === 'dark' ? 'dark' : 'light';

return {
'source': getSources({ theme, modeTheme, platform: 'web', language }),
'include': getSources({ theme, modeTheme, platform: 'web', language }),
'source': getComponentTokenFiles({ theme }),
'platforms': {
'css': {
...webCssTransformGroup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,25 @@ Object {
<color name=\\"sema_color_dataviz_08\\">#ff400387</color>
<color name=\\"sema_color_dataviz_09\\">#fff2681f</color>

</resources>
",
"dist/android/vr-theme/component/radiogroupbutton.xml": "<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>

<resources>
<dimen name=\\"comp_radiogroupbutton_motion_border_scale_easing\\">@dimen/base_motion_easing_bounce</dimen>
<dimen name=\\"comp_radiogroupbutton_motion_border_scale_duration\\">@dimen/base_motion_duration_150</dimen>
<dimen name=\\"comp_radiogroupbutton_motion_border_fade_easing\\">@dimen/base_motion_easing_exit</dimen>
<dimen name=\\"comp_radiogroupbutton_motion_border_fade_duration\\">@dimen/base_motion_duration_150</dimen>

</resources>
",
"dist/android/vr-theme/component/spinner.xml": "<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>

<resources>
<dimen name=\\"comp_spinner_color_background_pink\\">#d452d1</dimen>
<dimen name=\\"comp_spinner_color_background_orange\\">#ff7c36</dimen>
<dimen name=\\"comp_spinner_color_background_blue\\">#24ccb0</dimen>

</resources>
",
"dist/android/vr-theme/font-lineheight-ck.xml": "<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Array [
"dist/android/classic/space.xml",
"dist/android/vr-theme/color-dark.xml",
"dist/android/vr-theme/colors-light.xml",
"dist/android/vr-theme/component/radiogroupbutton.xml",
"dist/android/vr-theme/component/spinner.xml",
"dist/android/vr-theme/font-lineheight-ck.xml",
"dist/android/vr-theme/font-lineheight-default.xml",
"dist/android/vr-theme/font-lineheight-ja.xml",
Expand Down Expand Up @@ -178,5 +180,7 @@ Array [
"dist/ios-swift/vr-theme/GestaltTokensOpacityVR.swift",
"dist/ios-swift/vr-theme/GestaltTokensRoundingVR.swift",
"dist/ios-swift/vr-theme/GestaltTokensSpaceVR.swift",
"dist/ios-swift/vr-theme/components/GestaltTokensRadiogroupbutton.swift",
"dist/ios-swift/vr-theme/components/GestaltTokensSpinner.swift",
]
`;
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,31 @@ public enum GestaltTokensSpaceVR {
public static let sema0 = 0px
public static let baseUnit = 4px
}
",
"dist/ios-swift/vr-theme/components/GestaltTokensRadiogroupbutton.swift": "



import SwiftUI

public enum GestaltTokensRadiogroupbutton {
public static let compMotionBorderFadeDuration = baseDuration150
public static let compMotionBorderFadeEasing = baseEasingExit
public static let compMotionBorderScaleDuration = baseDuration150
public static let compMotionBorderScaleEasing = baseEasingBounce
}
",
"dist/ios-swift/vr-theme/components/GestaltTokensSpinner.swift": "



import SwiftUI

public enum GestaltTokensSpinner {
public static let compColorBackgroundBlue = #24ccb0
public static let compColorBackgroundOrange = #ff7c36
public static let compColorBackgroundPink = #d452d1
}
",
}
`;

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
"sema/text/language/vi",
"sema/text/font",
"sema/text/typography",
"sema/motion"
"sema/motion",
"comp/badge/default",
"comp/badge/mobile",
"comp/badge/ios",
"comp/badge/android",
"comp/badge/web"
]
}
Loading
Loading