-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add ClassNames component #828
Conversation
next-packages/core/src/style.js
Outdated
break | ||
case 'function': | ||
if (process.env.NODE_ENV !== 'production') { | ||
console.error( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this needed? it's already "next major version of Emotion" :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, I made this a while ago and copied classnames
from v9.
next-packages/core/src/style.js
Outdated
| { [key: string]: boolean } | ||
| Array<ClassNameArg> | ||
|
||
let classnames = (args: Array<ClassNameArg>): string => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can u explain more why this is duplicated? I suspect it's like a global caching registry issue, but couldnt this share the implementation with original cx, css & merge?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m just lazy, I think I’ll move it and merge into @emotion/utils
. There’s no point in sharing css and cx since they need slightly different things in here and in create-emotion.
Just FYI, I’m mainly looking for a review of the API rather than code review. |
Could you explain a little bit more why this is needed for SSR? I'm not too familiar with its intricacies |
Because there needs to be somewhere to render the style tags and the exact styles that need to be rendered there must be known when the style tag is being rendered, that's not possible if using something like |
Why? Isnt the css call synchronous anyway? |
Let's say you have this component, how is it possible to do automatic SSR? let SomeComponent = () => (
<div
className={css`
color: hotpink;
`}
/>
) |
Also, I just want to repeat this, this is only intended for cases when components accept props like |
Ok, I get now how it's impossible for auto-SSR. The API looks good, although it slightly shows that even though current approach brings easier SSR to the table it also has its drawbacks such as having to know that sometimes Also - not sure what's the best name for this component, maybe |
This isn't just for auto-SSR though, it's also for The |
Is this meant to be a replacement for previously presented APIs? You've already demoed i.e. rendering to iframes etc. Sorry for asking so many questions, I'm not too familiar with v10 APIs - lacking a "big picture" and how existing pieces fit together. |
No, this isn't meant to be a replacement for the css prop or styled, it's meant for for the small number of cases that they can't solve. Sorry, when I said providing the cache via context I meant consuming it via context. |
Ok, I think I get it now 👍 The only confusing part for me is the name of the component - for a css-in-js a component named From what I get it seems that we are going to have now 2 context consumer types - one holds registry, stylis, sheet etc and accounts for preferred way of writing "idiomatic" emotion (it doesnt provide things like |
Yeah, that's mostly correct though this isn't very different from the other consumers, they all work in the same way, they just provide different APIs to insert styles. This API is just less convenient but more flexible. I just thought of another name, |
I like it better 👍 |
I like this name better. I just thought of this, but what if it was just called |
@Andarist suggested that too, I feel like it doesn’t convey much meaning about what it does though. |
For me, it's also hard to understand. How about |
I like I don’t really get what |
Oh, I thought about but still... does |
|
There isn’t really a difference between the css function in this component and the css function in v9 except for the implementation. |
Are you talking about the css prop in emotion 10 or the css function in this component? |
It's different in SSR, isn't it? |
Kind of but the usage of it is the same which is the part that people care about |
I mean the difference between |
(I believe) I know interfaces of those functions are same, but if it work differently in some sense, it should convey those differences as a name, shouldn't it? |
If it works the same from the user’s perspective, why should they have to learn a new name for something that does the same thing? |
Oh sorry, didn’t see your comment about css from |
Actually, that's where my
But what you said in #828 (comment) makes sense, so I need to think more about this. However, if those refactoring cannot make sense from the first stage, then renaming |
|
Oh, yes, then we don't need to worry about refactoring. Then instead of concerning about new name for component, giving appropriate name for |
Guys, there is a better solution than wrapping every component with another one render prop. We can have the same api but with some requirements about where functions may be called. import * as React from 'react';
import { Provider, css } from '@emotion/contextual';
export const Component = () => (
<Provider>
<div className={css({ width: 100, height: 100, background: '#000' })}>
Content
</div>
</Provider>
) The point here is that since 16.5 we are able to consume context with |
This component doesn’t only need context though, it also needs to render elements. |
This is needed for emotion to work with /~https://github.com/reactjs/react-modal. Check this commit in @storybooks. |
Codecov Report
|
I'm gonna merge this into #824 because I want to try some stuff out. If anyone has any comments on it, you can still leave them here though. |
What:
Add
StyleClassNames component.css
andcx
work just like the exports fromemotion
except they work with emotion 10's SSR and the options that can be provided via context.It also accepts the
theme
.Why:
To account for cases when components accept props like
wrapperClassName
and etc.How:
Checklist:
I'm not totally sure about the API, the name of the component and whether it should be in the core package. I'd love to hear people's thoughts on it!!