DocSpace-client/packages/asc-web-components/modal-dialog/components/ModalBackdrop.js

63 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-04-08 22:13:08 +00:00
import React from "react";
import styled from "styled-components";
2022-04-08 23:41:44 +00:00
import PropTypes from "prop-types";
2022-04-08 22:13:08 +00:00
const StyledModalBackdrop = styled.div.attrs((props) => ({
style: {
backdropFilter: `${
props.modalSwipeOffset
2022-04-08 23:41:44 +00:00
? `blur(${
props.modalSwipeOffset < 0 && 18 - props.modalSwipeOffset * -0.14
}px)`
2022-04-08 22:13:08 +00:00
: "blur(18px)"
}`,
background: `${
props.modalSwipeOffset
2022-04-08 23:41:44 +00:00
? `rgba(6, 22, 38, ${
props.modalSwipeOffset < 0 && 0.2 - props.modalSwipeOffset * -0.002
})`
2022-04-08 22:13:08 +00:00
: `rgba(6, 22, 38, 0.2)`
}`,
},
}))`
display: block;
height: 100vh;
width: 100vw;
2022-04-08 23:41:44 +00:00
position: fixed;
2022-04-08 22:13:08 +00:00
left: 0;
top: 0;
2022-04-08 23:41:44 +00:00
z-index: ${(props) => props.zIndex};
transition: 0.2s;
opacity: 0;
&.modal-backdrop-active {
opacity: 1;
}
2022-04-08 22:13:08 +00:00
`;
2022-04-08 23:41:44 +00:00
const ModalBackdrop = ({ className, zIndex, modalSwipeOffset, children }) => {
2022-04-08 22:13:08 +00:00
return (
2022-04-08 23:41:44 +00:00
<StyledModalBackdrop
zIndex={zIndex}
className={className}
modalSwipeOffset={modalSwipeOffset}
>
2022-04-08 22:13:08 +00:00
{children}
</StyledModalBackdrop>
);
};
2022-04-08 23:41:44 +00:00
ModalBackdrop.propTypes = {
id: PropTypes.string,
className: PropTypes.string,
children: PropTypes.any,
zIndex: PropTypes.number,
visible: PropTypes.bool,
modalSwipeOffset: PropTypes.number,
};
2022-04-08 22:13:08 +00:00
export default ModalBackdrop;