@keystone-sites/marketing-design-system 1.0.21 → 1.0.23

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keystone-sites/marketing-design-system",
3
- "version": "1.0.21",
3
+ "version": "1.0.23",
4
4
  "description": "Keystone's marketing design system: tokens, the tick grid, type, primitives, site chrome, and the landing kit. Source-shipped CSS and TSX for Next.js consumers.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -1,7 +1,9 @@
1
- /* Business picker: the label, a box field holding the chosen chips with
2
- the search entry on its own row beneath them, the search menu floating
3
- over whatever follows, then the offers row and the error line. The
4
- field restates the grader's teal state language on the ks-field's box
1
+ /* Business picker: the label (an aside at its far end), a box field
2
+ holding the chosen chips with the search entry on its own row beneath
3
+ them, the search menu floating over whatever follows, then the offers
4
+ row and the error line. Folded, there is no field: the chips and the
5
+ offers stand in the stack, the search one of the offers. The field
6
+ restates the grader's teal state language on the ks-field's box
5
7
  radius. */
6
8
 
7
9
  :root {
@@ -18,9 +20,19 @@
18
20
  --_ph: var(--color-text-500);
19
21
  --_ink: var(--color-text-200);
20
22
  }
23
+ .picker-head {
24
+ display: flex;
25
+ align-items: baseline;
26
+ justify-content: space-between;
27
+ gap: var(--space-md);
28
+ }
21
29
  .picker-label {
22
30
  color: var(--color-text-200);
23
31
  }
32
+ .picker-aside {
33
+ flex: none;
34
+ color: var(--color-text-400);
35
+ }
24
36
  .picker-box {
25
37
  position: relative;
26
38
  }
@@ -105,6 +117,9 @@
105
117
  gap: var(--space-md);
106
118
  margin-top: var(--space-xs);
107
119
  }
120
+ .picker[data-folded] .picker-offers {
121
+ margin-top: var(--space-none);
122
+ }
108
123
  .picker-offers-label {
109
124
  color: var(--color-text-400);
110
125
  }
@@ -4,9 +4,12 @@
4
4
  * as many as the host allows. The chosen ones stand as chips in the
5
5
  * field; typing searches Google Places and the web and the menu's pick
6
6
  * joins them; businesses the host already knows of (`offers`) wait
7
- * beneath the field as one-tap adds. A business is only ever one of the
8
- * search's — a Google place or a website — never free text. Controlled:
9
- * the host owns `chosen`. Styles in business-picker.css. */
7
+ * beneath the field as one-tap adds. Folded, the field stays out of
8
+ * sight: the chosen chips and the offers stand on their own, the search
9
+ * a chip away (`onUnfold`) — for a list that is welcome but not asked
10
+ * for. A business is only ever one of the search's — a Google place or
11
+ * a website — never free text. Controlled: the host owns `chosen` and
12
+ * the fold. Styles in business-picker.css. */
10
13
 
11
14
  import { useId, useState, type FocusEvent, type KeyboardEvent, type ReactNode } from "react";
12
15
  import { IconSearchGlyph } from "../icons";
