Comments (4)
We should also document nested parts and pseudo elements overriding possibilities when combining nested parts and -st-extends
from stylable.
I wrote in the proposal about nested parts:
In the future we might want to allow nested parts definitions to provide a way to describe deep structure API
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 {}
from stylable.
Looking a bit forwards at issues with the nesting mechanism, we encountered some aspects that needs more clarifications.
Implicit class
When 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 Sugar
Adding -st-extends
under the part is syntactic sugar for setting the class to extend the extending reference.
For example the following code is sugar for ::navBtn
pseudo-element mapping to .navBtn
class and setting the .navBtn
class to extend the Button
component.
@st-part ::navBtn {
-st-extends: Button;
}
/* .local__navBtn .button__label */
::navBtn::label {}
/* .local__navBtn .button__label */
.navBtn::label {}
Nesting Parts
Adding 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 ::label
pseudo-element just under the ::navBtn
without effecting the .navBtn
class.
Notice that we focus on definition of parts, but definition of states would work in the same way.
Multiple Identical Parts and collisions
There 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-extends
in one of the ::navBtn
definitions would prevent setting -st-extends
in another, or directly inside the class definition, just as -st-extends
cannot be set in the same class more then once:
@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;
}
from stylable.
closing in favor of #2848
from stylable.
Related Issues (20)
- proposal: Type only class definition
- proposal: State declarations HOT 1
- @stylable/jest has no peer dependencies and is broken with jest 28
- `st-global` utility is not removed from valid @property definitions during transformation
- Imports with side effect HOT 1
- Add runtime validation to the options of our integrations HOT 2
- next.js with disabled JS not working HOT 3
- Unify analyze and transform hooks flow
- Stylesheet does not get applied when using Next.js 13 HOT 1
- Imported custom property false positive analysis
- CSS LSP emits false diagnostics for custom property global syntax
- build stylable without filesystem HOT 4
- question: how to get final css HOT 3
- Cyclic error combines mixin path and var paths
- -st-* declarations on imported class
- proposal: unify selector definition API HOT 1
- stylable build error with storybook 7 HOT 4
- Build errors when running create-stylable-app HOT 1
- Improve runtime injectCSS
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 stylable.