0.2.0 • Published 11 months ago

tailwindcss-shadcn-ui v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

tailwindcss-shadcn-ui

A plugin/preset for Tailwind CSS v3.2+ that provides base utilities for shadcn ui.

Installation

This plugin requires tailwindcss and tailwindcss-animate

npm

npm install tailwindcss-shadcn-ui --save-dev

yarn

yarn install -D tailwindcss-shadcn-ui

pnpm

pnpm add -D tailwindcss-shadcn-ui

Configuration

Recommend

Add the shadcn preset to your tailwind config file unsing the preset creator function.

With this approach we can get a full configured preset including tailwindcss-animate plugin and dark mode set to class. Shoutout to @simonswiss. He metioned the preset way in his video.

// tailwind.config.ts
import { type Config } from "tailwindcss";
import { createPreset } from "tailwindcss-shadcn-ui";

export default {
    presets: [createPreset()],
    // ...
} satisfies Config;

Alternative

With this approach we can not preconfigure the plugins to include the tailwindcss-animate plugin. So you have to include it yourself.

// tailwind.config.ts
import { type Config } from "tailwindcss";
import tailwindAnimate from "tailwindcss-animate";
import tailwindShadcnUi from "tailwindcss-shadcn-ui";

export default {
    darkMode: ["class"],
    // ...
    plugins: [
        // ...
        tailwindShadcnUi,
        tailwindAnimate,
    ],
} satisfies Config;

Theme presets

// tailwind.config.ts
import { createPreset } from "tailwindcss-shadcn-ui";
import { DEFAULT } from "tailwindcss-shadcn-ui/themes";

export default {
    presets: [createPreset({ theme: DEFAULT })],
    // ..
};
// tailwind.config.ts
import tailwindShadcnUi from "tailwindcss-shadcn-ui";
import { DEFAULT } from "tailwindcss-shadcn-ui/themes";

export default {
    // ...
    plugins: [
        // ...
        tailwindShadcnUi({
            theme: DEFAULT,
        }),
    ],
};

Available presets

PresetFiles
DEFAULTthemes/default.ts

Define your own theme

// tailwind.config.ts

import { createPreset, defineTheme } from "tailwindcss-shadcn-ui";
import { DEFAULT } from "tailwindcss-shadcn-ui/themes";

export default {
    presets: [
        createPreset({
            theme: defineTheme({
                base: {
                    radius: "2rem", // string|number(pixels),
                    fontFamily: "Inter", // string|string[]
                },
                light: {
                    background: "0 0% 0%", // `${number} ${number}% ${number}%`
                    foreground: [0, 0, 0], // [hue: number, saturation: number, lightness: number]
                    //...
                },
                dark: {
                    background: "#000000", // `#${string}`
                    // ...
                },
            }),
        }),
    ],
    // ..
};

export default {
    // ...
    plugins: [
        // ...
        tailwindShadcnUi({
            theme: defineTheme({
                // ..
            }),
        }),
    ],
};

The result

the preset adds following tailwind config.

