@@ -21,14 +21,21 @@ pages can break down into components using `data-component`
2121
2222components can break down into slots using ` data-slot `
2323
24- structure things so that this hierarchy is followed - you should rarely need to
24+ structure things so that this hierarchy is followed IN YOUR CSS - you should rarely need to
2525nest components inside other components. you should NEVER nest components inside
2626slots. you should NEVER nest slots inside other slots.
2727
28- thei hierarchy in css file does NOT have to match the hierarchy in the dom - you
29- can put components or slots at the same level even if one goes inside another.
28+ ** IMPORTANT: This hierarchy rule applies to CSS structure, NOT JSX/DOM structure.**
3029
31- it is more important to follow the pages -> components -> slots structure
30+ The hierarchy in css file does NOT have to match the hierarchy in the dom - you
31+ can put components or slots at the same level in CSS even if one goes inside another in the DOM.
32+
33+ Your JSX can nest however makes semantic sense - components can be inside slots,
34+ slots can contain components, etc. The DOM structure should be whatever makes the most
35+ semantic and functional sense.
36+
37+ It is more important to follow the pages -> components -> slots structure IN YOUR CSS,
38+ while keeping your JSX/DOM structure logical and semantic.
3239
3340use data attributes to represent different states of the component
3441
@@ -59,3 +66,35 @@ page specific styles should go next to the page they are styling so
5966` ./src/routes/about.tsx ` should have its styles in ` ./src/routes/about.css `
6067
6168` about.css ` should be scoped using ` data-page="about" `
69+
70+ ## Example of correct implementation
71+
72+ JSX can nest however makes sense semantically:
73+
74+ ``` jsx
75+ < div data- slot= " left" >
76+ < div data- component= " title" > Section Title< / div>
77+ < div data- slot= " content" > Content here< / div>
78+ < / div>
79+ ```
80+
81+ CSS maintains clean hierarchy regardless of DOM nesting:
82+
83+ ``` css
84+ [data-page = " home" ] {
85+ [data-component ="screenshots "] {
86+ [data-slot ="left "] {
87+ /* styles */
88+ }
89+ [data-slot = " content" ] {
90+ /* styles */
91+ }
92+ }
93+
94+ [data-component = " title" ] {
95+ /* can be at same level even though nested in DOM */
96+ }
97+ }
98+ ```
99+
100+ See ./src/routes/index.css and ./src/routes/index.tsx for a complete example.
0 commit comments