Comments (9)
Hi @goodmind!
We have not supported this yet, but it looks like a good case.
I'll try to implement this soon
from styled-jss.
But we're open for PR of course 😄
from styled-jss.
@lttb it looks like className
is generated only when component is rendered, so we can't add some magic toString
function to component itself
from styled-jss.
@lttb it looks like className is generated only when component is rendered, so we can't add some magic toString function to component itself
not exactly, let me explain how it works
we can separate properties on static and dynamic values (function values).
static values are the same for each instance, and we can use just one classname for all instances, so we generate classname for static properties immediately and share it for all instances of created styled component.
but if we have function values, we need to have its' own classname of dynamic values for each instance, that's why we generate dynamic classname in the constructor.
- so, for example, if we have component like
styled('div')({color: 'red'})
, we'll have just one classname for all instances. - on the other hand, if we have component like
styled('div')({color: props => props.color})
, we'll generate classname for each rendered component because of dynamic value. - finally, if we have
styled('div')({color: 'red', padding: props => props.padding})
, we'll generate 1 static classname for all instances and classname for dynamic values for each instance.
therefore with 1st and 3d cases we can use static classname in toString
.
But I don't want to generate additional static classname in the 2nd case. The possible solution is that we can generate it in lazy mode, just on toString
call for example, if we don't have static classname yet.
And, just to note, the possible temporary workaround may look like this:
const styled = Styled({
message: {
'&:not(:first-child) $AuthorName': {
display: 'none'
},
'&:not(:last-child) $StyledPeerPhoto': {
visibility: 'hidden'
}
}
})
const MyAuthorName = styled(AuthorName)({composes: '$AuthorName'})
const MyAvatar = styled(Avatar)({composes: '$StyledPeerPhoto'})
const Message = styled('div')({composes: '$message'})
from styled-jss.
And, just to note, the possible temporary workaround may look like this:
const styled = Styled({ message: { '&:not(:first-child) $AuthorName': { display: 'none' }, '&:not(:last-child) $StyledPeerPhoto': { visibility: 'hidden' } } }) const MyAuthorName = styled(AuthorName)({composes: '$AuthorName'}) const MyAvatar = styled(Avatar)({composes: '$StyledPeerPhoto'}) const Message = styled('div')({composes: '$message'})
You can check an example here: https://www.webpackbin.com/bins/-KrDP1-pNR8ddDXK-gR5
from styled-jss.
so, for example, if we have component like
styled('div')({color: 'red'})
, we'll have just one classname for all instances.
on the other hand, if we have component likestyled('div')({color: 'red'})
, we'll generate classname for each rendered component because of dynamic value.
I think there's should be props.color
?
from styled-jss.
I think there's should be props.color?
right, it's a typo
from styled-jss.
oh, I'm sorry forgot another one approach like this :) but I'd prefer styled-components way
const styled = Styled({
message: {
'&:not(:first-child) $authorName': {
display: 'none'
},
'&:not(:last-child) $styledPeerPhoto': {
visibility: 'hidden'
}
},
authorName: {},
styledPeerPhoto: {}
})
const Message = styled('div')({composes: '$message'})
export default injectStyled(styled)(({classes}) => (
<Message>
<AuthorName className={classes.authorName}>author</AuthorName>
<Avatar
className={classes.styledPeerPhoto}
src="https://avatars2.githubusercontent.com/u/11135392?v=4&s=88"
/>
</Message>
))
https://www.webpackbin.com/bins/-KrDXJZWZgM6d3ovH7PA
from styled-jss.
Hi @goodmind,
We've finally released this feature!
You can check your example here https://www.webpackbin.com/bins/-KwJAMdFdN8myP7g6dpD
from styled-jss.
Related Issues (20)
- Overriding component style HOT 2
- Border property HOT 2
- Support Observables from JSS9
- What about keyframes animation? HOT 7
- Add plugins without re-exporting styled HOT 6
- react-jss and styled-jss in the same app HOT 3
- Remove isObservable checks
- SSR Support for styled-jss
- SSR Support HOT 1
- Media queries don't work when using theming function HOT 9
- Bug: Nested composition causes invalid tag to be rendered HOT 1
- Support getting the ref of the wrapped component
- Add a way to filter props when extending other components
- Type Definitions HOT 1
- Mixing style objects and functions messes up specificity resolution HOT 1
- Composing function styles causes dynamic styles to not be used
- @global is not working HOT 4
- Component Name as the class name for easier debugging?
- How to install styled-jss when used in a library HOT 1
- Dynamic import styled-jss
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 styled-jss.