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

Commit 9673463

Browse files
Merge pull request #264 from chakra-ui/fix/theme-types
fix/theme types
2 parents 4c98874 + 5d8c878 commit 9673463

File tree

14 files changed

+144
-104
lines changed

14 files changed

+144
-104
lines changed

.changeset/stale-kiwis-shave.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
"@chakra-ui/c-visually-hidden": minor
3+
"@chakra-ui/c-theme-provider": minor
4+
"@chakra-ui/vue-composables": minor
5+
"@chakra-ui/c-close-button": minor
6+
"@chakra-ui/c-form-control": minor
7+
"@chakra-ui/c-media-query": minor
8+
"@chakra-ui/c-scroll-lock": minor
9+
"@chakra-ui/c-breadcrumb": minor
10+
"@chakra-ui/c-color-mode": minor
11+
"@chakra-ui/c-focus-lock": minor
12+
"@chakra-ui/c-accordion": minor
13+
"@chakra-ui/c-pin-input": minor
14+
"@chakra-ui/c-checkbox": minor
15+
"@chakra-ui/c-skip-nav": minor
16+
"@chakra-ui/vue-test-utils": minor
17+
"@chakra-ui/vue-auto-import": minor
18+
"@chakra-ui/c-spinner": minor
19+
"@chakra-ui/c-avatar": minor
20+
"@chakra-ui/c-button": minor
21+
"@chakra-ui/c-motion": minor
22+
"@chakra-ui/c-popper": minor
23+
"@chakra-ui/c-portal": minor
24+
"@chakra-ui/vue-accessibilty": minor
25+
"@chakra-ui/c-alert": minor
26+
"@chakra-ui/c-image": minor
27+
"@chakra-ui/c-input": minor
28+
"@chakra-ui/c-modal": minor
29+
"@chakra-ui/c-reset": minor
30+
"@chakra-ui/c-toast": minor
31+
"@chakra-ui/c-code": minor
32+
"@chakra-ui/c-icon": minor
33+
"@chakra-ui/c-menu": minor
34+
"@chakra-ui/vue-layout": minor
35+
"@chakra-ui/vue-styled": minor
36+
"@chakra-ui/vue-system": minor
37+
"@chakra-ui/c-tag": minor
38+
"@chakra-ui/vue-utils": minor
39+
"@chakra-ui/nuxt-next": minor
40+
"@chakra-ui/vue-next": minor
41+
---
42+
43+
Provide auto-import for components in Nuxt and expose theme type for `useTheme`
44+
hook"

@types/components.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* This is a generated file. Do not edit it's contents.
88
*
9-
* This file was generated on 2023-02-17T13:41:24.872Z
9+
* This file was generated on 2023-02-17T16:34:58.713Z
1010
*/
1111

1212
import { ChakraProps, chakra } from "@chakra-ui/vue-system"

components.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* This is a generated file. Do not edit it's contents.
88
*
9-
* This file was generated on 2023-02-17T13:41:24.872Z
9+
* This file was generated on 2023-02-17T16:34:58.713Z
1010
*/
1111

1212
import { ChakraProps, chakra } from "@chakra-ui/vue-system"

modules/nuxt/build.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export default defineBuildConfig({
2525
"nuxt3",
2626
"vue",
2727
"vue-demi",
28-
"@chakra-ui/utils",
2928
"css-box-model",
3029
"framesync",
3130
"lodash.mergewith",

modules/nuxt/playground/app.vue

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<c-container>
33
<c-heading>Chakra UI Vue Next</c-heading>
44
<c-grid template-columns="1fr 1fr" gap="5">
5-
<!-- <c-grid-item>
5+
<c-grid-item>
66
<c-stack>
77
<c-h-stack>
88
<chakra.p>Toggle Color Mode</chakra.p>
@@ -27,7 +27,7 @@
2727
>
2828
</c-stack>
2929
</c-stack>
30-
</c-grid-item> -->
30+
</c-grid-item>
3131
<c-grid-item>
3232
<c-heading>Toast</c-heading>
3333
<c-button @click="handleClick">Hello Chakra UI</c-button>
@@ -37,19 +37,7 @@
3737
</template>
3838

3939
<script setup lang="ts">
40-
import {
41-
chakra,
42-
CButton,
43-
CContainer,
44-
CGrid,
45-
CStack,
46-
CHStack,
47-
CGridItem,
48-
CHeading,
49-
useToast,
50-
useColorMode,
51-
CIconButton,
52-
} from "@chakra-ui/vue-next"
40+
import { chakra, useToast, useColorMode } from "@chakra-ui/vue-next"
5341
const toast = useToast()
5442
5543
const { colorMode, toggleColorMode } = useColorMode()

modules/nuxt/src/module.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
addPlugin,
44
createResolver,
55
addServerPlugin,
6-
installModule,
6+
addComponent,
77
} from "@nuxt/kit"
88
import type * as NuxtSchema from "@nuxt/schema"
99
import type * as Theme from "@chakra-ui/theme"
@@ -74,7 +74,32 @@ export default defineNuxtModule<ChakraModuleOptions>({
7474
}
7575
})
7676

