From d34adacb8a0f85dd1f6d0b85681b8f89761f57c1 Mon Sep 17 00:00:00 2001 From: Daria Dmitrienko Date: Thu, 10 Oct 2024 19:19:32 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=B5=D0=BD=D0=B5=D1=81=D0=BB?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=B0=20=D0=B4=D1=80=D1=83=D0=B3=D1=83=D1=8E=20?= =?UTF-8?q?=D0=B2=D0=B5=D1=82=D0=BA=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/arrow-button/ArrowButton.tsx | 8 +- .../article-params-form/ArticleParamsForm.tsx | 127 +++++++++++++++++- .../select/hooks/useOutsideClickClose.ts | 4 +- src/components/separator/index.module.scss | 2 +- src/components/spacer/Spacer.stories.tsx | 16 +++ src/components/spacer/Spacer.tsx | 5 + src/components/spacer/index.module.scss | 4 + src/components/spacer/index.tsx | 1 + src/index.tsx | 23 ++-- 9 files changed, 171 insertions(+), 19 deletions(-) create mode 100644 src/components/spacer/Spacer.stories.tsx create mode 100644 src/components/spacer/Spacer.tsx create mode 100644 src/components/spacer/index.module.scss create mode 100644 src/components/spacer/index.tsx diff --git a/src/components/arrow-button/ArrowButton.tsx b/src/components/arrow-button/ArrowButton.tsx index 5e2e0f7..1cc0946 100644 --- a/src/components/arrow-button/ArrowButton.tsx +++ b/src/components/arrow-button/ArrowButton.tsx @@ -5,10 +5,14 @@ import styles from './ArrowButton.module.scss'; /** Функция для обработки открытия/закрытия формы */ export type OnClick = () => void; -export const ArrowButton = () => { +export interface ArrowButtonProps { + onClick?: OnClick +} + +export const ArrowButton = ({ onClick }: ArrowButtonProps) => { return ( /* Не забываем указаывать role и aria-label атрибуты для интерактивных элементов */ -
void; +} + +export const ArticleParamsForm = ({ onChange }: propsArticleParamsForm) => { + const [sidebarIsOpen, setIsSidebarOpen] = useState(false); + const [selectedFont, setSelectedFont] = useState(defaultArticleState.fontFamilyOption); + const [selectedFontSize, setSelectedFontSize] = useState(defaultArticleState.fontSizeOption); + const [selectedFontColor, setSelectedFontColor] = useState(defaultArticleState.fontColor); + const [selectedBackgroundColor, setSelectedBackgroundColor] = useState(defaultArticleState.backgroundColor); + const [selectedWidthContent, setSelectedWidthContent] = useState(defaultArticleState.contentWidth); + + const rootRef = useRef(null); + let lastStyles = useRef(defaultArticleState); + + useOutsideClickClose({ + isOpen: sidebarIsOpen, + rootRef: rootRef, + onClose: () => { + setSelectedFont(lastStyles.current.fontFamilyOption) + setSelectedFontSize(lastStyles.current.fontSizeOption) + setSelectedFontColor(lastStyles.current.fontColor) + setSelectedBackgroundColor(lastStyles.current.backgroundColor) + setSelectedWidthContent(lastStyles.current.contentWidth) + }, + onChange: setIsSidebarOpen, + }); + + const toggleSidebar = () => { + // Вызов функции для изменения состояния + setIsSidebarOpen(!sidebarIsOpen); + } + + const submitHandler = (event: React.FormEvent) => { + event.preventDefault(); + + lastStyles.current = { + fontFamilyOption: selectedFont, + fontColor: selectedFontColor, + backgroundColor: selectedBackgroundColor, + contentWidth: selectedWidthContent, + fontSizeOption: selectedFontSize, + }; + + if (onChange) { + onChange(lastStyles.current) + } + } + + const resetHandler = (event: React.FormEvent) => { + event.preventDefault(); + setSelectedFontColor(defaultArticleState.fontColor) + setSelectedFont(defaultArticleState.fontFamilyOption) + setSelectedFontSize(defaultArticleState.fontSizeOption) + setSelectedBackgroundColor(defaultArticleState.backgroundColor) + setSelectedWidthContent(defaultArticleState.contentWidth) + if (onChange) { + onChange(defaultArticleState) + } + } -export const ArticleParamsForm = () => { return ( - <> - -