Skip to content

feat: #65 add style dictionary #120

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

Merged
merged 9 commits into from
Jul 3, 2024
Merged

Conversation

willmcvay
Copy link
Contributor

Pull request checklist

Detail as per issue below (required):

fixes: #65

Based on @lilykirkwood 's initial PR, pulls in tokens from Figma, parses and injects variables into the Linaria globals object.

@kurtdoherty
Copy link
Contributor

question: @willmcvay are you waiting for this to be reviewed or are there still some things you need to finish off before assigning reviewers?

note: I'm happy to review it if you'd like; I'll just need to set aside a block of time to do so (it's a pretty large PR 😅). Feel free to point me at specific files if you think some of the changes don't need to be specifically reviewed 🙏

@willmcvay willmcvay force-pushed the feat/#65-add-style-dictionary branch from 48d55dd to fcdfb38 Compare June 24, 2024 09:09
@willmcvay
Copy link
Contributor Author

question: @willmcvay are you waiting for this to be reviewed or are there still some things you need to finish off before assigning reviewers?

note: I'm happy to review it if you'd like; I'll just need to set aside a block of time to do so (it's a pretty large PR 😅). Feel free to point me at specific files if you think some of the changes don't need to be specifically reviewed 🙏

Hi @kurtdoherty yes, I don't want to add to it at this stage. TBH, whilst the LOC is quite high, all I have practically done is to replace the locally defined global CSS variables with those parsed from Figma to prove the concept that we can sync with the DS.

I would focus on

The other files are just me replacing the old variable format with the new one e.g.

Basically the same change many times :-)

Copy link
Contributor

@kurtdoherty kurtdoherty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Nice work on this @willmcvay 👏 Will be great to get this in and have our CSS derived from the DS in Figma 🥳

I just had two suggestions, both of which could be deferred to separate PRs if you'd prefer.

tokens/build.mjs Outdated
const lowerCasedTheme = theme.toLowerCase()
return {
source: ['./tokens/tokens.json'],
format: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: It seems like we could we simplify this and just use the built-in CSS format to get a CSS file, e.g. tokens.css, then import that file using a CSS @import statement in globals.ts 🤔

note: It's quite possible I'm missing something with Linaria that prevents this from working; though it seems @import statements are permitted in the global.ts as we're using it for the Source Code Pro font.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice suggestion, yes, this works - have implemented and was able to get rid of the linaria parse function.

tokens/build.mjs Outdated
buildPath: `tokens/${lowerCasedTheme}/`,
files: [
{
destination: 'linaria-tokens.ts',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: If my suggestion above works and gets implemented, we could avoid the linaria- and typescript- prefixes on the generated files and just have tokens.css and tokens.ts files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, have re-named :-)

try {
const object = JSON.parse(contents)
// Bit fragile but I only want the primitives, semantic and component variables for each theme
// Figma exports a "mode 1" that we don't need - confirmed with Andrei
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: It may be a bit fragile, but at least is well-contained to this file 👌 👏

package.json Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: This can be done separate to this PR, but while I think of it, we'll want to be able to import the typescript tokens from Elements, but I can't see them being exported. I notice that Elements isn't yet using package exports, but adding a package export to allow us to do import * as tokens from "@reapit/elements/tokens.ts" should be sufficient for us without bloating the main entry point with stuff that no one else is likely to need.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this for the TS tokens - FYI, by adding a CSS export, it duplicates the CSS variables at root which we don't want. If you need the CSS variables in your external project, you can just import the main stylesheet and they will be available globally with the other classes.

Copy link
Contributor

@kurtdoherty kurtdoherty Jul 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this for the TS tokens

I can't see where this is has been added to the manifest. Not a big deal though; we're not trying to consume the TS tokens until after we've done the purple colour change as part of the RC rollout for Console Cloud, so can come later if need be.

FYI, by adding a CSS export, it duplicates the CSS variables at root which we don't want

Yep, it's only useful for the TS tokens and only while Console Cloud is still using MUI components alongside Elements (unless other products are going to leverage them instead of the main stylesheet). Hopefully, there'll be a day in our future where we'll have zero MUI in Console Cloud and no longer need the TS tokens export at all 🤞

@willmcvay
Copy link
Contributor Author

@kurtdoherty Thanks for reviewing, if you could take a look again, would be good to get this merged in. Thanks

@kurtdoherty
Copy link
Contributor

kurtdoherty commented Jul 2, 2024

@willmcvay everything looks good to me 👌 Let's 🚢 it (assuming the "Codacy Static Code Analysis" issues don't need to be dealt with).

@willmcvay
Copy link
Contributor Author

@willmcvay everything looks good to me 👌 Let's 🚢 it (assuming the "Codacy Static Code Analysis" issues don't need to be dealt with).

Was just playing around with Codacy, it's not a thing we are supporting currently, have removed from the repo. Cheers for the review.

@willmcvay willmcvay merged commit e30cae7 into main Jul 3, 2024
4 of 5 checks passed
@willmcvay willmcvay deleted the feat/#65-add-style-dictionary branch July 3, 2024 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Design Tokens via Style Dictionary and Tokens Studio
2 participants