Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | import type { Meta, StoryObj } from '@storybook/react';
import AuthenticatedLayout from './AuthenticatedLayout';
import { Card, CardContent, CardHeader, CardTitle } from '../ui/Card';
import { Button } from '../ui/Button';
import { Alert, AlertDescription } from '../ui/Alert';
// Mock the usePage hook and route function for Storybook
const mockPageProps = {
auth: {
user: {
id: 1,
name: 'John Doe',
email: 'john@example.com',
},
},
};
// Mock the route function
(global as any).route = (name?: string) => {
const routes = {
'dashboard': '/dashboard',
'analytics': '/analytics',
'profile.edit': '/profile/edit',
'logout': '/logout',
};
if (!name) {
return {
current: () => 'dashboard' // Default current route
};
}
return routes[name as keyof typeof routes] || '#';
};
// Mock usePage hook
const mockUsePage = () => ({
props: mockPageProps,
});
// Apply the mock
jest.mock('@inertiajs/react', () => ({
usePage: () => mockUsePage(),
Link: ({ href, children, className, ...props }: any) => (
<a href={href} className={className} {...props}>
{children}
</a>
),
}));
const meta = {
title: 'Layout/AuthenticatedLayout',
component: AuthenticatedLayout,
parameters: {
layout: 'fullscreen',
mockData: [
{
url: '/api/user',
method: 'GET',
status: 200,
response: mockPageProps.auth.user,
},
],
},
tags: ['autodocs'],
argTypes: {
title: {
control: 'text',
},
},
decorators: [
(Story) => {
// Mock the inertia hooks for each story
const originalUsePage = require('@inertiajs/react').usePage;
require('@inertiajs/react').usePage = mockUsePage;
return (
<div>
<Story />
</div>
);
},
],
} satisfies Meta<typeof AuthenticatedLayout>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Default: Story = {
args: {
children: (
<div className="space-y-6">
<h1 className="text-2xl font-bold text-gray-900">Dashboard</h1>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
<Card>
<CardHeader>
<CardTitle>Total Users</CardTitle>
</CardHeader>
<CardContent>
<div className="text-3xl font-bold">1,234</div>
<p className="text-sm text-gray-600">+12% from last month</p>
</CardContent>
</Card>
<Card>
<CardHeader>
<CardTitle>Revenue</CardTitle>
</CardHeader>
<CardContent>
<div className="text-3xl font-bold">$12,345</div>
<p className="text-sm text-gray-600">+8% from last month</p>
</CardContent>
</Card>
<Card>
<CardHeader>
<CardTitle>Active Sessions</CardTitle>
</CardHeader>
<CardContent>
<div className="text-3xl font-bold">456</div>
<p className="text-sm text-gray-600">+3% from last month</p>
</CardContent>
</Card>
</div>
</div>
),
},
};
export const WithTitle: Story = {
args: {
title: 'Dashboard Overview',
children: (
<div className="space-y-6">
<Alert>
<AlertDescription>
Welcome to your dashboard! Here you can view your account overview and recent activity.
</AlertDescription>
</Alert>
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
<Card>
<CardHeader>
<CardTitle>Recent Activity</CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-2">
<div className="flex justify-between">
<span className="text-sm">User John logged in</span>
<span className="text-xs text-gray-500">2 min ago</span>
</div>
<div className="flex justify-between">
<span className="text-sm">New user registered</span>
<span className="text-xs text-gray-500">5 min ago</span>
</div>
<div className="flex justify-between">
<span className="text-sm">Payment processed</span>
<span className="text-xs text-gray-500">10 min ago</span>
</div>
</div>
</CardContent>
</Card>
<Card>
<CardHeader>
<CardTitle>Quick Actions</CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-2">
<Button className="w-full" variant="outline">
Add New User
</Button>
<Button className="w-full" variant="outline">
Generate Report
</Button>
<Button className="w-full" variant="outline">
View Settings
</Button>
</div>
</CardContent>
</Card>
</div>
</div>
),
},
};
export const WithHeader: Story = {
args: {
title: 'Analytics',
header: (
<div className="flex items-center justify-between">
<h1 className="text-xl font-semibold text-gray-900">Analytics Dashboard</h1>
<div className="flex space-x-2">
<Button variant="outline" size="sm">
Export Data
</Button>
<Button size="sm">
Refresh
</Button>
</div>
</div>
),
children: (
<div className="space-y-6">
<div className="grid grid-cols-1 md:grid-cols-4 gap-4">
<Card>
<CardHeader className="pb-2">
<CardTitle className="text-sm font-medium">Page Views</CardTitle>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">24,567</div>
<p className="text-xs text-gray-600">+14% from last week</p>
</CardContent>
</Card>
<Card>
<CardHeader className="pb-2">
<CardTitle className="text-sm font-medium">Unique Visitors</CardTitle>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">8,432</div>
<p className="text-xs text-gray-600">+7% from last week</p>
</CardContent>
</Card>
<Card>
<CardHeader className="pb-2">
<CardTitle className="text-sm font-medium">Bounce Rate</CardTitle>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">34.2%</div>
<p className="text-xs text-gray-600">-2% from last week</p>
</CardContent>
</Card>
<Card>
<CardHeader className="pb-2">
<CardTitle className="text-sm font-medium">Conversion Rate</CardTitle>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">3.8%</div>
<p className="text-xs text-gray-600">+0.5% from last week</p>
</CardContent>
</Card>
</div>
<Card>
<CardHeader>
<CardTitle>Traffic Overview</CardTitle>
</CardHeader>
<CardContent>
<div className="h-64 bg-gray-100 rounded-lg flex items-center justify-center">
<p className="text-gray-500">Chart placeholder</p>
</div>
</CardContent>
</Card>
</div>
),
},
};
export const ProfilePage: Story = {
args: {
title: 'Profile Settings',
header: (
<div>
<h1 className="text-xl font-semibold text-gray-900">Profile Settings</h1>
<p className="text-sm text-gray-600">Manage your account settings and preferences</p>
</div>
),
children: (
<div className="space-y-6">
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
<div className="lg:col-span-2">
<Card>
<CardHeader>
<CardTitle>Personal Information</CardTitle>
</CardHeader>
<CardContent className="space-y-4">
<div>
<label className="block text-sm font-medium text-gray-700">Full Name</label>
<input
type="text"
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm"
defaultValue="John Doe"
/>
</div>
<div>
<label className="block text-sm font-medium text-gray-700">Email</label>
<input
type="email"
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm"
defaultValue="john@example.com"
/>
</div>
<div>
<label className="block text-sm font-medium text-gray-700">Phone</label>
<input
type="tel"
className="mt-1 block w-full rounded-md border-gray-300 shadow-sm"
defaultValue="+1 (555) 123-4567"
/>
</div>
<div className="flex justify-end space-x-2">
<Button variant="outline">Cancel</Button>
<Button>Save Changes</Button>
</div>
</CardContent>
</Card>
</div>
<div>
<Card>
<CardHeader>
<CardTitle>Account Stats</CardTitle>
</CardHeader>
<CardContent className="space-y-4">
<div>
<p className="text-sm text-gray-600">Member since</p>
<p className="font-medium">January 2024</p>
</div>
<div>
<p className="text-sm text-gray-600">Last login</p>
<p className="font-medium">Today at 2:30 PM</p>
</div>
<div>
<p className="text-sm text-gray-600">Account type</p>
<p className="font-medium">Premium</p>
</div>
</CardContent>
</Card>
</div>
</div>
</div>
),
},
};
export const EmptyState: Story = {
args: {
title: 'Dashboard',
children: (
<div className="text-center py-12">
<div className="mx-auto w-24 h-24 bg-gray-100 rounded-full flex items-center justify-center">
<svg className="w-12 h-12 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5H7a2 2 0 00-2 2v10a2 2 0 002 2h8a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2" />
</svg>
</div>
<h3 className="mt-4 text-lg font-medium text-gray-900">No data available</h3>
<p className="mt-2 text-sm text-gray-500">
Get started by creating your first project or importing existing data.
</p>
<div className="mt-6 flex justify-center space-x-2">
<Button>Create Project</Button>
<Button variant="outline">Import Data</Button>
</div>
</div>
),
},
};
export const LoadingState: Story = {
args: {
title: 'Loading...',
children: (
<div className="space-y-6">
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
{[...Array(3)].map((_, i) => (
<Card key={i}>
<CardContent className="p-6">
<div className="animate-pulse">
<div className="h-4 bg-gray-200 rounded w-3/4 mb-2"></div>
<div className="h-8 bg-gray-200 rounded w-1/2 mb-2"></div>
<div className="h-3 bg-gray-200 rounded w-full"></div>
</div>
</CardContent>
</Card>
))}
</div>
<Card>
<CardContent className="p-6">
<div className="animate-pulse">
<div className="h-6 bg-gray-200 rounded w-1/4 mb-4"></div>
<div className="h-32 bg-gray-200 rounded"></div>
</div>
</CardContent>
</Card>
</div>
),
},
}; |