Skip to content

Commit

Permalink
modify default value of Button's disabled props to follow loading pro…
Browse files Browse the repository at this point in the history
…ps (#2510)

<!--
  How to write a good PR title:
- Follow [the Conventional Commits
specification](https://www.conventionalcommits.org/en/v1.0.0/).
  - Give as much context as necessary and as little as possible
  - Prefix it with [WIP] while it’s a work in progress
-->

## Self Checklist

- [x] I wrote a PR title in **English** and added an appropriate
**label** to the PR.
- [x] I wrote the commit message in **English** and to follow [**the
Conventional Commits
specification**](https://www.conventionalcommits.org/en/v1.0.0/).
- [x] I [added the
**changeset**](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md)
about the changes that needed to be released. (or didn't have to)
- [ ] I wrote or updated **documentation** related to the changes. (or
didn't have to)
- [ ] I wrote or updated **tests** related to the changes. (or didn't
have to)
- [ ] I tested the changes in various browsers. (or didn't have to)
  - Windows: Chrome, Edge, (Optional) Firefox
  - macOS: Chrome, Edge, Safari, (Optional) Firefox

## Related Issue

#2299 

<!-- Please link to issue if one exists -->

<!-- Fixes #0000 -->

## Summary

<!-- Please brief explanation of the changes made -->

- Button 의 disabled 의 기본값을 false 에서 loading 을 따라가도록 수정합니다. 

## Details

<!-- Please elaborate description of the changes -->

- loading: true, disabled: undefined -> disabled: true
- loading: true, disabled: false -> disabled: false


https://github.com/user-attachments/assets/c05e5848-91c5-46bc-bf0e-c7cfdab2002b

### Breaking change? (Yes/No)

<!-- If Yes, please describe the impact and migration path for users -->

No

## References

<!-- Please list any other resources or points the reviewer should be
aware of -->
  • Loading branch information
jintak0401 authored Dec 5, 2024
1 parent 9fc055d commit c8e5578
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 10 deletions.
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

0 comments on commit c8e5578

Please sign in to comment.