Skip to content
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

feat(PopoutWrapper): add prop strategy and deprecate prop fixed #8217

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vkui/src/components/ActionSheet/ActionSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const ActionSheet = ({
className={className}
style={style}
onClick={onCloseWithOther}
fixed
strategy="fixed"
>
{actionSheet}
</PopoutWrapper>
Expand Down
1 change: 1 addition & 0 deletions packages/vkui/src/components/Alert/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export const Alert = ({
style={style}
onClick={close}
getRootRef={getRootRef}
strategy="fixed"
>
<FocusTrap
{...animationHandlers}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
position: fixed;
}

.absolute {
position: absolute;
}

.overlay {
position: fixed;
inset-inline-start: 0;
Expand All @@ -42,7 +46,8 @@
background: var(--vkui--color_overlay_primary);
}

.fixed .overlay {
.fixed .overlay,
.absolute .overlay {
position: absolute;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ export default story;
type Story = StoryObj<PopoutWrapperProps>;

export const Playground: Story = {
render: (args) => <PopoutWrapper {...args} />,
render: (args) => (
<div style={{ width: 500, height: 500, position: 'relative' }}>
<PopoutWrapper {...args} />
</div>
),
args: {
children: 'Some content',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render } from '@testing-library/react';
import { baselineComponent, fakeTimers } from '../../testing/utils';
import { PopoutWrapper } from './PopoutWrapper';
import { PopoutWrapper, type PopoutWrapperProps } from './PopoutWrapper';
import styles from './PopoutWrapper.module.css';

describe(PopoutWrapper, () => {
Expand All @@ -19,8 +19,46 @@ describe(PopoutWrapper, () => {
it('should be closed if closing={true}', () => {
const result = render(<PopoutWrapper closing={true} data-testid="popout-wrapper" />);
const locator = result.getByTestId('popout-wrapper');
expect(locator).not.toHaveClass(styles.opening);
expect(locator).not.toHaveClass(styles.opened);
expect(locator).toHaveClass(styles.closing);
});

const strategyClassNames = [styles.fixed, styles.absolute];
it.each<{ strategy?: PopoutWrapperProps['strategy']; fixed?: boolean; className: string }>([
{
strategy: 'none',
className: '',
},
{
strategy: 'fixed',
className: styles.fixed,
},
{
strategy: 'absolute',
className: styles.absolute,
},
{
fixed: false,
className: '',
},
{
fixed: true,
className: styles.fixed,
},
{
className: styles.fixed,
},
])(
'should have className $className when use strategy $strategy, fixed $fixed',
({ strategy, fixed, className }) => {
const result = render(
<PopoutWrapper strategy={strategy} fixed={fixed} data-testid="popout-wrapper" />,
);
const locator = result.getByTestId('popout-wrapper');
className && expect(locator).toHaveClass(className);
const filteredClassNames = strategyClassNames.filter((cn) => cn !== className).join(' ');
expect(locator).not.toHaveClass(filteredClassNames);
},
);
});
});
24 changes: 22 additions & 2 deletions packages/vkui/src/components/PopoutWrapper/PopoutWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,34 @@ const stylesAlignY = {
bottom: styles.alignYBottom,
};

const stylesStrategy = {
fixed: styles.fixed,
absolute: styles.absolute,
none: undefined,
};

export interface PopoutWrapperProps extends HTMLAttributesWithRootRef<HTMLDivElement> {
/**
* Позволяет сделать прозрачную подложку
*/
noBackground?: boolean;
/**
* @deprecated будет удалён в **VKUI v8**
* Используйте `strategy` вместо этого свойства.
*
* Включает фиксированное позиционирование.
*
* По умолчанию у компонента не задан никакой `position`.
* При значении `false` у компонента не задан никакой `position`.
*/
fixed?: boolean;
/**
* Стратегия позиционирования:
*
* - `fixed`: у контейнера выставлен `position: fixed`
* - `absolute`: у контейнера выставлен `position: absolute`
* - `none`: у контейнера не выставлен `position`
inomdzhon marked this conversation as resolved.
Show resolved Hide resolved
*/
strategy?: 'fixed' | 'absolute' | 'none';
/**
* Выравнивает контент по горизонтали.
*/
Expand All @@ -55,12 +72,15 @@ export const PopoutWrapper = ({
alignX = 'center',
closing = false,
noBackground = false,
strategy: strategyProp,
fixed = true,
children,
onClick,
zIndex = 'var(--vkui--z_index_popout)',
...restProps
}: PopoutWrapperProps): React.ReactNode => {
const strategy = strategyProp || (fixed ? 'fixed' : 'none');

return (
<RootComponent
{...restProps}
Expand All @@ -69,7 +89,7 @@ export const PopoutWrapper = ({
stylesAlignY[alignY],
stylesAlignX[alignX],
closing ? styles.closing : styles.opened,
fixed && styles.fixed,
strategy && stylesStrategy[strategy],
!noBackground && styles.masked,
)}
baseStyle={{ zIndex }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const ScreenSpinner: React.FC<ScreenSpinnerProps> & {

return (
<AppRootPortal usePortal={usePortal}>
<PopoutWrapper className={className} style={style} noBackground>
<PopoutWrapper className={className} style={style} noBackground strategy="fixed">
<ScreenSpinnerContainer state={state} mode={mode} label={label} customIcon={customIcon}>
<ScreenSpinnerLoader {...restProps} />
<ScreenSpinnerSwapIcon onClick={onClick} cancelLabel={cancelLabel} />
Expand Down