Skip to content
Snippets Groups Projects
Commit d62269cb authored by Joao Ramia's avatar Joao Ramia
Browse files

feat(HoliBricks): introduce iconBefore and scaleIcon props for Button

parent 57374dc5
No related branches found
No related tags found
No related merge requests found
...@@ -37,6 +37,8 @@ export type ButtonProps = AccessibilityProps & { ...@@ -37,6 +37,8 @@ export type ButtonProps = AccessibilityProps & {
transparent?: boolean transparent?: boolean
selected?: boolean selected?: boolean
icon?: HoliIconType icon?: HoliIconType
iconBefore?: HoliIconType
scaleIcon?: number
inline?: boolean inline?: boolean
testID?: string testID?: string
} }
...@@ -52,6 +54,8 @@ export const Button = ({ ...@@ -52,6 +54,8 @@ export const Button = ({
transparent = false, transparent = false,
selected = false, selected = false,
icon, icon,
iconBefore,
scaleIcon = 1,
inline = false, inline = false,
testID, testID,
...rest ...rest
...@@ -67,6 +71,7 @@ export const Button = ({ ...@@ -67,6 +71,7 @@ export const Button = ({
const isSpinning = loading || isProcessing const isSpinning = loading || isProcessing
const labelToShow = isSpinning && loadingLabel ? loadingLabel : label const labelToShow = isSpinning && loadingLabel ? loadingLabel : label
const iconSize = 16 * scaleIcon
const handlePress = useCallback( const handlePress = useCallback(
async (event: GestureResponderEvent) => { async (event: GestureResponderEvent) => {
...@@ -103,6 +108,9 @@ export const Button = ({ ...@@ -103,6 +108,9 @@ export const Button = ({
{...accessibilityProps(rest)} {...accessibilityProps(rest)}
> >
<View style={styles.content}> <View style={styles.content}>
{iconBefore && !isSpinning && (
<HoliIcon icon={iconBefore} size={iconSize} color={styles.text(disabled, selected, variant).color} />
)}
<View style={styles.textContainer(size)}> <View style={styles.textContainer(size)}>
<Text size={size === 'lg' ? 'md' : 'sm'} colorOveride={styles.text(disabled, selected, variant).color}> <Text size={size === 'lg' ? 'md' : 'sm'} colorOveride={styles.text(disabled, selected, variant).color}>
{labelToShow} {labelToShow}
...@@ -111,12 +119,12 @@ export const Button = ({ ...@@ -111,12 +119,12 @@ export const Button = ({
{isSpinning && ( {isSpinning && (
<View testID="spinner"> <View testID="spinner">
<SpinningIconContainer spinning={isSpinning}> <SpinningIconContainer spinning={isSpinning}>
<HoliIcon icon={Loader} size={16} color={styles.text(disabled, selected, variant).color} /> <HoliIcon icon={Loader} size={iconSize} color={styles.text(disabled, selected, variant).color} />
</SpinningIconContainer> </SpinningIconContainer>
</View> </View>
)} )}
{!isSpinning && icon && ( {!isSpinning && icon && (
<HoliIcon icon={icon} size={16} color={styles.text(disabled, selected, variant).color} /> <HoliIcon icon={icon} size={iconSize} color={styles.text(disabled, selected, variant).color} />
)} )}
</View> </View>
</Pressable> </Pressable>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment