import React, { Component, PropTypes } from 'react'; import classNames from 'classnames'; import { intlShape } from 'react-intl'; import icons from './icons.scss'; import styles from './form.scss'; import buttons from './buttons.scss'; export class Input extends Component { static displayName = 'Input'; static propTypes = { placeholder: PropTypes.oneOfType([ PropTypes.shape({ id: PropTypes.string }), PropTypes.string ]), icon: PropTypes.string, skin: PropTypes.oneOf(['dark', 'light']), color: PropTypes.oneOf(['green', 'blue', 'red', 'lightViolet', 'darkBlue']) }; static contextTypes = { intl: intlShape.isRequired }; render() { let { icon, color = 'green', skin = 'dark' } = this.props; const props = { type: 'text', ...this.props }; if (props.placeholder && props.placeholder.id) { props.placeholder = this.context.intl.formatMessage(props.placeholder); } let baseClass = styles.formRow; if (icon) { baseClass = styles.formIconRow; icon = (
); } return (
{icon}
); } setEl = (el) => { this.el = el; }; getValue() { return this.el.value; } focus() { this.el.focus(); setTimeout(this.el.focus.bind(this.el), 10); } } export class LabeledInput extends Component { static displayName = 'LabeledInput'; static propTypes = { label: PropTypes.oneOfType([ PropTypes.shape({ id: PropTypes.string }), PropTypes.string ]).isRequired, id: PropTypes.string, icon: PropTypes.string, skin: PropTypes.oneOf(['dark', 'light']), color: PropTypes.oneOf(['green', 'blue', 'red', 'lightViolet', 'darkBlue']) }; static contextTypes = { intl: intlShape.isRequired }; render() { let { label } = this.props; let props = Object.assign({}, this.props); if (!props.id) { props.id = uniqueId('input'); } if (label && label.id) { label = this.context.intl.formatMessage(label); } return (
); } setEl = (el) => { this.el = el; }; getValue() { return this.el.getValue(); } focus() { this.el.focus(); } } export class Checkbox extends Component { static displayName = 'Checkbox'; static propTypes = { color: PropTypes.oneOf(['green', 'blue', 'red']) }; render() { const { label, color = 'green' } = this.props; return (