Skip to content

Commit

Permalink
DisclosureContent: migrate from reakit to @ariakit/react (#55639)
Browse files Browse the repository at this point in the history
* `DisclosureContent`: migrate from `reakit` to `@ariakit/react`

* add changelog entry

* include `WordPressComponentProps` & spread props

* move changelog entry to UNRELEASED

* adjust comment to mention `Ariakit` rather than `reakit`

* remove link to `ariakit` docs & comment about future plans
  • Loading branch information
flootr authored Nov 8, 2023
1 parent 08f0b7a commit a522e39
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 11 deletions.
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;
};

0 comments on commit a522e39

Please sign in to comment.