Skip to content

Commit 1705c76

Browse files
committed
docs(advance): [tailwind-css] add usage documents
1 parent a5d2696 commit 1705c76

File tree

5 files changed

+184
-8
lines changed

5 files changed

+184
-8
lines changed

packages/docs/.vitepress/cache/deps/_metadata.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
{
2-
"hash": "54b90a79",
2+
"hash": "55e25838",
33
"configHash": "3c7637e1",
4-
"lockfileHash": "122ab0a0",
5-
"browserHash": "ddb6c01e",
4+
"lockfileHash": "c539e7c4",
5+
"browserHash": "7345505d",
66
"optimized": {
77
"vue": {
88
"src": "../../../../../node_modules/.pnpm/vue@3.4.38_typescript@5.4.5/node_modules/vue/dist/vue.runtime.esm-bundler.js",
99
"file": "vue.js",
10-
"fileHash": "da2889df",
10+
"fileHash": "faf410e5",
1111
"needsInterop": false
1212
},
1313
"vitepress > @vue/devtools-api": {
1414
"src": "../../../../../node_modules/.pnpm/@vue+devtools-api@7.0.27_vue@3.4.38_typescript@5.4.5_/node_modules/@vue/devtools-api/dist/index.js",
1515
"file": "vitepress___@vue_devtools-api.js",
16-
"fileHash": "f3cb0771",
16+
"fileHash": "13c4d3c1",
1717
"needsInterop": false
1818
},
1919
"vitepress > @vueuse/core": {
2020
"src": "../../../../../node_modules/.pnpm/@vueuse+core@10.9.0_vue@3.4.38_typescript@5.4.5_/node_modules/@vueuse/core/index.mjs",
2121
"file": "vitepress___@vueuse_core.js",
22-
"fileHash": "c99140c1",
22+
"fileHash": "8d3aa876",
2323
"needsInterop": false
2424
},
2525
"vue-demi": {
2626
"src": "../../../../../node_modules/.pnpm/vitepress@1.1.4_@algolia+client-search@4.23.3_@types+node@20.12.7_postcss@8.4.41_search-insights@2.13.0_typescript@5.4.5/node_modules/vitepress/lib/vue-demi.mjs",
2727
"file": "vue-demi.js",
28-
"fileHash": "74931243",
28+
"fileHash": "dbaf235e",
2929
"needsInterop": false
3030
},
3131
"stylis": {
3232
"src": "../../../../../node_modules/.pnpm/stylis@4.3.2/node_modules/stylis/index.js",
3333
"file": "stylis.js",
34-
"fileHash": "d95cdf52",
34+
"fileHash": "0d6f93f8",
3535
"needsInterop": false
3636
}
3737
},

packages/docs/.vitepress/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function sidebarGuide() {
5757
{ text: 'CSS Mixin', link: 'css-mixin' },
5858
{ text: 'Nest CSS', link: 'nest-css' },
5959
{ text: 'Auto Prefix', link: 'auto-prefix' },
60+
{ text: 'Tailwind CSS', link: 'tailwind-css' },
6061
],
6162
},
6263
{

packages/docs/.vitepress/zh.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ function sidebarGuide() {
8181
{ text: '样式复用', link: 'css-mixin' },
8282
{ text: '嵌套CSS', link: 'nest-css' },
8383
{ text: 'CSS私有前缀', link: 'auto-prefix' },
84+
{ text: 'Tailwind CSS', link: 'tailwind-css' },
8485
],
8586
},
8687
{
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
outline: deep
3+
---
4+
5+
# Use Tailwind CSS
6+
7+
Starting from version `1.6.0`, `@vue-style-components/core` provides a `tw` function to insert `Tailwind CSS` classes into the `class` attribute of a Vue Component.
8+
9+
> Before staring to use `Tailwind CSS`, you need to install it first. ([How to install Tailwind CSS?](https://tailwindcss.com/docs/installation/using-postcss))
10+
11+
## Basic Usage
12+
13+
```vue
14+
<script setup lang="ts">
15+
import styled, { tw } from '@vue-styled-components/core'
16+
17+
const StyledDiv = styled.div`
18+
${tw`w-20 h-20 bg-red-500`}
19+
`
20+
</script>
21+
<template>
22+
<StyledDiv />
23+
</template>
24+
```
25+
26+
## Use tailwind css conditionally
27+
28+
```vue
29+
<script setup lang="ts">
30+
import styled, { tw } from '@vue-styled-components/core'
31+
32+
const StyledDiv = styled('div', { isRed: true })`
33+
width: 20px;
34+
height: 20px;
35+
${props => props.isRed && tw`bg-red-500`}
36+
`
37+
</script>
38+
<template>
39+
<StyledDiv />
40+
</template>
41+
```
42+
43+
## Compose Tailwind CSS
44+
45+
```vue
46+
<script setup lang="ts">
47+
import styled, { tw } from '@vue-styled-components/core'
48+
49+
const twButton = tw`px-4 py-2 rounded-md`
50+
51+
const StyledSmallButton = styled.div`
52+
width: 20px;
53+
height: 20px;
54+
${twButton}
55+
`
56+
57+
const StyledLargeButton = styled.div`
58+
width: 40px;
59+
height: 20px;
60+
${twButton}
61+
`
62+
</script>
63+
<template>
64+
<StyledSmallButton>small button</StyledSmallButton>
65+
<StyledLargeButton>large button</StyledLargeButton>
66+
</template>
67+
```
68+
69+
## Dynamic Tailwind CSS Classes
70+
71+
```vue
72+
<script setup lang="ts">
73+
import styled, { tw } from '@vue-styled-components/core'
74+
75+
const color = 'red'
76+
77+
const StyledDiv = styled('div', { isRed: true })`
78+
width: 20px;
79+
height: 20px;
80+
${tw`bg-red-500 ${`bg-${color}-500`}`}
81+
`
82+
</script>
83+
<template>
84+
<StyledDiv />
85+
</template>
86+
```
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
outline: deep
3+
---
4+
5+
# 使用 Tailwind CSS
6+
7+
`v1.6.0` 版本起支持使用 `Tailwind CSS` 构建样式。
8+
9+
> 开始前请 [安装及配置 `Tailwind CSS`](https://tailwindcss.com/docs/installation/using-postcss)
10+
11+
## 基础使用
12+
13+
`@vue-style-components/core` 提供了 `tw` 函数,用于将 `Tailwind CSS` 的类名插入为 Vue Component 的 `class` 属性。
14+
15+
```vue
16+
<script setup lang="ts">
17+
import styled, { tw } from '@vue-styled-components/core'
18+
19+
const StyledDiv = styled.div`
20+
${tw`w-20 h-20 bg-red-500`}
21+
`
22+
</script>
23+
<template>
24+
<StyledDiv />
25+
</template>
26+
```
27+
28+
## 动态控制
29+
30+
```vue
31+
<script setup lang="ts">
32+
import styled, { tw } from '@vue-styled-components/core'
33+
34+
const StyledDiv = styled('div', { isRed: true })`
35+
width: 20px;
36+
height: 20px;
37+
${props => props.isRed && tw`bg-red-500`}
38+
`
39+
</script>
40+
<template>
41+
<StyledDiv />
42+
</template>
43+
```
44+
45+
## 抽象为公共样式
46+
47+
```vue
48+
<script setup lang="ts">
49+
import styled, { tw } from '@vue-styled-components/core'
50+
51+
const twButton = tw`px-4 py-2 rounded-md`
52+
53+
const StyledSmallButton = styled.div`
54+
width: 20px;
55+
height: 20px;
56+
${twButton}
57+
`
58+
59+
const StyledLargeButton = styled.div`
60+
width: 40px;
61+
height: 20px;
62+
${twButton}
63+
`
64+
</script>
65+
<template>
66+
<StyledSmallButton>small button</StyledSmallButton>
67+
<StyledLargeButton>large button</StyledLargeButton>
68+
</template>
69+
```
70+
71+
## 动态类名
72+
73+
```vue
74+
<script setup lang="ts">
75+
import styled, { tw } from '@vue-styled-components/core'
76+
77+
const color = 'red'
78+
79+
const StyledDiv = styled('div', { isRed: true })`
80+
width: 20px;
81+
height: 20px;
82+
${tw`bg-red-500 ${`bg-${color}-500`}`}
83+
`
84+
</script>
85+
<template>
86+
<StyledDiv />
87+
</template>
88+
```

0 commit comments

Comments
 (0)