From 19103c9eb32c671fddd51e2123ca932a9621bf6e Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Sat, 14 Dec 2019 11:32:44 +0100 Subject: [PATCH] Basis IdentityInfo input component (#2048) --- .../react-params/src/Param/IdentityInfo.tsx | 185 ++++++++++++++++++ .../react-params/src/Param/findComponent.ts | 6 +- packages/react-params/src/translate.ts | 6 +- 3 files changed, 194 insertions(+), 3 deletions(-) create mode 100644 packages/react-params/src/Param/IdentityInfo.tsx diff --git a/packages/react-params/src/Param/IdentityInfo.tsx b/packages/react-params/src/Param/IdentityInfo.tsx new file mode 100644 index 0000000000..44ec4a01ea --- /dev/null +++ b/packages/react-params/src/Param/IdentityInfo.tsx @@ -0,0 +1,185 @@ +// Copyright 2017-2019 @polkadot/react-components 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 { Props } from '../types'; + +import React, { useEffect, useState } from 'react'; +import styled from 'styled-components'; +import { Input, Toggle } from '@polkadot/react-components'; + +import Bare from './Bare'; +import Struct from './Struct'; + +import { useTranslation } from '../translate'; + +interface WrapProps { + children: React.ReactNode; + onChange: (isChecked: boolean) => void; + value: boolean; +} + +function WrapToggle ({ children, onChange, value }: WrapProps): React.ReactElement { + const { t } = useTranslation(); + + return ( +
+ {children} + +
+ ); +} + +function IdentityInfo (props: Props): React.ReactElement { + const { className, isDisabled, onChange, style } = props; + + const { t } = useTranslation(); + const [hasDisplay, setHasDisplay] = useState(true); + const [hasEmail, setHasEmail] = useState(false); + const [hasImage, setHasImage] = useState(false); + const [hasLegal, setHasLegal] = useState(false); + const [hasPgp, setHasPgp] = useState(false); + const [hasRiot, setHasRiot] = useState(false); + const [hasWeb, setHasWeb] = useState(false); + const [valDisplay, setValDisplay] = useState(''); + const [valEmail, setValEmail] = useState(''); + const [valImage, setValImage] = useState(''); + const [valLegal, setValLegal] = useState(''); + const [valPgp, setValPgp] = useState(''); + const [valRiot, setValRiot] = useState(''); + const [valWeb, setValWeb] = useState(''); + + useEffect((): void => { + onChange && onChange({ + value: { + display: { [hasDisplay ? 'raw' : 'none']: hasDisplay ? valDisplay : null }, + email: { [hasEmail ? 'raw' : 'none']: hasEmail ? valEmail : null }, + image: { [hasImage ? 'raw' : 'none']: hasImage ? valImage : null }, + legal: { [hasLegal ? 'raw' : 'none']: hasLegal ? valLegal : null }, + riot: { [hasRiot ? 'raw' : 'none']: hasRiot ? valRiot : null }, + web: { [hasWeb ? 'raw' : 'none']: hasWeb ? valWeb : null }, + pgpFingerprint: hasPgp ? valPgp : null + }, + isValid: true + }); + }, [hasDisplay, hasEmail, hasImage, hasLegal, hasPgp, hasRiot, hasWeb, valDisplay, valEmail, valImage, valLegal, valPgp, valRiot, valWeb]); + + if (isDisabled) { + return ( + + ); + } + + return ( + + + '} + /> + + + '} + /> + + + '} + /> + + + '} + /> + + + '} + /> + + + '} + /> + + + '} + /> + + + ); +} + +export default styled(IdentityInfo)` + .toggle-Wrap { + position: relative; + + .toggle-Toggle { + position: absolute; + right: 3.5rem; + top: 0.5rem; + } + } +`; diff --git a/packages/react-params/src/Param/findComponent.ts b/packages/react-params/src/Param/findComponent.ts index 143c0d0173..6c15c205bc 100644 --- a/packages/react-params/src/Param/findComponent.ts +++ b/packages/react-params/src/Param/findComponent.ts @@ -18,10 +18,11 @@ import Code from './Code'; import Enum from './Enum'; import Hash256 from './Hash256'; import Hash512 from './Hash512'; -import Moment from './Moment'; -import Proposal from './Proposal'; +import IdentityInfo from './IdentityInfo'; import KeyValue from './KeyValue'; import KeyValueArray from './KeyValueArray'; +import Moment from './Moment'; +import Proposal from './Proposal'; import Null from './Null'; import Option from './Option'; import Raw from './Raw'; @@ -49,6 +50,7 @@ const components: ComponentMap = ([ { c: Enum, t: ['Enum'] }, { c: Hash256, t: ['BlockHash', 'CodeHash', 'Hash', 'H256', 'SeedOf'] }, { c: Hash512, t: ['H512', 'Signature'] }, + { c: IdentityInfo, t: ['IdentityInfo'] }, { c: KeyValue, t: ['KeyValue'] }, { c: KeyValueArray, t: ['Vec'] }, { c: Moment, t: ['Moment', 'MomentOf'] }, diff --git a/packages/react-params/src/translate.ts b/packages/react-params/src/translate.ts index 623d6a771d..41bb756717 100644 --- a/packages/react-params/src/translate.ts +++ b/packages/react-params/src/translate.ts @@ -2,6 +2,10 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { withTranslation } from 'react-i18next'; +import { useTranslation as useTranslationBase, UseTranslationResponse, withTranslation } from 'react-i18next'; + +export function useTranslation (): UseTranslationResponse { + return useTranslationBase('react-params'); +} export default withTranslation(['react-params']);