ghost-portal/packages/react-components/src/Table/Head.tsx
Jaco 8fbcbf8ded
Adjust Popup theme imports (#8668)
* Adjust Popup theme imports

* Add useTheme to dedupe

* Table head opacity

* Adjust header opacity

* Mock for useTheme

* hail-mary adjustment

* Remove esm pkg dupes

* Popup theme provider

* Remove accounts type sorting

* Remove type sorting tests

* Adjust Accounts header inputs

* Balance summary media

* Rebuild i18n

* Adjust styles
2023-01-01 16:25:30 +02:00

176 lines
3.2 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';
import Icon from '../Icon';
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>
<Icon
className='highlight--color'
icon='dot-circle'
/>
{label}
</h1>
)
: isEmpty
? ''
: label
}
</th>
)}
</tr>
{children}
</thead>
);
}
export default React.memo(styled(Head)`
opacity: 0.85;
z-index: 1;
th {
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;
.ui--Icon {
font-size: 1rem;
margin-right: 0.5rem;
vertical-align: middle;
}
.sub {
display: inline-block;
font-size: 1rem;
padding-left: 1.5rem;
text-overflow: ellipsis;
}
}
&: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,
&.number {
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;
}
&.balances {
text-align: right;
padding-right: 2.25rem;
}
}
tr {
background: var(--bg-table);
text-transform: lowercase;
&:first-child {
th {
border-top: 1px solid var(--border-table);
}
}
&.filter {
.ui.input,
.ui.selection.dropdown {
background: transparent;
&:first-child {
margin-top: -1px;
}
}
th {
padding: 0;
}
}
&:not(.filter) {
th {
color: var(--color-table-head);
}
}
}
`);