Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/components/cards/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as React from 'react'
import { cva, type VariantProps } from 'class-variance-authority'
import { Card as BaseCard, CardTitle as BaseCardTitle, CardContent as BaseCardContent } from '../ui/card'
import { cn } from '../../lib/utils'
export { CardFooter, CardHeader, CardAction, CardDescription } from '../ui/card'

const cardVariants = cva('rounded-sm', {
variants: {
variant: {
default: '',
layout: 'flex-1 gap-2 bg-background mb-4 md:mb-6',
},
},
defaultVariants: {
variant: 'default',
},
})

type CardProps = React.ComponentProps<typeof BaseCard> & VariantProps<typeof cardVariants>

export const Card = ({ className, variant, ...props }: CardProps) => (
<BaseCard className={cn(cardVariants({ variant }), className)} {...props} />
)

type CardTitleProps = React.ComponentProps<typeof BaseCardTitle>

export const CardTitle = ({ className, ...props }: CardTitleProps) => (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

@buberdds buberdds Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

welp it's how radix/shadcn card works. Now issue is more visible due to text-sm in content. CardContent affects Card width, CardHeader is having layout issues due to grid display. I did not find any magic tailwind class to fix that nicely. We can use two workarounds:

  1. control min-w on component level in app/storybook if content is very short
  2. overwrite radix/shadcn layout of CardsHader/Title/Action

I would go with 1 tbh because 2 is less predictible

https://bf5f8bfa.oasis-ui.pages.dev/?path=/story/components-card--with-action

<BaseCardTitle
className={cn('flex-1 flex justify-between [&>a]:font-medium [&>a]:text-sm', className)}
{...props}
/>
)

type CardContentProps = React.ComponentProps<typeof BaseCardContent>

export const CardContent = ({ className, ...props }: CardContentProps) => (
<BaseCardContent className={cn('text-sm', className)} {...props} />
)
4 changes: 2 additions & 2 deletions src/stories/Card/Card.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
CardFooter,
CardHeader,
CardTitle,
} from '../../components/ui/card.tsx'
} from '../../components/cards'
import { Button } from '../../components/ui/button.tsx'
import { expect, within } from 'storybook/test'

Expand Down Expand Up @@ -65,7 +65,7 @@ export const WithAction: Story = {
</Button>
</CardAction>
</CardHeader>
<CardContent>View your notifications here.</CardContent>
<CardContent>View and interact with your notifications here.</CardContent>
<CardFooter>
<Button variant="outline" className="w-full">
View all
Expand Down