// import { Select } from '@alifd/next'; import Checkbox from '../checkbox'; import ConfigProvider from '../config-provider'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import cls from 'classnames'; import hoistNonReactStatics from 'hoist-non-react-statics'; import { CommonThemeProps } from '../types'; import { Select as NextSelect } from '@alifd/next'; import { getTheme } from '../utils/getTheme'; import { omitProps } from '../utils/object'; import { SelectProps as NextSelectProps } from '@alifd/next/types/select'; const { Option } = NextSelect; interface SelectProps extends Omit, CommonThemeProps { size?: 'large' | 'medium' | 'small' | 'xs'; } interface Pagestates { inited: boolean; renderValue: any; } class Select extends Component { static Option = NextSelect.Option; static AutoComplete = NextSelect.AutoComplete; static OptionGroup = NextSelect.OptionGroup; static getDerivedStateFromProps(nextProps, prevState) { if (!prevState.inited) { return { inited: true, renderValue: nextProps.value || nextProps.defaultValue, }; } if (nextProps.value) { return { renderValue: nextProps.value, }; } return null; } constructor(props) { super(props); this.state = { inited: false, renderValue: null, }; } onSelectChange = (value, actionType, item) => { const { onChange } = this.props; this.setState({ renderValue: value, }); onChange && onChange(value, actionType, item); }; getSelected = item => { const { renderValue } = this.state; if (Array.isArray(renderValue)) { for (const value of renderValue) { if (typeof value === 'string' && typeof item.value === 'number' || typeof value === 'number' && typeof item.value === 'string') { if (parseInt(String(value), 10) === parseInt(String(item.value), 10)) { return true; } } if (value === item.value) { return true; } } } else if (renderValue === item.value) { return true; } return false; }; checkedItemRender = item => { const selected = this.getSelected(item); return ( ); }; static contextTypes = { theme: PropTypes.string, }; render() { const { prefix = 'next-', popupClassName, className, mode, size } = this.props; const theme = getTheme(this.context, this.props); // 多选 模式 if (mode === 'multiple') { const { prefix = 'next-', className, dataSource, ...otherProps } = this.props; if (size === 'xs') { return ( ); } return ( ); } if (size === 'xs') { const { prefix = 'next-', className, ...otherProps } = this.props; return ( ); } return ; } } hoistNonReactStatics(Select, NextSelect); export default ConfigProvider.config(Select);