Skip to content

Commit 5badabf

Browse files
feat: rebrand props combination pattern (#45)
1 parent 441cec8 commit 5badabf

File tree

5 files changed

+226
-167
lines changed

5 files changed

+226
-167
lines changed

src/course/02-lessons/01-Bronze/PropsCombination/exercise/exercise.stories.tsx

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ type Story = StoryObj<typeof Exercise>;
1616
*/
1717
export const Default: Story = {
1818
args: {
19-
title: 'The Coldest Sunset Festival',
20-
subText:
21-
'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatibus quia, nulla! Maiores et perferendis eaque, exercitationem praesentium nihil.',
22-
ctaText: '#festival',
23-
ctaUrl: '/',
24-
imageAltText: 'DJ playing at a festival',
25-
imageUrlMobile:
26-
'https://images.unsplash.com/photo-1493676304819-0d7a8d026dcf?w=767&h=640&fit=crop',
27-
imageUrlTablet:
28-
'https://images.unsplash.com/photo-1493676304819-0d7a8d026dcf?w=1024&h=640&fit=crop',
29-
imageUrlDesktop:
30-
'https://images.unsplash.com/photo-1493676304819-0d7a8d026dcf?w=1600&h=900&fit=crop',
31-
containerClassName: 'containerClassName',
32-
titleClassName: 'titleClassName',
33-
subTextClassName: 'subTextClassName',
34-
ctaClassName: 'ctaClassName',
35-
imageClassName: 'imageClassName'
19+
pokemonName: 'Charizard',
20+
pokemonType: 'Fire/Flying',
21+
pokemonHp: 180,
22+
pokemonLevel: 55,
23+
attackName: 'Fire Blast',
24+
attackDamage: 120,
25+
attackDescription: 'A powerful fire attack that may leave the target with a burn.',
26+
imageAltText: 'Charizard breathing fire',
27+
imageUrlSmall: 'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/6.png',
28+
imageUrlMedium: 'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/6.png',
29+
imageUrlLarge: 'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/6.png',
30+
cardClassName: 'shadow-xl',
31+
nameClassName: 'text-red-600',
32+
typeClassName: 'bg-red-500',
33+
hpClassName: 'text-red-700',
34+
attackClassName: 'border-red-400',
35+
imageClassName: 'hover:scale-105 transition-transform'
3636
}
3737
};

src/course/02-lessons/01-Bronze/PropsCombination/exercise/exercise.tsx

Lines changed: 86 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,104 +2,129 @@ import classnames from 'classnames';
22

33
/*
44
5-
1a👨🏻💻 group the following together:
5+
1a👨🏻💻 group the following together:
66
7-
* image - imageAltText, imageUrlMobile, imageUrlTablet, imageUrlDesktop
8-
* cta - ctaText, ctaUrl
9-
* classNames - containerClassName, titleClassName, subTextClassName, ctaClassName, imageClassName
7+
* pokemon - pokemonName, pokemonType, pokemonHp, pokemonLevel
8+
* attack - attackName, attackDamage, attackDescription
9+
* image - imageAltText, imageUrlSmall, imageUrlMedium, imageUrlLarge
10+
* styling - cardClassName, nameClassName, typeClassName, hpClassName, attackClassName, imageClassName
1011
1112
*/
12-
interface IExerciseProps {
13-
title: string;
14-
subText: string;
15-
ctaText: string;
16-
ctaUrl: string;
13+
interface IPokemonCardProps {
14+
pokemonName: string;
15+
pokemonType: string;
16+
pokemonHp: number;
17+
pokemonLevel: number;
18+
attackName: string;
19+
attackDamage: number;
20+
attackDescription: string;
1721
imageAltText: string;
18-
imageUrlMobile: string;
19-
imageUrlTablet: string;
20-
imageUrlDesktop: string;
21-
containerClassName?: string;
22-
titleClassName?: string;
23-
subTextClassName?: string;
24-
ctaClassName?: string;
22+
imageUrlSmall: string;
23+
imageUrlMedium: string;
24+
imageUrlLarge: string;
25+
cardClassName?: string;
26+
nameClassName?: string;
27+
typeClassName?: string;
28+
hpClassName?: string;
29+
attackClassName?: string;
2530
imageClassName?: string;
2631
}
2732

2833
/*
29-
1b👨🏻💻 Update the props to match the new types defined above.
34+
1b👨🏻💻 Update the props to match the new grouped types defined above.
3035
*/
3136
export const Exercise = ({
32-
title,
33-
subText,
34-
ctaText,
35-
ctaUrl,
37+
pokemonName,
38+
pokemonType,
39+
pokemonHp,
40+
pokemonLevel,
41+
attackName,
42+
attackDamage,
43+
attackDescription,
3644
imageAltText,
37-
imageUrlMobile,
38-
imageUrlTablet,
39-
imageUrlDesktop,
40-
containerClassName,
41-
titleClassName,
42-
subTextClassName,
43-
ctaClassName,
45+
imageUrlSmall,
46+
imageUrlMedium,
47+
imageUrlLarge,
48+
cardClassName,
49+
nameClassName,
50+
typeClassName,
51+
hpClassName,
52+
attackClassName,
4453
imageClassName
45-
}: IExerciseProps) => {
54+
}: IPokemonCardProps) => {
4655
/*
47-
2a 🤔 Could we destructure the image to be [mobile, tablet, desktop]?
56+
2a 🤔 Could we destructure the image to be [small, medium, large]?
4857
*/
4958
/*
50-
1c👨🏻💻 Update the props in the jsx
59+
1c👨🏻💻 Update the props in the jsx to use the grouped structure
5160
*/
5261
return (
5362
<article
5463
className={classnames(
55-
'max-w-sm rounded overflow-hidden shadow-lg',
56-
containerClassName
64+
'max-w-sm rounded-lg overflow-hidden shadow-lg bg-gradient-to-b from-yellow-100 to-yellow-200 border-2 border-yellow-400',
65+
cardClassName
5766
)}
5867
>
59-
<picture>
60-
{/* ✍🏻 picture elements are a great way to display responsive images */}
61-
{/* ✍🏻 Using rem instead of pixels will change the image when you zoom in the page */}
62-
{/* ✍🏻 Link: https://web.dev/learn/design/picture-element */}
63-
<source srcSet={imageUrlDesktop} media="(min-width: 62rem)" />
64-
<source srcSet={imageUrlTablet} media="(min-width: 40rem)" />
65-
<source srcSet={imageUrlMobile} media="(min-width: 32rem)" />
68+
<div className="bg-blue-600 text-white p-2 text-center">
69+
<span className="text-xs font-bold">
70+
⭐ Level {pokemonLevel}
71+
</span>
72+
</div>
73+
74+
<picture className="block p-4">
75+
<source srcSet={imageUrlLarge} media="(min-width: 62rem)" />
76+
<source srcSet={imageUrlMedium} media="(min-width: 40rem)" />
77+
<source srcSet={imageUrlSmall} media="(min-width: 32rem)" />
6678
<img
67-
src={imageUrlDesktop}
79+
src={imageUrlLarge}
6880
alt={imageAltText}
6981
className={classnames(
70-
'w-full object-cover h-full',
82+
'w-full h-48 object-contain rounded-lg',
7183
imageClassName
7284
)}
7385
/>
7486
</picture>
87+
7588
<div className="px-6 py-4">
7689
<h3
7790
className={classnames(
78-
'font-bold text-xl mb-2',
79-
titleClassName
91+
'font-bold text-2xl mb-2 text-center',
92+
nameClassName
8093
)}
8194
>
82-
{title}
95+
{pokemonName}
8396
</h3>
84-
<p
85-
className={classnames(
86-
'text-gray-700 text-base',
87-
subTextClassName
88-
)}
89-
>
90-
{subText}
91-
</p>
92-
</div>
93-
<div className="px-6 pt-4 pb-2">
94-
<a
95-
href={ctaUrl}
97+
98+
<div className="flex justify-between items-center mb-4">
99+
<span
100+
className={classnames(
101+
'inline-block bg-blue-500 text-white rounded-full px-3 py-1 text-sm font-semibold',
102+
typeClassName
103+
)}
104+
>
105+
{pokemonType} Type
106+
</span>
107+
<span
108+
className={classnames(
109+
'text-red-600 font-bold text-lg',
110+
hpClassName
111+
)}
112+
>
113+
❤️ {pokemonHp} HP
114+
</span>
115+
</div>
116+
117+
<div
96118
className={classnames(
97-
'inline-block bg-gray-200 hover:bg-gray-300 transition-colors rounded-full px-3 py-1 text-sm font-semibold text-gray-700 mr-2 mb-2',
98-
ctaClassName
119+
'bg-gray-100 rounded-lg p-3 border-l-4 border-orange-400',
120+
attackClassName
99121
)}
100122
>
101-
{ctaText}
102-
</a>
123+
<h4 className="font-bold text-orange-600 mb-1">
124+
{attackName} - {attackDamage} damage
125+
</h4>
126+
<p className="text-gray-700 text-sm">{attackDescription}</p>
127+
</div>
103128
</div>
104129
</article>
105130
);

src/course/02-lessons/01-Bronze/PropsCombination/final/final.stories.tsx

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,32 @@ type Story = StoryObj<typeof Final>;
1616
*/
1717
export const Default: Story = {
1818
args: {
19-
title: 'The Coldest Sunset Festival',
20-
subText:
21-
'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptatibus quia, nulla! Maiores et perferendis eaque, exercitationem praesentium nihil.',
22-
cta: {
23-
text: '#festival',
24-
url: '/'
19+
pokemon: {
20+
name: 'Pikachu',
21+
type: 'Electric',
22+
hp: 120,
23+
level: 25
24+
},
25+
attack: {
26+
name: 'Thunderbolt',
27+
damage: 90,
28+
description: 'A strong electric blast that may paralyze the target.'
2529
},
2630
image: {
27-
alt: 'DJ playing at a festival',
28-
images: [
29-
'https://images.unsplash.com/photo-1493676304819-0d7a8d026dcf?w=767&h=640&fit=crop',
30-
'https://images.unsplash.com/photo-1493676304819-0d7a8d026dcf?w=1024&h=640&fit=crop',
31-
'https://images.unsplash.com/photo-1493676304819-0d7a8d026dcf?w=1600&h=900&fit=crop'
31+
alt: 'Pikachu with electric sparks',
32+
sources: [
33+
'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/25.png',
34+
'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/25.png',
35+
'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/official-artwork/25.png'
3236
]
3337
},
34-
classNames: {
35-
container: 'container',
36-
title: 'title',
37-
subText: 'subText',
38-
cta: 'cta',
39-
image: 'image'
38+
styling: {
39+
card: 'shadow-xl border-yellow-400',
40+
name: 'text-yellow-600',
41+
type: 'bg-yellow-500',
42+
hp: 'text-yellow-700',
43+
attack: 'border-yellow-400',
44+
image: 'hover:scale-105 transition-transform'
4045
}
4146
}
4247
};

0 commit comments

Comments
 (0)