Skip to content

Commit 5121d8f

Browse files
committed
docs(nest-css): add docs for Component Selector
1 parent ae52619 commit 5121d8f

File tree

3 files changed

+91
-4
lines changed

3 files changed

+91
-4
lines changed

packages/docs/guide/advances/nest-css.md

+44-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ outline: deep
44

55
# Nest CSS
66

7+
## Basic Usage
8+
79
In Vue Styled Components, you can write CSS in the same way as `less` or `sass`. `@vue-styled-components/core` is based on `stylis` compiling CSS to basic css, so you needn't worry about the compatibility.
810

911
For example, you can write CSS like this:
@@ -32,4 +34,45 @@ const StyledDiv = styled.div`
3234
// .styled-xxx:hover:active {
3335
// background-color: #fff;
3436
// }
35-
```
37+
```
38+
39+
## Use `Component` as Selector
40+
41+
You can use `StyledComponent` as selector. For example:
42+
43+
:::demo
44+
```vue
45+
<script setup lang="ts">
46+
import styled, { ThemeProvider } from '@vue-styled-components/core'
47+
import { reactive } from 'vue'
48+
49+
const Container = styled.div`
50+
display: inline-block;
51+
padding: 4px 12px;
52+
`
53+
54+
const Button = styled.button`
55+
padding: 8px 24px;
56+
border-radius: 24px;
57+
color: white;
58+
background: black;
59+
`
60+
61+
const NewContainer = styled(Container)`
62+
${Button} {
63+
color: black;
64+
background: gray;
65+
}
66+
`
67+
</script>
68+
69+
<template>
70+
<Container>
71+
<Button>Button</Button>
72+
</Container>
73+
<NewContainer>
74+
<Button>Button</Button>
75+
</NewContainer>
76+
</template>
77+
```
78+
:::

packages/docs/guide/advances/theming.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ const changeTheme = () => {
100100
```
101101
:::
102102

103-
## Functional Theme
103+
## Function Theme
104104

105-
You may need to use functional themes, instead of object themes. For example, you may need to reverse colors, or change the color based on other conditions.
105+
You may need to use function themes, instead of object themes. For example, you may need to reverse colors, or change the color based on other conditions.
106106

107107
:::demo
108108
```vue

packages/docs/zh/guide/advances/nest-css.md

+45-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ outline: deep
44

55
# 嵌套 CSS
66

7+
## 基础用法
8+
79
你可以像 `less`, `sass` 一样使用嵌套 CSS。 `@vue-styled-components/core` 并非使用最新的CSS规范([nest css](https://drafts.csswg.org/css-nesting/#nesting))来实现,而是使用了 `stylis` 编译为最基础的 CSS,因此你不需要担心其兼容性问题。
810

911
如下:
@@ -35,4 +37,46 @@ const StyledDiv = styled.div`
3537
// .styled-xxx:hover:active {
3638
// background-color: #fff;
3739
// }
38-
```
40+
```
41+
42+
43+
## 使用组件作为选择器
44+
45+
你可以使用 `StyledComponent` 作为选择器,会自动转换为类选择器。例如:
46+
47+
:::demo
48+
```vue
49+
<script setup lang="ts">
50+
import styled, { ThemeProvider } from '@vue-styled-components/core'
51+
import { reactive } from 'vue'
52+
53+
const Container = styled.div`
54+
display: inline-block;
55+
padding: 4px 12px;
56+
`
57+
58+
const Button = styled.button`
59+
padding: 8px 24px;
60+
border-radius: 24px;
61+
color: white;
62+
background: black;
63+
`
64+
65+
const NewContainer = styled(Container)`
66+
${Button} {
67+
color: black;
68+
background: gray;
69+
}
70+
`
71+
</script>
72+
73+
<template>
74+
<Container>
75+
<Button>Button</Button>
76+
</Container>
77+
<NewContainer>
78+
<Button>Button</Button>
79+
</NewContainer>
80+
</template>
81+
```
82+
:::

0 commit comments

Comments
 (0)