Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit 164237e

Browse files
committed
docs: add gradient docs
1 parent 41791d7 commit 164237e

File tree

2 files changed

+135
-1
lines changed

2 files changed

+135
-1
lines changed

docs/.vitepress/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ function getSetupSidebar() {
4949
{
5050
text: 'Features',
5151
children: [
52-
{ text: 'Style Props', link: '/pages/features/style-props' }
52+
{ text: 'Style Props', link: '/pages/features/style-props' },
53+
{ text: 'Gradient', link: '/pages/features/gradient' }
5354
]
5455
},
5556
{

docs/pages/features/gradient.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
Gradients are a way to have transition between two or more colors. You can add
2+
gradient support using any of the following style props.
3+
4+
- `bgGradient`: a shorthand, convenient style prop to apply theme-aware
5+
gradients.
6+
- `bgClip`: a shorthand for `background-clip` CSS attribute. Useful when
7+
creating text gradients.
8+
- `backgroundClip`: the typical `background-clip` CSS attribute. Useful when
9+
creating text gradients.
10+
11+
## Background Gradient API
12+
13+
To add a gradient to an element, pass the `bgGradient` prop and set its value
14+
following the API:
15+
16+
- `linear(<direction>, <from>, <to>)`
17+
- `radial(<from>, <to>)`
18+
19+
You can also use other CSS gradient types like `repeating-linear`, `conic`, etc.
20+
21+
For linear gradients, the `<direction>` can be set to the default CSS directions
22+
(e.g. `to top`) or the shorthand equivalent (e.g `to-t`).
23+
24+
Here's the list of supported direction shorthands and their respective values:
25+
26+
```json
27+
{
28+
"to-t": "to top",
29+
"to-tr": "to top right",
30+
"to-r": "to right",
31+
"to-br": "to bottom right",
32+
"to-b": "to bottom",
33+
"to-bl": "to bottom left",
34+
"to-l": "to left",
35+
"to-tl": "to top left"
36+
}
37+
```
38+
39+
## Usage
40+
41+
Let's create a basic gradient from `green.200` to `pink.500`
42+
43+
```jsx
44+
<c-box w="100%" h="200px" bgGradient="linear(to-r, green.200, pink.500)" />
45+
```
46+
47+
### Customizing Colors
48+
49+
You can use both theme-aware color tokens or raw CSS color values.
50+
51+
```jsx
52+
<c-box w="100%" h="200px" bgGradient="linear(to-l, #7928CA, #FF0080)" />
53+
```
54+
55+
### Multiple Color Stops
56+
57+
By adding more color-stop points on the gradient line, you can create a highly
58+
customized transition between multiple colors.
59+
60+
```jsx
61+
<c-box
62+
w="100%"
63+
h="200px"
64+
bgGradient="linear(to-r, gray.300, yellow.400, pink.200)"
65+
/>
66+
```
67+
68+
Following the CSS gradient specification, you can also define the distribution
69+
of the color stops
70+
71+
```jsx
72+
<c-box
73+
w="100%"
74+
h="200px"
75+
bgGradient="linear(red.100 0%, orange.100 25%, yellow.100 50%)"
76+
/>
77+
```
78+
79+
## Text Gradient API
80+
81+
To add a text gradient, pass the `bgGradient` following the API and `bgClip`
82+
prop to `text`.
83+
84+
```jsx
85+
<c-text
86+
bgGradient="linear(to-l, #7928CA, #FF0080)"
87+
bgClip="text"
88+
fontSize="6xl"
89+
fontWeight="extrabold"
90+
>
91+
Welcome to Chakra UI Vue
92+
</c-text>
93+
```
94+
95+
## Responsive Gradients
96+
97+
You can control the responsiveness of gradients by specifying the gradients at
98+
the different breakpoints.
99+
100+
```jsx
101+
<c-box
102+
w="100%"
103+
h="200px"
104+
bgGradient={[
105+
"linear(to-tr, teal.300, yellow.400)",
106+
"linear(to-t, blue.200, teal.500)",
107+
"linear(to-b, orange.100, purple.300)",
108+
]}
109+
/>
110+
```
111+
112+
## Changing gradient with pseudo props
113+
114+
You can change the gradient of an element based on common CSS pseudo attributes
115+
(hover, focus, active, etc).
116+
117+
For example, on hover, add the gradient you wish to have.
118+
119+
```jsx
120+
<c-box
121+
as="button"
122+
p={4}
123+
color="white"
124+
fontWeight="bold"
125+
borderRadius="md"
126+
bgGradient="linear(to-r, teal.500, green.500)"
127+
_hover={{
128+
bgGradient: "linear(to-r, red.500, yellow.500)",
129+
}}
130+
>
131+
Click here
132+
</c-box>
133+
```

0 commit comments

Comments
 (0)