Polish: link buttons, theme-aware dark variant, assistant drawer overlay, sticky draft bar
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
aed14cd04f
commit
c549c34f60
13 changed files with 60 additions and 66 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { CircleAlert, Inbox, LoaderCircle, X } from 'lucide-react';
|
||||
import { AlertDialog, Dialog as RDialog, DropdownMenu, Popover as RPopover, Switch as RSwitch, Tooltip as RTooltip } from 'radix-ui';
|
||||
import { createContext, forwardRef, useCallback, useContext, useEffect, useId, useRef, useState, type ButtonHTMLAttributes, type InputHTMLAttributes, type ReactNode, type SelectHTMLAttributes, type TextareaHTMLAttributes } from 'react';
|
||||
import { Link } from 'react-router';
|
||||
import { cx } from '@/lib/util';
|
||||
|
||||
/* ------------------------------ Button ------------------------------ */
|
||||
|
|
@ -27,29 +28,49 @@ export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|||
loading?: boolean;
|
||||
icon?: ReactNode;
|
||||
block?: boolean;
|
||||
/** Renders a link to a page inside the app that looks like a button. */
|
||||
to?: string;
|
||||
/** Renders an ordinary link (downloads, external pages) that looks like a button. */
|
||||
href?: string;
|
||||
target?: string;
|
||||
download?: string | boolean;
|
||||
}
|
||||
|
||||
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button(
|
||||
{ variant = 'secondary', size = 'md', loading, icon, block, className, children, disabled, type = 'button', ...rest },
|
||||
{ variant = 'secondary', size = 'md', loading, icon, block, className, children, disabled, type = 'button', to, href, target, download, ...rest },
|
||||
ref,
|
||||
) {
|
||||
return (
|
||||
<button
|
||||
ref={ref}
|
||||
type={type}
|
||||
disabled={disabled || loading}
|
||||
aria-busy={loading || undefined}
|
||||
className={cx(
|
||||
'inline-flex shrink-0 select-none items-center justify-center font-medium whitespace-nowrap transition-[background,color,filter,transform] duration-100 active:scale-[0.985] disabled:pointer-events-none disabled:opacity-50',
|
||||
VARIANT[variant],
|
||||
SIZE[size],
|
||||
block && 'w-full',
|
||||
className,
|
||||
)}
|
||||
{...rest}
|
||||
>
|
||||
const classes = cx(
|
||||
'inline-flex shrink-0 select-none items-center justify-center font-medium whitespace-nowrap transition-[background,color,filter,transform] duration-100 active:scale-[0.985] disabled:pointer-events-none disabled:opacity-50',
|
||||
VARIANT[variant],
|
||||
SIZE[size],
|
||||
block && 'w-full',
|
||||
className,
|
||||
);
|
||||
const content = (
|
||||
<>
|
||||
{loading ? <LoaderCircle className="size-4 animate-spin" aria-hidden /> : icon ? <span className="grid shrink-0 place-items-center [&>svg]:size-4" aria-hidden>{icon}</span> : null}
|
||||
{children}
|
||||
</>
|
||||
);
|
||||
// A disabled link is not a thing: fall through to a disabled button.
|
||||
if (!disabled && !loading && to) {
|
||||
return (
|
||||
<Link to={to} className={classes} onClick={rest.onClick as never} aria-label={rest['aria-label']}>
|
||||
{content}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
if (!disabled && !loading && href) {
|
||||
return (
|
||||
<a href={href} target={target} download={download} rel={target === '_blank' ? 'noreferrer' : undefined} className={classes} aria-label={rest['aria-label']}>
|
||||
{content}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<button ref={ref} type={type} disabled={disabled || loading} aria-busy={loading || undefined} className={classes} {...rest}>
|
||||
{content}
|
||||
</button>
|
||||
);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue