ghost-portal/packages/react-components/src/Table/Head.tsx
Jaco Greeff af8b00750d
Select slot range via dropdown (#4845)
* Select slot range

* Formatting adjust

* Crowdload active/ended split

* Raised active cap

* Remove useFundIndexes

* Display leases for upcoming

* Formatting

* Correct header
2021-03-14 13:15:26 +01:00

157 lines
2.8 KiB
TypeScript

// Copyright 2017-2021 @polkadot/react-components authors & contributors
// SPDX-License-Identifier: Apache-2.0
import React from 'react';
import styled from 'styled-components';
import Icon from '../Icon';
type HeaderDef = [React.ReactNode?, string?, number?, (() => void)?];
interface Props {
className?: string;
filter?: React.ReactNode;
header?: (null | undefined | HeaderDef)[];
isEmpty: boolean;
}
function Head ({ 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>
<Icon
className='highlight--color'
icon='dot-circle'
/>
{label}
</h1>
)
: isEmpty
? ''
: label
}
</th>
)}
</tr>
</thead>
);
}
export default React.memo(styled(Head)`
position: relative;
z-index: 1;
th {
font: var(--font-sans);
font-weight: var(--font-weight-normal);
padding: 0.5rem 1rem 0.25rem;
text-align: right;
vertical-align: baseline;
white-space: nowrap;
h1, h2 {
font-size: 1.75rem;
}
h1 {
.ui--Icon {
font-size: 1rem;
margin-right: 0.5rem;
vertical-align: middle;
}
}
&:first-child {
border-left: 1px solid var(--border-table);
}
&:last-child {
border-right: 1px solid var(--border-table);
}
&.address {
padding-left: 3rem;
text-align: left;
}
&.badge {
padding: 0;
}
&.expand {
text-align: right;
}
&.isClickable {
border-bottom: 2px solid transparent;
cursor: pointer;
}
&.mini {
padding: 0 !important;
}
&.no-pad-left {
padding-left: 0.125rem;
}
&.no-pad-right {
padding-right: 0.125rem;
}
&.start {
text-align: left;
}
}
tr {
background: var(--bg-table);
text-transform: lowercase;
&:first-child {
th {
border-top: 1px solid var(--border-table);
}
}
&.filter {
.ui.input {
background: transparent;
&:first-child {
margin-top: -1px;
}
}
th {
padding: 0;
}
}
&:not(.filter) {
th {
color: var(--color-table-head);
}
}
}
`);