-
Notifications
You must be signed in to change notification settings - Fork 67
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
Discovery: Style Dictionary #1837
Comments
Being able to support react-native has emerged as a requirement for the Mobile app team. I was able to generate a react-native variables file for them (I have the transform on a branch but haven't pushed it up yet). Their feedback was:
I did provide a pointer to our JSON token files. Tim on the mobile team is the person to talk to (I'll get his details and add it here). |
Hi @timwright12! I've started to do some discovery work for generating different token formats. Style Dictionary does provide some pre-made transforms to help us generate one for React Native but reading Matt's comment above, it sounds like it might need some additional work? Here is an example of what that pre-made transform outputs for our tokens to react-native. export const colorBase = "#212121";
export const colorWhite = "#ffffff";
export const colorBlack = "#000000";
export const colorOrange = "#eb7f29";
export const colorLinkDefault = "#004795";
export const colorWarningMessage = "#fac922";
export const colorGibillAccent = "#fff1d2";
export const colorPrimary = "#0071bb";
....etc And this is an example they've provided on how to use that in a react-native project: https://github.com/amzn/style-dictionary/blob/main/examples/advanced/create-react-native-app/src/App.js#L4 import * as variables from "./style-dictionary-dist/variables";
export default function App() {
return (
<View style={styles.container}>
<Text style={styles.title}>Testing! Testing!</Text>
<Text style={styles.p}>All done!</Text>
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: variables.colorBrand01,
alignItems: "center",
justifyContent: "center",
},
title: {
fontSize: PixelRatio.getFontScale() * variables.sizeFontMd.scale,
color: variables.colorBrand02,
},
p: {
fontSize: PixelRatio.getFontScale() * variables.sizeFontSm.number,
color: variables.colorBrand02,
},
}); If the tokens don't look exactly right for your needs, we should be able to do custom filtering or even create our own custom transforms but I wanted to check in with you first to see if that was even necessary based on the output we're receiving above. |
Hey @jamigibbs! In chatting with Matt the React Native output was great, but we also wanted to request that the JSON format be available just for flexibility of use. For the individual tokens, hexcodes will work. For font sizing a spacing are you all able to use the same format as the example? This: export For us, just being able to use the colors is awesome, so if we can also use the sizing that'd be a bonus. |
Thanks @timwright12! I think it would be a pretty straightforward effort for us to make those modifications. Here's a quick POC with a couple of custom transforms that will convert And we can output that as either I think that's gets you everything you need? |
JSON + React Native should do it. Transforms look good too! Thank you! |
Discovery NotesCSS Library Quick OverviewThe CSS Library has two types of resources available:
The design tokens are what this discovery has focused on. Can we generate different token formats for React Native, UXPin, Sketch, etc?With style-dictionary, we should be able to generate any format that we need. They provide a number of pre-defined formats, transform groups, and transforms. And if those pre-defined formats don't get us exactly what we want, we can create our own custom formats or custom transforms. React Native The mobile team are a good example of needing something more custom than what style-dictionary can provide. They need A working example of this has been added to the discovery PR which includes two custom transforms: https://github.com/department-of-veterans-affairs/component-library/pull/766/files#diff-79ccf6c33f36bac9578b5a05b5b76e3b80ae31b308d1ee41f941bb8fd449ebb0 Figma An NPM package exists that we could use for Figma: style-dictionary-to-figma. I connected this package and generated a tokens file with it as part of this discovery work but this will need to be verified that it's working as expected as part of the development ticket. The Figma documentation says that you can import/use that file just by linking to its public source. UXPin Looking at some UXPin tutorials, I believe we can import a standard tokens CSS file directly into the service and it will automatically generate those values. I don't have access to a UXPin dashboard to verify this though (or found any specific UXPin documentation that confirms) but with the flexibility of style-dictionary, I believe we could make adjustments as needed. Sketch Importing tokens into Sketch might be more complicated. There are some Sketch plugins we could leverage (colors specifically) but we might need to create our own custom Sketch plugin in order to import all tokens (color, fonts, and spacing). The CMS Design system did build their own Sketch plugin but it seems like it's only handling color tokens so I'm not sure why they couldn't use one of the pre-made plugins. const colorSwatches = makeColorSwatches(tokenData.color);
colorSwatches.forEach((swatch) => {
doc.swatches.push(swatch);
}); Do we need more than color tokens in sketch? If not, then I believe we can just use one of the pre-made sketch plugins. How do we organize all of thisWith so many different token file types (including some with the same file extension), I propose we organize based on the interface it's meant to be used with:
Example usage in the component-library We can start using the generated tokens file now in the component library if we'd like. We will just need publish the latest updates to NPM and add the package. The existing
When can everyone start using the CSS Library token files?We probably first will want to figure out how the releases are going to work for the component library repo now that we have both the Some discovery work was already started to explore publishing multiple packages in a monorepo which I think we need to revisit. We left off wanting to do some additional discovery work with Lerna: #1068 Follow-up tickets
Other planning or discovery needed?
Other Useful Links |
Description
Do discovery work on a style dictionary to define design tokens that allows you to export them to be used in other tools and to use code right out of component library. Should be able to use the design tokens in Sketch, UXPin and Figma.
Details
Tasks
Acceptance Criteria
The text was updated successfully, but these errors were encountered: