Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify default value of Button's disabled props to follow loading props #2510

Merged
merged 10 commits into from
Dec 5, 2024
Merged
5 changes: 5 additions & 0 deletions .changeset/dry-chairs-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@channel.io/bezier-react': patch
---

If disabled is not passed from Button's props, disabled follows loading
4 changes: 4 additions & 0 deletions packages/bezier-react/src/components/AlphaButton/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,15 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
active,
className,
loading,
disabled: disabledProp,
...rest
},
forwardedRef
) {
const Comp = as as typeof BaseButton

const disabled = loading || disabledProp

return (
<Comp
ref={forwardedRef}
Expand All @@ -88,6 +91,7 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
active && styles.active,
className
)}
disabled={disabled}
{...rest}
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface ButtonOwnProps {
text: string

/**
* If `loading` is true, spinner will be shown, replacing the content.
* If `loading` is true, spinner will be shown, replacing the content. Also, the button will be disabled.
* @default false
*/
loading?: boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ export const FloatingButton = forwardRef<
size = 'm',
active,
className,
loading,
loading = false,
disabled: disabledProp = false,
...rest
},
forwardedRef
) {
const Comp = as as typeof BaseButton
const disabled = loading || disabledProp

return (
<Comp
Expand All @@ -90,6 +92,7 @@ export const FloatingButton = forwardRef<
active && styles.active,
className
)}
disabled={disabled}
{...rest}
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface FloatingButtonOwnProps {
text: string

/**
* If `loading` is true, spinner will be shown, replacing the content.
* If `loading` is true, spinner will be shown, replacing the content. Also, the button will be disabled.
* @default false
*/
loading?: boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ export const FloatingIconButton = forwardRef<
size = 'm',
active,
content,
loading,
loading = false,
disabled: disabledProp = false,
className,
...rest
},
forwardedRef
) {
const Comp = as as typeof BaseButton
const disabled = loading || disabledProp

return (
<Comp
Expand All @@ -55,6 +57,7 @@ export const FloatingIconButton = forwardRef<
active && styles.active,
className
)}
disabled={disabled}
{...rest}
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type FloatingIconButtonSize = 'xs' | 's' | 'm' | 'l' | 'xl'

interface FloatingIconButtonOwnProps {
/**
* If `loading` is true, spinner will be shown, replacing the content.
* If `loading` is true, spinner will be shown, replacing the content. Also, the button will be disabled.
* @default false
*/
loading?: boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@ export const IconButton = forwardRef<HTMLButtonElement, AlphaIconButtonProps>(
active,
shape = 'rectangle',
content,
loading,
loading = false,
disabled: disabledProp = false,
className,
...rest
},
forwardedRef
) {
const Comp = as as typeof BaseButton

const disabled = loading || disabledProp

return (
<Comp
ref={forwardedRef}
Expand All @@ -55,6 +58,7 @@ export const IconButton = forwardRef<HTMLButtonElement, AlphaIconButtonProps>(
active && styles.active,
className
)}
disabled={disabled}
{...rest}
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type IconButtonSize = 'xs' | 's' | 'm' | 'l' | 'xl'

interface IconButtonOwnProps {
/**
* If `loading` is true, spinner will be shown, replacing the content.
* If `loading` is true, spinner will be shown, replacing the content. Also, the button will be disabled.
* @default false
*/
loading?: boolean
Expand Down
6 changes: 4 additions & 2 deletions packages/bezier-react/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use client'
'use client'

import React, { forwardRef, useCallback } from 'react'

Expand Down Expand Up @@ -94,8 +94,8 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
as = BaseButton,
className,
text,
disabled = false,
loading = false,
disabled: disabledProp = false,
active = false,
size = 'm',
styleVariant = 'primary',
Expand All @@ -109,6 +109,8 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
) {
const Comp = as as typeof BaseButton

const disabled = loading || disabledProp

const handleClick = useCallback<React.MouseEventHandler<HTMLButtonElement>>(
(event) => {
if (!disabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ interface ButtonOwnProps {
text?: string

/**
* If `loading` is true, spinner will be shown, replacing the content.
* If `loading` is true, spinner will be shown, replacing the content. Also, the button will be disabled.
* @default false
*/
loading?: boolean
Expand Down
Loading