Skip to content

Commit 7818395

Browse files
committed
docs: add api reference documents
1 parent 288631b commit 7818395

File tree

4 files changed

+176
-40
lines changed

4 files changed

+176
-40
lines changed

docs/.vitepress/config.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default defineConfig({
5555
text: 'API',
5656
items: [
5757
{ text: 'Core', link: '/guide/api/core' },
58-
{ text: 'Utils', link: '/guide/api/utils' },
58+
{ text: 'Helper', link: '/guide/api/helper' },
5959
],
6060
},
6161
],

docs/guide/api/core.md

Lines changed: 61 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,65 +4,90 @@ outline: deep
44

55
# Core
66

7-
### `styled`
7+
## `styled`
88

99
It is a factory function.
1010

11-
#### Properties
11+
**Augments**
1212

13-
| Properties | Description |
14-
|------------|------------------------------------------------------------------------------------------------------------------------------------------|
15-
| HTML Tag | See [Supported HTML Tags](https://github.com/vue-styled-components/vue3-styled-components/blob/master/package/constants/domElements.ts). |
16-
| attrs | Pass attrs for styled component. |
13+
- Tag Name, `SupportedHTMLElements | Vue Component`, `required`
14+
- Props Definition, `Record<string, any>`
1715

18-
#### Arguments
16+
**Return**
1917

20-
| Params | Type |
21-
|------------------|-------------------------|
22-
| Tag Name | `SupportedHTMLElements` |
23-
| Props Definition | `Record<string, any>` |
18+
- Tag Function, used to create a styled component.
2419

25-
#### Return
20+
**Usage**
2621

27-
- `Tag Function`, used to create a styled component.
22+
```vue
23+
<script setup lang="ts">
24+
import { styled } from '@vue3-styled-components/package'
25+
26+
const StyledDiv = styled('div', { color: String })`
27+
width: 100%;
28+
padding: 0 10px;
29+
border-radius: 4px;
30+
text-align: center;
31+
`
32+
</script>
33+
34+
<template>
35+
<StyledDiv>Styled Div</StyledDiv>
36+
</template>
37+
```
38+
39+
### `.[HTML Tag]`
40+
41+
**Augments**
42+
43+
- Tagged Template Literal, `TemplateStringsArray`, `required`
44+
45+
**Return**
2846

29-
#### Usage
47+
- Vue Component, `DefineSetupFnComponent`
3048

31-
:::demo
49+
**Usage**
3250

3351
```vue
52+
<script setup lang="ts">
53+
import { styled } from '@vue3-styled-components/package'
3454
35-
<script setup>
36-
import { styled } from '@vue3-styled-components/package'
37-
38-
const StyledDiv = styled('div', { color: String })`
39-
width: 100%;
40-
height: 100px;
41-
border-radius: 4px;
42-
background-color: #6a488f;
43-
text-align: center;
44-
line-height: 100px;
45-
color: ${props => props.color};
46-
`
55+
const StyledDiv = styled.div`
56+
width: 40px;
57+
height: 40px;
58+
`
4759
</script>
4860
4961
<template>
50-
<StyledDiv color="#fff">Hi, I'm styled component.🥺</StyledDiv>
62+
<StyledDiv>Styled Component</StyledDiv>
5163
</template>
5264
```
5365

54-
:::
55-
5666
### `.arrts`
5767

5868
It is used for passing attributes to styled component.
5969

60-
#### Arguments
70+
**Augments**
71+
72+
- Attrs Object, `Record<string, number | string | boolean>`, `required`
73+
74+
**Return**
75+
76+
- Tag Function, used to create a styled component.
77+
78+
**Usage**
6179

62-
| Params | Type |
63-
|--------------|------------------------------------|
64-
| Attrs Object | `Record<string, number \| string>` |
80+
```vue
81+
<script setup lang="ts">
82+
import { styled } from '@vue3-styled-components/package'
6583
66-
#### Return
84+
const InputWithValue = styled.input.attrs({ value: "I'm input with default value. 🥺" })`
85+
width: 100%;
86+
height: 40px;
87+
`
88+
</script>
6789
68-
- `Tag Function`, used to create a styled component.
90+
<template>
91+
<InputWithValue type="text" />
92+
</template>
93+
```

docs/guide/api/helper.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
---
2+
outline: deep
3+
---
4+
5+
# Helper
6+
7+
## `createGlobalStyle`
8+
9+
A function to create a `style component` that can be used to handle global styles.
10+
11+
**Augments**
12+
13+
- Tagged Template Literal, `TemplateStringsArray`, `required`
14+
15+
**Return**
16+
17+
- Vue Component, `DefineSetupFnComponent`
18+
19+
**Usage**
20+
21+
```vue
22+
<script setup>
23+
import { createGlobalStyle } from '@vue3-styled-components/package'
24+
25+
const GlobalStyle = createGlobalStyle`
26+
body {
27+
color: ${(props) => props.color};
28+
}
29+
`
30+
</script>
31+
<template>
32+
<GlobalStyle color="white" />
33+
</template>
34+
```
35+
36+
## `keyframes`
37+
38+
A function to generate keyframes. It takes a template literal as an argument and returns a animation name.
39+
40+
**Augments**
41+
42+
- Tagged Template Literal, `TemplateStringsArray`, `required`
43+
44+
**Return**
45+
46+
- Animation Name, `string`
47+
48+
**Usage**
49+
50+
```vue
51+
<script setup lang="ts">
52+
import { styled, keyframes } from '@vue3-styled-components/package'
53+
54+
const animation = keyframes`
55+
from {
56+
opacity: 0;
57+
}
58+
to {
59+
opacity: 1;
60+
}
61+
`
62+
const DivWithAnimation = styled('div')`
63+
width: 100%;
64+
height: 40px;
65+
animation: ${animation} 2s ease-in infinite;
66+
`
67+
</script>
68+
<template>
69+
<DivWithAnimation>Div with animation</DivWithAnimation>
70+
</template>
71+
```
72+
73+
## `withAttrs`
74+
75+
A function to add attributes to a `ComponentInstance` or `HTMLElements`.
76+
**Augments**
77+
78+
- Component or Html Tag, `ComponentInstance | SupportedHTMLElements`, `required`
79+
- Attributes, `Record<string, any>`, `required`
80+
81+
**Return**
82+
83+
- Vue Component, `DefineSetupFnComponent`
84+
85+
**Usage**
86+
87+
```vue
88+
<script setup lang="ts">
89+
import { withAttrs } from '@vue3-styled-components/package'
90+
91+
const DivWithAttrs = withAttrs('div', {
92+
class: 'div-with-attrs'
93+
})
94+
95+
const DivWithAttrs2 = withAttrs(DivWithAttrs, {
96+
class: 'div-with-attrs-2'
97+
})
98+
</script>
99+
100+
<template>
101+
<DivWithAttrs>Div with attrs</DivWithAttrs>
102+
<DivWithAttrs2>Div with attrs 2</DivWithAttrs2>
103+
</template>
104+
105+
<style scope>
106+
.div-with-attrs {
107+
color: red;
108+
}
109+
110+
.div-with-attrs-2 {
111+
color: blue;
112+
}
113+
</style>
114+
```

docs/guide/api/utils.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)