UNPKG

kedao

Version:

Rich Text Editor Based On Draft.js

48 lines (47 loc) 2.72 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, { useRef } from 'react'; import { toggleSelectionFontSize, selectionHasInlineStyle } from '../../utils'; import styles from "./style.module.css"; import { defaultFontSizes } 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 FontSizePicker = ({ fontSizes = defaultFontSizes, defaultCaption, getContainerNode, editorState, onChange, disabled, onRequestFocus }) => { let caption = null; let currentFontSize = null; const dropDownInstance = useRef(null); fontSizes.find((item) => { if (selectionHasInlineStyle(editorState, `FONTSIZE-${item}`)) { caption = item; currentFontSize = item; return true; } return false; }); const toggleFontSize = (event) => { const fontSize = event.currentTarget.dataset.size; onChange(toggleSelectionFontSize(editorState, fontSize)); onRequestFocus(); return true; }; const language = useLanguage(); return (React.createElement(DropDown, { autoHide: true, caption: caption || defaultCaption, getContainerNode: getContainerNode, title: language.controls.fontSize, disabled: disabled, ref: dropDownInstance, className: cls('kedao-font-size-dropdown') }, React.createElement("ul", { className: cls('kedao-font-sizes') }, fontSizes.map((item) => { return (React.createElement("li", { key: item, role: "presentation", className: cls(item === currentFontSize ? 'active' : null), "data-size": item, onClick: (event) => { var _a; toggleFontSize(event); (_a = dropDownInstance.current) === null || _a === void 0 ? void 0 : _a.hide(); } }, item)); })))); }; export default FontSizePicker;