1.0.6 • Published 7 years ago

hake-draft v1.0.6

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

hake-draft

A wrapper Component for react-draft-wysiwyg

banner

This package require a css file, make sure you use webpack or similar tools for handler this file type.

Table of Contents

Install

npm i hake-draft -S

# or

yarn add hake-draft

Usage

import Draft, { htmlToDraft, draftToHtml, EmptyState, } from 'hake-draft'

state = {
    editorState: htmlToDraft('Your html contents') // or use an EmptyState
}

<Draft
    editorState={this.state.editorState}
    onEditorStateChange={(editorState) => { this.setState({ editorState }) }}
/>

// save html to server

const html = draftToHtml(content)

If you use antd's Form Component and you are ready to go.

<FormItem label="Contents" {...alignProps} wrapperCol={{ span: 16 }}>
    {getFieldDecorator('Content', {
        rules: [{ required: true, message: 'Please leave a message...' }],
    })(
        <Draft
            editorState={this.state.editorState}
            onEditorStateChange={(editorState) => { this.setState({ editorState }) }}
        />
        )}
</FormItem>

// convert state to html 

this.props.form.validateFields((err, data) => {
    if (err) {
        return
    }
    /**
    * do more check here.
    */
    if (data.Content) {
        data.Content = draftToHtml(data.Content)
    }
    // Now you have your html contents and ready to post to your server.
})

Contribute

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT © bang88

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

1.0.0-beta.2

7 years ago

1.0.0-beta.1

7 years ago

1.0.0-beta

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.2

7 years ago