Style tags (#5893)

* Style tags

* Style Input tags

* Change delete tag icon

* Update colors

* Style flags

* Apply review suggestions

Co-authored-by: Ewa Kowalska <ewcia.kowalska@gmail.com>
This commit is contained in:
MiZiet 2021-08-14 09:10:21 +02:00 committed by GitHub
parent d81285b4ee
commit 5c1f6729bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 215 additions and 156 deletions

View File

@ -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.",

View File

@ -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<Props> | null {
function Flags ({ className = '', flags: { isCouncil, isDevelopment, isExternal, isInjected, isMultisig, isNominator, isProxied, isSociety, isSudo, isTechCommittee, isValidator } }: Props): React.ReactElement<Props> | 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 (
<div className='ui--AddressMenu-flags'>
{isValidator && (
<Tag
color='theme'
label={t<string>('Validator')}
size='tiny'
/>
)}
{isNominator && (
<Tag
color='theme'
label={t<string>('Nominator')}
size='tiny'
/>
)}
{isExternal && (
isMultisig
? (
<Tag
color='green'
label={t<string>('Multisig')}
size='tiny'
/>
)
: isProxied
<div className={`${className} ui--AddressMenu-flags`}>
{
hasFlags && (
<h5>{t<string>('Flags')}</h5>
)
}
<div>
{isValidator && (
<Tag
color='theme'
label={t<string>('Validator')}
size='tiny'
/>
)}
{isNominator && (
<Tag
color='theme'
label={t<string>('Nominator')}
size='tiny'
/>
)}
{isExternal && (
isMultisig
? (
<Tag
color='grey'
label={t<string>('External')}
color='green'
label={t<string>('Multisig')}
size='tiny'
/>
)
: (
<Tag
color='grey'
label={t<string>('External')}
size='tiny'
/>
)
)}
{isInjected && (
<Tag
color='grey'
label={t<string>('Injected')}
size='tiny'
/>
)}
{isDevelopment && (
<Tag
color='grey'
label={t<string>('Test account')}
size='tiny'
/>
)}
{isCouncil && (
<Tag
color='blue'
label={t<string>('Council')}
size='tiny'
/>
)}
{isSociety && (
<Tag
color='green'
label={t<string>('Society')}
size='tiny'
/>
)}
{isTechCommittee && (
<Tag
color='orange'
label={t<string>('Technical committee')}
size='tiny'
/>
)}
{isSudo && (
<Tag
color='pink'
label={t<string>('Sudo key')}
size='tiny'
/>
)}
: isProxied
? (
<Tag
color='grey'
label={t<string>('External')}
size='tiny'
/>
)
: (
<Tag
color='grey'
label={t<string>('External')}
size='tiny'
/>
)
)}
{isInjected && (
<Tag
color='grey'
label={t<string>('Injected')}
size='tiny'
/>
)}
{isDevelopment && (
<Tag
color='grey'
label={t<string>('Test account')}
size='tiny'
/>
)}
{isCouncil && (
<Tag
color='blue'
label={t<string>('Council')}
size='tiny'
/>
)}
{isSociety && (
<Tag
color='green'
label={t<string>('Society')}
size='tiny'
/>
)}
{isTechCommittee && (
<Tag
color='orange'
label={t<string>('Technical committee')}
size='tiny'
/>
)}
{isSudo && (
<Tag
color='pink'
label={t<string>('Sudo key')}
size='tiny'
/>
)}
</div>
</div>
);
}
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;
}
`);

View File

@ -99,6 +99,7 @@ function FullSidebar ({ address, className = '', onClose, onUpdateName }: Props)
onToggleIsEditing={toggleIsEditingTags}
size='tiny'
value={tags}
withTitle
/>
</div>
<Flags flags={flags} />
@ -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;

View File

@ -16,10 +16,10 @@ interface Props {
onClick: () => void;
}
function EditButton ({ children, className, icon = 'edit', onClick }: Props): React.ReactElement<Props> {
function EditButton ({ children, className = '', icon = 'edit', onClick }: Props): React.ReactElement<Props> {
return (
<div
className={className}
className={`ui--EditButton ${className}`}
onClick={onClick}
>
{children}

View File

@ -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<Props> {
const { theme } = useContext<ThemeDef>(ThemeContext);
return (
<Dropdown
allowAdd={allowAdd && !isDisabled}
className={className}
className={`ui--InputTags ${theme}Theme ${className}`}
defaultValue={defaultValue}
help={help}
isDisabled={isDisabled}
@ -77,4 +82,28 @@ function InputTags ({ allowAdd = true, className = '', defaultValue, help, isDis
);
}
export default React.memo(InputTags);
export default React.memo(styled(InputTags)`
&& .ui.label {
border: none;
border-radius: 0.25rem;
box-shadow: none;
color: #fff;
display: inline-block;
font-size: 0.857rem;
font-weight: var(--font-weight-normal);
line-height: 1.143rem;
margin: 0.125rem 0.125rem;
padding: 0.571em 0.857em;
position: relative;
white-space: nowrap;
z-index: 1;
.delete.icon::before {
content: '\u2715';
}
}
&&.darkTheme .ui.label {
background-color: rgba(255, 255, 255, 0.08);
}
`);

View File

@ -1,8 +1,10 @@
// Copyright 2017-2021 @polkadot/react-components authors & contributors
// SPDX-License-Identifier: Apache-2.0
import React, { useState } from 'react';
import styled from 'styled-components';
import React, { useContext, useState } from 'react';
import styled, { ThemeContext } from 'styled-components';
import { ThemeDef } from '@polkadot/react-components/types';
import Tooltip from './Tooltip';
@ -10,14 +12,14 @@ interface Props {
className?: string;
color?: 'blue' | 'green' | 'grey' | 'orange' | 'pink' | 'red' | 'yellow' | 'theme';
hover?: React.ReactNode;
isTag?: boolean;
label: React.ReactNode;
size?: 'small' | 'tiny';
}
let tagId = 0;
function Tag ({ className = '', color = 'grey', hover, isTag = true, label, size = 'small' }: Props): React.ReactElement<Props> {
function Tag ({ className = '', color = 'theme', hover, label, size = 'small' }: Props): React.ReactElement<Props> {
const { theme } = useContext<ThemeDef>(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 (
<div
className={`${color === 'theme' ? 'highlight--color-bg highlight--bg' : ''} ${color}Color${isTag ? ' isTag' : ''} ${size}Size ${className}`}
className={`ui--Tag ${color}Color ${size}Size ${theme}Theme ${className}`}
color={color || 'grey'}
{...tooltipProps}
>
@ -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;
}
}
`);

