diff --git a/examples/focus-blur/Readme.md b/examples/focus-blur/Readme.md new file mode 100644 index 000000000..04b913be4 --- /dev/null +++ b/examples/focus-blur/Readme.md @@ -0,0 +1,8 @@ + +# Links Example + + + +This example shows you how you can wrap text in "inline" nodes to associate metadata, like an `href`, with a piece of text. This is how you'd add links to Slate, but it's also how you might add hashtags, at-mentions, and many more inline features! + +Check out the [Examples readme](..) to see how to run it! diff --git a/examples/focus-blur/index.js b/examples/focus-blur/index.js new file mode 100644 index 000000000..311be90d6 --- /dev/null +++ b/examples/focus-blur/index.js @@ -0,0 +1,145 @@ + +import { Editor, Mark, Raw } from '../..' +import React from 'react' +import ReactDOM from 'react-dom' +import initialState from './state.json' +import isUrl from 'is-url' +import { Map } from 'immutable' + +/** + * Define a schema. + * + * @type {Object} + */ + +const schema = { + nodes: { + paragraph: props =>
{props.children}
+ } +} + +/** + * The focus and blur example. + * + * @type {Component} + */ + +class FocusBlur extends React.Component { + + /** + * Deserialize the raw initial state. + * + * @type {Object} + */ + + state = { + state: Raw.deserialize(initialState, { terse: true }) + }; + + /** + * On change. + * + * @param {State} state + */ + + onChange = (state) => { + this.setState({ state }) + } + + /** + * Apply a focus or blur transform by `name` after a `timeout`. + * + * @param {String} name + * @param {Number} timeout + */ + + onClick = (e, name, timeout = 0) => { + e.preventDefault() + + setTimeout(() => { + const state = this.state.state + .transform() + [name]() + .apply() + + this.setState({ state }) + }, timeout) + } + + /** + * Generate focus and blur button handlers. + * + * @param {Event} e + */ + + onClickFocus = e => this.onClick(e, 'focus') + onClickFocusDelay = e => this.onClick(e, 'focus', 3000) + onClickBlur = e => this.onClick(e, 'blur') + onClickBlurDelay = e => this.onClick(e, 'blur', 3000) + + /** + * Render the app. + * + * @return {Element} element + */ + + render = () => { + return ( +