Skip to content

Commit

Permalink
fix: css variable cant use when useOpacityVariable is true
Browse files Browse the repository at this point in the history
  • Loading branch information
chizukicn committed Nov 27, 2023
1 parent 10bcebe commit 29d4b82
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ export interface PaletteOptions {
defaultValue?: string
}

/**
* use opacity variable
*
* ```css
* .text-primary {
* --un-text-opacity: 1;
* color: rgb(var(--un-palette-primary-rgb) / var(--un-text-opacity));
* }
* ```
* @default true
*/
useOpacityVariable?: boolean

/**
* @default --un-palette-[name]-color
*/
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ export const presetPalette = definePreset((options: PaletteOptions = {}) => {
for (const colorName in colorComponents[theme]) {
const components = colorComponents[theme][colorName];
const varName = getVarName(colorName);
rs.push(`${varName}-${colorFormat}:${components}`, ";");
if (useOpacityVariable) {
rs.push(`${varName}:${colorFormat}(var(${varName}-${colorFormat}))`, ";");
rs.push(`${varName}-${colorFormat}:${components}`, ";", `${varName}:${colorFormat}(var(${varName}-${colorFormat}))`, ";");
} else {
rs.push(`${varName}:${colorFormat}(${components})`, ";");
}
}
rs.push("}");
Expand Down

0 comments on commit 29d4b82

Please sign in to comment.