From 41d6303f6f37fa4183b979ce49243461c901f849 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 12 Aug 2020 09:39:50 +0200 Subject: [PATCH] Adjust table consistency (#3397) * Adjust table consistency * Header transparent * Non-transparent summary --- packages/page-staking/src/Slashes/Era.tsx | 53 +++++++++++++++++++ .../src/Slashes/{Header.tsx => Summary.tsx} | 0 packages/page-staking/src/Slashes/index.tsx | 36 ++----------- packages/react-components/src/Table/Body.tsx | 13 +++-- packages/react-components/src/Table/Head.tsx | 8 ++- packages/react-components/src/Table/index.tsx | 14 +---- 6 files changed, 73 insertions(+), 51 deletions(-) create mode 100644 packages/page-staking/src/Slashes/Era.tsx rename packages/page-staking/src/Slashes/{Header.tsx => Summary.tsx} (100%) diff --git a/packages/page-staking/src/Slashes/Era.tsx b/packages/page-staking/src/Slashes/Era.tsx new file mode 100644 index 0000000000..3aecc66938 --- /dev/null +++ b/packages/page-staking/src/Slashes/Era.tsx @@ -0,0 +1,53 @@ +// Copyright 2017-2020 @polkadot/app-staking authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import { SlashEra } from './types'; + +import React, { useMemo } from 'react'; +import { Table } from '@polkadot/react-components'; + +import { useTranslation } from '../translate'; +import Row from './Row'; +import Summary from './Summary'; + +interface Props { + slash: SlashEra; +} + +function Slashes ({ slash }: Props): React.ReactElement | null { + const { t } = useTranslation(); + const header = useMemo((): [string?, string?, number?][] => [ + [undefined, 'start', 3], + [t('reporters'), 'address'], + [t('own')], + [t('other')], + [t('total')], + [t('payout')] + ], [t]); + + return ( + + + + {header.map(([label, className, colSpan = 1], index): React.ReactNode => ( + + ))} + + {slash.slashes.map((slash, index): React.ReactNode => ( + + ))} +
+ +
+ ); +} + +export default React.memo(Slashes); diff --git a/packages/page-staking/src/Slashes/Header.tsx b/packages/page-staking/src/Slashes/Summary.tsx similarity index 100% rename from packages/page-staking/src/Slashes/Header.tsx rename to packages/page-staking/src/Slashes/Summary.tsx diff --git a/packages/page-staking/src/Slashes/index.tsx b/packages/page-staking/src/Slashes/index.tsx index f81c6028a4..f92a0209c8 100644 --- a/packages/page-staking/src/Slashes/index.tsx +++ b/packages/page-staking/src/Slashes/index.tsx @@ -11,8 +11,7 @@ import React, { useMemo } from 'react'; import { Table } from '@polkadot/react-components'; import { useTranslation } from '../translate'; -import Header from './Header'; -import Row from './Row'; +import Era from './Era'; interface Props { ownStashes?: StakerState[]; @@ -86,14 +85,6 @@ function calcSlashEras (slashes: [BN, UnappliedSlash[]][], ownStashes: StakerSta function Slashes ({ ownStashes = [], slashes }: Props): React.ReactElement | null { const { t } = useTranslation(); - const header = useMemo((): [string?, string?, number?][] => [ - [undefined, 'start', 3], - [t('reporters'), 'address'], - [t('own')], - [t('other')], - [t('total')], - [t('payout')] - ], [t]); const rows = useMemo(() => calcSlashEras(slashes, ownStashes), [ownStashes, slashes]); if (!rows.length) { @@ -108,29 +99,10 @@ function Slashes ({ ownStashes = [], slashes }: Props): React.ReactElement {rows.map((slash): React.ReactNode => ( - -
-
- {header.map(([label, className, colSpan = 1], index): React.ReactNode => ( - - ))} - - {slash.slashes.map((slash, index): React.ReactNode => ( - - ))} -
- -
+ slash={slash} + /> ))} ); diff --git a/packages/react-components/src/Table/Body.tsx b/packages/react-components/src/Table/Body.tsx index c862c80988..38f0ae04df 100644 --- a/packages/react-components/src/Table/Body.tsx +++ b/packages/react-components/src/Table/Body.tsx @@ -30,8 +30,6 @@ function Body ({ children, className = '', empty, emptySpinner }: Props): React. } export default React.memo(styled(Body)` - background: white; - td { padding: 0.75rem 1rem; text-align: left; @@ -139,7 +137,11 @@ export default React.memo(styled(Body)` tr { &:nth-child(even) { - background: #f9f8f7; + background: #faf9f8; + } + + &:nth-child(odd) { + background: white; } &:first-child td { @@ -170,10 +172,13 @@ export default React.memo(styled(Body)` } } + &.transparent { + background: transparent; + } + .ui--Button:not(.isIcon):not(:hover) { background: transparent !important; box-shadow: none !important; - // color: #555 !important; } .ui.toggle.checkbox input:checked~.box:before, diff --git a/packages/react-components/src/Table/Head.tsx b/packages/react-components/src/Table/Head.tsx index f53f4786e6..452b89af3d 100644 --- a/packages/react-components/src/Table/Head.tsx +++ b/packages/react-components/src/Table/Head.tsx @@ -10,11 +10,15 @@ type HeaderDef = [React.ReactNode?, string?, number?, (() => void)?]; interface Props { className?: string; filter?: React.ReactNode; - header: (null | undefined | HeaderDef)[]; + header?: (null | undefined | HeaderDef)[]; isEmpty: boolean; } -function Head ({ className = '', filter, header, isEmpty }: Props): React.ReactElement { +function Head ({ className = '', filter, header, isEmpty }: Props): React.ReactElement | null { + if (!header?.length) { + return null; + } + return ( {filter && ( diff --git a/packages/react-components/src/Table/index.tsx b/packages/react-components/src/Table/index.tsx index c2cc929c33..bde3193f55 100644 --- a/packages/react-components/src/Table/index.tsx +++ b/packages/react-components/src/Table/index.tsx @@ -16,7 +16,7 @@ interface TableProps { emptySpinner?: React.ReactNode; filter?: React.ReactNode; footer?: React.ReactNode; - header: [React.ReactNode?, string?, number?, (() => void)?][]; + header?: [React.ReactNode?, string?, number?, (() => void)?][]; isFixed?: boolean; } @@ -76,18 +76,6 @@ export default React.memo(styled(Table)` max-width: 100%; width: 100%; - label { - opacity: 0.6; - } - - th label { - opacity: 1; - } - - &:hover label { - opacity: 1; - } - td, &:not(.filter) th { &:first-child { padding-left: 1.5rem;