import React from 'react' import { css } from 'styled-components' import { head, isEmpty } from 'fp-ts/lib/Array' import { isNone, Option } from 'fp-ts/lib/Option' import { PopOver } from '@monorail/metaComponents/popOver/PopOver' import { Button, ButtonProps } from '@monorail/visualComponents/buttons/Button' import { ButtonDisplay, ButtonSize, } from '@monorail/visualComponents/buttons/buttonTypes' import { IconButton } from '@monorail/visualComponents/buttons/IconButton' import { ButtonsBar } from '@monorail/visualComponents/buttonsBar/ButtonsBar' import { SimpleListItem, SimpleListItemProps, } from '@monorail/visualComponents/list/List' import { Menu } from '@monorail/visualComponents/menu/Menu' const overrides = { button: css` margin-left: auto; `, } /** * The onClick event is for clicking the button, not the list item * in the dropdown. The logic for clicking the list item is handled * in this component. */ export type DropdownButtonListItem = Omit< Partial, 'onClick' | 'primaryText' > & { onClick: (event: React.MouseEvent) => void primaryText: SimpleListItemProps['primaryText'] } export type Props = { listItems: Array } & Partial> type State = { selectedListItem: Option } export const DropdownButton = ({ listItems, disabled }: Props) => { const selectedListItem = head(listItems) /** * you can't have a DropdownButton if there are no items, therefore * there must be at least one item in the list and * selectedListItem will always be of type some */ if (isEmpty(listItems) || isNone(selectedListItem)) { return null } return ( ( {listItems.map((listItem, idx) => ( { listItem.onClick(e) popOverProps.onClick(e) }} /> ))} )} toggle={toggleProps => { const selectedListItemValue = selectedListItem.value return ( ) }} /> ) }