Skip to content

Commit

Permalink
Substitute last bits of Ariakit by @wordpress/components
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed May 8, 2024
1 parent 4be2ebf commit f10e368
Showing 1 changed file with 47 additions and 20 deletions.
67 changes: 47 additions & 20 deletions packages/dataviews/src/view-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import clsx from 'clsx';
import * as Ariakit from '@ariakit/react';

/**
* WordPress dependencies
Expand Down Expand Up @@ -31,8 +30,14 @@ import type {
ViewList as ViewListType,
} from './types';

interface Action {
id: string;
label: string;
callback: ( items: Item[] ) => void;
}

interface ListViewProps {
actions: [];
actions: Action[];
data: Data;
fields: NormalizedField[];
getItemId: ( item: Item ) => string;
Expand All @@ -44,7 +49,7 @@ interface ListViewProps {
}

interface ListViewItemProps {
actions: [];
actions: Action[];
id?: string;
isSelected: boolean;
item: Item;
Expand All @@ -56,6 +61,10 @@ interface ListViewItemProps {
}

const {
DropdownMenuV2: DropdownMenu,
DropdownMenuGroupV2: DropdownMenuGroup,
DropdownMenuItemV2: DropdownMenuItem,
DropdownMenuItemLabelV2: DropdownMenuItemLabel,
CompositeV2: Composite,
CompositeItemV2: CompositeItem,
CompositeRowV2: CompositeRow,
Expand Down Expand Up @@ -153,23 +162,41 @@ function ListItem( {
</div>
{ actions && (
<div role="gridcell">
<Ariakit.MenuProvider>
<CompositeItem
store={ store }
render={
<Button
size="compact"
icon={ moreVertical }
label={ __( 'Actions' ) }
disabled={ ! actions.length }
className="dataviews-all-actions-button"
/>
}
/>
<Ariakit.Menu>
<Ariakit.MenuItem>Hello</Ariakit.MenuItem>
</Ariakit.Menu>
</Ariakit.MenuProvider>
<DropdownMenu
trigger={
<CompositeItem
store={ store }
render={
<Button
size="compact"
icon={ moreVertical }
label={ __( 'Actions' ) }
disabled={ ! actions.length }
className="dataviews-all-actions-button"
/>
}
/>
}
placement="bottom-end"
>
<DropdownMenuGroup>
{ actions.map( ( action: Action ) => {
return (
<DropdownMenuItem
key={ action.id }
action={ action }
onClick={ () =>
action.callback( [ item ] )
}
>
<DropdownMenuItemLabel>
{ action.label }
</DropdownMenuItemLabel>
</DropdownMenuItem>
);
} ) }
</DropdownMenuGroup>
</DropdownMenu>
</div>
) }
</HStack>
Expand Down

0 comments on commit f10e368

Please sign in to comment.