Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit 7b23cab

Browse files
committed
docs: add `` utility documentation to the color-mode page
1 parent 7edce2b commit 7b23cab

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

website/pages/color-mode.mdx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,45 @@ export default {
127127
}
128128
</script>
129129
```
130+
131+
## Computing values with `mode` utility function
132+
`@chakra-ui/vue@^0.10.0` exports a `mode` function that accepts two arguments for the `'light'` and `'dark'` mode respectively.
133+
When the current color mode is `'light'`, it returns the first argument. If the color mode is `'dark'`, it returns the second argument.
134+
135+
```js
136+
import Vue from 'vue'
137+
import Chakra, { mode } from '@chakra-ui/vue'
138+
139+
Vue.use(Chakra, {
140+
extendTheme: {
141+
baseStyles: {
142+
CIconButton: () => ({
143+
/**
144+
* When the color mode is `light`, `mode` returns `'blackAlpha.700'`.
145+
* Otherwise it returns `'whiteAlpha.400'`.
146+
*/
147+
color: mode('blackAlpha.700', 'whiteAlpha.400')
148+
})
149+
}
150+
}
151+
})
152+
```
153+
154+
### Usage in templates
155+
The `mode` function is also made globally available inside your Vue application context so you do not have to import it inside your
156+
Vue SFCs. You can access it by invoking `this.$mode` in the template or in your script.
157+
158+
```vue live=true
159+
<template>
160+
<c-box
161+
:bg="[
162+
$mode('orange.600', 'yellow.100'),
163+
$mode('pink.600', 'green.100')
164+
]"
165+
:color="$mode('white', 'blackAlpha.800')"
166+
@click="chakraToggleColorMode"
167+
>
168+
Box "{{ chakraColorMode }}" mode. Click me to toggle color mode.
169+
</c-box>
170+
</template>
171+
```

website/pages/overriding-component-styles.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Vue.use(Chakra, {
4949
})
5050
```
5151

52-
### Using the `mode` function
52+
### With the `mode` function
5353
`@chakra-ui/vue@^0.10.0` also exports a `mode` function that accepts two arguments for the `'light'` and `'dark'` mode respectively. When the current color mode is `'light'`, it returns the first argument. If the color mode is `'dark'`, it returns the second argument.
5454

5555
```js
@@ -59,7 +59,7 @@ import Chakra, { mode } from '@chakra-ui/vue'
5959
Vue.use(Chakra, {
6060
extendTheme: {
6161
baseStyles: {
62-
CIconButton: ({ colorMode }) => ({
62+
CIconButton: () => ({
6363
/**
6464
* When the color mode is `light`, `mode` returns `'blackAlpha.700'`.
6565
* Otherwise it returns `'whiteAlpha.400'`.

0 commit comments

Comments
 (0)