-
Notifications
You must be signed in to change notification settings - Fork 21
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
Proposal/RFC convention that mimics CSS parts and state #1030
base: develop
Are you sure you want to change the base?
Conversation
Not sure if you mean that the components all use the same naming, such as the |
In the perfect case, I would like all to use just
In the native case, the collisions are avoided automatically, as we got scoping for free. Just by the fact, it's a CSS pseudo element
So the part selector is never used alone. It's used with some other selector, to match witin the selected element. To mimic that behavior for React components, we could either enforce policy, to:
|
I know it's not a problem in native case, but what I meant about the concern is that mimics
Even though using another name instead of For example, basic components and composite components for share usage, and a consumer side component. function Icon() {
return <img className="part--icon" />;
}
function Item() {
return (
<ul className="gla-item">
{ /*<Icon />*/ }
<div className="part--title" />
<div className="part--description" />
</ul>
);
}
function List( { items } ) {
return (
<div className="gla-list">
<Icon />
<div className="part--title" />
<li>
{ items.map( () => (
<Item />
) ) }
</li>
</div>
);
}
function Page() {
return (
<div className="some-page">
<Icon />
<div className="part--description" />
<List />
</div>
);
} Possible styling problems: .some-page {
.part--description {
// Want to style page's description but also affect items' description
}
.part--title {
// Attempt to style title of either list or item without looking into the implementation details,
// but affects another one.
}
.gla-list {
.part--icon {
// Styled list's icon correctly without affecting to page's icon.
// But it might still break something if one day the <Icon> is added to <Item>,
// such as the commented out part within <Item>.
}
}
} I think that is why the convention of prefix component names like BEM is necessary. |
I'm trying to understand the real issue from within this proposal comes. It's just about conflicts? I was reading about the history of the project in order to get more context. I would appreciate a briefing about the context, otherwise, I will read all the related PR's little by little. Re- CSS Conflicts I used this (implemented by default in NextJS) https://github.com/css-modules/css-modules Never had a CSS conflict since I use it. And there are kinda default also in React Apps World (I know you don't 100% like it but that is where we are). Check some use cases here: https://css-tricks.com/css-modules-part-1-need/#what-are-css-modules |
Changes proposed in this Pull Request:
This is an RFC & POC of a CSS classes convention, to make React components, mimic native CSS behavior of
:part
and:--state
(Custom Pseudo Class).Despite the syntactic sugar, the main take here is that the component author specifies the parts/areas/classes as a part of public API, for external CSS styling. Then a consumer does not need to dig into the source code of imported components and rely on implementation details.
Benefits:
Drawbacks:
Detailed test instructions:
Additional
::part
,:--
equivalent for React components. (:host
,element-name
, &::slotted
would be great as well).