Skip to content

Dynamic custom properties polyfill #6

Open

Description

@ai

We could not polyfill full power of Custom Properties, but we could solve case, when we put some class to body and override variables inside (global theming) like boby.themeA.

You pass this <body> switching classes to plugin:

require('postcss-dynamic-custom-props')({ rootClasses: ['theme-A', 'theme-B'] })

Then plugin will find all overrides definitions like and remember a variable names:

.theme-A {
   --bg-color: red;
   --text-color: blue;
}

Then it will find all rules, where this variables used, like:

p {
   color: var(--text-color);
}

On final step it merge themes classes and overrides and generate this:

.themeA p {
   color: blue;
}

Idea came from this question: postcss/postcss-simple-vars#54 (comment)

/cc @ryoikarashi

Activity

  1. kevinSuttle commented on Sep 16, 2016

    @kevinSuttle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions