-
Notifications
You must be signed in to change notification settings - Fork 36
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
DOP-5093: make tabs selectors interactive on offline builds #1325
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bc3d67b
make tabs selectors interactive on offline builds
seungpark da7a419
update snapshots
seungpark cee2f75
Merge branch 'main' into DOP-5093
seungpark cc17a60
fix margin
seungpark 676d668
add conditional for new props (in effort to not trigger smartling re …
seungpark c063d62
update snapshots
seungpark 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 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
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,17 @@ | ||
import bindTabUI from './tabs'; | ||
import updateSidenavHeight from './sidenav'; | ||
import bindTabsSelectorsUI from './tabs-selectors'; | ||
const OFFLINE_UI_CLASSNAME = 'snooty-offline-ui'; | ||
|
||
const getScript = ({ key, fn }) => ( | ||
<script | ||
className={OFFLINE_UI_CLASSNAME} | ||
key={key} | ||
type="text/javascript" | ||
dangerouslySetInnerHTML={{ __html: `!${fn}()` }} | ||
/> | ||
); | ||
|
||
export const OFFLINE_HEAD_SCRIPTS = [bindTabUI, updateSidenavHeight, bindTabsSelectorsUI].map((fn, idx) => | ||
getScript({ key: `offline-docs-ui-${idx}`, fn }) | ||
); |
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,72 @@ | ||
/** | ||
* Tabs selectors are singular per page | ||
* For offline builds, refer to one ID from TabSelectors component | ||
* | ||
*/ | ||
|
||
function bindTabsSelectorsUI() { | ||
function onChoiceClick({ e, choices, tabsComponents, menu, button }) { | ||
// get the data-value attribute | ||
const tabName = e.currentTarget.getAttribute('data-value'); | ||
|
||
// set choice selected for styling css | ||
for (const choice of choices) { | ||
choice.setAttribute('selected', false); | ||
} | ||
e.currentTarget.setAttribute('selected', true); | ||
|
||
// handle the tabsComponents | ||
for (const tabsComponent of tabsComponents) { | ||
// find the tab within each tabsComponent | ||
const tabContent = tabsComponent.querySelector(`[data-value=${tabName}`); | ||
if (!tabContent) { | ||
continue; | ||
} | ||
// if it exists, hide all other tabs, and show this tab | ||
for (const tabPanel of tabsComponent.querySelectorAll('[role=tabpanel]')) { | ||
tabPanel.style.display = tabPanel.contains(tabContent) ? 'block' : 'none'; | ||
} | ||
} | ||
const buttonChildren = button.querySelectorAll('div'); | ||
const selectTextelm = buttonChildren[buttonChildren.length - 1]; | ||
selectTextelm.innerText = e.currentTarget.getAttribute('data-text'); | ||
|
||
// finally hide the menu | ||
menu.setAttribute('hidden', true); | ||
} | ||
|
||
const onContentLoaded = () => { | ||
const selectPortal = document.querySelector('#offline-select'); | ||
|
||
// bind menu opening to select component | ||
const button = selectPortal?.querySelector('button'); | ||
const menu = selectPortal?.querySelector('.offline-select-menu'); | ||
button?.addEventListener('click', () => { | ||
menu.toggleAttribute('hidden'); | ||
}); | ||
|
||
// bind choices selection to showing tabbed content | ||
const choices = menu?.querySelectorAll('.offline-select-choice') ?? []; | ||
const tabsComponents = document.querySelectorAll('.offline-tabs.drivers'); | ||
for (const choice of choices) { | ||
choice?.addEventListener('click', (e) => { | ||
onChoiceClick({ e, choices, tabsComponents, menu, button }); | ||
}); | ||
} | ||
|
||
// select the first choice on load | ||
// TODO: possibly add to local storage and store info here | ||
choices[0].click(); | ||
|
||
// bind document click to close menu | ||
document.addEventListener('click', (e) => { | ||
if (!selectPortal.contains(e.target)) { | ||
menu.setAttribute('hidden', true); | ||
} | ||
}); | ||
}; | ||
|
||
document.addEventListener('DOMContentLoaded', onContentLoaded, false); | ||
} | ||
|
||
export default bindTabsSelectorsUI; |
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor change to prevent image optimization from offline builds. will put in a separate PR if preferred!