Skip to content

Commit e0df038

Browse files
committed
✨ Add AvatarWithRating to Hero block
1 parent f534eef commit e0df038

File tree

6 files changed

+71
-38
lines changed

6 files changed

+71
-38
lines changed

src/blocks/Hero/Hero.astro

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,35 @@ import {
77
type IconProps
88
} from 'webcoreui/astro'
99
10+
import AvatarWithRating from '@blocks/AvatarWithRating/AvatarWithRating.astro'
11+
1012
import type { HeroProps } from './hero'
1113
import styles from './hero.module.scss'
1214
1315
interface Props extends HeroProps {}
1416
1517
const {
18+
badge,
1619
heading,
1720
subHeading,
1821
buttons,
19-
badge,
22+
avatarWithRating,
2023
image,
2124
reverse,
2225
className
2326
} = Astro.props
2427
2528
const classes = [
2629
styles.hero,
27-
reverse && styles.reverse,
28-
image?.src && styles.flex,
30+
image?.src && 'flex column justify-between sm-row sm-items-center',
31+
reverse && 'sm-row-reverse',
2932
className
3033
]
3134
---
3235

3336
<section class:list={classes}>
3437
<ConditionalWrapper condition={!!image?.src}>
35-
<div slot="wrapper">children</div>
38+
<div slot="wrapper" class={styles.wrapper}>children</div>
3639
{badge && (
3740
<Badge {...badge} className={styles.badge}>
3841
{badge.text}
@@ -58,6 +61,13 @@ const classes = [
5861
))}
5962
</div>
6063
)}
64+
65+
{avatarWithRating && (
66+
<AvatarWithRating
67+
{...avatarWithRating}
68+
className={styles.avatar}
69+
/>
70+
)}
6171
</ConditionalWrapper>
6272
{image?.src && (
6373
<img

src/blocks/Hero/Hero.svelte

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,32 @@
66
ConditionalWrapper
77
} from 'webcoreui/svelte'
88
9+
import AvatarWithRating from '@blocks/AvatarWithRating/AvatarWithRating.svelte'
10+
911
import type { HeroProps } from './hero'
1012
import styles from './hero.module.scss'
1113
1214
const {
15+
badge,
1316
heading,
1417
subHeading,
1518
buttons,
16-
badge,
19+
avatarWithRating,
1720
image,
1821
reverse,
1922
className
2023
}: HeroProps = $props()
2124
2225
const classes = classNames([
2326
styles.hero,
24-
reverse && styles.reverse,
25-
image?.src && styles.flex,
27+
image?.src && 'flex column justify-between sm-row sm-items-center',
28+
reverse && 'sm-row-reverse',
2629
className
2730
])
2831
</script>
2932

3033
<section class={classes}>
31-
<ConditionalWrapper condition={!!image?.src}>
34+
<ConditionalWrapper condition={!!image?.src} class={styles.wrapper}>
3235
{#if badge}
3336
<Badge {...badge} className={styles.badge}>
3437
{badge.text}
@@ -51,6 +54,13 @@
5154
{/each}
5255
</div>
5356
{/if}
57+
58+
{#if avatarWithRating}
59+
<AvatarWithRating
60+
{...avatarWithRating}
61+
className={styles.avatar}
62+
/>
63+
{/if}
5464
</ConditionalWrapper>
5565
{#if image?.src}
5666
<img

src/blocks/Hero/Hero.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,34 @@ import {
66
ConditionalWrapper
77
} from 'webcoreui/react'
88

9+
import AvatarWithRating from '@blocks/AvatarWithRating/AvatarWithRating.tsx'
10+
911
import type { HeroProps } from './hero'
1012
import styles from './hero.module.scss'
1113

1214
const Hero = ({
15+
badge,
1316
heading,
1417
subHeading,
1518
buttons,
16-
badge,
19+
avatarWithRating,
1720
image,
1821
reverse,
1922
className
2023
}: HeroProps) => {
2124
const classes = classNames([
2225
styles.hero,
23-
reverse && styles.reverse,
24-
image?.src && styles.flex,
26+
image?.src && 'flex column justify-between sm-row sm-items-center',
27+
reverse && 'sm-row-reverse',
2528
className
2629
])
2730

2831
return (
2932
<section className={classes}>
30-
<ConditionalWrapper condition={!!image?.src} wrapper={children => <div>{children}</div>}>
33+
<ConditionalWrapper
34+
condition={!!image?.src}
35+
wrapper={children => <div className={styles.wrapper}>{children}</div>}
36+
>
3137
{badge && (
3238
<Badge {...badge} className={styles.badge}>
3339
{badge.text}
@@ -51,6 +57,13 @@ const Hero = ({
5157
))}
5258
</div>
5359
)}
60+
61+
{avatarWithRating && (
62+
<AvatarWithRating
63+
{...avatarWithRating}
64+
className={styles.avatar}
65+
/>
66+
)}
5467
</ConditionalWrapper>
5568
{image?.src && (
5669
<img

src/blocks/Hero/hero.module.scss

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
@use 'webcoreui/config' as *;
22

33
.hero {
4-
&.flex {
5-
@include layout(flex, h-between, column, default);
6-
7-
div, img {
8-
flex: 1;
9-
}
4+
.wrapper, img {
5+
flex: 1;
106
}
117

128
h1 {
@@ -31,23 +27,7 @@
3127
@include spacing(mb-xs);
3228
}
3329

34-
.cta {
30+
.cta, .avatar {
3531
@include spacing(mt-md);
3632
}
3733
}
38-
39-
@include media(sm) {
40-
.hero {
41-
&:not(.reverse) {
42-
@include layout(v-center);
43-
}
44-
45-
&.flex {
46-
@include layout(row);
47-
}
48-
49-
&.reverse {
50-
@include layout(row-reverse);
51-
}
52-
}
53-
}

src/blocks/Hero/hero.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@ import type {
44
IconProps
55
} from 'webcoreui/astro'
66

7+
import type { AvatarWithRatingProps } from '@blocks/AvatarWithRating/avatarWithRating'
8+
79
export type HeroProps = {
10+
badge?: {
11+
text: string
12+
} & BadgeProps | null
813
heading: string
914
subHeading?: string
1015
buttons?: ({
1116
text: string
1217
icon?: IconProps['type'] | string
1318
} & ButtonProps)[]
14-
badge?: {
15-
text: string
16-
} & BadgeProps | null
19+
avatarWithRating?: AvatarWithRatingProps
1720
image?: {
1821
src: string
1922
alt: string

src/pages/blocks/hero.astro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import Layout from '@static/Layout.astro'
66
import AstroHero from '@blocks/Hero/Hero.astro'
77
import SvelteHero from '@blocks/Hero/Hero.svelte'
88
import ReactHero from '@blocks/Hero/Hero.tsx'
9+
10+
import { avatarGroup } from '@data'
911
---
1012

1113
<Layout docs="/blocks/hero">
@@ -28,6 +30,11 @@ import ReactHero from '@blocks/Hero/Hero.tsx'
2830
theme: 'outline',
2931
text: 'New releases'
3032
}}
33+
avatarWithRating={{
34+
avatar: { img: avatarGroup },
35+
rating: { score: 5, color: 'var(--w-color-success)' },
36+
text: '<b>123 students</b> already enrolled'
37+
}}
3138
image={{
3239
src: '/img/placeholder1.png',
3340
alt: 'Banner',
@@ -50,6 +57,11 @@ import ReactHero from '@blocks/Hero/Hero.tsx'
5057
theme: 'alert',
5158
text: 'New releases'
5259
}}
60+
avatarWithRating={{
61+
avatar: { img: avatarGroup },
62+
rating: { score: 5, color: 'var(--w-color-alert)' },
63+
text: '<b>123 students</b> already enrolled'
64+
}}
5365
image={{
5466
src: '/img/placeholder2.png',
5567
alt: 'Banner',
@@ -73,6 +85,11 @@ import ReactHero from '@blocks/Hero/Hero.tsx'
7385
theme: 'info',
7486
text: 'New releases'
7587
}}
88+
avatarWithRating={{
89+
avatar: { img: avatarGroup },
90+
rating: { score: 5, color: 'var(--w-color-info)' },
91+
text: '<b>123 students</b> already enrolled'
92+
}}
7693
image={{
7794
src: '/img/placeholder3.png',
7895
alt: 'Banner',

0 commit comments

Comments
 (0)