diff --git a/client/src/core-components/button.js b/client/src/core-components/button.js index 8b30ded0..755004f9 100644 --- a/client/src/core-components/button.js +++ b/client/src/core-components/button.js @@ -6,13 +6,13 @@ import classNames from 'classnames'; // CORE LIBS import callback from 'lib-core/callback'; -const Button = React.createClass({ +class Button extends React.Component { - contextTypes: { + static contextTypes = { router: React.PropTypes.object - }, + }; - propTypes: { + static propTypes = { children: React.PropTypes.node, type: React.PropTypes.oneOf([ 'primary', @@ -24,13 +24,11 @@ const Button = React.createClass({ params: React.PropTypes.object, query: React.PropTypes.query }) - }, + }; - getDefaultProps() { - return { - type: 'primary' - }; - }, + static defaultProps = { + type: 'primary' + }; render() { return ( @@ -38,19 +36,19 @@ const Button = React.createClass({ {this.props.children} ); - }, + } getProps() { let props = _.clone(this.props); - props.onClick = callback(this.handleClick, this.props.onClick); + props.onClick = callback(this.handleClick.bind(this), this.props.onClick); props.className = this.getClass(); delete props.route; delete props.type; return props; - }, + } getClass() { let classes = { @@ -62,13 +60,13 @@ const Button = React.createClass({ classes[this.props.className] = (this.props.className); return classNames(classes); - }, + } handleClick() { if (this.props.route) { this.context.router.push(this.props.route.to); } } -}); +} export default Button; diff --git a/client/src/core-components/checkbox.js b/client/src/core-components/checkbox.js index bd36f4fd..2a02ea11 100644 --- a/client/src/core-components/checkbox.js +++ b/client/src/core-components/checkbox.js @@ -5,25 +5,25 @@ import _ from 'lodash'; import callback from 'lib-core/callback'; import getIcon from 'lib-core/get-icon'; -let CheckBox = React.createClass({ +class CheckBox extends React.Component { - propTypes: { + static propTypes = { alignment: React.PropTypes.string, label: React.PropTypes.string, value: React.PropTypes.bool - }, + }; - getDefaultProps() { - return { - alignment: 'right' - }; - }, + static defaultProps = { + alignment: 'right' + }; - getInitialState() { - return { + constructor(props) { + super(props); + + this.state = { checked: false }; - }, + } render() { return ( @@ -35,7 +35,7 @@ let CheckBox = React.createClass({ ); - }, + } getProps() { let props = _.clone(this.props); @@ -45,7 +45,7 @@ let CheckBox = React.createClass({ props['aria-hidden'] = true; props.className = 'checkbox--box'; props.checked = this.getValue(); - props.onChange = callback(this.handleChange, this.props.onChange); + props.onChange = callback(this.handleChange.bind(this), this.props.onChange); delete props.alignment; delete props.error; @@ -53,7 +53,7 @@ let CheckBox = React.createClass({ delete props.value; return props; - }, + } getClass() { let classes = { @@ -64,29 +64,29 @@ let CheckBox = React.createClass({ }; return classNames(classes); - }, + } getIconProps() { return { 'aria-checked': this.getValue(), className: 'checkbox--icon', - onKeyDown: callback(this.handleIconKeyDown, this.props.onKeyDown), + onKeyDown: callback(this.handleIconKeyDown.bind(this), this.props.onKeyDown), role: "checkbox", tabIndex: 0 }; - }, + } getValue() { return (this.props.value === undefined) ? this.state.checked : this.props.value; - }, + } - handleChange: function (event) { + handleChange(event) { this.setState({ checked: event.target.checked }); - }, + } - handleIconKeyDown: function (event) { + handleIconKeyDown(event) { if (event.keyCode == 32) { event.preventDefault(); @@ -97,6 +97,6 @@ let CheckBox = React.createClass({ }); } } -}); +} export default CheckBox; diff --git a/client/src/core-components/drop-down.js b/client/src/core-components/drop-down.js index be3b1b80..38e85d48 100644 --- a/client/src/core-components/drop-down.js +++ b/client/src/core-components/drop-down.js @@ -1,32 +1,30 @@ -const React = require('react'); -const classNames = require('classnames'); -const _ = require('lodash'); -const {Motion, spring} = require('react-motion'); -const callback = require('lib-core/callback'); +import React from 'react'; +import classNames from 'classnames'; +import {Motion, spring} from 'react-motion'; -const Menu = require('core-components/menu'); -const Icon = require('core-components/icon'); +import Menu from 'core-components/menu'; +import Icon from 'core-components/icon'; -const DropDown = React.createClass({ +class DropDown extends React.Component { - propTypes: { + static propTypes = { defaultSelectedIndex: React.PropTypes.number, selectedIndex: React.PropTypes.number, items: Menu.propTypes.items - }, + }; - getDefaultProps() { - return { - defaultSelectedIndex: 0 - }; - }, + static defaultProps = { + defaultSelectedIndex: 2 + }; - getInitialState() { - return { + constructor(props) { + super(props); + + this.state = { selectedIndex: 0, opened: false }; - }, + } getAnimationStyles() { let closedStyle = { @@ -42,7 +40,7 @@ const DropDown = React.createClass({ defaultStyle: closedStyle, style: (this.state.opened) ? openedStyle : closedStyle }; - }, + } render() { let animation = this.getAnimationStyles(); @@ -52,18 +50,18 @@ const DropDown = React.createClass({
{this.renderCurrentItem(selectedItem)} - {this.renderList} + {this.renderList.bind(this)}
); - }, + } renderList({opacity, translateY}) { let style = { opacity: opacity, transform: `translateY(${translateY}px)`}; let menuProps = { items: this.props.items, - onItemClick: this.handleItemClick, - onMouseDown: this.handleListMouseDown, + onItemClick: this.handleItemClick.bind(this), + onMouseDown: this.handleListMouseDown.bind(this), selectedIndex: this.state.selectedIndex }; @@ -72,7 +70,7 @@ const DropDown = React.createClass({ ); - }, + } renderCurrentItem(item) { var iconNode = null; @@ -82,11 +80,11 @@ const DropDown = React.createClass({ } return ( -
+
{iconNode}{item.content}
); - }, + } getClass() { let classes = { @@ -97,19 +95,19 @@ const DropDown = React.createClass({ }; return classNames(classes); - }, + } handleBlur() { this.setState({ opened: false }); - }, + } handleClick() { this.setState({ opened: !this.state.opened }); - }, + } handleItemClick(index) { this.setState({ @@ -122,15 +120,15 @@ const DropDown = React.createClass({ index }); } - }, + } handleListMouseDown(event) { event.preventDefault(); - }, + } getSelectedIndex() { return (this.props.selectedIndex !== undefined) ? this.props.selectedIndex : this.state.selectedIndex; } -}); +} export default DropDown; diff --git a/client/src/core-components/form.js b/client/src/core-components/form.js index 36922806..54ec26e3 100644 --- a/client/src/core-components/form.js +++ b/client/src/core-components/form.js @@ -1,64 +1,66 @@ -const React = require('react'); -const _ = require('lodash'); -const classNames = require('classnames'); +import React from 'react'; +import _ from 'lodash'; +import classNames from 'classnames'; -const {reactDFS, renderChildrenWithProps} = require('lib-core/react-dfs'); -const ValidationFactory = require('lib-app/validations/validations-factory'); +import {reactDFS, renderChildrenWithProps} from 'lib-core/react-dfs'; +import ValidationFactory from 'lib-app/validations/validations-factory'; -const Input = require('core-components/input'); -const Checkbox = require('core-components/checkbox'); +import Input from 'core-components/input'; +import Checkbox from 'core-components/checkbox'; -const Form = React.createClass({ +class Form extends React.Component { - propTypes: { + static propTypes = { loading: React.PropTypes.bool, errors: React.PropTypes.object, onValidateErrors: React.PropTypes.func, onSubmit: React.PropTypes.func - }, + }; - childContextTypes: { + static childContextTypes = { loading: React.PropTypes.bool - }, + }; + + constructor(props) { + super(props); + + this.state = { + form: {}, + validations: {}, + errors: {} + }; + } getChildContext() { return { loading: this.props.loading }; - }, - - getInitialState() { - return { - form: {}, - validations: {}, - errors: {} - }; - }, + } componentDidMount() { this.setState(this.getInitialFormAndValidations()); - }, + } render() { return (
- {renderChildrenWithProps(this.props.children, this.getFieldProps)} + {renderChildrenWithProps(this.props.children, this.getFieldProps.bind(this))}
); - }, + } getProps() { let props = _.clone(this.props); props.className = this.getClass(); - props.onSubmit = this.handleSubmit; + props.onSubmit = this.handleSubmit.bind(this); delete props.errors; delete props.loading; delete props.onValidateErrors; return props; - }, + } getClass() { let classes = { @@ -68,7 +70,7 @@ const Form = React.createClass({ classes[this.props.className] = (this.props.className); return classNames(classes); - }, + } getFieldProps({props, type}) { let additionalProps = {}; @@ -86,7 +88,7 @@ const Form = React.createClass({ } return additionalProps; - }, + } getFieldError(fieldName) { let error = this.state.errors[fieldName]; @@ -95,7 +97,7 @@ const Form = React.createClass({ error = this.props.errors[fieldName] } return error; - }, + } getFirstErrorField() { let fieldName = _.findKey(this.state.errors); @@ -106,7 +108,7 @@ const Form = React.createClass({ } return fieldNode; - }, + } getAllFieldErrors() { let form = this.state.form; @@ -118,7 +120,7 @@ const Form = React.createClass({ }); return errors; - }, + } getErrorsWithValidatedField(fieldName, form = this.state.form, errors = this.state.errors) { let newErrors = _.clone(errors); @@ -128,7 +130,7 @@ const Form = React.createClass({ } return newErrors; - }, + } getInitialFormAndValidations() { let form = {}; @@ -154,17 +156,17 @@ const Form = React.createClass({ form: form, validations: validations } - }, + } handleSubmit(event) { event.preventDefault(); if (this.hasFormErrors()) { - this.updateErrors(this.getAllFieldErrors(), this.focusFirstErrorField); + this.updateErrors(this.getAllFieldErrors(), this.focusFirstErrorField.bind(this)); } else if (this.props.onSubmit) { this.props.onSubmit(this.state.form); } - }, + } handleFieldChange(fieldName, type, event) { let form = _.clone(this.state.form); @@ -178,19 +180,19 @@ const Form = React.createClass({ this.setState({ form: form }); - }, + } isValidFieldType(child) { return child.type === Input || child.type === Checkbox; - }, + } hasFormErrors() { return _.some(this.getAllFieldErrors()); - }, + } validateField(fieldName) { this.updateErrors(this.getErrorsWithValidatedField(fieldName)); - }, + } updateErrors(errors, callback) { this.setState({ @@ -200,7 +202,7 @@ const Form = React.createClass({ if (this.props.onValidateErrors) { this.props.onValidateErrors(errors); } - }, + } focusFirstErrorField() { let firstErrorField = this.getFirstErrorField(); @@ -209,6 +211,6 @@ const Form = React.createClass({ firstErrorField.focus(); } } -}); +} export default Form; diff --git a/client/src/core-components/icon.js b/client/src/core-components/icon.js index 69788693..6570bd90 100644 --- a/client/src/core-components/icon.js +++ b/client/src/core-components/icon.js @@ -1,34 +1,32 @@ -const React = require('react'); -const classNames = require('classnames'); +import React from 'react'; +import classNames from 'classnames'; -const Icon = React.createClass({ +class Icon extends React.Component { - propTypes: { + static propTypes = { name: React.PropTypes.string.isRequired, size: React.PropTypes.string - }, + }; - getDefaultProps() { - return { - size: 'lg' - }; - }, + static defaultProps = { + size: 'lg' + }; render() { return (this.props.name.length > 2) ? this.renderFontIcon() : this.renderFlag(); - }, + } renderFontIcon() { return (
) - }, + } getClass() { let classes = { @@ -62,7 +60,7 @@ const Message = React.createClass({ }; return classNames(classes); - }, + } getIconName() { let iconNames = { @@ -72,11 +70,11 @@ const Message = React.createClass({ }; return iconNames[this.props.type]; - }, + } getIconSize() { return (this.props.title) ? '2x' : 'lg'; } -}); +} export default Message; diff --git a/client/src/core-components/submit-button.js b/client/src/core-components/submit-button.js index e901c9ac..171351de 100644 --- a/client/src/core-components/submit-button.js +++ b/client/src/core-components/submit-button.js @@ -6,21 +6,19 @@ import classNames from 'classnames'; // CORE LIBS import Button from 'core-components/button'; -const SubmitButton = React.createClass({ +class SubmitButton extends React.Component { - contextTypes: { + static contextTypes = { loading: React.PropTypes.bool - }, + }; - propTypes: { + static propTypes = { children: React.PropTypes.node - }, + }; - getDefaultProps() { - return { - type: 'primary' - }; - }, + static defaultProps = { + type: 'primary' + }; render() { return ( @@ -28,20 +26,20 @@ const SubmitButton = React.createClass({ {(this.context.loading) ? this.renderLoading() : this.props.children} ); - }, + } renderLoading() { return (
); - }, + } getProps() { return _.extend({}, this.props, { disabled: this.context.loading, className: this.getClass() }); - }, + } getClass() { let classes = { @@ -53,6 +51,6 @@ const SubmitButton = React.createClass({ return classNames(classes); } -}); +} export default SubmitButton; diff --git a/client/src/core-components/widget-transition.js b/client/src/core-components/widget-transition.js index 36f3709b..70309ac3 100644 --- a/client/src/core-components/widget-transition.js +++ b/client/src/core-components/widget-transition.js @@ -3,35 +3,31 @@ import classNames from 'classnames'; import _ from 'lodash'; import {Motion, spring} from 'react-motion'; -import Widget from 'core-components/widget'; +class WidgetTransition extends React.Component { -let WidgetTransition = React.createClass({ - - propTypes: { + static propTypes = { sideToShow: React.PropTypes.string - }, + }; - getDefaultProps() { - return { - sideToShow: 'front' - }; - }, + static defaultProps = { + sideToShow: 'front' + }; getDefaultAnimation() { return { rotateY: -90 }; - }, + } render() { return ( - {this.renderChildren} + {this.renderChildren.bind(this)} ); - }, + } - renderChildren: function (animation) { + renderChildren(animation) { return (
{React.Children.map(this.props.children, function (child, index) { @@ -57,7 +53,7 @@ let WidgetTransition = React.createClass({ })}
) - }, + } getClass() { let classes = { @@ -66,13 +62,13 @@ let WidgetTransition = React.createClass({ }; return classNames(classes); - }, + } getAnimation() { return { rotateY: (this.props.sideToShow === 'front') ? spring(0, [100, 20]) : spring(180, [100, 20]) }; } -}); +} export default WidgetTransition; diff --git a/client/src/core-components/widget.js b/client/src/core-components/widget.js index 08e4ef5a..5b4ad675 100644 --- a/client/src/core-components/widget.js +++ b/client/src/core-components/widget.js @@ -1,17 +1,15 @@ import React from 'react'; import classNames from 'classnames'; -let Widget = React.createClass({ - propTypes: { +class Widget extends React.Component { + static propTypes = { title: React.PropTypes.string, children: React.PropTypes.node.isRequired - }, + }; - getDefaultProps() { - return { - title: '' - }; - }, + static defaultProps = { + title: '' + }; render() { return ( @@ -20,7 +18,7 @@ let Widget = React.createClass({ {this.props.children} ); - }, + } renderTitle() { let titleNode = null; @@ -30,7 +28,7 @@ let Widget = React.createClass({ } return titleNode; - }, + } getClass() { let classes = { @@ -41,6 +39,6 @@ let Widget = React.createClass({ return classNames(classes); } -}); +} export default Widget;