Skip to content

Commit

Permalink
feat: support color-scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
chizukicn committed Jan 17, 2024
1 parent 2094b88 commit fcffba5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getColorComponents, normalizeVarName } from "./utils";
* @returns
*/
export const presetPalette = definePreset((options: PaletteOptions = {}) => {
const { colors: _colors = {}, themeColors = {}, colorMode = {}, colorFormat = "rgb", useOpacityVariable = true } = options;
const { colors: _colors = {}, themeColors = {}, colorMode = {}, colorFormat = "rgb", useOpacityVariable = true, colorScheme = {} } = options;

Object.assign(themeColors, { ..._colors });

Expand Down Expand Up @@ -59,6 +59,10 @@ export const presetPalette = definePreset((options: PaletteOptions = {}) => {
rs.push(`[${attribute}="${theme}"]`);
}
rs.push("{");
if (colorScheme[theme]) {
rs.push(`color-scheme:${colorScheme[theme]};`);
}

for (const colorName in colorComponents[theme]) {
const components = colorComponents[theme][colorName];
const varName = getVarName(colorName);
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type CssVarName = string | {
suffix?: string
};

export type ColorScheme = "light" | "dark";
export interface PaletteOptions {

/**
Expand Down Expand Up @@ -58,5 +59,7 @@ export interface PaletteOptions {
cssVarName?: CssVarName

colorFormat?: "rgb" | "hsl"

colorScheme?: Record<string, ColorScheme>
}

0 comments on commit fcffba5

Please sign in to comment.