-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Break Away Overlay from ModalBox (#1073)
Signed-off-by: Daniel Valdivia <[email protected]>
- Loading branch information
Showing
6 changed files
with
158 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// This file is part of MinIO Design System | ||
// Copyright (c) 2024 MinIO, Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import { css, Theme } from "@emotion/react"; | ||
|
||
export const modalOverlay = (theme: Theme) => | ||
css({ | ||
position: "fixed" as const, | ||
zIndex: 1200, | ||
width: "100vw", | ||
height: "100vh", | ||
top: 0, | ||
left: 0, | ||
backgroundColor: theme.colors["Color/Neutral/Bg/colorBgOverlay"], | ||
display: "flex", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
opacity: 0, | ||
backdropFilter: "blur(4px)", | ||
"&.active": { | ||
opacity: 1, | ||
transition: "opacity 0.3s", | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// This file is part of MinIO Design System | ||
// Copyright (c) 2024 MinIO, Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
import React from "react"; | ||
import { OverrideTheme } from "../../global/global.types"; | ||
|
||
export interface OverlayProps { | ||
onClose: () => void; | ||
open: boolean; | ||
children: React.ReactNode; | ||
backgroundOverlay?: boolean; | ||
sx?: OverrideTheme; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// This file is part of MinIO Design System | ||
// Copyright (c) 2024 MinIO, Inc. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import { FC, useEffect, useMemo, useState } from "react"; | ||
import { createPortal } from "react-dom"; | ||
import { css, useTheme } from "@emotion/react"; | ||
|
||
import { useEscapeKey } from "../../global/hooks"; | ||
import { overridePropsParse } from "../../global/utils"; | ||
import { modalOverlay } from "./Overlay.styles"; | ||
import { OverlayProps } from "./Overlay.types"; | ||
|
||
const Overlay: FC<OverlayProps> = ({ | ||
onClose, | ||
open, | ||
children, | ||
backgroundOverlay = true, | ||
sx, | ||
}) => { | ||
const theme = useTheme(); | ||
useEscapeKey(onClose); | ||
|
||
const [displayOverlay, setDisplayOverlay] = useState<boolean>(false); | ||
|
||
const overrideThemes = useMemo(() => { | ||
if (sx) { | ||
return css({ ...overridePropsParse(sx, theme) }); | ||
} | ||
|
||
return {}; | ||
}, [sx, theme]); | ||
|
||
const overlayStyles = modalOverlay(theme); | ||
|
||
useEffect(() => { | ||
if (open) { | ||
setTimeout(() => setDisplayOverlay(true), 100); | ||
return; | ||
} | ||
setDisplayOverlay(false); | ||
}, [open]); | ||
|
||
if (!open) { | ||
return null; | ||
} | ||
|
||
const Overlay = ( | ||
<div css={[overrideThemes]} className={"OverlayMain"}> | ||
<div | ||
css={backgroundOverlay ? overlayStyles : {}} | ||
className={`overlay ${displayOverlay ? "active" : ""}`} | ||
> | ||
{children} | ||
</div> | ||
</div> | ||
); | ||
|
||
return createPortal(Overlay, document.body); | ||
}; | ||
|
||
export default Overlay; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters