import * as React from "react" ; import { DISPLAYNAME_PREFIX , removeNonHTMLProps } from "../../common/props" ; import { IRef , refHandler , setRef } from "../../common/refs" ; import { AbstractButton , IButtonProps , IAnchorButtonProps , ButtonProps , AnchorButtonProps } from "./abstractButton" ; export { IAnchorButtonProps , IButtonProps , ButtonProps , AnchorButtonProps } ; export class Button extends AbstractButton < HTMLButtonElement > { public static displayName = `${ DISPLAYNAME_PREFIX }.Button` ; public buttonRef : HTMLButtonElement | null = null ; protected handleRef : IRef < HTMLButtonElement > = refHandler ( this , "buttonRef" , this . props . elementRef ) ; public render ( ) { return ( < button type = "button" ref = { this . handleRef } { ... removeNonHTMLProps ( this . props ) } { ... this . getCommonButtonProps ( ) } > { this . renderChildren ( ) } < /button>); } public componentDidUpdate ( prevProps ) { if ( prevProps . elementRef !== this . props . elementRef ) { setRef ( prevProps . elementRef , null ) ; this . handleRef = refHandler ( this , "buttonRef" , this . props . elementRef ) ; setRef ( this . props . elementRef , this . buttonRef ) ; } } } export class AnchorButton extends AbstractButton < HTMLAnchorElement > { public static displayName = `${ DISPLAYNAME_PREFIX }.AnchorButton` ; public buttonRef : HTMLAnchorElement | null = null ; protected handleRef : IRef < HTMLAnchorElement > = refHandler ( this , "buttonRef" , this . props . elementRef ) ; public render ( ) { const { href , tabIndex = 0 } = this . props ; const commonProps = this . getCommonButtonProps ( ) ; return ( < a role = "button" ref = { this . handleRef } { ... removeNonHTMLProps ( this . props ) } { ... commonProps } href = { commonProps . disabled ? undefined : href } tabIndex = { commonProps . disabled ? - 1 : tabIndex } > { this . renderChildren ( ) } < /a>); } public componentDidUpdate ( prevProps ) { if ( prevProps . elementRef !== this . props . elementRef ) { setRef ( prevProps . elementRef , null ) ; this . handleRef = refHandler ( this , "buttonRef" , this . props . elementRef ) ; setRef ( this . props . elementRef , this . buttonRef ) ; } } }