Round dashboards: shape and ring, the ring drawn and turned in every look, Knob preset and face guide in the editor
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
f067fb60d4
commit
8b8cb5cda9
@@ -6,6 +6,7 @@ import { type CSSProperties, useEffect, useRef, useState } from "react"
|
||||
import {
|
||||
GridLayout,
|
||||
type Layout,
|
||||
noCompactor,
|
||||
type Position,
|
||||
setTransform,
|
||||
} from "react-grid-layout"
|
||||
@@ -48,7 +49,10 @@ import {
|
||||
DashboardView,
|
||||
GRID_GAP,
|
||||
isPlaced,
|
||||
isRound,
|
||||
offFace,
|
||||
placement,
|
||||
ringOf,
|
||||
rowHeightOf,
|
||||
rowsOf,
|
||||
widgetsOf,
|
||||
@@ -63,6 +67,7 @@ import {
|
||||
usePublishDashboard,
|
||||
useSaveDashboard,
|
||||
} from "./queries"
|
||||
import { RoundFace } from "./RingWidget"
|
||||
import { PaletteProvider } from "./settings"
|
||||
import { useUi } from "./ui"
|
||||
import { showTitle } from "./ui/core/config"
|
||||
@@ -234,8 +239,10 @@ export function DashboardEditor({
|
||||
const [settingsOpen, setSettingsOpen] = useState(false)
|
||||
const [paletteOpen, setPaletteOpen] = useState(false)
|
||||
// A phone reads the dashboard rather than arranges it, so the grid library
|
||||
// never mounts there. See DESIGN-GUIDELINES.md → Responsive.
|
||||
const stacked = useIsMobile()
|
||||
// never mounts there. See DESIGN-GUIDELINES.md → Responsive. A round one is
|
||||
// the exception: a knob's face is about a phone's width as it is.
|
||||
const round = isRound(draft)
|
||||
const stacked = useIsMobile() && !round
|
||||
// The dashboard's own appearance, on the surface only: the shell around the
|
||||
// canvas stays whatever the person editing chose for the app. Non-stacked,
|
||||
// `CanvasSurface` states it on the canvas box itself.
|
||||
@@ -310,6 +317,11 @@ export function DashboardEditor({
|
||||
const hasDraft = Boolean(dashboard.has_draft)
|
||||
const columns = columnsOf(draft)
|
||||
const widgets = widgetsOf(draft)
|
||||
// The ring is drawn along a round face's edge and takes no cell.
|
||||
const ring = ringOf(draft)
|
||||
const placedWidgets = ring
|
||||
? widgets.filter((widget) => widget !== ring)
|
||||
: widgets
|
||||
|
||||
const updateWidgets = (next: WidgetDef[]) => {
|
||||
commit({ ...draft, widgets: next })
|
||||
@@ -380,6 +392,7 @@ export function DashboardEditor({
|
||||
dashboards={railDashboards}
|
||||
current={draft.name}
|
||||
horizontal={stacked}
|
||||
dots={round}
|
||||
// Editing one dashboard of a panel and editing its neighbour are the
|
||||
// same job, so the rail keeps whichever mode this one is in.
|
||||
linkFor={(name) => ({
|
||||
@@ -393,13 +406,15 @@ export function DashboardEditor({
|
||||
// the rail's column when the panel carries one.
|
||||
const area = areaOf(draft, hasRail)
|
||||
|
||||
const layout = layoutOf(widgets, columns)
|
||||
const layout = layoutOf(placedWidgets, columns)
|
||||
const rows = rowsOf(draft, hasRail)
|
||||
|
||||
// maxRows below only constrains a *drag*. A stored placement is corrected
|
||||
// against `cols` and nothing else, so a canvas that shrank leaves whatever
|
||||
// now falls past its bottom edge drawn under the clip.
|
||||
const clipped = layout.filter((item) => item.y + item.h > rows)
|
||||
// A round face cuts the corners off the grid it is laid out in.
|
||||
const cornered = offFace(draft, layout)
|
||||
|
||||
/** Store what the grid ended up doing, unless it did nothing. */
|
||||
const applyLayout = (next: Layout) => {
|
||||
@@ -428,7 +443,7 @@ export function DashboardEditor({
|
||||
* room above it — it has to move sideways. */
|
||||
const reflow = () => {
|
||||
const at = new Map(layout.map((item) => [item.i, item]))
|
||||
const ordered = [...widgets].sort((a, b) => {
|
||||
const ordered = [...placedWidgets].sort((a, b) => {
|
||||
const left = at.get(a.id)
|
||||
const right = at.get(b.id)
|
||||
return (
|
||||
@@ -504,7 +519,22 @@ export function DashboardEditor({
|
||||
) : null}
|
||||
</div>
|
||||
) : (
|
||||
<CanvasSurface dashboard={draft} dots={edit} rail={rail}>
|
||||
<CanvasSurface
|
||||
dashboard={draft}
|
||||
dots={edit}
|
||||
rail={rail}
|
||||
face={
|
||||
<RoundFace
|
||||
dashboard={draft}
|
||||
editing={edit}
|
||||
selected={Boolean(ring) && ring?.id === selected}
|
||||
onPick={(id) => {
|
||||
setSettingsOpen(false)
|
||||
setSelected(id)
|
||||
}}
|
||||
/>
|
||||
}
|
||||
>
|
||||
{(scale) =>
|
||||
!edit ? (
|
||||
<DashboardView dashboard={draft} rail={hasRail} />
|
||||
@@ -514,6 +544,10 @@ export function DashboardEditor({
|
||||
layout={layout}
|
||||
onLayoutChange={applyLayout}
|
||||
positionStrategy={scaledStrategy(scale)}
|
||||
// A circle is narrowest at the top, which is where packing
|
||||
// upwards would put everything: a round face keeps each tile
|
||||
// where it was placed.
|
||||
compactor={round ? noCompactor : undefined}
|
||||
gridConfig={{
|
||||
cols: columns,
|
||||
rowHeight: rowHeightOf(draft, hasRail),
|
||||
@@ -535,7 +569,7 @@ export function DashboardEditor({
|
||||
}}
|
||||
resizeConfig={{ handles: ["e", "s", "se"] }}
|
||||
>
|
||||
{widgets.map((widget) => (
|
||||
{placedWidgets.map((widget) => (
|
||||
<div key={widget.id}>{pickable(widget, true)}</div>
|
||||
))}
|
||||
</GridLayout>
|
||||
@@ -626,6 +660,26 @@ export function DashboardEditor({
|
||||
Reflow
|
||||
</Button>
|
||||
</motion.div>
|
||||
) : cornered.length > 0 && !stacked ? (
|
||||
// Not a fault and nothing to re-pack: the tile still shows,
|
||||
// less what the circle cuts off it.
|
||||
<motion.div
|
||||
variants={slideUp}
|
||||
initial="hidden"
|
||||
animate="visible"
|
||||
exit="exit"
|
||||
transition={transitions.emphasized}
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
data-testid="canvas-cornered"
|
||||
className="absolute bottom-full left-1/2 mb-3 flex max-w-[calc(100vw-2rem)] -translate-x-1/2 items-center rounded-full border border-border bg-card/80 px-4 py-1.5 shadow-e2 backdrop-blur-md"
|
||||
>
|
||||
<span className="truncate text-sm">
|
||||
{cornered.length === 1
|
||||
? "1 widget reaches past the round face — its corners will be cut off."
|
||||
: `${cornered.length} widgets reach past the round face — their corners will be cut off.`}
|
||||
</span>
|
||||
</motion.div>
|
||||
) : null}
|
||||
|
||||
<Tooltip>
|
||||
@@ -729,6 +783,7 @@ export function DashboardEditor({
|
||||
<>
|
||||
<DashboardPalette
|
||||
open={paletteOpen}
|
||||
round={round}
|
||||
onOpenChange={setPaletteOpen}
|
||||
onAdd={addWidget}
|
||||
onSettings={openSettings}
|
||||
@@ -737,10 +792,22 @@ export function DashboardEditor({
|
||||
|
||||
<WidgetPanel
|
||||
widget={active}
|
||||
round={round}
|
||||
onRing={Boolean(active) && draft.ring === active?.id}
|
||||
// One ring per face, so putting a widget on it takes it off any
|
||||
// other.
|
||||
onRingChange={(on) =>
|
||||
active && commit({ ...draft, ring: on ? active.id : "" })
|
||||
}
|
||||
onChange={(changes) => active && patch(active.id, changes)}
|
||||
onDelete={() => {
|
||||
if (!active) return
|
||||
updateWidgets(widgets.filter((other) => other.id !== active.id))
|
||||
// A ring naming a widget that is gone is refused on save.
|
||||
commit({
|
||||
...draft,
|
||||
widgets: widgets.filter((other) => other.id !== active.id),
|
||||
ring: draft.ring === active.id ? "" : draft.ring,
|
||||
})
|
||||
setSelected(null)
|
||||
}}
|
||||
onClose={() => setSelected(null)}
|
||||
|
||||
Reference in New Issue
Block a user