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

functional CSS #4

Open
trusktr opened this issue May 25, 2020 · 0 comments
Open

functional CSS #4

trusktr opened this issue May 25, 2020 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@trusktr
Copy link
Member

trusktr commented May 25, 2020

Make a simple abstraction that can take a piece of CSS, generate a stylesheet from it, and provide the end developer a function that can be called in order to pass values for CSS variables/properties.

Initial description of the idea is in postcss/postcss#476 (comment).

Basically given the following CSS,

.foo {
  --some-prop: 1px;
  /* ... styles that use var(--some-prop) ... */
}

we can implement some a tool on the JS side that automatically gives you a simple abstraction:

css = css`
  .foo {
    --some-prop: 1px;
    /* ... styles that use var(--some-prop) ... */
  }
`

// ... call this any time later to update the style's `--some-prop` variable ...
this.css.update({someProp: '10px'})

This will help pave the way towards using reactive variables within CSS styles in a performant way.

Another ideas is we can abstract it so that the css template tag can automatically perform the property update internally:

css = css`
  .foo {
    --some-prop: ${this.foo};
    /* ... styles that use var(--some-prop) ... */
  }
`

// ... call this any time later to update the style's `--some-prop` variable ...
this.foo = '10px'

where this.foo is a reactive property.

Or maybe we just auto-create reactive accessors:

css = css`
  .foo {
    --some-prop: 1px;
    /* ... styles that use var(--some-prop) ... */
  }
`

// ... call this any time later to update the style's `--some-prop` variable ...
this.css.someProp = '10px'
@trusktr trusktr added the enhancement New feature or request label May 25, 2020
@trusktr trusktr added the good first issue Good for newcomers label Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant