Skip to content

Commit

Permalink
fix(plasma-web, plasma-b2c): fix NoScroll behavior in ModalBase
Browse files Browse the repository at this point in the history
  • Loading branch information
kayman233 committed Nov 10, 2023
1 parent 68bf296 commit 5900137
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 23 deletions.
5 changes: 4 additions & 1 deletion packages/plasma-b2c/api/plasma-b2c.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ import { MediaQueryFunction } from '@salutejs/plasma-hope';
import { Modal } from '@salutejs/plasma-hope';
import { modalClasses as modalBaseClasses } from '@salutejs/plasma-new-hope/styled-components';
import { ModalProps as ModalBaseProps } from '@salutejs/plasma-new-hope/styled-components';
import { modalTokens as modalBaseTokens } from '@salutejs/plasma-new-hope/styled-components';
import { ModalProps } from '@salutejs/plasma-hope';
import { ModalsProvider } from '@salutejs/plasma-hope';
import { ModalView } from '@salutejs/plasma-hope';
Expand Down Expand Up @@ -623,12 +624,14 @@ export { MediaQueryFunction }
export { Modal }

// @public
export const ModalBase: ForwardRefExoticComponent<ModalBaseProps & RefAttributes<HTMLDivElement>>;
export const ModalBase: React_2.ForwardRefExoticComponent<ModalBaseProps & React_2.RefAttributes<HTMLDivElement>>;

export { modalBaseClasses }

export { ModalBaseProps }

export { modalBaseTokens }

export { ModalProps }

export { ModalsProvider }
Expand Down
6 changes: 4 additions & 2 deletions packages/plasma-b2c/src/components/ModalBase/Modal.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { css } from '@salutejs/plasma-new-hope/styled-components';

import { modalBaseTokens } from '.';

