Skip to content

Commit

Permalink
feat(plasma-web/b2c): add Overlay component
Browse files Browse the repository at this point in the history
  • Loading branch information
TitanKuzmich committed Feb 9, 2024
1 parent e2e8027 commit f7dcdd9
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 0 deletions.
76 changes: 76 additions & 0 deletions packages/plasma-b2c/src/components/Overlay/Overlay.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React, { useState } from 'react';
import styled from 'styled-components';
import type { ComponentProps } from 'react';
import type { StoryObj, Meta } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { disableProps, InSpacingDecorator } from '@salutejs/plasma-sb-utils';

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

import { Overlay } from '.';

const onOverlayClick = action('onOverlayClick');

export default {
title: 'Controls/Overlay',
decorators: [InSpacingDecorator],
argTypes: {
isClickable: {
control: {
type: 'boolean',
},
table: { defaultValue: { summary: true } },
},
withBlur: {
control: {
type: 'boolean',
},
table: { defaultValue: { summary: false } },
},
...disableProps(['onOverlayClick', 'zIndex']),
},
} as Meta;

type StoryOverlayProps = ComponentProps<typeof Overlay>;

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

const StyledCloseButton = styled(Button)`
position: fixed;
top: 50%;
left: 50%;
z-index: 101;
transform: translate(-50%, -50%);
width: 15rem;
`;

const StoryDefault = (props: StoryOverlayProps) => {
const [isVisible, setIsVisible] = useState(false);

return (
<>
<StyledButton text="Показать overlay" onClick={() => setIsVisible(true)} />
{isVisible && (
<>
<Overlay {...props} />
<StyledCloseButton text=" Скрыть overlay" onClick={() => setIsVisible(false)} />
</>
)}
</>
);
};

export const Default: StoryObj<StoryOverlayProps> = {
args: {
zIndex: '100',
backgroundColorProperty: 'var(--plasma-colors-overlay-soft)',
withBlur: false,
transparent: false,
isClickable: true,
onOverlayClick,
},
render: (args) => <StoryDefault {...args} />,
};
2 changes: 2 additions & 0 deletions packages/plasma-b2c/src/components/Overlay/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { Overlay } from '@salutejs/plasma-new-hope/styled-components';
export type { OverlayProps } from '@salutejs/plasma-new-hope/styled-components';
1 change: 1 addition & 0 deletions packages/plasma-b2c/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export * from './components/List';
export * from './components/Modal';
export * from './components/ModalBase';
export * from './components/Notification';
export * from './components/Overlay';
export * from './components/PaginationDots';
export * from './components/Popup';
export * from './components/PopupBase';
Expand Down
76 changes: 76 additions & 0 deletions packages/plasma-web/src/components/Overlay/Overlay.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React, { useState } from 'react';
import styled from 'styled-components';
import type { ComponentProps } from 'react';
import type { StoryObj, Meta } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { disableProps, InSpacingDecorator } from '@salutejs/plasma-sb-utils';

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

import { Overlay } from '.';

const onOverlayClick = action('onOverlayClick');

export default {
title: 'Controls/Overlay',
decorators: [InSpacingDecorator],
argTypes: {
isClickable: {
control: {
type: 'boolean',
},
table: { defaultValue: { summary: true } },
},
withBlur: {
control: {
type: 'boolean',
},
table: { defaultValue: { summary: false } },
},
...disableProps(['onOverlayClick', 'zIndex']),
},
} as Meta;

type StoryOverlayProps = ComponentProps<typeof Overlay>;

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

const StyledCloseButton = styled(Button)`
position: fixed;
top: 50%;
left: 50%;
z-index: 101;
transform: translate(-50%, -50%);
width: 15rem;
`;

const StoryDefault = (props: StoryOverlayProps) => {
const [isVisible, setIsVisible] = useState(false);

return (
<>
<StyledButton text="Показать overlay" onClick={() => setIsVisible(true)} />
{isVisible && (
<>
<Overlay {...props} />
<StyledCloseButton view="primary" text=" Скрыть overlay" onClick={() => setIsVisible(false)} />
</>
)}
</>
);
};

export const Default: StoryObj<StoryOverlayProps> = {
args: {
zIndex: '100',
backgroundColorProperty: 'var(--plasma-colors-overlay-soft)',
withBlur: false,
transparent: false,
isClickable: true,
onOverlayClick,
},
render: (args) => <StoryDefault {...args} />,
};
2 changes: 2 additions & 0 deletions packages/plasma-web/src/components/Overlay/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { Overlay } from '@salutejs/plasma-new-hope/styled-components';
export type { OverlayProps } from '@salutejs/plasma-new-hope/styled-components';
1 change: 1 addition & 0 deletions packages/plasma-web/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export * from './components/List';
export * from './components/Modal';
export * from './components/ModalBase';
export * from './components/Notification';
export * from './components/Overlay';
export * from './components/PaginationDots';
export * from './components/Popup';
export * from './components/PopupBase';
Expand Down

0 comments on commit f7dcdd9

Please sign in to comment.