Skip to content

Commit

Permalink
fix-BannerBlock enhancement_350_adaptive_main_page
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderMorugin committed May 25, 2024
1 parent 56a46a4 commit 5a7ee33
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 132 deletions.
Binary file added src/assets/images/banner/banner_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
119 changes: 64 additions & 55 deletions src/entities/BannerCard/BannerCard.module.scss
Original file line number Diff line number Diff line change
@@ -1,77 +1,86 @@
@use '@/app/styles/index' as color;
@use '../../shared/styles/utils/mixins' as media;
@use '@/shared/styles/utils/variables' as var;
@use '@/shared/styles/utils/mixins' as media;

.storybook {
width: 1500px;
height: 400px;
height: 400px;
}

.slider {
flex: 1 0 100%;
.bannerCard {
position: relative;
background-color: color.$theme-secondary-color;
display: flex;
width: 100%;
flex: 1 0 100%;
user-select: none;
}

.link {
color: color.$black;
.content {
position: absolute;
width: 100%;
height: 100%;
top: 30%;
left: 12%;
display: flex;
flex-direction: column;
gap: 30px;

.content {
position: absolute;
left: 12%;
top: 100px;
@include media.respond-to('large') {
top: 20%;
}

@include media.respond-to('middle') {
left: 2%;
top: 40px;
}
@include media.respond-to('small') {
left: 3%;
top: 10px;
}

.title {
margin-top: 5px;
font-size: 30px;
color: color.$black;
line-height: 37.5px;
@include media.respond-to('middle') {
left: 5%;
gap: 15px;
}

@include media.respond-to('middle') {
font-size: 15px;
line-height: 18px;
font-weight: 500;
}
@include media.respond-to('small') {
font-size: 13px;
line-height: 10px;
}
}
@include media.respond-to('small') {
top: 25%;
}
}

.button {
border: 1px solid color.$body-color-light-grey;
column-gap: 15px;
background-color: inherit;
color: color.$black;
margin-top: 30px;
.title {
display: flex;
flex-direction: column;
line-height: 37px;
font-size: 30px;
font-weight: 500;

path {
fill: color.$black;
@include media.respond-to('middle') {
line-height: 18px;
font-size: 15px;
}
}

.button {
display: flex;
justify-content: center;
align-items: center;
gap: 15px;
font-size: 16px;
color: var.$body-color;
fill: var.$body-color;
border: 1px solid rgb(52 52 52 / 10%);
border-radius: 5px;
padding: 5px 15px;
transition: 0.25s;

@include media.respond-to('middle') {
font-size: 15px;
width: 150px;
height: 30px;
margin-top: 10px;
font-size: 13px;
}
@include media.respond-to('small') {
font-size: 13px;
width: 130px;
height: 20px;
margin-top: 10px;

&:hover {
color: var.$white;
fill: var.$white;
background: var.$body-color;
}

&:active {
transform: scale(0.9);
}
}

.icon {
transform: rotate(270deg);
}

.image {
object-fit: cover;
}
3 changes: 2 additions & 1 deletion src/entities/BannerCard/BannerCard.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Meta, StoryObj } from '@storybook/react'
import { FC } from 'react'

import img1 from '@/assets/images/banner/banner.png'
import img2 from '@/assets/images/banner/banner_small.png'

import BannerCard, { TBannerCard } from './BannerCard'
import styles from './BannerCard.module.scss'
Expand Down Expand Up @@ -39,7 +40,7 @@ export const Normal: Story = {
args: {
id: 100,
urlImg: img1,
urlImg_m: img1,
urlImg_m: img2,
alt: 'Mobil',
title: 'DJI OSMO',
subtitle: 'Mobile 4',
Expand Down
35 changes: 14 additions & 21 deletions src/entities/BannerCard/BannerCard.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { FC } from 'react'

import ArrowRightNextPage from '@/assets/icons/ArrowRightNextPage.svg'
import ArrowIcon from '@/assets/images/sideBarMenu/IconArrowDown.svg'
import { media } from '@/shared/styles/utils/media'
import { Button, ButtonSize, ButtonTheme } from '@/shared/ui/Button/Button'
import Heading, { HeadingType } from '@/shared/ui/Heading/Heading'
import Link from '@/shared/ui/Link/Link'
import Img from '@/ui/img'
Expand All @@ -20,8 +19,7 @@ export type TBannerCard = {
}

/**
* Entity SliderCard
* Карточка для SliderBlock на главной странице.
* Компонент BannerCard - это карточка для BannerBlock на главной странице
* @param {string} urlImg - изображение
* @param {string} urlImg_m - изображение
* @param {string} alt - название картинки, если картинка не подгрузится
Expand All @@ -32,23 +30,18 @@ export type TBannerCard = {

const BannerCard: FC<TBannerCard> = ({ alt, title, subtitle, href, urlImg, urlImg_m }) => {
return (
<div className={styles.slider}>
<Link to={href} className={styles.link}>
<div className={styles.content}>
<Heading type={HeadingType.NORMAL} className={styles.title}>
{title}
</Heading>
<Heading type={HeadingType.NORMAL} className={styles.title}>
{subtitle}
</Heading>

<Button size={ButtonSize.S} theme={ButtonTheme.PRIMARY} className={styles.button}>
Подробнее
<ArrowRightNextPage className={styles.icon} />
</Button>
</div>
<Img srcSet={urlImg_m} media={media.middle} src={urlImg} alt={alt} />
</Link>
<div className={styles.bannerCard}>
<div className={styles.content}>
<Heading type={HeadingType.NORMAL} className={styles.title}>
<span>{title}</span>
<span>{subtitle}</span>
</Heading>
<Link to={href} className={styles.button}>
Подробнее
<ArrowIcon className={styles.icon} />
</Link>
</div>
<Img srcSet={urlImg_m} media={media.middle} src={urlImg} alt={alt} className={styles.image} />
</div>
)
}
Expand Down
14 changes: 8 additions & 6 deletions src/mockData/bannerData.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
import img1 from '@/assets/images/banner/banner.png'
import img2 from '@/assets/images/banner/banner_small.png'
import { TBannerCard } from '@/entities/BannerCard/BannerCard'
import { Routes } from '@/shared/config/routerConfig/routes'

export const bannerData: TBannerCard[] = [
{
id: 100,
urlImg: img1,
urlImg_m: img1,
urlImg_m: img2,
alt: 'Mobil',
title: 'DJI OSMO',
subtitle: 'Mobile 4',
href: 'jelektronika/telefony-i-smart-chasy/umnye-chasy'
href: Routes.ABOUT // роут приведен только для примера
},
{
id: 101,
urlImg: img1,
urlImg_m: img1,
urlImg_m: img2,
alt: 'Mobil',
title: 'DJI OSMO',
subtitle: 'Mobile 4',
href: 'jelektronika/telefony-i-smart-chasy/umnye-chasy'
href: Routes.BLOG // роут приведен только для примера
},
{
id: 102,
urlImg: img1,
urlImg_m: img1,
urlImg_m: img2,
alt: 'Mobil',
title: 'DJI OSMO',
subtitle: 'Mobile 4',
href: 'jelektronika/telefony-i-smart-chasy/umnye-chasy'
href: Routes.CART // роут приведен только для примера
}
]
2 changes: 1 addition & 1 deletion src/pages/MainPage/MainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FC } from 'react'
import WrapperForMainContent from '@/components/WrapperForMainContent/WrapperForMainContent'
import Advantages from '@/widgets/Advantages'
import ArticleBlock from '@/widgets/ArticleBlock'
import BannerBlock from '@/widgets/BannerBlock/ui/BannerBlock'
import BannerBlock from '@/widgets/BannerBlock'
import BlogBlock from '@/widgets/BlogBlock/ui/BlogBlock'
import BrandsBlock from '@/widgets/BrandBlock/ui/BrandBlock/BrandBlock'
import CategoryGrid from '@/widgets/CategoryGrid'
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/BannerBlock/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import BannerBlock from './ui/BannerBlock'
export default BannerBlock
38 changes: 15 additions & 23 deletions src/widgets/BannerBlock/ui/BannerBlock.module.scss
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
@use '@/app/styles/index' as color;
@use '../../../shared/styles/utils/mixins' as media;
@use '@/shared/styles/utils/mixins' as media;

.storybook {
width: 1500px;
height: 400px;
height: 400px;
}

.container {
display: flex;
column-gap: 20px;
width: 1440px;
max-width: 100%;
height: 370px;
margin: 0 auto;
padding: 0 10px;

@include media.respond-to('middle') {
width: 715px;
height: 187px;
padding: 0;
}
.bannerBlock {
display: flex;
gap: 20px;
width: 100%;
min-height: 370px;

@include media.respond-to('small') {
width: 335px;
height: 87px;

}
}
@include media.respond-to('large') {
min-height: 300px;
}

@include media.respond-to('middle') {
min-height: 140px;
}
}
49 changes: 24 additions & 25 deletions src/widgets/BannerBlock/ui/BannerBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
import { FC } from 'react'

import BannerCard from '@/entities/BannerCard/BannerCard'
import Slider from '@/features/Slider/ui/Slider/Slider'
import { bannerData } from '@/mockData/bannerData'

import styles from './BannerBlock.module.scss'

/**
* Component BannerBlock
* Компонент для перелистывания главных картинок на главной странице.
* Компонент BannerBlock для перелистывания главных картинок на главной странице.
*/

const BannerBlock = () => {
if (bannerData.length === 0) {
return null
}

const BannerBlock: FC = () => {
return (
<div className={styles.container}>
<Slider>
{bannerData?.map(item => {
return (
<BannerCard
key={item.id}
id={item.id}
urlImg={item.urlImg}
urlImg_m={item.urlImg_m}
alt={item.alt}
title={item.title}
subtitle={item.subtitle}
href={item.href}
/>
)
})}
</Slider>
</div>
bannerData?.length !== 0 && (
<section className={styles.bannerBlock}>
<Slider>
{bannerData?.map(item => {
return (
<BannerCard
key={item.id}
id={item.id}
urlImg={item.urlImg}
urlImg_m={item.urlImg_m}
alt={item.alt}
title={item.title}
subtitle={item.subtitle}
href={item.href}
/>
)
})}
</Slider>
</section>
)
)
}
export default BannerBlock

0 comments on commit 5a7ee33

Please sign in to comment.