UNPKG

@kedao/editor

Version:

Rich Text Editor Based On Draft.js

50 lines 2.06 kB
import React from 'react'; import PropTypes from 'prop-types'; import { v4 as uuidv4 } from 'uuid'; import { ContentUtils } from '@kedao/utils'; import DropDown from '../../common/DropDown'; import './style.scss'; const toggleFontSize = (event, props) => { let fontSize = event.currentTarget.dataset.size; const hookReturns = props.hooks('toggle-font-size', fontSize)(fontSize); if (hookReturns === false) { return false; } if (!isNaN(fontSize)) { fontSize = hookReturns; } props.editor.setValue(ContentUtils.toggleSelectionFontSize(props.editorState, fontSize)); props.editor.requestFocus(); return true; }; const FontSize = (props) => { let caption = null; let currentFontSize = null; let dropDownInstance = null; props.fontSizes.find((item) => { if (ContentUtils.selectionHasInlineStyle(props.editorState, `FONTSIZE-${item}`)) { caption = item; currentFontSize = item; return true; } return false; }); return (React.createElement(DropDown, { autoHide: true, caption: caption || props.defaultCaption, getContainerNode: props.getContainerNode, title: props.language.controls.fontSize, // eslint-disable-next-line no-return-assign ref: (instance) => (dropDownInstance = instance), className: "control-item dropdown bf-font-size-dropdown" }, React.createElement("ul", { className: "bf-font-sizes" }, props.fontSizes.map((item) => { return (React.createElement("li", { key: uuidv4(), role: "presentation", className: item === currentFontSize ? 'active' : null, "data-size": item, onClick: (event) => { toggleFontSize(event, props); dropDownInstance.hide(); } }, item)); })))); }; FontSize.propTypes = { fontSizes: PropTypes.any, editorState: PropTypes.any, defaultCaption: PropTypes.any, getContainerNode: PropTypes.any, language: PropTypes.any }; export default FontSize; //# sourceMappingURL=index.js.map