-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
173 additions
and
2 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import A11yDialog from 'a11y-dialog' | ||
|
||
const initDialog = (dialogElement) => { | ||
const dialog = new A11yDialog(dialogElement) | ||
|
||
// scroll lock | ||
dialog | ||
.on('show', () => document.body.classList.add('overflow-hidden')) | ||
.on('hide', () => document.body.classList.remove('overflow-hidden')) | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
const dialogs = document.querySelectorAll('.dialog-container') | ||
dialogs.forEach(initDialog) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.Dialog { | ||
// Make sure the dialog container and all its descendants are not visible and not focusable when it is hidden | ||
.dialog-container[aria-hidden='true'] { | ||
display: none; | ||
} | ||
|
||
.dialog-overlay, | ||
.dialog-box { | ||
@apply animate-fadeIn; | ||
|
||
@media (prefers-reduced-motion: reduce) { | ||
animation: none; | ||
} | ||
} | ||
|
||
.button-close { | ||
top: -2rem; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { IconCloseTemplate } from '../Icons/IconClose' | ||
|
||
export const DialogTemplate = ({ | ||
dialogId, | ||
dialogTrigger, | ||
ariaLabelledBy = '', | ||
content, | ||
overlayClose = 'true', | ||
dialogBoxClass = '', | ||
}) => { | ||
const template = ` | ||
<div class="Dialog"> | ||
<span data-a11y-dialog-show="${dialogId}">${ | ||
dialogTrigger ? dialogTrigger : 'Dialog trigger' | ||
}</span> | ||
<div id="${dialogId}" | ||
aria-labelledby="${ | ||
ariaLabelledBy ? ariaLabelledBy : '' | ||
}" aria-hidden='true' | ||
class="dialog-container fixed top-0 left-0 z-50 flex w-full h-full overflow-auto" > | ||
<div class="dialog-overlay ${ | ||
overlayClose ? 'data-a11y-dialog-hide' : '' | ||
} | ||
bg-gray-dark bg-opacity-90 fixed top-0 left-0 w-full h-full"></div> | ||
<div class="container m-auto"> | ||
<div role="document" class="dialog-box ${ | ||
dialogBoxClass ? dialogBoxClass : '' | ||
} relative m-auto bg-white"> | ||
<button data-a11y-dialog-hide aria-label="Close dialog" | ||
class="button-close absolute right-0 flex-shrink-0 text-white focus:outline-none focus:ring-2"> | ||
${IconCloseTemplate({})} | ||
</button> | ||
${content} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
` | ||
return template | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { DialogTemplate } from './Dialog' | ||
|
||
export default { | ||
title: 'Components/Dialog', | ||
excludeStories: /.*Data$/, | ||
decorators: [ | ||
(Story) => `<div id="storyRoot" class="absolute inset-0">${Story()}</div>`, | ||
], | ||
argTypes: { | ||
dialogId: { | ||
type: { name: 'string', required: true }, | ||
description: 'Unique dialog id (needed for instantiation)', | ||
}, | ||
dialogTrigger: { | ||
type: { name: 'string', required: true }, | ||
description: 'Custom trigger', | ||
}, | ||
ariaLabelledBy: { | ||
type: { name: 'string', required: false }, | ||
description: 'Id of a dialog title element to define an accessible name', | ||
}, | ||
content: { | ||
type: { name: 'string', required: true }, | ||
description: 'Dialog content', | ||
}, | ||
overlayClose: { | ||
type: { name: 'boolean', required: false }, | ||
description: | ||
'Determines whether clicking the overlay will close the dialog', | ||
table: { | ||
defaultValue: { summary: true }, | ||
}, | ||
}, | ||
dialogBoxClass: { | ||
type: { name: 'string', required: false }, | ||
description: 'Content wrapper class', | ||
}, | ||
}, | ||
parameters: { | ||
html: { | ||
root: '#storyRoot', | ||
}, | ||
viewMode: 'docs', | ||
docs: { | ||
inlineStories: false, | ||
iframeHeight: 1050, | ||
description: { | ||
component: | ||
'Accessible dialog (modal) window based on a11y-dialog library.', | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
export const DialogData = { | ||
dialogId: 'block-dialog', | ||
dialogTrigger: '<button>Custom trigger</button>', | ||
ariaLabelledBy: 'block-dialog-title', | ||
content: ` | ||
<div class="p-3 sm:p-5"> | ||
<h3 id="block-dialog-title">Dialog title</h3> | ||
<hr aria-hidden="true" class="bg-gray-light-mid w-full h-2px border-0 my-3"/> | ||
<div class="py-3 max-h-xl overflow-auto"> | ||
<p class="py-2">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> | ||
<p class="py-2">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> | ||
<p class="py-2">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> | ||
<p class="py-2">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> | ||
<p class="py-2">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> | ||
</div> | ||
<div class="my-3"> | ||
<a href="#" target="" rel="" class="group cursor-pointer -default underline text-theme-color can-hover:hover:text-theme-color-hover"> | ||
<span class="break-words">Explore</span> | ||
</a> | ||
</div> | ||
</div> | ||
`, | ||
dialogBoxClass: 'max-w-2xl', | ||
} | ||
|
||
export const Default = DialogTemplate.bind({}) | ||
Default.args = DialogData |