Skip to content

Commit

Permalink
Add onChange prop to LiveEditor
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Jun 13, 2017
1 parent 1b8c7c1 commit e5bc31f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ It accepts these props for styling:
|className|PropTypes.string|An additional class that is added to the Content Editable
|ignoreTabKey|PropTypes.bool|Makes the editor ignore tab key presses so that keyboard users can tab past the editor without getting stuck
|style|PropTypes.object|Additional styles for the Content Editable
|onChange|PropTypes.function|Accepts a callback that is called when the user makes changes

This component renders a Prism.js editor underneath it and also renders all of Prism’s
styles inside a `style` tag.
Expand Down
10 changes: 9 additions & 1 deletion src/components/Live/LiveEditor.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import React from 'react'
import PropTypes from 'prop-types'
import { LiveContextTypes } from './LiveProvider'
import Editor from '../Editor'

const LiveEditor = (props, { live }) => (
<Editor
{...props}
code={live.code}
onChange={live.onChange}
onChange={code => {
live.onChange(code)

if (typeof props.onChange === 'function') {
props.onChange(code)
}
}}
/>
)

LiveEditor.contextTypes = LiveContextTypes
LiveEditor.propTypes = { onChange: PropTypes.function }

export default LiveEditor

0 comments on commit e5bc31f

Please sign in to comment.