Add isSplit on tables (unused) (#8659)

* Add isSplit on tables (unused)

* Remove unused styles
This commit is contained in:
Jaco 2022-12-31 12:18:12 +02:00 committed by GitHub
parent edf66416c6
commit af51568305
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 122 additions and 93 deletions

View File

@ -723,7 +723,7 @@ function Account ({ account: { address, meta }, className = '', delegation, filt
<tr className={`${className} ${isExpanded ? 'isExpanded' : 'isCollapsed'}`}>
<td />
<td className='columar'>
<Columar isFull>
<Columar is100>
<Columar.Column>
<LinkExternal
data={address}

View File

@ -349,7 +349,6 @@ function Overview ({ className = '', onStatusChange }: Props): React.ReactElemen
<Table
empty={!isLoading && sortedAccounts && t<string>("You don't have any accounts. Some features are currently hidden and will only become available once you have accounts.")}
header={header.accounts}
withCollapsibleRows
/>
)
: GROUP_ORDER.map((key) =>
@ -359,7 +358,6 @@ function Overview ({ className = '', onStatusChange }: Props): React.ReactElemen
empty={t<string>('No accounts')}
header={header[key]}
key={key}
withCollapsibleRows
>
{grouped[key].map((a) => accountComponents[a])}
</Table>

View File

@ -252,7 +252,7 @@ function Address ({ address, className = '', filter, isFavorite, toggleFavorite
<tr className={`${className} ${isExpanded ? 'isExpanded' : 'isCollapsed'}`}>
<td />
<td className='columar'>
<Columar isFull>
<Columar is100>
<Columar.Column>
<LinkExternal
data={address}

View File

@ -73,7 +73,6 @@ function Overview ({ className = '', onStatusChange }: Props): React.ReactElemen
<Table
empty={!isLoading && sortedAddresses && t<string>('no addresses saved yet, add any existing address')}
header={headerRef.current}
withCollapsibleRows
>
{!isLoading && sortedAddresses?.map(({ address, isFavorite }): React.ReactNode => (
<Address

View File

@ -42,7 +42,6 @@ function Bounties ({ className }: Props): React.ReactElement {
className='bounties-table-wrapper'
empty={sorted && t<string>('No open bounties')}
header={headerRef.current}
withCollapsibleRows
>
{sorted && info.bestNumber && sorted.map(({ bounty, description, index, proposals }) => (
<Bounty

View File

@ -61,7 +61,7 @@ function External ({ className = '', value: { image, imageHash, threshold } }: P
className='columar'
colSpan={100}
>
<Columar isFull>
<Columar is100>
<Columar.Column>
<LinkExternal
data={imageHash}

View File

@ -32,7 +32,6 @@ function Externals ({ className }: Props): React.ReactElement<Props> | null {
className={className}
empty={external === null && t<string>('No external proposal')}
header={headerRef.current}
withCollapsibleRows
>
{external && <External value={external} />}
</Table>

View File

@ -88,7 +88,7 @@ function Proposal ({ className = '', value: { balance, image, imageHash, index,
className='columar'
colSpan={100}
>
<Columar isFull>
<Columar is100>
<Columar.Column>
<LinkExternal
data={index}

View File

@ -32,7 +32,6 @@ function Proposals ({ className }: Props): React.ReactElement<Props> {
className={className}
empty={proposals && t<string>('No active proposals')}
header={headerRef.current}
withCollapsibleRows
>
{proposals?.map((proposal): React.ReactNode => (
<ProposalDisplay

View File

@ -177,7 +177,7 @@ function Referendum ({ className = '', value: { allAye, allNay, image, imageHash
className='columar'
colSpan={100}
>
<Columar isFull>
<Columar is100>
<Columar.Column>
<LinkExternal
data={index}

View File

@ -34,7 +34,6 @@ function Referendums ({ className = '', referendums }: Props): React.ReactElemen
className={className}
empty={referendums && t<string>('No active referendums')}
header={headerRef.current}
withCollapsibleRows
>
{referendums?.map((referendum): React.ReactNode => (
<Referendum

View File

@ -73,7 +73,6 @@ function Group ({ activeIssuance, className, isMember, members, palletReferenda,
header={header}
headerChildren={headerChildren}
key={key}
withCollapsibleRows
>
{referenda && referenda.map((r) => (
<Referendum

View File

@ -78,7 +78,6 @@ function Pools ({ className, ids, ownPools, params }: Props): React.ReactElement
empty={membersMap && filtered && t<string>('No available nomination pools')}
emptySpinner={t<string>('Retrieving nomination pools')}
header={header}
withCollapsibleRows
>
{membersMap && filtered && filtered.map((poolId) => (
<Pool

View File

@ -8,7 +8,7 @@ interface Props {
children: React.ReactNode;
className?: string;
is60?: boolean;
isFull?: boolean;
is100?: boolean;
isPadded?: boolean;
}
@ -29,44 +29,60 @@ function Column ({ children, className = '' }: Props): React.ReactElement<Props>
);
}
function Columar ({ children, className = '', is60, isFull, isPadded = true }: Props): React.ReactElement<Props> {
function Columar ({ children, className = '', is60, is100, isPadded = true }: Props): React.ReactElement<Props> {
return (
<div className={`ui--Columar ${isFull ? 'isFull' : is60 ? 'is60' : 'is50'} ${isPadded ? 'isPadded' : ''} ${className}`}>
<div className={`ui--Columar ${is100 ? 'is100' : (is60 ? 'is60' : 'is50')} ${isPadded ? 'isPadded' : ''} ${className}`}>
{children}
</div>
);
}
const ColumarStyled = React.memo(styled(Columar)`
&.isPadded .ui--Column {
&.isPadded > .ui--Column {
padding: 0 0.75rem;
}
> .ui--Column {
box-sizing: border-box;
max-width: 100%;
flex: 1 1;
margin: 0;
width: 100%;
&:first-child {
padding-left: 0;
}
&:last-child {
padding-right: 0;
}
}
@media (min-width: 1025px) {
display: flex;
flex-wrap: wrap;
&.is50 {
.ui--Column {
> .ui--Column {
max-width: 50%;
min-width: 50%;
}
}
&.is60 {
.ui--Column:first-child {
> .ui--Column:first-child {
max-width: 60%;
min-width: 60%;
}
.ui--Column:last-child {
> .ui--Column:last-child {
max-width: 40%;
min-width: 40%;
}
}
&.Full {
.ui--Column {
&.is100 {
> .ui--Column {
max-width: 100%;
min-width: 100%;
}
@ -74,20 +90,6 @@ const ColumarStyled = React.memo(styled(Columar)`
}
`) as unknown as ColumarType;
ColumarStyled.Column = React.memo(styled(Column)`
box-sizing: border-box;
max-width: 100%;
flex: 1 1;
margin: 0;
width: 100%;
&:first-child {
padding-left: 0;
}
&:last-child {
padding-right: 0;
}
`);
ColumarStyled.Column = Column;
export default ColumarStyled;

View File

@ -1,9 +1,10 @@
// Copyright 2017-2022 @polkadot/react-components authors & contributors
// SPDX-License-Identifier: Apache-2.0
import React from 'react';
import React, { useMemo } from 'react';
import styled from 'styled-components';
import Columar from '../Columar';
import Body from './Body';
import Foot from './Foot';
import Head from './Head';
@ -19,12 +20,12 @@ interface TableProps {
headerChildren?: React.ReactNode;
isFixed?: boolean;
isInline?: boolean;
isSplit?: boolean;
legend?: React.ReactNode;
noBodyTag?: boolean;
withCollapsibleRows: boolean;
}
function extractBodyChildren (children: React.ReactNode): [boolean, React.ReactNode] {
function extractBodyChildren (children: React.ReactNode): [boolean, React.ReactNode | React.ReactNode[]] {
if (!Array.isArray(children)) {
return [!children, children];
}
@ -35,32 +36,77 @@ function extractBodyChildren (children: React.ReactNode): [boolean, React.ReactN
return [isEmpty, isEmpty ? null : kids];
}
function Table ({ children, className = '', empty, emptySpinner, filter, footer, header, headerChildren, isFixed, isInline, legend, noBodyTag, withCollapsibleRows = false }: TableProps): React.ReactElement<TableProps> {
function Table ({ children, className = '', empty, emptySpinner, filter, footer, header, headerChildren, isFixed, isInline, isSplit, legend, noBodyTag }: TableProps): React.ReactElement<TableProps> {
const [isEmpty, bodyChildren] = extractBodyChildren(children);
const splitBody = useMemo(
(): [React.ReactNode[], React.ReactNode[]] | null => {
if (!isSplit || isEmpty || !Array.isArray(bodyChildren) || bodyChildren.length === 0) {
return null;
}
const half = Math.ceil(bodyChildren.length / 2);
return [bodyChildren.slice(0, half), bodyChildren.slice(half)];
},
[bodyChildren, isEmpty, isSplit]
);
const tableClassName = `${(isFixed && !isEmpty) ? 'isFixed' : 'isNotFixed'} ${isInline ? 'isInline' : ''}`;
const headerNode = (
<Head
filter={filter}
header={header}
isEmpty={isEmpty}
>
{headerChildren}
</Head>
);
return (
<div className={`ui--Table ${className}`}>
<div className={`ui--Table ${className} ${splitBody ? 'isSplit' : ''}`}>
{legend}
<table className={`${(isFixed && !isEmpty) ? 'isFixed' : 'isNotFixed'} ${isInline ? 'isInline' : ''} ${withCollapsibleRows ? 'withCollapsibleRows' : ''}`}>
<Head
filter={filter}
header={header}
isEmpty={isEmpty}
>
{headerChildren}
</Head>
<Body
empty={empty}
emptySpinner={emptySpinner}
noBodyTag={noBodyTag}
>
{bodyChildren}
</Body>
<Foot
footer={footer}
isEmpty={isEmpty}
/>
</table>
{splitBody
? (
<>
<table className={tableClassName}>
{headerNode}
</table>
<Columar isPadded={false}>
<Columar.Column>
<table className={tableClassName}>
<Body>
{splitBody[0]}
</Body>
</table>
</Columar.Column>
<Columar.Column>
<table className={tableClassName}>
<Body>
{splitBody[1]}
</Body>
</table>
</Columar.Column>
</Columar>
</>
)
: (
<table className={tableClassName}>
{headerNode}
<Body
empty={empty}
emptySpinner={emptySpinner}
noBodyTag={noBodyTag}
>
{bodyChildren}
</Body>
<Foot
footer={footer}
isEmpty={isEmpty}
/>
</table>
)
}
</div>
);
}
@ -69,6 +115,21 @@ export default React.memo(styled(Table)`
max-width: 100%;
width: 100%;
&.isSplit {
> table:first-child {
margin-bottom: 0;
}
> .ui--Columar {
margin-bottom: 1.5rem;
> .ui--Column > table {
// border width
margin-bottom: -0.125rem;
}
}
}
table {
border-spacing: 0;
max-width: 100%;
@ -86,18 +147,9 @@ export default React.memo(styled(Table)`
}
&.isInline {
// &.highlight--bg-faint,
// &.highlight--bg-faint::before {
// background: transparent;
// }
tbody tr {
// background: transparent;
td {
border-top-width: 1px;
padding: 0.25rem 0.75rem;
}
tbody tr td {
border-top-width: 1px;
padding: 0.25rem 0.75rem;
}
}
@ -128,22 +180,6 @@ export default React.memo(styled(Table)`
}
}
}
// &.withCollapsibleRows tbody tr {
// background-color: unset;
// &:nth-child(4n - 2),
// &:nth-child(4n - 3) {
// background-color: var(--bg-table);
// }
// }
// &:not(.withCollapsibleRows) tbody tr {
// &.isOdd,
// &:nth-child(odd):not(.isEven) {
// background: var(--bg-table);
// }
// }
}
tbody, thead {
@ -159,7 +195,7 @@ export default React.memo(styled(Table)`
position: relative;
td {
border-bottom: 0.125rem /* 1px */ solid var(--border-table);
border-bottom: 0.125rem solid var(--border-table);
padding: 0.5rem 1rem;
text-align: left;
vertical-align: middle;
@ -372,7 +408,7 @@ export default React.memo(styled(Table)`
&:last-child {
td {
border-bottom: /* 1px */ 0.125rem solid var(--border-table);
border-bottom: 0.125rem solid var(--border-table);
&:first-child {
border-bottom-left-radius: 0.25rem;