forked from jd-solanki/anu
-
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.
perf(rating): use
useColor
instead of useLayer
- Loading branch information
1 parent
1ff29a5
commit 105d642
Showing
5 changed files
with
38 additions
and
16 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { MaybeRef } from '@vueuse/core' | ||
import type { StyleValue } from 'vue' | ||
import type { ColorProp } from '@/composables/useProps' | ||
|
||
export const useColor = (color: MaybeRef<ColorProp>, cssVarName: MaybeRef<string>, as: 'text' | 'bg' = 'text') => { | ||
const styles = computed(() => { | ||
const _color = unref(color) | ||
const cssVar = computed(() => `--a-${unref(cssVarName)}`) | ||
|
||
const property = as === 'bg' ? 'background-color' : 'color' | ||
const isThemeColor = ['primary', 'success', 'info', 'warning', 'danger'].includes(_color as string) | ||
|
||
const _styles = { | ||
[cssVar.value]: isThemeColor ? `hsl(var(--a-${_color}))` : _color, | ||
[property]: `var(${cssVar.value})`, | ||
} as StyleValue | ||
|
||
return _styles | ||
}) | ||
|
||
return { | ||
styles, | ||
} | ||
} |
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