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

Commit 9e2385f

Browse files
committed
chore: build global styles
1 parent eca3d9a commit 9e2385f

File tree

6 files changed

+243
-253
lines changed

6 files changed

+243
-253
lines changed

.idea/workspace.xml

Lines changed: 6 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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 2022-03-05T09:54:15.061Z
9+
* This file was generated on 2022-07-10T15:02:42.611Z
1010
*/
1111

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

packages/c-button/src/button.utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface ButtonProps extends BaseThemedComponentProps {
1212
type?: ButtonTypes
1313
leftIcon?: string
1414
rightIcon?: string
15+
spinnerPlacement?: "start" | "end"
1516
iconSpacing?: SystemProps["marginRight"]
1617
}
1718

packages/styled/src/styled.tsx

Lines changed: 63 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,39 @@
1-
import clsx from 'clsx'
2-
import { mergeProps, SetupContext, h, Fragment } from 'vue'
3-
import { CSSInterpolation, serializeStyles } from '@emotion/serialize'
4-
import { extractStyleAttrs } from '@chakra-ui/vue-utils'
5-
import { getRegisteredStyles, insertStyles, SerializedStyles } from '@emotion/utils'
6-
import camelCase from 'lodash.camelcase'
7-
import { CreateStyled, PrivateStyledComponent, StyledOptions } from './types'
8-
import { defaultCache, __unusafe_useEmotionCache } from './cache'
9-
import { useEmotionTheme } from './theming'
10-
import memoize from 'lodash.memoize'
1+
import clsx from "clsx"
2+
import { mergeProps, SetupContext, h, Fragment } from "vue"
3+
import { CSSInterpolation, serializeStyles } from "@emotion/serialize"
4+
import { extractStyleAttrs } from "@chakra-ui/vue-utils"
5+
import {
6+
getRegisteredStyles,
7+
insertStyles,
8+
SerializedStyles,
9+
} from "@emotion/utils"
10+
import camelCase from "lodash.camelcase"
11+
import { CreateStyled, PrivateStyledComponent, StyledOptions } from "./types"
12+
import { defaultCache, __unusafe_useEmotionCache } from "./cache"
13+
import { useEmotionTheme } from "./theming"
14+
import memoize from "lodash.memoize"
1115

1216
const ILLEGAL_ESCAPE_SEQUENCE_ERROR = `You have illegal escape sequence in your template literal, most likely inside content's property value.
1317
Because you write your CSS inside a JavaScript string you actually have to do double escaping, so for example "content: '\\00d7';" should become "content: '\\\\00d7';".
1418
You can read more about this here:
1519
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#ES2018_revision_of_illegal_escape_sequences`
1620

17-
let isBrowser = typeof document !== 'undefined'
21+
let isBrowser = typeof document !== "undefined"
1822

1923
const Noop = () => null
2024
const camelCaseCache: any = {}
2125

2226
const _camelCase = memoize((key) => camelCase(key))
2327

