Socket
Book a DemoInstallSign in
Socket

@siposdani87/expo-rich-text-editor

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@siposdani87/expo-rich-text-editor

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.

latest
Source
npmnpm
Version
1.0.9
Version published
Weekly downloads
295
2.08%
Maintainers
1
Weekly downloads
 
Created
Source

@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

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<string>('');

    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}
                linkStyle={styles.link}
                textStyle={styles.text}
                containerStyle={styles.editor}
                toolbarStyle={styles.toolbar}
            />
            <RichTextViewer
                value={htmlStr}
                linkStyle={styles.link}
                textStyle={styles.text}
                containerStyle={styles.viewer}
            />
        </>
    );
};

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

Props

RichTextEditor

PropTypeDescription
value *stringHTML string with standard tags e.g.: p, b, strong, i, em, u, a, br
onValueChange *(value: string) => voidCall this function on value changed
onFocus() => voidCall this function on component focus
onBlur() => voidCall this function on component blur
onClickLink(href: string) => voidCall this function on link clicked
selectionColorstringColor of text selection
actionMapActionMapAction config for toolbar component
minHeightnumberMin height of container
textStyleStylePropStyle of base text
linkStyleStylePropStyle of link (a tag)
containerStyleStylePropStyle of content container
toolbarStyleStylePropStyle of toolbar container
disabledbooleanDisable editing on component
autoFocusbooleanAuto focus on component
debugbooleanPrint debug information to console

RichTextViewer

PropTypeDescription
value *stringHTML string with standard tags eg.: p, b, strong, i, em, u, a, ul, ol, li, br
onClickLink(href: string) => voidCall this function on link clicked
textStyleStylePropStyle of base text
linkStyleStylePropStyle of link (a tag)
containerStyleStylePropStyle of content container
debugbooleanPrint 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.

Developer

Dániel Sipos

Sponsors

This project is generously supported by TrophyMap, I18Nature, and several other amazing organizations.

Keywords

expo-rich-text-editor

FAQs

Package last updated on 07 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts