Stagger a rectangular panel's new dashboard by rail order
Changing dashboard kept the grid mounted, so every new tile rose at once. The grid is drawn afresh per dashboard and its tiles come in row by row: from below, top row first, for one further down the rail, and from above, bottom row first, for one further up, as a round panel's dashboards slide.
This commit is contained in:
@@ -393,6 +393,7 @@ export function DashboardView({
|
||||
editing,
|
||||
onDashboard,
|
||||
around,
|
||||
turned,
|
||||
}: {
|
||||
dashboard: Dashboard
|
||||
renderWidget?: (widget: WidgetDef) => React.ReactNode
|
||||
@@ -407,6 +408,9 @@ export function DashboardView({
|
||||
* previous (-1), and their names. */
|
||||
onDashboard?: (by: number) => void
|
||||
around?: [string | undefined, string | undefined]
|
||||
/** Which way along a panel's rail it was reached: down (1) or up (-1).
|
||||
* Its tiles come in from that side. */
|
||||
turned?: number
|
||||
}) {
|
||||
const all = widgetsOf(dashboard)
|
||||
const round = isRound(dashboard)
|
||||
@@ -424,15 +428,15 @@ export function DashboardView({
|
||||
)
|
||||
}
|
||||
|
||||
// Stacked, the arrangement becomes a reading order, so it follows the rows
|
||||
// the panel shows rather than the order widgets happened to be added in.
|
||||
const widgets = stacked
|
||||
? [...all].sort((a, b) => {
|
||||
const left = placement(a)
|
||||
const right = placement(b)
|
||||
return (left.y ?? 0) - (right.y ?? 0) || (left.x ?? 0) - (right.x ?? 0)
|
||||
})
|
||||
: all
|
||||
// In the rows the panel shows rather than the order widgets happened to be
|
||||
// added in: the reading order a stack follows, and the order tiles arrive
|
||||
// in. A grid places each one itself, and one nobody arranged has them all
|
||||
// at 0,0, which the sort leaves as they were.
|
||||
const widgets = [...all].sort((a, b) => {
|
||||
const left = placement(a)
|
||||
const right = placement(b)
|
||||
return (left.y ?? 0) - (right.y ?? 0) || (left.x ?? 0) - (right.x ?? 0)
|
||||
})
|
||||
const columns = columnsOf(dashboard)
|
||||
|
||||
const grid = (
|
||||
@@ -449,11 +453,15 @@ export function DashboardView({
|
||||
/>
|
||||
) : (
|
||||
<WidgetGrid
|
||||
// Drawn afresh for another dashboard, so its tiles arrive as a page
|
||||
// rather than all at once under a grid already shown.
|
||||
key={dashboard.name}
|
||||
dashboard={dashboard}
|
||||
widgets={widgets}
|
||||
columns={columns}
|
||||
stacked={stacked}
|
||||
rail={rail}
|
||||
from={turned !== undefined && turned < 0 ? -1 : 1}
|
||||
renderWidget={renderWidget}
|
||||
/>
|
||||
)}
|
||||
@@ -480,6 +488,7 @@ function WidgetGrid({
|
||||
columns,
|
||||
stacked,
|
||||
rail,
|
||||
from,
|
||||
renderWidget,
|
||||
}: {
|
||||
dashboard: Dashboard
|
||||
@@ -487,6 +496,8 @@ function WidgetGrid({
|
||||
columns: number
|
||||
stacked?: boolean
|
||||
rail?: boolean
|
||||
/** The side the tiles come in from: below (1) or above (-1). */
|
||||
from: number
|
||||
renderWidget?: (widget: WidgetDef) => React.ReactNode
|
||||
}) {
|
||||
const { Frame } = useUi()
|
||||
@@ -496,6 +507,7 @@ function WidgetGrid({
|
||||
className={cn("widget-grid", stacked && "widget-stacked")}
|
||||
data-placed={isPlaced(widgets) || undefined}
|
||||
variants={gridStagger}
|
||||
custom={from}
|
||||
initial="hidden"
|
||||
animate="visible"
|
||||
style={
|
||||
@@ -513,6 +525,7 @@ function WidgetGrid({
|
||||
style={widgetStyle(widget, columns)}
|
||||
className="widget-cell"
|
||||
variants={LOOK[look].enter}
|
||||
custom={from}
|
||||
transition={LOOK[look].spring}
|
||||
>
|
||||
{renderWidget ? (
|
||||
|
||||
Reference in New Issue
Block a user