Skip to content

Commit

Permalink
Fixed grayscale brand color bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
hridniev committed May 12, 2024
1 parent c049165 commit 8e3103f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
11 changes: 6 additions & 5 deletions src/preset.tailwind/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import colors from "tailwindcss/colors.js";
import forms from "@tailwindcss/forms";
import vuelessConfig from "../../vueless.config.js";

export const grayColors = ["slate", "gray", "zinc", "neutral", "stone"];
export const brandColors = [
export const GRAY_COLORS = ["slate", "gray", "zinc", "neutral", "stone"];
export const GRAYSCALE_BRAND_COLOR = "grayscale";
export const BRAND_COLORS = [
"brand",
"red",
"orange",
Expand Down Expand Up @@ -33,10 +34,10 @@ export function vuelessPreset() {
const brandColor = twColorWithOpacity("--color-brand");
const { brand, gray } = vuelessConfig;

let brandPalette = brandColors.includes(brand) ? colors[brand] : colors.green;
let grayPalette = grayColors.includes(gray) ? colors[gray] : colors.zinc;
let brandPalette = BRAND_COLORS.includes(brand) ? colors[brand] : colors.green;
let grayPalette = GRAY_COLORS.includes(gray) ? colors[gray] : colors.zinc;

if (brand === "grayscale") {
if (brand === GRAYSCALE_BRAND_COLOR) {
brandPalette = grayPalette;
}

Expand Down
16 changes: 10 additions & 6 deletions src/service.ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { merge } from "lodash-es";
import { defineConfig } from "cva";
import { twMerge } from "tailwind-merge";
import colors from "tailwindcss/colors";
import { brandColors, grayColors } from "../preset.tailwind";
import { BRAND_COLORS, GRAY_COLORS, GRAYSCALE_BRAND_COLOR } from "../preset.tailwind";
import vuelessConfig from "../../vueless.config.js";

/*
Expand Down Expand Up @@ -105,7 +105,7 @@ export default class UIServiceDefault {
// TODO: This should be rewrote to support all set of brand colors (not only one).
setBrandColor(brandColor) {
function getBrandColor(color, grayColor, brandColors) {
if (color === "grayscale") {
if (color === GRAYSCALE_BRAND_COLOR) {
return grayColor;
}

Expand All @@ -116,9 +116,9 @@ export default class UIServiceDefault {
return grayColors.includes(color) ? colors[color][900] : colors.zinc[900];
}

const grayColor = getGrayColor(gray, grayColors);
const localBrandColor = getBrandColor(brandColor, grayColor, brandColors);
const globalBrandColor = getBrandColor(brand, grayColor, brandColors);
const grayColor = getGrayColor(gray, GRAY_COLORS);
const localBrandColor = getBrandColor(brandColor, grayColor, BRAND_COLORS);
const globalBrandColor = getBrandColor(brand, grayColor, BRAND_COLORS);

const style = document.createElement("style");
const rgb = UIServiceDefault.convertHexInRgb(localBrandColor || globalBrandColor || grayColor);
Expand Down Expand Up @@ -167,7 +167,11 @@ export default class UIServiceDefault {
*/
static get(defaultConfig, name) {
return {
default: merge(defaultConfig.defaultVariants, globalComponentConfig[name]?.defaultVariants),
default: merge(
defaultConfig.defaultVariants,
brand === GRAYSCALE_BRAND_COLOR && { color: GRAYSCALE_BRAND_COLOR },
globalComponentConfig[name]?.defaultVariants,
),
};
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/ui.navigation-stepper/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import colors from "tailwindcss/colors";
import UHeader from "../ui.text-header";
import UIService from "../service.ui";
import { grayColors } from "../preset.tailwind";
import { GRAY_COLORS } from "../preset.tailwind";
import { UStepper } from "./constants/index";
import defaultConfig from "./configs/default.config";
Expand Down Expand Up @@ -112,7 +112,7 @@ const { wrapperAttrs, titleAttrs, stepperAttrs, ringAttrs, countAttrs, gradientA
const setStepperColor = computed(() => {
return colors[props.color]
? colors[props.color][500]
: grayColors.includes(props.color)
: GRAY_COLORS.includes(props.color)
? colors[props.color][900]
: colors.zinc[900];
});
Expand Down

0 comments on commit 8e3103f

Please sign in to comment.