Add the snackbar, badges, rich tooltips, alerts, stats and empty states
tests / lint (push) Successful in 1m3s
tests / feature (8.4) (push) Failing after 1m5s
tests / feature (8.5) (push) Failing after 1m4s
tests / browser (chrome, chromium) (push) Failing after 1m5s
tests / browser (firefox, firefox) (push) Failing after 1m1s
tests / browser (safari, webkit) (push) Failing after 1m1s
tests / lint (push) Successful in 1m3s
tests / feature (8.4) (push) Failing after 1m5s
tests / feature (8.5) (push) Failing after 1m4s
tests / browser (chrome, chromium) (push) Failing after 1m5s
tests / browser (firefox, firefox) (push) Failing after 1m1s
tests / browser (safari, webkit) (push) Failing after 1m1s
<x-toast> hosts the snackbar queue for the Toasts concern and window.materialToast(), one at a time, paused on hover and focus, with an optional action; it listens from the moment its script loads, so a toast dispatched before Alpine starts is shown rather than lost. <x-badge> is M3's dot and count, plus a tonal or outlined status label; <x-rich-tooltip> is transient or persistent; <x-alert>, <x-stat> and <x-empty-state> are built from M3's parts. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V9NnLxnPp8vaaurb3Z1MFy
This commit is contained in:
co-authored by
Claude Opus 5
parent
cd64f4f371
commit
648ad8efaf
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* `materialRichTooltip`: shows an `<x-rich-tooltip>`.
|
||||
*
|
||||
* Transient (the default): like a plain tooltip — after a short hover on a pointer that can hover,
|
||||
* at once on keyboard focus, and it stays while the pointer moves onto the bubble to reach its
|
||||
* actions. Persistent: a press on the trigger opens it as a light-dismiss popover.
|
||||
*/
|
||||
const HOVER_DELAY_MS = 500
|
||||
const LEAVE_GRACE_MS = 200
|
||||
|
||||
document.addEventListener('alpine:init', () => {
|
||||
window.Alpine.data('materialRichTooltip', (persistent = false) => ({
|
||||
timer: null,
|
||||
|
||||
init() {
|
||||
const bubble = this.$refs.bubble
|
||||
const wrapper = this.$el
|
||||
const open = () => bubble.matches(':popover-open')
|
||||
|
||||
if (persistent) {
|
||||
wrapper.addEventListener('click', (event) => {
|
||||
if (bubble.contains(event.target)) {
|
||||
return
|
||||
}
|
||||
|
||||
open() ? bubble.hidePopover() : bubble.showPopover()
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const show = (delay) => {
|
||||
clearTimeout(this.timer)
|
||||
this.timer = setTimeout(() => !open() && bubble.showPopover(), delay)
|
||||
}
|
||||
|
||||
const hide = (delay = 0) => {
|
||||
clearTimeout(this.timer)
|
||||
this.timer = setTimeout(() => open() && bubble.hidePopover(), delay)
|
||||
}
|
||||
|
||||
wrapper.addEventListener('pointerenter', (event) => event.pointerType === 'mouse' && show(HOVER_DELAY_MS))
|
||||
wrapper.addEventListener('pointerleave', () => hide(LEAVE_GRACE_MS))
|
||||
wrapper.addEventListener('focusin', (event) => event.target.matches(':focus-visible') && show(0))
|
||||
wrapper.addEventListener('focusout', (event) => !wrapper.contains(event.relatedTarget) && hide())
|
||||
document.addEventListener('keydown', (event) => event.key === 'Escape' && hide())
|
||||
},
|
||||
|
||||
destroy() {
|
||||
clearTimeout(this.timer)
|
||||
},
|
||||
}))
|
||||
})
|
||||
Reference in New Issue
Block a user