From 783ca2c5c068f8f4b819de966898e6d381a5a1a0 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Sun, 2 Jun 2019 16:29:29 +0200 Subject: [PATCH] Some small -> styled-components conversions (#1262) * Combine AddressSummary & Row * Cleanup address rendering * Tiny tags cleanups * Remove unused ui--AddressSummary overrides * Column component * Columar * Cleanups * Remove hot client * Backport data padding * Some small -> styled-components conversions * Move RecebtlyOffline styles * Cleanups --- packages/ui-app/src/AddressMini.tsx | 55 +++++++- packages/ui-app/src/Bubble.tsx | 56 +++++++-- packages/ui-app/src/RecentlyOffline.tsx | 83 ++++++++---- packages/ui-app/src/Tooltip.tsx | 18 +-- packages/ui-app/src/styles/components.css | 147 ---------------------- 5 files changed, 166 insertions(+), 193 deletions(-) diff --git a/packages/ui-app/src/AddressMini.tsx b/packages/ui-app/src/AddressMini.tsx index 64e96727ce..22994838d7 100644 --- a/packages/ui-app/src/AddressMini.tsx +++ b/packages/ui-app/src/AddressMini.tsx @@ -6,6 +6,7 @@ import { BareProps } from './types'; import BN from 'bn.js'; import React from 'react'; +import styled from 'styled-components'; import { AccountId, AccountIndex, Address } from '@polkadot/types'; import { OfflineStatus } from '@polkadot/app-staking/types'; import { RecentlyOffline } from '@polkadot/ui-app'; @@ -28,7 +29,7 @@ type Props = BareProps & { withBonded?: boolean }; -export default class AddressMini extends React.PureComponent { +class AddressMini extends React.PureComponent { render () { const { children, className, isPadded = true, style, value } = this.props; @@ -128,3 +129,55 @@ export default class AddressMini extends React.PureComponent { ); } } + +export default styled(AddressMini)` + display: inline-block; + padding: 0 0.25rem 0 1rem; + white-space: nowrap; + + &.padded { + display: inline-block; + padding: 0.25rem 0 0 1rem; + } + + &.summary { + position: relative; + top: -0.2rem; + } + + .ui--AddressMini-address { + &.withAddr { + font-family: monospace; + } + + &.withName { + text-align: right; + text-transform: uppercase; + min-width: 4em; + } + } + + .ui--AddressMini-balances { + display: grid; + } + + .ui--AddressMini-balances .ui--Bonded.result-bonded, + .ui--AddressMini-balances .ui--Bonded { + font-size: .75rem; + margin-right: 2.25rem; + margin-top: -.5rem; + text-align: right; + } + + .ui--AddressMini-info, + .ui--IdentityIcon { + display: inline-block; + position:relative; + vertical-align: middle; + } + + .ui--IdentityIcon { + margin-left: 0.5rem; + margin-right: 0; + } +`; diff --git a/packages/ui-app/src/Bubble.tsx b/packages/ui-app/src/Bubble.tsx index f2d5ee0037..903cd5dd59 100644 --- a/packages/ui-app/src/Bubble.tsx +++ b/packages/ui-app/src/Bubble.tsx @@ -7,6 +7,7 @@ import { SemanticCOLORS, SemanticICONS } from 'semantic-ui-react/dist/commonjs/g import React from 'react'; import SUILabel from 'semantic-ui-react/dist/commonjs/elements/Label/Label'; +import styled from 'styled-components'; import settings from '@polkadot/ui-settings'; import { classes } from './util'; @@ -19,7 +20,7 @@ type Props = BareProps & { label?: React.ReactNode }; -export default class Bubble extends React.PureComponent { +class Bubble extends React.PureComponent { render () { const { color, children, className, icon, label } = this.props; @@ -29,16 +30,8 @@ export default class Bubble extends React.PureComponent { color={color} >
- { - icon - ? - : undefined - } - { - label - ?
{label}
- : undefined - } + {icon && } + {label &&
{label}
}
{children} @@ -47,3 +40,44 @@ export default class Bubble extends React.PureComponent { ); } } + +export default styled(Bubble)` + font-weight: normal; + margin: 0.25rem; + padding: 0; + + * { + vertical-align: middle; + } + + .ui--Bubble-children, + .ui--Bubble-header { + display: inline-block; + vertical-align: middle; + } + + .ui--Bubble-children { + padding: 0 0.75rem 0 0; + } + + .ui--Bubble-header { + background: rgba(0, 0, 0, 0.05); + box-sizing: border-box; + border-radius: .28571429rem 0 0 .28571429rem; + height: 2.75rem; + margin-right: 0.75rem; + padding: 0 0.75rem; + text-align: center; + vertical-align: middle; + + > div { + display: inline-block; + line-height: 2.75rem !important; + vertical-align: middle; + } + + > .text { + padding: 0 0 0 0.25rem; + } + } +`; diff --git a/packages/ui-app/src/RecentlyOffline.tsx b/packages/ui-app/src/RecentlyOffline.tsx index 2fdbf8ee20..d1b3bc2a76 100644 --- a/packages/ui-app/src/RecentlyOffline.tsx +++ b/packages/ui-app/src/RecentlyOffline.tsx @@ -7,11 +7,13 @@ import { OfflineStatus } from '@polkadot/app-staking/types'; import BN from 'bn.js'; import React from 'react'; +import styled from 'styled-components'; import { formatNumber } from '@polkadot/util'; import Tooltip from './Tooltip'; import translate from './translate'; +import { classes } from './util'; type Props = I18nProps & { accountId: AccountId | string, @@ -30,19 +32,10 @@ class RecentlyOffline extends React.PureComponent { }; render () { - const { offline, inline, tooltip = false, t } = this.props; + const { accountId, className, inline, offline, tooltip = false, t } = this.props; const { isOpen } = this.state; - const accountId = this.props.accountId.toString(); - const count = offline.reduce((total, { count }) => total.add(count), new BN(0)); const blockNumbers = offline.map(({ blockNumber }) => `#${formatNumber(blockNumber)}`); - - const tooltipData = { - 'data-for': `offline-${accountId}`, - 'data-tip': true, - 'data-tip-disable': !tooltip - }; - const text = t('Reported offline {{count}} times, last at {{blockNumber}}', { replace: { count, @@ -52,17 +45,11 @@ class RecentlyOffline extends React.PureComponent { return (
{count.toString()} @@ -85,4 +72,56 @@ class RecentlyOffline extends React.PureComponent { } } -export default translate(RecentlyOffline); +export default translate(styled(RecentlyOffline)` + background: red; + border-radius: 16px; + box-shadow: 0 3px 3px rgba(0, 0, 0, 0.2); + color: #eee; + cursor: help; + display: flex; + font-size: 12px; + height: 22px; + justify-content: center; + left: 1rem; + padding: 0; + position: absolute; + text-align: center; + top: 1rem; + transition: all ease .2s; + width: 22px; + + & > * { + line-height: 22px; + overflow: hidden; + transition: all ease 0.25; + } + + .badge { + font-weight: bold; + width: auto; + } + + .detail { + width: 0; + } + + &.expand { + width: 300px; + + .badge { + width: 0; + } + + .detail { + width: auto; + } + } + + &.inline { + left: auto; + position: absolute; + right: -2.75rem; + top: -1rem; + z-index: 1; + } +`); diff --git a/packages/ui-app/src/Tooltip.tsx b/packages/ui-app/src/Tooltip.tsx index 54ba7c11eb..95efae50f9 100644 --- a/packages/ui-app/src/Tooltip.tsx +++ b/packages/ui-app/src/Tooltip.tsx @@ -2,16 +2,17 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. +import { BareProps } from './types'; + import React from 'react'; import ReactDOM from 'react-dom'; import ReactTooltip from 'react-tooltip'; -import { BareProps } from './types'; +import { classes } from './util'; const rootElement = document.getElementById('tooltips'); type Props = BareProps & { - delayShow?: number, dataFor?: string, effect?: 'solid' | 'float' offset?: { bottom?: number, left?: number, right?: number, top?: number }, @@ -21,13 +22,6 @@ type Props = BareProps & { }; export default class Tooltip extends React.PureComponent { - static defaultProps = { - delayShow: 250, - effect: 'solid', - place: 'bottom', - className: 'ui--Tooltip' - }; - private tooltipContainer: HTMLElement; constructor (props: Props) { @@ -49,16 +43,16 @@ export default class Tooltip extends React.PureComponent { } render () { - const { className, delayShow, effect, offset, place, text, trigger } = this.props; + const { className, effect = 'solid', offset, place = 'bottom', text, trigger } = this.props; return ReactDOM.createPortal( {text} , diff --git a/packages/ui-app/src/styles/components.css b/packages/ui-app/src/styles/components.css index 3653404409..b9c0b808ea 100644 --- a/packages/ui-app/src/styles/components.css +++ b/packages/ui-app/src/styles/components.css @@ -43,46 +43,6 @@ header .ui--Button-Group { margin: 0; } -.ui--AddressMini { - display: inline-block; - padding: 0 0.25rem 0 1rem; - white-space: nowrap; - - &.padded { - display: inline-block; - padding: 0.25rem 0 0 1rem; - } - - &.summary { - position: relative; - top: -0.2rem; - } - - .ui--AddressMini-info, - .ui--IdentityIcon { - display: inline-block; - position:relative; - vertical-align: middle; - } - - .ui--IdentityIcon { - margin-left: 0.5rem; - margin-right: 0; - } -} - -.ui--AddressMini-address { - &.withAddr { - font-family: monospace; - } - - &.withName { - text-align: right; - text-transform: uppercase; - min-width: 4em; - } -} - button.ui.icon.iconButton { padding: 0em .3em .3em .3em !important; color: #2e86ab !important; @@ -97,59 +57,6 @@ button.ui.icon.iconButton { cursor: pointer; } -.ui--AddressMini-balances { - display: grid; -} - -.ui--AddressMini-balances .ui--Bonded.result-bonded, -.ui--AddressMini-balances .ui--Bonded { - font-size: .75rem; - margin-right: 2.25rem; - margin-top: -.5rem; - text-align: right; -} - -.ui--Bubble.ui.label { - font-weight: normal; - margin: 0.25rem; - padding: 0; - - * { - vertical-align: middle; - } - - .ui--Bubble-children, - .ui--Bubble-header { - display: inline-block; - vertical-align: middle; - } - - .ui--Bubble-children { - padding: 0 0.75rem 0 0; - } - - .ui--Bubble-header { - background: rgba(0, 0, 0, 0.05); - box-sizing: border-box; - border-radius: .28571429rem 0 0 .28571429rem; - height: 2.75rem; - margin-right: 0.75rem; - padding: 0 0.75rem; - text-align: center; - vertical-align: middle; - - > div { - display: inline-block; - line-height: 2.75rem !important; - vertical-align: middle; - } - - > .text { - padding: 0 0 0 0.25rem; - } - } -} - .ui--DropdownLinked.ui--row { .small .ui.selection.dropdown { min-width: 5rem; @@ -215,60 +122,6 @@ button.ui.icon.iconButton { } } -.ui--RecentlyOffline { - position: absolute; - font-size: 12px; - cursor: help; - display: flex; - justify-content: center; - left: 1rem; - width: 22px; - height: 22px; - padding: 0; - background: red; - color: #eee; - border-radius: 16px; - box-shadow: 0 3px 3px rgba(0, 0, 0, 0.2); - text-align: center; - top: 1rem; - transition: all ease .2s; - - & > * { - line-height: 22px; - overflow: hidden; - transition: all ease 0.25; - } - - .badge { - font-weight: bold; - width: auto; - } - - .detail { - width: 0; - } - - &.expand { - width: 300px; - - .badge { - width: 0; - } - - .detail { - width: auto; - } - } - - &.inline { - position: absolute; - left: auto; - right: -2.75rem; - top: -1rem; - z-index: 1; - } -} - .ui--Static { overflow: hidden; word-break: break-all;