Skip to content

Commit

Permalink
Use Composite from @wordpress/components
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed May 8, 2024
1 parent dc0f82d commit e97be2b
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions packages/dataviews/src/view-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import * as Ariakit from '@ariakit/react';
*/
import { useInstanceId } from '@wordpress/compose';
import {
__experimentalHStack as HStack,
__experimentalHStack as HStack,
__experimentalVStack as VStack,
privateApis as componentsPrivateApis,
Spinner,
VisuallyHidden,
} from '@wordpress/components';
Expand All @@ -20,6 +21,7 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import { unlock } from './lock-unlock';
import type {
Data,
Item,
Expand Down Expand Up @@ -51,6 +53,13 @@ interface ListViewItemProps {
visibleFields: NormalizedField[];
}

const {
CompositeV2: Composite,
CompositeItemV2: CompositeItem,
CompositeRowV2: CompositeRow,
useCompositeStoreV2: useCompositeStore,
} = unlock( componentsPrivateApis );

function ListItem( {
actions,
id,
Expand All @@ -77,7 +86,8 @@ function ListItem( {
}, [ isSelected ] );

return (
<Ariakit.CompositeRow
<CompositeRow
ref={ itemRef }
render={ <li /> }
role="row"
className={ clsx( {
Expand All @@ -86,7 +96,7 @@ function ListItem( {
>
<HStack className="dataviews-view-list__item-wrapper">
<div role="gridcell">
<Ariakit.CompositeItem
<CompositeItem
store={ store }
render={ <div /> }
role="button"
Expand Down Expand Up @@ -137,12 +147,12 @@ function ListItem( {
</div>
</VStack>
</HStack>
</Ariakit.CompositeItem>
</CompositeItem>
</div>
{ actions && (
<div role="gridcell">
<Ariakit.MenuProvider>
<Ariakit.CompositeItem
<CompositeItem
store={ store }
render={
<Ariakit.MenuButton>
Expand All @@ -157,7 +167,7 @@ function ListItem( {
</div>
) }
</HStack>
</Ariakit.CompositeRow>
</CompositeRow>
);
}

Expand Down Expand Up @@ -202,7 +212,7 @@ export default function ViewList( props: ListViewProps ) {
[ baseId, getItemId ]
);

const store = Ariakit.useCompositeStore( {
const store = useCompositeStore( {
defaultActiveId: getItemDomId( selectedItem ),
} );

Expand All @@ -223,7 +233,7 @@ export default function ViewList( props: ListViewProps ) {
}

return (
<Ariakit.Composite
<Composite
id={ baseId }
render={ <ul /> }
className="dataviews-view-list"
Expand All @@ -247,6 +257,6 @@ export default function ViewList( props: ListViewProps ) {
/>
);
} ) }
</Ariakit.Composite>
</Composite>
);
}

0 comments on commit e97be2b

Please sign in to comment.