1
+ import { Progressing } from '@Common/Progressing'
1
2
import { ComponentSizeType } from '@Shared/constants'
2
3
import { ButtonProps , ButtonStyleType , ButtonVariantType } from './types'
3
- import { BUTTON_SIZE_TO_CLASS_NAME_MAP , BUTTON_SIZE_TO_ICON_CLASS_NAME_MAP } from './constants'
4
+ import { BUTTON_SIZE_TO_ICON_CLASS_NAME_MAP , BUTTON_SIZE_TO_LOADER_SIZE_MAP } from './constants'
5
+ import { getButtonDerivedClass } from './utils'
4
6
import './button.scss'
5
7
6
- export const getButtonDerivedClass = ( { size, variant, style } : Pick < ButtonProps , 'variant' | 'size' | 'style' > ) =>
7
- `button button__${ ButtonVariantType [ variant ] } --${ ButtonStyleType [ style ] } ${ BUTTON_SIZE_TO_CLASS_NAME_MAP [ size ] } `
8
-
9
8
const Button = ( {
10
9
buttonProps = { } ,
11
10
variant = ButtonVariantType . primary ,
@@ -15,20 +14,23 @@ const Button = ({
15
14
startIcon,
16
15
endIcon,
17
16
disabled,
17
+ isLoading,
18
18
} : ButtonProps ) => {
19
- const iconClass = `dc__no-shrink flex dc__fill-available-space ${ BUTTON_SIZE_TO_ICON_CLASS_NAME_MAP [ size ] } `
19
+ const visibilityClass = isLoading ? 'dc__visibility-hidden' : ''
20
+ const iconClass = `dc__no-shrink flex dc__fill-available-space ${ BUTTON_SIZE_TO_ICON_CLASS_NAME_MAP [ size ] } ${ visibilityClass } `
20
21
21
22
return (
22
23
< button
23
24
{ ...buttonProps }
24
- disabled = { disabled }
25
+ disabled = { disabled || isLoading }
25
26
// eslint-disable-next-line react/button-has-type
26
27
type = { buttonProps . type || 'button' }
27
- className = { `br-4 flex cursor dc__mnw-100 dc__tab-focus ${ getButtonDerivedClass ( { size, variant, style } ) } ${ disabled ? 'dc__disabled' : '' } ${ buttonProps . className || '' } ` }
28
+ className = { `br-4 flex cursor dc__mnw-100 dc__tab-focus dc__position-rel dc__capitalize ${ getButtonDerivedClass ( { size, variant, style } ) } ${ disabled ? 'dc__disabled' : '' } ${ buttonProps . className || '' } ` }
28
29
>
29
30
{ startIcon && < span className = { iconClass } > { startIcon } </ span > }
30
- < span className = " dc__mxw-150 dc__align-left dc__truncate" > { text } </ span >
31
+ < span className = { ` dc__mxw-150 dc__align-left dc__truncate ${ visibilityClass } ` } > { text } </ span >
31
32
{ endIcon && < span className = { iconClass } > { endIcon } </ span > }
33
+ { isLoading && < Progressing size = { BUTTON_SIZE_TO_LOADER_SIZE_MAP [ size ] } /> }
32
34
</ button >
33
35
)
34
36
}
0 commit comments