From 9ac3d6a09534c265624663dcb41239b1790ef001 Mon Sep 17 00:00:00 2001
From: MiZiet <55240109+MiZiet@users.noreply.github.com>
Date: Tue, 24 Aug 2021 11:14:34 +0200
Subject: [PATCH] Replace sui modal with a custom one (#5914)
* Remove SUI modal
* Update modal positioning
* Clean up imports
* Restore removed size
* Add tests for Modal component
* Add border radius to actions
* Disable global scroll
* Introduce ESC_KEYCODE const
* Arrange props
* Change components definitions
* Change styled components to functional
Co-authored-by: Jaco Greeff
---
.../src/Sidebar/RegistrarJudgement.tsx | 2 +-
packages/page-accounts/src/modals/Backup.tsx | 3 +-
.../page-accounts/src/modals/ChangePass.tsx | 3 +-
packages/page-accounts/src/modals/Create.tsx | 3 +-
.../page-accounts/src/modals/Delegate.tsx | 3 +-
packages/page-accounts/src/modals/Derive.tsx | 3 +-
.../page-accounts/src/modals/IdentityMain.tsx | 3 +-
.../page-accounts/src/modals/IdentitySub.tsx | 3 +-
packages/page-accounts/src/modals/Import.tsx | 3 +-
packages/page-accounts/src/modals/Ledger.tsx | 3 +-
.../src/modals/MultisigApprove.tsx | 3 +-
.../src/modals/MultisigCreate.tsx | 3 +-
.../page-accounts/src/modals/ProxiedAdd.tsx | 3 +-
.../src/modals/ProxyOverview.tsx | 3 +-
packages/page-accounts/src/modals/Qr.tsx | 3 +-
.../src/modals/RecoverAccount.tsx | 3 +-
.../page-accounts/src/modals/RecoverSetup.tsx | 3 +-
.../page-accounts/src/modals/Transfer.tsx | 3 +-
.../page-accounts/src/modals/Undelegate.tsx | 3 +-
packages/page-addresses/src/modals/Create.tsx | 7 +-
.../page-assets/src/Balances/Transfer.tsx | 3 +-
.../src/Overview/Create/Create.tsx | 3 +-
.../page-assets/src/Overview/Mint/Mint.tsx | 3 +-
.../src/BountyActions/AwardBounty.tsx | 3 +-
.../src/BountyActions/BountyAcceptCurator.tsx | 3 +-
.../BountyActions/BountyInitiateVoting.tsx | 3 +-
.../BountyActions/ProposeCuratorAction.tsx | 5 +-
packages/page-bounties/src/BountyCreate.tsx | 3 +-
.../BountyRejectCurator.tsx | 3 +-
.../src/BountyExtraActions/CloseBounty.tsx | 3 +-
.../ExtendBountyExpiryAction.tsx | 3 +-
.../src/BountyExtraActions/GiveUp.tsx | 3 +-
.../src/BountyExtraActions/SlashCurator.tsx | 3 +-
packages/page-contracts/src/Codes/Add.tsx | 7 +-
packages/page-contracts/src/Codes/Upload.tsx | 7 +-
packages/page-contracts/src/Contracts/Add.tsx | 7 +-
.../page-contracts/src/Contracts/Call.tsx | 2 +-
.../page-contracts/src/Contracts/Deploy.tsx | 7 +-
packages/page-contracts/src/RemoveABI.tsx | 2 +-
packages/page-council/src/Motions/Close.tsx | 3 +-
.../src/Motions/ProposeExternal.tsx | 3 +-
.../src/Motions/ProposeMotion.tsx | 3 +-
.../page-council/src/Motions/Slashing.tsx | 3 +-
packages/page-council/src/Motions/Voting.tsx | 3 +-
.../src/Overview/SubmitCandidacy.tsx | 2 +-
packages/page-council/src/Overview/Vote.tsx | 3 +-
.../page-democracy/src/Overview/Fasttrack.tsx | 3 +-
.../page-democracy/src/Overview/PreImage.tsx | 3 +-
.../page-democracy/src/Overview/Propose.tsx | 3 +-
.../page-democracy/src/Overview/Seconding.tsx | 3 +-
.../page-democracy/src/Overview/Voting.tsx | 3 +-
packages/page-gilt/src/Overview/BidAdd.tsx | 3 +-
packages/page-parachains/src/Auctions/Bid.tsx | 3 +-
.../src/Crowdloan/Contribute.tsx | 3 +-
.../page-parachains/src/Crowdloan/FundAdd.tsx | 3 +-
.../page-parachains/src/Crowdloan/Refund.tsx | 3 +-
.../src/Parathreads/RegisterId.tsx | 3 +-
.../src/Parathreads/RegisterThread.tsx | 3 +-
.../page-parachains/src/Proposals/Propose.tsx | 3 +-
packages/page-parachains/src/Teleport.tsx | 3 +-
packages/page-signing/src/Unlock.tsx | 3 +-
.../page-society/src/Candidates/BidNew.tsx | 3 +-
.../src/Candidates/CandidateVoting.tsx | 7 +-
.../src/Overview/DefenderVoting.tsx | 7 +-
.../src/Overview/DesignKusama.tsx | 5 +-
.../src/Actions/Account/BondExtra.tsx | 3 +-
.../src/Actions/Account/InjectKeys.tsx | 3 +-
.../src/Actions/Account/KickNominees.tsx | 3 +-
.../src/Actions/Account/Nominate.tsx | 3 +-
.../Actions/Account/SetControllerAccount.tsx | 3 +-
.../Actions/Account/SetRewardDestination.tsx | 3 +-
.../src/Actions/Account/SetSessionKey.tsx | 3 +-
.../src/Actions/Account/Unbond.tsx | 3 +-
.../src/Actions/Account/Validate.tsx | 3 +-
.../page-staking/src/Actions/NewNominator.tsx | 3 +-
.../page-staking/src/Actions/NewStash.tsx | 3 +-
.../page-staking/src/Actions/NewValidator.tsx | 3 +-
.../page-staking/src/Payouts/PayButton.tsx | 3 +-
.../page-staking/src/Targets/Nominate.tsx | 3 +-
.../page-tech-comm/src/Proposals/Close.tsx | 3 +-
.../page-tech-comm/src/Proposals/Propose.tsx | 2 +-
.../page-tech-comm/src/Proposals/Voting.tsx | 3 +-
.../page-treasury/src/Overview/Council.tsx | 3 +-
.../src/Overview/ProposalCreate.tsx | 3 +-
packages/page-treasury/src/Tips/TipCreate.tsx | 3 +-
.../page-treasury/src/Tips/TipEndorse.tsx | 3 +-
packages/react-components/src/Forget.tsx | 2 +-
.../react-components/src/Modal/Actions.tsx | 24 ++--
packages/react-components/src/Modal/Base.tsx | 109 +++++++++++++++++
.../react-components/src/Modal/Content.tsx | 19 +++
.../react-components/src/Modal/Header.tsx | 30 +++++
.../react-components/src/Modal/Modal.spec.tsx | 110 ++++++++++++++++++
packages/react-components/src/Modal/index.tsx | 42 +------
packages/react-components/src/Modal/types.tsx | 29 ++++-
.../react-components/src/styles/semantic.ts | 44 -------
packages/react-signer/src/TxSigned.tsx | 13 +--
packages/react-signer/src/TxUnsigned.tsx | 15 +--
packages/react-signer/src/index.tsx | 18 ++-
98 files changed, 519 insertions(+), 221 deletions(-)
create mode 100644 packages/react-components/src/Modal/Base.tsx
create mode 100644 packages/react-components/src/Modal/Content.tsx
create mode 100644 packages/react-components/src/Modal/Header.tsx
create mode 100644 packages/react-components/src/Modal/Modal.spec.tsx
diff --git a/packages/page-accounts/src/Sidebar/RegistrarJudgement.tsx b/packages/page-accounts/src/Sidebar/RegistrarJudgement.tsx
index 89bc6c4608..04cbde6222 100644
--- a/packages/page-accounts/src/Sidebar/RegistrarJudgement.tsx
+++ b/packages/page-accounts/src/Sidebar/RegistrarJudgement.tsx
@@ -67,7 +67,7 @@ function RegistrarJudgement ({ address, registrars, toggleJudgement }: Props): R
value={judgementEnum}
/>
-
+
{
('Backup account')}
+ onClose={onClose}
>
{
-
+
-
+
('Remove')}
diff --git a/packages/page-council/src/Motions/Close.tsx b/packages/page-council/src/Motions/Close.tsx
index 498e12cb52..e7751e597c 100644
--- a/packages/page-council/src/Motions/Close.tsx
+++ b/packages/page-council/src/Motions/Close.tsx
@@ -36,6 +36,7 @@ function Close ({ hasFailed, hash, idNumber, members, proposal }: Props): React.
{isOpen && (
('Close proposal')}
+ onClose={toggleOpen}
size='large'
>
@@ -55,7 +56,7 @@ function Close ({ hasFailed, hash, idNumber, members, proposal }: Props): React.
/>
-
+
('Propose external (majority)')}
+ onClose={toggleVisible}
size='large'
>
@@ -100,7 +101,7 @@ function ProposeExternal ({ className = '', isMember, members }: Props): React.R
/>
-
+
| nul
{isOpen && (
('Propose a council motion')}
+ onClose={toggleOpen}
size='large'
>
@@ -107,7 +108,7 @@ function Propose ({ isMember, members }: Props): React.ReactElement | nul
/>
-
+
('Revert pending slashes')}
+ onClose={toggleVisible}
size='large'
>
@@ -114,7 +115,7 @@ function Slashing ({ className = '', isMember, members }: Props): React.ReactEle
}
-
+
('Vote on proposal')}
+ onClose={toggleVoting}
size='large'
>
@@ -57,7 +58,7 @@ function Voting ({ hash, idNumber, isDisabled, members, prime, proposal }: Props
)}
-
+
|
)}
-
+
| null {
{isVisible && (
('Vote for current candidates')}
+ onClose={toggleVisible}
size='large'
>
@@ -125,7 +126,7 @@ function Vote ({ electionsInfo }: Props): React.ReactElement | null {
)}
-
+
('Fast track proposal')}
+ onClose={toggleFasttrack}
size='small'
>
@@ -106,7 +107,7 @@ function Fasttrack ({ imageHash, members, threshold }: Props): React.ReactElemen
label={t('threshold')}
/>
-
+
('Submit preimage')}
+ onClose={onClose}
size='large'
>
@@ -104,7 +105,7 @@ function PreImage ({ className = '', imageHash, isImminent = false, onClose }: P
)}
-
+
('Submit proposal')}
+ onClose={onClose}
size='large'
>
@@ -83,7 +84,7 @@ function Propose ({ className = '', onClose }: Props): React.ReactElement
/>
-
+
('Second proposal')}
+ onClose={toggleSeconding}
size='large'
>
@@ -62,7 +63,7 @@ function Seconding ({ deposit, depositors, image, proposalId }: Props): React.Re
/>
-
+
|
{isVotingOpen && (
('Vote on proposal')}
+ onClose={toggleVoting}
size='large'
>
@@ -74,7 +75,7 @@ function Voting ({ proposal, referendumId }: Props): React.ReactElement |
/>
-
+
{
('submit gilt bid')}
+ onClose={toggleOpen}
size='large'
>
@@ -89,7 +90,7 @@ function Bid ({ className, isDisabled }: Props): React.ReactElement {
/>
-
+
('Place bid')}
+ onClose={toggleOpen}
size='large'
>
@@ -119,7 +120,7 @@ function Bid ({ auctionInfo, className, lastWinners, ownedIds }: Props): React.R
/>
-
+
('Contribute to fund')}
+ onClose={toggleOpen}
size='large'
>
@@ -125,7 +126,7 @@ function Contribute ({ cap, className, needsSignature, paraId, raised }: Props):
/>
-
+
('Add campaign')}
+ onClose={toggleOpen}
size='large'
>
@@ -96,7 +97,7 @@ function FundAdd ({ auctionInfo, bestNumber, className, leasePeriod, ownedIds }:
/>
-
+
{
('Withdraw from fund')}
+ onClose={toggleOpen}
size='large'
>
@@ -46,7 +47,7 @@ function Refund ({ className, paraId }: Props): React.ReactElement {
/>
-
+
('Reserve ParaId')}
+ onClose={onClose}
size='large'
>
@@ -51,7 +52,7 @@ function RegisterId ({ className, nextParaId, onClose }: Props): React.ReactElem
/>
-
+
('Register parathread')}
+ onClose={onClose}
size='large'
>
@@ -119,7 +120,7 @@ function RegisterThread ({ className, nextParaId, onClose, ownedIds }: Props): R
/>
-
+
{
('Propose parachain')}
+ onClose={onClose}
size='large'
>
@@ -163,7 +164,7 @@ function Propose ({ className, onClose }: Props): React.ReactElement {
-
+
| null {
return (
('Teleport assets')}
+ onClose={onClose}
size='large'
>
@@ -160,7 +161,7 @@ function Teleport ({ onClose }: Props): React.ReactElement | null {
}
-
+
('Unlock account')}
+ onClose={onClose}
size='large'
>
@@ -84,7 +85,7 @@ function Unlock ({ onClose, onUnlock, pair }: Props): React.ReactElement
/>
-
+
{
return (
('Bid to join')}
+ onClose={onClose}
size='large'
>
@@ -43,7 +44,7 @@ function BidNew ({ onClose }: Props): React.ReactElement {
/>
-
+
{isVisible && (
- ('Vote for candidate')}>
+ ('Vote for candidate')}
+ onClose={toggleVisible}
+ >
-
+
{isVisible && (
- ('Vote for defender')}>
+ ('Vote for defender')}
+ onClose={toggleVisible}
+ >
-
+
| null {
{isShowing && (
@@ -64,10 +65,6 @@ function DesignKusama ({ accountId }: Props): React.ReactElement | null {
width={WIDTH}
/>
- ('Close')}
- onCancel={toggleDesign}
- />
)}
>
diff --git a/packages/page-staking/src/Actions/Account/BondExtra.tsx b/packages/page-staking/src/Actions/Account/BondExtra.tsx
index bf66506fd2..592a3c8621 100644
--- a/packages/page-staking/src/Actions/Account/BondExtra.tsx
+++ b/packages/page-staking/src/Actions/Account/BondExtra.tsx
@@ -57,6 +57,7 @@ function BondExtra ({ controllerId, onClose, stakingInfo, stashId }: Props): Rea
('Bond more funds')}
+ onClose={onClose}
size='large'
>
@@ -93,7 +94,7 @@ function BondExtra ({ controllerId, onClose, stakingInfo, stashId }: Props): Rea
)}
-
+
| null {
return (
('Inject Keys')}
+ onClose={onClose}
size='large'
>
@@ -117,7 +118,7 @@ function InjectKeys ({ onClose }: Props): React.ReactElement | null {
/>
-
+
('Submit key')}
diff --git a/packages/page-staking/src/Actions/Account/KickNominees.tsx b/packages/page-staking/src/Actions/Account/KickNominees.tsx
index 5e99e914d9..4d68693dfb 100644
--- a/packages/page-staking/src/Actions/Account/KickNominees.tsx
+++ b/packages/page-staking/src/Actions/Account/KickNominees.tsx
@@ -54,6 +54,7 @@ function KickNominees ({ className = '', controllerId, nominating, onClose, stas
('Remove nominees')}
+ onClose={onClose}
size='large'
>
@@ -76,7 +77,7 @@ function KickNominees ({ className = '', controllerId, nominating, onClose, stas
: ('Retrieving active nominators')} />
}
-
+
('Nominate Validators')}
+ onClose={onClose}
size='large'
>
@@ -42,7 +43,7 @@ function Nominate ({ className = '', controllerId, nominating, onClose, stashId,
withSenders
/>
-
+
('Change controller account')}
+ onClose={onClose}
size='large'
>
@@ -56,7 +57,7 @@ function SetControllerAccount ({ defaultControllerId, onClose, stashId }: Props)
/>
-
+
('Bonding Preferences')}
+ onClose={onClose}
size='large'
>
@@ -77,7 +78,7 @@ function SetRewardDestination ({ controllerId, defaultDestination, onClose, stas
)}
-
+
('Set Session Key')}
+ onClose={onClose}
size='large'
>
@@ -34,7 +35,7 @@ function SetSessionKey ({ controllerId, onClose, stashId }: Props): React.ReactE
withSenders
/>
-
+
('Unbond funds')}
+ onClose={onClose}
size='large'
>
@@ -78,7 +79,7 @@ function Unbond ({ className = '', controllerId, onClose, stakingLedger, stashId
)}
-
+
('Set validator preferences')}
+ onClose={onClose}
size='large'
>
@@ -34,7 +35,7 @@ function Validate ({ controllerId, onClose, stashId }: Props): React.ReactElemen
withSenders
/>
-
+
@@ -92,7 +93,7 @@ function NewNominator ({ isInElection, targets }: Props): React.ReactElement
-
+
('Bonding Preferences')}
+ onClose={_toggle}
size='large'
>
-
+
@@ -98,7 +99,7 @@ function NewValidator ({ isInElection, targets }: Props): React.ReactElement
-
+
('Payout all stakers')}
+ onClose={togglePayout}
size='large'
>
@@ -118,7 +119,7 @@ function PayButton ({ className, isAll, isDisabled, payout }: Props): React.Reac
}
-
+
('Nominate validators')}
+ onClose={toggleOpen}
size='large'
>
@@ -96,7 +97,7 @@ function Nominate ({ className = '', isDisabled, ownNominators, targets }: Props
/>
-
+
('Nominate')}
diff --git a/packages/page-tech-comm/src/Proposals/Close.tsx b/packages/page-tech-comm/src/Proposals/Close.tsx
index 368f78832f..023c8ffc09 100644
--- a/packages/page-tech-comm/src/Proposals/Close.tsx
+++ b/packages/page-tech-comm/src/Proposals/Close.tsx
@@ -36,6 +36,7 @@ function Close ({ hasFailed, hash, idNumber, members, proposal, type }: Props):
{isOpen && (
('Close proposal')}
+ onClose={toggleOpen}
size='large'
>
@@ -55,7 +56,7 @@ function Close ({ hasFailed, hash, idNumber, members, proposal, type }: Props):
/>
-
+
onChange={_onChangeExtrinsic}
/>
-
+
('Vote on proposal')}
+ onClose={toggleVoting}
size='small'
>
@@ -47,7 +48,7 @@ function Voting ({ hash, members, prime, proposalId, type }: Props): React.React
('You are voting with this collective\'s prime account. The vote will be the default outcome in case of any abstentions.')} />
)}
-
+
{isOpen && (
('Send to council')}
+ onClose={toggleOpen}
size='large'
>
@@ -79,7 +80,7 @@ function Council ({ id, isDisabled, members }: Props): React.ReactElement
/>
-
+
| null {
('Submit treasury proposal')}
+ onClose={toggleOpen}
size='large'
>
@@ -82,7 +83,7 @@ function Propose ({ className }: Props): React.ReactElement | null {
('Be aware that once submitted the proposal will be put to a council vote. If the proposal is rejected due to a lack of info, invalid requirements or non-benefit to the network as a whole, the full bond posted (as describe above) will be lost.')} />
-
+
{
{isOpen && (
('Submit tip request')}
+ onClose={toggleOpen}
size='large'
>
@@ -83,7 +84,7 @@ function TipCreate ({ members }: Props): React.ReactElement {
)}
-
+
('Submit tip endorsement')}
+ onClose={toggleOpen}
size='large'
>
@@ -71,7 +72,7 @@ function TipEndorse ({ defaultId, hash, isMember, isTipped, median, members }: P
/>
-
+
{
onClose={onClose}
>
{children || renderContent(props, t)}
-
+
('Forget')}
diff --git a/packages/react-components/src/Modal/Actions.tsx b/packages/react-components/src/Modal/Actions.tsx
index 49d5a30584..49d1dcb959 100644
--- a/packages/react-components/src/Modal/Actions.tsx
+++ b/packages/react-components/src/Modal/Actions.tsx
@@ -4,23 +4,25 @@
import type { ActionsProps } from './types';
import React from 'react';
-import { Modal as SUIModal } from 'semantic-ui-react';
+import styled from 'styled-components';
import Button from '../Button';
-import ButtonCancel from '../ButtonCancel';
-function Actions ({ cancelLabel, children, className = '', onCancel }: ActionsProps): React.ReactElement {
+function Actions ({ children, className = '' }: ActionsProps) {
return (
-
-
-
+
+
{children}
-
+
);
}
-export default React.memo(Actions);
+export default React.memo(styled(Actions)`
+ background-color: var(--bg-input);
+ border-radius: 0 0 4px 4px;
+
+ .ui--Button-Group {
+ margin: 1rem 1rem;
+ }
+`);
diff --git a/packages/react-components/src/Modal/Base.tsx b/packages/react-components/src/Modal/Base.tsx
new file mode 100644
index 0000000000..c10ec47f88
--- /dev/null
+++ b/packages/react-components/src/Modal/Base.tsx
@@ -0,0 +1,109 @@
+// Copyright 2017-2021 @polkadot/react-components authors & contributors
+// SPDX-License-Identifier: Apache-2.0
+
+import type { ThemeDef } from '../types';
+import type { ModalProps } from './types';
+
+import React, { useCallback, useContext, useEffect } from 'react';
+import { createPortal } from 'react-dom';
+import styled, { createGlobalStyle, ThemeContext } from 'styled-components';
+
+import Header from './Header';
+
+const ESC_KEYCODE = 27;
+
+function Base (props: ModalProps): React.ReactElement {
+ const { theme } = useContext(ThemeContext);
+ const { children, className = '', header, onClose, open = true, size = 'medium', testId = 'modal' } = props;
+
+ const listenKeyboard = useCallback((event: KeyboardEvent) => {
+ if (event.key === 'Escape' || event.keyCode === ESC_KEYCODE) {
+ onClose();
+ }
+ }, [onClose]);
+
+ useEffect(() => {
+ if (open) {
+ window.addEventListener('keydown', listenKeyboard, true);
+ }
+
+ return () => {
+ open && window.removeEventListener('keydown', listenKeyboard, true);
+ };
+ }, [open, listenKeyboard]);
+
+ return createPortal(
+ ,
+ document.body
+ );
+}
+
+const DisableGlobalScroll = createGlobalStyle`
+ body {
+ overflow: hidden;
+ }
+`;
+
+export default React.memo(styled(Base)`
+ position: fixed;
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 100%;
+ min-height: 100vh;
+ z-index: 1000;
+ overflow-y: auto;
+
+ .ui--Modal__overlay {
+ position: fixed;
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 100%;
+ background: rgba(96, 96, 96, 0.5);
+ }
+
+ .ui--Modal__body {
+ margin-top: 30px;
+ background: var(--bg-page);
+ border-radius: 4px;
+ box-shadow: none;
+
+ display: flex;
+ flex-direction: column;
+ position: absolute;
+ top: 0;
+ left: 50%;
+ transform: translate(-50%, 0);
+
+ max-width: 900px;
+ width: calc(100% - 16px);
+
+ color: var(--color-text);
+ font: var(--font-sans);
+ }
+
+ &.size-small .ui--Modal__body {
+ max-width: 720px;
+ }
+
+ &.size-large .ui--Modal__body {
+ max-width: 1080px;
+ }
+`);
diff --git a/packages/react-components/src/Modal/Content.tsx b/packages/react-components/src/Modal/Content.tsx
new file mode 100644
index 0000000000..10033b49bf
--- /dev/null
+++ b/packages/react-components/src/Modal/Content.tsx
@@ -0,0 +1,19 @@
+// Copyright 2017-2021 @polkadot/react-components authors & contributors
+// SPDX-License-Identifier: Apache-2.0
+
+import type { ContentProps } from './types';
+
+import React from 'react';
+import styled from 'styled-components';
+
+function Content ({ children, className = '' }: ContentProps) {
+ return (
+
+ {children}
+
+ );
+}
+
+export default React.memo(styled(Content)`
+ padding: 1.5rem;
+`);
diff --git a/packages/react-components/src/Modal/Header.tsx b/packages/react-components/src/Modal/Header.tsx
new file mode 100644
index 0000000000..fa9b8d9983
--- /dev/null
+++ b/packages/react-components/src/Modal/Header.tsx
@@ -0,0 +1,30 @@
+// Copyright 2017-2021 @polkadot/react-components authors & contributors
+// SPDX-License-Identifier: Apache-2.0
+
+import type { HeaderProps } from './types';
+
+import React from 'react';
+import styled from 'styled-components';
+
+import Button from '../Button';
+
+function Header ({ className, header, onClose }: HeaderProps) {
+ return (
+
+ {header && (
+
{header}
+ )}
+
+
+ );
+}
+
+export default React.memo(styled(Header)`
+ display: flex;
+ justify-content: space-between;
+ padding: 0.75rem 1.5rem 0;
+`);
diff --git a/packages/react-components/src/Modal/Modal.spec.tsx b/packages/react-components/src/Modal/Modal.spec.tsx
new file mode 100644
index 0000000000..7c44200dba
--- /dev/null
+++ b/packages/react-components/src/Modal/Modal.spec.tsx
@@ -0,0 +1,110 @@
+// Copyright 2017-2021 @polkadot/app-bounties authors & contributors
+// SPDX-License-Identifier: Apache-2.0
+
+import { fireEvent, render, screen } from '@testing-library/react';
+import React from 'react';
+import { ThemeProvider } from 'styled-components';
+
+import { lightTheme } from '@polkadot/apps/themes';
+import { useToggle } from '@polkadot/react-hooks';
+
+import Button from '../Button';
+import Modal from './index';
+
+function TestModal () {
+ const [isOpen, toggleIsOpen] = useToggle();
+
+ return (
+ <>
+
+ {isOpen && (
+
+
+ Test Modal Content
+
+
+
+
+
+ )}
+ >
+ );
+}
+
+function renderModal () {
+ return render(
+
+
+
+ );
+}
+
+describe('Modal Component', () => {
+ it('opens and closes modal', async () => {
+ renderModal();
+
+ await expectModalToBeClosed();
+ await openModal();
+ await expectModalToBeOpen();
+ await closeModal();
+ await expectModalToBeClosed();
+ });
+
+ it('renders all modal sections', async () => {
+ renderModal();
+
+ await expectModalToBeClosed();
+ await openModal();
+ await expectModalToBeOpen();
+
+ await screen.findByText('Test Modal');
+ await screen.findAllByText('Test Modal Content');
+ await screen.findByRole('button', { name: 'Submit Modal' });
+ });
+
+ it('closes modal with ESC button', async () => {
+ renderModal();
+
+ await expectModalToBeClosed();
+ await openModal();
+ await expectModalToBeOpen();
+
+ fireEvent.keyDown(window, {
+ charCode: 27,
+ code: 'Escape',
+ key: 'Escape',
+ keyCode: 27
+ });
+
+ await expectModalToBeClosed();
+ });
+});
+
+async function expectModalToBeClosed () {
+ await screen.findByRole('button', { name: 'Open Test Modal' });
+ expect(screen.queryAllByTestId('test-modal')).toHaveLength(0);
+}
+
+async function expectModalToBeOpen () {
+ await screen.findByTestId('test-modal');
+}
+
+async function openModal () {
+ fireEvent.click(await screen.findByRole('button', { name: 'Open Test Modal' }));
+}
+
+async function closeModal () {
+ fireEvent.click(await screen.findByTestId('close-modal'));
+}
diff --git a/packages/react-components/src/Modal/index.tsx b/packages/react-components/src/Modal/index.tsx
index 75ae278e00..f1f86789ac 100644
--- a/packages/react-components/src/Modal/index.tsx
+++ b/packages/react-components/src/Modal/index.tsx
@@ -1,49 +1,17 @@
// Copyright 2017-2021 @polkadot/react-components authors & contributors
// SPDX-License-Identifier: Apache-2.0
-import type { ThemeDef } from '@polkadot/react-components/types';
-import type { ActionsProps, ColumnsProps, ModalProps } from './types';
-
-import React, { useContext } from 'react';
-import { Modal as SUIModal } from 'semantic-ui-react';
-import { ThemeContext } from 'styled-components';
+import type { ModalType } from './types';
import Actions from './Actions';
+import ModalBase from './Base';
import Columns from './Columns';
+import Content from './Content';
-type ModalType = React.FC & {
- Actions: React.FC;
- Columns: React.FC;
- Content: typeof SUIModal.Content;
- Description: typeof SUIModal.Description;
-};
-
-function ModalBase (props: ModalProps): React.ReactElement {
- const { theme } = useContext(ThemeContext);
- const { children, className = '', header, open = true } = props;
-
- return (
-
- {header && (
-
-
{header}
-
- )}
- {children}
-
- );
-}
-
-const Modal = React.memo(ModalBase) as unknown as ModalType;
+const Modal = ModalBase as unknown as ModalType;
Modal.Actions = Actions;
Modal.Columns = Columns;
-Modal.Content = SUIModal.Content;
-Modal.Description = SUIModal.Description;
+Modal.Content = Content;
export default Modal;
diff --git a/packages/react-components/src/Modal/types.tsx b/packages/react-components/src/Modal/types.tsx
index 5d1c079294..fef3d42e44 100644
--- a/packages/react-components/src/Modal/types.tsx
+++ b/packages/react-components/src/Modal/types.tsx
@@ -3,6 +3,12 @@
import React from 'react';
+export interface HeaderProps {
+ className?: string;
+ header?: React.ReactNode;
+ onClose: () => void;
+}
+
export interface ColumnsProps {
children: React.ReactNode;
className?: string;
@@ -10,17 +16,32 @@ export interface ColumnsProps {
}
export interface ModalProps {
+ size?: 'large' | 'medium' | 'small';
children: React.ReactNode;
className?: string;
header?: React.ReactNode;
open?: boolean;
+ onClose: () => void;
+ testId?: string;
[index: string]: any;
}
export interface ActionsProps {
className?: string;
- cancelLabel?: string;
- children?: React.ReactNode;
- withOr?: boolean;
- onCancel: () => void;
+ children: React.ReactNode;
}
+
+export interface BodyProps {
+ size: 'large' | 'medium' | 'small'
+}
+
+export interface ContentProps {
+ className?: string;
+ children: React.ReactNode;
+}
+
+export type ModalType = React.FC & {
+ Actions: React.FC;
+ Columns: React.FC;
+ Content: React.FC;
+};
diff --git a/packages/react-components/src/styles/semantic.ts b/packages/react-components/src/styles/semantic.ts
index 036259f793..405900c9d0 100644
--- a/packages/react-components/src/styles/semantic.ts
+++ b/packages/react-components/src/styles/semantic.ts
@@ -123,50 +123,6 @@ export default (_theme: ThemeDef): string => `
z-index: 1;
}
- .ui.modal {
- background: var(--bg-page);
- box-shadow: none;
- color: var(--color-text);
- font: var(--font-sans);
-
- > .actions,
- > .content {
- background: transparent;
- }
-
- > .actions {
- border-top: none;
- text-align: right;
- padding: 0 1rem !important;
- }
-
- /* approx h1, color, size, font */
- > .header:not(.ui) {
- background: transparent;
- border-bottom: none;
- color: var(--color-summary);
- font: var(--font-sans);
- font-size: 1.75rem;
- font-weight: var(--font-weight-normal);
- line-height: 1.25rem;
- padding: 0.75rem 1.5rem 0;
- text-transform: lowercase;
-
- > label {
- margin-top: 0.5rem;
- }
-
- > h1 {
- line-height: 1;
- }
- }
-
- .description {
- margin: 1.5em 0;
- font-weight: var(--font-weight-normal);
- }
- }
-
.ui.page.modals.transition.visible {
display: flex !important;
}
diff --git a/packages/react-signer/src/TxSigned.tsx b/packages/react-signer/src/TxSigned.tsx
index 7039a3af50..bf934d3668 100644
--- a/packages/react-signer/src/TxSigned.tsx
+++ b/packages/react-signer/src/TxSigned.tsx
@@ -226,17 +226,6 @@ function TxSigned ({ className, currentItem, requestAddress }: Props): React.Rea
[qrResolve]
);
- const _onCancel = useCallback(
- (): void => {
- const { id, signerCb = NOOP, txFailedCb = NOOP } = currentItem;
-
- queueSetTxStatus(id, 'cancelled');
- signerCb(id, null);
- txFailedCb(null);
- },
- [currentItem, queueSetTxStatus]
- );
-
const _unlock = useCallback(
async (): Promise => {
let passwordError: string | null = null;
@@ -409,7 +398,7 @@ function TxSigned ({ className, currentItem, requestAddress }: Props): React.Rea
}
-
+
undefined;
-
async function send (queueSetTxStatus: QueueTxMessageSetStatus, currentItem: QueueTx, tx: SubmittableExtrinsic<'promise'>): Promise {
currentItem.txStartCb && currentItem.txStartCb();
@@ -40,17 +38,6 @@ function TxUnsigned ({ className, currentItem }: Props): React.ReactElement {
- const { id, signerCb = NOOP, txFailedCb = NOOP } = currentItem;
-
- queueSetTxStatus(id, 'cancelled');
- signerCb(id, null);
- txFailedCb(null);
- },
- [currentItem, queueSetTxStatus]
- );
-
const _onSend = useCallback(
async (): Promise => {
if (currentItem.extrinsic) {
@@ -70,7 +57,7 @@ function TxUnsigned ({ className, currentItem }: Props): React.ReactElement
-
+
undefined;
+
const AVAIL_STATUS = ['queued', 'qr', 'signing'];
async function submitRpc (api: ApiPromise, { method, section }: DefinitionRpcExt, values: any[]): Promise {
@@ -100,6 +102,19 @@ function Signer ({ children, className = '' }: Props): React.ReactElement
sendRpc(api, queueSetTxStatus, currentItem).catch(console.error);
}, [api, isRpc, currentItem, queueSetTxStatus]);
+ const _onCancel = useCallback(
+ (): void => {
+ if (currentItem) {
+ const { id, signerCb = NOOP, txFailedCb = NOOP } = currentItem;
+
+ queueSetTxStatus(id, 'cancelled');
+ signerCb(id, null);
+ txFailedCb(null);
+ }
+ },
+ [currentItem, queueSetTxStatus]
+ );
+
return (
<>
{children}
@@ -108,6 +123,7 @@ function Signer ({ children, className = '' }: Props): React.ReactElement
className={className}
header={<>{t('Authorize transaction')}{(count === 1) ? undefined : <> 1/{count}>}>}
key={currentItem.id}
+ onClose={_onCancel}
size='large'
>
{currentItem.isUnsigned