1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-03-06 13:59:47 +01:00
slate/examples/plugins/word-count.js
2018-10-10 14:00:45 -07:00

27 lines
608 B
JavaScript

import React from 'react'
import styled from 'react-emotion'
const WordCounter = styled('span')`
margin-top: 10px;
padding: 12px;
background-color: #ebebeb;
display: inline-block;
`
export default function WordCount(options) {
return {
renderEditor(props, next) {
const children = next()
const wordCount = props.value.document
.getBlocks()
.reduce((memo, b) => memo + b.text.trim().split(/\s+/).length, 0)
return (
<div>
<div>{children}</div>
<WordCounter>Word Count: {wordCount}</WordCounter>
</div>
)
},
}
}