2428
// @ts-ignore
25-
export const createStyled: CreateStyled = (tag: any, options?: StyledOptions) => {
26-
if (process.env.NODE_ENV !== 'production') {
29+
export const createStyled: CreateStyled = (
30+
tag: any,
31+
options?: StyledOptions
32+
) => {
33+
if (process.env.NODE_ENV !== "production") {
2734
if (tag === undefined) {
2835
throw new Error(
29-
'You are trying to create a styled element with an undefined component.\nYou may have forgotten to import it.'
36+
"You are trying to create a styled element with an undefined component.\nYou may have forgotten to import it."
3037
)
3138
}
3239
}
@@ -42,7 +49,7 @@ export const createStyled: CreateStyled = (tag: any, options?: StyledOptions) =>
4249
}
4350

4451
// Extract arguments from template literals
45-
return function<Props>(): PrivateStyledComponent<Props> {
52+
return function <Props>(): PrivateStyledComponent<Props> {
4653
let args = arguments
4754
let styles =
4855
isReal && tag.__emotion_styles !== undefined
@@ -55,27 +62,34 @@ export const createStyled: CreateStyled = (tag: any, options?: StyledOptions) =>
5562
if (args[0] == null || args[0].raw === undefined) {
5663
styles.push.apply(styles, args)
5764
} else {
58-
if (process.env.NODE_ENV !== 'production' && args[0][0] === undefined) {
65+
if (process.env.NODE_ENV !== "production" && args[0][0] === undefined) {
5966
console.error(ILLEGAL_ESCAPE_SEQUENCE_ERROR)
6067
}
6168
styles.push(args[0][0])
6269
let len = args.length
6370
let i = 1
6471
for (; i < len; i++) {
65-
if (process.env.NODE_ENV !== 'production' && args[0][i] === undefined) {
72+
if (process.env.NODE_ENV !== "production" && args[0][i] === undefined) {
6673
console.error(ILLEGAL_ESCAPE_SEQUENCE_ERROR)
6774
}
6875
styles.push(args[i], args[0][i])
6976
}
7077
}
7178

72-
function StyledComponent (props: any, { attrs, expose, slots }: SetupContext) {
79+
function StyledComponent(
80+
props: any,
81+
{ attrs, expose, slots }: SetupContext
82+
) {
7383
const cache = __unusafe_useEmotionCache(defaultCache)
7484
const { as, ...restAttrs } = attrs || {}
7585

7686
let mergedProps = { ...props, ...restAttrs }
7787

78-
let className = options?.__label ? `${cache.key}-${options?.__label || typeof tag === 'string' ? tag : 'element'} ` : ``
88+
let className = options?.__label
89+
? `${cache.key}-${
90+
options?.__label || typeof tag === "string" ? tag : "element"
91+
} `
92+
: ``
7993
const FinalTag = as || baseTag
8094
const classInterpolations = [] as string[]
8195

@@ -98,7 +112,7 @@ export const createStyled: CreateStyled = (tag: any, options?: StyledOptions) =>
98112
...attrs,
99113
...mergedProps,
100114
})
101-
115+
102116
if (attrs.class) {
103117
className += getRegisteredStyles(
104118
cache.registered,
@@ -116,14 +130,13 @@ export const createStyled: CreateStyled = (tag: any, options?: StyledOptions) =>
116130
const rules = insertStyles(
117131
cache,
118132
serialized,
119-
typeof FinalTag === 'string'
133+
typeof FinalTag === "string"
120134
)
121135

122136
className += `${cache.key}-${serialized.name}`
123-
if (targetClassName !== undefined) {
124-
className += ` ${targetClassName}`
125-
}
126-
137+
if (targetClassName !== undefined) {
138+
className += ` ${targetClassName}`
139+
}
127140

128141
const { attrs: htmlAttrs } = extractStyleAttrs(mergedProps)
129142
const vnodeProps = {
@@ -133,25 +146,21 @@ export const createStyled: CreateStyled = (tag: any, options?: StyledOptions) =>
133146
// @ts-expect-error
134147
delete vnodeProps?.theme
135148

136-
const StyledElement = (
137-
<FinalTag {...vnodeProps}>
138-
{slots}
139-
</FinalTag>
140-
)
141-
149+
const StyledElement = <FinalTag {...vnodeProps}>{slots}</FinalTag>
150+
142151
let possiblyStyleElement = <Noop />
143152
if (!isBrowser && rules !== undefined) {
144153
let serializedNames = serialized.name
145154
let next = serialized.next
146155
while (next !== undefined) {
147-
serializedNames += ' ' + next.name
156+
serializedNames += " " + next.name
148157
next = next.next
149158
}
150159
possiblyStyleElement = (
151160
<style
152161
{...{
153162
[`data-emotion`]: `${cache.key} ${serializedNames}`,
154-
nonce: cache.sheet.nonce
163+
nonce: cache.sheet.nonce,
155164
}}
156165
>
157166
{rules}
@@ -167,36 +176,39 @@ export const createStyled: CreateStyled = (tag: any, options?: StyledOptions) =>
167176
}
168177

169178
StyledComponent._name =
170-
identifierName === undefined ?
171-
`Styled${
172-
typeof baseTag === 'string' ? baseTag : baseTag.name || 'Component'
173-
}` :
174-
identifierName
179+
identifierName === undefined
180+
? `Styled${
181+
typeof baseTag === "string" ? baseTag : baseTag.name || "Component"
182+
}`
183+
: identifierName
175184

176185
StyledComponent.__emotion_real = StyledComponent
177186
StyledComponent.__emotion_base = baseTag
178187
StyledComponent.__emotion_styles = styles
179188

180-
Object.defineProperty(StyledComponent, 'toString', {
189+
Object.defineProperty(StyledComponent, "toString", {
181190
value() {
182191
if (
183192
targetClassName === undefined &&
184-
process.env.NODE_ENV !== 'production'
193+
process.env.NODE_ENV !== "production"
185194
) {
186-
return 'NO_COMPONENT_SELECTOR'
195+
return "NO_COMPONENT_SELECTOR"
187196
}
188197

189198
return `.${targetClassName}`
190-
}
199+
},
191200
})
192201

193-
StyledComponent.withComponent = (nextTag: any, nextOptions: StyledOptions) => {
202+
StyledComponent.withComponent = (
203+
nextTag: any,
204+
nextOptions: StyledOptions
205+
) => {
194206
return createStyled(
195207
nextTag,
196-
nextOptions === undefined ?
197-
options :
198-
{ ...(options || {}), ...nextOptions }
199-
// Here we use apply to make TypeScript happy. Otherwise we would use spread operator
208+
nextOptions === undefined
209+
? options
210+
: { ...(options || {}), ...nextOptions }
211+
// Here we use apply to make TypeScript happy. Otherwise we would use spread operator
200212
).apply(null, styles)
201213
}
202214

@@ -205,6 +217,8 @@ export const createStyled: CreateStyled = (tag: any, options?: StyledOptions) =>
205217
}
206218
}
207219

208-
export function css(...args: Array<CSSInterpolation | TemplateStringsArray>): SerializedStyles {
220+
export function css(
221+
...args: Array<CSSInterpolation | TemplateStringsArray>
222+
): SerializedStyles {
209223
return serializeStyles(args, {})
210-
}
224+
}

packages/styled/src/theming.tsx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
1-
import weakMemoize from '@emotion/weak-memoize'
2-
import { createContext } from '@chakra-ui/vue-utils';
1+
import weakMemoize from "@emotion/weak-memoize"
2+
import { createContext } from "@chakra-ui/vue-utils"
33
import { getTheme } from "./utils"
4-
import { ComputedRef } from 'vue';
4+
import { ComputedRef } from "vue"
55

6-
const [_EmotionThemeProvider, useEmotionTheme, EmotionThemeContextSymbol] = createContext<object>({
7-
strict: false,
8-
name: "EmotionThemeContext",
9-
})
6+
const [_EmotionThemeProvider, useEmotionTheme, EmotionThemeContextSymbol] =
7+
createContext<object>({
8+
strict: false,
9+
name: "EmotionThemeContext",
10+
})
1011

11-
let createCacheWithTheme = /* #__PURE__ */ weakMemoize(outerTheme => {
12-
return weakMemoize(theme => {
12+
let createCacheWithTheme = /* #__PURE__ */ weakMemoize((outerTheme) => {
13+
return weakMemoize((theme) => {
1314
return getTheme(outerTheme, theme)
1415
})
1516
})
1617

17-
function EmotionThemeProvider (theme: object | ((Obj: object) => Object)) {
18+
function EmotionThemeProvider(theme: object | ((Obj: object) => Object)) {
1819
let _theme = useEmotionTheme()
1920
if (theme !== _theme) {
20-
// @ts-ignore
21+
// @ts-ignore weak map typing not fulfilled properly
2122
_theme = createCacheWithTheme(_theme)(theme)
2223
}
2324
_EmotionThemeProvider(_theme)
2425
}
2526

26-
export { createCacheWithTheme as createThemeCache, EmotionThemeProvider, useEmotionTheme, EmotionThemeContextSymbol }
27+
export {
28+
createCacheWithTheme as createThemeCache,
29+
EmotionThemeProvider,
30+
useEmotionTheme,
31+
EmotionThemeContextSymbol,
32+
}

0 commit comments

Comments
 (0)