-
Notifications
You must be signed in to change notification settings - Fork 62
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: explicit custom-pseudo-element definition #2713
Comments
We should also document nested parts and pseudo elements overriding possibilities when combining nested parts and |
I wrote in the proposal about nested parts:
I think the first iteration of this will not include parts definitions with body that will allow extending, adding states or defining inline styles, but I can definitely see this extending in this direction. It isn't detailed, but I assume it will follow the same rules as a root extending another definition, just inline. So for example we could have an Accordion component with a header that extends something and defines nested parts that would override definitions from the extended definition: /* accordion.st.css */
@st-part ::header {
-st-extends: Box;
@st-part ::icon {}
@st-part ::title {}
} From the outside: in case the Box had an icon, it would be overridden by the Accordion icon, while the Box frame that is not overridden can still be accessed. @st-import Accordion from './accordion.st.css';
/* style the accordion icon inside the accordion header */
Accordion::header::icon {}
/* style the Box frame of the accordion header */
Accordion::header::frame {} |
Looking a bit forwards at issues with the nesting mechanism, we encountered some aspects that needs more clarifications. Implicit classWhen implicitly mapping a part to a class the part inherits the class definition: @st-part ::navBtn;
.navBtn {
-st-extends: Button;
}
/* .local__navBtn .button__label */
::navBtn::label {}
/* .local__navBtn .button__label */
.navBtn::label {} Inherit SugarAdding @st-part ::navBtn {
-st-extends: Button;
}
/* .local__navBtn .button__label */
::navBtn::label {}
/* .local__navBtn .button__label */
.navBtn::label {} Nesting PartsAdding a nested part defines style API to the part under the specific pseudo-element, and overrides the access to a part with identical name if it exist in the inherited extend, but doesn't change the class definition(!): @st-part ::navBtn {
-st-extends: Button;
@st-part ::label;
}
/* .local__navBtn .local__label */
::navBtn::label {}
/* .local__navBtn .button__label */
.navBtn::label {} The code above overrides the
Multiple Identical Parts and collisionsThere are cases where we want to have a part with the same name/class available in multiple placed in the structure: /* top level nav button that targets all navigation buttons */
@st-part ::navBtn;
@st-part ::header {
/* match more specific navigation buttons under the header */
@st-part ::navBtn;
}
/* .local__navBtn */
::navBtn {}
/* .local__header .local__navBtn */
::header::navBtn {} In this case setting @st-part ::navBtn {
/* this extend will be used */
-st-extends: Button;
};
@st-part ::header {
/* match more specific navigation buttons under the header */
@st-part ::navBtn {
/* ERROR: already extended */
-st-extends: Other;
}
}
.navBtn {
/* ERROR: already extended */
-st-extends: Other;
} |
closing in favor of #2848 |
We talked before (internally) about semantic primitives like component, part, theme, and variant to allow better DX. And this new proposal attempts to define the
@st-part
.Current state
Stylable does not allow explicit "part" definition,
custom-pseudo-element
is the result of other definitions:class
is a "part" - for every css class there is a publiccustom-pseudo-element
accessible from the stylesheet root.@custom-selector
can be used to override a the type and transformation of acustom-pseudo-element
derived from a class.Goal
simplify
custom-pseudo-element
definition by opting-in to a new "part" syntax:@custom-selector
is used by stylable todayProposal
When using the new
@st-part
:custom-pseudo-element
fromclass
definitioncustom-pseudo-element
definition to the root class@custom-selector
redundant and deprecated by adding it's selector mapping abilities to@st-part
(we can revive it to use a native implementation if it will be formal one day)custom-pseudo-element
style API - not exported by name to other stylesheetsSyntax
Examples
Implied class
Providing no class defaults to a class selector of the same name
Map selector to to target recursive structures
Then customize the Tree with the style API
Map to multiple
Open questions
custom-pseudo-element
to be used only within their definition stylesheet?explicit exports
- automatically export any of the part's selector classes to Javascript runtime to wire the view?Only class sugar definition
Report error for attempting to define a complex selector:
Styling could also be inlined:
The text was updated successfully, but these errors were encountered: