create-einja-app 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +307 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +1041 -0
- package/dist/cli.js.map +1 -0
- package/package.json +62 -0
- package/templates/turborepo-pandacss/.biomeignore +15 -0
- package/templates/turborepo-pandacss/.claude/hooks/einja/biome-format.sh +49 -0
- package/templates/turborepo-pandacss/.claude/hooks/einja/design-doc-check.sh +61 -0
- package/templates/turborepo-pandacss/.claude/hooks/einja/detect-secrets.sh +62 -0
- package/templates/turborepo-pandacss/.claude/hooks/einja/large-file-warning.sh +42 -0
- package/templates/turborepo-pandacss/.claude/hooks/einja/playwright-resize.sh +36 -0
- package/templates/turborepo-pandacss/.claude/hooks/einja/typecheck.sh +37 -0
- package/templates/turborepo-pandacss/.claude/hooks/einja/unset-volta-recursion.sh +32 -0
- package/templates/turborepo-pandacss/.claude/hooks/einja/validate-git-commit.sh +239 -0
- package/templates/turborepo-pandacss/.claude/hooks/einja/warn-index-ts.sh +34 -0
- package/templates/turborepo-pandacss/.claude/hooks/einja/warn-relative-import.sh +48 -0
- package/templates/turborepo-pandacss/.claude/settings.json +174 -0
- package/templates/turborepo-pandacss/.claude/skills/create-einja-app-release/SKILL.md +186 -0
- package/templates/turborepo-pandacss/.claude/skills/dev-cli-release/SKILL.md +173 -0
- package/templates/turborepo-pandacss/.cursor/commands/spec-create.md +227 -0
- package/templates/turborepo-pandacss/.cursor/commands/start-dev.md +98 -0
- package/templates/turborepo-pandacss/.cursor/commands/task-exec.md +287 -0
- package/templates/turborepo-pandacss/.cursor/commands/task-vibe-kanban-loop.md +532 -0
- package/templates/turborepo-pandacss/.cursor/commands/update-docs-by-task-specs.md +448 -0
- package/templates/turborepo-pandacss/.cursor/mcp.json +45 -0
- package/templates/turborepo-pandacss/.cursor/rules/api-rules.mdc +171 -0
- package/templates/turborepo-pandacss/.cursor/rules/api-test-rules.mdc +181 -0
- package/templates/turborepo-pandacss/.cursor/rules/base-code.mdc +70 -0
- package/templates/turborepo-pandacss/.cursor/rules/base-commit-rules.mdc +174 -0
- package/templates/turborepo-pandacss/.cursor/rules/base-design.mdc +12 -0
- package/templates/turborepo-pandacss/.cursor/rules/base-rules.mdc +231 -0
- package/templates/turborepo-pandacss/.cursor/rules/error-handling-rules.mdc +188 -0
- package/templates/turborepo-pandacss/.cursor/rules/refactor-rules.mdc +93 -0
- package/templates/turborepo-pandacss/.dockerignore +126 -0
- package/templates/turborepo-pandacss/.einja-sync.json +35 -0
- package/templates/turborepo-pandacss/.env.ci +25 -0
- package/templates/turborepo-pandacss/.env.example +35 -0
- package/templates/turborepo-pandacss/.env.personal.example +27 -0
- package/templates/turborepo-pandacss/.envrc +4 -0
- package/templates/turborepo-pandacss/.gitattributes +5 -0
- package/templates/turborepo-pandacss/.husky/pre-commit +1 -0
- package/templates/turborepo-pandacss/.lintstagedrc.js +24 -0
- package/templates/turborepo-pandacss/.mcp.json +45 -0
- package/templates/turborepo-pandacss/.node-version +1 -0
- package/templates/turborepo-pandacss/.templateignore +60 -0
- package/templates/turborepo-pandacss/.vscode/extensions.json +3 -0
- package/templates/turborepo-pandacss/CLAUDE.md +415 -0
- package/templates/turborepo-pandacss/README.md +322 -0
- package/templates/turborepo-pandacss/apps/web/middleware.ts +28 -0
- package/templates/turborepo-pandacss/apps/web/next.config.ts +10 -0
- package/templates/turborepo-pandacss/apps/web/package.json +80 -0
- package/templates/turborepo-pandacss/apps/web/panda.config.ts +114 -0
- package/templates/turborepo-pandacss/apps/web/postcss.config.cjs +6 -0
- package/templates/turborepo-pandacss/apps/web/public/file.svg +1 -0
- package/templates/turborepo-pandacss/apps/web/public/globe.svg +1 -0
- package/templates/turborepo-pandacss/apps/web/public/next.svg +1 -0
- package/templates/turborepo-pandacss/apps/web/public/vercel.svg +1 -0
- package/templates/turborepo-pandacss/apps/web/public/window.svg +1 -0
- package/templates/turborepo-pandacss/apps/web/src/app/(authenticated)/dashboard/page.tsx +79 -0
- package/templates/turborepo-pandacss/apps/web/src/app/(authenticated)/data/_components/UserTable.tsx +203 -0
- package/templates/turborepo-pandacss/apps/web/src/app/(authenticated)/data/page.tsx +57 -0
- package/templates/turborepo-pandacss/apps/web/src/app/(authenticated)/layout-client.tsx +31 -0
- package/templates/turborepo-pandacss/apps/web/src/app/(authenticated)/layout.tsx +17 -0
- package/templates/turborepo-pandacss/apps/web/src/app/(authenticated)/profile/page.tsx +59 -0
- package/templates/turborepo-pandacss/apps/web/src/app/api/auth/[...nextauth]/route.ts +3 -0
- package/templates/turborepo-pandacss/apps/web/src/app/api/auth/signup/route.ts +70 -0
- package/templates/turborepo-pandacss/apps/web/src/app/error.tsx +106 -0
- package/templates/turborepo-pandacss/apps/web/src/app/favicon.ico +0 -0
- package/templates/turborepo-pandacss/apps/web/src/app/global-error.tsx +110 -0
- package/templates/turborepo-pandacss/apps/web/src/app/globals.css +121 -0
- package/templates/turborepo-pandacss/apps/web/src/app/layout.tsx +28 -0
- package/templates/turborepo-pandacss/apps/web/src/app/not-found.tsx +54 -0
- package/templates/turborepo-pandacss/apps/web/src/app/page.module.css +165 -0
- package/templates/turborepo-pandacss/apps/web/src/app/page.test.tsx +52 -0
- package/templates/turborepo-pandacss/apps/web/src/app/page.tsx +284 -0
- package/templates/turborepo-pandacss/apps/web/src/app/signin/page.tsx +296 -0
- package/templates/turborepo-pandacss/apps/web/src/app/signup/page.tsx +395 -0
- package/templates/turborepo-pandacss/apps/web/src/application/use-cases/UserUseCases.test.ts +229 -0
- package/templates/turborepo-pandacss/apps/web/src/application/use-cases/UserUseCases.ts +115 -0
- package/templates/turborepo-pandacss/apps/web/src/components/auth/login-button.tsx +35 -0
- package/templates/turborepo-pandacss/apps/web/src/components/auth/logout-button.tsx +24 -0
- package/templates/turborepo-pandacss/apps/web/src/components/auth/user-avatar.test.tsx +68 -0
- package/templates/turborepo-pandacss/apps/web/src/components/auth/user-avatar.tsx +43 -0
- package/templates/turborepo-pandacss/apps/web/src/components/dashboard/dashboard-stats.tsx +128 -0
- package/templates/turborepo-pandacss/apps/web/src/components/providers/query-provider.tsx +30 -0
- package/templates/turborepo-pandacss/apps/web/src/components/providers/session-provider.tsx +12 -0
- package/templates/turborepo-pandacss/apps/web/src/components/shared/Sidebar.tsx +175 -0
- package/templates/turborepo-pandacss/apps/web/src/components/shared/header.tsx +166 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/accordion.tsx +64 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/alert-dialog.tsx +135 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/alert.tsx +60 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/aspect-ratio.tsx +9 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/avatar.tsx +41 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/badge.tsx +39 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/breadcrumb.tsx +101 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/button.tsx +56 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/card.tsx +75 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/checkbox.tsx +29 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/data-table.tsx +189 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/dialog-hook.tsx +210 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/dialog.tsx +129 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/drawer.tsx +124 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/dropdown-menu.tsx +228 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/form.tsx +152 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/hover-card.tsx +38 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/input.tsx +21 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/label.tsx +21 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/pagination.tsx +105 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/popover.tsx +42 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/progress.tsx +28 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/select.tsx +170 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/separator.tsx +28 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/skeleton.tsx +13 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/sonner.tsx +25 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/table.tsx +92 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/tabs.tsx +54 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/textarea.tsx +18 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/tooltip.tsx +57 -0
- package/templates/turborepo-pandacss/apps/web/src/components/ui/typography.tsx +158 -0
- package/templates/turborepo-pandacss/apps/web/src/lib/auth/guard.ts +36 -0
- package/templates/turborepo-pandacss/apps/web/src/lib/auth/index.ts +22 -0
- package/templates/turborepo-pandacss/apps/web/src/lib/prisma.ts +3 -0
- package/templates/turborepo-pandacss/apps/web/src/lib/utils.ts +6 -0
- package/templates/turborepo-pandacss/apps/web/test/globals.d.ts +1 -0
- package/templates/turborepo-pandacss/apps/web/test/matchers.d.ts +1 -0
- package/templates/turborepo-pandacss/apps/web/test/setup.ts +22 -0
- package/templates/turborepo-pandacss/apps/web/tsconfig.json +37 -0
- package/templates/turborepo-pandacss/apps/web/vitest.config.ts +20 -0
- package/templates/turborepo-pandacss/apps/web/vitest.d.ts +2 -0
- package/templates/turborepo-pandacss/biome.json +60 -0
- package/templates/turborepo-pandacss/components.json +21 -0
- package/templates/turborepo-pandacss/docker-compose.yml +27 -0
- package/templates/turborepo-pandacss/middleware.ts +32 -0
- package/templates/turborepo-pandacss/next.config.ts +10 -0
- package/templates/turborepo-pandacss/package-lock.json +9346 -0
- package/templates/turborepo-pandacss/package.json +64 -0
- package/templates/turborepo-pandacss/packages/config/package.json +41 -0
- package/templates/turborepo-pandacss/packages/config/panda.config.ts +114 -0
- package/templates/turborepo-pandacss/packages/config/src/index.ts +24 -0
- package/templates/turborepo-pandacss/packages/config/src/worktree-config-loader.ts +129 -0
- package/templates/turborepo-pandacss/packages/config/src/worktree-config.ts +75 -0
- package/templates/turborepo-pandacss/packages/config/tsconfig.build.json +19 -0
- package/templates/turborepo-pandacss/packages/config/tsconfig.json +24 -0
- package/templates/turborepo-pandacss/packages/config/typescript/base.json +19 -0
- package/templates/turborepo-pandacss/packages/front-core/package.json +24 -0
- package/templates/turborepo-pandacss/packages/front-core/src/auth/config.ts +84 -0
- package/templates/turborepo-pandacss/packages/front-core/src/auth/index.ts +5 -0
- package/templates/turborepo-pandacss/packages/front-core/src/auth/types/next-auth.d.ts +20 -0
- package/templates/turborepo-pandacss/packages/front-core/src/auth/utils.ts +29 -0
- package/templates/turborepo-pandacss/packages/front-core/src/context/index.ts +2 -0
- package/templates/turborepo-pandacss/packages/front-core/src/hooks/index.ts +2 -0
- package/templates/turborepo-pandacss/packages/front-core/src/index.ts +4 -0
- package/templates/turborepo-pandacss/packages/front-core/src/utils/index.ts +2 -0
- package/templates/turborepo-pandacss/packages/front-core/tsconfig.json +14 -0
- package/templates/turborepo-pandacss/packages/server-core/package.json +32 -0
- package/templates/turborepo-pandacss/packages/server-core/prisma/schema.prisma +102 -0
- package/templates/turborepo-pandacss/packages/server-core/prisma/seed.ts +67 -0
- package/templates/turborepo-pandacss/packages/server-core/prisma.config.ts +8 -0
- package/templates/turborepo-pandacss/packages/server-core/src/__generated__/fabbrica/index.d.ts +270 -0
- package/templates/turborepo-pandacss/packages/server-core/src/__generated__/fabbrica/index.js +484 -0
- package/templates/turborepo-pandacss/packages/server-core/src/core/result.test.ts +78 -0
- package/templates/turborepo-pandacss/packages/server-core/src/core/result.ts +53 -0
- package/templates/turborepo-pandacss/packages/server-core/src/domain/.gitkeep +0 -0
- package/templates/turborepo-pandacss/packages/server-core/src/domain/entities/User.test.ts +232 -0
- package/templates/turborepo-pandacss/packages/server-core/src/domain/entities/User.ts +105 -0
- package/templates/turborepo-pandacss/packages/server-core/src/domain/repository-interfaces/IUserRepository.ts +101 -0
- package/templates/turborepo-pandacss/packages/server-core/src/infrastructure/database/client.ts +15 -0
- package/templates/turborepo-pandacss/packages/server-core/src/infrastructure/database/mappers/UserMapper.test.ts +278 -0
- package/templates/turborepo-pandacss/packages/server-core/src/infrastructure/database/mappers/UserMapper.ts +103 -0
- package/templates/turborepo-pandacss/packages/server-core/src/infrastructure/database/repositories/UserRepository.test.ts +317 -0
- package/templates/turborepo-pandacss/packages/server-core/src/infrastructure/database/repositories/UserRepository.ts +169 -0
- package/templates/turborepo-pandacss/packages/server-core/src/testing/factories/index.ts +22 -0
- package/templates/turborepo-pandacss/packages/server-core/src/testing/factories/user.factory.ts +123 -0
- package/templates/turborepo-pandacss/packages/server-core/src/testing/fixtures/users.ts +92 -0
- package/templates/turborepo-pandacss/packages/server-core/src/testing/helpers/date.ts +49 -0
- package/templates/turborepo-pandacss/packages/server-core/src/testing/helpers/password.ts +50 -0
- package/templates/turborepo-pandacss/packages/server-core/src/testing/index.ts +26 -0
- package/templates/turborepo-pandacss/packages/server-core/tsconfig.json +14 -0
- package/templates/turborepo-pandacss/packages/server-core/vitest.config.ts +15 -0
- package/templates/turborepo-pandacss/packages/ui/package.json +37 -0
- package/templates/turborepo-pandacss/packages/ui/src/accordion.tsx +66 -0
- package/templates/turborepo-pandacss/packages/ui/src/alert-dialog.tsx +157 -0
- package/templates/turborepo-pandacss/packages/ui/src/alert.tsx +66 -0
- package/templates/turborepo-pandacss/packages/ui/src/aspect-ratio.tsx +11 -0
- package/templates/turborepo-pandacss/packages/ui/src/avatar.tsx +53 -0
- package/templates/turborepo-pandacss/packages/ui/src/badge.tsx +46 -0
- package/templates/turborepo-pandacss/packages/ui/src/breadcrumb.tsx +108 -0
- package/templates/turborepo-pandacss/packages/ui/src/button.tsx +59 -0
- package/templates/turborepo-pandacss/packages/ui/src/card.tsx +92 -0
- package/templates/turborepo-pandacss/packages/ui/src/checkbox.tsx +32 -0
- package/templates/turborepo-pandacss/packages/ui/src/data-table.tsx +216 -0
- package/templates/turborepo-pandacss/packages/ui/src/dialog-hook.tsx +226 -0
- package/templates/turborepo-pandacss/packages/ui/src/dialog.tsx +143 -0
- package/templates/turborepo-pandacss/packages/ui/src/drawer.tsx +135 -0
- package/templates/turborepo-pandacss/packages/ui/src/dropdown-menu.tsx +257 -0
- package/templates/turborepo-pandacss/packages/ui/src/form.tsx +168 -0
- package/templates/turborepo-pandacss/packages/ui/src/hover-card.tsx +44 -0
- package/templates/turborepo-pandacss/packages/ui/src/input.tsx +21 -0
- package/templates/turborepo-pandacss/packages/ui/src/label.tsx +24 -0
- package/templates/turborepo-pandacss/packages/ui/src/lib/utils.ts +6 -0
- package/templates/turborepo-pandacss/packages/ui/src/pagination.tsx +126 -0
- package/templates/turborepo-pandacss/packages/ui/src/popover.tsx +48 -0
- package/templates/turborepo-pandacss/packages/ui/src/progress.tsx +31 -0
- package/templates/turborepo-pandacss/packages/ui/src/select.tsx +185 -0
- package/templates/turborepo-pandacss/packages/ui/src/separator.tsx +28 -0
- package/templates/turborepo-pandacss/packages/ui/src/skeleton.tsx +13 -0
- package/templates/turborepo-pandacss/packages/ui/src/sonner.tsx +25 -0
- package/templates/turborepo-pandacss/packages/ui/src/table.tsx +116 -0
- package/templates/turborepo-pandacss/packages/ui/src/tabs.tsx +66 -0
- package/templates/turborepo-pandacss/packages/ui/src/textarea.tsx +18 -0
- package/templates/turborepo-pandacss/packages/ui/src/tooltip.tsx +61 -0
- package/templates/turborepo-pandacss/packages/ui/src/typography.tsx +187 -0
- package/templates/turborepo-pandacss/packages/ui/tsconfig.json +20 -0
- package/templates/turborepo-pandacss/panda.config.ts +114 -0
- package/templates/turborepo-pandacss/pnpm-lock.yaml +9032 -0
- package/templates/turborepo-pandacss/pnpm-workspace.yaml +11 -0
- package/templates/turborepo-pandacss/postcss.config.cjs +6 -0
- package/templates/turborepo-pandacss/prisma/schema.prisma +82 -0
- package/templates/turborepo-pandacss/public/file.svg +1 -0
- package/templates/turborepo-pandacss/public/globe.svg +1 -0
- package/templates/turborepo-pandacss/public/next.svg +1 -0
- package/templates/turborepo-pandacss/public/vercel.svg +1 -0
- package/templates/turborepo-pandacss/public/window.svg +1 -0
- package/templates/turborepo-pandacss/scripts/cli-template-update.ts +387 -0
- package/templates/turborepo-pandacss/scripts/env-show.ts +129 -0
- package/templates/turborepo-pandacss/scripts/env.ts +555 -0
- package/templates/turborepo-pandacss/scripts/init.sh +92 -0
- package/templates/turborepo-pandacss/scripts/setup-dev.ts +640 -0
- package/templates/turborepo-pandacss/scripts/template-update.ts +277 -0
- package/templates/turborepo-pandacss/scripts/worktree/dev.ts +872 -0
- package/templates/turborepo-pandacss/test/globals.d.ts +1 -0
- package/templates/turborepo-pandacss/test/setup.ts +22 -0
- package/templates/turborepo-pandacss/tsconfig.json +46 -0
- package/templates/turborepo-pandacss/turbo.json +57 -0
- package/templates/turborepo-pandacss/vitest.config.ts +20 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
2
|
+
import { ChevronRight, MoreHorizontal } from "lucide-react";
|
|
3
|
+
import type * as React from "react";
|
|
4
|
+
|
|
5
|
+
import { cn } from "{{packageName}}/ui/utils";
|
|
6
|
+
|
|
7
|
+
function Breadcrumb({ ...props }: React.ComponentProps<"nav">) {
|
|
8
|
+
return <nav aria-label="breadcrumb" data-slot="breadcrumb" {...props} />;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function BreadcrumbList({ className, ...props }: React.ComponentProps<"ol">) {
|
|
12
|
+
return (
|
|
13
|
+
<ol
|
|
14
|
+
data-slot="breadcrumb-list"
|
|
15
|
+
className={cn(
|
|
16
|
+
"text-muted-foreground flex flex-wrap items-center gap-1.5 text-sm break-words sm:gap-2.5",
|
|
17
|
+
className
|
|
18
|
+
)}
|
|
19
|
+
{...props}
|
|
20
|
+
/>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function BreadcrumbItem({ className, ...props }: React.ComponentProps<"li">) {
|
|
25
|
+
return (
|
|
26
|
+
<li
|
|
27
|
+
data-slot="breadcrumb-item"
|
|
28
|
+
className={cn("inline-flex items-center gap-1.5", className)}
|
|
29
|
+
{...props}
|
|
30
|
+
/>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function BreadcrumbLink({
|
|
35
|
+
asChild,
|
|
36
|
+
className,
|
|
37
|
+
...props
|
|
38
|
+
}: React.ComponentProps<"a"> & {
|
|
39
|
+
asChild?: boolean;
|
|
40
|
+
}) {
|
|
41
|
+
const Comp = asChild ? Slot : "a";
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<Comp
|
|
45
|
+
data-slot="breadcrumb-link"
|
|
46
|
+
className={cn("hover:text-foreground transition-colors", className)}
|
|
47
|
+
{...props}
|
|
48
|
+
/>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function BreadcrumbPage({ className, ...props }: React.ComponentProps<"span">) {
|
|
53
|
+
return (
|
|
54
|
+
<span
|
|
55
|
+
data-slot="breadcrumb-page"
|
|
56
|
+
aria-disabled="true"
|
|
57
|
+
aria-current="page"
|
|
58
|
+
className={cn("text-foreground font-normal", className)}
|
|
59
|
+
{...props}
|
|
60
|
+
/>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function BreadcrumbSeparator({ children, className, ...props }: React.ComponentProps<"li">) {
|
|
65
|
+
return (
|
|
66
|
+
<li
|
|
67
|
+
data-slot="breadcrumb-separator"
|
|
68
|
+
role="presentation"
|
|
69
|
+
aria-hidden="true"
|
|
70
|
+
className={cn("[&>svg]:size-3.5", className)}
|
|
71
|
+
{...props}
|
|
72
|
+
>
|
|
73
|
+
{children ?? <ChevronRight />}
|
|
74
|
+
</li>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function BreadcrumbEllipsis({ className, ...props }: React.ComponentProps<"span">) {
|
|
79
|
+
return (
|
|
80
|
+
<span
|
|
81
|
+
data-slot="breadcrumb-ellipsis"
|
|
82
|
+
role="presentation"
|
|
83
|
+
aria-hidden="true"
|
|
84
|
+
className={cn("flex size-9 items-center justify-center", className)}
|
|
85
|
+
{...props}
|
|
86
|
+
>
|
|
87
|
+
<MoreHorizontal className="size-4" />
|
|
88
|
+
<span className="sr-only">More</span>
|
|
89
|
+
</span>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export {
|
|
94
|
+
Breadcrumb,
|
|
95
|
+
BreadcrumbList,
|
|
96
|
+
BreadcrumbItem,
|
|
97
|
+
BreadcrumbLink,
|
|
98
|
+
BreadcrumbPage,
|
|
99
|
+
BreadcrumbSeparator,
|
|
100
|
+
BreadcrumbEllipsis,
|
|
101
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
2
|
+
import { type VariantProps, cva } from "class-variance-authority";
|
|
3
|
+
import type * as React from "react";
|
|
4
|
+
|
|
5
|
+
import { cn } from "{{packageName}}/ui/utils";
|
|
6
|
+
|
|
7
|
+
const buttonVariants = cva(
|
|
8
|
+
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
|
9
|
+
{
|
|
10
|
+
variants: {
|
|
11
|
+
variant: {
|
|
12
|
+
default: "bg-primary text-primary-foreground shadow-xs hover:bg-primary/90",
|
|
13
|
+
destructive:
|
|
14
|
+
"bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
15
|
+
outline:
|
|
16
|
+
"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
|
17
|
+
secondary: "bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80",
|
|
18
|
+
ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
19
|
+
link: "text-primary underline-offset-4 hover:underline",
|
|
20
|
+
},
|
|
21
|
+
size: {
|
|
22
|
+
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
|
23
|
+
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
|
24
|
+
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
|
25
|
+
icon: "size-9",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
defaultVariants: {
|
|
29
|
+
variant: "default",
|
|
30
|
+
size: "default",
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
function Button({
|
|
36
|
+
className,
|
|
37
|
+
variant,
|
|
38
|
+
size,
|
|
39
|
+
asChild = false,
|
|
40
|
+
...props
|
|
41
|
+
}: React.ComponentProps<"button"> &
|
|
42
|
+
VariantProps<typeof buttonVariants> & {
|
|
43
|
+
asChild?: boolean;
|
|
44
|
+
}) {
|
|
45
|
+
const Comp = asChild ? Slot : "button";
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<Comp
|
|
49
|
+
data-slot="button"
|
|
50
|
+
className={cn(buttonVariants({ variant, size, className }))}
|
|
51
|
+
{...props}
|
|
52
|
+
/>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { Button, buttonVariants };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
|
|
3
|
+
import { cn } from "{{packageName}}/ui/utils";
|
|
4
|
+
|
|
5
|
+
function Card({ className, ...props }: React.ComponentProps<"div">) {
|
|
6
|
+
return (
|
|
7
|
+
<div
|
|
8
|
+
data-slot="card"
|
|
9
|
+
className={cn(
|
|
10
|
+
"bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",
|
|
11
|
+
className
|
|
12
|
+
)}
|
|
13
|
+
{...props}
|
|
14
|
+
/>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
|
19
|
+
return (
|
|
20
|
+
<div
|
|
21
|
+
data-slot="card-header"
|
|
22
|
+
className={cn(
|
|
23
|
+
"@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-1.5 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",
|
|
24
|
+
className
|
|
25
|
+
)}
|
|
26
|
+
{...props}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
|
|
32
|
+
return (
|
|
33
|
+
<div
|
|
34
|
+
data-slot="card-title"
|
|
35
|
+
className={cn("leading-none font-semibold", className)}
|
|
36
|
+
{...props}
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
|
|
42
|
+
return (
|
|
43
|
+
<div
|
|
44
|
+
data-slot="card-description"
|
|
45
|
+
className={cn("text-muted-foreground text-sm", className)}
|
|
46
|
+
{...props}
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
|
|
52
|
+
return (
|
|
53
|
+
<div
|
|
54
|
+
data-slot="card-action"
|
|
55
|
+
className={cn("col-start-2 row-span-2 row-start-1 self-start justify-self-end", className)}
|
|
56
|
+
{...props}
|
|
57
|
+
/>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
|
62
|
+
return <div data-slot="card-content" className={cn("px-6", className)} {...props} />;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
|
66
|
+
return (
|
|
67
|
+
<div
|
|
68
|
+
data-slot="card-footer"
|
|
69
|
+
className={cn("flex items-center px-6 [.border-t]:pt-6", className)}
|
|
70
|
+
{...props}
|
|
71
|
+
/>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { Card, CardHeader, CardFooter, CardTitle, CardAction, CardDescription, CardContent };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
|
|
4
|
+
import { CheckIcon } from "lucide-react";
|
|
5
|
+
import type * as React from "react";
|
|
6
|
+
|
|
7
|
+
import { cn } from "{{packageName}}/ui/utils";
|
|
8
|
+
|
|
9
|
+
function Checkbox({ className, ...props }: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
|
|
10
|
+
return (
|
|
11
|
+
<CheckboxPrimitive.Root
|
|
12
|
+
data-slot="checkbox"
|
|
13
|
+
className={cn(
|
|
14
|
+
"peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
|
|
15
|
+
className
|
|
16
|
+
)}
|
|
17
|
+
{...props}
|
|
18
|
+
>
|
|
19
|
+
<CheckboxPrimitive.Indicator
|
|
20
|
+
data-slot="checkbox-indicator"
|
|
21
|
+
className="flex items-center justify-center text-current transition-none"
|
|
22
|
+
>
|
|
23
|
+
<CheckIcon className="size-3.5" />
|
|
24
|
+
</CheckboxPrimitive.Indicator>
|
|
25
|
+
</CheckboxPrimitive.Root>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { Checkbox };
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type ColumnDef,
|
|
5
|
+
type ColumnFiltersState,
|
|
6
|
+
type SortingState,
|
|
7
|
+
type VisibilityState,
|
|
8
|
+
flexRender,
|
|
9
|
+
getCoreRowModel,
|
|
10
|
+
getFilteredRowModel,
|
|
11
|
+
getPaginationRowModel,
|
|
12
|
+
getSortedRowModel,
|
|
13
|
+
useReactTable,
|
|
14
|
+
} from "@tanstack/react-table";
|
|
15
|
+
|
|
16
|
+
import { ChevronDown, ChevronLeft, ChevronRight } from "lucide-react";
|
|
17
|
+
import { useState } from "react";
|
|
18
|
+
import { Button } from "./button";
|
|
19
|
+
import {
|
|
20
|
+
DropdownMenu,
|
|
21
|
+
DropdownMenuCheckboxItem,
|
|
22
|
+
DropdownMenuContent,
|
|
23
|
+
DropdownMenuTrigger,
|
|
24
|
+
} from "./dropdown-menu";
|
|
25
|
+
import { Input } from "./input";
|
|
26
|
+
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "./table";
|
|
27
|
+
|
|
28
|
+
interface DataTableProps<TData, TValue> {
|
|
29
|
+
columns: ColumnDef<TData, TValue>[];
|
|
30
|
+
data: TData[];
|
|
31
|
+
searchKey?: string;
|
|
32
|
+
searchPlaceholder?: string;
|
|
33
|
+
enableColumnVisibility?: boolean;
|
|
34
|
+
enablePagination?: boolean;
|
|
35
|
+
pageSize?: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function DataTable<TData, TValue>({
|
|
39
|
+
columns,
|
|
40
|
+
data,
|
|
41
|
+
searchKey,
|
|
42
|
+
searchPlaceholder = "フィルター...",
|
|
43
|
+
enableColumnVisibility = true,
|
|
44
|
+
enablePagination = true,
|
|
45
|
+
pageSize = 10,
|
|
46
|
+
}: DataTableProps<TData, TValue>) {
|
|
47
|
+
const [sorting, setSorting] = useState<SortingState>([]);
|
|
48
|
+
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
|
|
49
|
+
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
|
50
|
+
const [rowSelection, setRowSelection] = useState({});
|
|
51
|
+
|
|
52
|
+
const table = useReactTable({
|
|
53
|
+
data,
|
|
54
|
+
columns,
|
|
55
|
+
onSortingChange: setSorting,
|
|
56
|
+
onColumnFiltersChange: setColumnFilters,
|
|
57
|
+
getCoreRowModel: getCoreRowModel(),
|
|
58
|
+
getPaginationRowModel: enablePagination ? getPaginationRowModel() : undefined,
|
|
59
|
+
getSortedRowModel: getSortedRowModel(),
|
|
60
|
+
getFilteredRowModel: getFilteredRowModel(),
|
|
61
|
+
onColumnVisibilityChange: setColumnVisibility,
|
|
62
|
+
onRowSelectionChange: setRowSelection,
|
|
63
|
+
state: {
|
|
64
|
+
sorting,
|
|
65
|
+
columnFilters,
|
|
66
|
+
columnVisibility,
|
|
67
|
+
rowSelection,
|
|
68
|
+
},
|
|
69
|
+
initialState: {
|
|
70
|
+
pagination: enablePagination
|
|
71
|
+
? {
|
|
72
|
+
pageSize: pageSize,
|
|
73
|
+
}
|
|
74
|
+
: undefined,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<div className="w-full">
|
|
80
|
+
{/* ツールバー */}
|
|
81
|
+
<div className="flex items-center py-4">
|
|
82
|
+
{searchKey && (
|
|
83
|
+
<Input
|
|
84
|
+
placeholder={searchPlaceholder}
|
|
85
|
+
value={(table.getColumn(searchKey)?.getFilterValue() as string) ?? ""}
|
|
86
|
+
onChange={(event) => table.getColumn(searchKey)?.setFilterValue(event.target.value)}
|
|
87
|
+
className="max-w-sm"
|
|
88
|
+
/>
|
|
89
|
+
)}
|
|
90
|
+
{enableColumnVisibility && (
|
|
91
|
+
<DropdownMenu>
|
|
92
|
+
<DropdownMenuTrigger asChild>
|
|
93
|
+
<Button variant="outline" className="ml-auto">
|
|
94
|
+
列 <ChevronDown className="ml-2 h-4 w-4" />
|
|
95
|
+
</Button>
|
|
96
|
+
</DropdownMenuTrigger>
|
|
97
|
+
<DropdownMenuContent align="end">
|
|
98
|
+
{table
|
|
99
|
+
.getAllColumns()
|
|
100
|
+
.filter((column) => column.getCanHide())
|
|
101
|
+
.map((column) => {
|
|
102
|
+
return (
|
|
103
|
+
<DropdownMenuCheckboxItem
|
|
104
|
+
key={column.id}
|
|
105
|
+
className="capitalize"
|
|
106
|
+
checked={column.getIsVisible()}
|
|
107
|
+
onCheckedChange={(value) => column.toggleVisibility(!!value)}
|
|
108
|
+
>
|
|
109
|
+
{column.id}
|
|
110
|
+
</DropdownMenuCheckboxItem>
|
|
111
|
+
);
|
|
112
|
+
})}
|
|
113
|
+
</DropdownMenuContent>
|
|
114
|
+
</DropdownMenu>
|
|
115
|
+
)}
|
|
116
|
+
</div>
|
|
117
|
+
|
|
118
|
+
{/* テーブル */}
|
|
119
|
+
<div className="rounded-md border">
|
|
120
|
+
<Table>
|
|
121
|
+
<TableHeader>
|
|
122
|
+
{table.getHeaderGroups().map((headerGroup) => (
|
|
123
|
+
<TableRow key={headerGroup.id}>
|
|
124
|
+
{headerGroup.headers.map((header) => {
|
|
125
|
+
return (
|
|
126
|
+
<TableHead key={header.id}>
|
|
127
|
+
{header.isPlaceholder
|
|
128
|
+
? null
|
|
129
|
+
: flexRender(header.column.columnDef.header, header.getContext())}
|
|
130
|
+
</TableHead>
|
|
131
|
+
);
|
|
132
|
+
})}
|
|
133
|
+
</TableRow>
|
|
134
|
+
))}
|
|
135
|
+
</TableHeader>
|
|
136
|
+
<TableBody>
|
|
137
|
+
{table.getRowModel().rows?.length ? (
|
|
138
|
+
table.getRowModel().rows.map((row) => (
|
|
139
|
+
<TableRow key={row.id} data-state={row.getIsSelected() && "selected"}>
|
|
140
|
+
{row.getVisibleCells().map((cell) => (
|
|
141
|
+
<TableCell key={cell.id}>
|
|
142
|
+
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
143
|
+
</TableCell>
|
|
144
|
+
))}
|
|
145
|
+
</TableRow>
|
|
146
|
+
))
|
|
147
|
+
) : (
|
|
148
|
+
<TableRow>
|
|
149
|
+
<TableCell colSpan={columns.length} className="h-24 text-center">
|
|
150
|
+
データがありません。
|
|
151
|
+
</TableCell>
|
|
152
|
+
</TableRow>
|
|
153
|
+
)}
|
|
154
|
+
</TableBody>
|
|
155
|
+
</Table>
|
|
156
|
+
</div>
|
|
157
|
+
|
|
158
|
+
{/* ページネーション */}
|
|
159
|
+
{enablePagination && (
|
|
160
|
+
<div className="flex items-center justify-end space-x-2 py-4">
|
|
161
|
+
<div className="flex-1 text-sm text-muted-foreground">
|
|
162
|
+
{table.getFilteredSelectedRowModel().rows.length} of{" "}
|
|
163
|
+
{table.getFilteredRowModel().rows.length} 行が選択されています。
|
|
164
|
+
</div>
|
|
165
|
+
<div className="space-x-2">
|
|
166
|
+
<Button
|
|
167
|
+
variant="outline"
|
|
168
|
+
size="sm"
|
|
169
|
+
onClick={() => table.previousPage()}
|
|
170
|
+
disabled={!table.getCanPreviousPage()}
|
|
171
|
+
>
|
|
172
|
+
<ChevronLeft className="h-4 w-4" />
|
|
173
|
+
前へ
|
|
174
|
+
</Button>
|
|
175
|
+
<Button
|
|
176
|
+
variant="outline"
|
|
177
|
+
size="sm"
|
|
178
|
+
onClick={() => table.nextPage()}
|
|
179
|
+
disabled={!table.getCanNextPage()}
|
|
180
|
+
>
|
|
181
|
+
次へ
|
|
182
|
+
<ChevronRight className="h-4 w-4" />
|
|
183
|
+
</Button>
|
|
184
|
+
</div>
|
|
185
|
+
</div>
|
|
186
|
+
)}
|
|
187
|
+
</div>
|
|
188
|
+
);
|
|
189
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { createContext, useCallback, useContext, useState } from "react";
|
|
4
|
+
import type React from "react";
|
|
5
|
+
import { Button } from "./button";
|
|
6
|
+
import {
|
|
7
|
+
Dialog,
|
|
8
|
+
DialogContent,
|
|
9
|
+
DialogDescription,
|
|
10
|
+
DialogFooter,
|
|
11
|
+
DialogHeader,
|
|
12
|
+
DialogTitle,
|
|
13
|
+
} from "./dialog";
|
|
14
|
+
|
|
15
|
+
interface DialogOptions {
|
|
16
|
+
title?: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
confirmText?: string;
|
|
19
|
+
cancelText?: string;
|
|
20
|
+
variant?: "default" | "destructive";
|
|
21
|
+
showCloseButton?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface DialogState {
|
|
25
|
+
isOpen: boolean;
|
|
26
|
+
title?: string;
|
|
27
|
+
description?: string;
|
|
28
|
+
confirmText?: string;
|
|
29
|
+
cancelText?: string;
|
|
30
|
+
variant?: "default" | "destructive";
|
|
31
|
+
showCloseButton?: boolean;
|
|
32
|
+
onConfirm?: () => void | Promise<void>;
|
|
33
|
+
onCancel?: () => void;
|
|
34
|
+
content?: React.ReactNode;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface DialogContextType {
|
|
38
|
+
openDialog: (
|
|
39
|
+
options: DialogOptions & {
|
|
40
|
+
onConfirm?: () => void | Promise<void>;
|
|
41
|
+
onCancel?: () => void;
|
|
42
|
+
}
|
|
43
|
+
) => void;
|
|
44
|
+
openCustomDialog: (content: React.ReactNode, options?: DialogOptions) => void;
|
|
45
|
+
closeDialog: () => void;
|
|
46
|
+
confirm: (
|
|
47
|
+
options: Omit<DialogOptions, "cancelText" | "confirmText"> & {
|
|
48
|
+
message: string;
|
|
49
|
+
confirmText?: string;
|
|
50
|
+
cancelText?: string;
|
|
51
|
+
}
|
|
52
|
+
) => Promise<boolean>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const DialogContext = createContext<DialogContextType | undefined>(undefined);
|
|
56
|
+
|
|
57
|
+
export function DialogProvider({ children }: { children: React.ReactNode }) {
|
|
58
|
+
const [dialogState, setDialogState] = useState<DialogState>({
|
|
59
|
+
isOpen: false,
|
|
60
|
+
showCloseButton: true,
|
|
61
|
+
});
|
|
62
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
63
|
+
|
|
64
|
+
const openDialog = useCallback(
|
|
65
|
+
(
|
|
66
|
+
options: DialogOptions & {
|
|
67
|
+
onConfirm?: () => void | Promise<void>;
|
|
68
|
+
onCancel?: () => void;
|
|
69
|
+
}
|
|
70
|
+
) => {
|
|
71
|
+
setDialogState({
|
|
72
|
+
isOpen: true,
|
|
73
|
+
title: options.title,
|
|
74
|
+
description: options.description,
|
|
75
|
+
confirmText: options.confirmText || "OK",
|
|
76
|
+
cancelText: options.cancelText || "キャンセル",
|
|
77
|
+
variant: options.variant || "default",
|
|
78
|
+
showCloseButton: options.showCloseButton ?? true,
|
|
79
|
+
onConfirm: options.onConfirm,
|
|
80
|
+
onCancel: options.onCancel,
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
[]
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const openCustomDialog = useCallback((content: React.ReactNode, options?: DialogOptions) => {
|
|
87
|
+
setDialogState({
|
|
88
|
+
isOpen: true,
|
|
89
|
+
content,
|
|
90
|
+
showCloseButton: options?.showCloseButton ?? true,
|
|
91
|
+
variant: options?.variant || "default",
|
|
92
|
+
});
|
|
93
|
+
}, []);
|
|
94
|
+
|
|
95
|
+
const closeDialog = useCallback(() => {
|
|
96
|
+
setDialogState((prev) => ({ ...prev, isOpen: false }));
|
|
97
|
+
setIsLoading(false);
|
|
98
|
+
}, []);
|
|
99
|
+
|
|
100
|
+
const confirm = useCallback(
|
|
101
|
+
(
|
|
102
|
+
options: Omit<DialogOptions, "cancelText" | "confirmText"> & {
|
|
103
|
+
message: string;
|
|
104
|
+
confirmText?: string;
|
|
105
|
+
cancelText?: string;
|
|
106
|
+
}
|
|
107
|
+
) => {
|
|
108
|
+
return new Promise<boolean>((resolve) => {
|
|
109
|
+
setDialogState({
|
|
110
|
+
isOpen: true,
|
|
111
|
+
title: options.title || "確認",
|
|
112
|
+
description: options.message,
|
|
113
|
+
confirmText: options.confirmText || "OK",
|
|
114
|
+
cancelText: options.cancelText || "キャンセル",
|
|
115
|
+
variant: options.variant || "default",
|
|
116
|
+
showCloseButton: options.showCloseButton ?? true,
|
|
117
|
+
onConfirm: () => {
|
|
118
|
+
resolve(true);
|
|
119
|
+
closeDialog();
|
|
120
|
+
},
|
|
121
|
+
onCancel: () => {
|
|
122
|
+
resolve(false);
|
|
123
|
+
closeDialog();
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
},
|
|
128
|
+
[closeDialog]
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
const handleConfirm = async () => {
|
|
132
|
+
if (dialogState.onConfirm) {
|
|
133
|
+
setIsLoading(true);
|
|
134
|
+
try {
|
|
135
|
+
await dialogState.onConfirm();
|
|
136
|
+
closeDialog();
|
|
137
|
+
} catch (error) {
|
|
138
|
+
console.error("Dialog confirm error:", error);
|
|
139
|
+
setIsLoading(false);
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
closeDialog();
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const handleCancel = () => {
|
|
147
|
+
if (dialogState.onCancel) {
|
|
148
|
+
dialogState.onCancel();
|
|
149
|
+
}
|
|
150
|
+
closeDialog();
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const contextValue: DialogContextType = {
|
|
154
|
+
openDialog,
|
|
155
|
+
openCustomDialog,
|
|
156
|
+
closeDialog,
|
|
157
|
+
confirm,
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
return (
|
|
161
|
+
<DialogContext.Provider value={contextValue}>
|
|
162
|
+
{children}
|
|
163
|
+
<Dialog open={dialogState.isOpen} onOpenChange={(open: boolean) => !open && closeDialog()}>
|
|
164
|
+
<DialogContent showCloseButton={dialogState.showCloseButton}>
|
|
165
|
+
{dialogState.content ? (
|
|
166
|
+
dialogState.content
|
|
167
|
+
) : (
|
|
168
|
+
<>
|
|
169
|
+
{dialogState.title && (
|
|
170
|
+
<DialogHeader>
|
|
171
|
+
<DialogTitle>{dialogState.title}</DialogTitle>
|
|
172
|
+
{dialogState.description && (
|
|
173
|
+
<DialogDescription>{dialogState.description}</DialogDescription>
|
|
174
|
+
)}
|
|
175
|
+
</DialogHeader>
|
|
176
|
+
)}
|
|
177
|
+
|
|
178
|
+
{(dialogState.onConfirm || dialogState.onCancel) && (
|
|
179
|
+
<DialogFooter>
|
|
180
|
+
{dialogState.onCancel && (
|
|
181
|
+
<Button variant="outline" onClick={handleCancel} disabled={isLoading}>
|
|
182
|
+
{dialogState.cancelText}
|
|
183
|
+
</Button>
|
|
184
|
+
)}
|
|
185
|
+
{dialogState.onConfirm && (
|
|
186
|
+
<Button
|
|
187
|
+
variant={dialogState.variant === "destructive" ? "destructive" : "default"}
|
|
188
|
+
onClick={handleConfirm}
|
|
189
|
+
disabled={isLoading}
|
|
190
|
+
>
|
|
191
|
+
{isLoading ? "処理中..." : dialogState.confirmText}
|
|
192
|
+
</Button>
|
|
193
|
+
)}
|
|
194
|
+
</DialogFooter>
|
|
195
|
+
)}
|
|
196
|
+
</>
|
|
197
|
+
)}
|
|
198
|
+
</DialogContent>
|
|
199
|
+
</Dialog>
|
|
200
|
+
</DialogContext.Provider>
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export function useDialog() {
|
|
205
|
+
const context = useContext(DialogContext);
|
|
206
|
+
if (context === undefined) {
|
|
207
|
+
throw new Error("useDialog must be used within a DialogProvider");
|
|
208
|
+
}
|
|
209
|
+
return context;
|
|
210
|
+
}
|