You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/component-parts.md
+17-18Lines changed: 17 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,9 +22,9 @@ How can a parent component customize the icon or text styles? With traditional a
22
22
- Use complex class name conventions
23
23
- Expose internal implementation details
24
24
25
-
## The Solution: `part` and `::part()`
25
+
## The Solution: `part` and `:part()`
26
26
27
-
CSSX solves this with the `part` attribute and `::part()` selector:
27
+
CSSX solves this with the `part` attribute and `:part()` selector:
28
28
29
29
### Step 1: Expose Parts in the Component
30
30
@@ -57,7 +57,7 @@ function Button({ icon, children }) {
57
57
58
58
### Step 2: Style Parts from the Parent
59
59
60
-
Use `::part()` (or `:part()`) to target those parts:
60
+
Use `:part()` (or `:part()`) to target those parts:
61
61
62
62
```jsx
63
63
functionApp() {
@@ -72,9 +72,9 @@ function App() {
72
72
styl`
73
73
.primary-button
74
74
background #28a745
75
-
.primary-button::part(icon)
75
+
.primary-button:part(icon)
76
76
color gold
77
-
.primary-button::part(text)
77
+
.primary-button:part(text)
78
78
font-weight bold
79
79
text-transform uppercase
80
80
`
@@ -85,7 +85,7 @@ The parent's styles are merged with the component's internal styles.
85
85
86
86
## How It Works
87
87
88
-
When you use `::part(name)`, CSSX:
88
+
When you use `:part(name)`, CSSX:
89
89
90
90
1. Creates a style prop named `{name}Style` (e.g., `iconStyle`, `textStyle`)
91
91
2. Passes it automatically to the child component
@@ -95,7 +95,7 @@ When you use `::part(name)`, CSSX:
95
95
// This:
96
96
<Button styleName="my-button"/>
97
97
styl`
98
-
.my-button::part(icon)
98
+
.my-button:part(icon)
99
99
color red
100
100
`
101
101
@@ -119,7 +119,7 @@ styl`
119
119
<Button style={{ background:'green' }} />
120
120
```
121
121
122
-
You don't need to write `::part(root)` explicitly — just style the class directly. This makes `part="root"` work seamlessly with any component that accepts a `style` prop, including third-party components and React Native built-ins.
122
+
You don't need to write `:part(root)` explicitly — just style the class directly. This makes `part="root"` work seamlessly with any component that accepts a `style` prop, including third-party components and React Native built-ins.
Copy file name to clipboardExpand all lines: docs/guide/index.md
+38-15Lines changed: 38 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ import { styl } from 'cssxjs'
35
35
36
36
functionButton({ children }) {
37
37
return (
38
-
<div part="root"styleName="root">
38
+
<div styleName="root">
39
39
{children}
40
40
</div>
41
41
)
@@ -49,16 +49,14 @@ function Button({ children }) {
49
49
}
50
50
```
51
51
52
-
The `part="root"` attribute allows parent components to style this element using `::part(root)` — a powerful composition pattern.
53
-
54
52
You can also use plain CSS if you prefer:
55
53
56
54
```jsx
57
55
import { css } from'cssxjs'
58
56
59
57
functionButton({ children }) {
60
58
return (
61
-
<div part="root"styleName="root">
59
+
<div styleName="root">
62
60
{children}
63
61
</div>
64
62
)
@@ -97,12 +95,14 @@ Works seamlessly on both **React Native** and **Web** (via react-native-web):
97
95
Style internal parts of child components from the parent — similar to CSS Shadow Parts:
98
96
99
97
```jsx
100
-
// Parent can style Button's internal parts
98
+
// Parent can style Button and its internal parts
101
99
styl`
102
-
.myButton::part(icon)
103
-
color green
104
-
.myButton::part(text)
105
-
font-weight bold
100
+
.myButton
101
+
background green
102
+
&:part(icon)
103
+
color gold
104
+
&:part(text)
105
+
font-weight bold
106
106
`
107
107
```
108
108
@@ -138,14 +138,17 @@ Automatic style caching prevents unnecessary re-renders. With the optional teamp
138
138
2.**Runtime**: The `styleName` prop applies matching styles based on class names
139
139
3.**Parts**: Components expose styled parts that parents can override
140
140
141
+
Use the `part` attribute to mark elements that can be styled from outside. The special `part="root"` maps to the standard `style` prop, letting parent components style your component directly:
0 commit comments