proposal: unify selector definition API #2848
Labels
core
Processing and transforming logic
discussion
Ongoing conversation
feature
New syntax feature or behavior
WIP
This proposal tries to unify the way selector API is defined in stylable. It's replacing previous st-part proposal for a broader solution aims to make the syntax simpler while adding capabilities that have been long requested and required for future experience we talked about.
Goals
Base Proposal
Single at-rule directive to enrich CSS definitions.
Define a Component
Define Pseudo States
Nested pseudo-states are defined as nested
@st
following a pseudo-class syntax (colon+name).To set a non boolean state the name can be followed with parentheses with type definition similar to how states are defined today.
Equivalent today
usage
Define Pseudo Elements
Nested pseudo-elements are defined as nested
@st
following a pseudo-element syntax (double colon+name) with fat-arrow mapping them to a selector a relative selector list.Equivalent today
Usage
Map to Class (syntactic sugar)
In most cases components need to map parts to simple classes. For this, this proposal offers to allow definition of pseudo-element with a nested
@st
following a class name.Equivalent today
Deep Structure
Nested definitions or parts and states can help define deep API. This is a new capability that the current syntax doesn't allow without splitting into multiple stylesheets.
Inheritance
In order to reuse definitions, a component or an inner part can extend a known definition.
Equivalent today
Usage
Inheritance hide
Inherited states and parts can be blocked from usage with
@st-hide
Inheritance override
Inherited states and parts can be overridden by re-defining them. While override like this is possible with the current syntax, we probably want to add explicit "override" syntax to show intent and prevent unintended API overlap.
Equivalent today
Usage
Global
To escape out of namespacing, for targeting non-stylable CSS, mapping to global namespace can be used.
Equivalent today
Usage
Base styling
While Stylable encourage separation of component interface and style, some cases might want to include styling because they are part of the base look/structure. So styles nested within
@st
definitions are allowed and preserved in transpilation.Ambient root
This change allows us to define multiple components in a single stylesheet, and makes the default
.root
class unnecessary.In addition it opens up the possibility for components that have different parts that aren't nested under a single root, like a tooltip with the anchor part and the popup part.
Open questions / considerations
Base styling specificity
Any styling set within the
@st
definition is considered as base style, and should be easily overridden by customization, however the deep structure causes the styles to gain specificity that can be hard to override.There are 2 possible options that we are currently considering:
:where
to minimize base styling specificity@layer
to isolate it from any higher level componentA layer can always be added manually by a user (and is also less supported atm), and the where can be optional with some added configuration.
Base styling inheritance strategy
When setting nested styles within the
@st
definition, does pseudo selectors refer to the defined component or the extended definition?Option 1 - refer to the extended definition:
Option 2 - nesting parts refer to extended until override (order matters):
@st in @media?
If base styling is allowed, is there a way to define
@st
parts and states within media/conditional rules?Export classes with "." prefix
We wanted to change the way
@st-import
works to have classes prefixed with.
for a while and it might be a good chance to change the mode when opting-in to use this new mode. This will remove the ambiguity with imported elements and collisions with other symbols that cannot start with a dot.This change can be made in 2 places:
@st
at-rulein modules import statements from the opt-in stylesheetThe first is more self contained and the second one will probably prevent some stylesheets from migrating to the new syntax, so their consumers won't have to change anything.
The text was updated successfully, but these errors were encountered: