Skip to content

Commit

Permalink
feat(plasma-core, plasma-web, plasma-b2c): ModalBase component
Browse files Browse the repository at this point in the history
  • Loading branch information
kayman233 committed Sep 27, 2023
1 parent bdd8ace commit 63cfdf7
Show file tree
Hide file tree
Showing 23 changed files with 675 additions and 108 deletions.
12 changes: 12 additions & 0 deletions packages/plasma-b2c/api/plasma-b2c.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ import { MaxLinesProps } from '@salutejs/plasma-core';
import { mediaQuery } from '@salutejs/plasma-hope';
import { MediaQueryFunction } from '@salutejs/plasma-hope';
import { Modal } from '@salutejs/plasma-hope';
import { ModalBase } from '@salutejs/plasma-hope';
import { ModalBaseProps } from '@salutejs/plasma-hope';
import { ModalProps } from '@salutejs/plasma-hope';
import { ModalsProvider } from '@salutejs/plasma-hope';
import { ModalView } from '@salutejs/plasma-hope';
Expand All @@ -172,8 +174,10 @@ import { PopoverPlacement } from '@salutejs/plasma-hope';
import { PopoverProps } from '@salutejs/plasma-hope';
import { Popup } from '@salutejs/plasma-hope';
import { PopupBase } from '@salutejs/plasma-hope';
import { PopupBaseContext } from '@salutejs/plasma-hope';
import { PopupBasePlacement } from '@salutejs/plasma-hope';
import { PopupBaseProps } from '@salutejs/plasma-hope';
import { PopupBaseProvider } from '@salutejs/plasma-hope';
import { PopupProps } from '@salutejs/plasma-hope';
import { PreviewGallery } from '@salutejs/plasma-hope';
import { PreviewGalleryItemProps } from '@salutejs/plasma-hope';
Expand Down Expand Up @@ -576,6 +580,10 @@ export { MediaQueryFunction }

export { Modal }

export { ModalBase }

export { ModalBaseProps }

export { ModalProps }

export { ModalsProvider }
Expand Down Expand Up @@ -628,10 +636,14 @@ export { Popup }

export { PopupBase }

export { PopupBaseContext }

export { PopupBasePlacement }

export { PopupBaseProps }

export { PopupBaseProvider }

export { PopupProps }

export { PreviewGallery }
Expand Down
139 changes: 139 additions & 0 deletions packages/plasma-b2c/src/components/ModalBase/ModalBase.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import React from 'react';
import styled, { createGlobalStyle } from 'styled-components';
import { Story, Meta } from '@storybook/react';
import { surfaceSolid02, darkOverlayBlur, overlaySoft } from '@salutejs/plasma-tokens-web';
import { InSpacingDecorator } from '@salutejs/plasma-sb-utils';

import { SSRProvider } from '../SSRProvider';
import { Button } from '../Button';
import { PopupBaseProvider } from '../PopupBase';

import { ModalBase } from '.';

export default {
title: 'Controls/ModalBase',
decorators: [InSpacingDecorator],
argTypes: {
placement: {
options: [
'center',
'top',
'bottom',
'right',
'left',
'top-right',
'top-left',
'bottom-right',
'bottom-left',
],
control: {
type: 'select',
},
},
},
} as Meta;

type ModalBaseStoryProps = {
placement: string;
offsetX: number;
offsetY: number;
closeOnEsc: boolean;
closeOnOverlayClick: boolean;
withBlur: boolean;
};

const StyledButton = styled(Button)`
margin-top: 1rem;
width: 15rem;
`;

const StyledWrapper = styled.div`
height: 1200px;
`;

const ModalOverlayVariables = createGlobalStyle`
body {
--plasma-modal-blur-overlay-color: ${darkOverlayBlur};
--plasma-modal-overlay-color: ${overlaySoft};
}
`;

const Content = styled.div`
background: ${surfaceSolid02};
padding: 1rem;
`;

