This repository was archived by the owner on Sep 20, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +68
-15
lines changed Expand file tree Collapse file tree 6 files changed +68
-15
lines changed Original file line number Diff line number Diff line change
1
+ # @chakra-ui/nuxt-next
2
+
3
+ Nuxt.js Module for Chakra UI Vue
4
+
5
+ ## Installation
6
+
7
+ ``` sh
8
+ yarn add @chakra-ui/vue-next
9
+ # or
10
+ npm i @chakra-ui/vue-next
11
+ ```
12
+
13
+ ## Todo
14
+ - [ ] Install emotion
15
+ - [ ] Install plugin programmatically
Original file line number Diff line number Diff line change 29
29
"build:types" : " tsup src --dts-only"
30
30
},
31
31
"dependencies" : {
32
+ "@chakra-ui/c-color-mode" : " workspace:*" ,
32
33
"@chakra-ui/vue-next" : " workspace:*" ,
33
34
"@emotion/css" : " ^11.10.5" ,
34
35
"@emotion/server" : " ^11.10.0" ,
Original file line number Diff line number Diff line change @@ -6,24 +6,24 @@ import {
6
6
installModule ,
7
7
} from "@nuxt/kit"
8
8
import type * as NuxtSchema from "@nuxt/schema"
9
+ import { ChakraPluginOptions } from "@chakra-ui/vue-next"
9
10
10
- export default defineNuxtModule ( {
11
+ export default defineNuxtModule < ChakraPluginOptions > ( {
11
12
meta : {
12
- name : "@chakra-ui/nuxt-nect " ,
13
+ name : "@chakra-ui/nuxt-next " ,
13
14
configKey : "chakra" ,
14
15
compatibilty : ">=3.0.0" ,
15
16
} ,
16
- setup ( _ , nuxt ) {
17
+ setup ( _options , nuxt ) {
17
18
console . log ( "chakra-ui-nuxt:module" )
18
- /**
19
- * Register emotion plugin
20
- */
19
+ const theme = _options . extendTheme
21
20
21
+ // Install emotion module
22
22
installModule ( "@nuxtjs/emotion" )
23
23
const { resolve } = createResolver ( import . meta. url )
24
24
const runtimeDir = resolve ( "./runtime" )
25
25
nuxt . options . build . transpile . push ( runtimeDir )
26
26
addServerPlugin ( resolve ( runtimeDir , "chakra.server" ) )
27
- addPlugin ( resolve ( runtimeDir , "chakra.client " ) )
27
+ addPlugin ( resolve ( runtimeDir , "chakra.universal " ) )
28
28
} ,
29
29
} )
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
import type { NitroApp } from "nitropack"
2
+ import { H3Event , parseCookies } from "h3"
2
3
3
4
/**
4
5
* Why are we declaring types for `defineNitroPlugin`?
@@ -21,6 +22,19 @@ export function defineNitroPlugin(def: NitroAppPlugin): NitroAppPlugin {
21
22
return def
22
23
}
23
24
24
- export default defineNitroPlugin ( ( nitroApp ) => {
25
+ const CHAKRA_UI_COLOR_MODE_COOKIE_KEY = "chakra-ui-color-mode"
26
+
27
+ export default defineNitroPlugin ( ( app ) => {
25
28
console . log ( "chakra-ui-nuxt:server_runtime" )
29
+ app . hooks . hook ( "render:html" , ( html , { event : rawEvent } ) => {
30
+ const event = new H3Event ( rawEvent . node . req , rawEvent . node . res )
31
+ const parsedCookies = parseCookies ( event )
32
+ const colorMode = parsedCookies [ CHAKRA_UI_COLOR_MODE_COOKIE_KEY ]
33
+
34
+ if ( colorMode ) {
35
+ html . htmlAttrs . push ( `data-theme="${ colorMode } "` )
36
+ html . htmlAttrs . push ( `style="color-scheme: ${ colorMode } ;"` )
37
+ html . htmlAttrs . push ( `data-chakra-ui-ssr="true"` )
38
+ }
39
+ } )
26
40
} )
Original file line number Diff line number Diff line change
1
+ import type * as NuxtAppTypes from "nuxt/app"
2
+ import { defineNuxtPlugin } from "#imports"
3
+ import Chakra , {
4
+ chakra ,
5
+ ChakraPluginOptions ,
6
+ cookieStorageManagerSSR ,
7
+ extendChakra ,
8
+ ColorModeConstants ,
9
+ } from "@chakra-ui/vue-next"
10
+ import { domElements } from "@chakra-ui/vue-system"
11
+
12
+ export default defineNuxtPlugin ( ( nuxtApp ) => {
13
+ console . log ( "chakra-ui-nuxt:plugin_context" )
14
+
15
+ const app = nuxtApp . vueApp
16
+
17
+ app . use (
18
+ Chakra ,
19
+ extendChakra ( {
20
+ cssReset : true ,
21
+ colorModeManager : cookieStorageManagerSSR (
22
+ ColorModeConstants . CookieStorageKey
23
+ ) ,
24
+ } )
25
+ )
26
+
27
+ domElements . forEach ( ( tag ) => {
28
+ app . component ( `chakra.${ tag } ` , chakra ( tag ) )
29
+ } )
30
+ } )
You can’t perform that action at this time.
0 commit comments