-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
REACT-326 Button loader added + fixes
- Loading branch information
1 parent
e180943
commit 4a7832f
Showing
10 changed files
with
204 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,58 @@ | ||
import React, { FC, memo } from 'react'; | ||
import React, { FC, memo, useMemo } from 'react'; | ||
import { IButtonProps } from './interfaces/IButton'; | ||
import { EColors, ESizes, EVariants } from '../../constants/tsConstants'; | ||
import styles from './sass/Button.module.scss'; | ||
import BallPulse from '../Loaders/BallPulse/BallPulse'; | ||
|
||
const Button: FC<IButtonProps> = ({ | ||
label = '', | ||
text = '', | ||
aliaLabel = '', | ||
disabled = false, | ||
onPress, | ||
variant = 'contained', | ||
color = 'primary', | ||
size = 'medium', | ||
isLoading = false, | ||
onClick, | ||
onMouseEnter, | ||
onMouseLeave, | ||
variant = EVariants.CONTAINED, | ||
color = EColors.PRIMARY, | ||
size = ESizes.MEDIUM, | ||
iconLeft = null, | ||
iconRight = null, | ||
buttonClass = '', | ||
}) => ( | ||
<button | ||
className={` | ||
className = '', | ||
}) => { | ||
const loader = useMemo(() => { | ||
if (isLoading) { | ||
return ( | ||
<BallPulse | ||
className={styles.loader} | ||
color={variant === EVariants.CONTAINED || disabled ? undefined : color} | ||
/> | ||
); | ||
} | ||
return null; | ||
}, [isLoading, disabled, variant, color]); | ||
|
||
return ( | ||
<button | ||
aria-label={aliaLabel} | ||
type="button" | ||
className={` | ||
${styles.button} | ||
${styles[variant]} | ||
${styles[color]} | ||
${styles[size]} | ||
${disabled ? styles.disabled : ''} | ||
${buttonClass} | ||
${className} | ||
`} | ||
onClick={onPress} | ||
disabled={disabled} | ||
type="button" | ||
> | ||
{iconLeft && <img className={styles.iconLeft} src={iconLeft} alt={label || ''} />} | ||
{label && <span>{label}</span>} | ||
{iconRight && <img className={styles.iconRight} src={iconRight} alt={label || ''} />} | ||
</button> | ||
); | ||
|
||
disabled={disabled || isLoading} | ||
onClick={onClick} | ||
onMouseEnter={onMouseEnter} | ||
onMouseLeave={onMouseLeave} | ||
> | ||
{iconLeft && <img className={styles.iconLeft} src={iconLeft} alt={text} />} | ||
{text && <span className={isLoading ? styles.loaderText : ''}>{text}</span>} | ||
{loader} | ||
{iconRight && <img className={styles.iconRight} src={iconRight} alt={text} />} | ||
</button> | ||
); | ||
}; | ||
export default memo(Button); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
import { EColors, EVariants, EButtonSizes } from '../../../constants/tsConstants'; | ||
|
||
export interface IButtonProps { | ||
label?: string, | ||
onPress: () => void, | ||
text?: string, | ||
aliaLabel?: string, | ||
disabled?: boolean, | ||
styles?: string, | ||
variant: 'text' | 'contained' | 'outlined', | ||
color: 'primary' | 'warning' | 'error', | ||
size: 'small' | 'medium' | 'big' | 'large', | ||
isLoading?: boolean, | ||
onClick?: () => void, | ||
onMouseEnter?: () => void, | ||
onMouseLeave?: () => void, | ||
variant: EVariants, | ||
color: EColors, | ||
size: EButtonSizes, | ||
iconLeft?: string, | ||
iconRight?: string, | ||
buttonClass?: string, | ||
className?: string, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React, { FC } from 'react'; | ||
import { IBallPulseProps } from './interfaces/IBallPulse'; | ||
import { EBallPulseColorsExtender } from '../../../constants/tsConstants'; | ||
import styles from './sass/BallPulse.module.scss'; | ||
|
||
const BallPulse: FC<IBallPulseProps> = ({ | ||
className = '', | ||
color = EBallPulseColorsExtender.WHITE, | ||
}) => ( | ||
<div className={`${styles.wrapper} ${styles[color]} ${className}`}> | ||
<div /> | ||
<div /> | ||
<div /> | ||
</div> | ||
); | ||
|
||
export default BallPulse; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { EBallPulseColors } from '../../../../constants/tsConstants'; | ||
|
||
export interface IBallPulseProps { | ||
className?: string, | ||
color?: EBallPulseColors, | ||
} |
69 changes: 69 additions & 0 deletions
69
src/components/Loaders/BallPulse/sass/BallPulse.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
@import '../../../../sass/colors'; | ||
|
||
.wrapper { | ||
display: flex; | ||
|
||
&.white { | ||
> div { | ||
background-color: $white; | ||
} | ||
} | ||
|
||
&.primary { | ||
> div { | ||
background-color: $primary; | ||
} | ||
} | ||
|
||
&.success { | ||
> div { | ||
background-color: $success; | ||
} | ||
} | ||
|
||
&.warning { | ||
> div { | ||
background-color: $warning; | ||
} | ||
} | ||
|
||
&.error { | ||
> div { | ||
background-color: $error; | ||
} | ||
} | ||
|
||
> div { | ||
width: 8px; | ||
height: 8px; | ||
|
||
border-radius: 100%; | ||
margin: 2px; | ||
display: inline-block; | ||
-webkit-animation-fill-mode: both; | ||
animation-fill-mode: both; | ||
|
||
&:nth-child(1) { | ||
animation: scale .75s -.24s infinite cubic-bezier(.2,.68,.18,1.08); | ||
} | ||
|
||
&:nth-child(2) { | ||
animation: scale .75s -.12s infinite cubic-bezier(.2,.68,.18,1.08); | ||
} | ||
|
||
&:nth-child(3) { | ||
animation: scale .75s 0s infinite cubic-bezier(.2,.68,.18,1.08); | ||
} | ||
} | ||
} | ||
|
||
@keyframes scale { | ||
30% { | ||
-webkit-transform: scale(.3); | ||
transform: scale(.3); | ||
} | ||
100% { | ||
-webkit-transform: scale(1); | ||
transform: scale(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export enum ESizes { | ||
SMALL = 'small', | ||
MEDIUM = 'medium', | ||
BIG = 'big', | ||
} | ||
|
||
export enum EVariants { | ||
TEXT = 'text', | ||
CONTAINED = 'contained', | ||
OUTLINED = 'outlined', | ||
} | ||
|
||
export enum EColors { | ||
PRIMARY = 'primary', | ||
WARNING = 'warning', | ||
ERROR = 'error', | ||
} | ||
|
||
enum EButtonSizesExtender { | ||
LARGE = 'large', | ||
} | ||
|
||
export type EButtonSizes = ESizes | EButtonSizesExtender; | ||
|
||
export enum EBallPulseColorsExtender { | ||
WHITE = 'white', | ||
SUCCESS = 'success', | ||
} | ||
|
||
export type EBallPulseColors = EColors | EBallPulseColorsExtender; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* { | ||
font-family: -apple-system,Inter,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,sans-serif; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters