From 5c1f6729bc61fe66959ab36565b4f8016de162d6 Mon Sep 17 00:00:00 2001 From: MiZiet <55240109+MiZiet@users.noreply.github.com> Date: Sat, 14 Aug 2021 09:10:21 +0200 Subject: [PATCH] Style tags (#5893) * Style tags * Style Input tags * Change delete tag icon * Update colors * Style flags * Apply review suggestions Co-authored-by: Ewa Kowalska --- .../public/locales/en/react-components.json | 1 + packages/page-accounts/src/Sidebar/Flags.tsx | 181 ++++++++++-------- .../page-accounts/src/Sidebar/Sidebar.tsx | 20 +- packages/react-components/src/EditButton.tsx | 4 +- packages/react-components/src/InputTags.tsx | 35 +++- packages/react-components/src/Tag.tsx | 53 ++--- packages/react-components/src/Tags.tsx | 56 ++++-- packages/react-components/src/styles/index.ts | 21 ++ 8 files changed, 215 insertions(+), 156 deletions(-) diff --git a/packages/apps/public/locales/en/react-components.json b/packages/apps/public/locales/en/react-components.json index a70e828d2c..52b5bc340e 100644 --- a/packages/apps/public/locales/en/react-components.json +++ b/packages/apps/public/locales/en/react-components.json @@ -14,6 +14,7 @@ "Retrieving data": "Retrieving data", "Select the account you wish to vote with. You can approve \"aye\" or deny \"nay\" the proposal.": "Select the account you wish to vote with. You can approve \"aye\" or deny \"nay\" the proposal.", "Submit": "Submit", + "Tags": "Tags", "The amount that is associated with this vote. This value is is locked for the duration of the vote.": "The amount that is associated with this vote. This value is is locked for the duration of the vote.", "This chain does not yet support atomic batch operations. This means that if the transaction gets executed and one of the operations do fail (due to invalid data or lack of available funds) some of the changes made may not be applied.": "This chain does not yet support atomic batch operations. This means that if the transaction gets executed and one of the operations do fail (due to invalid data or lack of available funds) some of the changes made may not be applied.", "This operation does not remove the history of the account from the chain, nor any associated funds from the account. The forget operation only limits your access to the account on this browser.": "This operation does not remove the history of the account from the chain, nor any associated funds from the account. The forget operation only limits your access to the account on this browser.", diff --git a/packages/page-accounts/src/Sidebar/Flags.tsx b/packages/page-accounts/src/Sidebar/Flags.tsx index c3ea9240a8..4f6a3e02f0 100644 --- a/packages/page-accounts/src/Sidebar/Flags.tsx +++ b/packages/page-accounts/src/Sidebar/Flags.tsx @@ -4,6 +4,7 @@ import type { AddressFlags } from '@polkadot/react-hooks/types'; import React from 'react'; +import styled from 'styled-components'; import { Tag } from '@polkadot/react-components'; @@ -11,9 +12,10 @@ import { useTranslation } from '../translate'; interface Props { flags: AddressFlags; + className?: string; } -function Flags ({ flags: { isCouncil, isDevelopment, isExternal, isInjected, isMultisig, isNominator, isProxied, isSociety, isSudo, isTechCommittee, isValidator } }: Props): React.ReactElement | null { +function Flags ({ className = '', flags: { isCouncil, isDevelopment, isExternal, isInjected, isMultisig, isNominator, isProxied, isSociety, isSudo, isTechCommittee, isValidator } }: Props): React.ReactElement | null { const { t } = useTranslation(); const hasFlags = isCouncil || isDevelopment || isExternal || isInjected || isMultisig || isProxied || isSociety || isSudo || isTechCommittee || isValidator || isNominator; @@ -22,90 +24,111 @@ function Flags ({ flags: { isCouncil, isDevelopment, isExternal, isInjected, isM } return ( -
- {isValidator && ( - ('Validator')} - size='tiny' - /> - )} - {isNominator && ( - ('Nominator')} - size='tiny' - /> - )} - {isExternal && ( - isMultisig - ? ( - ('Multisig')} - size='tiny' - /> - ) - : isProxied +
+ { + hasFlags && ( +
{t('Flags')}
+ ) + } +
+ {isValidator && ( + ('Validator')} + size='tiny' + /> + )} + {isNominator && ( + ('Nominator')} + size='tiny' + /> + )} + {isExternal && ( + isMultisig ? ( ('External')} + color='green' + label={t('Multisig')} size='tiny' /> ) - : ( - ('External')} - size='tiny' - /> - ) - )} - {isInjected && ( - ('Injected')} - size='tiny' - /> - )} - {isDevelopment && ( - ('Test account')} - size='tiny' - /> - )} - {isCouncil && ( - ('Council')} - size='tiny' - /> - )} - {isSociety && ( - ('Society')} - size='tiny' - /> - )} - {isTechCommittee && ( - ('Technical committee')} - size='tiny' - /> - )} - {isSudo && ( - ('Sudo key')} - size='tiny' - /> - )} + : isProxied + ? ( + ('External')} + size='tiny' + /> + ) + : ( + ('External')} + size='tiny' + /> + ) + )} + {isInjected && ( + ('Injected')} + size='tiny' + /> + )} + {isDevelopment && ( + ('Test account')} + size='tiny' + /> + )} + {isCouncil && ( + ('Council')} + size='tiny' + /> + )} + {isSociety && ( + ('Society')} + size='tiny' + /> + )} + {isTechCommittee && ( + ('Technical committee')} + size='tiny' + /> + )} + {isSudo && ( + ('Sudo key')} + size='tiny' + /> + )} +
); } -export default React.memo(Flags); +export default React.memo(styled(Flags)` + h5 { + text-align: left; + font-style: normal; + font-weight: var(--font-weight-bold); + font-size: 0.714rem; + line-height: 1rem; + text-transform: uppercase; + margin-bottom: 0.5rem; + } + + .ui--Tag { + margin: 0.1rem 0 0.1rem 0.571rem; + } +`); diff --git a/packages/page-accounts/src/Sidebar/Sidebar.tsx b/packages/page-accounts/src/Sidebar/Sidebar.tsx index d8e04e6e40..5a98e61740 100644 --- a/packages/page-accounts/src/Sidebar/Sidebar.tsx +++ b/packages/page-accounts/src/Sidebar/Sidebar.tsx @@ -99,6 +99,7 @@ function FullSidebar ({ address, className = '', onClose, onUpdateName }: Props) onToggleIsEditing={toggleIsEditingTags} size='tiny' value={tags} + withTitle />
@@ -249,19 +250,8 @@ export default React.memo(styled(FullSidebar)` margin: 0.75rem 0 0; } - .ui--AddressMenu-flags { - display: flex; - flex-wrap: wrap; - justify-content: flex-end; - - > * { - margin-bottom: 0.4rem; - - &:not(:first-child) { - margin-left: 1rem; - margin-right: 0; - } - } + .ui--AddressMenu-tags { + width: 100%; } .ui--AddressMenu-identityIcon { @@ -281,10 +271,6 @@ export default React.memo(styled(FullSidebar)` } } - .tags--toggle { - display: inline-block; - } - .inline-icon { cursor: pointer; margin: 0 0 0 0.5rem; diff --git a/packages/react-components/src/EditButton.tsx b/packages/react-components/src/EditButton.tsx index 14aa6b79fb..e7284183ab 100644 --- a/packages/react-components/src/EditButton.tsx +++ b/packages/react-components/src/EditButton.tsx @@ -16,10 +16,10 @@ interface Props { onClick: () => void; } -function EditButton ({ children, className, icon = 'edit', onClick }: Props): React.ReactElement { +function EditButton ({ children, className = '', icon = 'edit', onClick }: Props): React.ReactElement { return (
{children} diff --git a/packages/react-components/src/InputTags.tsx b/packages/react-components/src/InputTags.tsx index a130b839ee..65d0002865 100644 --- a/packages/react-components/src/InputTags.tsx +++ b/packages/react-components/src/InputTags.tsx @@ -1,8 +1,11 @@ // Copyright 2017-2021 @polkadot/react-components authors & contributors // SPDX-License-Identifier: Apache-2.0 -import React from 'react'; +import React, { useContext } from 'react'; import store from 'store'; +import styled, { ThemeContext } from 'styled-components'; + +import { ThemeDef } from '@polkadot/react-components/types'; import Dropdown from './Dropdown'; @@ -54,10 +57,12 @@ function onAddTag (value: string): void { } function InputTags ({ allowAdd = true, className = '', defaultValue, help, isDisabled, isError, label, onBlur, onChange, onClose, placeholder, searchInput, value, withLabel }: Props): React.ReactElement { + const { theme } = useContext(ThemeContext); + return ( { +function Tag ({ className = '', color = 'theme', hover, label, size = 'small' }: Props): React.ReactElement { + const { theme } = useContext(ThemeContext); const [trigger] = useState(() => `tag-hover-${Date.now()}-${tagId++}`); const tooltipProps = hover ? { 'data-for': trigger, 'data-tip': true } @@ -25,7 +27,7 @@ function Tag ({ className = '', color = 'grey', hover, isTag = true, label, size return (
@@ -44,15 +46,19 @@ export default React.memo(styled(Tag)` border-radius: 0.25rem; color: #fff; display: inline-block; - font-size: 0.78571429rem; + font-size: 0.857rem; font-weight: var(--font-weight-normal); - line-height: 1; + line-height: 1.143rem; margin: 0 0.125rem; - padding: 0.5833em 0.833em; + padding: 0.571em 0.857em; position: relative; white-space: nowrap; z-index: 1; + &.themeColor.darkTheme { + background-color: rgba(255,255,255,0.08); + } + &.tinySize { font-size: .71428571rem; } @@ -84,35 +90,4 @@ export default React.memo(styled(Tag)` &.yellowColor { background: darkgoldenrod; } - - &.isTag { - border-radius: 0 0.25rem 0.25rem 0; - padding-left: 1.5em; - padding-right: 1.25em; - - &:after { - background-color: #fff; - border-radius: 500rem; - content: ''; - left: -0.25em; - margin-top: -0.25em; - position: absolute; - width: 0.5em; - height: 0.5em; - top: 50%; - } - - &:before { - background-color: inherit; - background-image: none; - content: ''; - right: 100%; - width: 1.56em; - height: 1.56em; - position: absolute; - transform: translateY(-50%) translateX(50%) rotate(-45deg); - top: 50%; - transition: none; - } - } `); diff --git a/packages/react-components/src/Tags.tsx b/packages/react-components/src/Tags.tsx index 3a77e2295e..f673a13791 100644 --- a/packages/react-components/src/Tags.tsx +++ b/packages/react-components/src/Tags.tsx @@ -18,9 +18,10 @@ interface Props { onToggleIsEditing?: () => void; onSave?: () => void; value: string[]; + withTitle?: boolean; } -function Tags ({ children, className = '', isEditable, isEditing, onChange, onSave, onToggleIsEditing, value }: Props): React.ReactElement { +function Tags ({ children, className = '', isEditable, isEditing, onChange, onSave, onToggleIsEditing, value, withTitle }: Props): React.ReactElement { const { t } = useTranslation(); const contents = useMemo( @@ -45,6 +46,9 @@ function Tags ({ children, className = '', isEditable, isEditing, onChange, onSa return (
+ {withTitle && ( +
{t('Tags')}
+ )} {isEditable && isEditing ? ( ) - : ( -
- {isEditable - ? ( - - {contents} - - ) - : contents} -
- ) + : isEditable + ? ( + + {contents} + + ) + : contents } {children}
@@ -76,11 +77,34 @@ function Tags ({ children, className = '', isEditable, isEditing, onChange, onSa } export default React.memo(styled(Tags)` - .tags--toggle { - display: inline-block; + h5 { + font-style: normal; + font-weight: var(--font-weight-bold); + font-size: 0.714rem; + line-height: 1rem; + text-transform: uppercase; + margin-bottom: 0.5rem; + } - label { - display: inline-block !important; + label { + display: inline-block; + } + + .ui--EditButton { + display: flex; + align-items: center; + flex-wrap: wrap; + + &.center { + justify-content: center; + } + + &.left { + justify-content: left; } } + + .ui--Tag { + margin: 0.1rem 0 0.1rem 0.571rem; + } `); diff --git a/packages/react-components/src/styles/index.ts b/packages/react-components/src/styles/index.ts index 6cce02a72f..7cb5dc0882 100644 --- a/packages/react-components/src/styles/index.ts +++ b/packages/react-components/src/styles/index.ts @@ -53,6 +53,16 @@ function getMenuHoverContrast (uiHighlight: string | undefined): string { : 'rgba(255, 255, 255, 0.15)'; } +function hexToRGB (hex: string, alpha?: string) { + const r = parseInt(hex.slice(1, 3), 16); + const g = parseInt(hex.slice(3, 5), 16); + const b = parseInt(hex.slice(5, 7), 16); + + return alpha + ? `rgba(${r}, ${g}, ${b}, ${alpha})` + : `rgb(${r}, ${g}, ${b})`; +} + export default createGlobalStyle(({ theme, uiHighlight }: Props & ThemeProps) => ` .highlight--all { background: ${getHighlight(uiHighlight)} !important; @@ -276,6 +286,17 @@ export default createGlobalStyle(({ theme, uiHighlight }: Pr } } + .ui--Tag.themeColor.lightTheme, + .ui--InputTags.lightTheme .ui.label { + background: ${hexToRGB(getHighlight(uiHighlight), '0.08')} !important; + color: ${countBrightness(uiHighlight) > BRIGHTNESS ? '#424242' : getHighlight(uiHighlight)}; + } + + .ui--Tag.themeColor.darkTheme, + .ui--InputTags.darkTheme .ui.label { + color: ${countBrightness(uiHighlight) > BRIGHTNESS ? getHighlight(uiHighlight) : '#fff'}; + } + #root { background: var(--bg-page); color: var(--color-text);