feat: redesign the timeline as day columns with a bar per placement
This commit is contained in:
1 parent
4e50f23558
commit
e976342c09
8 files changed
+413
-190
No files matched your search
@@ -1,22 +1,26 @@
|
||||
import { Controller } from '@hotwired/stimulus'
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = [ 'today' ]
|
||||
static targets = [ 'scroller', 'today' ]
|
||||
|
||||
connect() {
|
||||
if (false === this.hasTodayTarget) {
|
||||
requestAnimationFrame(() => this.scrollToToday({ behavior: 'instant' }))
|
||||
}
|
||||
|
||||
// centres today's column; the house column stays in front of the left part
|
||||
scrollToToday({ behavior = 'smooth' } = {}) {
|
||||
if (false === this.hasScrollerTarget || false === this.hasTodayTarget) {
|
||||
return
|
||||
}
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
const containerRect = this.element.getBoundingClientRect()
|
||||
const todayRect = this.todayTarget.getBoundingClientRect()
|
||||
const scroller = this.scrollerTarget
|
||||
const scrollerRect = scroller.getBoundingClientRect()
|
||||
const todayRect = this.todayTarget.getBoundingClientRect()
|
||||
|
||||
const scrollLeft = todayRect.left - containerRect.left + this.element.scrollLeft
|
||||
const centered = scrollLeft - (this.element.clientWidth / 2) + (todayRect.width / 2)
|
||||
const maxScrollLeft = this.element.scrollWidth - this.element.clientWidth
|
||||
const scrollLeft = todayRect.left - scrollerRect.left + scroller.scrollLeft
|
||||
const centered = scrollLeft - (scroller.clientWidth / 2) + (todayRect.width / 2)
|
||||
const maxScrollLeft = scroller.scrollWidth - scroller.clientWidth
|
||||
|
||||
this.element.scrollLeft = Math.min(Math.max(0, centered), maxScrollLeft)
|
||||
})
|
||||
scroller.scrollTo({ left: Math.min(Math.max(0, centered), maxScrollLeft), behavior })
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,56 @@
|
||||
.scroll-container {
|
||||
/*
|
||||
* The timeline (administrative/assignment/timeline.html.twig): one grid per house with a fixed
|
||||
* house column and one column per day. The header, the background and every house share the
|
||||
* column template, so their columns line up; --timeline-days is set on .timeline.
|
||||
*/
|
||||
.timeline {
|
||||
--timeline-label: 11rem;
|
||||
--timeline-day: 1.75rem;
|
||||
|
||||
@apply overflow-auto;
|
||||
max-height: calc(100vh - 320px);
|
||||
max-height: calc(100vh - 260px);
|
||||
}
|
||||
|
||||
.timeline-grid {
|
||||
display: grid;
|
||||
grid-template-columns: var(--timeline-label) repeat(var(--timeline-days), var(--timeline-day));
|
||||
}
|
||||
|
||||
.timeline-background {
|
||||
@apply pointer-events-none absolute inset-0;
|
||||
grid-template-rows: 100%;
|
||||
}
|
||||
|
||||
.timeline-header {
|
||||
@apply sticky top-0 z-20 border-b-2 border-brand bg-white;
|
||||
}
|
||||
|
||||
.timeline-corner {
|
||||
@apply sticky left-0 z-10 border-r border-line bg-white;
|
||||
}
|
||||
|
||||
.timeline-house {
|
||||
@apply relative border-b border-line py-1;
|
||||
grid-auto-rows: 1.75rem;
|
||||
}
|
||||
|
||||
.timeline-house-label {
|
||||
@apply sticky left-0 z-10 -my-1 border-r border-line bg-white px-3 py-2;
|
||||
}
|
||||
|
||||
.timeline-bar {
|
||||
@apply relative z-[1] mx-px my-0.5 flex min-w-0 items-center gap-x-1 overflow-hidden whitespace-nowrap px-1.5 text-xs leading-none;
|
||||
}
|
||||
|
||||
/* the states differ in shape too, not only in colour: dashed, outlined, filled */
|
||||
.timeline-bar--open {
|
||||
@apply border border-dashed border-muted bg-white text-muted;
|
||||
}
|
||||
|
||||
.timeline-bar--pending {
|
||||
@apply border border-brand bg-brand-light text-brand-dark;
|
||||
}
|
||||
|
||||
.timeline-bar--staffed {
|
||||
@apply border border-emerald-800 bg-emerald-700 text-white;
|
||||
}
|
||||
Reference in new issue
Block a user