Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/oakfang/untrigger

A DraftJS plugin for sentiment analysis
https://github.com/oakfang/untrigger

Last synced: 6 days ago
JSON representation

A DraftJS plugin for sentiment analysis

Awesome Lists containing this project

README

        

# untrigger

## Usage with DraftJS

```js
import styled from 'styled-components';
import { CompositeDecorator } from 'draft-js';
import { createSentimentDecorators } from 'untrigger/draftjs';
import { myDecorator } from './my-decorators';

export default new CompositeDecorator([
myDecorator,
...createSentimentDecorators({
negativeComponent: styled.span`
color: red;
text-decoration: line-through;
`,
positiveComponent: styled.span`
color: green;
`,
}),
]);
```

## Usage with React (using [`sentiment`](https://www.npmjs.com/package/sentiment))

```js
import React, { useState } from 'react';
import styled from 'styled-components';
import { useSentimentAnalysis } from 'untrigger/hooks';

export function EmojiTextBox() {
const [text, setText] = useState('');
const { score } = useSentimentAnalysis(text);
let emoji = '😐';
if (score < 0) {
emoji = '🤬';
} else if (score > 0) {
emoji = '😊';
}
return (

setText(e.target.value)} />
{emoji}

);
}

const Container = styled.div`
display: flex;
`;
```