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

fix(plasma-new-hope): Popup and Portal improvements #1299

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 2 additions & 3 deletions packages/caldera-online/api/caldera-online.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import { PopupInfo } from '@salutejs/plasma-new-hope/styled-components';
import { PopupPlacement } from '@salutejs/plasma-new-hope/styled-components';
import { PopupProps } from '@salutejs/plasma-new-hope/styled-components';
import { PopupProvider } from '@salutejs/plasma-new-hope/styled-components';
import { Portal } from '@salutejs/plasma-new-hope/styled-components';
import { PortalProps } from '@salutejs/plasma-new-hope/styled-components';
import { PropsType } from '@salutejs/plasma-new-hope/types/engines/types';
import { RadioGroup } from '@salutejs/plasma-new-hope/styled-components';
Expand Down Expand Up @@ -88,7 +89,6 @@ import { ToastRole } from '@salutejs/plasma-new-hope/styled-components';
import { usePopupContext } from '@salutejs/plasma-new-hope/styled-components';
import { useSegment } from '@salutejs/plasma-new-hope/styled-components';
import { useToast } from '@salutejs/plasma-new-hope/styled-components';
import { Variants } from '@salutejs/plasma-new-hope/types/engines/types';

export { addFocus }

Expand Down Expand Up @@ -441,8 +441,7 @@ export { PopupProps }

export { PopupProvider }

// @public (undocumented)
export const Portal: FunctionComponent<PropsType<Variants> & PortalProps & RefAttributes<HTMLDivElement>>;
export { Portal }

export { PortalProps }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import styled from 'styled-components';
import { Button } from '../Button/Button';
import { BodyM } from '../Typography';

import { Portal } from './Portal';
import { Portal } from '.';

