@keystone-sites/marketing-design-system 1.0.22 → 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.22",
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
  );