2021-02-04 19:15:23 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2023-02-15 15:39:46 +01:00
|
|
|
import React, { useRef } from 'react';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { Menu } from '../../../ui/menu';
|
2023-02-15 15:39:46 +01:00
|
|
|
import { ButtonIcon, ICON_NAMES } from '../../../component-library';
|
|
|
|
import { useI18nContext } from '../../../../hooks/useI18nContext';
|
2020-05-15 20:53:52 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const ConnectedAccountsListOptions = ({
|
|
|
|
children,
|
|
|
|
onShowOptions,
|
|
|
|
onHideOptions,
|
|
|
|
show,
|
|
|
|
}) => {
|
2023-02-15 15:39:46 +01:00
|
|
|
const ref = useRef(false);
|
|
|
|
const t = useI18nContext();
|
2020-05-15 20:53:52 +02:00
|
|
|
|
Improve account options menu (#8607)
The account options menu is now much faster, and it correctly closes
when 'Switch account' is selected.
A static width had to be set on the menu so that it could be positioned
reliably. Without this width set, it was rendered as a different size
before positioning than after, which resulted in it being positioned
incorrectly. A `z-index` had to be added (equal to the `z-index` used
by the popover component) to ensure it wasn't rendered beneath the
popover.
The menu is automatically positioned relative to the account options
button, appearing below the button by default but above it instead if
there isn't room below. It is positioned to be inside the bounds of the
popover as well.
The account options button is now a `<button>` rather than a `<i>`.
This required a few additional style rules to overrule the default
button styles. Additionally the size was increased so that it matches
the designs more closely.
The callbacks for connecting, disconnecting, and switching accounts
have been updated to use state and props to determine the correct
address to use, rather than being bound to the correct address
parameter in the render function. This means we aren't creating a new
function upon each render anymore.
The `showAccountOptions` method still needs to be bound once per
account, but this was switched to use more readable syntax (`.bind`,
instead of the double arrow function).
`react-popper` and `@popperjs/core` were both added as dependencies.
These should be used for any UI requiring relative positioning (e.g.
tooltips, menus, etc.). Older versions of these libraries are already
in our codebase as transitive dependencies of the tooltip library we're
using.
2020-05-18 19:51:29 +02:00
|
|
|
return (
|
2023-02-15 15:39:46 +01:00
|
|
|
<div ref={ref}>
|
|
|
|
<ButtonIcon
|
|
|
|
iconName={ICON_NAMES.MORE_VERTICAL}
|
|
|
|
className="connected-accounts-options__button"
|
2020-11-03 00:41:28 +01:00
|
|
|
onClick={onShowOptions}
|
2023-02-15 15:39:46 +01:00
|
|
|
ariaLabel={t('options')}
|
2020-11-03 00:41:28 +01:00
|
|
|
/>
|
|
|
|
{show ? (
|
|
|
|
<Menu
|
2023-02-15 15:39:46 +01:00
|
|
|
anchorElement={ref.current}
|
2020-11-03 00:41:28 +01:00
|
|
|
onHide={onHideOptions}
|
|
|
|
popperOptions={{
|
|
|
|
modifiers: [
|
|
|
|
{ name: 'preventOverflow', options: { altBoundary: true } },
|
|
|
|
],
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</Menu>
|
|
|
|
) : null}
|
2023-02-15 15:39:46 +01:00
|
|
|
</div>
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
Improve account options menu (#8607)
The account options menu is now much faster, and it correctly closes
when 'Switch account' is selected.
A static width had to be set on the menu so that it could be positioned
reliably. Without this width set, it was rendered as a different size
before positioning than after, which resulted in it being positioned
incorrectly. A `z-index` had to be added (equal to the `z-index` used
by the popover component) to ensure it wasn't rendered beneath the
popover.
The menu is automatically positioned relative to the account options
button, appearing below the button by default but above it instead if
there isn't room below. It is positioned to be inside the bounds of the
popover as well.
The account options button is now a `<button>` rather than a `<i>`.
This required a few additional style rules to overrule the default
button styles. Additionally the size was increased so that it matches
the designs more closely.
The callbacks for connecting, disconnecting, and switching accounts
have been updated to use state and props to determine the correct
address to use, rather than being bound to the correct address
parameter in the render function. This means we aren't creating a new
function upon each render anymore.
The `showAccountOptions` method still needs to be bound once per
account, but this was switched to use more readable syntax (`.bind`,
instead of the double arrow function).
`react-popper` and `@popperjs/core` were both added as dependencies.
These should be used for any UI requiring relative positioning (e.g.
tooltips, menus, etc.). Older versions of these libraries are already
in our codebase as transitive dependencies of the tooltip library we're
using.
2020-05-18 19:51:29 +02:00
|
|
|
|
|
|
|
ConnectedAccountsListOptions.propTypes = {
|
|
|
|
children: PropTypes.node.isRequired,
|
|
|
|
onHideOptions: PropTypes.func.isRequired,
|
|
|
|
onShowOptions: PropTypes.func.isRequired,
|
|
|
|
show: PropTypes.bool.isRequired,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
Improve account options menu (#8607)
The account options menu is now much faster, and it correctly closes
when 'Switch account' is selected.
A static width had to be set on the menu so that it could be positioned
reliably. Without this width set, it was rendered as a different size
before positioning than after, which resulted in it being positioned
incorrectly. A `z-index` had to be added (equal to the `z-index` used
by the popover component) to ensure it wasn't rendered beneath the
popover.
The menu is automatically positioned relative to the account options
button, appearing below the button by default but above it instead if
there isn't room below. It is positioned to be inside the bounds of the
popover as well.
The account options button is now a `<button>` rather than a `<i>`.
This required a few additional style rules to overrule the default
button styles. Additionally the size was increased so that it matches
the designs more closely.
The callbacks for connecting, disconnecting, and switching accounts
have been updated to use state and props to determine the correct
address to use, rather than being bound to the correct address
parameter in the render function. This means we aren't creating a new
function upon each render anymore.
The `showAccountOptions` method still needs to be bound once per
account, but this was switched to use more readable syntax (`.bind`,
instead of the double arrow function).
`react-popper` and `@popperjs/core` were both added as dependencies.
These should be used for any UI requiring relative positioning (e.g.
tooltips, menus, etc.). Older versions of these libraries are already
in our codebase as transitive dependencies of the tooltip library we're
using.
2020-05-18 19:51:29 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
export default ConnectedAccountsListOptions;
|