Comments (4)
@MicheleBertoli @johanneslumpe Got a new idea on my mind. The proposed API design seems quite fine. I guess its no real difference if the changeTheme
/updateTheme
is returned by theming()
or if it is a method of the renderer itself, though being returned by theming seems more transparent.
To do style rehydration I thought about actually providing another enhancer which additionally tracks all rule(id)-props combinations. This would decouple both features which can be useful each by their own.
This would look sth. like:
const renderer = createRenderer({
enhancers: [ rehydrate() ]
})
let someVar = 'red'
const rule = props => ({
color: props.color,
backgroundColor: someVar
})
renderer.renderRule(rule, { fontSize: '15px' }) // => 'c0 c0-foo'
// .c0 { background-color: red }
someVar = 'blue'
renderer.rehydrate()
// .c0 { background-color: blue }
See #71
from fela.
Well done, I love the solution.
Did you already think about a function to change the theme?
from fela.
@rofrischmann @MicheleBertoli
What do you think about this:
Instead of returning an enhancer directly, theming(theme)
could return an object with a shape like { enhancer, changeTheme }
. changeTheme
would be a function which takes a new theme as a parameter to allow on the fly theme changes. That function could then easily be passed down via context in react for example (or via any other way in other frameworks).
The only downside I see here (in a react context) is that this change wouldn't cause a re-render because it's outside of react. This could partially be mitigated by keeping the theme object in a redux store for example, but it still might not force a complete re-render.
from fela.
I thought about adding renderer.updateTheme(theme)
to the enhancer to trigger theme updates, but I am yet not sure how to rehydrate all styles. One idea would be to just clear all styles and rerender everything (e.g. using forceUpdate
on the <Provider />
.
Right now the rendered & cached CSS is compressed so I can not imply the used theme
afterwards.
I will have to test this in a real world use case though.
Update: Seems like @johanneslumpe was faster :P But still we have identical ideas I guess :P
from fela.
Related Issues (20)
- Improve IStyle type HOT 5
- Update react-fela peer dependency react to support v17 HOT 2
- Readme docs links 404 HOT 2
- react-fela providers only accept single element children HOT 2
- Use fela with ReactDOM.createPortal on a different window HOT 1
- fela-plugin-responsive-value doesn’t handle nested objects
- Fela doesn’t hydrate CSS custom properties HOT 1
- fela-plugin-multiple-selectors doesn’t extend styles
- renderStatic doesn’t handle nested objects
- Document targetDocument
- renderToNodeList not exported in react-fela/index.d.ts HOT 1
- Typescript plugin doesn't extend style definition HOT 5
- Native ESM support HOT 5
- renderStatic not applying some plugins HOT 6
- Missing changelog for 11.5.x & 11.6.x HOT 2
- Rehydration of `&` selectors HOT 10
- Rules are mixing between components when we switch between pages. HOT 1
- Typescript interface for renderer configuration (IConfig) misses some options HOT 2
- Transform key as array ignored HOT 5
- [Feature] Add bindings for solid-js HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fela.