Skip to content

Commit ae42623

Browse files
committed
docs: improve docs, fix mistakes
1 parent f77d1b1 commit ae42623

10 files changed

Lines changed: 77 additions & 54 deletions

File tree

docs/api/css.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ The custom `u` unit works in `css` too:
116116
### Part Selectors
117117

118118
```css
119-
.button::part(icon) {
119+
.button:part(icon) {
120120
color: red;
121121
}
122122

123-
.button::part(text) {
123+
.button:part(text) {
124124
font-weight: bold;
125125
}
126126
```

docs/api/jsx-props.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function ProgressBar({ progress }) {
8282

8383
## part
8484

85-
Expose an element for external styling via `::part()`.
85+
Expose an element for external styling via `:part()`.
8686

8787
```jsx
8888
function Button({ children }) {
@@ -101,17 +101,17 @@ Parent components can then style these parts:
101101

102102
```jsx
103103
styl`
104-
.my-button::part(icon)
104+
.my-button:part(icon)
105105
color gold
106-
.my-button::part(text)
106+
.my-button:part(text)
107107
font-weight bold
108108
`
109109
```
110110

111111
### How Parts Work
112112

113113
1. Child component marks elements with `part="name"`
114-
2. Parent uses `::part(name)` selector to target those elements
114+
2. Parent uses `:part(name)` selector to target those elements
115115
3. Babel transforms both sides to connect them automatically
116116

117117
See the [Component Parts guide](/guide/component-parts) for detailed examples.

docs/api/styl-function.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ function Parent() {
9595
styl`
9696
.card
9797
background white
98-
.card::part(title)
98+
.card:part(title)
9999
font-weight bold
100-
.card::part(icon)
100+
.card:part(icon)
101101
color blue
102102
`
103103
}
104104
```
105105

106-
The part styles from both class selectors (`.card::part(title)`) and inline (`titleStyle`) are merged together.
106+
The part styles from both class selectors (`.card:part(title)`) and inline (`titleStyle`) are merged together.
107107

108108
## Combining with Props
109109

docs/api/styl.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ See [CSS Variables](/api/variables) for runtime variable updates.
197197
| `.class` | Class selector |
198198
| `.class1.class2` | Multiple classes (same element) |
199199
| `&.modifier` | Modifier class (used within parent) |
200-
| `::part(name)` | Part selector |
200+
| `:part(name)` | Part selector |
201201

202202
> **Note:** Descendant selectors (`.parent .child`) are not supported. Apply modifiers directly to each element that needs styling.
203203
@@ -208,10 +208,10 @@ See [CSS Variables](/api/variables) for runtime variable updates.
208208
Target internal parts of child components:
209209

210210
```stylus
211-
.button::part(icon)
211+
.button:part(icon)
212212
color red
213213
214-
.button::part(text)
214+
.button:part(text)
215215
font-weight bold
216216
```
217217

docs/examples/card.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function Card({ title, subtitle, children, actions }) {
6363

6464
## Styling from Parent
6565

66-
Use `::part()` selectors to customize the card from parent components:
66+
Use `:part()` selectors to customize the card from parent components:
6767

6868
```jsx
6969
import { styl } from 'cssxjs'
@@ -92,14 +92,14 @@ function ProductCard({ product }) {
9292
.product-card
9393
max-width 320px
9494
95-
&::part(header)
96-
background linear-gradient(135deg, #667eea, #764ba2)
95+
&:part(header)
96+
background #667eea
9797
padding 16px 20px
9898
99-
&::part(title)
99+
&:part(title)
100100
color white
101101
102-
&::part(subtitle)
102+
&:part(subtitle)
103103
color rgba(255,255,255,0.8)
104104
font-size 20px
105105
font-weight 600
@@ -121,5 +121,5 @@ function ProductCard({ product }) {
121121
## Key Concepts
122122

123123
- **`part` attribute** exposes elements for external styling
124-
- **`::part()` selector** targets parts from parent components
124+
- **`:part()` selector** targets parts from parent components
125125
- **Encapsulation** — Card defines structure, parent customizes appearance

docs/guide/component-parts.md

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ How can a parent component customize the icon or text styles? With traditional a
2222
- Use complex class name conventions
2323
- Expose internal implementation details
2424

25-
## The Solution: `part` and `::part()`
25+
## The Solution: `part` and `:part()`
2626

27-
CSSX solves this with the `part` attribute and `::part()` selector:
27+
CSSX solves this with the `part` attribute and `:part()` selector:
2828

2929
### Step 1: Expose Parts in the Component
3030

@@ -57,7 +57,7 @@ function Button({ icon, children }) {
5757

5858
### Step 2: Style Parts from the Parent
5959

60-
Use `::part()` (or `:part()`) to target those parts:
60+
Use `:part()` (or `:part()`) to target those parts:
6161

6262
```jsx
6363
function App() {
@@ -72,9 +72,9 @@ function App() {
7272
styl`
7373
.primary-button
7474
background #28a745
75-
.primary-button::part(icon)
75+
.primary-button:part(icon)
7676
color gold
77-
.primary-button::part(text)
77+
.primary-button:part(text)
7878
font-weight bold
7979
text-transform uppercase
8080
`
@@ -85,7 +85,7 @@ The parent's styles are merged with the component's internal styles.
8585

8686
## How It Works
8787

88-
When you use `::part(name)`, CSSX:
88+
When you use `:part(name)`, CSSX:
8989

9090
1. Creates a style prop named `{name}Style` (e.g., `iconStyle`, `textStyle`)
9191
2. Passes it automatically to the child component
@@ -95,7 +95,7 @@ When you use `::part(name)`, CSSX:
9595
// This:
9696
<Button styleName="my-button" />
9797
styl`
98-
.my-button::part(icon)
98+
.my-button:part(icon)
9999
color red
100100
`
101101

@@ -119,7 +119,7 @@ styl`
119119
<Button style={{ background: 'green' }} />
120120
```
121121

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.
123123

124124
## Complete Example
125125

@@ -189,13 +189,12 @@ function App() {
189189
190190
.featured-card
191191
flex 1
192-
&::part(root)
193-
background linear-gradient(135deg, #667eea, #764ba2)
194-
&::part(header)
192+
background #667eea
193+
&:part(header)
195194
border-bottom-color rgba(255,255,255,0.2)
196-
&::part(title)
195+
&:part(title)
197196
color white
198-
&::part(content)
197+
&:part(content)
199198
color rgba(255,255,255,0.9)
200199
`
201200
}
@@ -216,10 +215,10 @@ function Page() {
216215
)
217216

218217
styl`
219-
.page::part(sidebar)
218+
.page:part(sidebar)
220219
width 250px
221220
222-
.main-card::part(header)
221+
.main-card:part(header)
223222
background #f5f5f5
224223
`
225224
}
@@ -252,13 +251,13 @@ Combine class selectors with parts for conditional styling:
252251

253252
```jsx
254253
styl`
255-
.button::part(icon)
254+
.button:part(icon)
256255
color gray
257256
258-
.button.primary::part(icon)
257+
.button.primary:part(icon)
259258
color white
260259
261-
.button.danger::part(icon)
260+
.button.danger:part(icon)
262261
color red
263262
`
264263
```

docs/guide/index.md

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { styl } from 'cssxjs'
3535

3636
function Button({ children }) {
3737
return (
38-
<div part="root" styleName="root">
38+
<div styleName="root">
3939
{children}
4040
</div>
4141
)
@@ -49,16 +49,14 @@ function Button({ children }) {
4949
}
5050
```
5151

52-
The `part="root"` attribute allows parent components to style this element using `::part(root)` — a powerful composition pattern.
53-
5452
You can also use plain CSS if you prefer:
5553

5654
```jsx
5755
import { css } from 'cssxjs'
5856

5957
function Button({ children }) {
6058
return (
61-
<div part="root" styleName="root">
59+
<div styleName="root">
6260
{children}
6361
</div>
6462
)
@@ -97,12 +95,14 @@ Works seamlessly on both **React Native** and **Web** (via react-native-web):
9795
Style internal parts of child components from the parent — similar to CSS Shadow Parts:
9896

9997
```jsx
100-
// Parent can style Button's internal parts
98+
// Parent can style Button and its internal parts
10199
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
106106
`
107107
```
108108

@@ -138,14 +138,17 @@ Automatic style caching prevents unnecessary re-renders. With the optional teamp
138138
2. **Runtime**: The `styleName` prop applies matching styles based on class names
139139
3. **Parts**: Components expose styled parts that parents can override
140140

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:
142+
141143
```jsx
144+
// Card.jsx
142145
import { styl } from 'cssxjs'
143146

144-
function Card({ children, variant }) {
147+
function Card({ title, children }) {
145148
return (
146-
<div part="root" styleName={['root', variant]}>
149+
<div part="root" styleName="root">
147150
<div part="header" styleName="header">
148-
<span part="title" styleName="title">Title</span>
151+
<span part="title" styleName="title">{title}</span>
149152
</div>
150153
<div part="content" styleName="content">{children}</div>
151154
</div>
@@ -156,9 +159,6 @@ function Card({ children, variant }) {
156159
background white
157160
border-radius 8px
158161
159-
&.primary
160-
border 2px solid var(--primary-color)
161-
162162
.header
163163
padding 2u
164164
@@ -172,6 +172,29 @@ function Card({ children, variant }) {
172172
}
173173
```
174174

175+
```jsx
176+
// App.jsx — styling Card from the parent
177+
import { styl } from 'cssxjs'
178+
import { Card } from './Card'
179+
180+
function App() {
181+
return (
182+
<Card styleName="featured-card" title="Welcome">
183+
Hello world!
184+
</Card>
185+
)
186+
187+
styl`
188+
.featured-card
189+
background #667eea
190+
&:part(title)
191+
color white
192+
&:part(content)
193+
color rgba(255,255,255,0.9)
194+
`
195+
}
196+
```
197+
175198
## Next Steps
176199

177200
- [Installation](/guide/installation) - Set up CSSX in your project

docs/guide/pug.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ function UserProfile({ user, isOnline, onLogout }) {
212212
align-items center
213213
gap 16px
214214
padding 20px
215-
background linear-gradient(135deg, #667eea, #764ba2)
215+
background #667eea
216216
217217
.avatar
218218
width 64px

docs/guide/usage.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ CSSX runs on React Native, so not all CSS features are available.
226226
| Class selectors | `.card`, `.button` | |
227227
| Compound selectors | `.card.featured` | Same element |
228228
| Parent reference `&` | `&.active`, `&.disabled` | `styl` only |
229-
| Part selectors | `::part(icon)`, `:part(text)` | |
229+
| Part selectors | `:part(icon)`, `:part(text)` | |
230230
| CSS variables | `var(--color)`, `var(--size, 16px)` | |
231231
| Animations | `animation fadeIn 0.3s ease` | Reanimated v4 components only |
232232
| Keyframes | `@keyframes fadeIn` | Reanimated v4 components only |
@@ -248,6 +248,7 @@ CSSX runs on React Native, so not all CSS features are available.
248248
| Descendant selectors | `.parent .child` — add modifier to child directly |
249249
| Attribute selectors | `[type="text"]` — use class modifiers instead |
250250
| `:first-child`, `:nth-child` | Handle in JS when rendering |
251+
| `linear-gradient`, `radial-gradient` | Use solid colors or images |
251252

252253
### Example: Replacing :hover
253254

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ features:
2121
details: Same styles work on iOS, Android, and Web via react-native-web. Write once, run everywhere
2222
icon: 📱
2323
- title: Component Parts
24-
details: Style internal elements of child components using ::part() selectors, similar to CSS Shadow Parts
24+
details: Style internal elements of child components using :part() selectors, similar to CSS Shadow Parts
2525
icon: 🧩
2626
- title: Dynamic CSS Variables
2727
details: Use var(--name) with runtime updates. Change themes instantly and components re-render automatically

0 commit comments

Comments
 (0)