-
Notifications
You must be signed in to change notification settings - Fork 32
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
feat: Theming - Spectrum Provider #1582
Merged
bmingles
merged 17 commits into
deephaven:main
from
bmingles:1543-theming-spectrum-provider
Oct 24, 2023
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
d74b335
Spectrum theme provider
bmingles 0a699dc
Spectrum theme + styleguide
bmingles 876ef5d
Removed unused code
bmingles 62f517f
Spectrum samples
bmingles 730dbe5
Spectrum samples
bmingles 095209e
Added a menu for styleguide
bmingles 9085317
Updated comments and added transition
bmingles 9147e5a
Theme overrides + deleted unused modules
bmingles e773f30
Updated snapshots
bmingles 5953e2c
Fixed failing tests
bmingles 9779f4d
Fixed failing test
bmingles 63fa1f3
Playwright fixes
bmingles 8537f41
Added mocks for theme files
bmingles f3bdbf4
Moved themes outside of Spectrum provider
bmingles c0b9c2b
Only set preload data after themes loaded
bmingles b4be075
ThemProvider now always passes children
bmingles 870156b
Updated comment
bmingles 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = 'mock-theme-dark-components'; |
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 @@ | ||
module.exports = 'mock-theme-dark-palette'; |
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 @@ | ||
module.exports = 'mock-theme-dark-semantic-editor'; |
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 @@ | ||
module.exports = 'mock-theme-dark-semantic-grid'; |
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 @@ | ||
module.exports = 'mock-theme-dark-semantic'; |
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 @@ | ||
module.exports = 'mock-theme-light-palette'; |
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,3 @@ | ||
module.exports = { | ||
'dh-spectrum-alias': 'mock-dh-spectrum-alias', | ||
}; |
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,3 @@ | ||
module.exports = { | ||
'dh-spectrum-overrides': 'mock-dh-spectrum-overrides', | ||
}; |
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,3 @@ | ||
module.exports = { | ||
'dh-spectrum-palette': 'mock-dh-spectrum-palette', | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
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
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 @@ | ||
/* | ||
* GotoTopButton is only visible if user has scrolled down. Visibility attribute | ||
* can't really make use of CSS transitions, so we use opacity instead. Including | ||
* visibility for accessibility reasons. | ||
*/ | ||
.goto-top-button { | ||
visibility: visible; | ||
opacity: 1; | ||
transition: | ||
opacity 300ms, | ||
visibility 0s linear 0s; | ||
} | ||
html:not([data-scroll='true']) .goto-top-button { | ||
visibility: hidden; | ||
opacity: 0; | ||
transition: | ||
opacity 300ms, | ||
visibility 0s linear 300ms; | ||
} |
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,48 @@ | ||
import React, { useCallback, useEffect } from 'react'; | ||
import { Button, Icon } from '@adobe/react-spectrum'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { vsChevronUp } from '@deephaven/icons'; | ||
import './GotoTopButton.css'; | ||
|
||
/** | ||
* Button that scrolls to top of styleguide and clears location hash. | ||
*/ | ||
export function GotoTopButton(): JSX.Element { | ||
const gotoTop = useCallback(() => { | ||
window.scrollTo({ | ||
top: 0, | ||
behavior: 'smooth', | ||
}); | ||
|
||
// Small delay to give scrolling a chance to move smoothly to top | ||
setTimeout(() => { | ||
window.location.hash = ''; | ||
}, 500); | ||
}, []); | ||
|
||
// Set data-scroll="true" on the html element when the user scrolls down below | ||
// 120px. CSS uses this to only show the button when the user has scrolled. | ||
useEffect(() => { | ||
function onScroll() { | ||
document.documentElement.dataset.scroll = String(window.scrollY > 120); | ||
} | ||
document.addEventListener('scroll', onScroll, { passive: true }); | ||
return () => { | ||
document.removeEventListener('scroll', onScroll); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<Button | ||
UNSAFE_className="goto-top-button" | ||
variant="accent" | ||
onPress={gotoTop} | ||
> | ||
<Icon> | ||
<FontAwesomeIcon icon={vsChevronUp} /> | ||
</Icon> | ||
</Button> | ||
); | ||
} | ||
|
||
export default GotoTopButton; |
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,125 @@ | ||
import React, { Key, useCallback, useEffect, useState } from 'react'; | ||
import { | ||
ActionButton, | ||
Icon, | ||
Item, | ||
Menu, | ||
MenuTrigger, | ||
Section, | ||
} from '@adobe/react-spectrum'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { vsMenu } from '@deephaven/icons'; | ||
import { | ||
MENU_CATEGORY_DATA_ATTRIBUTE, | ||
NO_MENU_DATA_ATTRIBUTE, | ||
SPECTRUM_COMPONENT_SAMPLES_ID, | ||
} from './constants'; | ||
|
||
interface Link { | ||
id: string; | ||
label: string; | ||
} | ||
type LinkCategory = { category: string; items: Link[] }; | ||
|
||
/** | ||
* Metadata only div that provides a MENU_CATEGORY_DATA_ATTRIBUTE defining a | ||
* menu category. These will be queried by the SamplesMenu component to build | ||
* up the menu sections. | ||
*/ | ||
export function SampleMenuCategory({ | ||
'data-menu-category': dataMenuCategory, | ||
}: Record<typeof MENU_CATEGORY_DATA_ATTRIBUTE, string>): JSX.Element { | ||
return <div data-menu-category={dataMenuCategory} />; | ||
} | ||
|
||
/** | ||
* Creates a menu from h2, h3 elements on the page and assigns them each an id | ||
* for hash navigation purposes. If the current hash matches one of the ids, it | ||
* will scroll to that element. This handles the initial page load scenario. | ||
* Menu sections are identified by divs with MENU_CATEGORY_DATA_ATTRIBUTE | ||
* attributes. | ||
*/ | ||
export function SamplesMenu(): JSX.Element { | ||
const [links, setLinks] = useState<LinkCategory[]>([]); | ||
|
||
useEffect(() => { | ||
let currentCategory: LinkCategory = { | ||
category: '', | ||
items: [], | ||
}; | ||
const categories: LinkCategory[] = [currentCategory]; | ||
|
||
const spectrumComponentsSamples = document.querySelector( | ||
`#${SPECTRUM_COMPONENT_SAMPLES_ID}` | ||
); | ||
|
||
document | ||
.querySelectorAll(`h2,h3,[${MENU_CATEGORY_DATA_ATTRIBUTE}]`) | ||
.forEach(el => { | ||
if (el.textContent == null || el.hasAttribute(NO_MENU_DATA_ATTRIBUTE)) { | ||
return; | ||
} | ||
|
||
// Create a new category section | ||
if (el.hasAttribute(MENU_CATEGORY_DATA_ATTRIBUTE)) { | ||
currentCategory = { | ||
category: el.getAttribute(MENU_CATEGORY_DATA_ATTRIBUTE) ?? '', | ||
items: [], | ||
}; | ||
categories.push(currentCategory); | ||
|
||
return; | ||
} | ||
|
||
const id = `${ | ||
spectrumComponentsSamples?.contains(el) === true ? 'spectrum-' : '' | ||
}${el.textContent}` | ||
.toLowerCase() | ||
.replace(/\s/g, '-'); | ||
|
||
// eslint-disable-next-line no-param-reassign | ||
el.id = id; | ||
|
||
currentCategory.items.push({ id, label: el.textContent }); | ||
|
||
if (`#${id}` === window.location.hash) { | ||
el.scrollIntoView(); | ||
} | ||
}); | ||
|
||
setLinks(categories); | ||
}, []); | ||
|
||
const onAction = useCallback((key: Key) => { | ||
const id = String(key); | ||
const el = document.getElementById(id); | ||
el?.scrollIntoView({ | ||
behavior: 'smooth', | ||
}); | ||
|
||
// Keep hash in sync for page reloads, but give some delay to allow smooth | ||
// scrolling above | ||
setTimeout(() => { | ||
window.location.hash = id; | ||
}, 500); | ||
}, []); | ||
|
||
return ( | ||
<MenuTrigger> | ||
<ActionButton> | ||
<Icon> | ||
<FontAwesomeIcon icon={vsMenu} /> | ||
</Icon> | ||
</ActionButton> | ||
<Menu items={links} onAction={onAction}> | ||
{({ category, items }) => ( | ||
<Section key={category} items={items} title={category}> | ||
{({ id, label }) => <Item key={id}>{label}</Item>} | ||
</Section> | ||
)} | ||
</Menu> | ||
</MenuTrigger> | ||
); | ||
} | ||
|
||
export default SamplesMenu; |
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.
Why 120px? Name the constant to give it some more context.
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.
It's arbitrary. It just "felt" right. I'll name it in next PR