table.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. "use client"
  2. import * as React from "react"
  3. import { cn } from "@/lib/utils"
  4. function Table({ className, ...props }: React.ComponentProps<"table">) {
  5. return (
  6. <div
  7. data-slot="table-container"
  8. className="relative w-full overflow-x-auto"
  9. >
  10. <table
  11. data-slot="table"
  12. className={cn("w-full caption-bottom text-sm", className)}
  13. {...props}
  14. />
  15. </div>
  16. )
  17. }
  18. function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
  19. return (
  20. <thead
  21. data-slot="table-header"
  22. className={cn("[&_tr]:border-b", className)}
  23. {...props}
  24. />
  25. )
  26. }
  27. function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {
  28. return (
  29. <tbody
  30. data-slot="table-body"
  31. className={cn("[&_tr:last-child]:border-0", className)}
  32. {...props}
  33. />
  34. )
  35. }
  36. function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
  37. return (
  38. <tfoot
  39. data-slot="table-footer"
  40. className={cn(
  41. "bg-muted/50 border-t font-medium [&>tr]:last:border-b-0",
  42. className
  43. )}
  44. {...props}
  45. />
  46. )
  47. }
  48. function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
  49. return (
  50. <tr
  51. data-slot="table-row"
  52. className={cn(
  53. "hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",
  54. className
  55. )}
  56. {...props}
  57. />
  58. )
  59. }
  60. function TableHead({ className, ...props }: React.ComponentProps<"th">) {
  61. return (
  62. <th
  63. data-slot="table-head"
  64. className={cn(
  65. "text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
  66. className
  67. )}
  68. {...props}
  69. />
  70. )
  71. }
  72. function TableCell({ className, ...props }: React.ComponentProps<"td">) {
  73. return (
  74. <td
  75. data-slot="table-cell"
  76. className={cn(
  77. "p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
  78. className
  79. )}
  80. {...props}
  81. />
  82. )
  83. }
  84. function TableCaption({
  85. className,
  86. ...props
  87. }: React.ComponentProps<"caption">) {
  88. return (
  89. <caption
  90. data-slot="table-caption"
  91. className={cn("text-muted-foreground mt-4 text-sm", className)}
  92. {...props}
  93. />
  94. )
  95. }
  96. export {
  97. Table,
  98. TableHeader,
  99. TableBody,
  100. TableFooter,
  101. TableHead,
  102. TableRow,
  103. TableCell,
  104. TableCaption,
  105. }