ghost-portal/packages/react-components/src/Table/Head.tsx
Jaco ac2e910d8b
Adjust Table borders (w/ spacing) (#8729)
* Adjust Table borders (w/ spacing)

* Background only on cells
2023-01-08 15:54:26 +02:00

145 lines
2.6 KiB
TypeScript

// Copyright 2017-2023 @polkadot/react-components authors & contributors
// SPDX-License-Identifier: Apache-2.0
import React from 'react';
import styled from 'styled-components';
type HeaderDef = [React.ReactNode?, string?, number?, (() => void)?];
interface Props {
children?: React.ReactNode;
className?: string;
filter?: React.ReactNode;
header?: (null | undefined | HeaderDef)[];
isEmpty: boolean;
}
function Head ({ children, className = '', filter, header, isEmpty }: Props): React.ReactElement<Props> | null {
if (!header?.length) {
return null;
}
return (
<thead className={className}>
{filter && (
<tr className='filter'>
<th colSpan={100}>{filter}</th>
</tr>
)}
<tr>
{header.filter((h): h is HeaderDef => !!h).map(([label, className = 'default', colSpan = 1, onClick], index) =>
<th
className={className}
colSpan={colSpan}
key={index}
onClick={onClick}
>
{index === 0
? <h1>{label}</h1>
: isEmpty
? ''
: label
}
</th>
)}
</tr>
{children}
</thead>
);
}
export default React.memo(styled(Head)`
z-index: 1;
th {
background: var(--bg-table);
font: var(--font-sans);
font-weight: var(--font-weight-normal);
padding: 0.375rem 1rem;
text-align: right;
vertical-align: middle;
white-space: nowrap;
h1, h2 {
font-size: 1.75rem;
}
h1 {
display: table-cell;
vertical-align: middle;
.sub {
display: inline-block;
font-size: 1rem;
padding-left: 1.5rem;
text-overflow: ellipsis;
vertical-align: middle;
}
}
&.address {
padding-left: 3rem;
text-align: left;
}
&.badge {
padding: 0;
}
&.expand,
&.number {
text-align: right;
}
&.isClickable {
cursor: pointer;
}
&.mini {
padding: 0 !important;
}
&.no-pad-left {
padding-left: 0.125rem;
}
&.no-pad-right {
padding-right: 0.125rem;
}
&.start {
text-align: left;
}
&.balances {
text-align: right;
padding-right: 2.25rem;
}
}
tr {
text-transform: lowercase;
&.filter {
.ui.input,
.ui.selection.dropdown {
background: transparent;
&:first-child {
margin-top: 0;
}
}
th {
padding: 0;
}
}
&:not(.filter) {
th {
color: var(--color-table-head);
}
}
}
`);