import "capsomer/tokens.css";
import "capsomer/schedule-dialog.css";
import { ScheduleDialog } from "capsomer/react/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
Prop
Type
Required
Does
open
boolean
Yes
onClose
() => void
Yes
returnTo
HTMLElement | null
Focus goes back here when it closes: the button that opened it.
onSchedule
(iso: string) => Promise<void> | void
Yes
Sends the time, as an ISO string; the dialog closes when it resolves, and stays (with the app's message said elsewhere) when it throws.
title
ReactNode
Yes
description
ReactNode
current
string | null
A time already scheduled, as an ISO time: the field starts at it.
label
string
confirm
ReactNode
The confirm's words. Default "Schedule".
lead
string
The line under the field once a time is chosen. Default "Goes live" and the time.
Functions
Function
Signature
Does
checkSchedule
(value: string, now: number): ScheduleCheck
What 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
Class
Is
.cap-schedule-dialog-lead
the root
State
Read from
:empty
the platform
Accessibility
Key
Does
Tab, Shift+Tab
Moves 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
Esc
Closes 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.