1.0.9 • Published 3 days ago

@siposdani87/expo-rich-text-editor v1.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
3 days ago

@siposdani87/expo-rich-text-editor

Version Download License

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.

1.0.9

3 days ago

1.0.8

2 months ago

1.0.7

4 months ago

1.0.6

8 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

12 months ago

1.0.2

1 year ago

1.0.1

1 year ago

0.9.2

1 year ago

0.9.0

2 years ago

0.8.1

2 years ago

0.9.1

1 year ago

0.8.0

2 years ago

0.7.0

2 years ago

0.5.0

2 years ago

0.6.0

2 years ago

0.5.1

2 years ago

0.4.0

2 years ago

0.3.0

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago