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

Commit 5e675e1

Browse files
committed
feat(wip-styled): completed tests for styled function api
1 parent f30fac0 commit 5e675e1

File tree

25 files changed

+480
-111
lines changed

25 files changed

+480
-111
lines changed

components.d.ts

Lines changed: 2 additions & 2 deletions
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 2022-02-15T20:12:51.041Z
9+
* This file was generated on 2022-03-03T13:59:03.450Z
1010
*/
1111

1212
import { ChakraProps, chakra } from "@chakra-ui/vue-system"
@@ -191,8 +191,8 @@ declare module "@vue/runtime-core" {
191191
/* Component custom props types for JSX and TSX auto complete */
192192
export interface ComponentCustomProps
193193
extends JsxComponentCustomProps,
194+
ComponentCustomProps,
194195
ChakraProps {
195-
onClick?: () => any
196196
vSlots?: {
197197
[eleName: string]: JSX.Element
198198
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@
154154
"tinycolor2": "^1.4.2",
155155
"ts-jest": "^26.5.0",
156156
"ts-node": "^9.0.0",
157-
"typescript": "^4.5.4",
157+
"typescript": "^4.6.2",
158158
"unplugin-vue-components": "^0.14.0",
159-
"vite": "^2.7.4",
159+
"vite": "^2.8.6",
160160
"vite-plugin-mdx-vue": "^1.6.0",
161161
"vite-plugin-pages": "^0.20.1",
162162
"vite-plugin-vue-layouts": "^0.5.0",

packages/core/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@
4646
"@chakra-ui/vue-a11y": "0.1.0-alpha.9",
4747
"@chakra-ui/vue-composables": "0.1.0-alpha.9",
4848
"@chakra-ui/vue-layout": "0.1.0-alpha.11",
49+
"@chakra-ui/vue-styled": "0.0.0-alpha.0",
4950
"@chakra-ui/vue-system": "0.1.0-alpha.10",
5051
"@chakra-ui/vue-theme": "1.0.0-alpha.10",
51-
"@chakra-ui/vue-theme-tools": "0.1.0-alpha.10"
52+
"@chakra-ui/vue-theme-tools": "0.1.0-alpha.10",
53+
"@emotion/cache": "^11.7.1"
5254
},
5355
"devDependencies": {
5456
"vue": "^3.2.29"
@@ -59,4 +61,4 @@
5961
"publishConfig": {
6062
"access": "public"
6163
}
62-
}
64+
}

packages/core/src/helpers/plugin.types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ColorModeRef } from "@chakra-ui/c-color-mode"
22
import { UnwrapRef } from "vue"
33
import { ThemeOverride } from "../extend-theme"
4+
import { Options } from "@emotion/cache"
45

56
interface ExtendIconsPath {
67
path: string
@@ -17,4 +18,5 @@ export interface ChakraPluginOptions {
1718
extendTheme?: ThemeOverride
1819
icons?: IconsOptions
1920
defaultColorMode?: UnwrapRef<ColorModeRef>
21+
emotionCacheOptions?: Options
2022
}

packages/core/src/index.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,30 @@ import defaultTheme from "@chakra-ui/vue-theme"
33
import type { ColorModeRef } from "@chakra-ui/c-color-mode"
44
import { toCSSVar, WithCSSVar } from "@chakra-ui/styled-system"
55
import { chakra, injectGlobal } from "@chakra-ui/vue-system"
6+
import {
7+
EmotionThemeContextSymbol,
8+
EmotionCacheInjectionSymbol,
9+
} from "@chakra-ui/vue-styled"
10+
import createCache from "@emotion/cache"
611
import internalIcons from "./icon.internals"
712
import { extendTheme, ThemeOverride } from "./extend-theme"
813
import { MergedIcons, parseIcons } from "./parse-icons"
914
import { injectResetStyles, injectThemeGlobalStyles } from "./helpers/css-reset"
1015
import { mode } from "@chakra-ui/vue-theme-tools"
1116
import { ChakraPluginOptions } from "./helpers/plugin.types"
1217

18+
/**
19+
* 1. Support passing cache options from plugin
20+
* 2. Provide emotion theme directly from plugin
21+
* 3.
22+
*/
23+
1324
/**
1425
* Helper function to extend Chakra plugin with options
1526
* It just returns its arguments with typescript types added
1627
*/
17-
export function chakraOptions(
28+
29+
export function extendChakra(
1830
options: ChakraPluginOptions = { cssReset: true }
1931
) {
2032
return options
@@ -56,8 +68,16 @@ const ChakraUIVuePlugin: Plugin = {
5668

5769
// Bind theme to application global properties and provide to application
5870
app.config.globalProperties.$chakraTheme = computedTheme.value
71+
app.config.globalProperties.$chakraTheme = computedTheme.value
72+
app.provide(EmotionThemeContextSymbol, computedTheme.value)
5973
app.provide("$chakraTheme", computedTheme.value as ThemeOverride)
6074

75+
// Provide emotion cache
76+
if (options.emotionCacheOptions) {
77+
const emotionCache = createCache(options.emotionCacheOptions)
78+
app.provide(EmotionCacheInjectionSymbol, emotionCache)
79+
}
80+
6181
libraryIcons = parseIcons(libraryIcons)
6282

6383
// Merge internal icons and library icons

packages/layout/src/kbd.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { vueThemingProps } from "@chakra-ui/vue-utils"
1+
import { vueThemingProps, extractStyleAttrs } from "@chakra-ui/vue-utils"
22
import {
33
chakra,
44
DOMElements,
55
ThemingProps,
66
useStyleConfig,
77
HTMLChakraProps,
8-
extractStyleAttrs,
98
ComponentWithProps,
109
DeepPartial,
1110
} from "@chakra-ui/vue-system"

packages/styled/examples/styled.vue

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<template>
2+
<div>
3+
<div>Hello world</div>
4+
<Button>Button</Button>
5+
<chakra.button
6+
aria-label="Dope button"
7+
:bg="['pink.500', 'yellow.500', 'orange.500', 'green.500']"
8+
color="white"
9+
px="4"
10+
py="2"
11+
@click="handleClick"
12+
:layer-style="{
13+
bg: 'black',
14+
color: 'white',
15+
}"
16+
>
17+
Hot pink
18+
</chakra.button>
19+
</div>
20+
</template>
21+
22+
<script lang="tsx" setup>
23+
import { defineComponent, h } from "vue"
24+
import styled from "../src"
25+
import { _chakra as chakra } from "@chakra-ui/vue-system"
26+
27+
const Button = chakra("button", {
28+
baseStyle: {
29+
bg: "blue.700",
30+
color: "white",
31+
fontWeight: "bold",
32+
px: 4,
33+
py: 3,
34+
},
35+
})
36+
37+
function handleClick(e: MouseEvent) {
38+
console.log("Clicked", e)
39+
}
40+
41+
const CButton = defineComponent({
42+
setup() {
43+
return () => (
44+
<Button height="32px" onClick={handleClick}>
45+
Main Button
46+
</Button>
47+
)
48+
},
49+
})
50+
</script>

packages/styled/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727
"@emotion/utils": "^1.0.0",
2828
"@emotion/weak-memoize": "^0.2.5",
2929
"clsx": "^1.1.1",
30-
"lodash.camelcase": "^4.3.0"
30+
"lodash.camelcase": "^4.3.0",
31+
"lodash.memoize": "^4.1.2"
32+
},
33+
"devDependencies": {
34+
"@types/lodash.memoize": "^4.1.6"
3135
},
3236
"peerDependencies": {
3337
"vue": "^3.2.31"

packages/styled/src/cache.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
SetupContext
1212
} from "vue"
1313

14-
const [EmotionCacheProvider, useEmotionCache] = createContext<EmotionCache>({
14+
const [EmotionCacheProvider, useEmotionCache, EmotionCacheInjectionSymbol] = createContext<EmotionCache>({
1515
strict: false,
1616
name: "EmotionCacheContext",
1717
})
@@ -50,4 +50,4 @@ if (canUseDOM()) {
5050
}
5151
}
5252

53-
export { withEmotionCache, EmotionCacheProvider }
53+
export { withEmotionCache, EmotionCacheProvider, EmotionCacheInjectionSymbol }

packages/styled/src/index.ts renamed to packages/styled/src/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { createStyled } from "./styled"
22
import { tags } from "./tags"
33

44
export * from "./cache"
5+
export * from "./theming"
56

67
// bind it to avoid mutating the original function
78
const styled = createStyled.bind()
@@ -11,4 +12,4 @@ tags.forEach((tagName) => {
1112
styled[tagName] = styled(tagName)
1213
})
1314

14-
export default styled
15+
export default styled

0 commit comments

Comments
 (0)