export const ModalBaseDemo: Story<ModalBaseStoryProps> = ({ placement, offsetX, offsetY, ...rest }) => {
const [isOpenA, setIsOpenA] = React.useState(false);
const [isOpenB, setIsOpenB] = React.useState(false);
const [isOpenC, setIsOpenC] = React.useState(false);

return (
<SSRProvider>
<StyledWrapper>
<ModalOverlayVariables />
<PopupBaseProvider>
<div style={{ display: 'flex', flexDirection: 'column' }}>
<StyledButton text="Открыть A" onClick={() => setIsOpenA(true)} />
</div>
<ModalBase
id="modalA"
onClose={() => setIsOpenA(false)}
isOpen={isOpenA}
placement={placement}
offset={[offsetX, offsetY]}
{...rest}
>
<Content>
<Button onClick={() => setIsOpenA(false)}>Close</Button>
<div style={{ display: 'flex', flexDirection: 'column' }}>
<StyledButton text="Открыть B" onClick={() => setIsOpenB(true)} />
</div>
<ModalBase
id="modalB"
onClose={() => setIsOpenB(false)}
isOpen={isOpenB}
placement="left"
offset={[offsetX, offsetY]}
{...rest}
>
<Content>
<Button style={{ marginRight: '1rem' }} onClick={() => setIsOpenB(false)}>
Close
</Button>
<div style={{ display: 'flex', flexDirection: 'column' }}>
<StyledButton text="Открыть C" onClick={() => setIsOpenC(true)} />
</div>
<ModalBase
id="modalC"
onClose={() => setIsOpenC(false)}
isOpen={isOpenC}
placement="top"
offset={[offsetX, offsetY]}
{...rest}
>
<Content>
<Button style={{ marginRight: '1rem' }} onClick={() => setIsOpenC(false)}>
Close
</Button>
<>Content</>
</Content>
</ModalBase>
</Content>
</ModalBase>
</Content>
</ModalBase>
</PopupBaseProvider>
</StyledWrapper>
</SSRProvider>
);
};

ModalBaseDemo.args = {
placement: 'center',
withBlur: false,
closeOnEsc: true,
closeOnOverlayClick: true,
offsetX: 0,
offsetY: 0,
};
2 changes: 2 additions & 0 deletions packages/plasma-b2c/src/components/ModalBase/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { ModalBase } from '@salutejs/plasma-hope';
export type { ModalBaseProps } from '@salutejs/plasma-hope';
42 changes: 22 additions & 20 deletions packages/plasma-b2c/src/components/PopupBase/PopupBase.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { surfaceSolid03, surfaceSolid02 } from '@salutejs/plasma-tokens-web';
import { SSRProvider } from '../SSRProvider';
import { Button } from '../Button';

import { PopupBase } from '.';
import { PopupBase, PopupBaseProvider } from '.';

