Skip to content

Commit daf3202

Browse files
committed
feat(ui-parts): add using floating ui to modal
1 parent 5689a13 commit daf3202

20 files changed

Lines changed: 159 additions & 187 deletions

.pnp.cjs

Lines changed: 4 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui-parts/modal/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@atls-ui-parts/modal",
3-
"version": "1.0.6",
3+
"version": "1.1.0",
44
"license": "BSD-3-Clause",
55
"type": "module",
66
"main": "./src/index.ts",
@@ -13,12 +13,12 @@
1313
"postpack": "rm -rf dist"
1414
},
1515
"dependencies": {
16-
"@atls-ui-parts/condition": "workspace:*",
17-
"@atls-ui-parts/portal": "workspace:*",
18-
"clsx": "2.1.1",
19-
"framer-motion": "12.9.2"
16+
"@atls-utils/use-float": "workspace:*",
17+
"@floating-ui/react": "0.27.8",
18+
"clsx": "2.1.1"
2019
},
2120
"devDependencies": {
21+
"@storybook/preview-api": "8.6.12",
2222
"@storybook/react": "8.6.12",
2323
"@types/react": "19.1.2",
2424
"@vanilla-extract/css": "1.17.1",

ui-parts/modal/src/backdrop/backdrop.component.tsx

Lines changed: 0 additions & 19 deletions
This file was deleted.

ui-parts/modal/src/backdrop/backdrop.css.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

ui-parts/modal/src/backdrop/backdrop.interfaces.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

ui-parts/modal/src/backdrop/backdrop.motion.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

ui-parts/modal/src/backdrop/index.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

ui-parts/modal/src/component.tsx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import type { ReactNode } from 'react'
2+
3+
import type { ModalProps } from './interfaces.js'
4+
5+
import { FloatingOverlay } from '@floating-ui/react'
6+
import { FloatingPortal } from '@floating-ui/react'
7+
import { FloatingFocusManager } from '@floating-ui/react'
8+
import { cloneElement } from 'react'
9+
10+
import { useFloat } from '@atls-utils/use-float'
11+
12+
export const Modal = ({
13+
open = false,
14+
onClose,
15+
children,
16+
backdropProps,
17+
focusProps,
18+
}: ModalProps): ReactNode => {
19+
const handleOpenChange = (isOpen: boolean): void => {
20+
if (!isOpen && onClose) {
21+
onClose()
22+
}
23+
}
24+
25+
const { refs, isOpen, context, getFloatingProps } = useFloat({
26+
open,
27+
onOpenChange: handleOpenChange,
28+
role: 'dialog',
29+
dismiss: { outsidePressEvent: 'mousedown' },
30+
})
31+
32+
if (!isOpen) {
33+
return null
34+
}
35+
36+
const ContainerElement = cloneElement(children, { ref: refs.setFloating, ...getFloatingProps() })
37+
38+
return (
39+
<FloatingPortal>
40+
<FloatingOverlay lockScroll {...backdropProps}>
41+
<FloatingFocusManager context={context} {...focusProps}>
42+
{ContainerElement}
43+
</FloatingFocusManager>
44+
</FloatingOverlay>
45+
</FloatingPortal>
46+
)
47+
}

ui-parts/modal/src/container/container.component.tsx

Lines changed: 0 additions & 16 deletions
This file was deleted.

ui-parts/modal/src/container/container.css.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)