feat(web): shared loading skeleton recipes (List/Form/AppShell) + common.loading (#53)
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import type { Meta, StoryObj } from '@storybook/react-vite'
|
||||
import { expect } from 'storybook/test'
|
||||
|
||||
import { AppShellSkeleton, FormSkeleton, ListSkeleton } from './skeletons'
|
||||
|
||||
const meta = {
|
||||
component: ListSkeleton,
|
||||
tags: ['ai-generated'],
|
||||
} satisfies Meta<typeof ListSkeleton>
|
||||
|
||||
export default meta
|
||||
type Story = StoryObj<typeof meta>
|
||||
|
||||
export const List: Story = {
|
||||
render: () => <ListSkeleton rows={4} />,
|
||||
play: async ({ canvas }) => {
|
||||
await expect(canvas.getByRole('status')).toBeInTheDocument()
|
||||
},
|
||||
}
|
||||
|
||||
export const Form: Story = { render: () => <FormSkeleton /> }
|
||||
|
||||
export const AppShellLoading: Story = { render: () => <AppShellSkeleton /> }
|
||||
@@ -0,0 +1,63 @@
|
||||
import { useTranslation } from "react-i18next"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { Skeleton } from "@/components/ui/skeleton"
|
||||
|
||||
function ListSkeleton({
|
||||
rows = 6,
|
||||
rowClassName = "h-9 w-full",
|
||||
className,
|
||||
}: {
|
||||
rows?: number
|
||||
rowClassName?: string
|
||||
className?: string
|
||||
}) {
|
||||
const { t } = useTranslation()
|
||||
return (
|
||||
<div role="status" aria-busy="true" aria-label={t("common.loading")} className={cn("space-y-2 p-3", className)}>
|
||||
{Array.from({ length: rows }).map((_, i) => (
|
||||
<Skeleton key={i} className={rowClassName} />
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function FormSkeleton({ fields = 5, className }: { fields?: number; className?: string }) {
|
||||
const { t } = useTranslation()
|
||||
return (
|
||||
<div role="status" aria-busy="true" aria-label={t("common.loading")} className={cn("space-y-4 p-4", className)}>
|
||||
{Array.from({ length: fields }).map((_, i) => (
|
||||
<div key={i} className="space-y-1">
|
||||
<Skeleton className="h-3 w-24" />
|
||||
<Skeleton className="h-8 w-full" />
|
||||
</div>
|
||||
))}
|
||||
<Skeleton className="h-8 w-28" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function AppShellSkeleton() {
|
||||
const { t } = useTranslation()
|
||||
return (
|
||||
<div role="status" aria-busy="true" aria-label={t("common.loading")} className="flex min-h-screen">
|
||||
<aside className="w-44 space-y-2 border-r p-3">
|
||||
{Array.from({ length: 5 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-8 w-full" />
|
||||
))}
|
||||
</aside>
|
||||
<div className="flex flex-1 flex-col">
|
||||
<div className="flex items-center border-b px-4 py-2">
|
||||
<Skeleton className="h-6 w-40" />
|
||||
</div>
|
||||
<div className="flex-1 space-y-2 p-3">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<Skeleton key={i} className="h-9 w-full" />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export { ListSkeleton, FormSkeleton, AppShellSkeleton }
|
||||
Reference in New Issue
Block a user