Skip to content

Commit aba1d82

Browse files
committed
perf: 优化颜色生成规则
1 parent e99b035 commit aba1d82

File tree

5 files changed

+18
-31
lines changed

5 files changed

+18
-31
lines changed

packages/dl-common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@xuanmo/dl-common",
3-
"version": "0.0.5-beta.46",
3+
"version": "0.0.5-beta.47",
44
"author": {
55
"name": "xuanmo",
66
"email": "me@xuanmo.xin"

packages/dl-common/src/config-provider/config-provider.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ export default defineComponent({
3131
const style = {
3232
height: props.fullHeight ? '100%' : undefined
3333
}
34-
3534
if (props.isRoot) {
3635
const htmlEl = document.querySelector('html')
36+
const styles: string[] = []
3737
if (htmlEl) {
3838
for (const [key, value] of Object.entries(theme.value)) {
39-
htmlEl.style.setProperty(key, value)
39+
styles.push(`${key}: ${value};`)
4040
}
41+
htmlEl.style.cssText += styles.join('')
4142
}
4243
} else {
4344
Object.assign(style, theme.value)

packages/dl-common/src/config-provider/props.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const CONFIG_PROVIDER_PROPS = {
7272
*/
7373
isRoot: {
7474
type: Boolean,
75-
default: true
75+
default: false
7676
},
7777

7878
/**

packages/dl-common/src/config-provider/use-style.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,3 @@ export const useTheme = (props: ConfigProviderProps) => {
3535
return style
3636
})
3737
}
38-
39-
export function useStyle(props: ConfigProviderProps) {
40-
return computed<CSSProperties>(() => {
41-
const style: CSSProperties = {
42-
height: props.fullHeight ? '100%' : undefined
43-
}
44-
if (props.theme?.primary) {
45-
Object.assign(style, generateStyle(color.generateColors(props.theme.primary), 'primary'))
46-
}
47-
if (props.theme?.success) {
48-
Object.assign(style, generateStyle(color.generateColors(props.theme.success), 'success'))
49-
}
50-
if (props.theme?.warning) {
51-
Object.assign(style, generateStyle(color.generateColors(props.theme.warning), 'warning'))
52-
}
53-
if (props.theme?.error) {
54-
Object.assign(style, generateStyle(color.generateColors(props.theme.error), 'error'))
55-
}
56-
return style
57-
})
58-
}

packages/dl-common/src/index.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,24 @@ import './style/index.scss'
1010
// 引入图标样式
1111
import '../../dl-icons/src/style.scss'
1212

13-
const install = function (app: App) {
13+
const install = function (
14+
app: App,
15+
options?: {
16+
primaryColor?: string
17+
successColor?: string
18+
warningColor?: string
19+
errorColor?: string
20+
}
21+
) {
22+
color.generatePrimaryColors(options?.primaryColor)
23+
color.generateSuccessColors(options?.successColor)
24+
color.generateWarningColors(options?.warningColor)
25+
color.generateErrorColors(options?.errorColor)
1426
Object.values(components).forEach((component: any) => {
1527
if (/^d-/.test(component?.name)) app.use(component)
1628
})
1729
}
1830

19-
color.generatePrimaryColors()
20-
color.generateSuccessColors()
21-
color.generateWarningColors()
22-
color.generateErrorColors()
23-
2431
export type ComponentNames = keyof typeof components extends infer T
2532
? T extends `D${infer Name}`
2633
? `D${Name}`

0 commit comments

Comments
 (0)