@keystone-sites/marketing-design-system 1.0.25 → 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 +1 -1
- package/primitives/buttons.tsx +4 -0
- package/primitives/grader.css +27 -6
- package/primitives/grader.tsx +37 -8
- package/tokens/motion.css +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keystone-sites/marketing-design-system",
|
|
3
|
-
"version": "1.0.
|
|
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": {
|
package/primitives/buttons.tsx
CHANGED
|
@@ -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}
|
package/primitives/grader.css
CHANGED
|
@@ -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
|
|
191
|
-
resting hover is bg/300's ring on
|
|
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 {
|
package/primitives/grader.tsx
CHANGED
|
@@ -5,11 +5,14 @@
|
|
|
5
5
|
* suggestion the visitor picked — clicked, or highlighted and entered —
|
|
6
6
|
* opens the Grader: submitting typed text never takes the top result on
|
|
7
7
|
* the visitor's behalf, so an email address or a stray name goes
|
|
8
|
-
* nowhere until a business is chosen from the list.
|
|
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.
|
|
9
12
|
* A host that is the Grader itself passes `onChoose` and navigates in place. */
|
|
10
13
|
|
|
11
|
-
import { useId, useState } from "react";
|
|
12
|
-
import type { FocusEvent, FormEvent, KeyboardEvent } from "react";
|
|
14
|
+
import { useId, useRef, useState } from "react";
|
|
15
|
+
import type { FocusEvent, FormEvent, KeyboardEvent, MouseEvent } from "react";
|
|
13
16
|
import { ButtonArrow } from "./buttons";
|
|
14
17
|
import { GraderSelectMenu, type GraderMenuLabels } from "./grader-menu";
|
|
15
18
|
import { IconSparkle } from "../icons";
|
|
@@ -71,6 +74,7 @@ export function GraderInput({
|
|
|
71
74
|
const listId = `${baseId}-list`;
|
|
72
75
|
const errorId = `${baseId}-error`;
|
|
73
76
|
const optionId = (index: number) => `${baseId}-opt-${index}`;
|
|
77
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
74
78
|
|
|
75
79
|
const [query, setQuery] = useState(defaultValue);
|
|
76
80
|
const [focused, setFocused] = useState(false);
|
|
@@ -79,6 +83,9 @@ export function GraderInput({
|
|
|
79
83
|
const [active, setActive] = useState<ActiveRow>({ index: NO_ROW, resultsFor: "" });
|
|
80
84
|
const [chosen, setChosen] = useState<GraderSuggestion | null>(null);
|
|
81
85
|
const [error, setError] = useState(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);
|
|
82
89
|
|
|
83
90
|
const search = useGraderSearch(query, !chosen);
|
|
84
91
|
const trimmed = query.trim();
|
|
@@ -89,6 +96,9 @@ export function GraderInput({
|
|
|
89
96
|
: NO_ROW;
|
|
90
97
|
const open = focused && !dismissed && !chosen && !error && search.results.length > 0;
|
|
91
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);
|
|
92
102
|
|
|
93
103
|
const inPlace = Boolean(onChoose);
|
|
94
104
|
|
|
@@ -106,9 +116,13 @@ export function GraderInput({
|
|
|
106
116
|
|
|
107
117
|
/** Enter or the submit button: the chosen or highlighted business opens
|
|
108
118
|
* the Grader; typed text alone only shows the suggestions — or says there
|
|
109
|
-
* are none — and waits for a pick. */
|
|
119
|
+
* are none — and waits for a pick; an empty field is handed the keyboard. */
|
|
110
120
|
function submit() {
|
|
111
|
-
if (!trimmed
|
|
121
|
+
if (!trimmed) {
|
|
122
|
+
inputRef.current?.focus();
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (searching) return;
|
|
112
126
|
if (chosen && chosen.name === trimmed) {
|
|
113
127
|
openGrader(chosen);
|
|
114
128
|
return;
|
|
@@ -117,9 +131,12 @@ export function GraderInput({
|
|
|
117
131
|
setError(true);
|
|
118
132
|
return;
|
|
119
133
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
134
|
+
if (highlighted) {
|
|
135
|
+
choose(highlighted);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
setDismissed(false);
|
|
139
|
+
setNudged(true);
|
|
123
140
|
}
|
|
124
141
|
|
|
125
142
|
function onSubmit(e: FormEvent<HTMLFormElement>) {
|
|
@@ -127,6 +144,12 @@ export function GraderInput({
|
|
|
127
144
|
submit();
|
|
128
145
|
}
|
|
129
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
|
+
|
|
130
153
|
function onKeyDown(e: KeyboardEvent<HTMLInputElement>) {
|
|
131
154
|
if (e.nativeEvent.isComposing) return;
|
|
132
155
|
setFocused(true);
|
|
@@ -185,18 +208,23 @@ export function GraderInput({
|
|
|
185
208
|
data-error={error ? "" : undefined}
|
|
186
209
|
data-state={forceState}
|
|
187
210
|
data-open={open || undefined}
|
|
211
|
+
data-nudge={nudged || undefined}
|
|
188
212
|
action={`${GRADER_URL}/`}
|
|
189
213
|
method="get"
|
|
190
214
|
target={inPlace ? undefined : "_blank"}
|
|
191
215
|
onSubmit={onSubmit}
|
|
192
216
|
onFocus={() => setFocused(true)}
|
|
193
217
|
onBlur={onBlur}
|
|
218
|
+
onAnimationEnd={(e) => {
|
|
219
|
+
if (e.animationName === "grader-nudge") setNudged(false);
|
|
220
|
+
}}
|
|
194
221
|
>
|
|
195
222
|
<div className="grader-field ts-text-md-light">
|
|
196
223
|
<span className="grader-sparkle">
|
|
197
224
|
<IconSparkle />
|
|
198
225
|
</span>
|
|
199
226
|
<input
|
|
227
|
+
ref={inputRef}
|
|
200
228
|
className="type type-fixed"
|
|
201
229
|
type="text"
|
|
202
230
|
name={FIELD_NAME}
|
|
@@ -232,6 +260,7 @@ export function GraderInput({
|
|
|
232
260
|
chrome={shape === "box" ? "ink" : error ? "gray" : chrome}
|
|
233
261
|
loading={searching}
|
|
234
262
|
label={submitLabel}
|
|
263
|
+
onMouseDown={onSubmitMouseDown}
|
|
235
264
|
/>
|
|
236
265
|
</div>
|
|
237
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);
|