-
Notifications
You must be signed in to change notification settings - Fork 42
Modal for links #389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SharonStrats
wants to merge
13
commits into
main
Choose a base branch
from
modal-for-links
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Modal for links #389
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
eefe66e
added modals
SharonStrats 5e2a431
added styles for modal
SharonStrats f947e1a
exported modals
SharonStrats ccbd029
merged main
SharonStrats e05ffe1
changed style to new way
SharonStrats e5b4110
avoid doc-wide .modal lookup
SharonStrats 1b682fc
improve name and return modal
SharonStrats 6a798d8
Apply suggestions from code review
SharonStrats fabb939
update
SharonStrats da4fe11
lint fix
SharonStrats 7eb175b
accessibility
SharonStrats 9426f6c
tests
SharonStrats a99b5ff
added stories
SharonStrats File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,95 @@ | ||
| import { | ||
| ModalWidgetStyleOptions, | ||
| modalStyles, | ||
| getModalStyle, | ||
| getModalContentStyle, | ||
| getModalCloseStyle | ||
| } from './modalsStyle' | ||
| import { getClasses } from '../jss' | ||
|
|
||
| export type ListItem = { | ||
| label: string, | ||
| link: string | ||
| } | ||
|
|
||
| // Two functions that need to be implemented to use the modal | ||
| // When the user clicks the button, open the modal | ||
|
SharonStrats marked this conversation as resolved.
Outdated
|
||
| /* Click handler on the button to display it. | ||
| btn.onclick = function() { | ||
| modal.style.display = "block"; | ||
| } | ||
|
|
||
| // When the user clicks anywhere outside of the modal, close it | ||
|
SharonStrats marked this conversation as resolved.
Outdated
|
||
| Window click handler so that the modal will close | ||
| even if the user doesn't click close | ||
|
SharonStrats marked this conversation as resolved.
Outdated
|
||
| window.onclick = function(event) { | ||
| if (event.target == modal) { | ||
| modal.style.display = "none"; | ||
| } */ | ||
| const closeClickHandler = () => { | ||
| const modal: HTMLDivElement | null = document.querySelector('.modal') | ||
| if (modal) { | ||
| modal.style.display = 'none' | ||
| } | ||
| } | ||
|
SharonStrats marked this conversation as resolved.
Outdated
|
||
|
|
||
| const createModal = (dom: HTMLDocument, options: ModalWidgetStyleOptions) => { | ||
| const modal = dom.createElement('div') | ||
| const style = getModalStyle(options) | ||
| const { classes } = getClasses(dom.head, { | ||
| modal: style | ||
| }) | ||
| modal.classList.add(classes.modal) | ||
| return modal | ||
| } | ||
|
|
||
| const createModalContent = (dom: HTMLDocument) => { | ||
| const modalContent: HTMLDivElement = dom.createElement('div') | ||
| const style = getModalContentStyle() | ||
| const { classes } = getClasses(dom.head, { | ||
| modalContent: style | ||
| }) | ||
| modalContent.classList.add(classes.modalContent) | ||
| return modalContent | ||
| } | ||
|
|
||
| const createCloseButton = (dom: HTMLDocument) => { | ||
| const closeButton: HTMLSpanElement = dom.createElement('span') | ||
| closeButton.addEventListener('click', closeClickHandler) | ||
| const style = getModalCloseStyle() | ||
| const { classes } = getClasses(dom.head, { | ||
| close: style | ||
| }) | ||
| closeButton.classList.add(classes.close) | ||
| return closeButton | ||
|
SharonStrats marked this conversation as resolved.
Outdated
SharonStrats marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| const createListItems = (dom: HTMLDocument, list: ListItem) => { | ||
| const li:HTMLLIElement = dom.createElement('li') | ||
| li.setAttribute('style', modalStyles.listItemStyle) | ||
| const link: HTMLAnchorElement = dom.createElement('a') | ||
| link.setAttribute('style', modalStyles.anchorStyle) | ||
| link.href = list.link | ||
| link.innerHTML = list.label | ||
|
SharonStrats marked this conversation as resolved.
Outdated
|
||
| li.appendChild(link) | ||
| return li | ||
| } | ||
|
|
||
| const createUnOrderedList = (dom: HTMLDocument, listOfLinks: ListItem[]) => { | ||
| const ul: HTMLUListElement = dom.createElement('ul') | ||
| ul.setAttribute('style', modalStyles.unorderedListStyle) | ||
| listOfLinks.forEach(list => { | ||
| const li = createListItems(dom, list) | ||
| ul.appendChild(li) | ||
| }) | ||
| return ul | ||
|
SharonStrats marked this conversation as resolved.
Outdated
|
||
| } | ||
| export const createWindow = (dom: HTMLDocument, listOfLinks: ListItem[], options: ModalWidgetStyleOptions) => { | ||
| const modal = createModal(dom, options) | ||
|
SharonStrats marked this conversation as resolved.
Outdated
|
||
| const modalContent = createModalContent(dom) | ||
| const closeButton = createCloseButton(dom) | ||
| const ul = createUnOrderedList(dom, listOfLinks) | ||
| modalContent.appendChild(closeButton) | ||
| modalContent.appendChild(ul) | ||
| modal.appendChild(modalContent) | ||
| } | ||
|
SharonStrats marked this conversation as resolved.
Outdated
|
||
This file contains hidden or 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,72 @@ | ||
| /** | ||
| * Get the button style, based on options. | ||
| * See https://design.inrupt.com/atomic-core/?cat=Atoms#Buttons | ||
|
SharonStrats marked this conversation as resolved.
Outdated
|
||
| */ | ||
| export type ModalWidgetStyleOptions = { | ||
| topPosition?: string, | ||
| leftPosition?: string, | ||
| withGreyedBackground?: boolean | ||
| } | ||
|
|
||
| export const modalStyles = { | ||
| unorderedListStyle: 'padding: 0 .2em;', | ||
| listItemStyle: 'list-style: none; box-shadow: 1px 1px 1px 1px #888888; padding: .5em', | ||
| anchorStyle: 'text-decoration: none' | ||
| } | ||
|
|
||
| export const getModalStyle = (options: ModalWidgetStyleOptions = {}) => { | ||
| const topPosition = (options.topPosition) ? options.topPosition : '50px' | ||
| const leftPosition = (options.leftPosition) ? options.leftPosition : '50px' | ||
|
|
||
| if (options.withGreyedBackground) { | ||
| return { | ||
| display: 'none', | ||
| position: 'fixed', | ||
| 'z-index': '1', | ||
| overflow: 'auto', /* Enable scroll if needed */ | ||
| 'background-color': 'rgba(0,0,0,0.4)', /* Black w/ opacity */ | ||
| 'padding-top': '100px', | ||
| left: '0', | ||
| top: '0', | ||
| width: '100%', | ||
| height: '100%' | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| display: 'none', | ||
| position: 'fixed', | ||
| 'z-index': '1', | ||
| top: `${topPosition}`, | ||
| left: `${leftPosition}`, | ||
| overflow: 'auto', /* Enable scroll if needed */ | ||
| 'background-color': 'rgba(0,0,0,0.4)' /* Black w/ opacity */ | ||
| } | ||
| } | ||
|
|
||
| export const getModalContentStyle = () => { | ||
| return { | ||
| display: 'flex', | ||
| 'flex-direction': 'column', | ||
| 'background-color': '#fefefe' | ||
| } | ||
| } | ||
|
|
||
| export const getModalCloseStyle = () => { | ||
| return { | ||
| color: '#aaaaaa', | ||
| 'align-self': 'flex-end', | ||
| 'font-size': '20px', | ||
| 'font-weight': 'bold', | ||
| 'margin-right': '.2em', | ||
| 'margin-top': '.2em', | ||
| '&:hover': { | ||
| 'text-decoration': 'none', | ||
| cursor: 'pointer' | ||
| }, | ||
| '&:focus': { | ||
| 'text-decoration': 'none', | ||
| cursor: 'pointer' | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.