-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathcard.stories.tsx
509 lines (469 loc) · 13.3 KB
/
card.stories.tsx
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
import React from "react";
import {Meta} from "@storybook/react";
import {card} from "@heroui/theme";
import {Link} from "@heroui/link";
import {Button} from "@heroui/button";
import {Code} from "@heroui/code";
import {Image} from "@heroui/image";
import {Card, CardBody, CardHeader, CardFooter, CardProps} from "../src";
export default {
title: "Components/Card",
component: Card,
argTypes: {
shadow: {
control: {
type: "select",
},
options: ["sm", "md", "lg"],
},
radius: {
control: {
type: "select",
},
options: ["none", "sm", "md", "lg"],
},
fullWidth: {
control: {
type: "boolean",
},
},
isFooterBlurred: {
control: {
type: "boolean",
},
},
isHoverable: {
control: {
type: "boolean",
},
},
isPressable: {
control: {
type: "boolean",
},
},
isDisabled: {
control: {
type: "boolean",
},
},
disableRipple: {
control: {
type: "boolean",
},
},
disableAnimation: {
control: {
type: "boolean",
},
},
},
decorators: [
(Story) => (
<div className="flex items-center justify-center w-screen h-screen">
<Story />
</div>
),
],
} as Meta<typeof Card>;
const defaultProps = {
...card.defaultVariants,
disableRipple: false,
};
const Template = (args: CardProps) => (
<Card {...args} className="max-w-md">
<CardBody>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed</p>
</CardBody>
</Card>
);
const WithDividerTemplate = (args: CardProps) => (
<Card {...args} className="max-w-md">
<CardHeader className="border-b border-divider dark:border-divider-dark">
<strong>Description</strong>
</CardHeader>
<CardBody className="py-8">
<p>The Object constructor creates an object wrapper for the given value.</p>
</CardBody>
<CardFooter className="border-t border-divider dark:border-divider-dark">
<p>
When called in a non-constructor context, Object behaves identically to{" "}
<Code color="primary">new Object()</Code>.
</p>
</CardFooter>
</Card>
);
const WithFooterTemplate = (args: CardProps) => (
<Card {...args} className="p-4 max-w-md">
<CardHeader className="flex gap-3">
<Image
alt="heroui logo"
height={34}
radius="lg"
src="https://avatars.githubusercontent.com/u/86160567?s=200&v=4"
width={34}
/>
<div className="flex flex-col">
<b className="text-lg">HeroUI</b>
<p className="text-default-500">heroui.com</p>
</div>
</CardHeader>
<CardBody className="py-2">
<p>Make beautiful websites regardless of your design experience.</p>
</CardBody>
<CardFooter>
<Link isExternal showAnchorIcon href="https://github.com/heroui-inc/heroui">
Visit source code on GitHub.
</Link>
</CardFooter>
</Card>
);
const WithAbsImageHeaderTemplate = (args: CardProps) => (
<Card {...args} className="max-w-[330px]">
<CardHeader className="absolute top-2 z-20">
<div className="flex flex-col">
<p className="text-white/60 text-xs uppercase font-bold">What to watch</p>
<p className="text-white text-2xl">Stream the Apple event</p>
</div>
</CardHeader>
<Image
alt="Card background"
className="w-full h-[440px] object-cover"
height={440}
src={"/images/assets/apple-event.jpeg"}
width={330}
/>
</Card>
);
const WithAbsImgHeaderFooterTemplate = (args: CardProps) => (
<Card className="w-[330px] bg-zinc-100 dark:bg-zinc-100" {...args}>
<CardHeader className="absolute top-2 z-10">
<div className="flex flex-col gap-2">
<p className="text-xs text-black/40 uppercase font-bold">New</p>
<h4 className="text-3xl font-medium text-black">HomePod mini</h4>
<p className="text-sm text-black/80 pr-1.5">
Room-filling sound, Intelligent assistant. Smart home control. Works seamlessly with
iPhone. Check it out
</p>
</div>
</CardHeader>
<Image
alt="Card background"
className="w-full h-[440px] pt-10 object-contain"
height={440}
src={"/images/assets/homepod.jpeg"}
width={300}
/>
<CardFooter className="justify-between absolute bottom-0 z-10">
<div>
<p className="text-xs text-black/80">Available soon.</p>
<p className="text-xs text-black/80">Get notified.</p>
</div>
<Button className="text-tiny" color="primary" radius="full" size="sm">
Notify Me
</Button>
</CardFooter>
</Card>
);
const CoverImgTemplate = (args: CardProps) => (
<div className="max-w-[900px] gap-2 grid grid-cols-12 grid-rows-2 px-8">
<Card {...args} className="col-span-12 sm:col-span-4">
<CardHeader className="absolute z-10 top-1 flex-col !items-start">
<p className="text-xs text-white/60 uppercase font-bold">What to watch</p>
<h4 className="text-white font-medium text-lg">Stream the Acme event</h4>
</CardHeader>
<img
alt="Card background"
className="w-full h-full object-cover"
src="https://heroui.com/images/card-example-4.jpeg"
/>
</Card>
<Card {...args} className="col-span-12 sm:col-span-4">
<CardHeader className="absolute z-10 top-1 flex-col !items-start">
<p className="text-xs text-white/60 uppercase font-bold">Plant a tree</p>
<h4 className="text-white font-medium text-lg">Contribute to the planet</h4>
</CardHeader>
<img
alt="Card background"
className="w-full h-full object-cover"
src="https://heroui.com/images/card-example-3.jpeg"
/>
</Card>
<Card {...args} className="col-span-12 sm:col-span-4">
<CardHeader className="absolute z-10 top-1 flex-col !items-start">
<p className="text-xs text-white/60 uppercase font-bold">Supercharged</p>
<h4 className="text-white font-medium text-lg">Creates beauty like a beast</h4>
</CardHeader>
<img
alt="Card background"
className="w-full h-full object-cover"
src="https://heroui.com/images/card-example-2.jpeg"
/>
</Card>
<Card {...args} isFooterBlurred className="w-full h-[400px] col-span-12 sm:col-span-5">
<CardHeader className="absolute z-10 top-1 flex-col items-start">
<p className="text-xs text-white/60 uppercase font-bold">New</p>
<h4 className="text-black font-medium text-2xl">Acme camera</h4>
</CardHeader>
<img
alt="Card example background"
className="w-full h-full scale-125 -translate-y-10 object-cover"
src="https://heroui.com/images/card-example-6.jpeg"
/>
<CardFooter className="absolute bg-white/30 bottom-0 border-t border-slate-300 z-10 justify-between">
<div>
<p className="text-black text-xs">Available soon.</p>
<p className="text-black text-xs">Get notified.</p>
</div>
<Button color="secondary" radius="full" size="sm" variant="flat">
Notify Me
</Button>
</CardFooter>
</Card>
<Card {...args} isFooterBlurred className="w-full h-[400px] col-span-12 sm:col-span-7">
<CardHeader className="absolute z-10 top-1 flex-col items-start">
<p className="text-xs text-white/60 uppercase font-bold">Your day your way</p>
<h4 className="text-white/90 font-medium text-2xl">Your checklist for better sleep</h4>
</CardHeader>
<img
alt="Relaxing app background"
className="w-full h-full object-cover"
src="https://heroui.com/images/card-example-5.jpeg"
/>
<CardFooter className="absolute bg-black/40 bottom-0 z-10 border-t border-default-600 dark:border-default-100">
<div className="flex flex-grow gap-2 items-center">
<img
alt="Breathing app icon"
className="rounded-full w-10 h-11 bg-black"
src={"/images/assets/breathing-app-icon.jpeg"}
/>
<div className="flex flex-col">
<p className="text-xs text-white/60">Breathing App</p>
<p className="text-xs text-white/60">Get a good night's sleep.</p>
</div>
</div>
<Button radius="full">Get App</Button>
</CardFooter>
</Card>
</div>
);
const CenterImgTemplate = (args: CardProps) => (
<Card {...args} className="max-w-fit py-4 px-0">
<CardHeader className="pb-0 pt-2 px-4 flex-col !items-start">
<p className="text-xs uppercase font-bold">Daily Mix</p>
<small className="text-default-500">12 Tracks</small>
<h4 className="font-bold text-lg">Frontend Radio</h4>
</CardHeader>
<CardBody className="overflow-visible py-2">
<Image
isBlurred
alt="Card background"
src={"/images/assets/local-image-1.jpeg"}
width={300}
/>
</CardBody>
</Card>
);
const PrimaryActionTemplate = (args: CardProps) => {
const list = [
{
title: "Orange",
img: "/images/fruit-1.jpeg",
price: "$5.50",
},
{
title: "Tangerine",
img: "/images/fruit-2.jpeg",
price: "$3.00",
},
{
title: "Raspberry",
img: "/images/fruit-3.jpeg",
price: "$10.00",
},
{
title: "Lemon",
img: "/images/fruit-4.jpeg",
price: "$5.30",
},
{
title: "Avocado",
img: "/images/fruit-5.jpeg",
price: "$15.70",
},
{
title: "Lemon 2",
img: "/images/fruit-6.jpeg",
price: "$8.00",
},
{
title: "Banana",
img: "/images/fruit-7.jpeg",
price: "$7.50",
},
{
title: "Watermelon",
img: "/images/fruit-8.jpeg",
price: "$12.20",
},
];
type ListItem = (typeof list)[number];
const handlePress = (item: ListItem) => {
// eslint-disable-next-line no-console
console.log("item pressed", item);
};
return (
<div className="gap-2 grid grid-cols-2 sm:grid-cols-4">
{list.map((item, index) => (
// eslint-disable-next-line no-console
<Card {...args} key={index} isPressable onPress={() => handlePress(item)}>
<CardBody className="p-0">
<img
alt={item.title}
className="w-full h-[140px] object-cover"
src={"https://heroui.com" + item.img}
/>
</CardBody>
<CardFooter className="justify-between">
<b>{item.title}</b>
<p className="text-default-500">{item.price}</p>
</CardFooter>
</Card>
))}
</div>
);
};
const PressableTemplate = (args: CardProps) => {
// Both events should be fired when clicking on the card
const handlePress = () => {
// eslint-disable-next-line no-console
alert("card pressed");
};
const onClick = () => {
// eslint-disable-next-line no-console
alert("card clicked");
};
return (
<Card {...args} isPressable onClick={onClick} onPress={handlePress}>
<CardBody>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</CardBody>
</Card>
);
};
const CenterImgWithHeaderTemplate = (args: CardProps) => {
const list = [
{
title: "Mac",
img: "/images/assets/mac.png",
},
{
title: "iPhone",
img: "/images/assets/iphone.png",
},
{
title: "iPad",
img: "/images/assets/ipad.png",
},
{
title: "Apple Watch",
img: "/images/assets/apple-watch.png",
},
{
title: "AirPods",
img: "/images/assets/airpods.png",
},
{
title: "AirTag",
img: "/images/assets/airtag.png",
},
{
title: "Apple TV",
img: "/images/assets/appletv.png",
},
{
title: "HomePod mini",
img: "/images/assets/homepod-mini.png",
},
{
title: "Accessories",
img: "/images/assets/accessories.png",
},
];
return (
<div className="flex gap-2 justify-center flex-wrap">
{list.map((item, index) => (
<div key={index}>
<Card {...args} isPressable className="w-[200px] h-[200px]">
<CardHeader className="p-0">
<h5 className="pl-6 pt-3">{item.title}</h5>
</CardHeader>
<CardBody className="h-full justify-center">
<img alt={item.title} className="w-[180px]" src={item.img} />
</CardBody>
</Card>
</div>
))}
</div>
);
};
export const Default = {
render: Template,
args: {
...defaultProps,
},
};
export const Pressable = {
render: PressableTemplate,
args: {
...defaultProps,
},
};
export const WithDivider = {
render: WithDividerTemplate,
args: {
...defaultProps,
},
};
export const WithFooter = {
render: WithFooterTemplate,
args: {
...defaultProps,
},
};
export const WithAbsImageHeader = {
render: WithAbsImageHeaderTemplate,
args: {
...defaultProps,
},
};
export const WithAbsImgHeaderFooter = {
render: WithAbsImgHeaderFooterTemplate,
args: {
...defaultProps,
},
};
export const CoverImg = {
render: CoverImgTemplate,
args: {
...defaultProps,
},
};
export const CenterImg = {
render: CenterImgTemplate,
args: {
...defaultProps,
},
};
export const PrimaryAction = {
render: PrimaryActionTemplate,
args: {
...defaultProps,
},
};
export const CenterImgWithHeader = {
render: CenterImgWithHeaderTemplate,
args: {
...defaultProps,
},
};