UNPKG

@atlaskit/editor-plugin-highlight

Version:

Highlight plugin for @atlaskit/editor-core

51 lines 2.29 kB
import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; import { useState } from 'react'; import { changeColor } from '../../editor-commands/change-color'; export var useDropdownEvents = function useDropdownEvents(args) { var toolbarItemRef = args.toolbarItemRef, setIsDropdownOpen = args.setIsDropdownOpen, isDropdownOpen = args.isDropdownOpen, pluginInjectionApi = args.pluginInjectionApi; var _useState = useState(false), _useState2 = _slicedToArray(_useState, 2), isOpenedByKeyboard = _useState2[0], setIsOpenedByKeyboard = _useState2[1]; return { handleClick: function handleClick() { setIsOpenedByKeyboard(false); setIsDropdownOpen(!isDropdownOpen); }, handleKeyDown: function handleKeyDown(event) { if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); setIsOpenedByKeyboard(true); setIsDropdownOpen(!isDropdownOpen); } }, handleClickOutside: function handleClickOutside() { if (isDropdownOpen) { setIsDropdownOpen(false); setIsOpenedByKeyboard(false); } }, handleEscapeKeydown: function handleEscapeKeydown() { if (isDropdownOpen) { var _toolbarItemRef$curre; setIsDropdownOpen(false); setIsOpenedByKeyboard(false); toolbarItemRef === null || toolbarItemRef === void 0 || (_toolbarItemRef$curre = toolbarItemRef.current) === null || _toolbarItemRef$curre === void 0 || _toolbarItemRef$curre.focus(); } }, handleColorChange: function handleColorChange(_ref) { var _pluginInjectionApi$c, _pluginInjectionApi$a; var color = _ref.color, inputMethod = _ref.inputMethod; pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c = pluginInjectionApi.core) === null || _pluginInjectionApi$c === void 0 || _pluginInjectionApi$c.actions.execute(changeColor(pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions)({ color: color, inputMethod: inputMethod })); setIsDropdownOpen(false); }, isOpenedByKeyboard: isOpenedByKeyboard }; };