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

Commit d22f950

Browse files
Merge pull request #395 from HoukasaurusRex/develop
docs: add vuepress installation guide
2 parents a1f47dd + a400a47 commit d22f950

File tree

1 file changed

+140
-0
lines changed

1 file changed

+140
-0
lines changed

website/pages/with-vuepress.mdx

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
import SEO from '../components/SEO'
2+
import { CodeGroup, CodeTab } from '~/components/code'
3+
4+
<SEO
5+
title="Using UI with Vuepress"
6+
description="Getting started with Chakra UI and Vuepress"
7+
/>
8+
9+
# Usage with Vuepress
10+
11+
If you use Vuepress, you can extend your theme to install Chakra globally using Vuepress's [theme inheritance](https://vuepress.vuejs.org/theme/inheritance.html).
12+
13+
<carbon-ad />
14+
15+
## Installation
16+
17+
Install Chakra UI Vue and its peer dependency, `@emotion/css`
18+
19+
<br/>
20+
21+
<CodeGroup lang="bash">
22+
<CodeTab label="Yarn">
23+
yarn add @chakra-ui/vue @emotion/css
24+
</CodeTab>
25+
<CodeTab label="NPM">
26+
npm install @chakra-ui/vue @emotion/css
27+
</CodeTab>
28+
</CodeGroup>
29+
30+
## Usage
31+
32+
### Extend Your Theme
33+
34+
First create a `theme` folder in your .vuepress directory and extend you Vuepress theme in your `theme/index.js` file.
35+
36+
```js
37+
module.exports = {
38+
extend: '@vuepress/theme-default' // whichever vuepress theme you use
39+
}
40+
```
41+
42+
### Add Chakra's Global Mixins
43+
44+
Add the Chakra UI providers in your `theme/enhanceApp.js` file as shown.
45+
46+
```js
47+
import Chakra, { internalIcons, defaultTheme, parsePackIcons } from '@chakra-ui/vue'
48+
import { faHandHoldingHeart } from '@fortawesome/free-solid-svg-icons'
49+
50+
export default ({
51+
Vue, // the version of Vue being used in the VuePress app
52+
options, // the options for the root Vue instance
53+
router, // the router instance for the app
54+
siteData, // site metadata
55+
isServer // is this enhancement applied in server-rendering or client
56+
}) => {
57+
Vue.use(Chakra)
58+
Vue.mixin({
59+
provide () {
60+
return {
61+
$chakraTheme: () => defaultTheme,
62+
$chakraColorMode: () => this.colorMode,
63+
$toggleColorMode: this.toggleColorMode,
64+
// icons must be parsed and spread into the icons provider to be available globally
65+
$chakraIcons: {
66+
...internalIcons,
67+
...parsePackIcons({ faHandHoldingHeart })
68+
}
69+
}
70+
},
71+
methods: {
72+
toggleColorMode () {
73+
this.colorMode = this.colorMode === 'light' ? 'dark' : 'light'
74+
}
75+
}
76+
})
77+
})
78+
```
79+
80+
Now you can wrap your main application inside the Chakra `CThemeProvider` component by creating a layout wrapper in `theme/layouts/Layout.vue`.
81+
82+
```vue
83+
<template>
84+
<CThemeProvider>
85+
<CReset /> <!-- NOTE: Resetting styles may have adverse effects on some themes -->
86+
<Layout />
87+
</CThemeProvider>
88+
</template>
89+
90+
<script>
91+
import { CThemeProvider, CReset } from '@chakra-ui/vue'
92+
import Layout from '@parent-theme/layouts/Layout.vue'
93+
94+
export default {
95+
name: 'ChakraLayout',
96+
components: {
97+
CThemeProvider,
98+
CReset,
99+
Layout
100+
}
101+
}
102+
</script>
103+
```
104+
105+
106+
## Using Chakra components
107+
108+
_In your `App.vue` file._
109+
110+
```vue
111+
<template>
112+
<c-box>
113+
<c-button>
114+
Chakra Consumed! ⚡️
115+
</c-button>
116+
</c-box>
117+
</template>
118+
119+
<script lang="js">
120+
import { CBox, CButton } from '@chakra-ui/vue'
121+
122+
export default {
123+
name: 'App',
124+
components: {
125+
CBox,
126+
CButton
127+
}
128+
}
129+
</script>
130+
```
131+
132+
### Codesandbox starters
133+
134+
- [Vue Starter](https://codesandbox.io/s/chakra-ui-vue-starter-2sy0g)
135+
- [Nuxt Starter](https://codesandbox.io/s/chakra-ui-nuxt-demo-f8tq4)
136+
- [Gridsome Starter](https://codesandbox.io/s/chakra-ui-gridsome-demo-038c9)
137+
138+
### Storybook Components
139+
140+
You can also view all developed components in [Storybook](https://chakra-ui-vue.netlify.com)!

0 commit comments

Comments
 (0)