Skip to content

Commit

Permalink
feat(button): remove unsafe method (#1039)
Browse files Browse the repository at this point in the history
  • Loading branch information
aso1datov committed Mar 27, 2020
1 parent 1ecb020 commit 8c89726
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,16 @@ export type ButtonProps = DeepReadonly<{

}>;

type ButtonState = {
focused: boolean;
hovered: boolean;
pressed: boolean;
}

/**
* Компонент кнопки (да, она нажимается!).
*/
export class Button extends React.PureComponent<ButtonProps> {
export class Button extends React.PureComponent<ButtonProps, ButtonState> {
protected cn = createCn('button');

static defaultProps: Partial<ButtonProps> = {
Expand All @@ -190,6 +196,17 @@ export class Button extends React.PureComponent<ButtonProps> {
formNoValidate: false
};

static getDerivedStateFromProps(nextProps: ButtonProps): Partial<ButtonState> | null {
if (nextProps.disabled) {
return {
hovered: false,
focused: false
};
}

return null;
}

state = {
focused: false,
hovered: false,
Expand All @@ -198,16 +215,6 @@ export class Button extends React.PureComponent<ButtonProps> {

private control: HTMLButtonElement | HTMLSpanElement;

// eslint-disable-next-line camelcase
UNSAFE_componentWillReceiveProps(nextProps) {
if (nextProps.disabled) {
this.setState({
hovered: false,
focused: false
});
}
}

render() {
const isButton = this.props.tag !== 'span';

Expand Down

0 comments on commit 8c89726

Please sign in to comment.