-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): Button
busy
states (#3502)
Co-authored-by: Alex Carpenter <[email protected]>
- Loading branch information
1 parent
5b4902b
commit 7070989
Showing
10 changed files
with
278 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
--- |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,24 +1,41 @@ | ||
import cn from 'clsx'; | ||
import * as React from 'react'; | ||
|
||
import * as Icon from './icon'; | ||
import { Spinner } from './spinner'; | ||
|
||
export const Button = React.forwardRef<HTMLButtonElement, React.ButtonHTMLAttributes<HTMLButtonElement>>( | ||
function Button({ children, className, ...props }, forwardedRef) { | ||
return ( | ||
// eslint-disable-next-line react/button-has-type | ||
<button | ||
ref={forwardedRef} | ||
{...props} | ||
className={cn( | ||
'text-accent-contrast bg-accent-9 border-accent-9 hover:bg-accent-10 focus:ring-gray-a3 relative isolate inline-flex w-full select-none appearance-none items-center justify-center rounded-md border px-space-2 py-space-1.5 text-[0.8125rem]/[1.125rem] font-medium shadow-[0_1px_1px_0_theme(colors.white/.07)_inset] outline-none ring-[0.1875rem] ring-transparent before:absolute before:inset-0 before:rounded-[calc(theme(borderRadius.md)-1px)] before:shadow-[0_1px_1px_0_theme(colors.white/.07)_inset] after:pointer-events-none after:absolute after:inset-0 after:-z-10 after:rounded-[calc(theme(borderRadius.md)-1px)] after:bg-gradient-to-b after:from-white/10 after:to-transparent hover:after:opacity-0 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50', | ||
className, | ||
)} | ||
> | ||
{children} | ||
|
||
<Icon.CaretRight className='text-[0.625rem] ml-2 opacity-60 shrink-0' /> | ||
</button> | ||
); | ||
}, | ||
); | ||
export const Button = React.forwardRef(function Button( | ||
{ | ||
busy, | ||
children, | ||
className, | ||
disabled, | ||
icon, | ||
...props | ||
}: React.ButtonHTMLAttributes<HTMLButtonElement> & { busy?: boolean; icon?: React.ReactNode }, | ||
forwardedRef: React.ForwardedRef<HTMLButtonElement>, | ||
) { | ||
return ( | ||
// eslint-disable-next-line react/button-has-type | ||
<button | ||
ref={forwardedRef} | ||
{...props} | ||
className={cn( | ||
'text-accent-contrast bg-accent-9 border-accent-9 focus:ring-gray-a3 relative isolate inline-flex w-full select-none appearance-none items-center justify-center rounded-md border px-2 py-1.5 text-[0.8125rem]/[1.125rem] font-medium shadow-[0_1px_1px_0_theme(colors.white/.07)_inset] outline-none ring-[0.1875rem] ring-transparent before:absolute before:inset-0 before:rounded-[calc(theme(borderRadius.md)-1px)] before:shadow-[0_1px_1px_0_theme(colors.white/.07)_inset] after:pointer-events-none after:absolute after:inset-0 after:-z-10 after:rounded-[calc(theme(borderRadius.md)-1px)] after:bg-gradient-to-b after:from-white/10 after:to-transparent disabled:pointer-events-none disabled:cursor-not-allowed', | ||
// note: only reduce opacity of `disabled` so `busy` is more prominent | ||
disabled && 'disabled:opacity-50', | ||
!busy && !disabled && 'hover:bg-accent-10 hover:after:opacity-0', | ||
className, | ||
)} | ||
disabled={busy || disabled} | ||
> | ||
{busy ? ( | ||
<Spinner className='shrink-0 text-[1.125rem]'>Loading…</Spinner> | ||
) : ( | ||
<> | ||
{children} | ||
{icon && <span className='text-[0.625rem] ml-2 opacity-60 shrink-0'>{icon}</span>} | ||
</> | ||
)} | ||
</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
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
Oops, something went wrong.