Skip to content

Commit

Permalink
Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
aarongarciah committed Oct 9, 2024
1 parent 5336fa6 commit d0a2e12
Showing 1 changed file with 32 additions and 31 deletions.
63 changes: 32 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,42 +351,43 @@ There are two ways to achieve this (both involve using a CSS variable):

1. Declare a CSS variable directly in the styles and set its value using inline styles:

```jsx
const Heading = styled('h1')({
color: 'var(--color)',
});
```jsx
const Heading = styled('h1')({
color: 'var(--color)',
});

function Heading() {
const [color, setColor] = React.useState('red');
function Heading() {
const [color, setColor] = React.useState('red');

return <Heading style={{ '--color': color }} />;
}
```
return <Heading style={{ '--color': color }} />;
}
```

2. Use a callback function as a value to create a dynamic style for the specific CSS property:
```jsx
const Heading = styled('h1')({
color: ({ isError }) => (isError ? 'red' : 'black'),
});
```

Pigment CSS replaces the callback with a CSS variable and injects the value through inline styles. This makes it possible to create a static CSS file while still allowing dynamic styles.

```css
.Heading_class_akjsdfb {
color: var(--Heading_class_akjsdfb-0);
}
```

```jsx
<h1
style={{
'--Heading_class_akjsdfb-0': isError ? 'red' : 'black',
}}
>
Hello
</h1>
```
```jsx
const Heading = styled('h1')({
color: ({ isError }) => (isError ? 'red' : 'black'),
});
```

Pigment CSS replaces the callback with a CSS variable and injects the value through inline styles. This makes it possible to create a static CSS file while still allowing dynamic styles.

```css
.Heading_class_akjsdfb {
color: var(--Heading_class_akjsdfb-0);
}
```

```jsx
<h1
style={{
'--Heading_class_akjsdfb-0': isError ? 'red' : 'black',
}}
>
Hello
</h1>
```

#### Styled component as a CSS selector

Expand Down

0 comments on commit d0a2e12

Please sign in to comment.