diff --git a/.storybook/preview-body.html b/.storybook/preview-body.html new file mode 100644 index 000000000..a9676ff1f --- /dev/null +++ b/.storybook/preview-body.html @@ -0,0 +1,2 @@ +
+
diff --git a/ui/app/components/app/connected-accounts-list/connected-accounts-list-options-item/connected-accounts-list-options-item.component.js b/ui/app/components/app/connected-accounts-list/connected-accounts-list-options-item/connected-accounts-list-options-item.component.js deleted file mode 100644 index e1fe4e167..000000000 --- a/ui/app/components/app/connected-accounts-list/connected-accounts-list-options-item/connected-accounts-list-options-item.component.js +++ /dev/null @@ -1,26 +0,0 @@ -import classnames from 'classnames' -import PropTypes from 'prop-types' -import React, { PureComponent } from 'react' - -export default class ConnectedAccountsListOptionsItem extends PureComponent { - static propTypes = { - iconClassNames: PropTypes.string.isRequired, - children: PropTypes.node.isRequired, - onClick: PropTypes.func, - } - - static defaultProps = { - onClick: undefined, - } - - render () { - const { children, iconClassNames, onClick } = this.props - - return ( - - ) - } -} diff --git a/ui/app/components/app/connected-accounts-list/connected-accounts-list-options-item/index.js b/ui/app/components/app/connected-accounts-list/connected-accounts-list-options-item/index.js deleted file mode 100644 index fd9f7f347..000000000 --- a/ui/app/components/app/connected-accounts-list/connected-accounts-list-options-item/index.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from './connected-accounts-list-options-item.component' diff --git a/ui/app/components/app/connected-accounts-list/connected-accounts-list-options/connected-accounts-list-options.component.js b/ui/app/components/app/connected-accounts-list/connected-accounts-list-options/connected-accounts-list-options.component.js index de7b5411c..0fcc2d818 100644 --- a/ui/app/components/app/connected-accounts-list/connected-accounts-list-options/connected-accounts-list-options.component.js +++ b/ui/app/components/app/connected-accounts-list/connected-accounts-list-options/connected-accounts-list-options.component.js @@ -1,34 +1,23 @@ import PropTypes from 'prop-types' -import React, { useRef, useState } from 'react' -import { createPortal } from 'react-dom' -import { usePopper } from 'react-popper' +import React, { useState } from 'react' +import { Menu } from '../../../ui/menu' const ConnectedAccountsListOptions = ({ children, onShowOptions, onHideOptions, show }) => { const [optionsButtonElement, setOptionsButtonElement] = useState(null) - const [popperElement, setPopperElement] = useState(null) - const popoverContainerElement = useRef(document.getElementById('popover-content')) - const { attributes, styles } = usePopper(optionsButtonElement, popperElement, { - modifiers: [{ name: 'preventOverflow', options: { altBoundary: true } }], - }) return ( <> +) + +MenuItem.propTypes = { + children: PropTypes.node.isRequired, + className: PropTypes.string, + iconClassName: PropTypes.string, + onClick: PropTypes.func, +} + +MenuItem.defaultProps = { + className: undefined, + iconClassName: undefined, + onClick: undefined, +} + +export default MenuItem diff --git a/ui/app/components/ui/menu/menu.js b/ui/app/components/ui/menu/menu.js new file mode 100644 index 000000000..8fa40f508 --- /dev/null +++ b/ui/app/components/ui/menu/menu.js @@ -0,0 +1,43 @@ +import PropTypes from 'prop-types' +import React, { useRef, useState } from 'react' +import { createPortal } from 'react-dom' +import { usePopper } from 'react-popper' +import classnames from 'classnames' + +const Menu = ({ anchorElement, children, className, onHide, popperOptions }) => { + const [popperElement, setPopperElement] = useState(null) + const popoverContainerElement = useRef(document.getElementById('popover-content')) + + const { attributes, styles } = usePopper(anchorElement, popperElement, popperOptions) + + return createPortal( + <> +
+
+ { children } +
+ , + popoverContainerElement.current + ) +} + +Menu.propTypes = { + anchorElement: PropTypes.instanceOf(window.Element), + children: PropTypes.node.isRequired, + className: PropTypes.string, + onHide: PropTypes.func.isRequired, + popperOptions: PropTypes.object, +} + +Menu.defaultProps = { + anchorElement: undefined, + className: undefined, + popperOptions: undefined, +} + +export default Menu diff --git a/ui/app/components/ui/menu/menu.scss b/ui/app/components/ui/menu/menu.scss new file mode 100644 index 000000000..de6dc6108 --- /dev/null +++ b/ui/app/components/ui/menu/menu.scss @@ -0,0 +1,46 @@ +.menu { + &__container { + background: $white; + box-shadow: 0 2px 10px rgba(0, 0, 0, 0.214); + border-radius: 8px; + width: 225px; + color: $Black-100; + display: flex; + flex-direction: column; + align-items: center; + padding: 0 16px; + + font-family: Roboto, 'sans-serif'; + font-size: 14px; + font-weight: normal; + line-height: 20px; + + z-index: 1050; + } + + &__background { + position: absolute; + top: 0; + left: 0; + width: 100vw; + height: 100vh; + z-index: 1050; + } +} + +.menu-item { + background: none; + font-family: inherit; + font-size: inherit; + + display: flex; + flex-direction: row; + align-items: center; + width: 100%; + padding: 14px 0; + cursor: pointer; + + &__icon { + margin-right: 8px; + } +} diff --git a/ui/app/components/ui/menu/menu.stories.js b/ui/app/components/ui/menu/menu.stories.js new file mode 100644 index 000000000..ec8822d62 --- /dev/null +++ b/ui/app/components/ui/menu/menu.stories.js @@ -0,0 +1,36 @@ +import React, { useState } from 'react' +import { Menu, MenuItem } from '.' +import { action } from '@storybook/addon-actions' + +export default { + title: 'Menu', +} + +export const basic = () => { + return ( + + Menu Item 1 + Menu Item 2 + Menu Item 3 + + ) +} + +export const anchored = () => { + const [anchorElement, setAnchorElement] = useState(null) + return ( + <> + + + Menu Item 1 + Menu Item 2 + Menu Item 3 + + + ) +}