feat: redesign buttons and share them in dialogs
This commit is contained in:
parent
b9a708b2e9
commit
af248df648
@ -1,16 +1,15 @@
|
|||||||
import type { Dispatch, SetStateAction } from 'react';
|
import type { Dispatch, SetStateAction } from 'react';
|
||||||
import React, { useRef } from 'react';
|
import React, { useRef } from 'react';
|
||||||
import { Button as AriaButton } from 'react-aria-components';
|
import { useButton, type AriaButtonOptions } from 'react-aria';
|
||||||
import { useButton } from 'react-aria';
|
|
||||||
import { cn } from '~/utils/cn';
|
import { cn } from '~/utils/cn';
|
||||||
|
|
||||||
export interface ButtonProps extends React.HTMLProps<HTMLButtonElement> {
|
export interface ButtonProps extends AriaButtonOptions<'button'> {
|
||||||
variant?: 'heavy'
|
variant?: 'heavy' | 'light'
|
||||||
isDisabled?: boolean
|
className?: string
|
||||||
children?: React.ReactNode
|
children?: React.ReactNode
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Button({ variant = 'light', ...props }: Props) {
|
export default function Button({ variant = 'light', ...props }: ButtonProps) {
|
||||||
const ref = useRef<HTMLButtonElement | null>(null);
|
const ref = useRef<HTMLButtonElement | null>(null);
|
||||||
const { buttonProps } = useButton(props, ref);
|
const { buttonProps } = useButton(props, ref);
|
||||||
|
|
||||||
|
|||||||
@ -1,17 +1,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Title from '~/components/Title';
|
import Title from '~/components/Title';
|
||||||
|
import Text from '~/components/Text';
|
||||||
import { cn } from '~/utils/cn';
|
import { cn } from '~/utils/cn';
|
||||||
|
|
||||||
function Text(props: React.HTMLProps<HTMLParagraphElement>) {
|
|
||||||
return (
|
|
||||||
<p {...props} className={cn('text-base leading-6 my-0', props.className)} />
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
type Props = React.HTMLProps<HTMLDivElement> & {
|
|
||||||
variant?: 'raised' | 'flat';
|
|
||||||
};
|
|
||||||
|
|
||||||
interface Props extends React.HTMLProps<HTMLDivElement> {
|
interface Props extends React.HTMLProps<HTMLDivElement> {
|
||||||
variant?: 'raised' | 'flat';
|
variant?: 'raised' | 'flat';
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,17 +1,17 @@
|
|||||||
import React, { Dispatch, ReactNode, SetStateAction } from 'react';
|
import React, { Dispatch, ReactNode, SetStateAction } from 'react';
|
||||||
import Button, { ButtonProps } from '~/components/Button';
|
import Button, { ButtonProps } from '~/components/Button';
|
||||||
import Title from '~/components/Title';
|
import Title from '~/components/Title';
|
||||||
|
import Text from '~/components/Text';
|
||||||
|
import Card from '~/components/Card';
|
||||||
import {
|
import {
|
||||||
Button as AriaButton,
|
|
||||||
Dialog as AriaDialog,
|
Dialog as AriaDialog,
|
||||||
DialogTrigger,
|
DialogTrigger,
|
||||||
Heading as AriaHeading,
|
|
||||||
Modal,
|
Modal,
|
||||||
ModalOverlay,
|
ModalOverlay,
|
||||||
} from 'react-aria-components';
|
} from 'react-aria-components';
|
||||||
import { cn } from '~/utils/cn';
|
import { cn } from '~/utils/cn';
|
||||||
|
|
||||||
interface ActionProps extends ButtonProps {
|
interface ActionProps extends Omit<ButtonProps, 'variant'> {
|
||||||
variant: 'cancel' | 'confirm';
|
variant: 'cancel' | 'confirm';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,10 +25,16 @@ function Action(props: ActionProps) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Text(props: React.HTMLProps<HTMLParagraphElement>) {
|
interface GutterProps {
|
||||||
|
children: ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
function Gutter({ children }: GutterProps) {
|
||||||
return (
|
return (
|
||||||
<p {...props} className={cn('text-base leading-6 my-0', props.className)} />
|
<div className="mt-6 flex justify-end gap-2 mt-6">
|
||||||
);
|
{children}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PanelProps {
|
interface PanelProps {
|
||||||
@ -42,29 +48,28 @@ function Panel({ children, control, className }: PanelProps) {
|
|||||||
<ModalOverlay
|
<ModalOverlay
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
className={cn(
|
className={cn(
|
||||||
'fixed inset-0 h-screen w-screen z-50 bg-black/30',
|
'fixed inset-0 h-screen w-screen z-50',
|
||||||
'flex items-center justify-center dark:bg-black/70',
|
'flex items-center justify-center',
|
||||||
|
'bg-headplane-900/15 dark:bg-headplane-900/30',
|
||||||
'entering:animate-in exiting:animate-out',
|
'entering:animate-in exiting:animate-out',
|
||||||
'entering:fade-in entering:duration-200 entering:ease-out',
|
'entering:fade-in entering:duration-100 entering:ease-out',
|
||||||
'exiting:fade-out exiting:duration-100 exiting:ease-in',
|
'exiting:fade-out exiting:duration-50 exiting:ease-in',
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
isOpen={control ? control[0] : undefined}
|
isOpen={control ? control[0] : undefined}
|
||||||
onOpenChange={control ? control[1] : undefined}
|
onOpenChange={control ? control[1] : undefined}
|
||||||
>
|
>
|
||||||
<Modal
|
<Modal className={cn(
|
||||||
className={cn(
|
'bg-white dark:bg-headplane-900 rounded-3xl w-full max-w-lg',
|
||||||
'w-full max-w-md overflow-hidden rounded-2xl p-4',
|
'entering:animate-in exiting:animate-out',
|
||||||
'bg-ui-50 dark:bg-ui-900 shadow-lg',
|
'entering:zoom-in-95 entering:ease-out entering:duration-100',
|
||||||
'entering:animate-in exiting:animate-out',
|
'exiting:zoom-out-95 exiting:ease-in exiting:duration-50',
|
||||||
'dark:border dark:border-ui-700',
|
)}>
|
||||||
'entering:zoom-in-95 entering:ease-out entering:duration-200',
|
<Card variant="flat" className="w-full max-w-lg">
|
||||||
'exiting:zoom-out-95 exiting:ease-in exiting:duration-100',
|
<AriaDialog role="alertdialog" className="outline-none">
|
||||||
)}
|
{({ close }) => children(close)}
|
||||||
>
|
</AriaDialog>
|
||||||
<AriaDialog role="alertdialog" className="outline-none relative">
|
</Card>
|
||||||
{({ close }) => children(close)}
|
|
||||||
</AriaDialog>
|
|
||||||
</Modal>
|
</Modal>
|
||||||
</ModalOverlay>
|
</ModalOverlay>
|
||||||
);
|
);
|
||||||
@ -83,4 +88,11 @@ function Dialog({ children, control }: DialogProps) {
|
|||||||
return <DialogTrigger>{children}</DialogTrigger>;
|
return <DialogTrigger>{children}</DialogTrigger>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Object.assign(Dialog, { Button, Title, Text, Panel, Action });
|
export default Object.assign(Dialog, {
|
||||||
|
Action,
|
||||||
|
Button,
|
||||||
|
Gutter,
|
||||||
|
Panel,
|
||||||
|
Title,
|
||||||
|
Text,
|
||||||
|
});
|
||||||
|
|||||||
@ -1,17 +1,16 @@
|
|||||||
import type { Dispatch, SetStateAction } from 'react';
|
import type { Dispatch, SetStateAction } from 'react';
|
||||||
import React, { useRef } from 'react';
|
import React, { useRef } from 'react';
|
||||||
import { Button as AriaButton } from 'react-aria-components';
|
import { useButton, type AriaButtonOptions } from 'react-aria';
|
||||||
import { useButton } from 'react-aria';
|
|
||||||
import { cn } from '~/utils/cn';
|
import { cn } from '~/utils/cn';
|
||||||
|
|
||||||
interface Props extends React.HTMLProps<HTMLButtonElement> {
|
export interface IconButtonProps extends AriaButtonOptions<'button'> {
|
||||||
variant?: 'heavy'
|
variant?: 'heavy' | 'light'
|
||||||
isDisabled?: boolean
|
className?: string
|
||||||
children: React.ReactNode
|
children: React.ReactNode
|
||||||
label: string
|
label: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function IconButton({ variant = 'light', ...props }: Props) {
|
export default function IconButton({ variant = 'light', ...props }: IconButtonProps) {
|
||||||
const ref = useRef<HTMLButtonElement | null>(null);
|
const ref = useRef<HTMLButtonElement | null>(null);
|
||||||
const { buttonProps } = useButton(props, ref);
|
const { buttonProps } = useButton(props, ref);
|
||||||
|
|
||||||
|
|||||||
15
app/components/Text.tsx
Normal file
15
app/components/Text.tsx
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { cn } from '~/utils/cn';
|
||||||
|
|
||||||
|
export interface TextProps {
|
||||||
|
children: React.ReactNode;
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Text({ children, className }: TextProps) {
|
||||||
|
return (
|
||||||
|
<p className={cn('text-md my-0', className)}>
|
||||||
|
{children}
|
||||||
|
</p>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -1,12 +1,14 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { cn } from '~/utils/cn';
|
||||||
|
|
||||||
export interface TitleProps {
|
export interface TitleProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Title({ children }: TitleProps) {
|
export default function Title({ children, className }: TitleProps) {
|
||||||
return (
|
return (
|
||||||
<h3 className="text-2xl font-bold mb-6">
|
<h3 className={cn('text-2xl font-bold mb-6', className)}>
|
||||||
{children}
|
{children}
|
||||||
</h3>
|
</h3>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -111,9 +111,12 @@ export default function MachineRow({ machine, routes, magic, users, stats }: Pro
|
|||||||
<div className="flex items-center gap-x-1">
|
<div className="flex items-center gap-x-1">
|
||||||
{machine.ipAddresses[0]}
|
{machine.ipAddresses[0]}
|
||||||
<Menu>
|
<Menu>
|
||||||
<Menu.Button>
|
<Menu.IconButton
|
||||||
|
className="bg-transparent"
|
||||||
|
label="IP Addresses"
|
||||||
|
>
|
||||||
<ChevronDownIcon className="w-4 h-4" />
|
<ChevronDownIcon className="w-4 h-4" />
|
||||||
</Menu.Button>
|
</Menu.IconButton>
|
||||||
<Menu.Items>
|
<Menu.Items>
|
||||||
{machine.ipAddresses.map((ip) => (
|
{machine.ipAddresses.map((ip) => (
|
||||||
<Menu.ItemButton
|
<Menu.ItemButton
|
||||||
|
|||||||
@ -64,7 +64,7 @@ export async function action({ request }: ActionFunctionArgs) {
|
|||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
const { machine, magic, routes, users } = useLoaderData<typeof loader>();
|
const { machine, magic, routes, users } = useLoaderData<typeof loader>();
|
||||||
const routesState = useState(false);
|
const [showRouting, setShowRouting] = useState(false);
|
||||||
useLiveData({ interval: 1000 });
|
useLiveData({ interval: 1000 });
|
||||||
|
|
||||||
const expired =
|
const expired =
|
||||||
@ -201,7 +201,11 @@ export default function Page() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<h2 className="text-xl font-medium mb-4 mt-8">Subnets & Routing</h2>
|
<h2 className="text-xl font-medium mb-4 mt-8">Subnets & Routing</h2>
|
||||||
<Routes machine={machine} routes={routes} state={routesState} />
|
<Routes
|
||||||
|
machine={machine}
|
||||||
|
routes={routes}
|
||||||
|
state={[showRouting, setShowRouting]}
|
||||||
|
/>
|
||||||
<div className="flex items-center justify-between mb-4">
|
<div className="flex items-center justify-between mb-4">
|
||||||
<p>
|
<p>
|
||||||
Subnets let you expose physical network routes onto Tailscale.{' '}
|
Subnets let you expose physical network routes onto Tailscale.{' '}
|
||||||
@ -212,7 +216,7 @@ export default function Page() {
|
|||||||
Learn More
|
Learn More
|
||||||
</Link>
|
</Link>
|
||||||
</p>
|
</p>
|
||||||
<Button variant="light" control={routesState}>
|
<Button onPress={() => setShowRouting(true)}>
|
||||||
Review
|
Review
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
@ -247,13 +251,11 @@ export default function Page() {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<Button
|
||||||
|
onPress={() => setShowRouting(true)}
|
||||||
className={cn(
|
className={cn(
|
||||||
'p-0 rounded-sm bg-transparent mt-1',
|
'px-1.5 py-0.5 rounded-md mt-1.5',
|
||||||
'text-blue-500 dark:text-blue-400',
|
'text-blue-500 dark:text-blue-400',
|
||||||
'hover:bg-transparent',
|
|
||||||
'hover:text-blue-600 dark:hover:text-blue-500',
|
|
||||||
)}
|
)}
|
||||||
control={routesState}
|
|
||||||
>
|
>
|
||||||
Edit
|
Edit
|
||||||
</Button>
|
</Button>
|
||||||
@ -283,13 +285,11 @@ export default function Page() {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<Button
|
||||||
|
onPress={() => setShowRouting(true)}
|
||||||
className={cn(
|
className={cn(
|
||||||
'p-0 rounded-sm bg-transparent mt-1',
|
'px-1.5 py-0.5 rounded-md mt-1.5',
|
||||||
'text-blue-500 dark:text-blue-400',
|
'text-blue-500 dark:text-blue-400',
|
||||||
'hover:bg-transparent',
|
|
||||||
'hover:text-blue-600 dark:hover:text-blue-500',
|
|
||||||
)}
|
)}
|
||||||
control={routesState}
|
|
||||||
>
|
>
|
||||||
Edit
|
Edit
|
||||||
</Button>
|
</Button>
|
||||||
@ -322,13 +322,11 @@ export default function Page() {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<Button
|
||||||
|
onPress={() => setShowRouting(true)}
|
||||||
className={cn(
|
className={cn(
|
||||||
'p-0 rounded-sm bg-transparent mt-1',
|
'px-1.5 py-0.5 rounded-md mt-1.5',
|
||||||
'text-blue-500 dark:text-blue-400',
|
'text-blue-500 dark:text-blue-400',
|
||||||
'hover:bg-transparent',
|
|
||||||
'hover:text-blue-600 dark:hover:text-blue-500',
|
|
||||||
)}
|
)}
|
||||||
control={routesState}
|
|
||||||
>
|
>
|
||||||
Edit
|
Edit
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
import { XIcon } from '@primer/octicons-react';
|
import { X } from 'lucide-react';
|
||||||
import { Form, useSubmit } from 'react-router';
|
import { Form, useSubmit } from 'react-router';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
import Button from '~/components/Button';
|
import IconButton from '~/components/IconButton';
|
||||||
import Code from '~/components/Code';
|
import Code from '~/components/Code';
|
||||||
import Dialog from '~/components/Dialog';
|
import Dialog from '~/components/Dialog';
|
||||||
|
|
||||||
@ -12,19 +12,18 @@ interface Props {
|
|||||||
|
|
||||||
export default function Remove({ username }: Props) {
|
export default function Remove({ username }: Props) {
|
||||||
const submit = useSubmit();
|
const submit = useSubmit();
|
||||||
const dialogState = useState(false);
|
const [dialog, setDialog] = useState(false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Button
|
<IconButton
|
||||||
variant="light"
|
label={`Delete ${username}`}
|
||||||
control={dialogState}
|
onPress={() => setDialog(true)}
|
||||||
className="rounded-full p-0 w-8 h-8 flex items-center justify-center"
|
|
||||||
>
|
>
|
||||||
<XIcon className="w-4 h-4" />
|
<X className="p-0.5" />
|
||||||
</Button>
|
</IconButton>
|
||||||
<Dialog control={dialogState}>
|
<Dialog control={[dialog, setDialog]}>
|
||||||
<Dialog.Panel control={dialogState}>
|
<Dialog.Panel control={[dialog, setDialog]}>
|
||||||
{(close) => (
|
{(close) => (
|
||||||
<>
|
<>
|
||||||
<Dialog.Title>Delete {username}?</Dialog.Title>
|
<Dialog.Title>Delete {username}?</Dialog.Title>
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
import { PencilIcon } from '@primer/octicons-react';
|
import { Pencil } from 'lucide-react';
|
||||||
import { Form, useSubmit } from 'react-router';
|
import { Form, useSubmit } from 'react-router';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
import Button from '~/components/Button';
|
import IconButton from '~/components/IconButton';
|
||||||
import Dialog from '~/components/Dialog';
|
import Dialog from '~/components/Dialog';
|
||||||
import TextField from '~/components/TextField';
|
import TextField from '~/components/TextField';
|
||||||
|
|
||||||
@ -13,20 +13,19 @@ interface Props {
|
|||||||
|
|
||||||
export default function Rename({ username, magic }: Props) {
|
export default function Rename({ username, magic }: Props) {
|
||||||
const submit = useSubmit();
|
const submit = useSubmit();
|
||||||
const dialogState = useState(false);
|
const [dialog, setDialog] = useState(false);
|
||||||
const [newName, setNewName] = useState(username);
|
const [newName, setNewName] = useState(username);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Button
|
<IconButton
|
||||||
variant="light"
|
label={`Rename ${username}`}
|
||||||
control={dialogState}
|
onPress={() => setDialog(true)}
|
||||||
className="rounded-full p-0 w-8 h-8 flex items-center justify-center"
|
|
||||||
>
|
>
|
||||||
<PencilIcon className="w-4 h-4" />
|
<Pencil className="p-1" />
|
||||||
</Button>
|
</IconButton>
|
||||||
<Dialog control={dialogState}>
|
<Dialog control={[dialog, setDialog]}>
|
||||||
<Dialog.Panel control={dialogState}>
|
<Dialog.Panel control={[dialog, setDialog]}>
|
||||||
{(close) => (
|
{(close) => (
|
||||||
<>
|
<>
|
||||||
<Dialog.Title>Rename {username}?</Dialog.Title>
|
<Dialog.Title>Rename {username}?</Dialog.Title>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user