Git Product home page Git Product logo

gabepereira / expo-rich-text-editor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from siposdani87/expo-rich-text-editor

0.0 0.0 0.0 2.14 MB

This rich text editor is written in TypeScript and uses React Hooks structure. This component uses the HTML ContentEditable div feature and React communicate and send data to native JavaScript via WebView. It has basic text editing options.

License: MIT License

Shell 0.62% JavaScript 0.25% TypeScript 70.94% HTML 28.20%

expo-rich-text-editor's Introduction

@siposdani87/expo-rich-text-editor

Version Download License

Buy Me A Coffee

This rich text editor written in TypeScript and use React Hooks structure. This component use the HTML ContentEditable div feature and React communicate and send data to native JavaScript via WebView. It has base editing options.

Getting Started

Installing

npm install @siposdani87/expo-rich-text-editor

# Expo
expo install @siposdani87/expo-rich-text-editor

Basic Usage

Check example directory for more samples and options.

import { MaterialIcons } from '@expo/vector-icons';
import { RichTextEditor, RichTextViewer, ActionMap, ActionKey } from '@siposdani87/expo-rich-text-editor';

const htmlStr = '<p><i><u>Underline italic text</u></i> <b>bold word</b> normal words</p>';

export const RichTextComponents = () => {
    const [value, setValue] = useState('');

    const getColor = (selected: boolean): string => {
      return selected ? 'red' : 'black';
    };

    const getActionMap = (): ActionMap => {
        return {
            [ActionKey.bold]: ({ selected }) => (
                <MaterialIcons
                    name="format-bold"
                    size={14}
                    color={getColor(selected)}
                />
            ),
        };
    };

    const onValueChange = (v: string): void => {
        console.log('onValueChange', v);
        setValue(v);
    };

    return (
        <>
            <RichTextEditor
                minHeight={150}
                value={value}
                selectionColor="green"
                actionMap={getActionMap()}
                onValueChange={onValueChange}
                toolbarStyle={styles.toolbar}
                editorStyle={styles.editor}
            />

            <RichTextViewer value={htmlStr} editorStyle={styles.viewer} linkStyle={styles.link} />
        </>
    );
};

const styles = StyleSheet.create({
    viewer: {
        borderColor: 'green',
        borderWidth: 1,
        padding: 5,
        // fontFamily: 'Oswald_400Regular',
    },
    editor: {
        borderColor: 'blue',
        borderWidth: 1,
        padding: 5,
        // fontFamily: 'Inter_500Medium',
        fontSize: 18,
    },
    toolbar: {
        borderColor: 'red',
        borderWidth: 1,
    },
    link: {
        color: 'green',
    },
});

Props

RichTextEditor

Prop Type Description
value * string HTML string with standard tags eg.: p, b, strong, i, em, u, a, br
onValueChange * (value: string) => void Call this function on value changed
onFocus () => void Call this function on component focus
onBlur () => void Call this function on component blur
actionMap ActionMap Action config for toolbar component
editorStyle Style Style for editor container
linkStyle Style Style for link (a tag)
toolbarStyle Style Style for toolbar container
selectionColor string Color of text selection
minHeight number Min height of container
disabled boolean Disable editing on component
debug boolean Print debug information to console

RichTextViewer

Prop Type Description
value * string HTML string with standard tags eg.: p, b, strong, i, em, u, a, ul, ol, li, br
editorStyle Style Style for editor container
linkStyle Style Style for link (a tag)
debug boolean Print debug information to console

Preview

Overview

Bugs or Requests

If you encounter any problems feel free to open an issue. If you feel the library is missing a feature, please raise a ticket. Pull request are also welcome.

expo-rich-text-editor's People

Contributors

dsipos avatar siposdani87 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.