An open API service indexing awesome lists of open source software.

https://github.com/avin/react-substring

Replace substrings with components
https://github.com/avin/react-substring

Last synced: 4 months ago
JSON representation

Replace substrings with components

Awesome Lists containing this project

README

          

# react-substring

> Decorating substrings with components. Useful to highlight something in your text content.

[![NPM registry](https://img.shields.io/npm/v/react-substring.svg?style=for-the-badge)](https://yarnpkg.com/en/package/react-substring)
![](https://img.shields.io/travis/:avin/:react-substring.svg?style=for-the-badge)
[![NPM license](https://img.shields.io/badge/license-mit-red.svg?style=for-the-badge)](LICENSE)

## Demo

Here is an [examples page](https://avin.github.io/react-substring)

## Install

```bash
# Yarn
yarn add react-substring

# NPM
npm install --save react-substring
```

## Features

* Search substrings by simple string or regular expressions.
* Decorate substrings with custom components or just add some style or className to them.
* Personal decorating for each match pattern.

## Usage

```js
import React from 'react';
import Substring from 'react-substring';

const RedString = ({ children }) => {children};

const DemoComponent = () => (

Decorate substrings with custom components or just add some style or className to them

);
```

## API

#### Props

| Property | Type | Required? | Description |
| :----------- | :--------------- | :-------: | :------------------------------------------------------------------------------------------------- |
| substrings | Array | ✓ | Array on Substring objects. |
| outerTagName | String | | Tag name passed to document.createElement to create the outer container element. (Default: `span`) |
| style | Object | | Optional inline style to attach to outermost element. |
| className | Object | | Optional inline style to attach to outermost element. |

#### Substring object fields

| Field name | Type | Required? | Description |
| :------------ | :------------------------ | :-------: | :------------------------------------------------------------------------------------------------- |
| match | RegExp or String | ✓ | Pattern to search substrings for processing. Can use array of patterns here. |
| component | React.Component or String | | React component or tag name taking matching content. (Default: `mark`) |
| caseSensitive | Bool | | If use match as string - it allows to switch on case sensitive search substring (Default: `false`) |
| props | Object | | Additional props for matching component (can use `style`, `className` or something else) |

## License

MIT © [avin](https://github.com/avin)