import React , { PureComponent } from 'react' ; import type PropsType from './PropsType' ; import Keyboard from '../keyboard' ; import Popup from '../popup' ; export interface KeyboardPickerProps extends PropsType { prefixCls ? : string ; className ? : string ; } export interface KeyboardPickerState { visible ? : boolean ; } export default class KeyboardPicker extends PureComponent < KeyboardPickerProps , KeyboardPickerState > { static defaultProps : KeyboardPickerProps = { prefixCls : 'za-keyboard-picker' , visible : false , type : 'number' , destroy : true , } ; static getDerivedStateFromProps ( nextProps ) { if ( 'visible' in nextProps ) { return { visible : nextProps . visible } ; } return null ; } constructor ( props ) { super ( props ) ; this . state = { visible : props . visible , } ; } onKeyClick = ( key ) => { if ( [ 'ok' , 'close' ] . indexOf ( key ) > - 1 ) { this . setState ( { visible : false } ) ; } const { onKeyClick } = this . props ; if ( typeof onKeyClick === 'function' ) { onKeyClick ( key ) ; } } ; render ( ) { const { prefixCls , className , destroy , ... others } = this . props ; const { visible } = this . state ; return ( < Popup className = { className } visible = { visible } mask = { false } destroy = { destroy } > < div className = { prefixCls } > < Keyboard { ... others } onKeyClick = { this . onKeyClick } / > < /div> < /Popup>); } }