diff --git a/packages/@headlessui-react/CHANGELOG.md b/packages/@headlessui-react/CHANGELOG.md index 3694842687..4c926d0fbd 100644 --- a/packages/@headlessui-react/CHANGELOG.md +++ b/packages/@headlessui-react/CHANGELOG.md @@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Expose `--input-width` and `--button-width` CSS variables on the `ComboboxOptions` component ([#3057](https://github.com/tailwindlabs/headlessui/pull/3057)) - Expose the `--button-width` CSS variable on the `PopoverPanel` component ([#3058](https://github.com/tailwindlabs/headlessui/pull/3058)) - Close the `Combobox`, `Dialog`, `Listbox`, `Menu` and `Popover` components when the trigger disappears ([#3075](https://github.com/tailwindlabs/headlessui/pull/3075)) +- Add new `CloseButton` component and `useClose` hook ([#3096](https://github.com/tailwindlabs/headlessui/pull/3096)) ## [2.0.0-alpha.4] - 2024-01-03 diff --git a/packages/@headlessui-react/src/components/close-button/close-button.tsx b/packages/@headlessui-react/src/components/close-button/close-button.tsx new file mode 100644 index 0000000000..e873284e54 --- /dev/null +++ b/packages/@headlessui-react/src/components/close-button/close-button.tsx @@ -0,0 +1,21 @@ +'use client' + +import React, { type ElementType, type Ref } from 'react' +import { useClose } from '../../internal/close-provider' +import { forwardRefWithAs, mergeProps } from '../../utils/render' +import { Button, type ButtonProps, type _internal_ComponentButton } from '../button/button' + +let DEFAULT_BUTTON_TAG = 'button' as const + +export type CloseButtonProps = + ButtonProps + +function CloseButtonFn( + props: ButtonProps, + ref: Ref +) { + let close = useClose() + return