-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Theming - Spectrum Provider (#1582)
In this PR: - First pass of mapping Spectrum dark theme variables to DH theme variables - Added Spectrum components that are being used by DH UI to the styleguide - Added some navigation to styleguide - Added a Playwright config for Firefox to fix an issue where no pointers were detected in `'(any-pointer: fine)'` media queries resolves #1543
- Loading branch information
Showing
45 changed files
with
1,330 additions
and
165 deletions.
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.