import React from 'react'; import CustomPropTypes from './utils/propTypes.js'; const { PropTypes } = React; const TYPES = [ 'button', 'reset', 'submit', ]; export let Button = React.createClass({ propTypes: { disabled: PropTypes.bool, /** * You can use a custom element for this component */ componentClass: CustomPropTypes.elementType, /** * Defines HTML button type Attribute * @type {("button"|"reset"|"submit")} * @defaultValue 'button' */ type: PropTypes.oneOf(TYPES), }, getDefaultProps() { return { disabled: false, type: 'button', }; }, render() { let renderFuncName = this.props.href || this.props.target ? 'renderAnchor' : 'renderButton'; return this[renderFuncName](); }, renderAnchor() { let Component = this.props.componentClass || 'a'; let href = this.props.href || '#'; return ( {this.props.children} ); }, renderButton() { let Component = this.props.componentClass || 'button'; return ( {this.props.children} ); }, });