Skip to content

Commit 086b343

Browse files
committed
docs(api-reference): [core] supplement docs
1 parent 855f34b commit 086b343

File tree

19 files changed

+161
-146
lines changed

19 files changed

+161
-146
lines changed

docs/.vitepress/config.mts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ export default defineConfig({
2929
'copy-error': '复制失败',
3030
},
3131
},
32-
32+
3333
// https://vitepress.dev/reference/default-theme-config
3434
nav: [
3535
{ text: 'Home', link: '/' },
3636
{ text: 'Guide', link: '/guide/basic/quick-start' },
3737
],
38-
38+
3939
sidebar: [
4040
{
4141
text: 'Basic',
@@ -51,8 +51,15 @@ export default defineConfig({
5151
text: 'Advances',
5252
items: [{ text: 'Theming', link: '/guide/advances/theming' }],
5353
},
54+
{
55+
text: 'API',
56+
items: [
57+
{ text: 'Core', link: '/guide/api/core' },
58+
{ text: 'Utils', link: '/guide/api/utils' },
59+
],
60+
},
5461
],
55-
62+
5663
socialLinks: [{ icon: 'github', link: 'https://github.com/vue-styled-components/vue3-styled-components' }],
5764
},
5865
markdown: {

docs/api-examples.md

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

docs/guide/api/core.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
outline: deep
3+
---
4+
5+
# Core
6+
7+
### `styled`
8+
9+
It is a factory function.
10+
11+
#### Properties
12+
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. |
17+
18+
#### Arguments
19+
20+
| Params | Type |
21+
|------------------|-------------------------|
22+
| Tag Name | `SupportedHTMLElements` |
23+
| Props Definition | `Record<string, any>` |
24+
25+
#### Return
26+
27+
- `Tag Function`, used to create a styled component.
28+
29+
#### Usage
30+
31+
:::demo
32+
33+
```vue
34+
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+
`
47+
</script>
48+
49+
<template>
50+
<StyledDiv color="#fff">Hi, I'm styled component.🥺</StyledDiv>
51+
</template>
52+
```
53+
54+
:::
55+
56+
### `.arrts`
57+
58+
It is used for passing attributes to styled component.
59+
60+
#### Arguments
61+
62+
| Params | Type |
63+
|--------------|------------------------------------|
64+
| Attrs Object | `Record<string, number \| string>` |
65+
66+
#### Return
67+
68+
- `Tag Function`, used to create a styled component.

docs/guide/api/utils.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
outline: deep
3+
---

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ hero:
1212
actions:
1313
- theme: brand
1414
text: Get started
15-
link: /markdown-examples
15+
link: /guide/basic/quick-start
1616
- theme: alt
1717
text: View on Github
1818
link: https://github.com/vue-styled-components/vue3-styled-components

docs/markdown-examples.md

Lines changed: 0 additions & 85 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { ExpressionsType } from '@/utils'
2+
import { defineComponent, h } from 'vue'
3+
import { generateComponentName, insertExpressions } from '@/utils'
4+
import { injectStyle } from '@/utils/injectStyle'
5+
6+
export const createGlobalStyle = (styles: TemplateStringsArray, ...expressions: ExpressionsType) => {
7+
return defineComponent(
8+
(_, { attrs }) => {
9+
const cssStringsWithExpression = insertExpressions(styles, expressions)
10+
injectStyle('global', cssStringsWithExpression, attrs)
11+
return () => {
12+
return h('div', { style: 'display: none' })
13+
}
14+
},
15+
{
16+
name: generateComponentName('global'),
17+
inheritAttrs: true,
18+
styled: true
19+
} as any
20+
)
21+
}

package/helper/css.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { ExpressionsType, insertExpressions } from '@/utils'
2+
3+
export function css(strings: TemplateStringsArray, ...interpolations: ExpressionsType) {
4+
return insertExpressions(strings, interpolations)
5+
}

package/helper/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export * from './withAttrs'
2+
export * from './is'
3+
export * from './create-global-style'
4+
export * from './keyframes'
5+
export * from './css'
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@ export function isStyledComponent(target: any) {
99
}
1010

1111
export function isVueComponent(target: any) {
12-
return target && (typeof target.render === 'function' || typeof target.template === 'string')
12+
return target && (typeof target.setup === 'function' || typeof target.render === 'function' || typeof target.template === 'string')
13+
}
14+
15+
export function isValidElementType(target: any) {
16+
return isTag(target) || isStyledComponent(target) || isVueComponent(target)
1317
}

0 commit comments

Comments
 (0)