diff --git a/src/components/Modal/Modal.stories.tsx b/src/components/Modal/Modal.stories.tsx index 8bc93b50a..fe0971cff 100644 --- a/src/components/Modal/Modal.stories.tsx +++ b/src/components/Modal/Modal.stories.tsx @@ -5,19 +5,35 @@ import { Icon } from '../Icon'; import { iconTypes } from '../Icon/collection'; import colors from '../../styles/colors'; import { Input } from '../Input'; +import { useArgs } from '@storybook/addons'; export default { title: 'Popup/Modal', component: Modal, } as ComponentMeta; -const Template: ComponentStory = (args) => ; +const Template: ComponentStory = (args) => { + const [{}, updateArgs] = useArgs(); + + return ( + { + console.log('canceled'); + updateArgs({ isVisible: false }); + }} + onOk={() => { + console.log('pressed ok'); + updateArgs({ isVisible: false }); + }} + /> + ); +}; export const Regular = Template.bind({}); Regular.args = { id: 'regular', title: 'Confirm', - isVisible: true, children: [
>` - ${(p) => (p.isVisible ? 'display: grid;' : 'display: none;')}; +const ModalStyled = styled.div` ${fonts.text}; background-color: ${colors.white}; box-shadow: 0 4px 10px rgba(48, 71, 105, 0.1); @@ -43,11 +42,23 @@ const ModalFooter = styled.div` padding: 15px 32px 20px; `; +const ModalWrapperStyled = styled.div>` + ${(p) => (p.isVisible ? 'display: grid;' : 'display: none;')}; + background: rgba(0, 0, 0, 0.3); + bottom: 0; + left: 0; + position: fixed; + right: 0; + top: 0; + z-index: 5; +`; + const ModalStyles = { ModalContent, ModalFooter, ModalHeader, ModalStyled, + ModalWrapperStyled, }; export default ModalStyles; diff --git a/src/components/Modal/Modal.test.tsx b/src/components/Modal/Modal.test.tsx index 5a26dbbe7..e872c6eff 100644 --- a/src/components/Modal/Modal.test.tsx +++ b/src/components/Modal/Modal.test.tsx @@ -1,20 +1,44 @@ import ReactDOM from 'react-dom'; import React from 'react'; -import { composeStories } from '@storybook/testing-react'; -import * as stories from './Modal.stories'; -const { Regular } = composeStories(stories); +import Modal from './Modal'; +import { Icon } from '../Icon'; +import { iconTypes } from '../Icon/collection'; +import color from '../../styles/colors'; describe('Modal - Regular', () => { let container: HTMLDivElement; - let modalTestId = 'modal-test-id'; - let headerTestId = 'modal-header-test-id'; - let contentTestId = 'modal-content-test-id'; - let footerTestId = 'modal-footer-test-id'; + const modalTestId = 'modal-test-id'; + const headerTestId = 'modal-header-test-id'; + const contentTestId = 'modal-content-test-id'; + const footerTestId = 'modal-footer-test-id'; beforeEach(() => { + const args = { + id: 'regular', + title: 'Confirm', + children: [ +
+ +

Proceed uploading?

+
, + ], + isVisible: true, + }; container = document.createElement('div'); document.body.appendChild(container); - ReactDOM.render(, container); + ReactDOM.render(, container); }); afterEach(() => { diff --git a/src/components/Modal/Modal.tsx b/src/components/Modal/Modal.tsx index 1c9de921d..95decd38a 100644 --- a/src/components/Modal/Modal.tsx +++ b/src/components/Modal/Modal.tsx @@ -4,14 +4,20 @@ import Button from '../Button/Button'; import ModalStyles from './Modal.styles'; import { iconTypes } from '../Icon/collection'; -const { ModalHeader, ModalStyled, ModalFooter, ModalContent } = ModalStyles; +const { + ModalHeader, + ModalStyled, + ModalFooter, + ModalContent, + ModalWrapperStyled, +} = ModalStyles; const Modal: React.FC = ({ id = String(Date.now()), children, isOkDisabled, isCancelDisabled, - isVisible, + isVisible = true, cancelText = 'Cancel', okText = 'Ok', onCancel, @@ -25,51 +31,60 @@ const Modal: React.FC = ({ }, [isVisible]); return ( - - -

{title}

-