Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions app/components/ui/button.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Slot } from '@radix-ui/react-slot'
import { Slot, Slottable } from '@radix-ui/react-slot'
import { cva, type VariantProps } from 'class-variance-authority'
import type * as React from 'react'

Expand Down Expand Up @@ -26,10 +26,14 @@ const buttonVariants = cva(
lg: 'h-10 rounded-md px-6 has-[>svg]:px-4',
icon: 'size-9',
},
isLoading: {
true: 'cursor-progress',
},
},
defaultVariants: {
variant: 'default',
size: 'default',
isLoading: false,
},
},
)
Expand All @@ -39,19 +43,27 @@ function Button({
variant,
size,
asChild = false,
isLoading = false,
children,
...props
}: React.ComponentProps<'button'> &
VariantProps<typeof buttonVariants> & {
asChild?: boolean
isLoading?: boolean
}) {
const Comp = asChild ? Slot : 'button'

return (
<Comp
data-slot="button"
className={cn(buttonVariants({ variant, size, className }))}
className={cn(buttonVariants({ variant, size, isLoading, className }))}
{...props}
/>
>
{isLoading && (
<span className="border-background mr-2 h-4 w-4 animate-spin rounded-full border-2 border-t-transparent" />
)}
<Slottable>{children}</Slottable>
</Comp>
)
}

Expand Down
4 changes: 3 additions & 1 deletion app/routes/$handle+/posts.$id.edit/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@conform-to/react'
import { parseWithZod } from '@conform-to/zod'
import { ArrowLeftIcon } from 'lucide-react'
import { data, Form, href, Link, redirect } from 'react-router'
import { data, Form, href, Link, redirect, useNavigation } from 'react-router'
import { z } from 'zod'
import { AppHeadingSection } from '~/components/AppHeadingSection'
import { Button, Input, Label, Textarea } from '~/components/ui'
Expand Down Expand Up @@ -95,6 +95,7 @@ export default function PostEditPage({
shouldValidate: 'onInput',
onValidate: ({ formData }) => parseWithZod(formData, { schema }),
})
const navigation = useNavigation()

return (
<div className="relative">
Expand Down Expand Up @@ -130,6 +131,7 @@ export default function PostEditPage({
name="intent"
value="update"
form={form.id}
isLoading={navigation.state === 'submitting'}
>
更新する
</Button>
Expand Down
6 changes: 5 additions & 1 deletion app/routes/auth+/sign_in/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ const SignInForm = () => {
return (
<div className="mx-auto text-center">
<fetcher.Form method="POST" action={href('/auth/sign_in')}>
<Button type="submit" className="rounded-full">
<Button
type="submit"
className="rounded-full"
isLoading={fetcher.state !== 'idle'}
>
Google アカウントでサインイン
</Button>
</fetcher.Form>
Expand Down