@@ -21,6 +24,8 @@ const GROUP_LABELS: GraderMenuLabels = { places: "Google Places", web: "Websites
21
24
  interface BusinessPickerProps {
22
25
  id: string;
23
26
  label: ReactNode;
27
+ /** A quiet word beside the label (that the list is optional). */
28
+ aside?: ReactNode;
24
29
  /** Shown while nothing is typed; the field's invitation. */
25
30
  placeholder: string;
26
31
  chosen: readonly GraderSuggestion[];
@@ -39,6 +44,11 @@ interface BusinessPickerProps {
39
44
  addLabel?: (name: string) => string;
40
45
  error?: string | null;
41
46
  autoFocus?: boolean;
47
+ /** The field kept away until asked for; chips and offers stand alone. */
48
+ folded?: boolean;
49
+ /** The search chip's words and what it does when folded. */
50
+ unfoldLabel?: string;
51
+ onUnfold?: () => void;
42
52
  }
43
53
 
44
54
  interface ActiveRow {
@@ -56,6 +66,7 @@ function contextOf(item: GraderSuggestion): string {
56
66
  export function BusinessPicker({
57
67
  id,
58
68
  label,
69
+ aside,
59
70
  placeholder,
60
71
  chosen,
61
72
  onChange,
@@ -68,9 +79,13 @@ export function BusinessPicker({
68
79
  addLabel = (name) => `Add ${name}`,
69
80
  error,
70
81
  autoFocus,
82
+ folded = false,
83
+ unfoldLabel = "Search",
84
+ onUnfold,
71
85
  }: BusinessPickerProps) {
72
86
  const baseId = useId();
73
87
  const listId = `${baseId}-list`;
88
+ const labelId = `${baseId}-label`;
74
89
  const errorId = `${id}-error`;
75
90
  const optionId = (index: number) => `${baseId}-opt-${index}`;
76
91
 
@@ -136,6 +151,59 @@ export function BusinessPicker({
136
151
  setFocused(false);
137
152
  }
138
153
 
154
+ const chips = chosen.map((item) => (
155
+ <Chip
156
+ key={item.id}
157
+ sub={contextOf(item)}
158
+ removeLabel={removeLabel(item.name)}
159
+ onRemove={() => remove(item)}
160
+ >
161
+ {item.name}
162
+ </Chip>
163
+ ));
164
+ const adds = pending.map((item) => (
165
+ <ChipAdd key={item.id} label={addLabel(item.name)} onClick={() => add(item)}>
166
+ {item.name}
167
+ </ChipAdd>
168
+ ));
169
+ const errorLine = error ? (
170
+ <p className="type type-fixed ts-text-sm-light picker-error" id={errorId} role="alert">
171
+ {error}
172
+ </p>
173
+ ) : null;
174
+
175
+ if (folded) {
176
+ return (
177
+ <div className="picker" data-folded="" role="group" aria-labelledby={labelId}>
178
+ <div className="picker-head">
179
+ <span className="type type-fixed ts-text-sm-medium picker-label" id={labelId}>
180
+ {label}
181
+ </span>
182
+ {aside ? (
183
+ <span className="type type-fixed ts-text-xs-regular picker-aside">{aside}</span>
184
+ ) : null}
185
+ </div>
186
+ {chips.length > 0 && <div className="picker-chips">{chips}</div>}
187
+ {!full && (
188
+ <div className="picker-offers">
189
+ {offersLabel && adds.length > 0 ? (
190
+ <span className="type type-fixed ts-text-xs-regular picker-offers-label">
191
+ {offersLabel}
192
+ </span>
193
+ ) : null}
194
+ <div className="picker-offers-row">
195
+ {adds}
196
+ <ChipAdd glyph="search" label={unfoldLabel} onClick={() => onUnfold?.()}>
197
+ {unfoldLabel}
198
+ </ChipAdd>
199
+ </div>
200
+ </div>
201
+ )}
202
+ {errorLine}
203
+ </div>
204
+ );
205
+ }
206
+
139
207
  return (
140
208
  <div
141
209
  className="picker"
@@ -144,25 +212,17 @@ export function BusinessPicker({
144
212
  onFocus={() => setFocused(true)}
145
213
  onBlur={onBlur}
146
214
  >
147
- <label className="type type-fixed ts-text-sm-medium picker-label" htmlFor={id}>
148
- {label}
149
- </label>
215
+ <div className="picker-head">
216
+ <label className="type type-fixed ts-text-sm-medium picker-label" htmlFor={id}>
217
+ {label}
218
+ </label>
219
+ {aside ? (
220
+ <span className="type type-fixed ts-text-xs-regular picker-aside">{aside}</span>
221
+ ) : null}
222
+ </div>
150
223
  <div className="picker-box">
151
224
  <div className="picker-field">
152
- {chosen.length > 0 && (
153
- <div className="picker-chips">
154
- {chosen.map((item) => (
155
- <Chip
156
- key={item.id}
157
- sub={contextOf(item)}
158
- removeLabel={removeLabel(item.name)}
159
- onRemove={() => remove(item)}
160
- >
161
- {item.name}
162
- </Chip>
163
- ))}
164
- </div>
165
- )}
225
+ {chips.length > 0 && <div className="picker-chips">{chips}</div>}
166
226
  {!full && (
167
227
  <span className="picker-entry">
168
228
  <IconSearchGlyph className="picker-glyph" />
@@ -208,27 +268,17 @@ export function BusinessPicker({
208
268
  />
209
269
  )}
210
270
  </div>
211
- {pending.length > 0 && !full && (
271
+ {adds.length > 0 && !full && (
212
272
  <div className="picker-offers">
213
273
  {offersLabel ? (
214
274
  <span className="type type-fixed ts-text-xs-regular picker-offers-label">
215
275
  {offersLabel}
216
276
  </span>
217
277
  ) : null}
218
- <div className="picker-offers-row">
219
- {pending.map((item) => (
220
- <ChipAdd key={item.id} label={addLabel(item.name)} onClick={() => add(item)}>
221
- {item.name}
222
- </ChipAdd>
223
- ))}
224
- </div>
278
+ <div className="picker-offers-row">{adds}</div>
225
279
  </div>
226
280
  )}
227
- {error ? (
228
- <p className="type type-fixed ts-text-sm-light picker-error" id={errorId} role="alert">
229
- {error}
230
- </p>
231
- ) : null}
281
+ {errorLine}
232
282
  </div>
233
283
  );
234
284
  }
@@ -1,12 +1,13 @@
1
1
  /* Chip: a round token on the paper surface — the name, an optional run-on
2
2
  of context, and the remove control at its end. `ChipAdd` is the same
3
- shape outlined in a dash with a plus, offering one more. Fixed material
4
- heights; the type is the chrome's sm step. */
3
+ shape outlined in a dash with a plus (or a search glyph), offering one
4
+ more. Fixed material heights; the type is the chrome's sm step. */
5
5
 
6
6
  :root {
7
7
  --chip-h: 32px;
8
8
  --chip-remove: 20px;
9
9
  --chip-plus: 10px;
10
+ --chip-glyph: 12px;
10
11
  }
11
12
 
12
13
  .chip {
@@ -107,6 +108,11 @@
107
108
  width: 1.5px;
108
109
  height: 100%;
109
110
  }
111
+ .chip-glyph {
112
+ flex: none;
113
+ width: var(--chip-glyph);
114
+ height: var(--chip-glyph);
115
+ }
110
116
  @media (hover: hover) {
111
117
  .chip-add:hover {
112
118
  border-color: var(--color-teal-300);
@@ -1,9 +1,10 @@
1
1
  /** Chip: one chosen thing in a selection, with the control that removes
2
2
  * it; and the offer of one more (`ChipAdd`), drawn as the same shape with
3
- * a plus. Styles in chip.css. */
3
+ * a plus — or a search glyph, when the offer is to go looking. Styles in
4
+ * chip.css. */
4
5
 
5
6
  import type { ReactNode } from "react";
6
- import { IconGalleryClose } from "../icons";
7
+ import { IconGalleryClose, IconSearchGlyph } from "../icons";
7
8
 
8
9
  interface ChipProps {
9
10
  children: ReactNode;
@@ -32,13 +33,20 @@ interface ChipAddProps {
32
33
  children: ReactNode;
33
34
  /** Spoken on the control, naming what it adds. */
34
35
  label: string;
36
+ /** The mark before the name: a plus for one more, a search glyph for
37
+ * opening a search. */
38
+ glyph?: "plus" | "search";
35
39
  onClick: () => void;
36
40
  }
37
41
 
38
- export function ChipAdd({ children, label, onClick }: ChipAddProps) {
42
+ export function ChipAdd({ children, label, glyph = "plus", onClick }: ChipAddProps) {
39
43
  return (
40
44
  <button type="button" className="chip chip-add" aria-label={label} onClick={onClick}>
41
- <span className="chip-plus" aria-hidden="true" />
45
+ {glyph === "search" ? (
46
+ <IconSearchGlyph className="chip-glyph" />
47
+ ) : (
48
+ <span className="chip-plus" aria-hidden="true" />
49
+ )}
42
50
  <span className="type type-fixed ts-text-sm-medium chip-name">{children}</span>
43
51
  </button>
44
52
  );
@@ -38,7 +38,6 @@
38
38
  flex-direction: column;
39
39
  box-sizing: border-box;
40
40
  width: 100%;
41
- max-width: 28rem;
42
41
  max-height: calc(100dvh - var(--space-2xl) * 2);
43
42
  overflow-y: auto;
44
43
  border: 1px solid var(--color-border-050);
@@ -60,6 +59,9 @@
60
59
  .modal-sheet[data-size="xs"] .modal-body {
61
60
  padding-block: calc(var(--space-4xl) + var(--space-xs)) calc(var(--space-3xl) + var(--space-xs));
62
61
  }
62
+ .modal-sheet[data-size="sm"] {
63
+ max-width: 30rem;
64
+ }
63
65
  .modal-sheet[data-size="md"] {
64
66
  max-width: 36rem;
65
67
  }
@@ -3,7 +3,8 @@
3
3
  /** Modal: a centred sheet over a dimmed ground. Locks page scroll, traps
4
4
  * Tab, closes on Escape and on the backdrop, and returns focus to the
5
5
  * element that opened it. Renders into the body so grid geometry stays
6
- * untouched. Styles live in modal.css. */
6
+ * untouched; a body that changes size while open (a step, a new `size`)
7
+ * tweens the sheet to it. Styles live in modal.css. */
7
8
 
8
9
  import { useEffect, useRef, type ReactNode } from "react";
9
10
  import { createPortal } from "react-dom";
@@ -15,7 +16,7 @@ interface ModalProps {
15
16
  /** Names the dialog for assistive technology. */
16
17
  label: string;
17
18
  onClose: () => void;
18
- /** Sheet width: xs for a sign-in, sm for prompts, md for forms, lg for records. */
19
+ /** Sheet width: xs for a prompt, sm for a sign-in, md for forms, lg for records. */
19
20
  size?: "xs" | "sm" | "md" | "lg";
20
21
  /** The page behind: lightened to paper, or dimmed to ink and blurred
21
22
  * under a sheet on the page ground with a long soft drop. */
@@ -25,6 +26,30 @@ interface ModalProps {
25
26
  children: ReactNode;
26
27
  }
27
28
 
29
+ interface Box {
30
+ width: number;
31
+ height: number;
32
+ }
33
+
34
+ const same = (a: Box, b: Box) => a.width === b.width && a.height === b.height;
35
+
36
+ // Clipped while it moves: a growing sheet is briefly shorter than its
37
+ // content, and that is no cause for a scrollbar. The cap moves with the
38
+ // width, which it would otherwise hold back.
39
+ const frame = ({ width, height }: Box): Keyframe => ({
40
+ width: `${width}px`,
41
+ maxWidth: `${width}px`,
42
+ height: `${height}px`,
43
+ overflowY: "hidden",
44
+ });
45
+
46
+ /** A CSS time as the Web Animations API wants it. The computed token
47
+ * may come back in either unit (a bundler shortens `250ms` to `.25s`). */
48
+ function milliseconds(time: string): number {
49
+ const t = time.trim();
50
+ return t.endsWith("ms") ? parseFloat(t) : parseFloat(t) * 1000;
51
+ }
52
+
28
53
  export function Modal({
29
54
  label,
30
55
  onClose,
@@ -34,6 +59,7 @@ export function Modal({
34
59
  children,
35
60
  }: ModalProps) {
36
61
  const sheetRef = useRef<HTMLDivElement>(null);
62
+ const bodyRef = useRef<HTMLDivElement>(null);
37
63
  const openerRef = useRef<Element | null>(null);
38
64
 
39
65
  useEffect(() => {
@@ -48,6 +74,79 @@ export function Modal({
48
74
  };
49
75
  }, []);
50
76
 
77
+ // The body changing size (a step, a new `size`) moves the sheet
78
+ // smoothly: as the new content lands, the sheet tweens from the box it
79
+ // stood in to its new one. Reduced motion snaps; so does the first
80
+ // measure.
81
+ useEffect(() => {
82
+ const sheet = sheetRef.current;
83
+ const body = bodyRef.current;
84
+ if (
85
+ !sheet ||
86
+ !body ||
87
+ typeof ResizeObserver === "undefined" ||
88
+ typeof sheet.animate !== "function"
89
+ )
90
+ return;
91
+ const reduced = window.matchMedia("(prefers-reduced-motion: reduce)");
92
+ const box = (): Box => ({ width: sheet.offsetWidth, height: sheet.offsetHeight });
93
+ let flight: { tween: Animation; hold: Animation; from: Box; to: Box } | null = null;
94
+ const fly = (from: Box, to: Box, at = 0) => {
95
+ const style = getComputedStyle(sheet);
96
+ const timing = {
97
+ duration: milliseconds(style.getPropertyValue("--motion-drawer-duration")),
98
+ easing: style.getPropertyValue("--motion-drawer-ease").trim(),
99
+ };
100
+ // The body keeps its settled width, centred, while the sheet moves
101
+ // around it: its lines land wrapped as they will stay, and the
102
+ // observer stays quiet until the content itself changes again.
103
+ // Measured before the sheet is set moving, which would carry it.
104
+ const held: Keyframe = {
105
+ width: `${body.offsetWidth}px`,
106
+ boxSizing: "border-box",
107
+ alignSelf: "center",
108
+ };
109
+ const tween = sheet.animate([frame(from), frame(to)], timing);
110
+ const hold = body.animate([held, held], timing);
111
+ tween.currentTime = at;
112
+ hold.currentTime = at;
113
+ tween.onfinish = () => {
114
+ flight = null;
115
+ };
116
+ flight = { tween, hold, from, to };
117
+ };
118
+ // The sheet's box as last settled (its layout box, untouched by the
119
+ // entrance's transform): by the time the observer runs, layout
120
+ // already holds the new one.
121
+ let last: Box | null = null;
122
+ const ro = new ResizeObserver(() => {
123
+ if (!flight) {
124
+ const from = last;
125
+ last = box();
126
+ if (from && !same(from, last) && !reduced.matches) fly(from, last);
127
+ return;
128
+ }
129
+ // Content changing under way: lift the tween to see where the sheet
130
+ // would now settle, and either put it back or turn it toward the
131
+ // new end.
132
+ const { tween, hold, from, to } = flight;
133
+ const at = Number(tween.currentTime);
134
+ const now = box();
135
+ tween.cancel();
136
+ hold.cancel();
137
+ flight = null;
138
+ last = box();
139
+ if (same(last, to)) fly(from, to, at);
140
+ else fly(now, last);
141
+ });
142
+ ro.observe(body);
143
+ return () => {
144
+ ro.disconnect();
145
+ flight?.tween.cancel();
146
+ flight?.hold.cancel();
147
+ };
148
+ }, []);
149
+
51
150
  useEffect(() => {
52
151
  const onKey = (event: KeyboardEvent) => {
53
152
  if (event.key === "Escape") {
@@ -76,7 +175,9 @@ export function Modal({
76
175
  <button type="button" className="modal-close" aria-label="Close" onClick={onClose}>
77
176
  <IconGalleryClose />
78
177
  </button>
79
- <div className="modal-body">{children}</div>
178
+ <div ref={bodyRef} className="modal-body">
179
+ {children}
180
+ </div>
80
181
  {foot ? <div className="modal-foot">{foot}</div> : null}
81
182
  </div>
82
183
  </div>,