mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-11 19:42:54 +08:00
Fix implicit any for Radio
This commit is contained in:
parent
b647078baa
commit
9b5a16ba93
@ -103,7 +103,7 @@ export default class Header extends React.Component<HeaderProps, any> {
|
||||
}
|
||||
}
|
||||
|
||||
onTypeChange = (e) => {
|
||||
onTypeChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const onTypeChange = this.props.onTypeChange;
|
||||
if (onTypeChange) {
|
||||
onTypeChange(e.target.value);
|
||||
|
@ -3,9 +3,9 @@ import PropTypes from 'prop-types';
|
||||
import classNames from 'classnames';
|
||||
import shallowEqual from 'shallowequal';
|
||||
import Radio from './radio';
|
||||
import { AbstractCheckboxGroupProps } from '../checkbox/Group';
|
||||
import { RadioGroupProps, RadioGroupState } from './interface';
|
||||
|
||||
function getCheckedValue(children) {
|
||||
function getCheckedValue(children: React.ReactNode) {
|
||||
let value = null;
|
||||
let matched = false;
|
||||
React.Children.forEach(children, (radio: any) => {
|
||||
@ -17,17 +17,7 @@ function getCheckedValue(children) {
|
||||
return matched ? { value } : undefined;
|
||||
}
|
||||
|
||||
export interface RadioGroupProps extends AbstractCheckboxGroupProps {
|
||||
defaultValue?: any;
|
||||
value?: any;
|
||||
onChange?: React.FormEventHandler<any>;
|
||||
size?: 'large' | 'default' | 'small';
|
||||
onMouseEnter?: React.FormEventHandler<any>;
|
||||
onMouseLeave?: React.FormEventHandler<any>;
|
||||
name?: string;
|
||||
}
|
||||
|
||||
export default class RadioGroup extends React.Component<RadioGroupProps, any> {
|
||||
export default class RadioGroup extends React.Component<RadioGroupProps, RadioGroupState> {
|
||||
static defaultProps = {
|
||||
disabled: false,
|
||||
};
|
||||
@ -36,7 +26,7 @@ export default class RadioGroup extends React.Component<RadioGroupProps, any> {
|
||||
radioGroup: PropTypes.any,
|
||||
};
|
||||
|
||||
constructor(props) {
|
||||
constructor(props: RadioGroupProps) {
|
||||
super(props);
|
||||
let value;
|
||||
if ('value' in props) {
|
||||
@ -63,7 +53,7 @@ export default class RadioGroup extends React.Component<RadioGroupProps, any> {
|
||||
};
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
componentWillReceiveProps(nextProps: RadioGroupProps) {
|
||||
if ('value' in nextProps) {
|
||||
this.setState({
|
||||
value: nextProps.value,
|
||||
@ -78,12 +68,12 @@ export default class RadioGroup extends React.Component<RadioGroupProps, any> {
|
||||
}
|
||||
}
|
||||
|
||||
shouldComponentUpdate(nextProps, nextState) {
|
||||
shouldComponentUpdate(nextProps: RadioGroupProps, nextState: RadioGroupState) {
|
||||
return !shallowEqual(this.props, nextProps) ||
|
||||
!shallowEqual(this.state, nextState);
|
||||
}
|
||||
|
||||
onRadioChange = (ev) => {
|
||||
onRadioChange = (ev: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const lastValue = this.state.value;
|
||||
const { value } = ev.target;
|
||||
if (!('value' in this.props)) {
|
||||
|
@ -2,9 +2,7 @@ import Radio from './radio';
|
||||
import Group from './group';
|
||||
import Button from './radioButton';
|
||||
|
||||
export { RadioProps } from './radio';
|
||||
export { RadioGroupProps } from './group';
|
||||
export { RadioButtonProps } from './radioButton';
|
||||
export * from './interface';
|
||||
|
||||
Radio.Button = Button;
|
||||
Radio.Group = Group;
|
||||
|
29
components/radio/interface.tsx
Normal file
29
components/radio/interface.tsx
Normal file
@ -0,0 +1,29 @@
|
||||
import * as React from 'react';
|
||||
import { AbstractCheckboxGroupProps } from '../checkbox/Group';
|
||||
import { AbstractCheckboxProps } from '../checkbox/Checkbox';
|
||||
|
||||
export interface RadioGroupProps extends AbstractCheckboxGroupProps {
|
||||
defaultValue?: any;
|
||||
value?: any;
|
||||
onChange?: React.ChangeEventHandler<HTMLInputElement>;
|
||||
size?: 'large' | 'default' | 'small';
|
||||
onMouseEnter?: React.MouseEventHandler<HTMLDivElement>;
|
||||
onMouseLeave?: React.MouseEventHandler<HTMLDivElement>;
|
||||
name?: string;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export interface RadioGroupState {
|
||||
value: any;
|
||||
}
|
||||
|
||||
export interface RadioGroupContext {
|
||||
radioGroup: {
|
||||
onChange: React.ChangeEventHandler<HTMLInputElement>;
|
||||
value: any;
|
||||
disabled: boolean;
|
||||
name: string;
|
||||
};
|
||||
}
|
||||
|
||||
export type RadioProps = AbstractCheckboxProps;
|
@ -3,13 +3,11 @@ import PropTypes from 'prop-types';
|
||||
import RcCheckbox from 'rc-checkbox';
|
||||
import classNames from 'classnames';
|
||||
import shallowEqual from 'shallowequal';
|
||||
import { AbstractCheckboxProps } from '../checkbox/Checkbox';
|
||||
import RadioGroup from './group';
|
||||
import RadioButton from './radioButton';
|
||||
import { RadioProps, RadioGroupContext } from './interface';
|
||||
|
||||
export type RadioProps = AbstractCheckboxProps;
|
||||
|
||||
export default class Radio extends React.Component<RadioProps, any> {
|
||||
export default class Radio extends React.Component<RadioProps, {}> {
|
||||
static Group: typeof RadioGroup;
|
||||
static Button: typeof RadioButton;
|
||||
|
||||
@ -24,7 +22,7 @@ export default class Radio extends React.Component<RadioProps, any> {
|
||||
|
||||
private rcCheckbox: any;
|
||||
|
||||
shouldComponentUpdate(nextProps, nextState, nextContext) {
|
||||
shouldComponentUpdate(nextProps: RadioProps, nextState: {}, nextContext: RadioGroupContext) {
|
||||
return !shallowEqual(this.props, nextProps) ||
|
||||
!shallowEqual(this.state, nextState) ||
|
||||
!shallowEqual(this.context.radioGroup, nextContext.radioGroup);
|
||||
@ -38,7 +36,7 @@ export default class Radio extends React.Component<RadioProps, any> {
|
||||
this.rcCheckbox.blur();
|
||||
}
|
||||
|
||||
saveCheckbox = (node) => {
|
||||
saveCheckbox = (node: any) => {
|
||||
this.rcCheckbox = node;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user