From 7c43f935a10e0e125ba2fcd47868619c8b9303f7 Mon Sep 17 00:00:00 2001 From: Javi Velasco Date: Thu, 22 Oct 2015 01:31:17 +0200 Subject: [PATCH] Babel to stage 2 and remove decorators --- .babelrc | 4 +- components/autocomplete/index.jsx | 146 +++++++++++----------- components/button/index.jsx | 8 +- components/card/index.jsx | 22 ++-- components/checkbox/index.jsx | 28 ++--- components/date_picker/calendar/day.jsx | 13 +- components/date_picker/calendar/index.jsx | 46 +++---- components/date_picker/calendar/month.jsx | 13 +- components/date_picker/dialog.jsx | 32 ++--- components/date_picker/index.jsx | 24 ++-- components/dialog/index.jsx | 6 +- components/drawer/index.jsx | 10 +- components/dropdown/index.jsx | 23 ++-- components/form/index.jsx | 14 +-- components/input/index.jsx | 10 +- components/link/index.jsx | 2 +- components/list/item.jsx | 14 +-- components/list/list.jsx | 6 +- components/menu/icon_menu.jsx | 14 +-- components/menu/menu.jsx | 26 ++-- components/menu/menu_item.jsx | 14 +-- components/progress_bar/index.jsx | 6 +- components/radio/radio_button.jsx | 22 ++-- components/radio/radio_group.jsx | 10 +- components/ripple/index.jsx | 18 +-- components/slider/index.jsx | 80 ++++++------ components/snackbar/index.jsx | 11 +- components/switch/index.jsx | 22 ++-- components/tabs/tab.jsx | 6 +- components/tabs/tabs.jsx | 12 +- components/time_picker/clock/face.jsx | 8 +- components/time_picker/clock/hand.jsx | 30 ++--- components/time_picker/clock/hours.jsx | 28 ++--- components/time_picker/clock/index.jsx | 40 +++--- components/time_picker/clock/minutes.jsx | 24 ++-- components/time_picker/dialog.jsx | 42 +++---- components/time_picker/index.jsx | 14 +-- package.json | 2 +- spec/components/autocomplete.jsx | 10 +- spec/components/card.jsx | 14 +-- spec/components/checkbox.jsx | 18 +-- spec/components/dialog.jsx | 12 +- spec/components/drawer.jsx | 16 +-- spec/components/dropdown.jsx | 18 +-- spec/components/form.jsx | 18 +-- spec/components/icon_menu.jsx | 22 ++-- spec/components/menu.jsx | 14 +-- spec/components/navigation.jsx | 6 +- spec/components/progress.jsx | 18 +-- spec/components/radio.jsx | 18 +-- spec/components/snackbar.jsx | 14 +-- spec/components/switch.jsx | 12 +- 52 files changed, 527 insertions(+), 533 deletions(-) diff --git a/.babelrc b/.babelrc index 15d27ad9..1c6ca3a6 100644 --- a/.babelrc +++ b/.babelrc @@ -1,4 +1,4 @@ { - "stage": 0, - "loose": "all" + "stage": 2, + "optional": ["es7.classProperties"] } diff --git a/components/autocomplete/index.jsx b/components/autocomplete/index.jsx index ce78e245..7d1aab65 100644 --- a/components/autocomplete/index.jsx +++ b/components/autocomplete/index.jsx @@ -1,12 +1,10 @@ import React from 'react'; import ReactDOM from 'react-dom'; -import autobind from 'autobind-decorator'; -import utils from '../utils'; import Input from '../input'; import style from './style'; +import utils from '../utils'; -@autobind -export default class Autocomplete extends React.Component { +class Autocomplete extends React.Component { static propTypes = { className: React.PropTypes.string, dataSource: React.PropTypes.any, @@ -51,14 +49,14 @@ export default class Autocomplete extends React.Component { this.refs.input.setValue(state.query); } - handleQueryChange () { + handleQueryChange = () => { const query = this.refs.input.getValue(); if (this.state.query !== query) { this.setState({query: query}); } - } + }; - handleKeyPress (event) { + handleKeyPress = (event) => { if (event.which === 13 && this.state.active) { this._selectOption(this.state.active); } @@ -70,9 +68,9 @@ export default class Autocomplete extends React.Component { if (index >= suggestionsKeys.length) index = 0; this.setState({active: suggestionsKeys[index]}); } - } + }; - handleFocus () { + handleFocus = () => { let client = event.target.getBoundingClientRect(); let screen_height = window.innerHeight || document.documentElement.offsetHeight; @@ -82,23 +80,79 @@ export default class Autocomplete extends React.Component { up: client.top > ((screen_height / 2) + client.height), focus: true }); - } + }; - handleBlur () { + handleBlur = () => { if (this.state.focus) this.setState({focus: false}); - } + }; - handleHover (event) { + handleHover = (event) => { this.setState({active: event.target.getAttribute('id')}); - } + }; - handleSelect (event) { + handleSelect = (event) => { utils.events.pauseEvent(event); this._selectOption(event.target.getAttribute('id')); + }; + + handleUnselect = (event) => { + this._unselectOption(event.target.getAttribute('id')); + }; + + renderSelected () { + if (this.props.multiple) { + return ( + + ); + } } - handleUnselect (event) { - this._unselectOption(event.target.getAttribute('id')); + renderSuggestions () { + return [...this._getSuggestions()].map(([key, value]) => { + let className = style.suggestion; + if (this.state.active === key) className += ` ${style.active}`; + return
  • {value}
  • ; + }); + } + + render () { + let className = style.root; + if (this.props.className) className += ` ${this.props.className}`; + if (this.state.focus) className += ` ${style.focus}`; + + let suggestionsClassName = style.suggestions; + if (this.state.up) suggestionsClassName += ` ${style.up}`; + let suggestionsStyle = {width: this.state.width}; + + return ( +
    + {this.props.label ? : ''} + {this.renderSelected()} + + +
    + ); } _indexDataSource (data = {}) { @@ -161,60 +215,6 @@ export default class Autocomplete extends React.Component { setError (data) { this.input.setError(data); } - - renderSelected () { - if (this.props.multiple) { - return ( - - ); - } - } - - renderSuggestions () { - return [...this._getSuggestions()].map(([key, value]) => { - let className = style.suggestion; - if (this.state.active === key) className += ` ${style.active}`; - return
  • {value}
  • ; - }); - } - - render () { - let className = style.root; - if (this.props.className) className += ` ${this.props.className}`; - if (this.state.focus) className += ` ${style.focus}`; - - let suggestionsClassName = style.suggestions; - if (this.state.up) suggestionsClassName += ` ${style.up}`; - let suggestionsStyle = {width: this.state.width}; - - return ( -
    - {this.props.label ? : ''} - {this.renderSelected()} - - -
    - ); - } } + +export default Autocomplete; diff --git a/components/button/index.jsx b/components/button/index.jsx index 86dfe467..9554894c 100644 --- a/components/button/index.jsx +++ b/components/button/index.jsx @@ -1,12 +1,10 @@ import React from 'react'; -import autobind from 'autobind-decorator'; import FontIcon from '../font_icon'; import Ripple from '../ripple'; import style from './style.scss'; import events from '../utils/events'; -@autobind -export default class Button extends React.Component { +class Button extends React.Component { static propTypes = { accent: React.PropTypes.bool, className: React.PropTypes.string, @@ -31,7 +29,7 @@ export default class Button extends React.Component { ripple: true }; - handleMouseDown (event) { + handleMouseDown = (event) => { events.pauseEvent(event); this.refs.ripple.start(event); } @@ -60,3 +58,5 @@ export default class Button extends React.Component { ); } } + +export default Button; diff --git a/components/card/index.jsx b/components/card/index.jsx index d1d8b13d..406cbd4f 100644 --- a/components/card/index.jsx +++ b/components/card/index.jsx @@ -1,11 +1,9 @@ import React from 'react'; -import autobind from 'autobind-decorator'; import Navigation from '../navigation'; import Ripple from '../ripple'; import style from './style.scss'; -@autobind -export default class Card extends React.Component { +class Card extends React.Component { static propTypes = { className: React.PropTypes.string, color: React.PropTypes.string, @@ -23,17 +21,13 @@ export default class Card extends React.Component { type: 'default' }; - state = { - loading: this.props.loading - }; - - handleMouseDown (event) { + handleMouseDown = (event) => { if (this.props.onClick) { event.preventDefault(); this.refs.ripple.start(event); this.props.onClick(event, this); } - } + }; renderTitle () { let styleFigure = {}, styleOverflow = {}; @@ -68,7 +62,7 @@ export default class Card extends React.Component { if (this.props.onClick) className += ` ${style.touch}`; if (this.props.image || this.props.color) className += ` ${style.contrast}`; if (this.props.color) className += ` ${style.color}`; - if (this.state.loading) className += ` ${style.loading}`; + if (this.props.loading) className += ` ${style.loading}`; if (this.props.className) className += ` ${this.props.className}`; return ( @@ -83,14 +77,12 @@ export default class Card extends React.Component { ); } - - loading (value) { - this.setState({loading: value}); - } } + +export default Card; diff --git a/components/checkbox/index.jsx b/components/checkbox/index.jsx index 570efa20..e629b149 100644 --- a/components/checkbox/index.jsx +++ b/components/checkbox/index.jsx @@ -1,11 +1,9 @@ import React from 'react'; -import autobind from 'autobind-decorator'; import Ripple from '../ripple'; -import style from './style'; import events from '../utils/events'; +import style from './style'; -@autobind -export default class Checkbox extends React.Component { +class Checkbox extends React.Component { static propTypes = { checked: React.PropTypes.bool, className: React.PropTypes.string, @@ -27,31 +25,31 @@ export default class Checkbox extends React.Component { checked: this.props.checked }; - handleChange (event) { + handleChange = (event) => { this.setState({checked: !this.state.checked}, () => { if (this.props.onChange) this.props.onChange(event, this); }); - } + }; - handleClick (event) { + handleClick = (event) => { events.pauseEvent(event); if (!this.props.disabled) this.handleChange(event); - } + }; - handleMouseDown (event) { + handleMouseDown = (event) => { if (!this.props.disabled) this.refs.ripple.start(event); - } + }; - handleInputClick (event) { + handleInputClick = (event) => { events.pauseEvent(event); - } + }; render () { let fieldClassName = style.field; let checkboxClassName = style.check; + if (this.state.checked) checkboxClassName += ` ${style.checked}`; if (this.props.disabled) fieldClassName += ` ${style.disabled}`; if (this.props.className) fieldClassName += ` ${this.props.className}`; - if (this.state.checked) checkboxClassName += ` ${style.checked}`; return (