Remove classes utility (#4106)

* Remove classes utility

* Update packages/react-components/src/InputNumber.tsx
This commit is contained in:
Jaco Greeff 2020-11-30 16:01:37 +01:00 committed by GitHub
parent 1e5e584a99
commit ee25db733d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 42 additions and 100 deletions

View File

@ -8,7 +8,7 @@ import BN from 'bn.js';
import React from 'react';
import styled from 'styled-components';
import { classes, toShortAddress } from './util';
import { toShortAddress } from './util';
import AccountName from './AccountName';
import BalanceDisplay from './Balance';
import BondedDisplay from './Bonded';
@ -44,7 +44,7 @@ function AddressMini ({ balance, bonded, children, className = '', iconInfo, isH
}
return (
<div className={classes('ui--AddressMini', isHighlight ? 'isHighlight' : '', isPadded ? 'padded' : '', withShrink ? 'withShrink' : '', className)}>
<div className={`ui--AddressMini${isHighlight ? ' isHighlight' : ''}${isPadded ? ' padded' : ''}${withShrink ? ' withShrink' : ''} ${className}`}>
{label && (
<label className='ui--AddressMini-label'>{label}</label>
)}

View File

@ -6,8 +6,6 @@ import type { AccountId, AccountIndex, Address } from '@polkadot/types/interface
import React from 'react';
import { Available } from '@polkadot/react-query';
import { classes } from './util';
export interface Props {
className?: string;
label?: React.ReactNode;
@ -21,7 +19,7 @@ function AvailableDisplay ({ className = '', label, params }: Props): React.Reac
return (
<Available
className={classes('ui--Available', className)}
className={`ui--Available ${className}`}
label={label}
params={params}
/>

View File

@ -8,8 +8,6 @@ import React from 'react';
import { Balance, FormatBalance } from '@polkadot/react-query';
import { BN_ZERO } from '@polkadot/util';
import { classes } from './util';
export interface RenderProps {
className?: string;
label?: React.ReactNode;
@ -43,7 +41,7 @@ export function renderProvided ({ className = '', label, value }: RenderProps):
return (
<FormatBalance
className={classes('ui--Balance', className)}
className={`ui--Balance ${className}`}
label={label}
value={Array.isArray(value) ? value[0] : value}
>
@ -65,7 +63,7 @@ function BalanceDisplay (props: Props): React.ReactElement<Props> | null {
? <>{renderProvided({ className, label, value: balance })}</>
: (
<Balance
className={classes('ui--Balance', className)}
className={`ui--Balance ${className}`}
label={label}
params={params}
/>

View File

@ -8,7 +8,6 @@ import React from 'react';
import { Bonded } from '@polkadot/react-query';
import { renderProvided } from './Balance';
import { classes } from './util';
export interface Props {
bonded?: BN | BN[];
@ -29,7 +28,7 @@ function BondedDisplay (props: Props): React.ReactElement<Props> | null {
? <>{renderProvided({ className, label, value: bonded })}</>
: (
<Bonded
className={classes('ui--Bonded', className)}
className={`ui--Bonded ${className}`}
label={label}
params={params}
/>

View File

@ -12,7 +12,6 @@ import { FormatBalance } from '@polkadot/react-query';
import { GenericCall, getTypeDef } from '@polkadot/types';
import Static from './Static';
import { classes } from './util';
import { useTranslation } from './translate';
export interface Props {
@ -64,7 +63,7 @@ function Call ({ children, className = '', labelHash, mortality, onError, tip, v
}, [value, withHash]);
return (
<div className={classes('ui--Extrinsic', className)}>
<div className={`ui--Extrinsic ${className}`}>
<Params
isDisabled
onError={onError}

View File

@ -6,8 +6,6 @@ import type { BaseProps } from './types';
import React from 'react';
import styled from 'styled-components';
import { classes } from '../util';
const Wrapper = styled.div`
position: relative;
display: inline-block;
@ -18,7 +16,7 @@ const Wrapper = styled.div`
function BaseChart ({ children, className = '' }: BaseProps): React.ReactElement<BaseProps> {
return (
<Wrapper className={classes('ui--Chart', className)}>
<Wrapper className={`ui--Chart ${className}`}>
{children}
</Wrapper>
);

View File

@ -6,8 +6,6 @@ import type { AccountId, AccountIndex, Address } from '@polkadot/types/interface
import React, { useEffect, useState } from 'react';
import keyring from '@polkadot/ui-keyring';
import { classes } from './util';
interface Props {
accountId: AccountId | AccountIndex | Address | string | Uint8Array | null;
className?: string;
@ -44,7 +42,7 @@ function CryptoType ({ accountId, className = '', label = '' }: Props): React.Re
}, [accountId]);
return (
<div className={classes('ui--CryptoType', className)}>
<div className={`ui--CryptoType ${className}`}>
{label}{type}
</div>
);

View File

@ -7,7 +7,6 @@ import SUIButton from 'semantic-ui-react/dist/commonjs/elements/Button/Button';
import SUIDropdown, { DropdownProps } from 'semantic-ui-react/dist/commonjs/modules/Dropdown/Dropdown';
import { isUndefined } from '@polkadot/util';
import { classes } from './util';
import Labelled from './Labelled';
interface Props<Option> {
@ -112,7 +111,7 @@ function BaseDropdown<Option> ({ allowAdd = false, children, className = '', def
? <SUIButton.Group>{dropdown}{children}</SUIButton.Group>
: (
<Labelled
className={classes('ui--Dropdown', className)}
className={`ui--Dropdown ${className}`}
help={help}
isFull={isFull}
label={label}

View File

@ -10,7 +10,6 @@
import CodeFlask from 'codeflask';
import React, { useEffect, useRef, useState } from 'react';
import styled from 'styled-components';
import { classes } from '@polkadot/react-components/util';
interface Props {
className?: string;
@ -63,7 +62,7 @@ function Editor ({ className = '', code, isValid, onEdit }: Props): React.ReactE
return (
<div
className={classes('ui-Editor', className, isValid === false ? 'invalid' : '')}
className={`ui-Editor ${className}${isValid === false ? ' invalid' : ''}`}
id={editorId}
/>
);

View File

@ -12,7 +12,7 @@ import Params from '@polkadot/react-params';
import { getTypeDef } from '@polkadot/types';
import { useTranslation } from './translate';
import { classes, getContractAbi } from './util';
import { getContractAbi } from './util';
export interface Props {
children?: React.ReactNode;
@ -64,7 +64,7 @@ function EventDisplay ({ children, className = '', value }: Props): React.ReactE
);
return (
<div className={classes('ui--Event', className)}>
<div className={`ui--Event ${className}`}>
{children}
<Params
isDisabled

View File

@ -12,7 +12,7 @@ import keyring from '@polkadot/ui-keyring';
import createKeyringItem from '@polkadot/ui-keyring/options/item';
import { isNull, isUndefined } from '@polkadot/util';
import { classes, getAddressName } from '../util';
import { getAddressName } from '../util';
import addressToAddress from '../util/toAddress';
import Dropdown from '../Dropdown';
import createHeader from './createHeader';
@ -159,7 +159,7 @@ class InputAddress extends React.PureComponent<Props, State> {
return (
<Dropdown
className={classes('ui--InputAddress', hideAddress && 'hideAddress', className)}
className={`ui--InputAddress${hideAddress ? ' hideAddress' : ''} ${className}`}
defaultValue={_defaultValue}
help={help}
isDisabled={isDisabled}

View File

@ -7,7 +7,6 @@ import type { ConstValueBase } from './types';
import React from 'react';
import Dropdown from '../Dropdown';
import { classes } from '../util';
interface Props {
className?: string;
@ -37,7 +36,7 @@ function SelectKey (props: Props): React.ReactElement<Props> | null {
return (
<Dropdown
className={classes('ui--DropdownLinked-Items', className)}
className={`ui--DropdownLinked-Items ${className}`}
isError={isError}
onChange={onChange}
options={options}

View File

@ -7,7 +7,6 @@ import type { ConstValueBase, StorageEntryPromise } from './types';
import React from 'react';
import Dropdown from '../Dropdown';
import { classes } from '../util';
interface Props {
className?: string;
@ -21,7 +20,7 @@ interface Props {
function SelectSection ({ className = '', defaultValue, isError, onChange, options, value: { section } }: Props): React.ReactElement<Props> {
return (
<Dropdown
className={classes('ui--DropdownLinked-Sections', className)}
className={`ui--DropdownLinked-Sections ${className}`}
defaultValue={defaultValue}
isError={isError}
onChange={onChange}

View File

@ -4,8 +4,6 @@
import React from 'react';
import Label from 'semantic-ui-react/dist/commonjs/elements/Label/Label';
import { classes } from './util';
interface Props {
className?: string;
label?: React.ReactNode;
@ -17,7 +15,7 @@ const defaultLabel: React.ReactNode = (
function InputError ({ className = '', label = defaultLabel }: Props): React.ReactElement<Props> {
return (
<div className={classes('ui--InputError', className)}>
<div className={`ui--InputError ${className}`}>
<Label
color='red'
pointing='left'

View File

@ -8,7 +8,6 @@ import React, { useCallback } from 'react';
import { ApiPromise } from '@polkadot/api';
import Dropdown from '../Dropdown';
import { classes } from '../util';
interface Props {
api: ApiPromise;
@ -32,7 +31,7 @@ function SelectMethod ({ api, className = '', isError, onChange, options, value
return (
<Dropdown
className={classes('ui--DropdownLinked-Items', className)}
className={`ui--DropdownLinked-Items ${className}`}
isError={isError}
onChange={onChange}
options={options}

View File

@ -7,7 +7,6 @@ import type { DropdownOptions } from '../util/types';
import React from 'react';
import Dropdown from '../Dropdown';
import { classes } from '../util';
interface Props {
className?: string;
@ -21,7 +20,7 @@ interface Props {
function SelectSection ({ className = '', defaultValue, isError, onChange, options, value }: Props): React.ReactElement<Props> {
return (
<Dropdown
className={classes('ui--DropdownLinked-Sections', className)}
className={`ui--DropdownLinked-Sections ${className}`}
defaultValue={defaultValue}
isError={isError}
onChange={onChange}

View File

@ -10,7 +10,6 @@ import styled from 'styled-components';
import { registry } from '@polkadot/react-api';
import { BN_ZERO, BN_TEN, formatBalance, isBn } from '@polkadot/util';
import { classes } from './util';
import { BitLengthOption } from './constants';
import Dropdown from './Dropdown';
import Input, { KEYS_PRE } from './Input';
@ -251,7 +250,7 @@ function InputNumber ({ autoFocus, bitLength = DEFAULT_BITLENGTH, children, clas
return (
<Input
autoFocus={autoFocus}
className={classes('ui--InputNumber', isDisabled && 'isDisabled', className)}
className={`ui--InputNumber${isDisabled ? ' isDisabled' : ''} ${className}`}
help={help}
isAction={isSi}
isDisabled={isDisabled}

View File

@ -8,7 +8,6 @@ import React, { useCallback } from 'react';
import Dropdown from '../Dropdown';
import rpcs from './rpcs';
import { classes } from '../util';
interface Props {
className?: string;
@ -30,7 +29,7 @@ function SelectMethod ({ className = '', isError, onChange, options, value }: Pr
return (
<Dropdown
className={classes('ui--DropdownLinked-Items', className)}
className={`ui--DropdownLinked-Items ${className}`}
isError={isError}
onChange={onChange}
options={options}

View File

@ -7,7 +7,6 @@ import type { DropdownOptions } from '../util/types';
import React from 'react';
import Dropdown from '../Dropdown';
import { classes } from '../util';
interface Props {
className?: string;
@ -21,7 +20,7 @@ interface Props {
function SelectSection ({ className = '', defaultValue, isError, onChange, options, value }: Props): React.ReactElement<Props> {
return (
<Dropdown
className={classes('ui--DropdownLinked-Sections', className)}
className={`ui--DropdownLinked-Sections ${className}`}
defaultValue={defaultValue}
isError={isError}
onChange={onChange}

View File

@ -9,7 +9,6 @@ import { ApiPromise } from '@polkadot/api';
import { useApi } from '@polkadot/react-hooks';
import Dropdown from '../Dropdown';
import { classes } from '../util';
interface Props {
className?: string;
@ -38,7 +37,7 @@ function SelectKey (props: Props): React.ReactElement<Props> | null {
return (
<Dropdown
className={classes('ui--DropdownLinked-Items', className)}
className={`ui--DropdownLinked-Items ${className}`}
isError={isError}
onChange={onChange}
options={options}

View File

@ -7,7 +7,6 @@ import type { DropdownOptions } from '../util/types';
import React from 'react';
import Dropdown from '../Dropdown';
import { classes } from '../util';
interface Props {
className?: string;
@ -21,7 +20,7 @@ interface Props {
function SelectSection ({ className = '', defaultValue, isError, onChange, options, value: { creator: { section } } }: Props): React.ReactElement<Props> {
return (
<Dropdown
className={classes('ui--DropdownLinked-Sections', className)}
className={`ui--DropdownLinked-Sections ${className}`}
defaultValue={defaultValue}
isError={isError}
onChange={onChange}

View File

@ -7,7 +7,6 @@ import styled from 'styled-components';
import { useToggle } from '@polkadot/react-hooks';
import Icon from './Icon';
import { classes } from './util';
export interface InsetProps {
className?: string;
@ -38,18 +37,7 @@ function Inset ({ children, className = '', header, href, isCollapsible, isError
return (
<div
className={
classes(
'ui--Inset',
href && 'as-link',
isCollapsible && 'collapsible',
(isError && !isSuccess) && 'error',
(!isError && isSuccess) && 'success',
withBottomMargin && 'bottom-margin',
withTopMargin && 'top-margin',
className
)
}
className={`ui--Inset ${href ? ' as-link' : ''}${isCollapsible ? ' collapsible' : ''}${(isError && !isSuccess) ? ' error' : ''}${(!isError && isSuccess) ? ' success' : ''}${withBottomMargin ? ' bottom-margin' : ''}${withTopMargin ? ' top-margin' : ''} ${className}`}
>
{isCollapsible && (
<div
@ -58,13 +46,13 @@ function Inset ({ children, className = '', header, href, isCollapsible, isError
>
<h3>{header}</h3>
<Icon
className={classes(isCollapsed && 'collapsed')}
className={isCollapsed ? 'collapsed' : ''}
icon='angle-up'
/>
</div>
)}
<div
className={classes('children', (isCollapsible && isCollapsed) && 'collapsed')}
className={`children${(isCollapsible && isCollapsed) ? ' collapsed' : ''}`}
onClick={_onClick}
>
{children}

View File

@ -6,7 +6,6 @@ import React, { useState } from 'react';
import styled from 'styled-components';
import Icon from './Icon';
import { classes } from './util';
import Tooltip from './Tooltip';
interface Props {
@ -21,7 +20,7 @@ function LabelHelp ({ className = '', help, icon = 'question-circle' }: Props):
const [trigger] = useState(`label-help-${++id}`);
return (
<div className={classes('ui--LabelHelp', className)}>
<div className={`ui--LabelHelp ${className}`}>
<Icon
icon={icon}
tooltip={trigger}

View File

@ -6,8 +6,6 @@ import type { AccountId, AccountIndex, Address } from '@polkadot/types/interface
import React from 'react';
import { LockedVote } from '@polkadot/react-query';
import { classes } from './util';
export interface Props {
className?: string;
label?: React.ReactNode;
@ -15,16 +13,14 @@ export interface Props {
withLabel?: boolean;
}
function LockedVoteDisplay (props: Props): React.ReactElement<Props> | null {
const { className = '', label, params } = props;
function LockedVoteDisplay ({ className = '', label, params }: Props): React.ReactElement<Props> | null {
if (!params) {
return null;
}
return (
<LockedVote
className={classes('ui--LockedVote', className)}
className={`ui--LockedVote ${className}`}
label={label}
params={params}
/>

View File

@ -6,8 +6,6 @@ import type { AccountId, AccountIndex, Address } from '@polkadot/types/interface
import React from 'react';
import { Nonce } from '@polkadot/react-query';
import { classes } from './util';
export interface Props {
className?: string;
label?: React.ReactNode;
@ -21,7 +19,7 @@ function NonceDisplay ({ className = '', label, params }: Props): React.ReactEle
return (
<Nonce
className={classes('ui--Nonce', className)}
className={`ui--Nonce ${className}`}
label={label}
params={params.toString()}
/>

View File

@ -6,7 +6,6 @@ import styled from 'styled-components';
import CopyButton from './CopyButton';
import Labelled from './Labelled';
import { classes } from './util';
interface Props {
children?: React.ReactNode;
@ -37,7 +36,7 @@ function Output ({ children, className = '', help, isError, isFull, isHidden, is
labelExtra={labelExtra}
withLabel={withLabel}
>
<div className={classes('ui--output', isError && 'error', isMonospace && 'monospace')}>
<div className={`ui--output}${isError ? ' error' : ''}${isMonospace ? ' monospace' : ''}`}>
{isTrimmed && value && (value.length > 256)
? `${value.substr(0, 96)}…${value.substr(-96)}`
: value

View File

@ -5,7 +5,6 @@ import React from 'react';
import styled from 'styled-components';
import { useToggle } from '@polkadot/react-hooks';
import { classes } from './util';
import EditButton from './EditButton';
import Input from './Input';
import Tags from './Tags';
@ -167,7 +166,7 @@ export interface RowProps {
tags?: string[];
}
function Row ({ address, buttons, children, className, defaultName, details, icon, iconInfo, isDisabled, isEditableName, isEditableTags, isInline, name, onChangeName, onChangeTags, onSaveName, onSaveTags, tags }: RowProps): React.ReactElement<RowProps> {
function Row ({ address, buttons, children, className = '', defaultName, details, icon, iconInfo, isDisabled, isEditableName, isEditableTags, isInline, name, onChangeName, onChangeTags, onSaveName, onSaveTags, tags }: RowProps): React.ReactElement<RowProps> {
const [isEditingName, toggleIsEditingName] = useToggle();
const [isEditingTags, toggleIsEditingTags] = useToggle();
@ -178,7 +177,7 @@ function Row ({ address, buttons, children, className, defaultName, details, ico
return (
<div
className={classes('ui--Row', isDisabled && 'isDisabled', isInline && 'isInline', className)}
className={`ui--Row${isDisabled ? ' isDisabled' : ''}${isInline ? ' isInline' : ''} ${className}`}
>
<div className='ui--Row-base'>
{icon && (

View File

@ -12,7 +12,6 @@ import Button from '../Button';
import Icon from '../Icon';
import Spinner from '../Spinner';
import { useTranslation } from '../translate';
import { classes } from '../util';
import StatusContext from './Context';
import { STATUS_COMPLETE } from './constants';
@ -70,7 +69,7 @@ function signerIconName (status: QueueTxStatus): IconName {
function renderStatus ({ account, action, id, message, removeItem, status }: QueueStatus): React.ReactNode {
return (
<div
className={classes('item', status)}
className={`item ${status}`}
key={id}
>
<div className='wrapper'>
@ -117,7 +116,7 @@ function renderItem ({ error, extrinsic, id, removeItem, rpc, status }: QueueTx)
return (
<div
className={classes('item', status)}
className={`item ${status}`}
key={id}
>
<div className='wrapper'>

View File

@ -5,7 +5,6 @@ import type { VoidFn } from './types';
import React, { useCallback, useMemo } from 'react';
import styled from 'styled-components';
import { classes } from './util';
import EditButton from './EditButton';
import InputTags from './InputTags';
@ -24,7 +23,7 @@ interface Props {
value: string[];
}
function Tags ({ children, className, isEditable, isEditing, onChange, onSave, onToggleIsEditing, value }: Props): React.ReactElement<Props> {
function Tags ({ children, className = '', isEditable, isEditing, onChange, onSave, onToggleIsEditing, value }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const contents = useMemo(
@ -48,7 +47,7 @@ function Tags ({ children, className, isEditable, isEditing, onChange, onSave, o
);
return (
<div className={classes('ui--Tags', className)}>
<div className={`ui--Tags ${className}`}>
{isEditable && isEditing
? (
<InputTags

View File

@ -1,8 +0,0 @@
// Copyright 2017-2020 @polkadot/react-components authors & contributors
// SPDX-License-Identifier: Apache-2.0
export default function classes (...classNames: (boolean | null | string | undefined)[]): string {
return classNames
.filter((className): boolean => !!className)
.join(' ');
}

View File

@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
export { default as checkVisibility } from './checkVisibility';
export { default as classes } from './classes';
export { default as getAddressMeta } from './getAddressMeta';
export { default as getAddressName } from './getAddressName';
export { default as getAddressTags } from './getAddressTags';

View File

@ -3,7 +3,6 @@
import React from 'react';
import styled from 'styled-components';
import { classes } from '@polkadot/react-components/util';
interface Props {
children?: React.ReactNode;
@ -12,7 +11,7 @@ interface Props {
function Bare ({ children, className = '' }: Props): React.ReactElement<Props> {
return (
<div className={classes('ui--row', className)}>
<div className={`ui--row ${className}`}>
{children}
</div>
);

View File

@ -4,7 +4,6 @@
import type { Props, Props as CProps } from '../types';
import React, { useMemo, useRef } from 'react';
import { classes } from '@polkadot/react-components/util';
import { encodeTypeDef } from '@polkadot/types/create';
import { isUndefined } from '@polkadot/util';
@ -35,7 +34,7 @@ function Param ({ className = '', defaultValue, isDisabled, isInOption, isOption
)
: (
<compRef.current
className={classes('ui--Param', className)}
className={`ui--Param ${className}`}
defaultValue={defaultValue}
isDisabled={isDisabled}
isInOption={isInOption}

View File

@ -5,7 +5,6 @@ import type { Keys, ValidatorId } from '@polkadot/types/interfaces';
import type { Codec } from '@polkadot/types/types';
import React from 'react';
import { classes } from '@polkadot/react-components/util';
import { Option, Raw } from '@polkadot/types';
import { isFunction, isNull, isUndefined, u8aToHex } from '@polkadot/util';
@ -17,7 +16,7 @@ interface DivProps {
function div ({ className = '', key }: DivProps, ...values: React.ReactNode[]): React.ReactNode {
return (
<div
className={classes('ui--Param-text', className)}
className={`ui--Param-text ${className}`}
key={key}
>
{values}