0.3.1 • Published 1 year ago

@bob-obringer/tw-color-schemes v0.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Tailwind CSS Color Schemes

This package helps manage multiple color schemes for tailwind.

Pass it a color scheme definition, and it gives you a colorSchemePlugin to include in your tailwind configuration.

Installation

pnpm add -D @bob-obringer/tw-color-schemes
npm install --save-dev @bob-obringer/tw-color-schemes
yarn add --dev @bob-obringer/tw-color-schemes

Features

  • Create as many color schemes as you want
  • Allows components to reference a single semantic color name instead of managing all modes
  • Removes the need for additional dark: or light: class names on each of your components
  • Allows nesting color schemes within a single page using a class name to switch schemes
  • Supports multiple color formats (hex, rgb, tailwind rgb tokens)
  • Typesafe, ensuring all color schemes include all required color entries

Usage

my-color-scheme.ts

import { createColorSchemePlugin } from "@bob-obringer/tw-color-schemes";
import { primitive, awesome } from "someones/awesome/colors";

const colorSchemePlugin = createColorSchemePlugin(
  {
    background: {
      default: primitive["Flat Grays"]["00"].value,
      primary: primitive["Flat Grays"]["00"].value,
      secondary: primitive["Flat Grays"]["01"].value,
    },
    text: {
      default: primitive["Flat Grays"]["00"].value,
      primary: primitive["Flat Grays"]["00"].value,
      secondary: primitive["Transparent Grays"]["08"].value,
    },
    border: {
      default: primitive["Transparent Grays"]["09"].value,
      primary: primitive["Transparent Grays"]["09"].value,
      secondary: primitive["Transparent Grays"]["05"].value,
    },
  },
  {
    awesome: {
      background: {
        default: awesome["Flat Grays"]["00"].value,
        primary: awesome["Flat Grays"]["00"].value,
        secondary: awesome["Flat Grays"]["01"].value,
      },
      text: {
        default: awesome["Flat Grays"]["00"].value,
        primary: awesome["Flat Grays"]["00"].value,
        secondary: awesome["Transparent Grays"]["08"].value,
      },
      border: {
        default: awesome["Transparent Grays"]["09"].value,
        primary: awesome["Transparent Grays"]["09"].value,
        secondary: awesome["Transparent Grays"]["05"].value,
      },
    },
  },
);

tailwind.config.ts

import type { Config } from "tailwindcss";
import { colors, colorSchemePlugin } from "./my-color-scheme.ts";

export const config: Config = {
  ...
  plugins: [colorSchemePlugin]
};

export default config;

Root.tsx

export default function Root() {
  return (
    <body className="awesome-color-scheme">
      ...
      <div className="text-color-primary">I'm awesome text 😀🔥</div>
      <div className="light-color-scheme">
        <div className="text-color-primary">I'm less awesome text 😔</div>
      </div>
      ...
    </body>
  );
}

Status

Tailwind 4 is going to change both the need and approach to this. I don't plan on making any significant changes to this package until Tailwind 4 is further along.

0.3.0

1 year ago

0.1.2

1 year ago

0.2.0

1 year ago

0.1.1

1 year ago

0.1.4

1 year ago

0.3.1

1 year ago

0.1.3

1 year ago

0.1.5

1 year ago

0.1.0

1 year ago

0.0.35

1 year ago

0.0.34

1 year ago

0.0.33

1 year ago

0.0.32

1 year ago

0.0.31

1 year ago

0.0.30

1 year ago

0.0.29

1 year ago

0.0.28

1 year ago

0.0.27

1 year ago

0.0.26

1 year ago

0.0.25

1 year ago

0.0.24

1 year ago

0.0.22

1 year ago

0.0.19

1 year ago

0.0.18

1 year ago

0.0.17

1 year ago

0.0.16

1 year ago

0.0.8

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago