@commmerce/ui 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,6 +23,7 @@ import { LitElement } from 'lit';
23
23
  * @slot bottom-navigation - A `cm-bottom-navigation`. Shown, fixed to the bottom of the window, when the frame is narrower than 1024px. No need to set its `fixed` attribute.
24
24
  * @slot mobile-menu - A `cm-mobile-menu`. Shown over the page while `menu-open` is set and the frame is narrower than 1024px.
25
25
  * @fires cm-menu-toggle - When the frame opens or closes the mobile menu itself: from the `menu-item` in the bottom navigation, Escape, or a choice in the menu. `detail: { open }`. Not fired when you set `menu-open` yourself.
26
+ * @cssprop --cm-app-frame-bottom-offset - Extra space at the end of the page, for a bar of your own fixed to the bottom of the window (e.g. a field app's own bottom navigation). Added to the frame's padding for its bottom navigation. Default `0px`.
26
27
  * @cssprop --cm-app-frame-height - Height the side navigation fits in (it scrolls when taller). Default `100dvh`, the window. Set it when the frame is inside a box of its own.
27
28
  */
28
29
  export declare class CmAppFrame extends LitElement {
@@ -45,6 +45,7 @@ const deepActive = () => {
45
45
  * @slot bottom-navigation - A `cm-bottom-navigation`. Shown, fixed to the bottom of the window, when the frame is narrower than 1024px. No need to set its `fixed` attribute.
46
46
  * @slot mobile-menu - A `cm-mobile-menu`. Shown over the page while `menu-open` is set and the frame is narrower than 1024px.
47
47
  * @fires cm-menu-toggle - When the frame opens or closes the mobile menu itself: from the `menu-item` in the bottom navigation, Escape, or a choice in the menu. `detail: { open }`. Not fired when you set `menu-open` yourself.
48
+ * @cssprop --cm-app-frame-bottom-offset - Extra space at the end of the page, for a bar of your own fixed to the bottom of the window (e.g. a field app's own bottom navigation). Added to the frame's padding for its bottom navigation. Default `0px`.
48
49
  * @cssprop --cm-app-frame-height - Height the side navigation fits in (it scrolls when taller). Default `100dvh`, the window. Set it when the frame is inside a box of its own.
49
50
  */
50
51
  export class CmAppFrame extends LitElement {
@@ -187,7 +188,7 @@ CmAppFrame.styles = [
187
188
  overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin;
188
189
  padding: var(--cm-space-20); padding-inline-end: 0;
189
190
  }
190
- main { display: block; min-inline-size: 0; padding-block-end: var(--_bottom); }
191
+ main { display: block; min-inline-size: 0; padding-block-end: calc(var(--_bottom) + var(--cm-app-frame-bottom-offset, 0px)); }
191
192
  main:focus { outline: none; }
192
193
  .bottom { position: fixed; inset-inline: 0; inset-block-end: 0; z-index: 40; }
193
194
  ::slotted([slot='bottom-navigation']) { position: static; }
@@ -0,0 +1,380 @@
1
+ import { LitElement, type PropertyValues, type TemplateResult } from 'lit';
2
+ import { CmLocalizedElement } from '../localize.js';
3
+ import './icon.js';
4
+ import './spinner.js';
5
+ declare const strings: {
6
+ /** Accessible name of the calendar when it has no `label`. */
7
+ label: string;
8
+ /** Header buttons. */
9
+ previousMonth: string;
10
+ nextMonth: string;
11
+ previousWeek: string;
12
+ nextWeek: string;
13
+ /** The narrow week view shows three days at a time. */
14
+ previousDays: string;
15
+ nextDays: string;
16
+ previousDay: string;
17
+ nextDay: string;
18
+ today: string;
19
+ /** The group of view buttons, and the buttons. */
20
+ views: string;
21
+ month: string;
22
+ week: string;
23
+ day: string;
24
+ /** Row heading of all-day events in the week and day views. */
25
+ allDay: string;
26
+ /** Heading of the hour column in the week and day views (read by screen readers only). */
27
+ time: string;
28
+ /** The visible text of the Add button above the day's list on narrow screens. */
29
+ add: string;
30
+ /** The "+" button of a day in the month view, and the Add button of the day's list. `{date}` e.g. "Wednesday 18 November". */
31
+ addOn: string;
32
+ /** The "+" button in the all-day row of the week and day views. */
33
+ addAllDay: string;
34
+ /** An empty hour in the week and day views. `{time}` e.g. "3:00 pm". */
35
+ addAt: string;
36
+ /** The overflow button of a month day, visible text. */
37
+ more: string;
38
+ /** The overflow button's accessible name. */
39
+ moreLabel: string;
40
+ /** A day button in the narrow month view. */
41
+ dayEvents: {
42
+ one: string;
43
+ other: string;
44
+ };
45
+ /** The day's list with nothing in it. */
46
+ noEvents: string;
47
+ /** Announced while `loading`. */
48
+ loading: string;
49
+ /** A time range: "3:00 to 3:30 pm". `{start}` and `{end}` are formatted for the locale (a shared am/pm is written once). */
50
+ timeRange: string;
51
+ /** When an event happens, in its accessible name. */
52
+ timed: string;
53
+ allDayOn: string;
54
+ allDayRange: string;
55
+ /** An event's accessible name: "Call Ravi Stores, Wednesday 18 November, 3:00 to 3:30 pm, Follow-up". */
56
+ eventName: string;
57
+ eventNameKind: string;
58
+ /** What screen readers call a movable event, after its name. */
59
+ roleDescription: string;
60
+ /** Read after an event's name. */
61
+ openHint: string;
62
+ instructions: string;
63
+ /** Read with the grid. */
64
+ gridHelp: string;
65
+ /** Added to an event's name while its move is saved (`pending`). */
66
+ saving: string;
67
+ /** Move announcements. `{event}` the event's title, `{place}` a day ("Thursday 19 November") or a day and time. */
68
+ pickedUp: string;
69
+ over: string;
70
+ moved: string;
71
+ sameSpot: string;
72
+ cancelled: string;
73
+ refused: string;
74
+ reverted: string;
75
+ };
76
+ declare module '../localize.js' {
77
+ interface CmStrings {
78
+ calendar: typeof strings;
79
+ }
80
+ }
81
+ export type CalendarView = 'month' | 'week' | 'day';
82
+ export type CalendarEventTone = 'neutral' | 'attention' | 'information' | 'success' | 'critical';
83
+ /** How an event was moved: dragged with a pointer, moved with the keyboard, or by calling `moveEvent()`. */
84
+ export type CalendarMoveSource = 'pointer' | 'keyboard' | 'api';
85
+ /** Start and end of an event, as local ISO strings: `yyyy-mm-dd` for all-day events (end = last day), else `yyyy-mm-ddThh:mm`. */
86
+ export interface CalendarTimes {
87
+ start: string;
88
+ end: string;
89
+ }
90
+ /** `detail` of `cm-move`. */
91
+ export interface CalendarMoveDetail {
92
+ /** The event's `value`. */
93
+ value: string;
94
+ /** The `cm-calendar-event` element. */
95
+ event: CmCalendarEvent;
96
+ /** Where it was and where it goes. */
97
+ from: CalendarTimes;
98
+ to: CalendarTimes;
99
+ /** An all-day event (times are dates then). */
100
+ allDay: boolean;
101
+ source: CalendarMoveSource;
102
+ /**
103
+ * Call with the promise that saves the move: the event shows as saving (`pending`) until it settles; if it
104
+ * rejects, the calendar puts the event back (`revert()`) and announces it. Call it during the event.
105
+ */
106
+ waitUntil(promise: Promise<unknown>): void;
107
+ }
108
+ /** `detail` of `cm-range-change`: the view and the first and last day shown (ISO dates, both included). */
109
+ export interface CalendarRange {
110
+ view: CalendarView;
111
+ start: string;
112
+ end: string;
113
+ }
114
+ /** `detail` of `cm-add`. */
115
+ export interface CalendarAddDetail {
116
+ /** `yyyy-mm-dd` from a day in the month view or the all-day row; `yyyy-mm-ddThh:mm` from an hour in the week and day views. */
117
+ start: string;
118
+ /** True for a day (month view, all-day row). */
119
+ allDay: boolean;
120
+ view: CalendarView;
121
+ }
122
+ /**
123
+ * One event on a `cm-calendar`: a call, a follow-up, a demo. It shows nothing itself: the calendar draws it as a
124
+ * chip in every view. Set `start` (and `end`) as local ISO date-times, or dates with `all-day`.
125
+ * @element cm-calendar-event
126
+ * @slot - The title, when `heading` is not set.
127
+ */
128
+ export declare class CmCalendarEvent extends LitElement {
129
+ static properties: {
130
+ value: {
131
+ reflect: boolean;
132
+ };
133
+ heading: {};
134
+ label: {};
135
+ start: {};
136
+ end: {};
137
+ allDay: {
138
+ type: BooleanConstructor;
139
+ attribute: string;
140
+ reflect: boolean;
141
+ };
142
+ kind: {};
143
+ tone: {
144
+ reflect: boolean;
145
+ };
146
+ icon: {};
147
+ href: {};
148
+ locked: {
149
+ type: BooleanConstructor;
150
+ reflect: boolean;
151
+ };
152
+ pending: {
153
+ type: BooleanConstructor;
154
+ reflect: boolean;
155
+ };
156
+ moving: {
157
+ type: BooleanConstructor;
158
+ reflect: boolean;
159
+ };
160
+ };
161
+ /** Identifies the event in `cm-move` and `cm-open` (e.g. its id). Defaults to the title. */
162
+ value: string;
163
+ /** The title, e.g. "Call Ravi Stores". */
164
+ heading: string;
165
+ /** The title for screen readers and announcements, when it should differ from `heading`. */
166
+ label: string;
167
+ /** Local start, ISO `yyyy-mm-ddThh:mm`; for an all-day event `yyyy-mm-dd` (a date alone makes it all-day). */
168
+ start: string;
169
+ /** Local end, ISO `yyyy-mm-ddThh:mm` (default: 30 minutes after `start`); for an all-day event, its last day `yyyy-mm-dd` (default: the start day). */
170
+ end: string;
171
+ /** Lasts the whole day (or days): shown in the all-day row of the week and day views, and first in a month day. */
172
+ allDay: boolean;
173
+ /** What it is, in a word or two: "Follow-up", "Demo", "Call". Shown on the chip and read in its name, so colour is never the only signal. */
174
+ kind: string;
175
+ /** Colour of the chip, from the semantic tones. Pick one per kind and keep it. */
176
+ tone: CalendarEventTone;
177
+ /** A `cm-icon` name shown before the title (e.g. `phone` for calls). The month view shows the icon instead of `kind`. */
178
+ icon: string;
179
+ /** Makes the chip a link to the record. Without it, activating the chip fires `cm-open`. */
180
+ href: string;
181
+ /** The event can't be moved (e.g. no permission). It can still be opened. */
182
+ locked: boolean;
183
+ /** The move is being saved: the chip is greyed and can't be moved again until it is cleared. Set by `waitUntil()` in `cm-move`, or by you. */
184
+ pending: boolean;
185
+ /** Set by the calendar while the event is picked up or dragged. Read it for styling; don't set it. */
186
+ moving: boolean;
187
+ static styles: import("lit").CSSResult;
188
+ /** The event's name: `label`, `heading`, or its text. */
189
+ get name(): string;
190
+ /** The value used in events: `value`, or the name. */
191
+ get key(): string;
192
+ protected updated(): void;
193
+ render(): symbol;
194
+ }
195
+ /**
196
+ * A calendar of events in month, week and day views: an outreach planner of calls, follow-ups and demos. Events are
197
+ * `cm-calendar-event` children; the calendar draws them as chips with a kind and a colour.
198
+ *
199
+ * The header has Previous, Today and Next, the range shown and a view switch. Each change of view or range fires
200
+ * `cm-range-change` with the days shown, so the app loads their events. Events move between days (month, week) and
201
+ * times (week, day) by dragging (on touch, press and hold first) or with the keyboard: focus an event, press Space,
202
+ * choose a day or time with the arrow keys and press Enter. Each move fires a cancelable `cm-move`. A "+" on each
203
+ * day (and each hour in the week and day views) fires `cm-add`.
204
+ *
205
+ * When the calendar is narrower than 600px the month view becomes a compact grid with the chosen day's events
206
+ * listed under it, and the week view shows three days.
207
+ * @element cm-calendar
208
+ * @slot - `cm-calendar-event` elements, in any order.
209
+ * @fires cm-range-change - When the days shown change (view, Previous/Next/Today, `date`, or the width crossing 600px), and once on first render. `detail: { view, start, end }` (ISO dates, both included). Load the events for those days.
210
+ * @fires cm-move - Before an event moves. Cancelable: `preventDefault()` keeps it where it was. `detail: { value, event, from: { start, end }, to: { start, end }, allDay, source, waitUntil }` (see `CalendarMoveDetail`).
211
+ * @fires cm-add - From a "+" button or an empty hour. `detail: { start, allDay, view }`: `start` is `yyyy-mm-dd` for a day, `yyyy-mm-ddThh:mm` for an hour.
212
+ * @fires cm-open - When an event chip is activated (click or Enter). `detail: { value, event }`. Cancelable: on a chip with `href`, `preventDefault()` stops the link.
213
+ * @csspart header - The row with the navigation, the range and the view switch.
214
+ * @csspart title - The range shown ("November 2026").
215
+ * @csspart grid - The month table, or the week and day time grid.
216
+ * @csspart agenda - The chosen day's list under the narrow month view.
217
+ * @cssprop --cm-calendar-hour-height - Height of an hour in the week and day views. Default 48px.
218
+ * @cssprop --cm-calendar-time-height - Most height of the scrolling week and day views. Default 600px.
219
+ * @cssprop --cm-calendar-day-height - Height of a day in the month view. Default 112px.
220
+ */
221
+ export declare class CmCalendar extends CmLocalizedElement {
222
+ #private;
223
+ static properties: {
224
+ view: {
225
+ reflect: boolean;
226
+ };
227
+ date: {
228
+ reflect: boolean;
229
+ };
230
+ today: {};
231
+ label: {
232
+ string: string;
233
+ };
234
+ step: {
235
+ type: NumberConstructor;
236
+ };
237
+ locale: {
238
+ noAccessor: boolean;
239
+ };
240
+ firstDayOfWeek: {
241
+ type: NumberConstructor;
242
+ attribute: string;
243
+ };
244
+ hourCycle: {
245
+ attribute: string;
246
+ };
247
+ dayStart: {
248
+ type: NumberConstructor;
249
+ attribute: string;
250
+ };
251
+ maxEvents: {
252
+ type: NumberConstructor;
253
+ attribute: string;
254
+ };
255
+ headingLevel: {
256
+ type: NumberConstructor;
257
+ attribute: string;
258
+ };
259
+ loading: {
260
+ type: BooleanConstructor;
261
+ reflect: boolean;
262
+ };
263
+ readonly: {
264
+ type: BooleanConstructor;
265
+ reflect: boolean;
266
+ };
267
+ controlled: {
268
+ type: BooleanConstructor;
269
+ reflect: boolean;
270
+ };
271
+ dragging: {
272
+ type: BooleanConstructor;
273
+ reflect: boolean;
274
+ };
275
+ _narrow: {
276
+ state: boolean;
277
+ };
278
+ _more: {
279
+ state: boolean;
280
+ };
281
+ _target: {
282
+ state: boolean;
283
+ };
284
+ };
285
+ /** `month`, `week` or `day`. */
286
+ view: CalendarView;
287
+ /** A day in the range shown, ISO `yyyy-mm-dd`. Previous, Next and Today change it. Empty: today. On narrow screens it is also the day listed under the month. */
288
+ date: string;
289
+ /** Today's date, ISO `yyyy-mm-dd`, for the Today button and the highlight. Empty: the device's date. Set it from your server, or to fix the date in tests. */
290
+ today: string;
291
+ /** Accessible name of the calendar, e.g. "Outreach planner". Default: the built-in string `label` ("Calendar"). */
292
+ label: string;
293
+ /** Minutes events snap to when moved in the week and day views (1 to 240). Default 15. */
294
+ step: number;
295
+ /** BCP 47 language for month and weekday names, times and the first day of the week. Empty: the same language as every other component. */
296
+ get locale(): string;
297
+ set locale(v: string);
298
+ /** First day of the week: 0 = Sunday, 1 = Monday … 6 = Saturday. Defaults to the locale's custom where the browser knows it (as in `cm-date-picker`), else Sunday. */
299
+ firstDayOfWeek?: number;
300
+ /** `h12` or `h23` to force a 12- or 24-hour clock. Empty: the locale's clock. */
301
+ hourCycle: '' | 'h12' | 'h23';
302
+ /** The hour the week and day views scroll to when they open (0 to 23). Default 8. */
303
+ dayStart: number;
304
+ /** Most chips in a month day; with more, the last place shows "+N more", which lists the whole day. Default 3. */
305
+ maxEvents: number;
306
+ /** Level of the range heading for screen readers (1 to 6). Default 2. */
307
+ headingLevel: number;
308
+ /** Events are loading: the grid is busy and "Loading events" is announced. */
309
+ loading: boolean;
310
+ /** No "+" buttons and no moving: events can only be opened. */
311
+ readonly: boolean;
312
+ /**
313
+ * You move the events: the calendar fires `cm-move` but never changes `start` and `end`. Change them (or re-render
314
+ * the event) in your `cm-move` listener. Use it with React, Vue and other frameworks that render from data.
315
+ */
316
+ controlled: boolean;
317
+ /** Set while an event is dragged with a pointer. Read it for styling; don't set it. */
318
+ dragging: boolean;
319
+ _narrow: boolean;
320
+ /** The day whose "+N more" list is open. */
321
+ _more: string;
322
+ /** Where the moving event would land. */
323
+ _target: {
324
+ iso: string;
325
+ min?: number;
326
+ } | null;
327
+ constructor();
328
+ static styles: import("lit").CSSResult[];
329
+ /** The `cm-calendar-event` children. */
330
+ get events(): CmCalendarEvent[];
331
+ /** The event with this `value` (or title). */
332
+ event(value: string): CmCalendarEvent | undefined;
333
+ /** The view and the first and last day shown, as in `cm-range-change`. */
334
+ get range(): CalendarRange;
335
+ /** The event picked up with the keyboard, if any. */
336
+ get heldEvent(): CmCalendarEvent | null;
337
+ /** The last message announced (for tests and logging). */
338
+ get announcement(): string;
339
+ /** Announces a message in the calendar's live region. */
340
+ announce(text: string): void;
341
+ connectedCallback(): void;
342
+ disconnectedCallback(): void;
343
+ protected willUpdate(changed: PropertyValues): void;
344
+ protected firstUpdated(): void;
345
+ protected updated(): void;
346
+ /** Shows the previous month, week (three days when narrow) or day. */
347
+ previous(): void;
348
+ /** Shows the next month, week (three days when narrow) or day. */
349
+ next(): void;
350
+ /** Shows the range with today in it. */
351
+ goToToday(): void;
352
+ /**
353
+ * Picks up an event for moving with the arrow keys, as Space does: e.g. from a "Move" item in your own menu.
354
+ * `day` (ISO) is the day it is picked up from, for an all-day event over several days. Returns false when the
355
+ * event is not shown, `locked`, `pending` or the calendar is `readonly`.
356
+ */
357
+ pickUp(event: CmCalendarEvent | string, day?: string): boolean;
358
+ /** Cancels a keyboard move or a drag in progress: the event stays where it was. */
359
+ cancelMove(): void;
360
+ /**
361
+ * Moves an event to a new start (local ISO; `end` defaults to keeping its length), as a drop would: fires
362
+ * `cm-move`, and unless it is cancelled (or the calendar is `controlled`) changes `start` and `end`. Returns false
363
+ * when the move was cancelled or the event was not found.
364
+ */
365
+ moveEvent(event: CmCalendarEvent | string, start: string, end?: string): boolean;
366
+ /**
367
+ * Puts an event back where it was before its last move by the calendar, clears `pending` and announces it. Call
368
+ * it when saving the move failed (a rejected `waitUntil()` promise does this for you). Does nothing with
369
+ * `controlled` (put it back in your data) or when the event has not moved. Returns whether it went back.
370
+ */
371
+ revert(event: CmCalendarEvent | string): boolean;
372
+ render(): TemplateResult<1>;
373
+ }
374
+ declare global {
375
+ interface HTMLElementTagNameMap {
376
+ 'cm-calendar': CmCalendar;
377
+ 'cm-calendar-event': CmCalendarEvent;
378
+ }
379
+ }
380
+ export {};