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

DisclosureContent: migrate from reakit to @ariakit/react #55639

Merged
merged 6 commits into from
Nov 8, 2023
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
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Internal

- Migrate `Divider` from `reakit` to `ariakit` ([#55622](https://github.com/WordPress/gutenberg/pull/55622))
- Migrate `DisclosureContent` from `reakit` to `ariakit` and TypeScript ([#55639](https://github.com/WordPress/gutenberg/pull/55639))

### Experimental

Expand Down
11 changes: 0 additions & 11 deletions packages/components/src/disclosure/index.js

This file was deleted.

44 changes: 44 additions & 0 deletions packages/components/src/disclosure/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* External dependencies
*/
// eslint-disable-next-line no-restricted-imports
import * as Ariakit from '@ariakit/react';

/**
* WordPress dependencies
*/
import { forwardRef } from '@wordpress/element';

/**
* Internal dependencies
*/
import type { DisclosureContentProps } from './types';
import type { WordPressComponentProps } from '../context';

/**
* Accessible Disclosure component that controls visibility of a section of
* content. It follows the WAI-ARIA Disclosure Pattern.
*/
const UnforwardedDisclosureContent = (
{
visible,
children,
...props
}: WordPressComponentProps< DisclosureContentProps, 'div', false >,
ref: React.ForwardedRef< any >
) => {
const disclosure = Ariakit.useDisclosureStore( { open: visible } );

return (
<Ariakit.DisclosureContent
store={ disclosure }
ref={ ref }
{ ...props }
>
{ children }
</Ariakit.DisclosureContent>
);
};

export const DisclosureContent = forwardRef( UnforwardedDisclosureContent );
export default DisclosureContent;
10 changes: 10 additions & 0 deletions packages/components/src/disclosure/types.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export type DisclosureContentProps = {
/**
* If set to `true` the content will be shown, otherwise it's hidden.
*/
visible?: boolean;
/**
* The content to display within the component.
*/
children: React.ReactNode;
};