* Add subs modal * Add tests * Add Translations * Improve closing modal * Improve tests * Improve styles * Style balances & identity * Optimize imports * Improve styles * Set greater width to balance section * Rename subs modal toggle * Change 'amount' to 'count' in test name * Set make modal header fixed while content is scrollable * Style multisig * Update multisig styles * Capitalize headers * Move sidebar tests to Sidebar.spec.tsx * Remove duplications in tests * Add UserIcon component * Revert subs modal changes and add scrollable section in Sidebar * Remove unused styles * Use accountsPage clearAccount method * Wrap subs into Expander * Add useSubidentities hook * Adjust api mock in tests * WIP - split judgements * Display judgements * Handle no judgements case * [WIP] Add popup test * Extract JudgmentTag component * Add popup test * Refactor tests and remove pointer from no judgements tag * Extract JudgementTag test class * Close popup on scroll * Remove old section * Clean registration * Clean up identity in useAccountInfo and mock in Page * Remove fragment tag * Fix imports * Move SortedJudgements to /types * Move Registrar interface to types * Refactor clickRegistrar fcn * Move hasAccount check to isRegistrar * Add useJudgements hook * Rename and move getJudgementColor to utils * Fix import and casting in tests * Sort imports * Add review fixes * Fix tests Co-authored-by: Krzysztof Jelski <krzysztof@ethworks.io> Co-authored-by: Ewa Kowalska <ewcia.kowalska@gmail.com> Co-authored-by: Jaco Greeff <jacogr@gmail.com>
70 lines
1.9 KiB
TypeScript
70 lines
1.9 KiB
TypeScript
// Copyright 2017-2021 @polkadot/react-components authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { PopupProps } from './types';
|
|
|
|
import React, { useCallback, useEffect, useRef } from 'react';
|
|
import styled from 'styled-components';
|
|
|
|
import { Button } from '@polkadot/react-components/index';
|
|
import { useOutsideClick, useToggle } from '@polkadot/react-hooks';
|
|
|
|
import PopupWindow from './PopupWindow';
|
|
|
|
function Popup ({ children, className = '', closeOnScroll = false, isDisabled = false, onCloseAction, position = 'left', value }: PopupProps) {
|
|
const [isOpen, toggleIsOpen, setIsOpen] = useToggle(false);
|
|
const triggerRef = useRef<HTMLDivElement>(null);
|
|
const dropdownRef = useRef<HTMLDivElement>(null);
|
|
const closeWindow = useCallback(() => setIsOpen(false), [setIsOpen]);
|
|
|
|
useOutsideClick([triggerRef, dropdownRef], closeWindow);
|
|
|
|
useEffect(() => {
|
|
if (closeOnScroll) {
|
|
document.addEventListener('scroll', closeWindow, true);
|
|
}
|
|
|
|
return () => document.removeEventListener('scroll', closeWindow, true);
|
|
}, [closeOnScroll, closeWindow, setIsOpen]);
|
|
|
|
useEffect(() => {
|
|
if (!isOpen && onCloseAction) {
|
|
onCloseAction();
|
|
}
|
|
}, [isOpen, onCloseAction]);
|
|
|
|
return (
|
|
<div className={`ui--Popup ${className}`}>
|
|
{isOpen && (
|
|
<PopupWindow
|
|
position={position}
|
|
triggerRef={triggerRef}
|
|
windowRef={dropdownRef}
|
|
>
|
|
{value}
|
|
</PopupWindow>
|
|
)}
|
|
<div
|
|
onClick={toggleIsOpen}
|
|
ref={triggerRef}
|
|
>
|
|
{children ?? (
|
|
<Button
|
|
className={isOpen ? 'isOpen' : ''}
|
|
icon='ellipsis-v'
|
|
isDisabled={isDisabled}
|
|
isReadOnly={false}
|
|
/>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export default React.memo(styled(Popup)`
|
|
display: inline-flex;
|
|
flex-direction: column;
|
|
justify-content: center;
|
|
position: relative;
|
|
`);
|