Skip to content

Commit

Permalink
feat(tw): allow custom colors in createPreset
Browse files Browse the repository at this point in the history
  • Loading branch information
itsjavi committed Sep 2, 2024
1 parent cca0ed6 commit c43edd0
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions src/lib/create-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,28 @@ import type { PluginCreator } from "tailwindcss/types/config";
type PluginAPI = Parameters<PluginCreator>[0];
export type TailwindColor = keyof typeof twColors;

type CustomColorLevel =
| 50
| 100
| 200
| 300
| 400
| 500
| 600
| 700
| 800
| 900
| 950;
type CustomColor = Record<CustomColorLevel, string>;

type PresetConfig = {
primaryColor?: TailwindColor;
secondaryColor?: TailwindColor;
grayColor?: TailwindColor;
backgroundColor?: string;
foregrondColor?: string;
borderColor?: string;
customColors?: Record<string, CustomColor | string>;
};

export const createTailwindPreset = ({
Expand All @@ -23,7 +38,12 @@ export const createTailwindPreset = ({
backgroundColor = "var(--background)",
foregrondColor = "var(--foreground)",
borderColor = "var(--border)",
customColors = {},
}: PresetConfig = {}): Partial<Config> => {
const _colors = {
...twColors,
...customColors,
};
const preset: Partial<Config> = {
darkMode: ["class"],
safelist: ["dark"],
Expand All @@ -33,12 +53,13 @@ export const createTailwindPreset = ({
background: backgroundColor,
foreground: foregrondColor,
border: borderColor,
primary: twColors[primaryColor],
secondary: twColors[secondaryColor],
gray: twColors[grayColor],
danger: twColors.red,
warn: twColors.yellow,
twgray: twColors.gray,
primary: _colors[primaryColor],
secondary: _colors[secondaryColor],
gray: _colors[grayColor],
danger: _colors.red,
warn: _colors.yellow,
twgray: _colors.gray,
...customColors,
},
// backdropBlur: {
// DEFAULT: "12px",
Expand Down

0 comments on commit c43edd0

Please sign in to comment.