Skip to content

Commit

Permalink
fix(react): added storybook example and modified cypress test
Browse files Browse the repository at this point in the history
added storybook example and modified cypress test for popover menu
  • Loading branch information
cd3859 committed Feb 25, 2025
1 parent 89ab8ec commit 56c1e24
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export const PopoverDropdown = () => {
/>
</IcPopoverMenu>
<IcPopoverMenu submenuId="actions" aria-label="popover">
<IcMenuItem label="Edit" />
<IcMenuItem label="Find" />
<IcMenuItem label="Delete" variant="destructive" />
<IcMenuItem id="edit-id" label="Edit" />
<IcMenuItem id="find-id" label="Find" />
<IcMenuItem id="delete-id" label="Delete" variant="destructive" />
</IcPopoverMenu>
</>
</div>
Expand Down
70 changes: 70 additions & 0 deletions packages/react/src/stories/ic-popover-menu.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,76 @@ export const TopPlacement = {
name: "Top placement",
};

export const DynamicPopover = {
render:(args) => {
const furtherWorkCheckboxNames = [
{ checkboxName: "beans", verb: "grind"},
{checkboxName: "coffee", verb: "drink"}
];

const parentItems = furtherWorkCheckboxNames.map(({ checkboxName, verb }) => (
<IcMenuItem
id={`bulk-${checkboxName.toLowerCase()}-menu`}
key={`${checkboxName}Menu`}
label={`${checkboxName} ${verb}`}
submenuTriggerFor={checkboxName.toLowerCase()}
/>
));

const submenus = furtherWorkCheckboxNames.map((tagCheckboxName) => {
const { checkboxName, verb } = tagCheckboxName;
return (
<IcPopoverMenu
key={`${checkboxName}Menu`}
submenuId={checkboxName.toLowerCase()}
>
<IcMenuItem
id={`bulk-${checkboxName.toLocaleLowerCase()}-add`}
label={`${checkboxName} ${verb}`}
/>
<IcMenuItem
id={`bulk-${checkboxName.toLocaleLowerCase()}-remove`}
label={`${checkboxName} not ${verb}`}
/>
</IcPopoverMenu>
);
})

function buttonClick() {
document.querySelector("ic-popover-menu").open =
!document.querySelector("ic-popover-menu").open;
}
return (
<>
<IcButton id="button-dynamic" onClick={buttonClick}>
Show/Hide popover
</IcButton>
<IcPopoverMenu
id="dynamic-popover"
anchor="button-dynamic"
aria-label="popover"
open="false"
>
<IcMenuGroup id="bulk-management" label="Bulk Actions">
{parentItems}
</IcMenuGroup>

<IcMenuGroup>
<IcMenuItem
id="bulk-remove"
label="Remove Items"
variant="destructive"
/>
</IcMenuGroup>

</IcPopoverMenu>
{submenus}
</>
)
},
name: "Dynamic popover",
}

export const Playground = {
render: (args) => (
<div>
Expand Down

0 comments on commit 56c1e24

Please sign in to comment.