From 3ab3a128deaf10300b31102b79458528227baa54 Mon Sep 17 00:00:00 2001 From: afc163 Date: Fri, 14 Apr 2017 17:13:04 +0800 Subject: fix react createClass and PropTypes warning --- src/Select.jsx | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'src/Select.jsx') diff --git a/src/Select.jsx b/src/Select.jsx index deb155d..49fed5b 100644 --- a/src/Select.jsx +++ b/src/Select.jsx @@ -1,4 +1,5 @@ -import React, { PropTypes } from 'react'; +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; import ReactDom from 'react-dom'; import classnames from 'classnames'; @@ -22,38 +23,36 @@ const scrollTo = (element, to, duration) => { }); }; -const Select = React.createClass({ - propTypes: { +class Select extends Component { + static propTypes = { prefixCls: PropTypes.string, options: PropTypes.array, selectedIndex: PropTypes.number, type: PropTypes.string, onSelect: PropTypes.func, onMouseEnter: PropTypes.func, - }, + }; - getInitialState() { - return { - active: false, - }; - }, + state = { + active: false, + }; componentDidMount() { // jump to selected option this.scrollToSelected(0); - }, + } componentDidUpdate(prevProps) { // smooth scroll to selected option if (prevProps.selectedIndex !== this.props.selectedIndex) { this.scrollToSelected(120); } - }, + } - onSelect(value) { + onSelect = (value) => { const { onSelect, type } = this.props; onSelect(type, value); - }, + } getOptions() { const { options, selectedIndex, prefixCls } = this.props; @@ -75,7 +74,7 @@ const Select = React.createClass({ {item.value} ); }); - }, + } scrollToSelected(duration) { // move to selected item @@ -91,16 +90,16 @@ const Select = React.createClass({ const topOption = list.children[index]; const to = topOption.offsetTop; scrollTo(select, to, duration); - }, + } - handleMouseEnter(e) { + handleMouseEnter = (e) => { this.setState({ active: true }); this.props.onMouseEnter(e); - }, + } - handleMouseLeave() { + handleMouseLeave = () => { this.setState({ active: false }); - }, + } render() { if (this.props.options.length === 0) { @@ -122,7 +121,7 @@ const Select = React.createClass({ ); - }, -}); + } +} export default Select; -- cgit v1.2.3