77-
nuxt.options.build.transpile.push("@chakra-ui")
77+
// Transpile
78+
nuxt.options.build.transpile.push("@chakra-ui/vue-next")
79+
80+
// Auto-import components
81+
for (const component in Chakra) {
82+
/**
83+
* Group of strict checks to make sure that
84+
* we only generate types for components.
85+
*/
86+
if (
87+
component.startsWith("C") &&
88+
// @ts-ignore
89+
Chakra[component]?.name &&
90+
// @ts-ignore
91+
Chakra[component]?.setup &&
92+
// @ts-ignore
93+
typeof Chakra[component]?.setup === "function"
94+
) {
95+
addComponent({
96+
name: component,
97+
// @ts-ignore
98+
export: Chakra[component]?.name,
99+
filePath: "@chakra-ui/vue-next",
100+
})
101+
}
102+
}
78103

79104
nuxt.options.appConfig.$chakraConfig = {
80105
extendTheme,

packages/system/src/composables/use-chakra.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { inject } from "vue"
22
import { useColorMode } from "@chakra-ui/c-color-mode"
3-
import { Dict } from "@chakra-ui/utils"
3+
import { ChakraTheme } from "@chakra-ui/theme"
44

55
/** Provides theme object in component context */
6-
export const useTheme = <T extends object = Dict>(): T => {
6+
export const useTheme = <T extends ChakraTheme = ChakraTheme>(): T => {
77
const theme = inject("$chakraTheme") as T
88
return theme
99
}

packages/system/src/system.utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { UnionStringArray, omit } from "@chakra-ui/utils"
1+
import { UnionStringArray } from "@chakra-ui/utils"
22
import { keyframes, injectGlobal } from "@emotion/css"
33
import { PropType } from "vue"
44

packages/vue-composables/src/use-counter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { clampValue, countDecimalPlaces, toPrecision } from "@chakra-ui/utils"
2-
import { computed, ref, watchEffect } from "vue"
2+
import { ref, watchEffect } from "vue"
33

44
export interface UseCounterProps {
55
/**

packages/vue/src/helpers/css-reset.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ export function injectThemeGlobalStyles(
3030
)
3131
if (!globalStyles.value) return undefined
3232

33-
const cache = createCache({
34-
key: "chakra-global",
35-
nonce: "__chakra__",
36-
})
33+
const cache =
34+
_cache ||
35+
createCache({
36+
key: "chakra-global",
37+
nonce: "__chakra__",
38+
})
3739

3840
const _globalStyles = computed(() => css(globalStyles.value)(theme))
3941

@@ -52,6 +54,7 @@ export function injectThemeGlobalStyles(
5254
key: `${key} ${serializedStyles.value.name}`,
5355
nonce: cache.sheet.nonce,
5456
container: cache.sheet.container,
57+
// @ts-ignore
5558
speedy: cache.sheet.isSpeedy,
5659
})
5760

@@ -104,6 +107,7 @@ export function injectThemeGlobalStyles(
104107
sheet.flush()
105108
}
106109

110+
// @ts-ignore
107111
cache.insert(``, serializedStyles.value, sheet, false)
108112
})
109113
}

0 commit comments

Comments
 (0)