salesforce-ux / theo

Theo is a an abstraction for transforming and formatting Design Tokens
BSD 3-Clause "New" or "Revised" License
1.95k stars 117 forks source link

Add documentation for the `type` prop in token files #176

Open JasonNutmeg opened 5 years ago

JasonNutmeg commented 5 years ago

The readme shows the usage of the type prop in the token files but doesn't describe what the prop is used for or what values are available for it.

It would be great to add that to the readme.

NoWorries commented 5 years ago

I believe that the basic values are below, these are then used with value transforms:

You can extend it with custom types/transforms, example of size transform below:

module.exports = theo => {
  theo.registerValueTransform(
    'addpx',
    prop => prop.get('type') === 'size',
    prop => prop.get('value') + 'px'
  );
  theo.registerTransform("web", ['addpx']);
}
JasonNutmeg commented 5 years ago

Thanks @NoWorries ! Would be useful to have that information in the official documentation as well 🙂

CH-RhyMoore commented 5 years ago

The mental list I've been keeping is size, number, color, string, and property.

There's a big difference between string and property in some output formats--presence or absence of outer quotes.

I don't think this covers all of the formats that support them, but the ones I remember off the top of my head that were important were in CSS Modules.

I can have a token that's usable in composes like below if it's a property, while a string won't work:

@values * as componentTokens from 'component-tokens.cssmodules.css';

.my-selector {
  composes: componentTokens.typography-style;
}

Similarly, for breakpoints, string results in a malformed media query, while property doesn't...

@values phone, tablet, desktop from 'breakpoint-tokens.cssmodules.css';

@media phone, tablet {
  /* styles */
}
frebro commented 4 years ago

Stumbling on this a year later. Are there any docs on what values are available for the type prop? Unsure where to look.