Skip to content

Commit

Permalink
refactor: add DEFAULT colors for bg, border and text
Browse files Browse the repository at this point in the history
  • Loading branch information
itsjavi committed Sep 8, 2024
1 parent d8e37ac commit 4673385
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 34 deletions.
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ a glassmorphic style:

## Installation

This is a Tailwind CSS component library, so you need to install the package,
and also adjust your `tailwind.config.js|ts` configuration.
This is a Tailwind CSS component library, so you need to install the package, adjust your `tailwind.config.js|ts` configuration and some global styles.

```bash
npm install glasscn-ui
Expand Down Expand Up @@ -102,6 +101,32 @@ export default {
};
```

### Global styles

```css
@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
:root {
--background: theme("colors.background.DEFAULT");
--foreground: theme("colors.foreground.DEFAULT");
--foreground-muted: theme("colors.foreground.muted.DEFAULT");
--border: theme("colors.border.DEFAULT");
--border-muted: theme("colors.border.muted.DEFAULT");
}

.dark {
--background: theme("colors.background.dark");
--foreground: theme("colors.foreground.dark");
--foreground-muted: theme("colors.foreground.muted.dark");
--border: theme("colors.border.dark");
--border-muted: theme("colors.border.muted.dark");
}
}
```

## What components are not included?

In order to reduce the amount of dependencies and the bundle size and complexity, some components are not included:
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui-extras/heading-title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const twStyles = {
gradient: ["bg-clip-text text-transparent bg-gradient-to-br"],
},
colors: {
default: ["text-foreground dark:text-foreground-dark"],
default: ["text-foreground"],
primary: ["text-primary-600"],
secondary: ["text-secondary-600"],
},
Expand Down
8 changes: 4 additions & 4 deletions src/components/ui/breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { cn } from "@/lib/utils";
const twStyles = {
nav: "mx-auto flex w-full justify-center",
list: [
"flex flex-wrap items-center gap-1.5 break-words text-sm text-neutral-500",
"sm:gap-2.5 dark:text-neutral-400",
"flex flex-wrap items-center gap-1.5 break-words text-sm text-foreground-muted",
"sm:gap-2.5",
],
item: "inline-flex items-center gap-1.5",
link: "transition-colors hover:text-neutral-950 dark:hover:text-neutral-50",
page: "font-normal text-neutral-950 dark:text-neutral-50",
link: "transition-colors hover:text-foreground",
page: "font-normal text-foreground",
separator: "[&>svg]:size-3.5",
ellipsis: "flex h-9 w-9 items-center justify-center",
};
Expand Down
10 changes: 5 additions & 5 deletions src/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

