Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨 Add FloatingOverlay to Scrim #2513

Merged
merged 2 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ const {
} = tokens

export const scrim: ComponentToken = {
width: '100%',
height: '100%',
background,
}
29 changes: 10 additions & 19 deletions packages/eds-core-react/src/components/Scrim/Scrim.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import { forwardRef, MouseEvent, HTMLAttributes, useRef, useMemo } from 'react'
import styled from 'styled-components'
import { scrim as tokens } from './Scrim.tokens'
import {
useGlobalKeyPress,
useHideBodyScroll,
mergeRefs,
} from '@equinor/eds-utils'
import { useGlobalKeyPress, mergeRefs } from '@equinor/eds-utils'
import { FloatingOverlay } from '@floating-ui/react-dom-interactions'

const { height, width, background } = tokens
const { background } = tokens

const StyledScrim = styled.div`
width: ${width};
height: ${height};
const StyledScrim = styled(FloatingOverlay)`
background: ${background};
position: fixed;
z-index: 1300;
top: 0;
left: 0;
align-items: center;
justify-content: center;
display: flex;
Expand Down Expand Up @@ -47,12 +39,6 @@ export const Scrim = forwardRef<HTMLDivElement, ScrimProps>(function Scrim(
() => mergeRefs<HTMLDivElement>(scrimRef, ref),
[scrimRef, ref],
)
const props = {
...rest,
open,
isDismissable,
}
useHideBodyScroll(open)

useGlobalKeyPress('Escape', () => {
if (isDismissable && onClose && open) {
Expand All @@ -73,7 +59,12 @@ export const Scrim = forwardRef<HTMLDivElement, ScrimProps>(function Scrim(
}

return (
<StyledScrim onClick={handleMouseClose} ref={combinedScrimRef} {...props}>
<StyledScrim
lockScroll
onClick={handleMouseClose}
ref={combinedScrimRef}
{...rest}
>
<ScrimContent>{children}</ScrimContent>
</StyledScrim>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
exports[`Scrim Matches snapshot 1`] = `
<DocumentFragment>
.c0 {
width: 100%;
height: 100%;
background: var(--eds_ui_background__scrim,rgba(0,0,0,0.4));
position: fixed;
z-index: 1300;
top: 0;
left: 0;
-webkit-align-items: center;
-webkit-box-align: center;
-ms-flex-align: center;
Expand All @@ -31,7 +26,7 @@ exports[`Scrim Matches snapshot 1`] = `

<div
class="c0"
open=""
style="position: fixed; overflow: auto; top: 0px; right: 0px; bottom: 0px; left: 0px;"
>
<div
class="c1"
Expand Down