From 5854694907dbe0ec21db81b21e0dc0207a28c07f Mon Sep 17 00:00:00 2001 From: HoukasaurusRex Date: Sat, 6 Mar 2021 16:56:42 +0800 Subject: [PATCH] docs: add vuepress installation guide --- website/pages/with-vuepress.mdx | 140 ++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 website/pages/with-vuepress.mdx diff --git a/website/pages/with-vuepress.mdx b/website/pages/with-vuepress.mdx new file mode 100644 index 00000000..0ebcfc04 --- /dev/null +++ b/website/pages/with-vuepress.mdx @@ -0,0 +1,140 @@ +import SEO from '../components/SEO' +import { CodeGroup, CodeTab } from '~/components/code' + + + +# Usage with Vuepress + +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). + + + +## Installation + +Install Chakra UI Vue and its peer dependency, `@emotion/css` + +
+ + + + yarn add @chakra-ui/vue @emotion/css + + + npm install @chakra-ui/vue @emotion/css + + + +## Usage + +### Extend Your Theme + +First create a `theme` folder in your .vuepress directory and extend you Vuepress theme in your `theme/index.js` file. + +```js +module.exports = { + extend: '@vuepress/theme-default' // whichever vuepress theme you use +} +``` + +### Add Chakra's Global Mixins + +Add the Chakra UI providers in your `theme/enhanceApp.js` file as shown. + +```js +import Chakra, { internalIcons, defaultTheme, parsePackIcons } from '@chakra-ui/vue' +import { faHandHoldingHeart } from '@fortawesome/free-solid-svg-icons' + +export default ({ + Vue, // the version of Vue being used in the VuePress app + options, // the options for the root Vue instance + router, // the router instance for the app + siteData, // site metadata + isServer // is this enhancement applied in server-rendering or client +}) => { + Vue.use(Chakra) + Vue.mixin({ + provide () { + return { + $chakraTheme: () => defaultTheme, + $chakraColorMode: () => this.colorMode, + $toggleColorMode: this.toggleColorMode, + // icons must be parsed and spread into the icons provider to be available globally + $chakraIcons: { + ...internalIcons, + ...parsePackIcons({ faHandHoldingHeart }) + } + } + }, + methods: { + toggleColorMode () { + this.colorMode = this.colorMode === 'light' ? 'dark' : 'light' + } + } + }) +}) +``` + +Now you can wrap your main application inside the Chakra `CThemeProvider` component by creating a layout wrapper in `theme/layouts/Layout.vue`. + +```vue + + + +``` + + +## Using Chakra components + +_In your `App.vue` file._ + +```vue + + + +``` + +### Codesandbox starters + +- [Vue Starter](https://codesandbox.io/s/chakra-ui-vue-starter-2sy0g) +- [Nuxt Starter](https://codesandbox.io/s/chakra-ui-nuxt-demo-f8tq4) +- [Gridsome Starter](https://codesandbox.io/s/chakra-ui-gridsome-demo-038c9) + +### Storybook Components + +You can also view all developed components in [Storybook](https://chakra-ui-vue.netlify.com)!