Giter VIP home page Giter VIP logo

Comments (7)

kiwi-admin avatar kiwi-admin commented on May 28, 2024 1

Since the Storybook uses Webpack. You can leverage sass-loader to compile your SASS files into single file. Preserve the CSS token annotations and point the add-on to it.

//.storybook/preview.js

import content from '!!raw-loader!sass-loader?{"sassOptions":{"outputStyle":"expanded"}}!../path/to/your/index.scss';

export const parameters = {
  ...
  designToken: {
    files: [{ filename: 'index.css', content: content.toString() }],
  },
};

from storybook-design-token.

Sqrrl avatar Sqrrl commented on May 28, 2024

Hey. So far I haven't found a good way to compile sass variable declarations in the browser and extract the necessary information. But I'm definitely open for suggestions. The same goes for Less.

from storybook-design-token.

danielo515 avatar danielo515 commented on May 28, 2024

Maybe it is possible to use sass interop with Javascript? That way at least sass variables can be used

from storybook-design-token.

Sqrrl avatar Sqrrl commented on May 28, 2024

Since the Storybook uses Webpack. You can leverage sass-loader to compile your SASS files into single file. Preserve the CSS token annotations and point the add-on to it.

//.storybook/preview.js

import content from '!!raw-loader!sass-loader?{"sassOptions":{"outputStyle":"expanded"}}!../path/to/your/index.scss';

export const parameters = {
  ...
  designToken: {
    files: [{ filename: 'index.css', content: content.toString() }],
  },
};

Sass won't compile variable declarations to css variables, will it? So if I don't miss anything, this would result in a index.css without any token declarations.

from storybook-design-token.

lgradzki-cksource avatar lgradzki-cksource commented on May 28, 2024

would be great to have it!

$variable: someFunction(param, param2)

someFunction($param, $param2) {
  @return unquote("hsla(#{$param}, #{$param2}, 100%, 1");
}

add-on doesn't return compiled hsla color value but a function

from storybook-design-token.

Sqrrl avatar Sqrrl commented on May 28, 2024

This was a deliberate design choice for preprocessed styles (Sass, Less). Afaik there is no reasonable way to compile the scss styles and not lose the token/variable information.

You could generate CSS custom properties from your Sass variables and annotate them. (see sass/sass#3091 (comment))

from storybook-design-token.

oobleck avatar oobleck commented on May 28, 2024

Since the Storybook uses Webpack. You can leverage sass-loader to compile your SASS files into single file. Preserve the CSS token annotations and point the add-on to it.

//.storybook/preview.js

import content from '!!raw-loader!sass-loader?{"sassOptions":{"outputStyle":"expanded"}}!../path/to/your/index.scss';

export const parameters = {
  ...
  designToken: {
    files: [{ filename: 'index.css', content: content.toString() }],
  },
};

Sass won't compile variable declarations to css variables, will it? So if I don't miss anything, this would result in a index.css without any token declarations.

Sass won't generate custom props automatically. That would be the responsibility of the author. But it is easy to do. A simple example.

This feature would be awesome 🥳 🚀 because my preference is to maintain a map of tokens in scss and then generate the custom props from there. This gives a lot of flexibility to consumers of my component lib.

$palette-map: (
  brand: dodgerblue,
  status-critical: crimson,
);

:root {
  /**
   * @tokens Colors
   * @presenter Color
   */
  @each $name, $color in $palette-map {
    --prefix-color-#{$name}: #{$color};
  }
}

Perhaps I'll take a stab at a PR with @kiwi-admin's suggestion.

from storybook-design-token.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.