File size: 2,729 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
87
88
89
90
91
92
93
94
95
96
97
98
99
import { useTheme } from '@mui/material';
import type { DrawerProps } from '@mui/material';
import { Divider, Drawer, Portal } from '@mui/material';
import type { FC, PropsWithChildren } from 'react';
import React, { Fragment } from 'react';
import { useIsSmallScreen } from '../../core/components/hooks';

const darkBlack = 'rgba(0, 0, 0, 0.87)';
const bright = 'rgba(255,255,255, 0.98)';
const brightBorder = 'rgba(0, 0, 0, 0.12)';

export type BottomToolbarDrawerProps = {
  open: boolean;
  style?: React.CSSProperties;
  className?: string;
  anchor?: DrawerProps['anchor'];
  dark?: boolean;
  scale?: number;
};

export const BottomToolbarDrawer: FC<
  PropsWithChildren<BottomToolbarDrawerProps>
> = ({ className, anchor, open, scale = 1, children, style = {} }) => {
  const divider = (
    <Divider
      style={{
        marginLeft: -24,
        marginRight: -24,
        marginTop: 12,
        marginBottom: 12,
      }}
    />
  );

  const theChildren = React.Children.toArray(children).filter(Boolean);
  const isSmall = useIsSmallScreen();
  const theme = useTheme();
  const dark = theme.palette.mode === 'dark';
  return (
    <Portal>
      <Drawer
        SlideProps={{
          mountOnEnter: true,
          unmountOnExit: true,
        }}
        variant="persistent"
        className={className}
        open={open}
        anchor={anchor}
        PaperProps={{
          style: {
            zIndex: 10,
            backgroundColor: 'transparent',
            border: 'none',
            overflow: 'visible',
            pointerEvents: 'none',
          },
        }}
      >
        <div
          style={{
            pointerEvents: 'all',
            border: `${dark ? darkBlack : brightBorder} 1px solid`,
            borderRadius: '4px 4px 0 0',
            backgroundColor: dark ? darkBlack : bright,
            padding: '12px 24px',

            ...(isSmall
              ? {
                  marginLeft: 20,
                  marginRight: 80,
                }
              : {
                  marginLeft: 'auto',
                  marginRight: 'auto',
                  minWidth: '50vw',
                  maxWidth: 'min(1280px, calc(100vw - 250px))',
                }),
            boxShadow: '0px 1px 8px -1px rgba(0,0,0,0.4)',
            position: 'relative',

            transformOrigin: 'bottom',
            transform: `scale(${scale})`,
            transition: 'scale 0.3s',
            ...style,
          }}
        >
          {theChildren.map((child, index) => (
            <Fragment key={index}>
              {child}
              {index < theChildren.length - 1 ? divider : null}
            </Fragment>
          ))}
        </div>
      </Drawer>
    </Portal>
  );
};