import React from 'react'; import { Component } from 'react'; import styled, { ThemeProvider } from 'styled-components'; import { gridSize } from '@atlaskit/theme/constants'; import { B400 } from '@atlaskit/theme/colors'; import Item, { itemThemeNamespace } from '@atlaskit/item'; import EditorDoneIcon from '@atlaskit/icon/glyph/editor/done'; import Tooltip from '@atlaskit/tooltip'; import { DropdownOptionT } from './types'; export const menuItemDimensions = { width: 175, height: 32, }; const Spacer = styled.span` display: flex; flex: 1; padding: 8px; `; const MenuContainer = styled.div` min-width: ${menuItemDimensions.width}px; `; const padding = gridSize(); export const itemSpacing = gridSize() / 2; const editorItemTheme = { borderRadius: 0, beforeItemSpacing: { compact: itemSpacing, }, padding: { compact: { bottom: padding, left: padding, right: padding, top: padding, }, }, height: { compact: menuItemDimensions.height, }, }; export interface Props { hide: Function; dispatchCommand: Function; items: Array>; } export default class Dropdown extends Component { render() { const { hide, dispatchCommand, items } = this.props; return ( {items .filter((item) => !item.hidden) .map((item, idx) => { const itemContent = ( { /** * The order of dispatching the event and hide() is important, because * the ClickAreaBlock will be relying on the element to calculate the * click coordinate. * For more details, please visit the comment in this PR https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/5328/edm-1321-set-selection-near-smart-link?link_source=email#chg-packages/editor/editor-core/src/plugins/floating-toolbar/ui/DropdownMenu.tsx */ dispatchCommand(item.onClick); hide(); }} data-testid={item.testId} isDisabled={item.disabled} > {item.title} ); if (item.tooltip) { return ( {itemContent} ); } return itemContent; })} ); } private renderSelected(item: DropdownOptionT) { const { selected } = item; if (selected !== undefined) { return selected ? ( ) : ( ); } return; } }