-
-
Notifications
You must be signed in to change notification settings - Fork 399
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
Support full syntax in function rules and values #682
Comments
I got an idea what we can do here: due to the fact that other cssinjs libs have also functions and they don't expect those to be updatable at 60 FPS we can do this:
{
button: {
// If value is an array and first item is a function, we got a function value.
top: [props => props.top]
}
} {
// If rule is an array and first item is a function, we got a fast function rule.
button: [(props) => ({
top: props.top
})
} Additionally we could allow passing options: {
button: {
// Second array value is an options object.
top: [props => props.top, {someOptions}]
}
} Another interface idea: // This function name could be something else…
import {fast} from 'jss'
{
// fast() will mark the function with a flag that allows to distinguish "fast" functions without plugins.
button: fast((props) => ({
top: props.top
}))
} I am open for any other interface suggestions. |
Fast functions being ones that require updates at 60fps? |
Fast functions being ones which can be updated frequently using Basically current function values/rules implementation IS the "fast" version, which is why I couldn't add all plugins to the results they return, because that would slow them down. So we need a way to use the entire JSS syntax for more "static" use cases, where static doesn't mean it can be done only once, but it shouldn't be updated frequently. This is the way styled-components is using them. At the same time I want to keep the "fast" version for frequent updates. So we need to distinguish those 2 versions somehow. |
@kof I got another idea according to "fast" functions. Maybe better to revert your idea, and use such kind of wrapper for function values/rules only if needed to isolate block (class name) from root scope? Let's say this would be named as "slow" function. It will be executed separately with all of the plugins enabled by a user. |
@AleshaOleg people expect all rules to work the same way with fn values, because other libraries support this. JSS is the only one with "fast" functions, thats why I think we should go by default for slow version and make fast optional. Another reason is that having animations is also not the most popular use cases compared to props based regular styling. |
Idea: we can make function values/rules "slow" by default and only keep Observables as fast by default. The reasons are:
The benefits are
That being said, we can reintroduce fast functions later on if there is a need as a new feature, since it requires a new interface now anyways. |
* added fallbacks test to fn rules * only call onChangeValue if plugins: true * enable removing props from fn rules * shorter syntax with coercion * wip full syntax support * restore browsers.json * changelog * move hook call to the core * isProcessed flag explanation * added tests to fn rules * remove media rule as a function test case * added a test for #796, as part of #682 * tests for compose plugin * observables - move documentation to the package - update docs, since plugins don't apply by default - introduce option process: true to the plugin to enable plugins if user wants that * move fn values docs * wording * Added tests for using jss-plugin-syntax-expand with function rules and values * Skip fn values with jss-expand for now * move container rules update to the core * optimize onProcessStyle onProcessStyle is invoked on each .update, but in this case we only need to do this once, because fn values can't be added * put variables in the right scope
* added fallbacks test to fn rules * only call onChangeValue if plugins: true * enable removing props from fn rules * shorter syntax with coercion * wip full syntax support * restore browsers.json * changelog * move hook call to the core * isProcessed flag explanation * added tests to fn rules * remove media rule as a function test case * added a test for #796, as part of #682 * tests for compose plugin * observables - move documentation to the package - update docs, since plugins don't apply by default - introduce option process: true to the plugin to enable plugins if user wants that * move fn values docs * wording * support typed cssom * Update docs/json-api.md * Update changelog.md
* added fallbacks test to fn rules * only call onChangeValue if plugins: true * enable removing props from fn rules * shorter syntax with coercion * wip full syntax support * restore browsers.json * changelog * move hook call to the core * isProcessed flag explanation * added tests to fn rules * remove media rule as a function test case * added a test for #796, as part of #682 * tests for compose plugin * observables - move documentation to the package - update docs, since plugins don't apply by default - introduce option process: true to the plugin to enable plugins if user wants that * move fn values docs * wording * Added tests for using jss-plugin-syntax-expand with function rules and values * Skip fn values with jss-expand for now * move container rules update to the core * optimize onProcessStyle onProcessStyle is invoked on each .update, but in this case we only need to do this once, because fn values can't be added * put variables in the right scope * changelog * Update changelog.md * process: true always
* added fallbacks test to fn rules * only call onChangeValue if plugins: true * enable removing props from fn rules * shorter syntax with coercion * wip full syntax support * restore browsers.json * changelog * move hook call to the core * isProcessed flag explanation * added tests to fn rules * remove media rule as a function test case * added a test for #796, as part of #682 * tests for compose plugin * observables - move documentation to the package - update docs, since plugins don't apply by default - introduce option process: true to the plugin to enable plugins if user wants that * move fn values docs * wording * scoped keyframes * Added tests for using jss-plugin-syntax-expand with function rules and values * Skip fn values with jss-expand for now * use "keyframes-{name}" as a key in KeyFramesRule Changed the key to a form where it can be used directly as-is for id generation, so we don't have to fake the rule when using generateClassName * keyframes name parser with validation * wip keyframes inside of global * move container rules update to the core * optimize onProcessStyle onProcessStyle is invoked on each .update, but in this case we only need to do this once, because fn values can't be added * put variables in the right scope * changelog * update tests with key keyframes name * Update changelog.md * Update docs/json-api.md * Update changelog.md * process: true always * support multiple whitespaces after keyframes identifier * move keyframe name generation to outside * call external plugins first we need to separate internal and external queues, queue 0 is external, 1 is internal and 1 is executed always after 0 * move keyframes rule to plugins * move StyleRule to a plugin Additionally stop rendering StyleRule when user passes a bad/unknown at-rule * move viewport rule to plugins * move simple rule to plugins * move FontFace rule * rename plugins to {rule}Rule schema * beter types for queue * Add support for animation property * optimize perf, handle arrays * fix tests, add more tests * Fix * Support arrays * remove array support * use global instead of window * always run stylerule plugin first, to avoid regexes of the at rules * ensure to always use style rule as a first rule in plugins flow started to complain with "Unused suppression comment." so I removed them * fix cache plugin * test raw rule registration order * rewrite internal plugins queue * better logic in plugins.use() * better types * better types * fix types * keyframe inside of global TODO - Rethink BaseStyleRule - Evtl move generateClassName to the rule models - Evtl rename generateClassName to generateId * default export in plugins * move id generator to models * update snapshots * fix circular deps * use CSSKeyframeRule * generateClassName -> generateId * added exampls with keyframes to global plugin * docs, small syntactic changes
Implemented in #878 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
When will this be made publicly available? There have been no releases since July. 😢 |
You can help doing it, otherwise just wait and watch issues, we are working on a big release. |
* added fallbacks test to fn rules * only call onChangeValue if plugins: true * enable removing props from fn rules * shorter syntax with coercion * wip full syntax support * restore browsers.json * changelog * move hook call to the core * isProcessed flag explanation * added tests to fn rules * remove media rule as a function test case * added a test for cssinjs#796, as part of cssinjs#682 * tests for compose plugin * observables - move documentation to the package - update docs, since plugins don't apply by default - introduce option process: true to the plugin to enable plugins if user wants that * move fn values docs * wording * Added tests for using jss-plugin-syntax-expand with function rules and values * Skip fn values with jss-expand for now * move container rules update to the core * optimize onProcessStyle onProcessStyle is invoked on each .update, but in this case we only need to do this once, because fn values can't be added * put variables in the right scope
* added fallbacks test to fn rules * only call onChangeValue if plugins: true * enable removing props from fn rules * shorter syntax with coercion * wip full syntax support * restore browsers.json * changelog * move hook call to the core * isProcessed flag explanation * added tests to fn rules * remove media rule as a function test case * added a test for cssinjs#796, as part of cssinjs#682 * tests for compose plugin * observables - move documentation to the package - update docs, since plugins don't apply by default - introduce option process: true to the plugin to enable plugins if user wants that * move fn values docs * wording * support typed cssom * Update docs/json-api.md * Update changelog.md
* added fallbacks test to fn rules * only call onChangeValue if plugins: true * enable removing props from fn rules * shorter syntax with coercion * wip full syntax support * restore browsers.json * changelog * move hook call to the core * isProcessed flag explanation * added tests to fn rules * remove media rule as a function test case * added a test for cssinjs#796, as part of cssinjs#682 * tests for compose plugin * observables - move documentation to the package - update docs, since plugins don't apply by default - introduce option process: true to the plugin to enable plugins if user wants that * move fn values docs * wording * scoped keyframes * Added tests for using jss-plugin-syntax-expand with function rules and values * Skip fn values with jss-expand for now * use "keyframes-{name}" as a key in KeyFramesRule Changed the key to a form where it can be used directly as-is for id generation, so we don't have to fake the rule when using generateClassName * keyframes name parser with validation * wip keyframes inside of global * move container rules update to the core * optimize onProcessStyle onProcessStyle is invoked on each .update, but in this case we only need to do this once, because fn values can't be added * put variables in the right scope * changelog * update tests with key keyframes name * Update changelog.md * Update docs/json-api.md * Update changelog.md * process: true always * support multiple whitespaces after keyframes identifier * move keyframe name generation to outside * call external plugins first we need to separate internal and external queues, queue 0 is external, 1 is internal and 1 is executed always after 0 * move keyframes rule to plugins * move StyleRule to a plugin Additionally stop rendering StyleRule when user passes a bad/unknown at-rule * move viewport rule to plugins * move simple rule to plugins * move FontFace rule * rename plugins to {rule}Rule schema * beter types for queue * Add support for animation property * optimize perf, handle arrays * fix tests, add more tests * Fix * Support arrays * remove array support * use global instead of window * always run stylerule plugin first, to avoid regexes of the at rules * ensure to always use style rule as a first rule in plugins flow started to complain with "Unused suppression comment." so I removed them * fix cache plugin * test raw rule registration order * rewrite internal plugins queue * better logic in plugins.use() * better types * better types * fix types * keyframe inside of global TODO - Rethink BaseStyleRule - Evtl move generateClassName to the rule models - Evtl rename generateClassName to generateId * default export in plugins * move id generator to models * update snapshots * fix circular deps * use CSSKeyframeRule * generateClassName -> generateId * added exampls with keyframes to global plugin * docs, small syntactic changes
Hi, I'm using I've been able to do it easily with But I'm not able to achieve the same behaviour with I've found a workaround by importing the Thanks! I love this project. |
@monsieur-z have you found a way? |
Can you explain more about your workaround using jss instance? I encountered same issue and still can't find a solution |
There's no more to it than what's in this pen: https://codesandbox.io/s/jss-dynamic-global-value-7n9rb |
So I got dynamic global styles working by wrapping it in a function. import { createUseStyles as createJssUseStyles } from 'react-jss'
import React from 'react'
import ReactDOM from 'react-dom'
const createUseStyles = ({ color }) => {
return createJssUseStyles({
test: {
height: 30
},
// you need to have the local class outside of \@global and @global styles must come after
// eslint-disable-next-line sort-keys
'@global': {
'.wrapper': {
'& $test': {
background: color
}
}
}
})
}
const Test = ({ color }) => {
const classes = createUseStyles({ color })()
return (
<div className='wrapper'>
<div className={classes.test}>TESTO</div>
</div>
)
} Some observations:
|
@sam-m-m this is going to generate styles every time component updates, don't recommend doing this |
was ever a development in solving this issue of dynamic styles in global styling in react-jss? |
Currently the only plugin that we run over function values/rules is jss-default-unit. The problem with running every plugin over it is that we would add performance overhead to something that is supposed to be usable for animations.
Originates in https://github.com/cssinjs/react-jss/issues/185
Cases:
The text was updated successfully, but these errors were encountered: