diff --git a/packages/page-accounts/src/Accounts/Account.tsx b/packages/page-accounts/src/Accounts/Account.tsx index e61a37cb40..291ad1ed90 100644 --- a/packages/page-accounts/src/Accounts/Account.tsx +++ b/packages/page-accounts/src/Accounts/Account.tsx @@ -723,7 +723,7 @@ function Account ({ account: { address, meta }, className = '', delegation, filt - + ("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('No accounts')} header={header[key]} key={key} - withCollapsibleRows > {grouped[key].map((a) => accountComponents[a])} diff --git a/packages/page-addresses/src/Contacts/Address.tsx b/packages/page-addresses/src/Contacts/Address.tsx index 57bdc7532c..37e5d658f6 100644 --- a/packages/page-addresses/src/Contacts/Address.tsx +++ b/packages/page-addresses/src/Contacts/Address.tsx @@ -252,7 +252,7 @@ function Address ({ address, className = '', filter, isFavorite, toggleFavorite - + ('no addresses saved yet, add any existing address')} header={headerRef.current} - withCollapsibleRows > {!isLoading && sortedAddresses?.map(({ address, isFavorite }): React.ReactNode => (
('No open bounties')} header={headerRef.current} - withCollapsibleRows > {sorted && info.bestNumber && sorted.map(({ bounty, description, index, proposals }) => ( - + | null { className={className} empty={external === null && t('No external proposal')} header={headerRef.current} - withCollapsibleRows > {external && } diff --git a/packages/page-democracy/src/Overview/Proposal.tsx b/packages/page-democracy/src/Overview/Proposal.tsx index 3e1acd9bb2..84b1ea40df 100644 --- a/packages/page-democracy/src/Overview/Proposal.tsx +++ b/packages/page-democracy/src/Overview/Proposal.tsx @@ -88,7 +88,7 @@ function Proposal ({ className = '', value: { balance, image, imageHash, index, className='columar' colSpan={100} > - + { className={className} empty={proposals && t('No active proposals')} header={headerRef.current} - withCollapsibleRows > {proposals?.map((proposal): React.ReactNode => ( - + ('No active referendums')} header={headerRef.current} - withCollapsibleRows > {referendums?.map((referendum): React.ReactNode => ( {referenda && referenda.map((r) => ( ('No available nomination pools')} emptySpinner={t('Retrieving nomination pools')} header={header} - withCollapsibleRows > {membersMap && filtered && filtered.map((poolId) => ( ); } -function Columar ({ children, className = '', is60, isFull, isPadded = true }: Props): React.ReactElement { +function Columar ({ children, className = '', is60, is100, isPadded = true }: Props): React.ReactElement { return ( -
+
{children}
); } 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; diff --git a/packages/react-components/src/Table/index.tsx b/packages/react-components/src/Table/index.tsx index 3083af973c..c0d71d55a0 100644 --- a/packages/react-components/src/Table/index.tsx +++ b/packages/react-components/src/Table/index.tsx @@ -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 { +function Table ({ children, className = '', empty, emptySpinner, filter, footer, header, headerChildren, isFixed, isInline, isSplit, legend, noBodyTag }: TableProps): React.ReactElement { 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 = ( + + {headerChildren} + + ); + return ( -
+
{legend} - - - {headerChildren} - - - {bodyChildren} - - -
+ {splitBody + ? ( + <> + + {headerNode} +
+ + + + + {splitBody[0]} + +
+
+ + + + {splitBody[1]} + +
+
+
+ + ) + : ( + + {headerNode} + + {bodyChildren} + + +
+ ) + }
); } @@ -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;