From c26a7cd89b7889bcfd0c9993e0aac1aac8e1c575 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Thu, 30 Jun 2016 18:22:48 -0700 Subject: Add selector component to ui mocker --- development/selector.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 development/selector.js (limited to 'development/selector.js') diff --git a/development/selector.js b/development/selector.js new file mode 100644 index 000000000..b58904cdf --- /dev/null +++ b/development/selector.js @@ -0,0 +1,30 @@ +const Component = require('react').Component +const h = require('react-hyperscript') +const inherits = require('util').inherits + +module.exports = NewComponent + +inherits(NewComponent, Component) +function NewComponent () { + Component.call(this) +} + +NewComponent.prototype.render = function () { + const props = this.props + let { states, selectedKey, actions, store } = props + + const state = this.state || {} + const selected = state.selected || selectedKey + + return h('select', { + value: selected, + onChange:(event) => { + const selectedKey = event.target.value + store.dispatch(actions.update(selectedKey)) + this.setState({ selected: selectedKey }) + }, + }, Object.keys(states).map((stateName) => { + return h('option', { value: stateName }, stateName) + })) + +} -- cgit v1.2.3