@atlaskit/editor-plugin-highlight
Version:
Highlight plugin for @atlaskit/editor-core
58 lines (57 loc) • 2.58 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useDropdownEvents = void 0;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _react = require("react");
var _changeColor = require("../../editor-commands/change-color");
var useDropdownEvents = exports.useDropdownEvents = function useDropdownEvents(args) {
var toolbarItemRef = args.toolbarItemRef,
setIsDropdownOpen = args.setIsDropdownOpen,
isDropdownOpen = args.isDropdownOpen,
pluginInjectionApi = args.pluginInjectionApi;
var _useState = (0, _react.useState)(false),
_useState2 = (0, _slicedToArray2.default)(_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((0, _changeColor.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
};
};