export default {
    plugins: [tailwindAnimate],
    theme: {
        container: {
            center: true,
            padding: "2rem",
            screens: {
                "2xl": "1400px",
            },
        },
        extend: {
            fontFamily: {
                sans: ["var(--font-sans)", ...fontFamily.sans],
            },
            colors: {
                border: "hsl(var(--border) / <alpha-value>)",
                input: "hsl(var(--input) / <alpha-value>)",
                ring: "hsl(var(--ring) / <alpha-value>)",
                background: "hsl(var(--background) / <alpha-value>)",
                foreground: "hsl(var(--foreground) / <alpha-value>)",
                primary: {
                    DEFAULT: "hsl(var(--primary) / <alpha-value>)",
                    foreground: "hsl(var(--primary-foreground) / <alpha-value>)",
                },
                secondary: {
                    DEFAULT: "hsl(var(--secondary) / <alpha-value>)",
                    foreground: "hsl(var(--secondary-foreground) / <alpha-value>)",
                },
                destructive: {
                    DEFAULT: "hsl(var(--destructive) / <alpha-value>)",
                    foreground: "hsl(var(--destructive-foreground) / <alpha-value>)",
                },
                muted: {
                    DEFAULT: "hsl(var(--muted) / <alpha-value>)",
                    foreground: "hsl(var(--muted-foreground) / <alpha-value>)",
                },
                accent: {
                    DEFAULT: "hsl(var(--accent) / <alpha-value>)",
                    foreground: "hsl(var(--accent-foreground) / <alpha-value>)",
                },
                popover: {
                    DEFAULT: "hsl(var(--popover) / <alpha-value>)",
                    foreground: "hsl(var(--popover-foreground) / <alpha-value>)",
                },
                card: {
                    DEFAULT: "hsl(var(--card) / <alpha-value>)",
                    foreground: "hsl(var(--card-foreground) / <alpha-value>)",
                },
            },
            borderRadius: {
                lg: "var(--radius)",
                md: "calc(var(--radius) - 2px)",
                sm: "calc(var(--radius) - 4px)",
            },
            keyframes: {
                "accordion-down": {
                    from: { height: "0" },
                    to: { height: "var(--radix-accordion-content-height)" },
                },
                "accordion-up": {
                    from: { height: "var(--radix-accordion-content-height)" },
                    to: { height: "0" },
                },
            },
            animation: {
                "accordion-down": "accordion-down 0.2s ease-out",
                "accordion-up": "accordion-up 0.2s ease-out",
            },
        },
    },
};

The plugin adds following base styles with values based on your configured theme.

:root {
    --background: 0 0% 100%;
    --foreground: 222.2 47.4% 11.2%;

    --muted: 210 40% 96.1%;
    --muted-foreground: 215.4 16.3% 46.9%;

    --popover: 0 0% 100%;
    --popover-foreground: 222.2 47.4% 11.2%;

    --card: 0 0% 100%;
    --card-foreground: 222.2 47.4% 11.2%;

    --border: 214.3 31.8% 91.4%;
    --input: 214.3 31.8% 91.4%;

    --primary: 222.2 47.4% 11.2%;
    --primary-foreground: 210 40% 98%;

    --secondary: 210 40% 96.1%;
    --secondary-foreground: 222.2 47.4% 11.2%;

    --accent: 210 40% 96.1%;
    --accent-foreground: 222.2 47.4% 11.2%;

    --destructive: 0 100% 50%;
    --destructive-foreground: 210 40% 98%;

    --ring: 215 20.2% 65.1%;

    --radius: 0.5rem;
    --font-sans: Inter;
}

.dark {
    --background: 224 71% 4%;
    --foreground: 213 31% 91%;

    --muted: 223 47% 11%;
    --muted-foreground: 215.4 16.3% 56.9%;

    --popover: 224 71% 4%;
    --popover-foreground: 215 20.2% 65.1%;

    --card: 224 71% 4%;
    --card-foreground: 213 31% 91%;

    --border: 216 34% 17%;
    --input: 216 34% 17%;

    --primary: 210 40% 98%;
    --primary-foreground: 222.2 47.4% 1.2%;

    --secondary: 222.2 47.4% 11.2%;
    --secondary-foreground: 210 40% 98%;

    --accent: 216 34% 17%;
    --accent-foreground: 210 40% 98%;

    --destructive: 0 63% 31%;
    --destructive-foreground: 210 40% 98%;

    --ring: 216 34% 17%;

    --radius: 0.5rem;
}

* {
    @apply border-border;
}

body {
    @apply bg-background text-foreground;
    font-feature-settings: "rlig" 1, "calt" 1;
}
0.2.0

11 months ago

0.1.0

11 months ago

0.0.8

11 months ago

0.0.7

11 months ago

0.0.6

11 months ago

0.0.5

11 months ago

0.0.4

11 months ago

0.0.3

11 months ago

0.0.2

11 months ago

1.0.1

11 months ago