Skip to content

Commit

Permalink
feat(ModalDialog): expose hasCloseButton prop
Browse files Browse the repository at this point in the history
  • Loading branch information
maxime-gendron committed Dec 9, 2021
1 parent 3135fb3 commit 432bf14
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
8 changes: 5 additions & 3 deletions packages/react/src/components/modal/modal-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ const HeadingWrapper = styled.div`
`;

const TitleIcon = styled(Icon)`
left: -32px;
margin-top: calc(var(--spacing-half) * 1.5);
position: absolute;
top: 0;
left: -32px;
`;

export interface ModalDialogProps {
Expand All @@ -65,6 +65,7 @@ export interface ModalDialogProps {
className?: string;
confirmButton?: { label?: string, onConfirm?(): void };
footerContent?: ReactElement;
hasCloseButton?: boolean;
isOpen: boolean;
/**
* Defines if the overlay click should close the modal
Expand All @@ -88,6 +89,7 @@ export function ModalDialog({
className,
confirmButton,
footerContent,
hasCloseButton,
isOpen,
shouldCloseOnOverlayClick = true,
subtitle,
Expand All @@ -114,7 +116,7 @@ export function ModalDialog({
}

function getHeader(): ReactElement | undefined {
const HeadingWrapperComponent = titleIcon ? HeadingWrapper : Fragment;
const HeadingWrapperComponent = hasTitleIcon ? HeadingWrapper : Fragment;

if (title || subtitle) {
return (
Expand Down Expand Up @@ -172,7 +174,7 @@ export function ModalDialog({
ariaLabelledBy={title ? titleId : undefined}
className={className}
modalHeader={getHeader()}
hasCloseButton
hasCloseButton={hasCloseButton}
modalFooter={footerContent || getFooter()}
role="dialog"
onAfterOpen={() => titleRef.current?.focus()}
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/icons/alert-filled.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/react/src/icons/warning-filled.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 27 additions & 2 deletions packages/storybook/stories/modal-dialog.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,34 @@ It is important for users of screenreaders that other page content be hidden (vi
ariaDescribedby="story-description"
isOpen={isModalOpen}
onRequestClose={closeModal}
title="Heading 5"
title="With title icon"
titleIcon="warningFilled"
subtitle="Subtitle 1"
>
<p id="story-description">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus
fringilla tellus nec auctor gravida.</p>
</ModalDialog>
</Fragment>
);
}}
</Story>
</Preview>

### Without close button

<Preview>
<Story name="Without close button">
{() => {
const {isModalOpen, closeModal, openModal} = useModal();
return (
<Fragment>
<Button label="Open Modal" buttonType="primary" onClick={openModal} />
<ModalDialog
appElement="#root"
ariaDescribedby="story-description"
hasCloseButton={false}
isOpen={isModalOpen}
onRequestClose={closeModal}
title="Without close button"
>
<p id="story-description">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus
fringilla tellus nec auctor gravida.</p>
Expand Down

0 comments on commit 432bf14

Please sign in to comment.