feat: adopt E&P corporate design in admin
This commit is contained in:
1 parent
55378b2bbc
commit
c660bd68de
36 files changed
+866
-544
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import { Controller } from '@hotwired/stimulus'
|
||||
|
||||
/*
|
||||
* The sidebar as a drawer on small screens: a modal <dialog> (target "dialog"), so focus stays inside
|
||||
* and Escape closes it. A click on the dimmed page beside it closes it too, and so does widening the
|
||||
* window until the sidebar shows (lg).
|
||||
*/
|
||||
export default class extends Controller {
|
||||
static targets = ['dialog']
|
||||
|
||||
connect () {
|
||||
this.wide = window.matchMedia('(min-width: 64rem)')
|
||||
this.onWide = (event) => event.matches && this.close()
|
||||
this.wide.addEventListener('change', this.onWide)
|
||||
}
|
||||
|
||||
disconnect () {
|
||||
this.wide.removeEventListener('change', this.onWide)
|
||||
}
|
||||
|
||||
open () {
|
||||
this.dialogTarget.showModal()
|
||||
}
|
||||
|
||||
close () {
|
||||
this.dialogTarget.close()
|
||||
}
|
||||
|
||||
// a click on the dialog element itself, not on its content, is a click on the backdrop
|
||||
closeOnBackdrop (event) {
|
||||
if (event.target === this.dialogTarget) {
|
||||
this.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
import { Controller } from '@hotwired/stimulus'
|
||||
|
||||
/*
|
||||
* A small menu behind a "⋯" button: the button (menu#toggle) opens the panel (target "panel") below
|
||||
* itself. The panel is positioned fixed, so a scrolling container can't cut it off. Escape, a click
|
||||
* outside or a click on one of its items closes it; arrow keys move between the items. Scrolling or
|
||||
* resizing closes it too: a fixed panel would stay put while its row moves away (a table swiped
|
||||
* sideways on a phone).
|
||||
*/
|
||||
export default class extends Controller {
|
||||
static targets = ['button', 'panel']
|
||||
|
||||
connect () {
|
||||
this.onOutside = (event) => {
|
||||
if (!this.element.contains(event.target)) {
|
||||
this.close()
|
||||
}
|
||||
}
|
||||
this.onKey = (event) => this.key(event)
|
||||
this.onScroll = (event) => {
|
||||
if (!this.panelTarget.contains(event.target)) {
|
||||
this.close()
|
||||
}
|
||||
}
|
||||
this.onResize = () => this.close()
|
||||
}
|
||||
|
||||
disconnect () {
|
||||
this.close()
|
||||
}
|
||||
|
||||
toggle (event) {
|
||||
event.stopPropagation()
|
||||
this.panelTarget.hidden ? this.open() : this.close()
|
||||
}
|
||||
|
||||
open () {
|
||||
const box = this.buttonTarget.getBoundingClientRect()
|
||||
const panel = this.panelTarget
|
||||
panel.hidden = false
|
||||
// below the button, aligned to its right edge, and inside the window
|
||||
const left = Math.max(8, Math.min(box.right - panel.offsetWidth, window.innerWidth - panel.offsetWidth - 8))
|
||||
const below = box.bottom + 4 + panel.offsetHeight <= window.innerHeight
|
||||
panel.style.left = `${left}px`
|
||||
panel.style.top = `${below ? box.bottom + 4 : box.top - panel.offsetHeight - 4}px`
|
||||
this.buttonTarget.setAttribute('aria-expanded', 'true')
|
||||
document.addEventListener('click', this.onOutside, true)
|
||||
document.addEventListener('keydown', this.onKey)
|
||||
// capture: scroll events don't bubble, and the scrolling box may be any ancestor
|
||||
document.addEventListener('scroll', this.onScroll, true)
|
||||
window.addEventListener('resize', this.onResize)
|
||||
this.items()[0]?.focus({ preventScroll: true })
|
||||
}
|
||||
|
||||
close () {
|
||||
if (this.panelTarget.hidden) {
|
||||
return
|
||||
}
|
||||
this.panelTarget.hidden = true
|
||||
this.buttonTarget.setAttribute('aria-expanded', 'false')
|
||||
document.removeEventListener('click', this.onOutside, true)
|
||||
document.removeEventListener('keydown', this.onKey)
|
||||
document.removeEventListener('scroll', this.onScroll, true)
|
||||
window.removeEventListener('resize', this.onResize)
|
||||
}
|
||||
|
||||
// an item was chosen: it does its own work (htmx, link), the menu only closes
|
||||
choose () {
|
||||
this.close()
|
||||
}
|
||||
|
||||
key (event) {
|
||||
const items = this.items()
|
||||
const index = items.indexOf(document.activeElement)
|
||||
if (event.key === 'Escape') {
|
||||
event.stopPropagation()
|
||||
this.close()
|
||||
this.buttonTarget.focus()
|
||||
} else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
||||
event.preventDefault()
|
||||
const next = (index + (event.key === 'ArrowDown' ? 1 : -1) + items.length) % items.length
|
||||
items[next]?.focus()
|
||||
}
|
||||
}
|
||||
|
||||
items () {
|
||||
return [...this.panelTarget.querySelectorAll('a, button:not([disabled])')]
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { Controller } from '@hotwired/stimulus'
|
||||
|
||||
export default class extends Controller {
|
||||
static outlets = [ 'mobilenav' ]
|
||||
static classes = [ 'closed' ]
|
||||
|
||||
trigger({ params: { mode } }) {
|
||||
this.mobilenavOutlet.toggle(mode)
|
||||
}
|
||||
|
||||
toggle(mode) {
|
||||
// Add animation classes only now to avoid fouc
|
||||
this.element.classList.add('transition-transform', 'duration-300')
|
||||
this.element.classList.toggle(this.closedClass, 'close' === mode)
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
import { Controller } from '@hotwired/stimulus'
|
||||
|
||||
export default class extends Controller {
|
||||
|
||||
static classes = ['closed', 'iconClosed', 'iconExpanded']
|
||||
static targets = ['submenu', 'button', 'icon']
|
||||
static values = { expanded: Boolean }
|
||||
|
||||
toggleSubmenu() {
|
||||
this.expandedValue = !this.expandedValue
|
||||
}
|
||||
|
||||
expandedValueChanged(expanded) {
|
||||
this.submenuTarget.classList.toggle(this.closedClass, false === expanded)
|
||||
if (false === this.hasButtonTarget) {
|
||||
return
|
||||
}
|
||||
this.buttonTarget.setAttribute('aria-expanded', expanded)
|
||||
if (false === this.hasIconTarget) {
|
||||
return
|
||||
}
|
||||
if (true === expanded) {
|
||||
this.iconTarget.classList.add(...this.iconExpandedClasses)
|
||||
this.iconTarget.classList.remove(...this.iconClosedClasses)
|
||||
} else {
|
||||
this.iconTarget.classList.add(...this.iconClosedClasses)
|
||||
this.iconTarget.classList.remove(...this.iconExpandedClasses)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user