From ad3bd4eb63346fd7fce27b9d4f7968df70c24b81 Mon Sep 17 00:00:00 2001 From: Inomdzhon Mirdzhamolov Date: Tue, 29 Oct 2024 02:33:19 +0300 Subject: [PATCH] refactor: update ModalRoot/ModalPage/ModalCard --- packages/vkui/package.json | 2 +- .../components/Backdrop/Backdrop.module.css | 55 ++ .../vkui/src/components/Backdrop/Backdrop.tsx | 45 + .../vkui/src/components/Group/Group.test.tsx | 12 +- .../src/components/Group/GroupContainer.tsx | 4 +- .../ModalCard/ModalCard.e2e-playground.tsx | 14 +- .../components/ModalCard/ModalCard.module.css | 105 ++- .../ModalCard/ModalCard.stories.tsx | 72 +- .../components/ModalCard/ModalCard.test.tsx | 71 +- .../src/components/ModalCard/ModalCard.tsx | 116 +-- .../ModalCard/ModalCardInternal.tsx | 203 +++++ ...rd-mobile-android-chromium-dark-1-snap.png | 4 +- ...odalcard-mobile-ios-webkit-dark-1-snap.png | 4 +- .../ModalCardBase/ModalCardBase.module.css | 1 - .../ModalCardBase/ModalCardBase.tsx | 9 +- .../ModalOutlet/ModalOutlet.module.css | 16 + .../components/ModalOutlet/ModalOutlet.tsx | 31 + .../components/ModalPage/ModalPage.module.css | 247 +++--- .../ModalPage/ModalPage.stories.tsx | 479 ++++++++--- .../components/ModalPage/ModalPage.test.tsx | 58 +- .../src/components/ModalPage/ModalPage.tsx | 202 +---- .../components/ModalPage/ModalPageContext.tsx | 8 - .../ModalPage/ModalPageInternal.tsx | 214 +++++ .../src/components/ModalPage/checklist.md | 25 + .../vkui/src/components/ModalPage/types.ts | 104 +++ .../ModalPageContent.module.css | 4 + .../ModalPageContent/ModalPageContent.tsx | 25 + .../ModalPageFooter.module.css | 14 + .../ModalPageFooter/ModalPageFooter.tsx | 25 + .../ModalPageHeader.e2e-playground.tsx | 13 +- .../ModalPageHeader.module.css | 10 +- .../ModalPageHeader.stories.tsx | 3 +- .../ModalPageHeader/ModalPageHeader.tsx | 10 +- .../components/ModalRoot/ModalRoot.module.css | 59 -- .../ModalRoot/ModalRoot.stories.tsx | 67 +- .../components/ModalRoot/ModalRoot.test.tsx | 688 ++++------------ .../src/components/ModalRoot/ModalRoot.tsx | 769 ++---------------- .../ModalRoot/ModalRootAdaptive.test.tsx | 41 - .../ModalRoot/ModalRootAdaptive.tsx | 21 - .../components/ModalRoot/ModalRootContext.tsx | 63 +- .../components/ModalRoot/ModalRootDesktop.tsx | 243 ------ .../vkui/src/components/ModalRoot/Readme.md | 91 +-- .../src/components/ModalRoot/constants.ts | 1 - .../vkui/src/components/ModalRoot/types.ts | 71 +- .../ModalRoot/useModalManager.test.tsx | 302 ------- .../components/ModalRoot/useModalManager.tsx | 298 ++----- .../ModalRoot/useModalRootContext.tsx | 3 +- .../ModalRoot/withModalRootContext.tsx | 2 +- .../components/PanelHeader/PanelHeader.tsx | 4 +- .../SplitLayout/SplitLayout.stories.tsx | 2 +- packages/vkui/src/context/ModalContext.tsx | 18 + packages/vkui/src/hooks/useKeyboard.ts | 56 -- .../vkui/src/hooks/useVirtualKeyboardState.ts | 170 ++++ packages/vkui/src/index.ts | 4 +- packages/vkui/src/lib/dom.tsx | 49 ++ packages/vkui/src/storybook/ModalWrapper.tsx | 4 +- packages/vkui/src/styles/constants.css | 3 + styleguide/config.js | 2 +- 58 files changed, 2193 insertions(+), 3043 deletions(-) create mode 100644 packages/vkui/src/components/Backdrop/Backdrop.module.css create mode 100644 packages/vkui/src/components/Backdrop/Backdrop.tsx create mode 100644 packages/vkui/src/components/ModalCard/ModalCardInternal.tsx create mode 100644 packages/vkui/src/components/ModalOutlet/ModalOutlet.module.css create mode 100644 packages/vkui/src/components/ModalOutlet/ModalOutlet.tsx delete mode 100644 packages/vkui/src/components/ModalPage/ModalPageContext.tsx create mode 100644 packages/vkui/src/components/ModalPage/ModalPageInternal.tsx create mode 100644 packages/vkui/src/components/ModalPage/checklist.md create mode 100644 packages/vkui/src/components/ModalPage/types.ts create mode 100644 packages/vkui/src/components/ModalPageContent/ModalPageContent.module.css create mode 100644 packages/vkui/src/components/ModalPageContent/ModalPageContent.tsx create mode 100644 packages/vkui/src/components/ModalPageFooter/ModalPageFooter.module.css create mode 100644 packages/vkui/src/components/ModalPageFooter/ModalPageFooter.tsx delete mode 100644 packages/vkui/src/components/ModalRoot/ModalRoot.module.css delete mode 100644 packages/vkui/src/components/ModalRoot/ModalRootAdaptive.test.tsx delete mode 100644 packages/vkui/src/components/ModalRoot/ModalRootAdaptive.tsx delete mode 100644 packages/vkui/src/components/ModalRoot/ModalRootDesktop.tsx delete mode 100644 packages/vkui/src/components/ModalRoot/constants.ts delete mode 100644 packages/vkui/src/components/ModalRoot/useModalManager.test.tsx create mode 100644 packages/vkui/src/context/ModalContext.tsx delete mode 100644 packages/vkui/src/hooks/useKeyboard.ts create mode 100644 packages/vkui/src/hooks/useVirtualKeyboardState.ts diff --git a/packages/vkui/package.json b/packages/vkui/package.json index 739ff70f3b..3fbd99bf52 100644 --- a/packages/vkui/package.json +++ b/packages/vkui/package.json @@ -66,7 +66,7 @@ "test:e2e-update": "../../scripts/generate_env_docker.sh -u && docker compose --env-file=./.env.docker up --abort-on-container-exit", "test:e2e:ci": "yarn run -T playwright test --config playwright-ct.config.ts", "test:e2e-update:ci": "yarn run test:e2e:ci --update-snapshots", - "lint:generated-files": "yarn run -T tsc scripts/generateCSSCustomMedias.mjs --checkJs --module ESNext --moduleResolution node --resolveJsonModule --allowSyntheticDefaultImports --noEmit && yarn run generate:css-custom-medias && git diff --exit-code src/styles/customMedias.generated.css", + "lint:generated-files": "yarn run -T tsc scripts/generateCSSCustomMedias.mjs --checkJs --module ESNext --moduleResolution node --resolveJsonModule --allowSyntheticDefaultImports --jsx react-jsx --noEmit && yarn run generate:css-custom-medias && git diff --exit-code src/styles/customMedias.generated.css", "storybook": "bash -c 'source .env && yarn run -T cross-env SANDBOX=\\.storybook storybook dev -p ${STORYBOOK_DEV_PORT:=6006}'", "storybook:build": "yarn run -T cross-env SANDBOX=\\.storybook FROM_STORYBOOK=1 storybook build", "generate:css-custom-medias": "node scripts/generateCSSCustomMedias.mjs" diff --git a/packages/vkui/src/components/Backdrop/Backdrop.module.css b/packages/vkui/src/components/Backdrop/Backdrop.module.css new file mode 100644 index 0000000000..285106588f --- /dev/null +++ b/packages/vkui/src/components/Backdrop/Backdrop.module.css @@ -0,0 +1,55 @@ +.host { + position: absolute; + inset: 0; + background-color: rgba(0, 0, 0, 0.4); + user-select: none; + -webkit-tap-highlight-color: transparent; + transition: opacity 0.5s ease; + will-change: opacity; +} + +.hostStateEnter { + opacity: 0; + transition-property: none; +} + +.hostStateEntering { + opacity: var(--vkui_internal--backdrop--opacity); + transition-timing-function: ease-in; +} + +.hostStateEntered { + opacity: var(--vkui_internal--backdrop--opacity); +} + +.hostStateExit { + opacity: var(--vkui_internal--backdrop--opacity); + transition-property: none; +} + +.hostStateExiting { + opacity: 0; + transition-timing-function: ease-out; +} + +.hostStateExited { + opacity: 0; + transition-property: none; +} +/* Mobile */ +@media (--viewWidth-smallTabletMinus) { + .hostStateEntering, + .hostStateExiting { + transition-duration: var(--vkui--animation_duration_l); + } +} +/* Desktop */ +@media (--viewWidth-smallTabletPlus) { + .hostStateEntering { + transition-duration: 0.2s; + } + + .hostStateExiting { + transition-duration: 0.1s; + } +} diff --git a/packages/vkui/src/components/Backdrop/Backdrop.tsx b/packages/vkui/src/components/Backdrop/Backdrop.tsx new file mode 100644 index 0000000000..c6b4d6de96 --- /dev/null +++ b/packages/vkui/src/components/Backdrop/Backdrop.tsx @@ -0,0 +1,45 @@ +'use client'; + +import { classNames } from '@vkontakte/vkjs'; +import { useExternRef } from '../../hooks/useExternRef'; +import { useCSSTransition, type UseCSSTransitionState } from '../../lib/animation/useCSSTransition'; +import type { HasRootRef } from '../../types'; +import styles from './Backdrop.module.css'; + +const transitionStateClassNames: Partial> = { + appear: styles['hostStateEnter'], + appearing: styles['hostStateEntering'], + appeared: styles['hostStateEntered'], + enter: styles['hostStateEnter'], + entering: styles['hostStateEntering'], + entered: styles['hostStateEntered'], + exit: styles['hostStateExit'], + exiting: styles['hostStateExiting'], + exited: styles['hostStateExited'], +}; + +export interface BackdropProps extends HasRootRef { + visible?: boolean; + onClick?: (event: React.MouseEvent) => void; +} + +/** + * @private + */ +export const Backdrop = ({ visible, getRootRef, onClick, ...restProps }: BackdropProps) => { + const [transitionState, { ref, onTransitionEnd }] = useCSSTransition(visible, { + enableAppear: true, + }); + const handleRef = useExternRef(getRootRef, ref); + + return ( +