-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #344 from Studio-Yandex-Practicum/enhancement_338_…
…sidebar_menu_modal Enhancement 338 sidebar menu modal
- Loading branch information
Showing
18 changed files
with
488 additions
and
20 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import SideBarButton from './ui/SideBarButton' | ||
export default SideBarButton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
@use '@/shared/styles/utils/variables' as var; | ||
|
||
.sideBarButton { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
gap: 10px; | ||
width: fit-content; | ||
background: var.$white; | ||
font-size: 14px; | ||
color: var.$body-color; | ||
fill: var.$body-color; | ||
padding: 5px 15px; | ||
transition: 0.25s; | ||
} | ||
|
||
.sideBarButton:hover { | ||
color: var.$header-color; | ||
fill: var.$header-color; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
|
||
import SideBarButton from './SideBarButton' | ||
|
||
const meta = { | ||
title: 'entities/SideBarButton', | ||
component: SideBarButton, | ||
parameters: { | ||
layout: 'centered' | ||
}, | ||
tags: ['autodocs'] | ||
} satisfies Meta<typeof SideBarButton> | ||
|
||
export default meta | ||
type Story = StoryObj<typeof meta> | ||
|
||
export const Default: Story = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { FC } from 'react' | ||
|
||
import CategoryIcon from '@/assets/images/sideBarMenu/iconCategory.svg' | ||
import { Button, ButtonDesign, ButtonSize } from '@/shared/ui/Button/Button' | ||
|
||
import styles from './SideBarButton.module.scss' | ||
|
||
interface ISideBarButton { | ||
onClick: () => void | ||
} | ||
|
||
/** | ||
* Компонент кнопки "Меню" - для адаптива Side Bar Menu | ||
* @param {function} onClick - функция клика для открытия модального окна SideBarMenuModal | ||
*/ | ||
|
||
const SideBarButton: FC<ISideBarButton> = ({ onClick }) => { | ||
return ( | ||
<Button | ||
design={ButtonDesign.SQUARE} | ||
size={ButtonSize.S} | ||
type="button" | ||
onClick={onClick} | ||
className={styles.sideBarButton}> | ||
<span>Меню</span> | ||
<CategoryIcon /> | ||
</Button> | ||
) | ||
} | ||
|
||
export default SideBarButton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/features/SideBarMenuModal/SideBarLink/SideBarLink.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
@use '@/shared/styles/utils/variables' as var; | ||
|
||
.sideBarLink { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
gap: 10px; | ||
background: var.$body-bg; | ||
min-height: 45px; | ||
border-radius: 5px; | ||
font-size: 15px; | ||
color: var.$body-color; | ||
fill: var.$body-color; | ||
padding: 10px 15px; | ||
cursor: pointer; | ||
transition: 0.25s; | ||
|
||
&__arrow { | ||
transform: rotate(270deg); | ||
} | ||
} | ||
|
||
.sideBarLink:hover { | ||
color: var.$header-color; | ||
fill: var.$header-color; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { KeyboardEventHandler, FC } from 'react' | ||
|
||
import ArrowIcon from '@/assets/images/sideBarMenu/IconArrowDown.svg' | ||
|
||
import styles from './SideBarLink.module.scss' | ||
|
||
export interface ISideBarLink { | ||
isVisible?: boolean | ||
onKeyUp?: KeyboardEventHandler<HTMLDivElement> | ||
onClick?: () => void | ||
title?: string | ||
} | ||
|
||
/** | ||
* Компонент модального окна SideBarMenuModal, отвечающий за развертывание названий обьектов массива | ||
* @param {boolean} isVisible - булево значение скрывающее стрелку; | ||
* @param {function} onKeyUp - функция обнуляющая пользователя по нажатии клавиши Enter; | ||
* @param {function} onClick - функция клика по роуту; | ||
* @param {string} title - название роута; | ||
*/ | ||
|
||
const SideBarLink: FC<ISideBarLink> = ({ isVisible, onKeyUp, onClick, title }) => { | ||
return ( | ||
<div tabIndex={0} role="button" onKeyUp={onKeyUp} className={styles.sideBarLink} onClick={onClick}> | ||
{title} | ||
{isVisible && <ArrowIcon className={styles.sideBarLink__arrow} />} | ||
</div> | ||
) | ||
} | ||
|
||
export default SideBarLink |
47 changes: 47 additions & 0 deletions
47
src/features/SideBarMenuModal/SideBarSublinks/SideBarSublinks.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
@use '@/shared/styles/utils/variables' as var; | ||
|
||
.sideBarSublinks { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
background: var.$white; | ||
width: 100%; | ||
border-radius: 5px; | ||
|
||
&__header { | ||
display: flex; | ||
align-items: center; | ||
gap: 10px; | ||
width: 100%; | ||
margin-bottom: 18px; | ||
cursor: pointer; | ||
} | ||
|
||
&__headerArrow { | ||
transform: rotate(90deg); | ||
} | ||
|
||
&__routes { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 5px; | ||
width: 100%; | ||
} | ||
|
||
&__route { | ||
display: flex; | ||
align-items: center; | ||
background: var.$body-bg; | ||
min-height: 45px; | ||
border-radius: 5px; | ||
font-size: 15px; | ||
color: var.$body-color; | ||
padding: 10px 10px 10px 15px; | ||
cursor: pointer; | ||
transition: 0.25s; | ||
} | ||
|
||
&__route:hover { | ||
color: var.$header-color; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/features/SideBarMenuModal/SideBarSublinks/SideBarSublinks.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { KeyboardEvent, FC } from 'react' | ||
import { useNavigate } from 'react-router-dom' | ||
|
||
import ArrowIcon from '@/assets/images/sideBarMenu/IconArrowDown.svg' | ||
import Heading, { HeadingType } from '@/shared/ui/Heading/Heading' | ||
import Link from '@/shared/ui/Link/Link' | ||
|
||
import { IData } from '../model/types/types' | ||
|
||
import styles from './SideBarSublinks.module.scss' | ||
|
||
export interface ISideBarSublinks { | ||
isActive?: boolean | ||
choice?: number | ||
index?: number | ||
item?: IData | ||
title?: string | ||
} | ||
|
||
/** | ||
* Компонент модального окна SideBarMenuModal, отвечающий за развертывание роутов и их названий | ||
* @param {boolean} isActive - булево значение; | ||
* @param {number} choice - изменяемое состояние индекса; | ||
* @param {number} index - индекс выбранной кнопки; | ||
* @param {object} item - обьект массива; | ||
* @param {string} title - заголовок обьекта массива; | ||
*/ | ||
|
||
const SideBarSublinks: FC<ISideBarSublinks> = ({ isActive, choice, index, item, title }) => { | ||
const navigate = useNavigate() | ||
|
||
const handleKeyDown = (e: KeyboardEvent<HTMLAnchorElement>, index: string) => { | ||
if (e.code === 'Enter' || e.code === 'Space') { | ||
e.preventDefault() | ||
navigate(index) | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
{choice === index && ( | ||
<div className={styles.sideBarSublinks}> | ||
<div tabIndex={0} role="button" className={styles.sideBarSublinks__header}> | ||
<ArrowIcon className={styles.sideBarSublinks__headerArrow} /> | ||
<Heading type={HeadingType.SMALL}>{title}</Heading> | ||
</div> | ||
<ul role="list" className={styles.sideBarSublinks__routes}> | ||
{isActive && | ||
choice === index && | ||
item?.routes?.map((el: IData, i: number) => ( | ||
<li role="link" key={i}> | ||
<Link | ||
onKeyDown={e => handleKeyDown(e, el.route || '#')} | ||
to={el.route || '#'} | ||
className={styles.sideBarSublinks__route}> | ||
{el.subtitle} | ||
</Link> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
)} | ||
</> | ||
) | ||
} | ||
|
||
export default SideBarSublinks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import SideBarMenuModal from './ui/SideBarMenuModal' | ||
export default SideBarMenuModal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export interface IData { | ||
routes?: IRoute[] | ||
subtitle?: string | ||
route?: string | ||
} | ||
|
||
export interface IRoute { | ||
subtitle?: string | ||
route?: string | ||
} |
45 changes: 45 additions & 0 deletions
45
src/features/SideBarMenuModal/ui/SideBarMenuModal.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
@use '@/shared/styles/utils/variables' as var; | ||
|
||
.sideBarMenuModal { | ||
position: absolute; | ||
bottom: 0; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: flex-end; | ||
gap: 5px; | ||
width: 100%; | ||
padding: 25px; | ||
|
||
&__container { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 18px; | ||
background: var.$white; | ||
border-radius: 10px; | ||
padding: 30px; | ||
} | ||
|
||
&__list { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 5px; | ||
list-style: none; | ||
} | ||
|
||
&__button { | ||
display: flex; | ||
align-items: center; | ||
background: var.$white; | ||
border-radius: 10px; | ||
font-size: 15px; | ||
font-weight: 700; | ||
letter-spacing: 0.5px; | ||
color: var.$body-color; | ||
padding: 10px 20px; | ||
transition: 0.25s; | ||
} | ||
|
||
&__button:hover { | ||
color: var.$header-color; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/features/SideBarMenuModal/ui/SideBarMenuModal.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
import { useState } from 'react' | ||
|
||
import SideBarMenuModal from './SideBarMenuModal' | ||
|
||
const meta = { | ||
title: 'features/SideBarMenuModal', | ||
component: SideBarMenuModal, | ||
parameters: { | ||
layout: 'centered' | ||
}, | ||
tags: ['autodocs'] | ||
} satisfies Meta<typeof SideBarMenuModal> | ||
|
||
export default meta | ||
type Story = StoryObj<typeof meta> | ||
|
||
export const Default: Story = () => { | ||
const [user, setUser] = useState('Elon Musk') | ||
|
||
const handleLogOut = () => { | ||
setUser('') | ||
} | ||
|
||
return ( | ||
<div style={{ display: 'flex', justifyContent: 'center' }}> | ||
<SideBarMenuModal user={user} handleLogOut={handleLogOut} /> | ||
</div> | ||
) | ||
} | ||
|
||
Default.args = { | ||
user: 'Elon Musk' | ||
} |
Oops, something went wrong.