11import classNames from "classnames" ;
2- import React , { MouseEventHandler , useEffect , useRef , useState } from "react" ;
3- import type { ButtonHTMLAttributes , ReactNode } from "react" ;
2+ import React , { useEffect , useRef , useState } from "react" ;
43
54import type { ButtonProps } from "../Button" ;
65import Icon from "../Icon" ;
76
8- import type { ClassName , PropsWithSpread } from "types" ;
7+ import type { PropsWithSpread } from "types" ;
8+ import Button from "../Button" ;
99
1010export const LOADER_MIN_DURATION = 400 ; // minimium duration (ms) loader displays
1111export const SUCCESS_DURATION = 2000 ; // duration (ms) success tick is displayed
@@ -17,41 +17,16 @@ export enum Label {
1717
1818export type Props = PropsWithSpread <
1919 {
20- /**
21- * The appearance of the button.
22- */
23- appearance ?: ButtonProps [ "appearance" ] ;
24- /**
25- * The content of the button.
26- */
27- children ?: ReactNode ;
28- /**
29- * Optional class(es) to pass to the button element.
30- */
31- className ?: ClassName ;
32- /**
33- * Whether the button should be disabled.
34- */
35- disabled ?: boolean ;
36- /**
37- * Whether the button should display inline.
38- */
39- inline ?: boolean ;
4020 /**
4121 * Whether the button should be in the loading state.
4222 */
4323 loading ?: boolean ;
44- /**
45- * Function for handling button click event.
46- */
47- onClick ?: MouseEventHandler < HTMLButtonElement > ;
4824 /**
4925 * Whether the button should be in the success state.
5026 */
51-
5227 success ?: boolean ;
5328 } ,
54- ButtonHTMLAttributes < HTMLButtonElement >
29+ ButtonProps
5530> ;
5631
5732/**
@@ -62,12 +37,9 @@ export type Props = PropsWithSpread<
6237 * props table:
6338 */
6439const ActionButton = ( {
65- appearance,
6640 children,
6741 className,
68- onClick,
6942 disabled = null ,
70- inline = false ,
7143 loading = false ,
7244 success = false ,
7345 ...buttonProps
@@ -150,33 +122,20 @@ const ActionButton = ({
150122 return ( ) => window . clearTimeout ( successTimeout ) ;
151123 } , [ showSuccess ] ) ;
152124
153- const buttonClasses = classNames (
154- className ,
155- "p-action-button" ,
156- appearance ? `p-button--${ appearance } ` : "p-button" ,
157- {
158- "is-processing" : showLoader || showSuccess ,
159- "is-disabled" : disabled === null ? showLoader : disabled ,
160- "is-inline" : inline ,
161- } ,
162- ) ;
125+ const buttonClasses = classNames ( className , "p-action-button" , {
126+ "is-processing" : showLoader || showSuccess ,
127+ } ) ;
163128 const showIcon = showLoader || showSuccess ;
164- const isDisabled = disabled === null ? showLoader : disabled ;
165129 const icon = ( showLoader && "spinner" ) || ( showSuccess && "success" ) || null ;
166- const iconLight = appearance === "positive" || appearance === "negative" ;
167- const onClickDisabled : MouseEventHandler < HTMLButtonElement > = ( e ) =>
168- e . preventDefault ( ) ;
169-
170- // This component uses the base button element instead of the Button component
171- // as the button requires a ref and Button would have to be updated to use
172- // forwardRef which is not currently supported by components that use
173- // typescript generics.
130+ const iconLight =
131+ buttonProps . appearance === "positive" ||
132+ buttonProps . appearance === "negative" ;
133+
174134 return (
175- < button
135+ < Button
176136 className = { buttonClasses }
177137 ref = { ref }
178- onClick = { isDisabled ? onClickDisabled : onClick }
179- aria-disabled = { isDisabled || undefined }
138+ disabled = { disabled === null ? showLoader : disabled }
180139 style = {
181140 height && width
182141 ? {
@@ -197,7 +156,7 @@ const ActionButton = ({
197156 ) : (
198157 children
199158 ) }
200- </ button >
159+ </ Button >
201160 ) ;
202161} ;
203162
0 commit comments