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

[MenuGroup] Converted to a functional component #2536

Merged
merged 3 commits into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@

### Code quality

- Converted `MenuGroup` into a functional component ([#2536](https://github.com/Shopify/polaris-react/pull/2536))

### Deprecations
82 changes: 39 additions & 43 deletions src/components/ActionMenu/components/MenuGroup/MenuGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, {useCallback} from 'react';

import {MenuGroupDescriptor} from '../../../../types';

Expand All @@ -19,51 +19,47 @@ export interface MenuGroupProps extends MenuGroupDescriptor {
onClose(title: string): void;
}

export class MenuGroup extends React.Component<MenuGroupProps, never> {
render() {
const {
accessibilityLabel,
active,
actions,
details,
title,
icon,
} = this.props;

if (!actions.length) {
return null;
}
export function MenuGroup({
accessibilityLabel,
active,
actions,
details,
title,
icon,
onClose,
onOpen,
}: MenuGroupProps) {
const handleClose = useCallback(() => {
onClose(title);
}, [onClose, title]);

const popoverActivator = (
<MenuAction
disclosure
content={title}
icon={icon}
accessibilityLabel={accessibilityLabel}
onAction={this.handleOpen}
/>
);
const handleOpen = useCallback(() => {
onOpen(title);
}, [onOpen, title]);

return (
<Popover
active={Boolean(active)}
activator={popoverActivator}
preferredAlignment="left"
onClose={this.handleClose}
>
<ActionList items={actions} onActionAnyItem={this.handleClose} />
{details && <div className={styles.Details}>{details}</div>}
</Popover>
);
if (!actions.length) {
return null;
}

private handleClose = () => {
const {title, onClose} = this.props;
onClose(title);
};
const popoverActivator = (
<MenuAction
disclosure
content={title}
icon={icon}
accessibilityLabel={accessibilityLabel}
onAction={handleOpen}
/>
);

private handleOpen = () => {
const {title, onOpen} = this.props;
onOpen(title);
};
return (
<Popover
active={Boolean(active)}
activator={popoverActivator}
preferredAlignment="left"
onClose={handleClose}
>
<ActionList items={actions} onActionAnyItem={handleClose} />
{details && <div className={styles.Details}>{details}</div>}
</Popover>
);
}