Skip to content

Commit c16f36e

Browse files
committed
docs: update all examples to use RN components instead of web-only div, span, button etc.
1 parent 8536661 commit c16f36e

23 files changed

Lines changed: 662 additions & 508 deletions

docs/api/babel.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,18 @@ The Babel preset transforms:
7878
### Before Transform
7979

8080
```jsx
81+
import { View, Text } from 'react-native'
82+
8183
function Button({ children }) {
8284
return (
83-
<button styleName="button">
84-
<span part="icon"></span>
85-
{children}
86-
</button>
85+
<View styleName="root">
86+
<Text part="icon" styleName="icon"></Text>
87+
<Text styleName="text">{children}</Text>
88+
</View>
8789
)
8890

8991
styl`
90-
.button
92+
.root
9193
padding 12px 24px
9294
background blue
9395
`
@@ -107,6 +109,7 @@ CSSX works with TypeScript. The `styl` and `pug` template literals are removed a
107109

108110
```tsx
109111
import { styl } from 'cssxjs'
112+
import { View, Text } from 'react-native'
110113

111114
interface CardProps {
112115
title: string
@@ -115,10 +118,10 @@ interface CardProps {
115118

116119
function Card({ title, children }: CardProps) {
117120
return (
118-
<div styleName="card">
119-
<h2 styleName="title">{title}</h2>
121+
<View styleName="card">
122+
<Text styleName="title">{title}</Text>
120123
{children}
121-
</div>
124+
</View>
122125
)
123126

124127
styl`

docs/api/css.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,24 @@ The `css` template literal lets you write styles using plain CSS syntax.
66

77
```jsx
88
import { css } from 'cssxjs'
9+
import { Pressable, Text } from 'react-native'
910

1011
function Button({ children }) {
11-
return <button styleName="button">{children}</button>
12+
return (
13+
<Pressable styleName="button">
14+
<Text styleName="text">{children}</Text>
15+
</Pressable>
16+
)
1217

1318
css`
1419
.button {
1520
padding: 12px 24px;
1621
background: #007bff;
17-
color: white;
1822
border-radius: 8px;
1923
}
24+
.text {
25+
color: white;
26+
}
2027
`
2128
}
2229
```
@@ -34,6 +41,8 @@ Use `css` instead of `styl` when you:
3441
Works the same as `styl` — inside a function for component-scoped styles, or at module level for shared styles:
3542

3643
```jsx
44+
import { View } from 'react-native'
45+
3746
// Module-level (shared)
3847
css`
3948
.shared-button {
@@ -42,7 +51,7 @@ css`
4251
`
4352

4453
function Card() {
45-
return <div styleName="card">...</div>
54+
return <View styleName="card">...</View>
4655

4756
// Function-level (scoped)
4857
css`

docs/api/jsx-props.md

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,49 @@ CSSX extends JSX with custom props for styling.
77
Apply class-based styles to an element. Works like `className` but with scoped, processed styles.
88

99
```jsx
10-
<div styleName="card featured">Content</div>
10+
<View styleName="card featured">
11+
<Text>Content</Text>
12+
</View>
1113
```
1214

1315
**Syntax Options:**
1416

1517
```jsx
1618
// String — simple static class
17-
<div styleName="card" />
19+
<View styleName="card" />
1820

1921
// Array with object — recommended for dynamic classes
20-
<div styleName={['card', variant, { active, disabled }]} />
22+
<View styleName={['card', variant, { active, disabled }]} />
2123
```
2224

2325
### Array Pattern (Recommended)
2426

2527
Use arrays with an object at the end for modifiers:
2628

2729
```jsx
28-
function Card({ variant, highlighted, compact }) {
30+
import { View, Text } from 'react-native'
31+
32+
function Card({ variant, highlighted, compact, children }) {
2933
return (
30-
<div styleName={['card', variant, { highlighted, compact }]}>
31-
Content
32-
</div>
34+
<View styleName={['card', variant, { highlighted, compact }]}>
35+
<Text>{children}</Text>
36+
</View>
3337
)
3438

3539
styl`
3640
.card
3741
background white
38-
border 1px solid #ddd
42+
border-width 1px
43+
border-color #ddd
3944
padding 16px
4045
4146
&.featured
42-
border 2px solid gold
47+
border-width 2px
48+
border-color gold
4349
4450
&.highlighted
45-
box-shadow 0 0 10px gold
51+
shadow-color gold
52+
shadow-radius 10px
4653
4754
&.compact
4855
padding 8px
@@ -62,18 +69,19 @@ The pattern:
6269
For truly dynamic values, combine `styleName` with the `style` prop:
6370

6471
```jsx
72+
import { View, Text } from 'react-native'
73+
6574
function ProgressBar({ progress }) {
6675
return (
67-
<div styleName="bar" style={{ width: `${progress}%` }}>
68-
{progress}%
69-
</div>
76+
<View styleName="bar" style={{ width: `${progress}%` }}>
77+
<Text>{progress}%</Text>
78+
</View>
7079
)
7180

7281
styl`
7382
.bar
7483
height 20px
7584
background-color #4caf50
76-
transition width 0.3s
7785
`
7886
}
7987
```
@@ -85,12 +93,14 @@ function ProgressBar({ progress }) {
8593
Expose an element for external styling via `:part()`.
8694

8795
```jsx
96+
import { Pressable, Text } from 'react-native'
97+
8898
function Button({ children }) {
8999
return (
90-
<button part="root" styleName="root">
91-
<span part="icon"></span>
92-
<span part="text">{children}</span>
93-
</button>
100+
<Pressable part="root" styleName="root">
101+
<Text part="icon" styleName="icon"></Text>
102+
<Text part="text" styleName="text">{children}</Text>
103+
</Pressable>
94104
)
95105
}
96106
```

0 commit comments

Comments
 (0)