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
- Host: GitHub
- URL: https://github.com/avin/react-substring
- Owner: avin
- Created: 2018-11-02T18:41:50.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-22T20:30:27.000Z (over 7 years ago)
- Last Synced: 2024-11-07T07:04:54.496Z (over 1 year ago)
- Language: JavaScript
- Homepage: https://avin.github.io/react-substring
- Size: 1.36 MB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# react-substring
> Decorating substrings with components. Useful to highlight something in your text content.
[](https://yarnpkg.com/en/package/react-substring)

[](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)