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

update headless ui #320

Merged
merged 1 commit into from
Oct 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
148 changes: 117 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"@aboutbits/react-material-icons": "^2.0.0",
"@aboutbits/react-toolbox": "^0.2.5",
"@floating-ui/react": "^0.26.10",
"@headlessui/react": "^1.7.18",
"@headlessui/react": "^2.1.9",
"axios": "^1.6.8",
"classnames": "^2.5.1",
"lodash": "^4.17.21",
Expand Down
9 changes: 6 additions & 3 deletions src/components/dialog/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Dialog as HeadlessDialog } from '@headlessui/react'
import {
Dialog as HeadlessDialog,
DialogPanel as HeadlessDialogPanel,
} from '@headlessui/react'
import classNames from 'classnames'
import { MutableRefObject, ReactElement, useRef } from 'react'
import { useTheme } from '../../../framework'
Expand Down Expand Up @@ -49,7 +52,7 @@ export function Dialog({
onClose={onDismiss ?? (() => undefined)}
{...props}
>
<HeadlessDialog.Panel
<HeadlessDialogPanel
ref={panelRef}
aria-label={ariaLabel}
className={classNames(
Expand All @@ -62,7 +65,7 @@ export function Dialog({
)}
>
{children}
</HeadlessDialog.Panel>
</HeadlessDialogPanel>
</HeadlessDialog>
</DialogContext.Provider>
)
Expand Down
16 changes: 10 additions & 6 deletions src/components/menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import {
offset,
useFloating,
} from '@floating-ui/react'
import { Menu as HeadlessMenu } from '@headlessui/react'
import {
Menu as HeadlessMenu,
MenuButton as HeadlessMenuButton,
MenuItems as HeadlessMenuItems,
} from '@headlessui/react'
import classNames from 'classnames'
import { Fragment, ReactElement, ReactNode, ReactPortal } from 'react'
import { useTheme } from '../../framework'
Expand Down Expand Up @@ -52,7 +56,7 @@ export type MenuProps = {

/**
* A dropdown menu that uses the `Menu` component of [HeadlessUI](https://headlessui.com/react/dialog) and the anchor positioning of [Floating UI](https://floating-ui.com).
Menu items are added as children using the [MenuItem](/docs/components-menu-menuitem--docs) component.
Menu items are added as children using the [MenuItem](/docs/components-menu-menuitem--docs) component.
*/
export function Menu({ className, children, button, placement }: MenuProps) {
const { menu } = useTheme()
Expand All @@ -72,23 +76,23 @@ export function Menu({ className, children, button, placement }: MenuProps) {
<HeadlessMenu as="div" className={classNames(menu.container, className)}>
{({ open }) => (
<>
<HeadlessMenu.Button as={Fragment} ref={refs.setReference}>
<HeadlessMenuButton as={Fragment} ref={refs.setReference}>
{typeof button === 'function'
? button({
placement: placementUnionToPlacementEnum(finalPlacement),
open,
})
: button}
</HeadlessMenu.Button>
</HeadlessMenuButton>
{open && (
<FloatingPortal>
<HeadlessMenu.Items
<HeadlessMenuItems
ref={refs.setFloating}
className={menu.list.base}
style={floatingStyles}
>
{children}
</HeadlessMenu.Items>
</HeadlessMenuItems>
</FloatingPortal>
)}
</>
Expand Down