2
0

table.tsx 2.4 KB

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