Skip to content

Commit

Permalink
Card (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
dani-moreno authored Apr 15, 2024
1 parent 59ca150 commit 566ce8b
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 0 deletions.
61 changes: 61 additions & 0 deletions lib/foundations/card.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import type { Meta, StoryObj } from "@storybook/react"

import { Button } from "@/foundations/button"

import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "./card"

const meta = {
component: Card,
parameters: {
layout: "centered",
},
tags: ["autodocs"],
args: {},
} satisfies Meta<typeof Card>

export default meta
type Story = StoryObj<typeof meta>

export const Basic: Story = {
render: () => {
return (
<Card>
<CardContent>This is a basic card</CardContent>
</Card>
)
},
}

export const WithTitle: Story = {
render: () => {
return (
<Card>
<CardHeader>
<CardTitle>Card title</CardTitle>
<CardDescription>Description of the title</CardDescription>
</CardHeader>
<CardContent>This is a card with a title</CardContent>
</Card>
)
},
}

export const WithFooter: Story = {
render: () => {
return (
<Card>
<CardContent>This is a card with a footer</CardContent>
<CardFooter>
<Button className="w-full">Clock in</Button>
</CardFooter>
</Card>
)
},
}
79 changes: 79 additions & 0 deletions lib/foundations/card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import * as React from "react"

import { cn } from "@/lib/utils"

const Card = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn(
"rounded-2xl border bg-card text-card-foreground shadow-sm",
className
)}
{...props}
/>
))
Card.displayName = "Card"

const CardHeader = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex flex-col space-y-1.5 p-6 pb-0", className)}
{...props}
/>
))
CardHeader.displayName = "CardHeader"

const CardTitle = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLHeadingElement>
>(({ className, ...props }, ref) => (
<h3
ref={ref}
className={cn(
"text-2xl font-semibold leading-none tracking-tight",
className
)}
{...props}
/>
))
CardTitle.displayName = "CardTitle"

const CardDescription = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLParagraphElement>
>(({ className, ...props }, ref) => (
<p
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
))
CardDescription.displayName = "CardDescription"

const CardContent = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
))
CardContent.displayName = "CardContent"

const CardFooter = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex items-center px-6 pb-6 pt-0", className)}
{...props}
/>
))
CardFooter.displayName = "CardFooter"

export { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle }

0 comments on commit 566ce8b

Please sign in to comment.