const meta: Meta<typeof Portal> = {
title: 'Controls/Portal',
Expand Down
10 changes: 0 additions & 10 deletions packages/caldera-online/src/components/Portal/Portal.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion packages/caldera-online/src/components/Portal/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { Portal } from './Portal';
export { Portal } from '@salutejs/plasma-new-hope/styled-components';

export type { PortalProps } from '@salutejs/plasma-new-hope/styled-components';
4 changes: 2 additions & 2 deletions packages/plasma-b2c/api/plasma-b2c.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ import { PopupProps as PopupBaseProps } from '@salutejs/plasma-new-hope/styled-c
import { PopupProvider as PopupBaseProvider } from '@salutejs/plasma-new-hope/styled-components';
import { PopupInfo } from '@salutejs/plasma-new-hope/styled-components';
import { PopupProps } from '@salutejs/plasma-hope';
import { Portal } from '@salutejs/plasma-new-hope/styled-components';
import { PortalProps } from '@salutejs/plasma-new-hope/styled-components';
import { PreviewGallery } from '@salutejs/plasma-hope';
import { PreviewGalleryItemProps } from '@salutejs/plasma-hope';
Expand Down Expand Up @@ -1672,8 +1673,7 @@ export { PopupInfo }

export { PopupProps }

// @public (undocumented)
export const Portal: FunctionComponent<PropsType<Variants> & PortalProps & RefAttributes<HTMLDivElement>>;
export { Portal }

export { PortalProps }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import styled from 'styled-components';
import { Button } from '../Button/Button';
import { BodyM } from '../Typography';

import { Portal } from './Portal';
import { Portal } from '.';

const meta: Meta<typeof Portal> = {
title: 'Controls/Portal',
Expand Down
10 changes: 0 additions & 10 deletions packages/plasma-b2c/src/components/Portal/Portal.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion packages/plasma-b2c/src/components/Portal/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { Portal } from './Portal';
export { Portal } from '@salutejs/plasma-new-hope/styled-components';

export type { PortalProps } from '@salutejs/plasma-new-hope/styled-components';
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import type { CSSProperties } from 'react';
import { usePopper } from 'react-popper';
import { useFocusTrap, useForkRef } from '@salutejs/plasma-core';

import { component, mergeConfig } from '../../engines';
import type { RootProps } from '../../engines/types';
import { cx } from '../../utils';
import { portalConfig } from '../Portal';
import { Portal } from '../Portal';

import { base as viewCSS } from './variations/_view/base';
import type { PopoverPlacement, PopoverProps } from './Popover.types';
Expand All @@ -16,9 +15,6 @@ import { classes } from './Popover.tokens';
export const ESCAPE_KEYCODE = 27;
export const POPOVER_PORTAL_ID = 'plasma-popover-root';

const mergedPortalConfig = mergeConfig(portalConfig);
const Portal = component(mergedPortalConfig);

/**
* Всплывающее окно с возможностью позиционирования
* и вызова по клику либо ховеру.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const PopupView = styled.div`
`;

export const PopupRootContainer = styled.div<PopupRootContainerProps>`
position: ${({ frame }) => (frame === 'document' ? 'fixed' : 'absolute')};
position: absolute;
z-index: ${({ zIndex }) => zIndex || DEFAULT_Z_INDEX};
left: ${({ position }) => position.left || ''};
right: ${({ position }) => position.right || ''};
Expand Down
6 changes: 1 addition & 5 deletions packages/plasma-new-hope/src/components/Popup/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { useForkRef, safeUseId } from '@salutejs/plasma-core';

import { RootProps } from '../../engines/types';
import { cx } from '../../utils';
import { portalConfig } from '../Portal';
import { component, mergeConfig } from '../../engines';
import { Portal } from '../Portal';

import type { PopupPlacementBasic, PopupPlacement, PopupPositionType, PopupProps } from './Popup.types';
import { POPUP_PORTAL_ID } from './PopupContext';
Expand Down Expand Up @@ -79,9 +78,6 @@ export const handlePosition = (
};
};

const mergedPortalConfig = mergeConfig(portalConfig);
const Portal = component(mergedPortalConfig);

/**
* Базовый копмонент Popup.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const PopupRoot = forwardRef<HTMLDivElement, PopupRootProps>(
className={classes.root}
ref={innerRef}
placement={placement}
frame={frame}
offset={offset}
zIndex={zIndex}
onAnimationEnd={handleAnimationEnd}
Expand Down
30 changes: 9 additions & 21 deletions packages/plasma-new-hope/src/components/Portal/Portal.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
import React, { forwardRef } from 'react';
import React from 'react';
import ReactDOM from 'react-dom';

import type { RootProps } from '../../engines/types';

import { PortalProps } from './Portal.types';

/*
* Вспомогательный компонент. Используется в Popup, Popover.
* Представляет собой ReactDOM.createPortal() в форме компонента.
*/
export const portalRoot = (Root: RootProps<HTMLDivElement, Omit<PortalProps, 'container'>>) =>
forwardRef<HTMLDivElement, PortalProps>(({ children, container, disabled = false }, outerRootRef) => {
const portalContainer = typeof container === 'function' ? container() : container;

return (
<Root disabled={disabled} ref={outerRootRef}>
{disabled && children}
{!disabled && ReactDOM.createPortal(children, portalContainer)}
</Root>
);
});
export const Portal = ({ children, container, disabled = false }: PortalProps) => {
const portalContainer = typeof container === 'function' ? container() : container;

export const portalConfig = {
name: 'Portal',
tag: 'div',
layout: portalRoot,
base: '',
variations: {},
defaults: {},
return (
<>
{disabled && children}
{!disabled && ReactDOM.createPortal(children, portalContainer)}
</>
);
};
2 changes: 1 addition & 1 deletion packages/plasma-new-hope/src/components/Portal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { portalConfig, portalRoot } from './Portal';
export { Portal } from './Portal';
export type { PortalProps } from './Portal.types';
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { styled } from '@linaria/react';
import { Button } from '../Button/Button';
import { WithTheme } from '../../../_helpers';
import { Body } from '../../../typograpy/components/Body/Body';

import { Portal } from './Portal';
import { Portal } from '../../../../components/Portal';

const meta: Meta<typeof Portal> = {
title: 'plasma_b2c/Portal',
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { styled } from '@linaria/react';
import { Button } from '../Button/Button';
import { WithTheme } from '../../../_helpers';
import { Body } from '../../../typograpy/components/Body/Body';

import { Portal } from './Portal';
import { Portal } from '../../../../components/Portal';

const meta: Meta<typeof Portal> = {
title: 'plasma_web/Portal',
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions packages/plasma-web/api/plasma-web.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ import { PopupProps as PopupBaseProps } from '@salutejs/plasma-new-hope/styled-c
import { PopupProvider as PopupBaseProvider } from '@salutejs/plasma-new-hope/styled-components';
import { PopupInfo } from '@salutejs/plasma-new-hope/styled-components';
import { PopupProps } from '@salutejs/plasma-hope';
import { Portal } from '@salutejs/plasma-new-hope/styled-components';
import { PortalProps } from '@salutejs/plasma-new-hope/styled-components';
import { PreviewGallery } from '@salutejs/plasma-hope';
import { PreviewGalleryItemProps } from '@salutejs/plasma-hope';
Expand Down Expand Up @@ -1674,8 +1675,7 @@ export { PopupInfo }

export { PopupProps }

// @public (undocumented)
export const Portal: FunctionComponent<PropsType<Variants> & PortalProps & RefAttributes<HTMLDivElement>>;
export { Portal }

export { PortalProps }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import styled from 'styled-components';
import { Button } from '../Button/Button';
import { BodyM } from '../Typography';

import { Portal } from './Portal';
import { Portal } from '.';

const meta: Meta<typeof Portal> = {
title: 'Controls/Portal',
Expand Down
10 changes: 0 additions & 10 deletions packages/plasma-web/src/components/Portal/Portal.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion packages/plasma-web/src/components/Portal/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { Portal } from './Portal';
export { Portal } from '@salutejs/plasma-new-hope/styled-components';

export type { PortalProps } from '@salutejs/plasma-new-hope/styled-components';
4 changes: 2 additions & 2 deletions packages/sdds-dfa/api/sdds-dfa.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ import { PopupInfo } from '@salutejs/plasma-new-hope/styled-components';
import { PopupPlacement } from '@salutejs/plasma-new-hope/styled-components';
import { PopupProps } from '@salutejs/plasma-new-hope/styled-components';
import { PopupProvider } from '@salutejs/plasma-new-hope/styled-components';
import { Portal } from '@salutejs/plasma-new-hope/styled-components';
import { PortalProps } from '@salutejs/plasma-new-hope/styled-components';
import { ProgressProps } from '@salutejs/plasma-new-hope/styled-components';
import { PropsType } from '@salutejs/plasma-new-hope/types/engines/types';
Expand Down Expand Up @@ -1278,8 +1279,7 @@ export { PopupProps }

export { PopupProvider }

// @public (undocumented)
export const Portal: FunctionComponent<PropsType<Variants> & PortalProps & RefAttributes<HTMLDivElement>>;
export { Portal }

export { PortalProps }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import styled from 'styled-components';
import { Button } from '../Button/Button';
import { BodyM } from '../Typography';

import { Portal } from './Portal';
import { Portal } from '.';

const meta: Meta<typeof Portal> = {
title: 'Controls/Portal',
Expand Down
10 changes: 0 additions & 10 deletions packages/sdds-dfa/src/components/Portal/Portal.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion packages/sdds-dfa/src/components/Portal/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { Portal } from './Portal';
export { Portal } from '@salutejs/plasma-new-hope/styled-components';

export type { PortalProps } from '@salutejs/plasma-new-hope/styled-components';
4 changes: 2 additions & 2 deletions packages/sdds-serv/api/sdds-serv.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ import { PopupInfo } from '@salutejs/plasma-new-hope/styled-components';
import { PopupPlacement } from '@salutejs/plasma-new-hope/styled-components';
import { PopupProps } from '@salutejs/plasma-new-hope/styled-components';
import { PopupProvider } from '@salutejs/plasma-new-hope/styled-components';
import { Portal } from '@salutejs/plasma-new-hope/styled-components';
import { PortalProps } from '@salutejs/plasma-new-hope/styled-components';
import { ProgressProps } from '@salutejs/plasma-new-hope/styled-components';
import { PropsType } from '@salutejs/plasma-new-hope/types/engines/types';
Expand Down Expand Up @@ -1140,8 +1141,7 @@ export { PopupProps }

export { PopupProvider }

// @public (undocumented)
export const Portal: FunctionComponent<PropsType<Variants> & PortalProps & RefAttributes<HTMLDivElement>>;
export { Portal }

export { PortalProps }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import styled from 'styled-components';
import { Button } from '../Button/Button';
import { BodyM } from '../Typography';

import { Portal } from './Portal';
import { Portal } from '.';

const meta: Meta<typeof Portal> = {
title: 'Controls/Portal',
Expand Down
10 changes: 0 additions & 10 deletions packages/sdds-serv/src/components/Portal/Portal.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion packages/sdds-serv/src/components/Portal/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { Portal } from './Portal';
export { Portal } from '@salutejs/plasma-new-hope/styled-components';

export type { PortalProps } from '@salutejs/plasma-new-hope/styled-components';
Loading