export const config = {
defaults: {
view: 'default',
},
variations: {
view: {
default: css`
--plasma-modal-overlay-with-blur-color: rgba(35, 35, 35, 0.2);
--plasma-modal-overlay-color: rgba(8, 8, 8, 0.56);
${modalBaseTokens.modalOverlayWithBlurColor}: rgba(35, 35, 35, 0.2);
${modalBaseTokens.modalOverlayColor}: rgba(8, 8, 8, 0.56);
`,
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import styled from 'styled-components';
import { Story, Meta } from '@storybook/react';
import { surfaceSolid02 } from '@salutejs/plasma-tokens-web';
import { surfaceSolid02 } from '@salutejs/plasma-tokens-b2c';
import { InSpacingDecorator } from '@salutejs/plasma-sb-utils';

import { SSRProvider } from '../SSRProvider';
Expand Down
22 changes: 19 additions & 3 deletions packages/plasma-b2c/src/components/ModalBase/ModalBase.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
import React, { ForwardRefExoticComponent, RefAttributes, forwardRef } from 'react';
import { modalConfig, component, mergeConfig } from '@salutejs/plasma-new-hope/styled-components';
import type { ModalProps } from '@salutejs/plasma-new-hope/styled-components';
import { createGlobalStyle } from 'styled-components';

import { config } from './Modal.config';

// linaria не поддерживает динамический global style
const NoScroll = createGlobalStyle`
body {
overflow-y: hidden;
}
`;

const mergedConfig = mergeConfig(modalConfig, config);
const ModalBaseComponent = component(mergedConfig) as React.ForwardRefExoticComponent<
ModalProps & React.RefAttributes<HTMLDivElement>
const ModalBaseComponent = component(mergedConfig) as ForwardRefExoticComponent<
ModalProps & RefAttributes<HTMLDivElement>
>;

/**
* Модальное окно.
*/
export const ModalBase = ModalBaseComponent;
export const ModalBase = forwardRef<HTMLDivElement, ModalProps>(({ children, ...rest }) => {
return (
<ModalBaseComponent {...rest}>
<NoScroll />
{children}
</ModalBaseComponent>
);
});
5 changes: 4 additions & 1 deletion packages/plasma-b2c/src/components/ModalBase/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export { ModalBase } from './ModalBase';
export { modalClasses as modalBaseClasses } from '@salutejs/plasma-new-hope/styled-components';
export {
modalClasses as modalBaseClasses,
modalTokens as modalBaseTokens,
} from '@salutejs/plasma-new-hope/styled-components';

export type { ModalProps as ModalBaseProps } from '@salutejs/plasma-new-hope/styled-components';
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ export const classes = {
*/
overlay: 'modal-overlay',
};

export const tokens = {
modalOverlayWithBlurColor: '--plasma-modal-overlay-with-blur-color',
modalOverlayColor: '--plasma-modal-overlay-color',
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { styled } from '@linaria/react';

import { DEFAULT_Z_INDEX } from '../../Popup/utils';
import { tokens } from '../Modal/Modal.tokens';

// TODO: новый отдельный оверлей #778
export const Overlay = styled.div<{
Expand All @@ -20,7 +21,7 @@ export const Overlay = styled.div<{
z-index: ${({ zIndex }) => zIndex || DEFAULT_Z_INDEX};
--plasma_private-overlay-background-color: ${({ $withBlur }) =>
$withBlur ? 'var(--plasma-modal-overlay-with-blur-color)' : 'var(--plasma-modal-overlay-color)'};
$withBlur ? `var(${tokens.modalOverlayWithBlurColor})` : `var(${tokens.modalOverlayColor})`};
--plasma_private-overlay-backdrop-filter: ${({ $withBlur }) => ($withBlur ? 'blur(1rem)' : 'none')};
Expand Down
2 changes: 1 addition & 1 deletion packages/plasma-new-hope/src/components/Modal/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { modalConfig, modalRoot } from './Modal/Modal';
export { classes as modalClasses } from './Modal/Modal.tokens';
export { classes as modalClasses, tokens as modalTokens } from './Modal/Modal.tokens';
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { css } from '@linaria/core';

import { modalTokens } from '../../../../components/Modal';

export const config = {
defaults: {
view: 'default',
},
variations: {
view: {
default: css`
--plasma-modal-overlay-with-blur-color: var(--overlay-blur);
--plasma-modal-overlay-color: var(--overlay-soft);
${modalTokens.modalOverlayWithBlurColor}: var(--overlay-blur);
${modalTokens.modalOverlayColor}: var(--overlay-soft);
`,
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { css } from '@linaria/core';

import { modalTokens } from '../../../../components/Modal';

export const config = {
defaults: {
view: 'default',
},
variations: {
view: {
default: css`
--plasma-modal-overlay-with-blur-color: var(--overlay-blur);
--plasma-modal-overlay-color: var(--overlay-soft);
${modalTokens.modalOverlayWithBlurColor}: var(--overlay-blur);
${modalTokens.modalOverlayColor}: var(--overlay-soft);
`,
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { css } from '@linaria/core';

import { modalTokens } from '../../../../components/Modal';

export const config = {
defaults: {
view: 'default',
},
variations: {
view: {
default: css`
--plasma-modal-overlay-with-blur-color: var(--overlay-blur);
--plasma-modal-overlay-color: var(--overlay-soft);
${modalTokens.modalOverlayWithBlurColor}: var(--overlay-blur);
${modalTokens.modalOverlayColor}: var(--overlay-soft);
`,
},
},
Expand Down
5 changes: 4 additions & 1 deletion packages/plasma-web/api/plasma-web.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ import { MediaQueryFunction } from '@salutejs/plasma-hope';
import { Modal } from '@salutejs/plasma-hope';
import { modalClasses as modalBaseClasses } from '@salutejs/plasma-new-hope/styled-components';
import { ModalProps as ModalBaseProps } from '@salutejs/plasma-new-hope/styled-components';
import { modalTokens as modalBaseTokens } from '@salutejs/plasma-new-hope/styled-components';
import { ModalProps } from '@salutejs/plasma-hope';
import { ModalsProvider } from '@salutejs/plasma-hope';
import { ModalView } from '@salutejs/plasma-hope';
Expand Down Expand Up @@ -623,12 +624,14 @@ export { MediaQueryFunction }
export { Modal }

// @public
export const ModalBase: ForwardRefExoticComponent<ModalBaseProps & RefAttributes<HTMLDivElement>>;
export const ModalBase: React_2.ForwardRefExoticComponent<ModalBaseProps & React_2.RefAttributes<HTMLDivElement>>;

export { modalBaseClasses }

export { ModalBaseProps }

export { modalBaseTokens }

export { ModalProps }

export { ModalsProvider }
Expand Down
6 changes: 4 additions & 2 deletions packages/plasma-web/src/components/ModalBase/Modal.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { css } from '@salutejs/plasma-new-hope/styled-components';

import { modalBaseTokens } from '.';

export const config = {
defaults: {
view: 'default',
},
variations: {
view: {
default: css`
--plasma-modal-overlay-with-blur-color: rgba(35, 35, 35, 0.2);
--plasma-modal-overlay-color: rgba(8, 8, 8, 0.56);
${modalBaseTokens.modalOverlayWithBlurColor}: rgba(35, 35, 35, 0.2);
${modalBaseTokens.modalOverlayColor}: rgba(8, 8, 8, 0.56);
`,
},
},
Expand Down
22 changes: 19 additions & 3 deletions packages/plasma-web/src/components/ModalBase/ModalBase.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
import React, { ForwardRefExoticComponent, RefAttributes, forwardRef } from 'react';
import { modalConfig, component, mergeConfig } from '@salutejs/plasma-new-hope/styled-components';
import type { ModalProps } from '@salutejs/plasma-new-hope/styled-components';
import { createGlobalStyle } from 'styled-components';

import { config } from './Modal.config';

// linaria не поддерживает динамический global style
const NoScroll = createGlobalStyle`
body {
overflow-y: hidden;
}
`;

const mergedConfig = mergeConfig(modalConfig, config);
const ModalBaseComponent = component(mergedConfig) as React.ForwardRefExoticComponent<
ModalProps & React.RefAttributes<HTMLDivElement>
const ModalBaseComponent = component(mergedConfig) as ForwardRefExoticComponent<
ModalProps & RefAttributes<HTMLDivElement>
>;

/**
* Модальное окно.
*/
export const ModalBase = ModalBaseComponent;
export const ModalBase = forwardRef<HTMLDivElement, ModalProps>(({ children, ...rest }) => {
return (
<ModalBaseComponent {...rest}>
<NoScroll />
{children}
</ModalBaseComponent>
);
});
5 changes: 4 additions & 1 deletion packages/plasma-web/src/components/ModalBase/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export { ModalBase } from './ModalBase';
export { modalClasses as modalBaseClasses } from '@salutejs/plasma-new-hope/styled-components';
export {
modalClasses as modalBaseClasses,
modalTokens as modalBaseTokens,
} from '@salutejs/plasma-new-hope/styled-components';

export type { ModalProps as ModalBaseProps } from '@salutejs/plasma-new-hope/styled-components';

0 comments on commit 5900137

Please sign in to comment.