-
Notifications
You must be signed in to change notification settings - Fork 0
Review #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SirDraiger
wants to merge
8
commits into
main
Choose a base branch
from
review
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Review #1
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
247f8a2
form open/close
SirDraiger 0cf0343
form content
SirDraiger 10804ae
add form state for elements && form submit/reset
SirDraiger 2431452
updating data between form and article
SirDraiger 35e30b4
isOpen props transmission restored
SirDraiger 2cbd148
applying standard styles to an article when resetting the form
SirDraiger 5af8ec4
fix double click bug
SirDraiger d209ca2
revision of styles
SirDraiger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,19 +1,30 @@ | ||
| import arrow from 'src/images/arrow.svg'; | ||
|
|
||
| import styles from './ArrowButton.module.scss'; | ||
| import clsx from 'clsx'; | ||
|
|
||
| /** Функция для обработки открытия/закрытия формы */ | ||
| export type OnClick = () => void; | ||
|
|
||
| export const ArrowButton = () => { | ||
| export type ArrowButtonProps = { | ||
| isOpen?: boolean; | ||
| onClick?: OnClick; | ||
| }; | ||
|
|
||
| export const ArrowButton = ({ isOpen, onClick }: ArrowButtonProps) => { | ||
| return ( | ||
| /* Не забываем указаывать role и aria-label атрибуты для интерактивных элементов */ | ||
| <div | ||
| role='button' | ||
| aria-label='Открыть/Закрыть форму параметров статьи' | ||
| tabIndex={0} | ||
| className={styles.container}> | ||
| <img src={arrow} alt='иконка стрелочки' className={styles.arrow} /> | ||
| className={clsx(styles.container, { [styles.container_open]: isOpen })} | ||
| onClick={onClick}> | ||
| <img | ||
| src={arrow} | ||
| alt='иконка стрелочки' | ||
| className={clsx(styles.arrow, { [styles.arrow_open]: isOpen })} | ||
| /> | ||
| </div> | ||
| ); | ||
| }; | ||
This file contains hidden or 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
176 changes: 166 additions & 10 deletions
176
src/components/article-params-form/ArticleParamsForm.tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -1,20 +1,176 @@ | ||
| import { ArrowButton } from 'components/arrow-button'; | ||
| import { Button } from 'components/button'; | ||
| import { Text } from 'components/text'; | ||
| import { Select } from 'components/select'; | ||
| import { RadioGroup } from 'components/radio-group'; | ||
| import { Separator } from 'components/separator'; | ||
|
|
||
| import styles from './ArticleParamsForm.module.scss'; | ||
| import { SyntheticEvent, useEffect, useRef, useState } from 'react'; | ||
| import clsx from 'clsx'; | ||
| import { | ||
| ArticleStateType, | ||
| fontFamilyOptions, | ||
| fontSizeOptions, | ||
| fontColors, | ||
| contentWidthArr, | ||
| } from '../../constants/articleProps'; | ||
|
|
||
| export type ArticleParamsFormProps = { | ||
| defaultArticleParams: ArticleStateType; | ||
| articleParams: ArticleStateType; | ||
| setCurrentArticleState: (params: ArticleStateType) => void; | ||
| }; | ||
|
|
||
| export const ArticleParamsForm = ({ | ||
| defaultArticleParams, | ||
| articleParams, | ||
| setCurrentArticleState, | ||
| }: ArticleParamsFormProps) => { | ||
| // Храним статус открытия формы | ||
| const [open, setOpen] = useState(false); | ||
|
|
||
| // Закрытие формы при клике вне её области и нажатию на Esc | ||
| const refForm = useRef<HTMLDivElement | null>(null); | ||
|
|
||
| // Открытие формы | ||
| function handlerOpenForm() { | ||
| setOpen(!open); | ||
| } | ||
|
|
||
| useEffect(() => { | ||
| if (!open) return; | ||
|
|
||
| function handleClick(event: MouseEvent) { | ||
| if ( | ||
| open && | ||
| refForm.current && | ||
| !refForm.current.contains(event.target as HTMLElement) | ||
| ) { | ||
| setOpen(!open); | ||
| } | ||
| } | ||
|
|
||
| function handlePressEsc(event: KeyboardEvent) { | ||
| if (event.key === 'Escape') { | ||
| setOpen(!open); | ||
| } | ||
| } | ||
|
|
||
| document.addEventListener('mousedown', handleClick); | ||
| document.addEventListener('keydown', handlePressEsc); | ||
|
|
||
| return () => { | ||
| document.removeEventListener('mousedown', handleClick); | ||
| document.removeEventListener('keydown', handlePressEsc); | ||
| }; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Отлично! Хорошая реализация форм, круто, что вы очищаете обработчик |
||
| }, [open]); | ||
|
|
||
| // Стейты элементов формы | ||
| const [currentFontFamily, setCurrentFontFamily] = useState( | ||
| articleParams.fontFamilyOption | ||
| ); | ||
| const [currentFontSize, setCurrentFontSize] = useState( | ||
| articleParams.fontSizeOption | ||
| ); | ||
| const [currentFontColor, setCurrentFontColor] = useState( | ||
| articleParams.fontColor | ||
| ); | ||
| const [currentBackgroundColor, setCurrentBackgroundColor] = useState( | ||
| articleParams.backgroundColor | ||
| ); | ||
| const [currentContentWidth, setCurrentContentWidth] = useState( | ||
| articleParams.contentWidth | ||
| ); | ||
|
|
||
| // Отправка формы | ||
| function handlerSubmitForm(event: SyntheticEvent) { | ||
| event.preventDefault(); | ||
|
|
||
| // Изменённые данные формы для передачи в стейт | ||
| const formData: ArticleStateType = { | ||
| fontFamilyOption: currentFontFamily, | ||
| fontColor: currentFontColor, | ||
| backgroundColor: currentBackgroundColor, | ||
| contentWidth: currentContentWidth, | ||
| fontSizeOption: currentFontSize, | ||
| }; | ||
|
|
||
| // Отправка данных в стейт | ||
| setCurrentArticleState(formData); | ||
| } | ||
|
|
||
| // Сброс данных формы и статьи на дефолтные | ||
| function handlerResetForm() { | ||
| setCurrentFontFamily(defaultArticleParams.fontFamilyOption); | ||
| setCurrentFontSize(defaultArticleParams.fontSizeOption); | ||
| setCurrentFontColor(defaultArticleParams.fontColor); | ||
| setCurrentBackgroundColor(defaultArticleParams.backgroundColor); | ||
| setCurrentContentWidth(defaultArticleParams.contentWidth); | ||
| setCurrentArticleState(defaultArticleParams); | ||
| } | ||
|
|
||
| export const ArticleParamsForm = () => { | ||
| return ( | ||
| <> | ||
| <ArrowButton /> | ||
| <aside className={styles.container}> | ||
| <form className={styles.form}> | ||
| <div className={styles.bottomContainer}> | ||
| <Button title='Сбросить' type='reset' /> | ||
| <Button title='Применить' type='submit' /> | ||
| </div> | ||
| </form> | ||
| </aside> | ||
| {/* Доп. див для правки бага двойного клика https://app.pachca.com/chats?thread_id=3492502 */} | ||
| <div ref={refForm}> | ||
| <ArrowButton onClick={handlerOpenForm} isOpen={open} /> | ||
| <aside | ||
| className={clsx(styles.container, { [styles.container_open]: open })}> | ||
| <form className={styles.form} onSubmit={handlerSubmitForm}> | ||
| <Text as={'h2'} weight={800} size={31} uppercase> | ||
| Задайте параметры | ||
| </Text> | ||
|
|
||
| <Select | ||
| title={'шрифт'} | ||
| options={fontFamilyOptions} | ||
| selected={currentFontFamily} | ||
| onChange={setCurrentFontFamily} | ||
| /> | ||
|
|
||
| <RadioGroup | ||
| title={'размер шрифта'} | ||
| options={fontSizeOptions} | ||
| selected={currentFontSize} | ||
| name={'fonst-size'} | ||
| onChange={setCurrentFontSize} | ||
| /> | ||
|
|
||
| <Select | ||
| title={'цвет шрифта'} | ||
| options={fontColors} | ||
| selected={currentFontColor} | ||
| onChange={setCurrentFontColor} | ||
| /> | ||
|
|
||
| <Separator /> | ||
|
|
||
| <Select | ||
| title={'цвет фона'} | ||
| options={fontColors} | ||
| selected={currentBackgroundColor} | ||
| onChange={setCurrentBackgroundColor} | ||
| /> | ||
|
|
||
| <Select | ||
| title={'цвет контекта'} | ||
| options={contentWidthArr} | ||
| selected={currentContentWidth} | ||
| onChange={setCurrentContentWidth} | ||
| /> | ||
|
|
||
| <div className={styles.bottomContainer}> | ||
| <Button | ||
| title='Сбросить' | ||
| type='reset' | ||
| onClick={handlerResetForm} | ||
| /> | ||
| <Button title='Применить' type='submit' /> | ||
| </div> | ||
| </form> | ||
| </aside> | ||
| </div> | ||
| </> | ||
| ); | ||
| }; | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| .separator { | ||
| width: 100%; | ||
| height: 1px; | ||
| background: #000000; | ||
| background: #d7d7d7; | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import { createRoot } from 'react-dom/client'; | ||
| import { StrictMode, CSSProperties } from 'react'; | ||
| import { StrictMode, CSSProperties, useState } from 'react'; | ||
| import clsx from 'clsx'; | ||
|
|
||
| import { Article } from './components/article/Article'; | ||
|
|
@@ -13,19 +13,27 @@ const domNode = document.getElementById('root') as HTMLDivElement; | |
| const root = createRoot(domNode); | ||
|
|
||
| const App = () => { | ||
| // Текущие параметры статьи. По умолчанию заполняем дефолтными значениями | ||
| const [currentArticleState, setCurrentArticleState] = | ||
| useState(defaultArticleState); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Можно лучше: компонент |
||
|
|
||
| return ( | ||
| <div | ||
| className={clsx(styles.main)} | ||
| style={ | ||
| { | ||
| '--font-family': defaultArticleState.fontFamilyOption.value, | ||
| '--font-size': defaultArticleState.fontSizeOption.value, | ||
| '--font-color': defaultArticleState.fontColor.value, | ||
| '--container-width': defaultArticleState.contentWidth.value, | ||
| '--bg-color': defaultArticleState.backgroundColor.value, | ||
| '--font-family': currentArticleState.fontFamilyOption.value, | ||
| '--font-size': currentArticleState.fontSizeOption.value, | ||
| '--font-color': currentArticleState.fontColor.value, | ||
| '--container-width': currentArticleState.contentWidth.value, | ||
| '--bg-color': currentArticleState.backgroundColor.value, | ||
| } as CSSProperties | ||
| }> | ||
| <ArticleParamsForm /> | ||
| <ArticleParamsForm | ||
| defaultArticleParams={defaultArticleState} | ||
| articleParams={currentArticleState} | ||
| setCurrentArticleState={setCurrentArticleState} | ||
| /> | ||
| <Article /> | ||
| </div> | ||
| ); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Отлично! Круто, что вы используете
clsx