Code Monkey home page Code Monkey logo

remirror's Introduction


remirror



Azure DevOps builds  Travis (.com) Code Climate maintainability  Code Climate technical debt GitHub commit activity  GitHub last commit GitHub issues  GitHub pull requests GitHub stars  GitHub tag (latest SemVer)  LICENSE  Netlify Status



Remirror is your toolkit for building world-class text-editors which run on the web, mobile and desktop.



Getting Started

⚠️Warning: This is still a prerelease library. The docs are poor and the API is subject to change. Over the next few months the quality will be bumped up and the use cases will grow.

For now to learn and understand, the best way is via looking through the @remirror/ui-* libraries.

Prerequisites

  • Typescript >= 3.4
  • React >= 16.8
  • Yarn >= 1.13

Epic Mode Heart Example

Installation

yarn add @remirror/core @remirror/react @remirror/core-extensions

The following is a small example which renders a floating menu and enables the extensions Bold, Italic and Underline.

import React, { FC, FunctionComponent, MouseEventHandler, useState } from 'react';

import { memoize, EMPTY_OBJECT_NODE } from '@remirror/core';
import { Bold, Italic, Underline } from '@remirror/core-extensions';
import {
  bubblePositioner,
  ManagedRemirrorEditor,
  RemirrorEventListener,
  RemirrorExtension,
  RemirrorManager,
  RemirrorProps,
  useRemirrorContext,
} from '@remirror/react';

const runAction = (action: () => void): MouseEventHandler<HTMLElement> => e => {
  e.preventDefault();
  action();
};

const SimpleFloatingMenu: FC = () => {
  const { getPositionerProps, actions } = useRemirrorContext(); // Pull in injected props from context

  const props = getPositionerProps({
    positionerId: 'bubble',
    ...bubblePositioner,
  });
  return (
    <div
      style={{
        position: 'absolute',
        bottom: props.isActive ? props.bottom : -9999,
        left: props.isActive ? props.left : -9999,
      }}
      ref={props.ref}
    >
      <button
        style={{
          backgroundColor: actions.bold.isActive() ? 'white' : 'pink',
          fontWeight: actions.bold.isActive() ? 600 : 300,
        }}
        disabled={!actions.bold.isEnabled()}
        onClick={runAction(actions.bold.command)}
      >
        b
      </button>
      <button
        style={{
          backgroundColor: actions.italic.isActive() ? 'white' : 'pink',
          fontWeight: actions.italic.isActive() ? 600 : 300,
        }}
        disabled={!actions.italic.isEnabled()}
        onClick={runAction(actions.italic.command)}
      >
        i
      </button>
      <button
        style={{
          backgroundColor: actions.underline.isActive() ? 'white' : 'pink',
          fontWeight: actions.underline.isActive() ? 600 : 300,
        }}
        disabled={!actions.underline.isEnabled()}
        onClick={runAction(actions.underline.command)}
      >
        u
      </button>
    </div>
  );
};

const EditorLayout: FunctionComponent = () => {
  return (
    <RemirrorManager>
      <RemirrorExtension Constructor={Bold} />
      <RemirrorExtension Constructor={Italic} />
      <RemirrorExtension Constructor={Underline} />
      <ManagedRemirrorEditor
        attributes={{ 'data-test-id': 'editor-instance' }}
        onChange={onChange}
        placeholder='Start typing for magic...'
        autoFocus={true}
        initialContent={EMPTY_OBJECT_NODE}
      >
        <SimpleFloatingMenu />
      </ManagedRemirrorEditor>
    </RemirrorManager>
  );
};

The above example uses hooks but you can just as easily rely on Higher Order Components (HOC's) to wrap your component.

In a similar fashion Higher Order Components (HOC's) can be used to wrap a component.

import { withRemirror } from '@remirror/react';

// ...

function SimpleMenu({ getPositionerProps }: InjectedRemirrorProps) {
  return <Menu {...getPositionerProps()} />;
}

export const WrappedSimpleMenu = withRemirror(SimpleMenu);

Quick Demos

Heart Effect

import { EpicMode, heartEffect, ParticleEffect } from '@remirror/extension-epic-mode';

interface EpicModeComponentProps {
  particleEffect: ParticleEffect;
  placeholder: string;
  shake?: boolean;
}

const EpicModeComponent: FC<EpicModeComponentProps> = ({ particleEffect, placeholder, shake }) => {
  return (
    <div style={{ gridArea: 'editor' }}>
      <RemirrorManager>
        <RemirrorExtension Constructor={Bold} />
        <RemirrorExtension Constructor={Italic} />
        <RemirrorExtension Constructor={Underline} />
        <RemirrorExtension Constructor={EpicMode} particleEffect={particleEffect} shake={shake} />
        <ManagedRemirrorEditor
          autoFocus={true}
          attributes={{ 'data-test-id': 'editor-instance' }}
          placeholder={placeholder}
          editorStyles={editorStyles}
        />
      </RemirrorManager>
    </div>
  );
};

export const EpicModeHeart: FunctionComponent = () => (
  <EpicModeComponent particleEffect={heartEffect} shake={false} placeholder='Type for hearts' />
);

Epic Mode Heart Example

Twitter

Twitter UI Example


Testing

From the root of this repository run the following to trigger a full typecheck, linting and jest tests.

yarn checks

By default these checks are run on every push. To prevent these hooks from running by default simply run:

yarn stop:hooks

This copies .config.sample.json to .config.json. This file is read before hooks are run and can cancel checks when configured.

To resume per-commit / per-push checks run:

yarn start:hooks

Built With

  • React - The web framework used
  • Prosemirror - A beautiful and elegant text editor for DOM environments.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests.

Versioning

This project uses SemVer for versioning. For the versions available, see the tags on this repository.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

  • The api and Many ideas were stolen borrowed from tiptap which is a prosemirror editor for Vue. The concept of extensions and a lot of the early code was a direct port from this library.
  • At the time I started thinking about building an editor Slate didn't have great support for Android devices (they've since addressed this here)

remirror's People

Contributors

ifiokjr avatar renovate-bot avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.