Skip to content

Schedule dialog

A dialog that asks when to publish, names the time zone, and sends nothing until confirmed.

<div data-mount="new"></div>

Installation

// package.json: "capsomer": "github:DrDustinEdwards/capsomer#v0.152.2"
import "capsomer/tokens.css";
import "capsomer/base.css";
import "capsomer/schedule-dialog.css";
import { checkSchedule } from "capsomer/behavior/schedule-dialog";

Usage

import { ScheduleDialog } from "capsomer/react/schedule-dialog";

<ScheduleDialog
  open={open}
  onClose={() => setOpen(false)}
  returnTo={opener}
  title="Schedule this post"
  description="The site publishes it at the time you choose. Revert to draft takes it back."
  current={pendingUpdate?.publishAt}
  onSchedule={async (iso) => {
    const result = await send("schedule", { publishAt: iso });
    if (!result.ok) throw new Error(result.message);
  }}
/>;

Examples

Replace a scheduled update: the field starts at the time already set

<div data-mount="replace"></div>

API reference

ScheduleDialog

PropTypeRequiredDoes
openbooleanYes
onClose() => voidYes
returnToHTMLElement | nullFocus goes back here when it closes: the button that opened it.
onSchedule(iso: string) => Promise<void> | voidYesSends the time, as an ISO string; the dialog closes when it resolves, and stays (with the app's message said elsewhere) when it throws.
titleReactNodeYes
descriptionReactNode
currentstring | nullA time already scheduled, as an ISO time: the field starts at it.
labelstring
confirmReactNodeThe confirm's words. Default "Schedule".
leadstringThe line under the field once a time is chosen. Default "Goes live" and the time.

Functions

FunctionSignatureDoes
checkSchedule(value: string, now: number): ScheduleCheckWhat a datetime-local value means at now: past is measured when the time was chosen, so a time that passes while the dialog is open is not refused under the person's eyes.

Parts and data attributes

ClassIs
.cap-schedule-dialog-leadthe root
StateRead from
:emptythe platform

Accessibility

KeyDoes
Tab, Shift+TabMoves between the field, Cancel and the confirm, kept inside the dialog
Up arrow, Down arrow (field)Changes the part of the date or time with focus (the browser's own)
Enter (confirm)Sends the time once it is in the future
EscCloses without sending; focus back on the opener
  • The shared Dialog: modal, named by its title, described by its description, focus kept inside and returned.
  • The field is a Field: label, Required, the zone as its description and a past time as its error.
  • The line that says the time back is a status, so the chosen time is said once it is valid.
  • The time is a <time datetime> (the Time component), in words, with UTC beside the local time.