Skip to content

Commit 122e854

Browse files
committed
docs(theme): add desc for useTheme
1 parent f82e67f commit 122e854

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

packages/docs/guide/advances/theming.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ const Link = defineComponent(() => {
130130

131131
:::
132132

133+
## Getting Theme by Hook
134+
135+
Yet you can also get theme by using `useTheme` hook, but it must be used within a `ThemeProvider`.
136+
137+
The usage see [useTheme](/guide/api/hook)
138+
133139
## How to Get Theme Hints with TypeScript
134140

135141
When using styled components, you might reference your theme context like `${props => props.theme.primary}`. To enable TypeScript to provide autocomplete hints and type checking for your theme properties, you can extend the `DefaultTheme` interface.

packages/docs/guide/api/hook.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ outline: deep
44

55
# Hook
66

7-
## useStyledClassName <div style="display: inline-flex; align-items: center;"><Badge type="info" text="deprecated at v1.3.0.beta.1" /></div>
7+
## `useTheme`
88

99
**Return**
1010

11-
- `getStyledClassName`, `styledComponentInstance => string`
12-
- `styledClassNameMap`, `Record<string, string>`, `{[componentName]: className}`
11+
- `DefaultTheme`
1312

1413
**Usage**
1514

1615
```vue
1716
<script setup lang="ts">
18-
import { styled, useStyledClassName } from '@vue-styled-components/core'
17+
import styled, { useTheme } from '@vue-styled-components/core'
18+
19+
const theme = useTheme()
1920
2021
const StyledDiv = styled.div`
21-
background: #ccc;
22+
background: ${ theme.bg };
2223
`
23-
console.log(useStyledClassName(StyledDiv)) // styled-xxx(unique id)
2424
</script>
2525
```

packages/docs/zh/guide/advances/theming.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ const Link = defineComponent(() => {
123123

124124
:::
125125

126+
## 通过 Hook 获取主题
127+
128+
你还可以通过 `useTheme` 获取主题,但前提是必须属于 `ThemeProvider` 的组件树内。
129+
130+
使用方法参考 [useTheme](/zh/guide/api/hook)
131+
126132
## 如何通过 TypeScript 获取主题提示?
127133

128134
在使用 styled 组件时,你可能会通过 `${props => props.theme.primary}` 引用你的主题上下文。为了让 TypeScript 能够提供自动补全提示并进行类型检查,你可以扩展 `DefaultTheme` 接口。

packages/docs/zh/guide/api/hook.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,22 @@ outline: deep
44

55
# Hook
66

7-
## useStyledClassName <div style="display: inline-flex; align-items: center;"><Badge type="info" text="deprecated at v1.3.0.beta.1" /></div>
7+
## `useTheme`
88

9-
**返回**
9+
**Return**
1010

11-
- `getStyledClassName`, `styledComponentInstance => string`
12-
- `styledClassNameMap`, `Record<string, string>`, `{[componentName]: className}`
11+
- `DefaultTheme`
1312

14-
**用法**
13+
**使用**
1514

1615
```vue
1716
<script setup lang="ts">
18-
import { styled, useStyledClassName } from '@vue-styled-components/core'
17+
import styled, { useTheme } from '@vue-styled-components/core'
18+
19+
const theme = useTheme()
1920
2021
const StyledDiv = styled.div`
21-
background: #ccc;
22+
background: ${ theme.bg };
2223
`
23-
const { getStyledClassName } = useStyledClassName()
24-
console.log(getStyledClassName(StyledDiv)) // styled-xxx(unique id)
2524
</script>
2625
```

0 commit comments

Comments
 (0)