mango-ui-v3/components/TableElements.tsx

108 lines
2.9 KiB
TypeScript
Raw Normal View History

2022-02-23 17:37:31 -08:00
import { Disclosure, Transition } from '@headlessui/react'
2022-02-10 17:50:40 -08:00
import { ChevronDownIcon } from '@heroicons/react/solid'
2022-02-23 17:37:31 -08:00
import { Fragment, ReactNode } from 'react'
2022-03-20 17:06:13 -07:00
import dayjs from 'dayjs'
2021-09-03 05:11:21 -07:00
export const Table = ({ children }) => (
2022-02-10 15:48:14 -08:00
<table className="min-w-full">{children}</table>
2021-09-03 05:11:21 -07:00
)
export const TrHead = ({ children }) => (
<tr className="text-xs text-th-fgd-3">{children}</tr>
2021-09-03 05:11:21 -07:00
)
export const Th = ({ children }) => (
<th className="px-4 pb-2 text-left font-normal" scope="col">
2021-09-03 05:11:21 -07:00
{children}
</th>
)
2022-04-03 15:39:24 -07:00
export const TrBody = ({ children, className = '' }) => (
<tr className={`border-b border-th-bkg-4 ${className}`}>{children}</tr>
2021-09-03 05:11:21 -07:00
)
export const Td = ({
children,
className,
}: {
children: ReactNode
className?: string
}) => (
<td className={`h-16 px-4 text-sm text-th-fgd-2 ${className}`}>{children}</td>
2021-09-03 05:11:21 -07:00
)
type ExpandableRowProps = {
buttonTemplate: React.ReactNode
panelTemplate: React.ReactNode
rounded?: boolean
}
export const ExpandableRow = ({
buttonTemplate,
panelTemplate,
rounded,
}: ExpandableRowProps) => {
return (
<Disclosure>
{({ open }) => (
<>
<Disclosure.Button
className={`default-transition flex w-full items-center justify-between border-t border-th-bkg-4 p-4 font-normal text-th-fgd-1 hover:bg-th-bkg-4 focus:outline-none ${
rounded
? open
? 'rounded-b-none'
: 'rounded-md'
: 'rounded-none'
}`}
>
{buttonTemplate}
2022-02-23 17:37:31 -08:00
<div className="flex items-center justify-end pl-4">
<ChevronDownIcon
className={`${
open ? 'rotate-180 transform' : 'rotate-360 transform'
} default-transition h-5 w-5 flex-shrink-0 text-th-fgd-1`}
/>
</div>
</Disclosure.Button>
2022-02-23 17:37:31 -08:00
<Transition
appear={true}
show={open}
as={Fragment}
enter="transition-all ease-in duration-200"
enterFrom="opacity-0"
enterTo="opacity-100"
leave="transition ease-out"
leaveFrom="opacity-100"
leaveTo="opacity-0"
>
2022-02-23 17:37:31 -08:00
<Disclosure.Panel>
<div className="px-4 pb-4 pt-2">{panelTemplate}</div>
2022-02-23 17:37:31 -08:00
</Disclosure.Panel>
</Transition>
</>
)}
</Disclosure>
)
}
type RowProps = {
children: React.ReactNode
}
2022-03-21 04:56:37 -07:00
export const Row = ({ children }: RowProps) => {
return (
<div
2022-03-21 04:56:37 -07:00
className={`default-transition w-full rounded-none border-t border-th-bkg-4 p-4 font-normal text-th-fgd-1`}
>
{children}
</div>
)
}
2022-03-20 17:06:13 -07:00
2022-03-24 13:06:59 -07:00
export const TableDateDisplay = ({ date }: { date: string | number }) => (
2022-03-20 17:06:13 -07:00
<>
<p className="mb-0 text-th-fgd-2">{dayjs(date).format('DD MMM YYYY')}</p>
<p className="mb-0 text-xs">{dayjs(date).format('h:mma')}</p>
</>
)