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

🐛Scrim: use own useHideBodyScroll instead of f-ui #3619

Merged
merged 2 commits into from
Sep 9, 2024
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 @@ -52,6 +52,6 @@ const Demo = () => {
}
```

## Example: Scrim with Dialog
## Example: Scrim with SideSheet

<Canvas of={ComponentStories.Dismissable} />
54 changes: 13 additions & 41 deletions packages/eds-core-react/src/components/Scrim/Scrim.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Button, Scrim, ScrimProps, Dialog, Typography } from '../..'
import { Button, Scrim, ScrimProps, SideSheet } from '../..'
import { useState } from 'react'
import { StoryFn, Meta } from '@storybook/react'
import styled from 'styled-components'
import { useArgs } from '@storybook/preview-api'
import { Stack } from './../../../.storybook/components'
import page from './Scrim.docs.mdx'
Expand Down Expand Up @@ -36,14 +35,6 @@ const meta: Meta<typeof Scrim> = {

export default meta

const Wrapper = styled.div`
display: grid;
column-gap: 16px;
grid-template-columns: repeat(2, auto);
justify-content: end;
justify-self: end;
`

export const Introduction: StoryFn<ScrimProps> = (args) => {
const { open } = args
const [, updateArgs] = useArgs()
Expand All @@ -66,39 +57,20 @@ export const Introduction: StoryFn<ScrimProps> = (args) => {
)
}

//This story used to be imported from Dialog.stories.tsx, but there is currently an issue with importing stories from other places into mdx
//see https://github.com/storybookjs/storybook/issues/22451
export const Dismissable: StoryFn<ScrimProps> = () => {
const [isOpen, setIsOpen] = useState(false)
const handleOpen = () => {
setIsOpen(true)
}
const handleClose = () => {
setIsOpen(false)
}

return (
<>
<Button aria-haspopup="dialog" onClick={handleOpen}>
Trigger Dialog
</Button>
<Dialog open={isOpen} isDismissable onClose={handleClose}>
<Dialog.Header>
<Dialog.Title>Dismissable dialog</Dialog.Title>
</Dialog.Header>
<Dialog.CustomContent>
<Typography variant="body_short">
Closes dialog on click outside and escape key.
</Typography>
</Dialog.CustomContent>
<Dialog.Actions>
<Wrapper>
<Button onClick={handleClose}>OK</Button>
<Button variant="ghost" onClick={handleClose}>
Cancel
</Button>
</Wrapper>
</Dialog.Actions>
</Dialog>
</>
<div style={{ minHeight: '30vh' }}>
<Button onClick={() => setIsOpen(true)}>Open SideSheet</Button>
<Scrim open={isOpen} onClose={() => setIsOpen(false)} isDismissable>
<SideSheet open={isOpen} onClose={() => setIsOpen(false)}>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempora,
esse labore. Asperiores tempore ex amet veniam consequatur dolorum
perferendis, nihil non, culpa, modi sed nisi. Repellat, labore? Error,
accusantium sed?
</SideSheet>
</Scrim>
</div>
)
}
8 changes: 6 additions & 2 deletions packages/eds-core-react/src/components/Scrim/Scrim.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { forwardRef, MouseEvent, HTMLAttributes, useRef, useMemo } from 'react'
import styled from 'styled-components'
import { scrim as tokens } from './Scrim.tokens'
import { useGlobalKeyPress, mergeRefs } from '@equinor/eds-utils'
import {
useGlobalKeyPress,
mergeRefs,
useHideBodyScroll,
} from '@equinor/eds-utils'
import { FloatingOverlay } from '@floating-ui/react'

const { background } = tokens
Expand Down Expand Up @@ -34,6 +38,7 @@ export const Scrim = forwardRef<HTMLDivElement, ScrimProps>(function Scrim(
ref,
) {
const scrimRef = useRef<HTMLDivElement>(null)
useHideBodyScroll(open)

const combinedScrimRef = useMemo(
() => mergeRefs<HTMLDivElement>(scrimRef, ref),
Expand All @@ -60,7 +65,6 @@ export const Scrim = forwardRef<HTMLDivElement, ScrimProps>(function Scrim(

return (
<StyledScrim
lockScroll
onMouseDown={handleMouseClose}
ref={combinedScrimRef}
{...rest}
Expand Down