- handleSelection(id as string, event)} - closeOnSelection={false} - > - - -
    - {Object.keys(items).map((id) => { - const item = items[id]; - return
  • - - {item.text} - -
  • ; - })} -
-
-
+
diff --git a/src/components/LayerEditorMenu.tsx b/src/components/LayerEditorMenu.tsx new file mode 100644 index 00000000..c413867c --- /dev/null +++ b/src/components/LayerEditorMenu.tsx @@ -0,0 +1,48 @@ +import classnames from "classnames"; +import { useSelect } from "downshift"; +import { MdMoreVert } from "react-icons/md"; + +export type LayerEditorMenuItem = { + text: string + handler: () => void + disabled?: boolean + wdKey: string +}; + +type LayerEditorMenuProps = { + items: LayerEditorMenuItem[] +}; + +export function LayerEditorMenu({ items }: LayerEditorMenuProps) { + const { isOpen, highlightedIndex, getToggleButtonProps, getMenuProps, getItemProps } = useSelect({ + items, + itemToString: (item) => item?.text ?? "", + isItemDisabled: (item) => !!item.disabled, + toggleButtonId: "skip-target-layer-editor", + // Nothing stays selected, so picking the same action twice runs it twice. + selectedItem: null, + onSelectedItemChange: ({ selectedItem }) => selectedItem?.handler(), + }); + + return
+ + + + +
; +} diff --git a/src/styles/_layer.scss b/src/styles/_layer.scss index e7951bd4..689a5552 100644 --- a/src/styles/_layer.scss +++ b/src/styles/_layer.scss @@ -295,15 +295,10 @@ z-index: 9999; background: vars.$color-black; border: solid 1px vars.$color-midgray; - right: 0; + inset-inline-end: 0; min-width: 120px; } - [dir="rtl"] &__menu { - left: 0; - right: auto; - } - &__button__svg { width: 24px; height: 24px; @@ -311,6 +306,16 @@ &__menu__item { padding: 4px; + cursor: pointer; + + &--highlighted { + background: vars.$color-midgray; + } + + &[aria-disabled="true"] { + cursor: default; + opacity: 0.5; + } } }