How to use the draft-js.RichUtils.toggleInlineStyle function in draft-js

To help you get started, we’ve selected a few draft-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Foundry376 / Mailspring / app / src / components / composer-editor / text-style-plugin.jsx View on Github external
export function editorStateSettingTextStyle(editorState, groupPrefix, groupValue) {
  // TODO: Get all inine styles in selected area, not just at insertion point
  const currentStyle = editorState.getCurrentInlineStyle();
  const currentGroupKeys = currentStyle.filter(value => value.startsWith(groupPrefix));
  const nextGroupKey = groupValue ? `${groupPrefix}${groupValue}` : null;

  let nextEditorState = editorState;

  if (currentGroupKeys.count() !== 1 || currentGroupKeys[0] !== nextGroupKey) {
    for (const key of currentGroupKeys) {
      nextEditorState = RichUtils.toggleInlineStyle(nextEditorState, key);
    }
  }
  if (nextGroupKey) {
    nextEditorState = RichUtils.toggleInlineStyle(nextEditorState, nextGroupKey);
  }
  return nextEditorState;
}
github webdeveloperpr / draft-js-custom-styles / tests / index.spec.js View on Github external
it('should export custom + default + customStyleMap styles', () => {
    const editorState = new Raw()
      .addBlock('block 1')
      .anchorKey(0)
      .focusKey(5)
      .toEditorState();
    const newEditorStat1 = RichUtils.toggleInlineStyle(editorState, 'BOLD');
    const newEditorStat2 = RichUtils.toggleInlineStyle(newEditorStat1, 'MARK');
    const newEditorState3 = styles.color.add(newEditorStat2, 'red');
    const newEditorState4 = styles.backgroundColor.add(newEditorState3, 'green');
    const inlineStyles = exporter(newEditorState4);
    expect(inlineStyles).to.deep.equal({
      CUSTOM_COLOR_red: {
        style: {
          color: 'red',
        },
      },
      BOLD: {
        style: {
          fontWeight: 'bold',
        },
      },
      MARK: {
        style: {
github skovy / graphql-blog-client / src / containers / write / index.tsx View on Github external
private onItalicClick = () => {
    this.onChange(RichUtils.toggleInlineStyle(this.state.editorState, "ITALIC"));
  }
github brijeshb42 / medium-draft / src / createEditor.js View on Github external
_toggleInlineStyle(inlineStyle) {
      this.onChange(
        RichUtils.toggleInlineStyle(
          this.props.editorState,
          inlineStyle
        )
      );
    }
github Matterwiki / Matterwiki / client / app / components / WikiEditor / Toolbar.jsx View on Github external
_toggleInlineStyle(inlineStyle) {
		const {onChange, editorState} = this.props;

		onChange(
			RichUtils.toggleInlineStyle(
				editorState,
				inlineStyle
			)
		);
	}
github Beor18 / proyectos-con-react / demo005 / src / components / PageContainer.js View on Github external
onHighlight = () => {
        this.onChange(RichUtils.toggleInlineStyle(this.state.editorState, 'HIGHLIGHT'))
    }
github stuyspec / content-editor / lib / Toolbar.js View on Github external
const handleStyleChange = style => {
    onChange(RichUtils.toggleInlineStyle(editorState, style));
  };
  const handleBoldClick = event => {
github leejaen / react-lz-editor / src / editor / index.jsx View on Github external
nextEditorState = currentStyle.reduce((state, color) => {
        return RichUtils.toggleInlineStyle(state, color);
      }, nextEditorState);
    }
github strues / boldr / packages / frontend / BoldrText / components / FontFamily / FontFamily.js View on Github external
const { editorState, selection, currentInlineStyle, fontFamilies } = this.props;

    const nextContentState = fontFamilies.reduce((contentState, item) => {
      return Modifier.removeInlineStyle(contentState, selection, `FONTFAMILY-${item.name}`);
    }, editorState.getCurrentContent());

    let nextEditorState = EditorState.push(editorState, nextContentState, 'change-inline-style');

    if (selection.isCollapsed()) {
      nextEditorState = currentInlineStyle.reduce((state, fontFamily) => {
        return RichUtils.toggleInlineStyle(state, fontFamily);
      }, nextEditorState);
    }

    if (!currentInlineStyle.has(toggledFontFamily)) {
      nextEditorState = RichUtils.toggleInlineStyle(nextEditorState, toggledFontFamily);
    }

    this.props.onChange(nextEditorState);
  };
  render() {
github jay-ithiel / guild / src / components / editor / editor.jsx View on Github external
_toggleInlineStyle(inlineStyle) {
    this.onChange(
      RichUtils.toggleInlineStyle(this.props.editorState, inlineStyle)
    );
  }