-
Notifications
You must be signed in to change notification settings - Fork 199
feat(PanelHeader,PanelHeaderContext): remove FixedLayout using #9765
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| 'use client'; | ||
|
|
||
| import * as React from 'react'; | ||
| import { usePlatform } from '../../hooks/usePlatform'; | ||
| import { useResizeObserver } from '../../hooks/useResizeObserver'; | ||
| import { defineComponentDisplayNames } from '../../lib/react/defineComponentDisplayNames'; | ||
| import type { HasComponent } from '../../types'; | ||
| import { SplitColContext } from '../SplitCol/SplitColContext'; | ||
|
|
||
| type SplitColWidthWrapperProps = React.HTMLAttributes<HTMLElement> & HasComponent; | ||
|
|
||
| export const SplitColWidthWrapper: React.ForwardRefExoticComponent< | ||
| React.PropsWithoutRef<SplitColWidthWrapperProps> & React.RefAttributes<HTMLElement> | ||
| // eslint-disable-next-line react/display-name -- используется defineComponentDisplayNames | ||
| > = React.forwardRef<HTMLElement, SplitColWidthWrapperProps>( | ||
| ({ Component = 'div', style, ...restProps }, forwardedRef) => { | ||
| const platform = usePlatform(); | ||
| const { colRef } = React.useContext(SplitColContext); | ||
| const [width, setWidth] = React.useState<string | undefined>(undefined); | ||
|
|
||
| const doResize = React.useCallback(() => { | ||
| if (!colRef?.current) { | ||
| setWidth(undefined); | ||
| return; | ||
| } | ||
|
|
||
| const computedStyle = getComputedStyle(colRef.current); | ||
|
|
||
| setWidth( | ||
| `${ | ||
| colRef.current.clientWidth - | ||
| parseFloat(computedStyle.paddingLeft || '0') - | ||
| parseFloat(computedStyle.paddingRight || '0') | ||
| }px`, | ||
| ); | ||
| }, [colRef]); | ||
|
|
||
| React.useEffect(doResize, [doResize, platform]); | ||
| useResizeObserver(colRef, doResize); | ||
|
|
||
| return <Component {...restProps} ref={forwardedRef} style={{ width, ...style }} />; | ||
| }, | ||
| ); | ||
|
|
||
| if (process.env.NODE_ENV !== 'production') { | ||
| defineComponentDisplayNames(SplitColWidthWrapper, 'SplitColWidthWrapper'); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| 'use client'; | ||
|
|
||
| import * as React from 'react'; | ||
| import { defineComponentDisplayNames } from '../../lib/react/defineComponentDisplayNames'; | ||
| import type { HasComponent } from '../../types'; | ||
| import { OnboardingTooltipContainer } from './OnboardingTooltipContainer'; | ||
|
|
||
| type OnboardingTooltipFixedContainerProps = React.HTMLAttributes<HTMLDivElement> & HasComponent; | ||
|
|
||
| export const OnboardingTooltipFixedContainer: React.ForwardRefExoticComponent< | ||
| React.PropsWithoutRef<OnboardingTooltipFixedContainerProps> & React.RefAttributes<HTMLDivElement> | ||
| // eslint-disable-next-line react/display-name -- используется defineComponentDisplayNames | ||
| > = React.forwardRef<HTMLDivElement, OnboardingTooltipFixedContainerProps>((props, ref) => ( | ||
| <OnboardingTooltipContainer {...props} fixed ref={ref} /> | ||
| )); | ||
|
|
||
| if (process.env.NODE_ENV !== 'production') { | ||
| defineComponentDisplayNames(OnboardingTooltipFixedContainer, 'OnboardingTooltipFixedContainer'); | ||
| } |
|
Contributor
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. Контекст теперь не влезает по ширине 2026-04-29.11.28.19.mov |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,10 +6,12 @@ import { useAdaptivity } from '../../hooks/useAdaptivity'; | |
| import { useGlobalOnClickOutside } from '../../hooks/useGlobalOnClickOutside'; | ||
| import { usePlatform } from '../../hooks/usePlatform'; | ||
| import { type SizeTypeValues, ViewWidth, type ViewWidthType } from '../../lib/adaptivity'; | ||
| import { useCSSKeyframesAnimationController } from '../../lib/animation'; | ||
| import type { HTMLAttributesWithRootRef } from '../../types'; | ||
| import { useScrollLock } from '../AppRoot/ScrollContext'; | ||
| import { FixedLayout } from '../FixedLayout/FixedLayout'; | ||
| import { Box } from '../Box/Box'; | ||
| import { SplitColWidthWrapper } from '../FixedLayout/SplitColWidthWrapper'; | ||
| import { OnboardingTooltipFixedContainer } from '../OnboardingTooltip/OnboardingTooltipFixedContainer'; | ||
| import { Popover } from '../Popover/Popover'; | ||
| import styles from './PanelHeaderContext.module.css'; | ||
|
|
||
| function getViewWidthClassName( | ||
|
|
@@ -43,6 +45,8 @@ export interface PanelHeaderContextProps extends HTMLAttributesWithRootRef<HTMLD | |
| onClose: VoidFunction; | ||
| } | ||
|
|
||
| const ComponentDecorators = [SplitColWidthWrapper, OnboardingTooltipFixedContainer]; | ||
|
|
||
| /** | ||
| * @see https://vkui.io/components/panel-header-context | ||
| */ | ||
|
|
@@ -55,15 +59,17 @@ export const PanelHeaderContext = ({ | |
| }: PanelHeaderContextProps): React.ReactNode => { | ||
| const platform = usePlatform(); | ||
| const { sizeX: legacySizeX, viewWidth = 'none' } = useAdaptivity(); | ||
| const elementRef = React.useRef<HTMLDivElement>(null); | ||
| const [animationState, animationHandlers] = useCSSKeyframesAnimationController( | ||
| opened ? 'enter' : 'exit', | ||
| undefined, | ||
| true, | ||
| ); | ||
| const visible = animationState !== 'exited'; | ||
| const [visible, setVisible] = React.useState<boolean>(opened); | ||
| const [prevOpened, setPrevOpened] = React.useState<boolean>(opened); | ||
| const anchorRef = React.useRef<HTMLElement | null>(null); | ||
| const popoverRef = React.useRef<HTMLDivElement | null>(null); | ||
|
|
||
| useScrollLock(platform !== 'vkcom' && visible); | ||
| if (prevOpened !== opened) { | ||
| if (opened) { | ||
| setVisible(true); | ||
| } | ||
| setPrevOpened(opened); | ||
| } | ||
|
|
||
| const handleGlobalOnClickOutside = React.useCallback( | ||
| (event: MouseEvent) => { | ||
|
|
@@ -75,23 +81,32 @@ export const PanelHeaderContext = ({ | |
| [opened, onClose], | ||
| ); | ||
|
|
||
| useGlobalOnClickOutside(handleGlobalOnClickOutside, visible ? elementRef : null); | ||
| useScrollLock(platform !== 'vkcom' && visible); | ||
|
|
||
| useGlobalOnClickOutside( | ||
| handleGlobalOnClickOutside, | ||
| visible ? anchorRef : null, | ||
| visible ? popoverRef : null, | ||
| ); | ||
|
|
||
| if (!visible) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <FixedLayout | ||
| {...restProps} | ||
| <Box | ||
| Component={ComponentDecorators} | ||
| className={classNames( | ||
| styles.host, | ||
| platform === 'ios' && styles.ios, | ||
| opened ? styles.opened : styles.closing, | ||
| getViewWidthClassName(viewWidth, legacySizeX), | ||
| className, | ||
| )} | ||
| vertical="top" | ||
| position="fixed" | ||
| inlineSize="100%" | ||
| insetBlockStart={0} | ||
| {...restProps} | ||
| > | ||
| <div | ||
| onClick={(event) => { | ||
|
|
@@ -100,14 +115,31 @@ export const PanelHeaderContext = ({ | |
| }} | ||
| className={styles.fade} | ||
| /> | ||
| <div | ||
| data-testid={process.env.NODE_ENV === 'test' ? 'content' : undefined} | ||
| <Popover | ||
|
Contributor
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. nit: Насколько мы можем отказаться от Popover-а?
Contributor
Author
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. вообще можно оставить старую реализации всплывашки, но в issue привязанном написано переписать на Popover |
||
| shown={opened} | ||
| disableFlipMiddleware | ||
| disableShiftMiddleware | ||
| disableCloseOnClickOutside | ||
| disableCloseOnEscKey | ||
| strategy="absolute" | ||
| trigger="manual" | ||
| role="presentation" | ||
| content={<div className={styles.content}>{children}</div>} | ||
| sameWidth | ||
| usePortal={false} | ||
| zIndex={1} | ||
| noStyling | ||
| className={styles.in} | ||
| ref={elementRef} | ||
| {...animationHandlers} | ||
| offsetByMainAxis={0} | ||
| onShownChanged={(shown) => { | ||
| if (!shown) { | ||
| setVisible(false); | ||
| } | ||
| }} | ||
| getRootRef={popoverRef} | ||
| > | ||
| <div className={styles.content}>{children}</div> | ||
| </div> | ||
| </FixedLayout> | ||
| <Box getRootRef={anchorRef} inlineSize="100%" /> | ||
| </Popover> | ||
| </Box> | ||
| ); | ||
| }; | ||
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.
Пустой комментарий