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 Studio support 🎉 #30

Merged
merged 2 commits into from
Jun 5, 2023
Merged

Tokens Studio support 🎉 #30

merged 2 commits into from
Jun 5, 2023

Conversation

drwpow
Copy link
Collaborator

@drwpow drwpow commented Jun 5, 2023

Changes

Adds Tokens Studio support! 🥳

This is a better solution than a 50%-completed Figma sync functionality that I haven’t finished after over a year of procrastinating. Hopefully this is a win–win scenario:

  • ✅ Cobalt UI gets (much) better Figma support
  • ✅ Tokens Studio users can now export the W3C Design Format schema through Cobalt
  • ✅ Cobalt users don’t have to wrestle with a dumb, giant JSON config of all their Figma tokens just to get basic support working

Mini-FAQ

Is this project partnering with Tokens Studio?

No; this project is completely unaffiliated with Tokens Studio.

Isn’t Tokens Studio paid?

The 100% free version of the plugin offers everything Cobalt supports and then some. This is the only reason this solution is being proposed.

The paid “Pro” version offers some extra features not everyone needs (which are beyond the current scope of the W3C Design Tokens spec anyway). If, in the future, a necessary feature to make Figma syncing work is gated behind a paywall, this project may explore other options. But for now this is a great solution.

I was using co sync! Can you keep it around for longer?

If you were using this, I’d actually love for you to comment & explain how you managed manually typing hundreds of tokens in a tokens.config.js file in a sane way. Not to shame, of course—I’d actually love to hear your workflow to provide better workarounds. But also to inform the next steps of Figma syncing.

Why not release a Tokens Studio transformer instead?

Tokens Studio has a Style Dictionary transformer they officially support. I initially looked into doing something similar, but realized that’s a one-off and not pluggable.

Tokens Studio is meant to be a “no-code” solution, and at the moment that’s completely different than Cobalt’s approach of a pluggable, adaptable, configurable dev tool for the W3C Design Tokens format. The simplest solution for Tokens Studio support seemed to be adding support on Cobalt’s end to just parse the format automatically, which turned out to be trivial (it’s basically just converting type to $type and a tiny bit of math for basic support).

If, in the future, Tokens Studio releases more transformers, including one for the W3C Design Tokens format, I’d be happy to collaborate / align better on what they’re doing.

@changeset-bot
Copy link

changeset-bot bot commented Jun 5, 2023

🦋 Changeset detected

Latest commit: ed7c6bc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@cobalt-ui/core Minor
@cobalt-ui/cli Minor
@cobalt-ui/plugin-css Major
@cobalt-ui/plugin-js Major
@cobalt-ui/plugin-sass Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

const tokenSet = path[0];
if (typeof v.value === 'string') {
if (v.value.trim().startsWith('{') && !v.value.trim().startsWith(`{${tokenSet}`)) {
v.value = v.value.trim().replace('{', `{${tokenSet}.`);

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding

This replaces only the first occurrence of '{{'.
for (const [property, propertyValue] of Object.entries(v.value)) {
if (typeof propertyValue !== 'string') continue;
if (propertyValue.trim().startsWith('{') && !propertyValue.trim().startsWith(`{${tokenSet}`)) {
v.value[property] = v.value[property].trim().replace('{', `{${tokenSet}.`);

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding

This replaces only the first occurrence of '{{'.
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jun 5, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: ed7c6bc
Status: ✅  Deploy successful!
Preview URL: https://b4e1e3b9.cobalt-ui.pages.dev
Branch Preview URL: https://tokens-studio.cobalt-ui.pages.dev

View logs

@drwpow drwpow force-pushed the tokens-studio branch 6 times, most recently from 13904df to d2a4e68 Compare June 5, 2023 15:30
@drwpow drwpow merged commit 482f5cd into main Jun 5, 2023
@drwpow drwpow deleted the tokens-studio branch June 5, 2023 15:33
@drwpow drwpow mentioned this pull request Jun 5, 2023
@github-actions github-actions bot mentioned this pull request Jun 5, 2023
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.

1 participant