@keystone-sites/marketing-design-system 1.0.24 → 1.0.26

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.24",
3
+ "version": "1.0.26",
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": {
@@ -53,9 +53,13 @@ interface BusinessPickerProps {
53
53
 
54
54
  interface ActiveRow {
55
55
  index: number;
56
+ /** The query the index belongs to; a new answer highlights no row. */
56
57
  resultsFor: string;
57
58
  }
58
59
 
60
+ /** No row highlighted: Enter adds nothing until the visitor moves to one. */
61
+ const NO_ROW = -1;
62
+
59
63
  /** The address trimmed to what tells one business from its namesake:
60
64
  * the street, or the website's domain. */
61
65
  function contextOf(item: GraderSuggestion): string {
@@ -92,14 +96,15 @@ export function BusinessPicker({
92
96
  const [query, setQuery] = useState("");
93
97
  const [focused, setFocused] = useState(false);
94
98
  const [dismissed, setDismissed] = useState(false);
95
- const [active, setActive] = useState<ActiveRow>({ index: 0, resultsFor: "" });
99
+ const [active, setActive] = useState<ActiveRow>({ index: NO_ROW, resultsFor: "" });
96
100
 
97
101
  const full = chosen.length >= max;
98
102
  const search = useGraderSearch(query, !full);
103
+ /** The row the visitor highlighted among the current results, or none. */
99
104
  const activeIndex =
100
105
  active.resultsFor === search.resultsFor
101
- ? Math.min(active.index, Math.max(search.results.length - 1, 0))
102
- : 0;
106
+ ? Math.min(active.index, search.results.length - 1)
107
+ : NO_ROW;
103
108
  const open = focused && !dismissed && !full && search.results.length > 0;
104
109
  const searching = search.status === "loading";
105
110
  const has = (item: GraderSuggestion) => chosen.some((c) => c.id === item.id);
@@ -125,12 +130,19 @@ export function BusinessPicker({
125
130
  if (!count) return;
126
131
  e.preventDefault();
127
132
  setDismissed(false);
128
- const step = e.key === "ArrowDown" ? 1 : count - 1;
129
- setActive({ index: (activeIndex + step) % count, resultsFor: search.resultsFor });
133
+ // Down from no row lands on the first; up from none or the first wraps to the last.
134
+ const index =
135
+ e.key === "ArrowDown"
136
+ ? (activeIndex + 1) % count
137
+ : activeIndex <= 0
138
+ ? count - 1
139
+ : activeIndex - 1;
140
+ setActive({ index, resultsFor: search.resultsFor });
130
141
  break;
131
142
  }
132
143
  case "Enter": {
133
- // The picker lives inside a form: Enter picks, never submits.
144
+ // The picker lives inside a form: Enter adds the highlighted row, never
145
+ // submits — and never takes the top row on the visitor's behalf.
134
146
  e.preventDefault();
135
147
  const match = open ? search.results[activeIndex] : undefined;
136
148
  if (match) add(match);
@@ -242,7 +254,9 @@ export function BusinessPicker({
242
254
  aria-busy={searching || undefined}
243
255
  aria-expanded={open}
244
256
  aria-controls={open ? listId : undefined}
245
- aria-activedescendant={open ? optionId(activeIndex) : undefined}
257
+ aria-activedescendant={
258
+ open && activeIndex !== NO_ROW ? optionId(activeIndex) : undefined
259
+ }
246
260
  aria-invalid={error ? true : undefined}
247
261
  aria-describedby={error ? errorId : undefined}
248
262
  placeholder={chosen.length ? "" : placeholder}
@@ -243,6 +243,8 @@ interface ButtonArrowProps {
243
243
  label: string;
244
244
  type?: "button" | "submit";
245
245
  onClick?: MouseEventHandler<HTMLElement>;
246
+ /** Fires before the press takes focus, so a host can keep it elsewhere. */
247
+ onMouseDown?: MouseEventHandler<HTMLElement>;
246
248
  attrs?: PassAttrs;
247
249
  }
248
250
 
@@ -257,6 +259,7 @@ export function ButtonArrow({
257
259
  label,
258
260
  type = "button",
259
261
  onClick,
262
+ onMouseDown,
260
263
  attrs,
261
264
  }: ButtonArrowProps) {
262
265
  const glyph = (
@@ -318,6 +321,7 @@ export function ButtonArrow({
318
321
  aria-busy={loading || undefined}
319
322
  aria-label={label}
320
323
  onClick={onClick}
324
+ onMouseDown={onMouseDown}
321
325
  {...attrs}
322
326
  >
323
327
  {glyph}
@@ -150,7 +150,8 @@
150
150
  --_ring: var(--color-brown-200);
151
151
  }
152
152
 
153
- /* The arrow appears disabled while the field is empty. */
153
+ /* The arrow appears disabled while the field is empty. It stays
154
+ pressable: a press hands the field the keyboard (grader.tsx). */
154
155
  .grader-field:has(input:placeholder-shown) .btn-arrow:not(:disabled),
155
156
  .grader[data-state="default"] .grader-field .btn-arrow:not(:disabled),
156
157
  .grader[data-state="hover"] .grader-field .btn-arrow:not(:disabled),
@@ -158,7 +159,6 @@
158
159
  .grader[data-state="active"] .grader-field .btn-arrow:not(:disabled) {
159
160
  background: var(--_bg-disabled);
160
161
  color: var(--_glyph-disabled);
161
- pointer-events: none;
162
162
  }
163
163
 
164
164
  /* error — must out-specify the :has() filled/active rules above;
@@ -178,7 +178,6 @@
178
178
  .grader[data-error] .grader-field .btn-arrow:not(:disabled) {
179
179
  background: var(--_bg);
180
180
  color: var(--_glyph);
181
- pointer-events: auto;
182
181
  }
183
182
 
184
183
  /* The box (ks-Grader 64:5612, Index/Search): the field on radius/md, the
@@ -187,9 +186,9 @@
187
186
  the same 40 as md's — the phone's size, where the words would crowd
188
187
  the field. The placeholder reads text/lg at md and sm where the pill's
189
188
  md reads text/md. The design draws the submit in ink while the field
190
- is empty, so the box keeps its chrome there and only stays inert; its
191
- resting hover is bg/300's ring on the resting border, and focus and
192
- filled are the pill's. */
189
+ is empty, so the box keeps its chrome there; pressed, it hands the
190
+ field the keyboard (grader.tsx). Its resting hover is bg/300's ring on
191
+ the resting border, and focus and filled are the pill's. */
193
192
  .grader[data-shape="box"] .grader-field {
194
193
  border-radius: var(--radius-md);
195
194
  padding-inline: var(--space-lg) var(--space-xs);
@@ -320,6 +319,28 @@
320
319
  background: var(--color-bg-100);
321
320
  }
322
321
  }
322
+ /* nudge (motion.css): the submit pressed over typed text with no row
323
+ picked — the menu shakes side to side once, settling, to point at the
324
+ pick to make. grader.tsx drops the attribute on the beat's
325
+ animationend. Nothing on the menu paints during the shake, so moving
326
+ it is safe (motion.css). */
327
+ .grader[data-nudge] .grader-menu {
328
+ animation: grader-nudge var(--motion-nudge-duration) var(--motion-nudge-ease);
329
+ }
330
+ @keyframes grader-nudge {
331
+ 20% {
332
+ translate: calc(-1 * var(--motion-nudge-distance)) 0;
333
+ }
334
+ 40% {
335
+ translate: var(--motion-nudge-distance) 0;
336
+ }
337
+ 60% {
338
+ translate: calc(var(--motion-nudge-distance) / -2) 0;
339
+ }
340
+ 80% {
341
+ translate: calc(var(--motion-nudge-distance) / 2) 0;
342
+ }
343
+ }
323
344
 
324
345
  .grader-option-name,
325
346
  .grader-option-sub {
@@ -1,12 +1,18 @@
1
1
  "use client";
2
2
 
3
3
  /** Business grader search.
4
- * A no-JS submission still opens the Grader search. While results load,
5
- * submission pre-opens a tab inside the user gesture to avoid popup blocking.
4
+ * A no-JS submission still opens the Grader search. With JS, only a
5
+ * suggestion the visitor picked — clicked, or highlighted and entered —
6
+ * opens the Grader: submitting typed text never takes the top result on
7
+ * the visitor's behalf, so an email address or a stray name goes
8
+ * nowhere until a business is chosen from the list. A press on the
9
+ * submit before then leaves the keyboard in the field — and puts it
10
+ * there over an empty one — and shakes the suggestions once, so the
11
+ * visitor sees the pick is theirs to make.
6
12
  * A host that is the Grader itself passes `onChoose` and navigates in place. */
7
13
 
8
- import { useEffect, useId, useRef, useState } from "react";
9
- import type { FocusEvent, FormEvent, KeyboardEvent } from "react";
14
+ import { useId, useRef, useState } from "react";
15
+ import type { FocusEvent, FormEvent, KeyboardEvent, MouseEvent } from "react";
10
16
  import { ButtonArrow } from "./buttons";
11
17
  import { GraderSelectMenu, type GraderMenuLabels } from "./grader-menu";
12
18
  import { IconSparkle } from "../icons";
@@ -43,10 +49,13 @@ interface GraderInputProps {
43
49
 
44
50
  interface ActiveRow {
45
51
  index: number;
46
- /** The query the index belongs to; a new answer resets to the top row. */
52
+ /** The query the index belongs to; a new answer highlights no row. */
47
53
  resultsFor: string;
48
54
  }
49
55
 
56
+ /** No row highlighted: a new answer opens with nothing picked. */
57
+ const NO_ROW = -1;
58
+
50
59
  export function GraderInput({
51
60
  size = "lg",
52
61
  chrome = "teal",
@@ -65,27 +74,31 @@ export function GraderInput({
65
74
  const listId = `${baseId}-list`;
66
75
  const errorId = `${baseId}-error`;
67
76
  const optionId = (index: number) => `${baseId}-opt-${index}`;
77
+ const inputRef = useRef<HTMLInputElement>(null);
68
78
 
69
79
  const [query, setQuery] = useState(defaultValue);
70
80
  const [focused, setFocused] = useState(false);
71
81
  /** Escape hides the menu until the next edit or arrow key. */
72
82
  const [dismissed, setDismissed] = useState(false);
73
- const [active, setActive] = useState<ActiveRow>({ index: 0, resultsFor: "" });
83
+ const [active, setActive] = useState<ActiveRow>({ index: NO_ROW, resultsFor: "" });
74
84
  const [chosen, setChosen] = useState<GraderSuggestion | null>(null);
75
85
  const [error, setError] = useState(false);
76
- const [pending, setPending] = useState(false);
77
- const pendingTab = useRef<Window | null>(null);
78
- /** A submit is waiting on the first ready result. */
79
- const deferred = useRef(false);
86
+ /** Submitted over typed text with no row picked: the menu shakes once
87
+ * to point at the pick to make; cleared when that beat ends. */
88
+ const [nudged, setNudged] = useState(false);
80
89
 
81
90
  const search = useGraderSearch(query, !chosen);
82
91
  const trimmed = query.trim();
92
+ /** The row the visitor highlighted among the current results, or none. */
83
93
  const activeIndex =
84
94
  active.resultsFor === search.resultsFor
85
- ? Math.min(active.index, Math.max(search.results.length - 1, 0))
86
- : 0;
87
- const open = focused && !dismissed && !chosen && !error && !pending && search.results.length > 0;
95
+ ? Math.min(active.index, search.results.length - 1)
96
+ : NO_ROW;
97
+ const open = focused && !dismissed && !chosen && !error && search.results.length > 0;
88
98
  const searching = search.status === "loading";
99
+ const highlighted = open ? search.results[activeIndex] : undefined;
100
+ /** The submit has a business to open: a press scans it. */
101
+ const live = highlighted !== undefined || (chosen !== null && chosen.name === trimmed);
89
102
 
90
103
  const inPlace = Boolean(onChoose);
91
104
 
@@ -101,65 +114,29 @@ export function GraderInput({
101
114
  openGrader(item);
102
115
  }
103
116
 
104
- // Resolve a deferred submission from the first ready result.
105
- if (pending && search.status !== "loading") {
106
- setPending(false);
107
- if (search.status === "ready") {
108
- const match = search.results[0];
109
- if (match) {
110
- setChosen(match);
111
- setQuery(match.name);
112
- } else {
113
- setError(true);
114
- }
115
- }
116
- }
117
-
118
- // Resolve a deferred submission: navigate the pre-opened tab to the
119
- // match, or close it when none exists. In place, the match navigates
120
- // this document instead.
121
- useEffect(() => {
122
- if (pending || !deferred.current) return;
123
- deferred.current = false;
124
- const tab = pendingTab.current;
125
- pendingTab.current = null;
126
- if (inPlace) {
127
- if (chosen) onChoose?.(chosen);
117
+ /** Enter or the submit button: the chosen or highlighted business opens
118
+ * the Grader; typed text alone only shows the suggestions — or says there
119
+ * are none — and waits for a pick; an empty field is handed the keyboard. */
120
+ function submit() {
121
+ if (!trimmed) {
122
+ inputRef.current?.focus();
128
123
  return;
129
124
  }
130
- if (!tab) return;
131
- if (chosen && !tab.closed) {
132
- tab.opener = null;
133
- tab.location.href = graderScanUrl(chosen);
134
- } else {
135
- tab.close();
136
- }
137
- }, [pending, chosen, inPlace, onChoose]);
138
-
139
- // Never leave a blank tab behind if the island unmounts mid-wait.
140
- useEffect(
141
- () => () => {
142
- pendingTab.current?.close();
143
- pendingTab.current = null;
144
- },
145
- [],
146
- );
147
-
148
- function submit() {
149
- if (!trimmed || pending) return;
125
+ if (searching) return;
150
126
  if (chosen && chosen.name === trimmed) {
151
127
  openGrader(chosen);
152
128
  return;
153
129
  }
154
- if (search.status === "loading") {
155
- deferred.current = true;
156
- if (!inPlace) pendingTab.current = window.open("", "_blank");
157
- setPending(true);
130
+ if (search.results.length === 0) {
131
+ setError(true);
158
132
  return;
159
133
  }
160
- const match = search.results[open ? activeIndex : 0];
161
- if (match) choose(match);
162
- else setError(true);
134
+ if (highlighted) {
135
+ choose(highlighted);
136
+ return;
137
+ }
138
+ setDismissed(false);
139
+ setNudged(true);
163
140
  }
164
141
 
165
142
  function onSubmit(e: FormEvent<HTMLFormElement>) {
@@ -167,6 +144,12 @@ export function GraderInput({
167
144
  submit();
168
145
  }
169
146
 
147
+ /** A press on the submit with nothing to open leaves the field focused,
148
+ * so the visitor keeps typing — and keeps the keyboard on a phone. */
149
+ function onSubmitMouseDown(e: MouseEvent<HTMLElement>) {
150
+ if (!live) e.preventDefault();
151
+ }
152
+
170
153
  function onKeyDown(e: KeyboardEvent<HTMLInputElement>) {
171
154
  if (e.nativeEvent.isComposing) return;
172
155
  setFocused(true);
@@ -184,8 +167,14 @@ export function GraderInput({
184
167
  if (!count) return;
185
168
  e.preventDefault();
186
169
  setDismissed(false);
187
- const step = e.key === "ArrowDown" ? 1 : count - 1;
188
- setActive({ index: (activeIndex + step) % count, resultsFor: search.resultsFor });
170
+ // Down from no row lands on the first; up from none or the first wraps to the last.
171
+ const index =
172
+ e.key === "ArrowDown"
173
+ ? (activeIndex + 1) % count
174
+ : activeIndex <= 0
175
+ ? count - 1
176
+ : activeIndex - 1;
177
+ setActive({ index, resultsFor: search.resultsFor });
189
178
  break;
190
179
  }
191
180
  case "Home":
@@ -219,18 +208,23 @@ export function GraderInput({
219
208
  data-error={error ? "" : undefined}
220
209
  data-state={forceState}
221
210
  data-open={open || undefined}
211
+ data-nudge={nudged || undefined}
222
212
  action={`${GRADER_URL}/`}
223
213
  method="get"
224
214
  target={inPlace ? undefined : "_blank"}
225
215
  onSubmit={onSubmit}
226
216
  onFocus={() => setFocused(true)}
227
217
  onBlur={onBlur}
218
+ onAnimationEnd={(e) => {
219
+ if (e.animationName === "grader-nudge") setNudged(false);
220
+ }}
228
221
  >
229
222
  <div className="grader-field ts-text-md-light">
230
223
  <span className="grader-sparkle">
231
224
  <IconSparkle />
232
225
  </span>
233
226
  <input
227
+ ref={inputRef}
234
228
  className="type type-fixed"
235
229
  type="text"
236
230
  name={FIELD_NAME}
@@ -250,7 +244,7 @@ export function GraderInput({
250
244
  aria-busy={searching || undefined}
251
245
  aria-expanded={open}
252
246
  aria-controls={open ? listId : undefined}
253
- aria-activedescendant={open ? optionId(activeIndex) : undefined}
247
+ aria-activedescendant={open && activeIndex !== NO_ROW ? optionId(activeIndex) : undefined}
254
248
  aria-invalid={error || undefined}
255
249
  aria-describedby={error ? errorId : undefined}
256
250
  placeholder={placeholder}
@@ -264,9 +258,9 @@ export function GraderInput({
264
258
  shape={shape}
265
259
  // The box's submit is ink in every state; the pill's goes gray on error.
266
260
  chrome={shape === "box" ? "ink" : error ? "gray" : chrome}
267
- // Show loading during search and deferred hand-off.
268
- loading={pending || searching}
261
+ loading={searching}
269
262
  label={submitLabel}
263
+ onMouseDown={onSubmitMouseDown}
270
264
  />
271
265
  </div>
272
266
  {open && (
package/tokens/motion.css CHANGED
@@ -88,6 +88,12 @@
88
88
  /* Rail cells stagger on open and fade together on close. */
89
89
  --motion-rail-stagger: 40ms;
90
90
 
91
+ /* A nudge: a panel asked to be chosen from shakes side to side once,
92
+ each swing half the last, so the eye lands on it. */
93
+ --motion-nudge-duration: 400ms;
94
+ --motion-nudge-distance: 4px;
95
+ --motion-nudge-ease: var(--motion-drawer-ease-open);
96
+
91
97
  /* Carousel snapping uses the shared slide ease; dragging has no transition. */
92
98
  --motion-snap-dur: 450ms;
93
99
  --motion-snap-ease: var(--motion-slide-ease);