Skip to content

Commit

Permalink
card component, needs accessiblity and states improvements, boxShadow…
Browse files Browse the repository at this point in the history
…s added to the global tw config
  • Loading branch information
mewdev committed Nov 4, 2024
1 parent 888812a commit bdad52d
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 1 deletion.
54 changes: 54 additions & 0 deletions apps/design-system/stories/card.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import type { Meta, StoryObj } from "@storybook/react";

import { Card } from "@repo/design-system/card";

const meta: Meta<typeof Card> = {
title: "Components/Card",
component: Card,
decorators: [
(Story) => (
<div
style={{
display: "flex",
justifyContent: "center",
backgroundColor: "lightgray",
alignItems: "center",
height: "100vh",
}}
>
<Story />
</div>
),
],
};

type CardStory = StoryObj<typeof meta>;

export const Default: CardStory = {
args: {
children: "Hello, World!",
color: "white",
corner: "topRight",
},
};

export const Border: CardStory = {
args: {
children: "Hello, World!",
color: "white",
corner: "topRight",
border: "default",
},
};

export const BorderAndShadow: CardStory = {
args: {
children: "Hello, World!",
color: "white",
corner: "topRight",
border: "default",
shadow: "default",
},
};

export default meta;
11 changes: 11 additions & 0 deletions packages/design-system/config/boxShadow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ThemeConfig } from "tailwindcss/types/config";

const boxShadow: Pick<Partial<ThemeConfig>, "boxShadow"> = {
// !!! Adding custom boxShadow
boxShadow: {
// TODO: rewrite colors in RGB later
neutral: "6px 8px 0px 0px #DAD8D733",
},
};

export default boxShadow;
2 changes: 1 addition & 1 deletion packages/design-system/config/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const backgroundColorNeutral = {
neutral: neutralColors[90],
"neutral-strong-hover": neutralColors[30],
"neutral-strong-active": neutralColors[10],
"neutral-disaled": neutralColors[70],
"neutral-disabled": neutralColors[70],
"neutral-backdrop": `rgb(from ${neutralColors[70]} r g b / 0.1)`,
"neutral-backdrop-hover": `rgb(from ${neutralColors[70]} r g b / 0.2)`,
"neutral-backdrop-active": `rgb(from ${neutralColors[70]} r g b / 0.6)`,
Expand Down
70 changes: 70 additions & 0 deletions packages/design-system/src/card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import React from "react";
import { HTMLAttributes } from "react";
import { cva, VariantProps } from "class-variance-authority";
import { twMerge } from "tailwind-merge";

type Props = {
children: React.ReactNode;
} & VariantProps<typeof cardVariants> &
HTMLAttributes<HTMLDivElement>;

const cardVariants = cva(
"disabled:k1-bg-neutral-disabled disabled:k1-pointer-events-none focus:k1-ring-purple-500 focus:k1-ring-8",
{
variants: {
color: {
white:
// TODO: add white as neutral-fg-inverse to the config?
"k1-bg-white hover:k1-bg-neutral-backdrop-hover active:k1-bg-neutral-backdrop-active",
blue: "k1-bg-primary hover:k1-bg-primary-strong-hover active:k1-bg-primary-strong-active",
transparent:
"k1-bg-transparent hover:k1-bg-neutral-backdrop-hover active:k1-bg-neutral-backdrop-active",
},
corner: {
topRight: "k1-rounded-l k1-rounded-br",
topLeft: "k1-rounded-r k1-rounded-bl",
bottomRight: "k1-rounded-t k1-rounded-bl",
bottomLeft: "k1-rounded-t k1-rounded-br",
},
border: {
default: "k1-border-neutral k1-border",
strong: "k1-border-primary-strong k1-border",
none: null,
},
shadow: {
default: "k1-shadow-neutral",
none: null,
},
},
defaultVariants: {
color: "white",
corner: "topRight",
border: "default",
shadow: "default",
},
},
);

const Card = ({
children,
color,
corner,
border,
shadow,
className,
...rest
}: Props): JSX.Element => {
return (
<div
className={twMerge(
cardVariants({ color, corner, border, shadow }),
className,
)}
{...rest}
>
{children}
</div>
);
};

export { Card, cardVariants };
2 changes: 2 additions & 0 deletions packages/design-system/tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import colors from "./config/colors";
import typography from "./config/typography";
import spacing from "./config/spacing";
import borderRadius from "./config/borderRadius";
import boxShadow from "./config/boxShadow";

// Each package is responsible for its own content
const config: Config = {
Expand All @@ -13,6 +14,7 @@ const config: Config = {
...colors,
...typography,
...spacing,
...boxShadow,
},
// Replace the default Tailwind CSS with our own
...borderRadius,
Expand Down

0 comments on commit bdad52d

Please sign in to comment.