UNPKG

kedao

Version:

Rich Text Editor Based On Draft.js

48 lines (47 loc) 2.75 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { classNameParser } from '../../utils/style'; import React from 'react'; import { toggleSelectionLineHeight, selectionHasInlineStyle } from '../../utils'; import styles from "./style.module.css"; import { defaultLineHeights } from '../../constants'; import loadable from '@loadable/component'; import useLanguage from '../../hooks/use-language'; const DropDown = loadable(() => __awaiter(void 0, void 0, void 0, function* () { return yield import('../DropDown'); })); const cls = classNameParser(styles); const LineHeightPicker = ({ lineHeights = defaultLineHeights, defaultCaption, getContainerNode, onChange, onRequestFocus, disabled, editorState }) => { let caption = null; let currentLineHeight = null; const dropDownInstance = React.createRef(); lineHeights.find((item) => { if (selectionHasInlineStyle(editorState, `LINEHEIGHT-${item}`)) { caption = item; currentLineHeight = item; return true; } return false; }); const toggleLineHeight = (event) => { const lineHeight = event.currentTarget.dataset.size; onChange(toggleSelectionLineHeight(editorState, lineHeight)); onRequestFocus(); return true; }; const language = useLanguage(); return (React.createElement(DropDown, { autoHide: true, caption: caption || defaultCaption, getContainerNode: getContainerNode, title: language.controls.lineHeight, disabled: disabled, ref: dropDownInstance, className: cls('kedao-line-height-dropdown') }, React.createElement("ul", { className: cls('kedao-line-heights') }, lineHeights.map((item) => { return (React.createElement("li", { key: item, role: "presentation", className: cls(item === currentLineHeight ? 'active' : null), "data-size": item, onClick: (event) => { var _a; toggleLineHeight(event); (_a = dropDownInstance.current) === null || _a === void 0 ? void 0 : _a.hide(); } }, item)); })))); }; export default LineHeightPicker;