forked from polkadot-js/apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sidebar.tsx
74 lines (65 loc) · 1.65 KB
/
Sidebar.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2017-2024 @polkadot/react-components authors & contributors
// SPDX-License-Identifier: Apache-2.0
import React from 'react';
import Button from './Button/index.js';
import { styled } from './styled.js';
interface Props {
button?: React.ReactNode;
secondaryButton?: React.ReactNode;
children: React.ReactNode;
className?: string;
dataTestId?: string;
offset?: number | string;
onClose?: () => void;
position: 'left' | 'right';
sidebarRef: React.RefObject<HTMLDivElement>;
}
function Sidebar ({ button, children, className = '', dataTestId = '', onClose, position, secondaryButton, sidebarRef }: Props): React.ReactElement<Props> {
return (
<StyledDiv
className={`${className} ui--Sidebar ${position}Position`}
data-testid={dataTestId}
ref={sidebarRef}
>
<Button.Group className='ui--Sidebar-buttons'>
{button}
{secondaryButton}
<Button
dataTestId='close-sidebar-button'
icon='times'
isBasic
isCircular
onClick={onClose}
/>
</Button.Group>
{children}
</StyledDiv>
);
}
const StyledDiv = styled.div`
background: var(--bg-page);
bottom: 0;
margin-left: -0.125rem;
max-width: 24rem;
min-width: 24rem;
position: fixed;
padding: 1rem;
overflow-y: auto;
top: 0;
z-index: 999;
&.leftPosition {
box-shadow: 6px 0px 20px 0px rgba(0, 0, 0, 0.3);
left: 0;
}
&.rightPosition {
box-shadow: -6px 0px 20px 0px rgba(0, 0, 0, 0.3);
right: 0;
}
.ui--Sidebar-buttons {
margin: 0;
position: absolute;
right: 0.5rem;
top: 0.5rem;
}
`;
export default React.memo(Sidebar);