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

Feat/dropdown expandable menu #1129

Merged
merged 11 commits into from
Oct 11, 2023
Merged
5 changes: 5 additions & 0 deletions .changeset/feat-dropdownExpandableMenu.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-magma-dom': minor
---

feat(DropdownExpandableMenu): A new menu item display for the Dropdown component which enables expandable lists by one level.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ export interface AccordionButtonProps
/**
* @internal
*/
hasCustomArray?: boolean;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name is really ambiguous. Can we think of something more specific and descriptive? Lets also add a comment for further clarity on how this prop should be used

theme?: ThemeInterface;
silvalaura marked this conversation as resolved.
Show resolved Hide resolved
}

const StyledButton = styled.button<{
hasCustomArray?: boolean;
silvalaura marked this conversation as resolved.
Show resolved Hide resolved
isInverse?: boolean;
isExpanded?: boolean;
}>`
Expand Down Expand Up @@ -90,7 +92,13 @@ export const AccordionButton = React.forwardRef<
HTMLButtonElement,
AccordionButtonProps
>((props, forwardedRef) => {
const { children, testId, isInverse: isInverseProp, ...rest } = props;
const {
children,
testId,
hasCustomArray,
isInverse: isInverseProp,
...rest
} = props;
const theme = React.useContext(ThemeContext);
const isInverse = useIsInverse(isInverseProp);

Expand Down Expand Up @@ -122,11 +130,12 @@ export const AccordionButton = React.forwardRef<
aria-expanded={Boolean(isExpanded)}
data-testid={testId}
disabled={isDisabled}
hasCustomArray={hasCustomArray}
silvalaura marked this conversation as resolved.
Show resolved Hide resolved
id={buttonId}
isExpanded={isExpanded}
isInverse={isInverse}
onClick={handleClick}
onKeyDown={handleKeyDown}
onKeyDown={hasCustomArray ? null : handleKeyDown}
ref={ref}
theme={theme}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,20 @@ import { Card, CardBody } from '../Card';
import { Input } from '../Input';
import { Checkbox } from '../Checkbox';
import { PasswordInput } from '../PasswordInput';
import { SettingsIcon, MenuIcon } from 'react-magma-icons';
import {
LocalPizzaIcon,
LunchDiningIcon,
MenuIcon,
RestaurantMenuIcon,
SettingsIcon,
} from 'react-magma-icons';
import { Story, Meta } from '@storybook/react/types-6-0';
import { Paragraph, Spacer } from '../..';
import { ButtonGroup } from '../ButtonGroup';
import { DropdownExpandableMenuButton } from './DropdownExpandableMenuButton';
import { DropdownExpandableMenuItem } from './DropdownExpandableMenuItem';
import { DropdownExpandableMenuGroup } from './DropdownExpandableMenuGroup';
import { DropdownExpandableMenuPanel } from './DropdownExpandableMenuPanel';

const Template: Story<DropdownProps> = args => (
<div style={{ margin: '150px auto', textAlign: 'center' }}>
Expand Down Expand Up @@ -407,3 +417,114 @@ export const NoItems = args => {
</ButtonGroup>
);
};

export const ExpandableItems = args => {
return (
<Dropdown {...args}>
<DropdownButton>Expandable Items Dropdown</DropdownButton>
<DropdownContent>
<DropdownExpandableMenuGroup>
<DropdownExpandableMenuItem>
<DropdownExpandableMenuButton>Pasta</DropdownExpandableMenuButton>
<DropdownExpandableMenuPanel>
<DropdownMenuItem>Fresh</DropdownMenuItem>
<DropdownMenuItem>Processed</DropdownMenuItem>
</DropdownExpandableMenuPanel>
</DropdownExpandableMenuItem>
<DropdownExpandableMenuItem>
<DropdownExpandableMenuButton>
Prosciutto
</DropdownExpandableMenuButton>
<DropdownExpandableMenuPanel>
<DropdownMenuItem>Domestic</DropdownMenuItem>
<DropdownMenuItem>Speck</DropdownMenuItem>
</DropdownExpandableMenuPanel>
</DropdownExpandableMenuItem>
</DropdownExpandableMenuGroup>
</DropdownContent>
</Dropdown>
);
};

export const ExpandableItemsWithIcons = args => {
return (
<Dropdown {...args} width={120}>
<DropdownButton>Expandable Items Dropdown</DropdownButton>
<DropdownContent>
<DropdownExpandableMenuGroup isMulti={false} defaultIndex={0}>
<DropdownExpandableMenuItem disabled>
<DropdownExpandableMenuButton icon={<RestaurantMenuIcon />}>
Pasta antidisestablishmentarianism Pasta Pasta Pasta Pasta Pasta
Pasta Pasta Pasta Pasta Pasta Pasta
</DropdownExpandableMenuButton>
<DropdownExpandableMenuPanel>
<DropdownMenuItem>Fresh</DropdownMenuItem>
<DropdownMenuItem>Processed</DropdownMenuItem>
</DropdownExpandableMenuPanel>
</DropdownExpandableMenuItem>
<DropdownExpandableMenuItem>
<DropdownExpandableMenuButton icon={<LunchDiningIcon />}>
Prosciutto
</DropdownExpandableMenuButton>
<DropdownExpandableMenuPanel>
<DropdownMenuItem>Domestic</DropdownMenuItem>
<DropdownMenuItem>Speck</DropdownMenuItem>
</DropdownExpandableMenuPanel>
</DropdownExpandableMenuItem>
</DropdownExpandableMenuGroup>
<DropdownDivider />
<DropdownMenuItem icon={<LocalPizzaIcon />}>Pizza</DropdownMenuItem>
</DropdownContent>
</Dropdown>
);
};

export const ExpandableItemsWithIconsAndConsoleWarning = args => {
return (
<Dropdown {...args} width={240}>
<DropdownButton>Expandable Items Dropdown</DropdownButton>
<DropdownContent>
<DropdownExpandableMenuGroup>
<DropdownExpandableMenuItem>
<DropdownExpandableMenuButton>Pasta</DropdownExpandableMenuButton>
<DropdownExpandableMenuPanel>
<DropdownMenuItem>Fresh</DropdownMenuItem>
<DropdownMenuItem>Processed</DropdownMenuItem>
</DropdownExpandableMenuPanel>
</DropdownExpandableMenuItem>
<DropdownExpandableMenuItem>
<DropdownExpandableMenuButton icon={<LunchDiningIcon />}>
Prosciutto
</DropdownExpandableMenuButton>
<DropdownExpandableMenuPanel>
<DropdownMenuItem>Domestic</DropdownMenuItem>
<DropdownMenuItem>Speck</DropdownMenuItem>
<DropdownExpandableMenuGroup>
<DropdownExpandableMenuItem>
<DropdownExpandableMenuButton icon={<RestaurantMenuIcon />}>
Pasta
</DropdownExpandableMenuButton>
<DropdownExpandableMenuPanel>
<DropdownMenuItem>Fresh</DropdownMenuItem>
<DropdownMenuItem>Processed</DropdownMenuItem>
</DropdownExpandableMenuPanel>
</DropdownExpandableMenuItem>
<DropdownExpandableMenuItem>
<DropdownExpandableMenuButton icon={<LunchDiningIcon />}>
Prosciutto
</DropdownExpandableMenuButton>
<DropdownExpandableMenuPanel>
<DropdownMenuItem>Domestic</DropdownMenuItem>
<DropdownMenuItem>Speck</DropdownMenuItem>
</DropdownExpandableMenuPanel>
</DropdownExpandableMenuItem>
</DropdownExpandableMenuGroup>
</DropdownExpandableMenuPanel>
</DropdownExpandableMenuItem>
</DropdownExpandableMenuGroup>
<DropdownDivider />
<DropdownMenuItem icon={<LocalPizzaIcon />}>Pizza</DropdownMenuItem>
</DropdownContent>
</Dropdown>
);
};
Loading