View File

@ -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<Props> {
function Tags ({ children, className = '', isEditable, isEditing, onChange, onSave, onToggleIsEditing, value, withTitle }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const contents = useMemo(
@ -45,6 +46,9 @@ function Tags ({ children, className = '', isEditable, isEditing, onChange, onSa
return (
<div className={`ui--Tags ${className}`}>
{withTitle && (
<h5>{t<string>('Tags')}</h5>
)}
{isEditable && isEditing
? (
<InputTags
@ -58,17 +62,14 @@ function Tags ({ children, className = '', isEditable, isEditing, onChange, onSa
withLabel={false}
/>
)
: (
<div className='tags--toggle'>
{isEditable
? (
<EditButton onClick={onToggleIsEditing}>
{contents}
</EditButton>
)
: contents}
</div>
)
: isEditable
? (
<EditButton className={value.length === 0 ? 'center' : 'left'}
onClick={onToggleIsEditing}>
{contents}
</EditButton>
)
: contents
}
{children}
</div>
@ -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;
}
`);

View File

@ -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<Props & ThemeProps>(({ theme, uiHighlight }: Props & ThemeProps) => `
.highlight--all {
background: ${getHighlight(uiHighlight)} !important;
@ -276,6 +286,17 @@ export default createGlobalStyle<Props & ThemeProps>(({ 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);