export default {
title: 'Controls/PopupBase',
Expand Down Expand Up @@ -73,25 +73,27 @@ export const PopupBaseDemo: Story<PopupBaseStoryProps> = ({ placement, offsetX,
return (
<SSRProvider>
<StyledWrapper>
<div style={{ display: 'flex', flexDirection: 'column' }}>
<StyledButton text="Открыть во Frame" onClick={() => setIsOpenA(true)} />
<StyledButton text="Открыть в document" onClick={() => setIsOpenB(true)} />
</div>
<PopupBase frame={ref} isOpen={isOpenA} placement={placement} offset={[offsetX, offsetY]}>
<Content>
<Button onClick={() => setIsOpenA(false)}>Close</Button>
<>Content</>
</Content>
</PopupBase>
<OtherContent ref={ref}>
<>Frame</>
</OtherContent>
<PopupBase frame="document" isOpen={isOpenB} placement={placement} offset={[offsetX, offsetY]}>
<Content>
<Button onClick={() => setIsOpenB(false)}>Close</Button>
<>Content</>
</Content>
</PopupBase>
<PopupBaseProvider>
<div style={{ display: 'flex', flexDirection: 'column' }}>
<StyledButton text="Открыть во Frame" onClick={() => setIsOpenA(true)} />
<StyledButton text="Открыть в document" onClick={() => setIsOpenB(true)} />
</div>
<PopupBase frame={ref} isOpen={isOpenA} placement={placement} offset={[offsetX, offsetY]}>
<Content>
<Button onClick={() => setIsOpenA(false)}>Close</Button>
<>Content</>
</Content>
</PopupBase>
<OtherContent ref={ref}>
<>Frame</>
</OtherContent>
<PopupBase frame="document" isOpen={isOpenB} placement={placement} offset={[offsetX, offsetY]}>
<Content>
<Button onClick={() => setIsOpenB(false)}>Close</Button>
<>Content</>
</Content>
</PopupBase>
</PopupBaseProvider>
</StyledWrapper>
</SSRProvider>
);
Expand Down
2 changes: 2 additions & 0 deletions packages/plasma-b2c/src/components/PopupBase/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export { PopupBaseProvider, PopupBaseContext } from '@salutejs/plasma-hope';

export { PopupBase } from '@salutejs/plasma-hope';
export type { PopupBaseProps, PopupBasePlacement } from '@salutejs/plasma-hope';
1 change: 1 addition & 0 deletions packages/plasma-b2c/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export * from './components/Image';
export * from './components/Link';
export * from './components/List';
export * from './components/Modal';
export * from './components/ModalBase';
export * from './components/Notification';
export * from './components/PaginationDots';
export * from './components/Popup';
Expand Down
29 changes: 28 additions & 1 deletion packages/plasma-core/api/plasma-core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,21 @@ export interface MaxLinesProps {
maxLines?: number;
}

// @public
export const ModalBase: FC<ModalBaseProps>;

// @public (undocumented)
export interface ModalBaseProps extends Omit<PopupBaseProps, 'frame'> {
closeOnEsc?: boolean;
closeOnOverlayClick?: boolean;
focusAfterRef?: React_2.RefObject<HTMLElement>;
initialFocusRef?: React_2.RefObject<HTMLElement>;
onClose?: () => void;
onEscKeyDown?: (event: KeyboardEvent) => void;
onOverlayClick?: (event: React_2.MouseEvent<HTMLDivElement>) => void;
withBlur?: boolean;
}

// @public (undocumented)
export const monthLongName: (val: number) => string;

Expand Down Expand Up @@ -842,7 +857,12 @@ export interface PopoverProps extends HTMLAttributes<HTMLDivElement> {
export const Popup: React_2.NamedExoticComponent<PopupProps & React_2.RefAttributes<HTMLDivElement>>;

// @public
export const PopupBase: FC<PopupBaseProps>;
export const PopupBase: React_2.ForwardRefExoticComponent<PopupBaseProps & React_2.RefAttributes<HTMLDivElement>>;

// Warning: (ae-forgotten-export) The symbol "PopupBaseController" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export const PopupBaseContext: React_2.Context<PopupBaseController>;

// Warning: (ae-forgotten-export) The symbol "BasicPopupBasePlacement" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "MixedPopupBasePlacement" needs to be exported by the entry point index.d.ts
Expand All @@ -859,9 +879,16 @@ export interface PopupBaseProps extends React_2.HTMLAttributes<HTMLDivElement> {
offset?: [number | string, number | string];
// (undocumented)
placement?: PopupBasePlacement;
// Warning: (ae-forgotten-export) The symbol "PopupInfo" needs to be exported by the entry point index.d.ts
popupInfo?: PopupInfo;
zIndex?: string;
}

// @public (undocumented)
export const PopupBaseProvider: React_2.FC<{
children: ReactNode;
}>;

// @public (undocumented)
export interface PopupProps extends HTMLAttributes<HTMLDivElement> {
children?: ReactNode;
Expand Down
Loading

0 comments on commit 63cfdf7

Please sign in to comment.