-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(theme): remove theme scale style in theme-provider, remove s…
…pace style in common scss and theme-provider scss, use dynamicStyles to generate them in runtime, so that inherited scale value can work correctly
- Loading branch information
Showing
7 changed files
with
42 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './scss/common'; | ||
export * from './scss/components'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { createImportStyle, getThemeValueFromInstance, TGlobalContextConfig } from '@lun/components'; | ||
import { GlobalContextConfig, GlobalStaticConfig } from '@lun/components'; | ||
import { once, toPxIfNum } from '@lun/utils'; | ||
import commonStyles from './index.scss?inline'; | ||
|
||
export const importCommonDynamicTheme = once(() => { | ||
GlobalContextConfig.dynamicStyles.common.push((vm, name, context) => { | ||
const { theme, namespace } = context as TGlobalContextConfig; | ||
const themeScale = theme.scale as any; | ||
const n = namespace || GlobalStaticConfig.namespace; | ||
const { commonSeparator } = GlobalStaticConfig; | ||
const scale = getThemeValueFromInstance(vm, 'scale') || themeScale?.[name] || themeScale?.common || themeScale; | ||
|
||
function getVarName(...list: (string | number)[]) { | ||
return '--' + n + commonSeparator + list.join(commonSeparator); | ||
} | ||
const scaleVar = `var(${getVarName('scale')})`; | ||
|
||
const scaleStyle = scale > 0 ? `:host{${getVarName('scale')}:${scale}}` : ''; | ||
const spaces = [4, 8, 12, 16, 24, 32, 40, 48, 64], | ||
spaceStyle = `:host([scale]),:host([root]){${spaces | ||
.map( | ||
(s, i) => | ||
`${getVarName('space', i + 1)}:calc(${toPxIfNum(s)} * ${scaleVar});` + | ||
`${getVarName('space', 'hypot', i + 1)}:calc(${toPxIfNum(Math.hypot(s, s))} * ${scaleVar});`, | ||
) | ||
.join('')}}`; | ||
// TODO font-size line-height... radius | ||
return scaleStyle + spaceStyle; | ||
}); | ||
}); | ||
|
||
export const importCommonStaticTheme = once(createImportStyle('common', commonStyles)); | ||
|
||
export const importCommonTheme = () => { | ||
importCommonStaticTheme(); | ||
importCommonDynamicTheme(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
@use "./colors.scss"; | ||
@use "./radius.scss"; | ||
@use "./shadow.scss"; | ||
@use "./space.scss"; | ||
@use "./theme-colors.scss"; | ||
@use "./typography.scss"; |