Table.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import React from "react"
  2. interface TableProps {
  3. children: React.ReactNode
  4. }
  5. export function Table({ children }: TableProps) {
  6. return (
  7. <div className="overflow-x-auto my-6 border border-neutral-300 dark:border-neutral-700 rounded-lg">
  8. <table className="w-full border-collapse text-sm">{children}</table>
  9. </div>
  10. )
  11. }
  12. interface THeadProps {
  13. children: React.ReactNode
  14. }
  15. export function THead({ children }: THeadProps) {
  16. return <thead className="bg-neutral-100 dark:bg-neutral-800/50">{children}</thead>
  17. }
  18. interface TBodyProps {
  19. children: React.ReactNode
  20. }
  21. export function TBody({ children }: TBodyProps) {
  22. return <tbody className="bg-white dark:bg-neutral-900/50">{children}</tbody>
  23. }
  24. interface TrProps {
  25. children: React.ReactNode
  26. }
  27. export function Tr({ children }: TrProps) {
  28. return <tr className="border-b border-neutral-300 dark:border-neutral-700 last:border-b-0">{children}</tr>
  29. }
  30. interface ThProps {
  31. children: React.ReactNode
  32. width?: string
  33. }
  34. export function Th({ children, width }: ThProps) {
  35. return (
  36. <th
  37. className="px-4 py-2.5 text-left text-sm font-medium text-neutral-700 dark:text-neutral-300"
  38. style={{ width }}>
  39. {children}
  40. </th>
  41. )
  42. }
  43. interface TdProps {
  44. children: React.ReactNode
  45. colspan?: number
  46. rowspan?: number
  47. }
  48. export function Td({ children, colspan, rowspan }: TdProps) {
  49. return (
  50. <td className="px-4 py-3 text-neutral-600 dark:text-neutral-400" colSpan={colspan} rowSpan={rowspan}>
  51. {children}
  52. </td>
  53. )
  54. }