-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathHideSplitViewButton.tsx
86 lines (83 loc) · 2.38 KB
/
HideSplitViewButton.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
75
76
77
78
79
80
81
82
83
84
85
86
/**
* (c) 2022, Micro:bit Educational Foundation and contributors
*
* SPDX-License-Identifier: MIT
*/
import { Box, Icon, IconButtonProps } from "@chakra-ui/react";
import React, { ForwardedRef } from "react";
import { RiDownloadLine } from "react-icons/ri";
import CollapsibleButton from "../CollapsibleButton";
import { splitViewHideButton } from "../zIndex";
interface HideSplitViewButtonProps extends IconButtonProps {
onClick: () => void;
direction: "expandLeft" | "expandRight";
splitViewShown: boolean;
text?: string;
}
const HideSplitViewButton = React.forwardRef(
(
{
onClick,
direction,
splitViewShown,
text = "",
...props
}: HideSplitViewButtonProps,
ref: ForwardedRef<HTMLButtonElement>
) => {
const mode = text ? "button" : "icon";
let rightBorderRadius = 6;
let leftBorderRadius = 0;
let rotation = "rotate(270deg)";
if (
(direction === "expandRight" && splitViewShown) ||
(direction === "expandLeft" && !splitViewShown)
) {
rightBorderRadius = 0;
leftBorderRadius = 6;
rotation = "rotate(90deg)";
}
return (
<Box position="relative">
{/* Hack to cover divider box shadow on right hand side. */}
{direction === "expandLeft" && splitViewShown && (
<Box
width="10px"
height="60px"
background="#eaecf1"
zIndex={5}
position="absolute"
left="-10px"
top="-10px"
pointerEvents="none"
/>
)}
<CollapsibleButton
ref={ref}
mode={mode}
text={text}
icon={<Icon as={RiDownloadLine} transform={rotation} />}
fontSize="lg"
transition="none"
onClick={onClick}
borderTopRightRadius={rightBorderRadius}
borderBottomRightRadius={rightBorderRadius}
borderTopLeftRadius={leftBorderRadius}
borderBottomLeftRadius={leftBorderRadius}
py={3}
borderColor="black"
size="md"
minW="unset"
width={mode === "icon" ? "20px" : "auto"}
background="#eaecf1"
color="brand1.500"
variant="ghost"
zIndex={splitViewHideButton}
boxShadow={direction === "expandLeft" ? "md" : "none"}
{...props}
/>
</Box>
);
}
);
export default HideSplitViewButton;