diff --git a/src/components/Button/Button.d.ts b/src/components/Button/Button.d.ts new file mode 100644 index 00000000..e69de29b diff --git a/src/components/Button/Button.tsx b/src/components/Button/Button.tsx index 99e6ab82..0c00988e 100644 --- a/src/components/Button/Button.tsx +++ b/src/components/Button/Button.tsx @@ -4,7 +4,7 @@ import { ButtonType, ButtonColor } from './interfaces' import { IconType } from '../Icon/interfaces' import { Icon } from '../Icon' -interface Props { +export interface Props { /** Determines if the button should be outlined and not filled. By defaut is false */ outlined?: boolean /** Defines the button variant. By default is primary */ diff --git a/src/components/Modal/Modal.tsx b/src/components/Modal/Modal.tsx index 86b47634..f560f810 100644 --- a/src/components/Modal/Modal.tsx +++ b/src/components/Modal/Modal.tsx @@ -1,7 +1,6 @@ -import React, { Component, ReactNode } from 'react' +import React, { ReactNode } from 'react' import BootstrapModal from 'react-bootstrap/Modal' -import { Button } from '../Button' -import { ButtonColor } from '../Button/interfaces' +import { Button, Props as ButtonProps } from '../Button' import { ButtonsAlignment } from './interfaces' interface Props { @@ -31,153 +30,80 @@ interface Props { /** * Optional close button properties. **/ - closeButton?: { - /** - * Optional label for the close button. - * @default "Close" - **/ - label?: string - /** - * Optional color for the close button. - * @default "secondary" - **/ - color?: ButtonColor - /** - * Optional callback for the close button. - **/ - callback?(): void - } + closeButton?: ButtonProps /** * Optional middle button properties. **/ - middleButton?: { - /** - * Optional label for the middle button. - * @default "Another action" - **/ - label?: string - /** - * Optional color for the middle button. - * @default "warning" - **/ - color?: ButtonColor - /** - * Optional callback for the middle button. - **/ - callback?(): void - } + middleButton?: ButtonProps /** * Optional success button properties. **/ - successButton?: { - /** - * Optional label for the success button. - * @default "Confirm" - **/ - label?: string - /** - * Optional color for the success button. - * @default "primary" - **/ - color?: ButtonColor - /** - * Optional callback for the success button. - **/ - callback?(): void - } + successButton?: ButtonProps } /** * Add dialogs for lightboxes, user notifications, or completely custom content. */ -class Modal extends Component { - render() { - const { - show, - toggle, - title, - body, - verticallyCentered, - buttonsAlignment, - showHeaderCloseButton, - closeButton, - middleButton, - successButton, - } = this.props +const Modal = (props: Props) => { + const { + show, + toggle, + title, + body, + verticallyCentered, + buttonsAlignment, + showHeaderCloseButton, + closeButton, + middleButton, + successButton, + } = props - if (show) { - return ( - toggle()} - > - {(showHeaderCloseButton === false ? title : true) && ( - - {title && {title}} - - )} - {body && {body}} - - {closeButton && ( - - )} - {middleButton && ( - - )} - {successButton && ( - - )} - - - ) - } else return <> - } + return ( + toggle()} + > + {(showHeaderCloseButton === false ? title : true) && ( + + {title && {title}} + + )} + {body && {body}} + + {closeButton && ( + + )} + {middleButton && ( + + )} + {successButton && ( + + )} + + + ) } export { Modal } diff --git a/stories/modal.stories.tsx b/stories/modal.stories.tsx index dee82505..756ce68d 100644 --- a/stories/modal.stories.tsx +++ b/stories/modal.stories.tsx @@ -32,8 +32,11 @@ storiesOf('Modal', module) } closeButton={{ - label: 'Close me', - callback: () => console.log('modal closed'), + children: 'Close me', + onClick: () => { + console.log('clicked close') + setShow(!show) + }, }} /> @@ -57,14 +60,24 @@ storiesOf('Modal', module) } closeButton={{ - label: 'Close me', + children: 'Close me', color: 'secondary', - callback: () => console.log('modal closed'), + icon: 'remove', + iconLocation: 'left', + onClick: () => { + console.log('clicked close') + setShow(!show) + }, }} successButton={{ - label: 'I agree!', + children: 'I agree!', color: 'success', - callback: () => console.log('clicked agree'), + icon: 'add', + iconLocation: 'left', + onClick: () => { + console.log('clicked agree') + setShow(!show) + }, }} /> @@ -88,19 +101,35 @@ storiesOf('Modal', module) } closeButton={{ - label: 'Close me', + children: 'Close me', color: 'secondary', - callback: () => console.log('modal closed'), + icon: 'remove', + iconLocation: 'left', + onClick: () => { + console.log('clicked close') + setShow(!show) + }, }} middleButton={{ - label: 'Maybe', + children: 'Disabled', color: 'info', - callback: () => console.log('clicked maybe'), + icon: 'save', + iconLocation: 'left', + disabled: true, + onClick: () => { + console.log('clicked maybe') + setShow(!show) + }, }} successButton={{ - label: 'I agree!', + children: 'I agree!', color: 'success', - callback: () => console.log('clicked agree'), + icon: 'add', + iconLocation: 'left', + onClick: () => { + console.log('clicked agree') + setShow(!show) + }, }} /> @@ -130,19 +159,34 @@ storiesOf('Modal', module) verticallyCentered buttonsAlignment="right" closeButton={{ - label: 'Close me', + children: 'Close me', color: 'secondary', - callback: () => console.log('modal closed'), + icon: 'remove', + iconLocation: 'left', + onClick: () => { + console.log('clicked close') + setShow(!show) + }, }} middleButton={{ - label: 'Maybe', + children: 'Maybe', color: 'info', - callback: () => console.log('clicked maybe'), + icon: 'save', + iconLocation: 'left', + onClick: () => { + console.log('clicked maybe') + setShow(!show) + }, }} successButton={{ - label: 'I agree!', + children: 'I agree!', color: 'success', - callback: () => console.log('clicked agree'), + icon: 'add', + iconLocation: 'left', + onClick: () => { + console.log('clicked agree') + setShow(!show) + }, }} />