card.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import * as React from 'react';
  2. import { cn } from '@/lib/utils';
  3. function Card({
  4. className,
  5. size = 'default',
  6. ...props
  7. }: React.ComponentProps<'div'> & { size?: 'default' | 'sm' }) {
  8. return (
  9. <div
  10. data-slot="card"
  11. data-size={size}
  12. className={cn(
  13. 'ring-foreground/10 bg-card text-card-foreground gap-6 overflow-hidden rounded-xl py-6 text-sm shadow-xs ring-1 has-[>img:first-child]:pt-0 data-[size=sm]:gap-4 data-[size=sm]:py-4 *:[img:first-child]:rounded-t-xl *:[img:last-child]:rounded-b-xl group/card flex flex-col',
  14. className,
  15. )}
  16. {...props}
  17. />
  18. );
  19. }
  20. function CardHeader({ className, ...props }: React.ComponentProps<'div'>) {
  21. return (
  22. <div
  23. data-slot="card-header"
  24. className={cn(
  25. 'gap-1 rounded-t-xl px-6 group-data-[size=sm]/card:px-4 [.border-b]:pb-6 group-data-[size=sm]/card:[.border-b]:pb-4 group/card-header @container/card-header grid auto-rows-min items-start has-data-[slot=card-action]:grid-cols-[1fr_auto] has-data-[slot=card-description]:grid-rows-[auto_auto]',
  26. className,
  27. )}
  28. {...props}
  29. />
  30. );
  31. }
  32. function CardTitle({ className, ...props }: React.ComponentProps<'div'>) {
  33. return (
  34. <div
  35. data-slot="card-title"
  36. className={cn(
  37. 'text-base leading-normal font-medium group-data-[size=sm]/card:text-sm',
  38. className,
  39. )}
  40. {...props}
  41. />
  42. );
  43. }
  44. function CardDescription({ className, ...props }: React.ComponentProps<'div'>) {
  45. return (
  46. <div
  47. data-slot="card-description"
  48. className={cn('text-muted-foreground text-sm', className)}
  49. {...props}
  50. />
  51. );
  52. }
  53. function CardAction({ className, ...props }: React.ComponentProps<'div'>) {
  54. return (
  55. <div
  56. data-slot="card-action"
  57. className={cn('col-start-2 row-span-2 row-start-1 self-start justify-self-end', className)}
  58. {...props}
  59. />
  60. );
  61. }
  62. function CardContent({ className, ...props }: React.ComponentProps<'div'>) {
  63. return (
  64. <div
  65. data-slot="card-content"
  66. className={cn('px-6 group-data-[size=sm]/card:px-4', className)}
  67. {...props}
  68. />
  69. );
  70. }
  71. function CardFooter({ className, ...props }: React.ComponentProps<'div'>) {
  72. return (
  73. <div
  74. data-slot="card-footer"
  75. className={cn(
  76. 'rounded-b-xl px-6 group-data-[size=sm]/card:px-4 [.border-t]:pt-6 group-data-[size=sm]/card:[.border-t]:pt-4 flex items-center',
  77. className,
  78. )}
  79. {...props}
  80. />
  81. );
  82. }
  83. export { Card, CardHeader, CardFooter, CardTitle, CardAction, CardDescription, CardContent };