Skip to content

Commit 56012a1

Browse files
committed
update style props documentation
1 parent e38b2c4 commit 56012a1

File tree

2 files changed

+49
-10
lines changed

2 files changed

+49
-10
lines changed

README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,20 @@ const StyledLink = styled(Link, {
187187

188188
### Style Props
189189

190-
The second argument to the `styled` function also accepts a function that returns a styles object based on the props passed to the component:
190+
The second argument to the `styled` function also accepts a style resolver function that returns a styles object based on the props passed to the component:
191191

192192
```tsx
193193
import { styled } from 'restyle'
194194

195-
type GridProps = {
195+
interface GridStyleProps {
196196
gridTemplateColumns: string
197+
gridTemplateRows: string
197198
}
198199

199-
const Grid = styled('div', (props: GridProps) => ({
200+
const Grid = styled('div', (styleProps: GridStyleProps) => ({
200201
display: 'grid',
201-
gridTemplateColumns: props.gridTemplateColumns,
202+
gridTemplateColumns: styleProps.gridTemplateColumns,
203+
gridTemplateRows: styleProps.gridTemplateRows,
202204
}))
203205
```
204206

@@ -213,7 +215,24 @@ Now you can use these props to style the component:
213215
```
214216

215217
> [!IMPORTANT]
216-
> A proxy is used to differentiate between style props and those passed directly to the component. Therefore, only style props should be accessed within the function to ensure proper filtering.
218+
> A proxy is used to differentiate between style props and those passed directly to the component. Only style props should be accessed from the first parameter of the style resolver function to ensure proper filtering.
219+
220+
To access the props passed to the component, you can use the second parameter of the style resolver function. This is useful for applying styles based on props that are not style props:
221+
222+
```tsx
223+
import { styled } from 'restyle'
224+
225+
interface ButtonStyleProps {
226+
backgroundColor: string
227+
color: string
228+
}
229+
230+
const Button = styled('button', (styleProps: ButtonStyleProps, props) => ({
231+
backgroundColor: styleProps.backgroundColor,
232+
color: styleProps.color,
233+
opacity: props.disabled ? 0.6 : 1,
234+
}))
235+
```
217236

218237
### CSS Function
219238

site/app/Examples.mdx

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,20 @@ const StyledLink = styled(Link, {
2828

2929
### Style Props
3030

31-
The second argument to the `styled` function also accepts a function that returns a styles object based on the props passed to the component:
31+
The second argument to the `styled` function also accepts a style resolver function that returns a styles object based on the props passed to the component:
3232

3333
```tsx
3434
import { styled } from 'restyle'
3535

36-
type GridProps = {
36+
interface GridStyleProps {
3737
gridTemplateColumns: string
38+
gridTemplateRows: string
3839
}
3940

40-
const Grid = styled('div', (props: GridProps) => ({
41+
const Grid = styled('div', (styleProps: GridStyleProps) => ({
4142
display: 'grid',
42-
gridTemplateColumns: props.gridTemplateColumns,
43+
gridTemplateColumns: styleProps.gridTemplateColumns,
44+
gridTemplateRows: styleProps.gridTemplateRows,
4345
}))
4446
```
4547

@@ -53,7 +55,25 @@ Now you can use these props to style the component:
5355
</Grid>
5456
```
5557

56-
**Note**, a proxy is used to differentiate between style props and those passed directly to the component. Therefore, only style props should be accessed within the function to ensure proper filtering.
58+
> [!IMPORTANT]
59+
> A proxy is used to differentiate between style props and those passed directly to the component. Only style props should be accessed from the first parameter of the style resolver function to ensure proper filtering.
60+
61+
To access the props passed to the component, you can use the second parameter of the style resolver function. This is useful for applying styles based on props that are not style props:
62+
63+
```tsx
64+
import { styled } from 'restyle'
65+
66+
interface ButtonStyleProps {
67+
backgroundColor: string
68+
color: string
69+
}
70+
71+
const Button = styled('button', (styleProps: ButtonStyleProps, props) => ({
72+
backgroundColor: styleProps.backgroundColor,
73+
color: styleProps.color,
74+
opacity: props.disabled ? 0.6 : 1,
75+
}))
76+
```
5777

5878
### CSS Function
5979

0 commit comments

Comments
 (0)