mango-v4-ui/components/shared/TableElements.tsx

99 lines
1.9 KiB
TypeScript
Raw Normal View History

import dayjs from 'dayjs'
2023-05-21 20:15:58 -07:00
import { ReactNode, forwardRef } from 'react'
2022-11-20 02:44:14 -08:00
export const Table = ({
children,
className,
}: {
children: ReactNode
className?: string
2023-02-03 02:36:44 -08:00
}) => <table className={`m-0 min-w-full p-0 ${className}`}>{children}</table>
2022-11-20 02:44:14 -08:00
export const TrHead = ({
children,
className,
}: {
children: ReactNode
className?: string
}) => <tr className={`border-b border-th-bkg-3 ${className}`}>{children}</tr>
export const Th = ({
children,
className,
id,
2023-05-11 14:32:48 -07:00
xBorder = false,
2022-11-20 02:44:14 -08:00
}: {
children?: ReactNode
className?: string
id?: string
2023-05-11 14:32:48 -07:00
xBorder?: boolean
2022-11-20 02:44:14 -08:00
}) => (
<th
2023-05-11 14:32:48 -07:00
className={`whitespace-nowrap px-2 py-3 text-xs font-normal text-th-fgd-3 first:pl-6 last:pr-6 xl:px-4 ${
xBorder ? 'border-x border-th-bkg-3' : ''
} ${className}`}
2022-11-20 02:44:14 -08:00
id={id}
scope="col"
>
{children}
</th>
)
2023-05-21 20:15:58 -07:00
interface TrBodyProps {
2022-11-20 02:44:14 -08:00
children: ReactNode
className?: string
onClick?: () => void
2023-05-21 20:15:58 -07:00
}
export const TrBody = forwardRef<HTMLTableRowElement, TrBodyProps>(
(props, ref) => {
const { children, className, onClick } = props
return (
<tr
className={`border-y border-th-bkg-3 ${className}`}
onClick={onClick}
ref={ref}
>
{children}
</tr>
)
}
2022-11-20 02:44:14 -08:00
)
2023-05-21 20:15:58 -07:00
TrBody.displayName = 'TrBody'
2022-11-20 02:44:14 -08:00
export const Td = ({
children,
className,
2023-05-11 14:32:48 -07:00
xBorder = false,
2022-11-20 02:44:14 -08:00
}: {
children: ReactNode
className?: string
2023-05-11 14:32:48 -07:00
xBorder?: boolean
}) => (
2023-05-11 14:32:48 -07:00
<td
className={`px-2 py-3 first:pl-6 last:pr-6 xl:px-4 ${
xBorder ? 'border-x border-th-bkg-3' : ''
} ${className}`}
>
{children}
</td>
)
export const TableDateDisplay = ({
date,
showSeconds,
}: {
date: string | number
showSeconds?: boolean
}) => (
<>
2023-01-06 16:26:06 -08:00
<p className="tracking-normal text-th-fgd-2">
{dayjs(date).format('DD MMM YYYY')}
</p>
2022-12-19 16:42:13 -08:00
<p className="text-xs text-th-fgd-4">
{dayjs(date).format(showSeconds ? 'h:mm:ssa' : 'h:mma')}
</p>
</>
)