@layer base {
:root {
--background: theme('colors.background.DEFAULT');
--foreground: theme('colors.foreground.DEFAULT');
--foreground-muted: theme('colors.foreground.muted.DEFAULT');
--border: theme('colors.border.DEFAULT');
--border-muted: theme('colors.border.muted.DEFAULT');
--background: theme('colors.background.light');
--foreground: theme('colors.foreground.light');
--foreground-muted: theme('colors.foreground.muted.light');
--border: theme('colors.border.light');
--border-muted: theme('colors.border.muted.light');
}

.dark {
Expand Down
24 changes: 16 additions & 8 deletions src/lib/create-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ type CustomColorLevel =
| 700
| 800
| 900
| 950
| string;
| 950;
type CustomColor = Record<CustomColorLevel, string>;
type DarkLightColor = {
light: string;
Expand Down Expand Up @@ -159,7 +158,7 @@ const defaultConfig: PresetConfig = {

function resolveColor(color: TailwindColor | CustomColor): CustomColor {
if (typeof color === "string") {
return safeTwColors[color];
return safeTwColors[color] as CustomColor;
}
return color;
}
Expand All @@ -185,6 +184,10 @@ function resolveConfig(config: PartialPresetConfig): PresetConfig {
return resolvedConfig;
}

function getColorMix(color: string) {
return `color-mix(in srgb, ${color}, transparent calc(100% - <alpha-value> * 100%))`;
}

export function createTailwindPreset(
config: PartialPresetConfig = {},
): Partial<Config> {
Expand All @@ -197,23 +200,28 @@ export function createTailwindPreset(
extend: {
colors: {
background: {
DEFAULT: resolvedConfig.colors.background.light,
DEFAULT: getColorMix("var(--background)"),
light: resolvedConfig.colors.background.light,
dark: resolvedConfig.colors.background.dark,
// muted: resolvedConfig.colors.backgroundMuted,
},
foreground: {
DEFAULT: resolvedConfig.colors.foreground.light,
DEFAULT: getColorMix("var(--foreground)"),
light: resolvedConfig.colors.foreground.light,
dark: resolvedConfig.colors.foreground.dark,
muted: {
DEFAULT: resolvedConfig.colors.foregroundMuted.light,
DEFAULT: getColorMix("var(--foreground-muted)"),
light: resolvedConfig.colors.foregroundMuted.light,
dark: resolvedConfig.colors.foregroundMuted.dark,
},
},
border: {
DEFAULT: resolvedConfig.colors.border.light,
DEFAULT: getColorMix("var(--border)"),
light: resolvedConfig.colors.border.light,
dark: resolvedConfig.colors.border.dark,
muted: {
DEFAULT: resolvedConfig.colors.borderMuted.light,
DEFAULT: getColorMix("var(--border-muted)"),
light: resolvedConfig.colors.borderMuted.light,
dark: resolvedConfig.colors.borderMuted.dark,
},
},
Expand Down
33 changes: 22 additions & 11 deletions stories/breadcrumb.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
import {
Breadcrumb,
BreadcrumbEllipsis,
BreadcrumbItem,
BreadcrumbLink,
BreadcrumbList,
BreadcrumbPage,
BreadcrumbSeparator,
Breadcrumb,
BreadcrumbEllipsis,
BreadcrumbItem,
BreadcrumbLink,
BreadcrumbList,
BreadcrumbPage,
BreadcrumbSeparator,
} from "@/components/ui/breadcrumb";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import type { Meta, StoryObj } from "@storybook/react";

const meta: Meta<typeof Breadcrumb> = {
title: "UI/Breadcrumb",
component: Breadcrumb,
// tags: ["autodocs"],
decorators: [
(Story) => (
<div className="bg-decorator">
<Story />
<div className="text-foreground">FG text </div>
<div className="text-foreground-muted">
FG text muted
</div>
</div>
),
],
};

export default meta;
Expand Down
4 changes: 2 additions & 2 deletions stories/navigation-menu-demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function NavigationMenuDemo() {
<div className="mb-2 mt-4 text-lg font-medium">
shadcn/ui
</div>
<p className="text-sm leading-tight text-muted-foreground">
<p className="text-sm leading-tight text-foreground-muted">
Beautifully designed components that you can copy and
paste into your apps. Accessible. Customizable. Open
Source.
Expand Down Expand Up @@ -131,7 +131,7 @@ const ListItem = React.forwardRef<
{...props}
>
<div className="text-sm font-medium leading-none">{title}</div>
<p className="line-clamp-2 text-sm leading-snug text-foreground-muted dark:text-foreground-muted-dark group-hover:text-white group-focus:text-white">
<p className="line-clamp-2 text-sm leading-snug text-foreground-muted group-hover:text-white group-focus:text-white">
{children}
</p>
</a>
Expand Down
2 changes: 1 addition & 1 deletion stories/separator.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const Default: Story = {
<div>
<div className="space-y-1">
<h4 className="text-sm font-medium leading-none">Radix Primitives</h4>
<p className="text-sm text-muted-foreground">An open-source UI component library.</p>
<p className="text-sm text-foreground-muted">An open-source UI component library.</p>
</div>
<Separator className="my-4" />
<div className="flex h-5 items-center space-x-4 text-sm">
Expand Down

0 comments on commit 4673385

Please sign in to comment.