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

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.
@@ -1,4 +1,4 @@
1
- /** Labeled text, textarea, select, and checkbox field primitives. */
1
+ /** Labeled text, textarea, select, phone, and checkbox field primitives. */
2
2
 
3
3
  import type {
4
4
  InputHTMLAttributes,
@@ -7,6 +7,14 @@ import type {
7
7
  TextareaHTMLAttributes,
8
8
  } from "react";
9
9
  import { IconChevronDownSmall } from "../icons";
10
+ import {
11
+ COUNTRIES,
12
+ countryOf,
13
+ dialCode,
14
+ flagOf,
15
+ formatNational,
16
+ maskPlaceholder,
17
+ } from "../lib/phone";
10
18
 
11
19
  interface FieldShellProps {
12
20
  id: string;
@@ -17,6 +25,8 @@ interface FieldShellProps {
17
25
  labelHidden?: boolean;
18
26
  /** Compact control height for toolbars and dense forms. */
19
27
  compact?: boolean;
28
+ /** The pill, for a sheet whose controls are all round; the box otherwise. */
29
+ shape?: "box" | "pill";
20
30
  /** Error copy; also marks the control invalid. */
21
31
  error?: string | null;
22
32
  children: ReactNode;
@@ -29,6 +39,7 @@ function FieldShell({
29
39
  helpText,
30
40
  labelHidden,
31
41
  compact,
42
+ shape,
32
43
  error,
33
44
  children,
34
45
  }: FieldShellProps) {
@@ -37,6 +48,7 @@ function FieldShell({
37
48
  <div
38
49
  className="ks-field"
39
50
  data-size={compact ? "sm" : undefined}
51
+ data-shape={shape === "pill" ? shape : undefined}
40
52
  data-invalid={error ? "" : undefined}
41
53
  >
42
54
  <label
@@ -82,6 +94,7 @@ type TextInputProps = Omit<InputHTMLAttributes<HTMLInputElement>, "id" | "classN
82
94
  id: string;
83
95
  label: ReactNode;
84
96
  helpText?: string | null;
97
+ shape?: FieldShellProps["shape"];
85
98
  /** Renders the value in the mono face (identifiers, JSON). */
86
99
  mono?: boolean;
87
100
  };
@@ -93,6 +106,7 @@ export function FieldText({
93
106
  required,
94
107
  labelHidden,
95
108
  compact,
109
+ shape,
96
110
  error,
97
111
  mono,
98
112
  ...input
@@ -105,6 +119,7 @@ export function FieldText({
105
119
  helpText={helpText}
106
120
  labelHidden={labelHidden}
107
121
  compact={compact}
122
+ shape={shape}
108
123
  error={error}
109
124
  >
110
125
  <div className="ks-field-control" data-mono={mono || undefined}>
@@ -213,6 +228,101 @@ export function FieldSelect({
213
228
  );
214
229
  }
215
230
 
231
+ interface FieldPhoneProps extends ShellOptions {
232
+ id: string;
233
+ label: ReactNode;
234
+ helpText?: string | null;
235
+ shape?: FieldShellProps["shape"];
236
+ /** ISO country code of the number's country. */
237
+ country: string;
238
+ onCountryChange: (code: string) => void;
239
+ /** The national number as the field shows it (lib/phone.ts formats it). */
240
+ value: string;
241
+ onChange: (value: string) => void;
242
+ /** The country control's accessible name. */
243
+ countryLabel?: string;
244
+ autoFocus?: boolean;
245
+ required?: boolean;
246
+ disabled?: boolean;
247
+ }
248
+
249
+ /** A phone number: the country's flag over a native select of every
250
+ * country, its calling code, then the national number grouped as that
251
+ * country writes it. Reformatting on a country change keeps the digits. */
252
+ export function FieldPhone({
253
+ id,
254
+ label,
255
+ helpText,
256
+ required,
257
+ labelHidden,
258
+ compact,
259
+ shape,
260
+ error,
261
+ country,
262
+ onCountryChange,
263
+ value,
264
+ onChange,
265
+ countryLabel = "Country",
266
+ autoFocus,
267
+ disabled,
268
+ }: FieldPhoneProps) {
269
+ const selected = countryOf(country);
270
+ return (
271
+ <FieldShell
272
+ id={id}
273
+ label={label}
274
+ required={required}
275
+ helpText={helpText}
276
+ labelHidden={labelHidden}
277
+ compact={compact}
278
+ shape={shape}
279
+ error={error}
280
+ >
281
+ <div className="ks-field-control" data-kind="phone">
282
+ <span className="ks-field-country">
283
+ <span className="ks-field-flag" aria-hidden="true">
284
+ {flagOf(country)}
285
+ </span>
286
+ <IconChevronDownSmall className="ks-field-tick" />
287
+ <select
288
+ className="ks-field-country-select"
289
+ aria-label={countryLabel}
290
+ value={country}
291
+ disabled={disabled}
292
+ onChange={(e) => {
293
+ onCountryChange(e.target.value);
294
+ onChange(formatNational(value, countryOf(e.target.value)));
295
+ }}
296
+ >
297
+ {COUNTRIES.map((c) => (
298
+ <option key={c.code} value={c.code}>
299
+ {c.name} ({dialCode(c)})
300
+ </option>
301
+ ))}
302
+ </select>
303
+ </span>
304
+ <span className="ks-field-vr" aria-hidden="true" />
305
+ <span className="type type-fixed ks-field-dial">{dialCode(selected)}</span>
306
+ <input
307
+ className="type type-fixed"
308
+ id={id}
309
+ type="tel"
310
+ inputMode="numeric"
311
+ autoComplete="tel-national"
312
+ value={value}
313
+ onChange={(e) => onChange(formatNational(e.target.value, selected))}
314
+ placeholder={maskPlaceholder(selected)}
315
+ required={required}
316
+ disabled={disabled}
317
+ autoFocus={autoFocus}
318
+ aria-invalid={error ? true : undefined}
319
+ aria-describedby={describedBy(id, helpText, error)}
320
+ />
321
+ </div>
322
+ </FieldShell>
323
+ );
324
+ }
325
+
216
326
  interface FieldCheckboxProps {
217
327
  id: string;
218
328
  name: string;
@@ -0,0 +1,62 @@
1
+ /* GlyphToggle: a round control the height of a small button (the row it
2
+ stands in), on the small gray button's chrome when off and filled with
3
+ ink when on; the glyph, at the small button's icon size, is the only
4
+ content. */
5
+
6
+ :root {
7
+ --glyph-toggle-h: 36px;
8
+ --glyph-toggle-glyph: 16px;
9
+ }
10
+
11
+ .glyph-toggles {
12
+ display: inline-flex;
13
+ align-items: center;
14
+ gap: var(--space-xs);
15
+ }
16
+
17
+ .glyph-toggle {
18
+ appearance: none;
19
+ display: grid;
20
+ place-items: center;
21
+ flex: none;
22
+ width: var(--glyph-toggle-h);
23
+ height: var(--glyph-toggle-h);
24
+ padding: var(--space-none);
25
+ border: 0;
26
+ border-radius: var(--radius-full);
27
+ background: var(--color-bg-300);
28
+ color: var(--color-text-500);
29
+ cursor: pointer;
30
+ transition-property: background-color, color;
31
+ transition-duration: var(--motion-hover-duration);
32
+ transition-timing-function: var(--motion-hover-ease);
33
+ }
34
+ .glyph-toggle svg {
35
+ width: var(--glyph-toggle-glyph);
36
+ height: var(--glyph-toggle-glyph);
37
+ }
38
+ .glyph-toggle[aria-pressed="true"] {
39
+ background: var(--color-text-200);
40
+ color: var(--color-bg-100);
41
+ }
42
+ @media (hover: hover) {
43
+ .glyph-toggle:hover:not(:disabled) {
44
+ background: var(--color-bg-400);
45
+ color: var(--color-text-200);
46
+ }
47
+ .glyph-toggle[aria-pressed="true"]:hover:not(:disabled) {
48
+ background: var(--color-text-100);
49
+ color: var(--color-bg-000);
50
+ }
51
+ }
52
+ .glyph-toggle:focus-visible {
53
+ outline: none;
54
+ box-shadow: 0 0 0 var(--ring-w) var(--color-border-200);
55
+ }
56
+ .glyph-toggle:disabled {
57
+ cursor: wait;
58
+ color: var(--color-text-600);
59
+ }
60
+ .glyph-toggle[aria-pressed="true"]:disabled {
61
+ color: var(--color-bg-300);
62
+ }
@@ -0,0 +1,42 @@
1
+ /** GlyphToggle: a small round control that is on or off, drawn as a glyph
2
+ * alone — the state spoken by `aria-pressed`, the meaning by `label`,
3
+ * which is also its tooltip. A row of them (`GlyphToggles`) sits where a
4
+ * line of text would. Styles in glyph-toggle.css. */
5
+
6
+ import type { ReactNode } from "react";
7
+ import { Tooltip } from "./tooltip";
8
+
9
+ interface GlyphToggleProps {
10
+ /** The glyph (an icons.tsx line glyph). */
11
+ children: ReactNode;
12
+ /** Spoken, and the tooltip: what being on means. */
13
+ label: string;
14
+ pressed: boolean;
15
+ disabled?: boolean;
16
+ onClick: () => void;
17
+ }
18
+
19
+ export function GlyphToggle({ children, label, pressed, disabled, onClick }: GlyphToggleProps) {
20
+ return (
21
+ <Tooltip label={label}>
22
+ <button
23
+ type="button"
24
+ className="glyph-toggle"
25
+ aria-pressed={pressed}
26
+ aria-label={label}
27
+ disabled={disabled}
28
+ onClick={onClick}
29
+ >
30
+ {children}
31
+ </button>
32
+ </Tooltip>
33
+ );
34
+ }
35
+
36
+ export function GlyphToggles({ children, label }: { children: ReactNode; label: string }) {
37
+ return (
38
+ <span className="glyph-toggles" role="group" aria-label={label}>
39
+ {children}
40
+ </span>
41
+ );
42
+ }
@@ -253,6 +253,10 @@
253
253
  border: 1px solid var(--color-border-000);
254
254
  border-radius: var(--radius-xl);
255
255
  box-shadow: var(--shadow-hard-square-md);
256
+ /* A long result list scrolls inside the menu rather than running
257
+ past the viewport. */
258
+ max-height: min(22rem, 50dvh);
259
+ overflow-y: auto;
256
260
  }
257
261
  /* Large pills use a larger menu gap; small pills a smaller menu type. */
258
262
  @container style(--grader-size: lg) {
@@ -6,6 +6,7 @@
6
6
  --z-portal: 9999;
7
7
  --modal-close: 32px;
8
8
  --modal-mark: 44px;
9
+ --modal-scrim-blur: 3px;
9
10
  }
10
11
 
11
12
  .modal {
@@ -31,13 +32,15 @@
31
32
  animation: modal-dim var(--motion-rise-duration) var(--motion-drawer-ease) both;
32
33
  }
33
34
  .modal-sheet {
35
+ --_pad: var(--space-3xl);
34
36
  position: relative;
37
+ display: flex;
38
+ flex-direction: column;
35
39
  box-sizing: border-box;
36
40
  width: 100%;
37
41
  max-width: 28rem;
38
42
  max-height: calc(100dvh - var(--space-2xl) * 2);
39
43
  overflow-y: auto;
40
- padding: var(--space-3xl);
41
44
  border: 1px solid var(--color-border-050);
42
45
  border-radius: var(--radius-3xl);
43
46
  background: var(--color-bg-200);
@@ -46,18 +49,53 @@
46
49
  outline: none;
47
50
  animation: modal-pop var(--motion-rise-duration) var(--motion-drawer-ease) both;
48
51
  }
52
+ .modal-body {
53
+ padding: var(--_pad);
54
+ }
55
+ .modal-sheet[data-size="xs"] {
56
+ max-width: 25rem;
57
+ --_pad: var(--space-4xl);
58
+ }
59
+ /* The small sheet's body sits a touch deeper above than below. */
60
+ .modal-sheet[data-size="xs"] .modal-body {
61
+ padding-block: calc(var(--space-4xl) + var(--space-xs)) calc(var(--space-3xl) + var(--space-xs));
62
+ }
49
63
  .modal-sheet[data-size="md"] {
50
64
  max-width: 36rem;
51
65
  }
52
66
  .modal-sheet[data-size="lg"] {
53
67
  max-width: 64rem;
54
- padding: var(--space-2xl);
68
+ --_pad: var(--space-2xl);
55
69
  }
56
70
  @container (--rt) {
57
71
  .modal-sheet[data-size="lg"] {
58
- padding: var(--space-3xl);
72
+ --_pad: var(--space-3xl);
59
73
  }
60
74
  }
75
+
76
+ /* The foot: ruled off, quieter, centred. */
77
+ .modal-foot {
78
+ display: flex;
79
+ flex-direction: column;
80
+ align-items: center;
81
+ gap: var(--space-md);
82
+ padding: var(--space-xl) var(--space-3xl);
83
+ border-top: 1px solid var(--color-border-000);
84
+ text-align: center;
85
+ }
86
+
87
+ /* Ink backdrop: the page dims and blurs; the sheet sits on the page
88
+ ground, tighter-cornered, under a long soft drop and no hairline. */
89
+ .modal[data-backdrop="ink"] .modal-backdrop {
90
+ background: var(--color-scrim);
91
+ backdrop-filter: blur(var(--modal-scrim-blur));
92
+ }
93
+ .modal[data-backdrop="ink"] .modal-sheet {
94
+ border: 0;
95
+ border-radius: var(--radius-2xl);
96
+ background: var(--color-bg-100);
97
+ box-shadow: var(--shadow-sheet);
98
+ }
61
99
  .modal-close {
62
100
  appearance: none;
63
101
  position: absolute;
@@ -15,12 +15,24 @@ interface ModalProps {
15
15
  /** Names the dialog for assistive technology. */
16
16
  label: string;
17
17
  onClose: () => void;
18
- /** Sheet width: sm for prompts, md for forms, lg for records. */
19
- size?: "sm" | "md" | "lg";
18
+ /** Sheet width: xs for a sign-in, sm for prompts, md for forms, lg for records. */
19
+ size?: "xs" | "sm" | "md" | "lg";
20
+ /** The page behind: lightened to paper, or dimmed to ink and blurred
21
+ * under a sheet on the page ground with a long soft drop. */
22
+ backdrop?: "paper" | "ink";
23
+ /** A band under the body, ruled off from it: a seal, the small print. */
24
+ foot?: ReactNode;
20
25
  children: ReactNode;
21
26
  }
22
27
 
23
- export function Modal({ label, onClose, size = "sm", children }: ModalProps) {
28
+ export function Modal({
29
+ label,
30
+ onClose,
31
+ size = "sm",
32
+ backdrop = "paper",
33
+ foot,
34
+ children,
35
+ }: ModalProps) {
24
36
  const sheetRef = useRef<HTMLDivElement>(null);
25
37
  const openerRef = useRef<Element | null>(null);
26
38
 
@@ -50,7 +62,7 @@ export function Modal({ label, onClose, size = "sm", children }: ModalProps) {
50
62
  }, [onClose]);
51
63
 
52
64
  return createPortal(
53
- <div className="modal">
65
+ <div className="modal" data-backdrop={backdrop === "ink" ? backdrop : undefined}>
54
66
  <button type="button" className="modal-backdrop" aria-label="Close" onClick={onClose} />
55
67
  <div
56
68
  ref={sheetRef}
@@ -64,7 +76,8 @@ export function Modal({ label, onClose, size = "sm", children }: ModalProps) {
64
76
  <button type="button" className="modal-close" aria-label="Close" onClick={onClose}>
65
77
  <IconGalleryClose />
66
78
  </button>
67
- {children}
79
+ <div className="modal-body">{children}</div>
80
+ {foot ? <div className="modal-foot">{foot}</div> : null}
68
81
  </div>
69
82
  </div>,
70
83
  document.body,
@@ -0,0 +1,56 @@
1
+ /* Tooltip: the platform's dark pill, 8px off the trigger. In, it fades and
2
+ grows from 0.85 over 140ms; out, it fades and shrinks back over 100ms.
3
+ Reduced motion snaps both. The anchor wraps the trigger and is the pill's
4
+ positioning root. */
5
+
6
+ :root {
7
+ --tooltip-offset: 8px;
8
+ --tooltip-in-duration: 140ms;
9
+ --tooltip-out-duration: 100ms;
10
+ }
11
+
12
+ .tooltip-anchor {
13
+ position: relative;
14
+ display: inline-flex;
15
+ }
16
+
17
+ .tooltip {
18
+ position: absolute;
19
+ left: 50%;
20
+ z-index: var(--z-raised);
21
+ padding: var(--space-xs) var(--space-md);
22
+ border-radius: var(--radius-md);
23
+ background: var(--color-text-100);
24
+ color: var(--color-bg-100);
25
+ white-space: nowrap;
26
+ pointer-events: none;
27
+ opacity: 0;
28
+ visibility: hidden;
29
+ translate: -50% 0;
30
+ scale: 0.85;
31
+ transition-property: opacity, scale, visibility;
32
+ transition-duration: var(--tooltip-out-duration), var(--tooltip-out-duration), 0s;
33
+ transition-delay: 0s, 0s, var(--tooltip-out-duration);
34
+ transition-timing-function: ease-out;
35
+ }
36
+ .tooltip[data-placement="top"] {
37
+ bottom: calc(100% + var(--tooltip-offset));
38
+ transform-origin: bottom center;
39
+ }
40
+ .tooltip[data-placement="bottom"] {
41
+ top: calc(100% + var(--tooltip-offset));
42
+ transform-origin: top center;
43
+ }
44
+ .tooltip[data-open] {
45
+ opacity: 1;
46
+ visibility: visible;
47
+ scale: 1;
48
+ transition-duration: var(--tooltip-in-duration), var(--tooltip-in-duration), 0s;
49
+ transition-delay: 0s;
50
+ }
51
+ @media (prefers-reduced-motion: reduce) {
52
+ .tooltip {
53
+ transition: none;
54
+ scale: 1;
55
+ }
56
+ }
@@ -0,0 +1,103 @@
1
+ "use client";
2
+
3
+ /** Tooltip: the platform's dark pill (keystone-console's
4
+ * `keystone-design-system` Tooltip), ported without react-aria. A word on
5
+ * a control that shows on hover after a short delay and on keyboard
6
+ * focus, closes on leave, blur and Escape, and describes the trigger to
7
+ * assistive tech; an icon-only trigger still carries its own
8
+ * `aria-label`. Styles in tooltip.css. */
9
+
10
+ import {
11
+ type KeyboardEvent,
12
+ type PointerEvent,
13
+ type ReactElement,
14
+ type ReactNode,
15
+ cloneElement,
16
+ useEffect,
17
+ useId,
18
+ useRef,
19
+ useState,
20
+ } from "react";
21
+
22
+ export type TooltipPlacement = "top" | "bottom";
23
+
24
+ interface TooltipProps {
25
+ /** Tooltip text. */
26
+ label: ReactNode;
27
+ /** The trigger: one focusable element; it is given `aria-describedby`. */
28
+ children: ReactElement<{ "aria-describedby"?: string }>;
29
+ /** Which side of the trigger. */
30
+ placement?: TooltipPlacement;
31
+ /** Hover open delay in ms — the anti-flicker as a cursor passes through. */
32
+ delay?: number;
33
+ }
34
+
35
+ /* The platform's: hover opens after 100ms, focus at once. */
36
+ const OPEN_DELAY_MS = 100;
37
+
38
+ export function Tooltip({
39
+ label,
40
+ children,
41
+ placement = "top",
42
+ delay = OPEN_DELAY_MS,
43
+ }: TooltipProps) {
44
+ const id = useId();
45
+ const [open, setOpen] = useState(false);
46
+ const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
47
+ // A focus that a press brought is the press's, not the keyboard's.
48
+ const pressed = useRef(false);
49
+
50
+ const clear = () => {
51
+ if (timer.current !== null) clearTimeout(timer.current);
52
+ timer.current = null;
53
+ };
54
+ useEffect(() => clear, []);
55
+
56
+ const show = () => {
57
+ clear();
58
+ setOpen(true);
59
+ };
60
+ const hide = () => {
61
+ clear();
62
+ setOpen(false);
63
+ };
64
+ const onPointerEnter = (event: PointerEvent) => {
65
+ // A finger shows nothing: the label is the control's own.
66
+ if (event.pointerType !== "mouse") return;
67
+ clear();
68
+ timer.current = setTimeout(show, delay);
69
+ };
70
+ const onPointerDown = () => {
71
+ pressed.current = true;
72
+ };
73
+ const onFocus = () => {
74
+ if (!pressed.current) show();
75
+ pressed.current = false;
76
+ };
77
+ const onKeyDown = (event: KeyboardEvent) => {
78
+ if (event.key === "Escape") hide();
79
+ };
80
+
81
+ return (
82
+ <span
83
+ className="tooltip-anchor"
84
+ onPointerEnter={onPointerEnter}
85
+ onPointerLeave={hide}
86
+ onPointerDown={onPointerDown}
87
+ onFocus={onFocus}
88
+ onBlur={hide}
89
+ onKeyDown={onKeyDown}
90
+ >
91
+ {cloneElement(children, { "aria-describedby": id })}
92
+ <span
93
+ role="tooltip"
94
+ id={id}
95
+ className="type type-fixed ts-text-xs-medium tooltip"
96
+ data-placement={placement}
97
+ data-open={open || undefined}
98
+ >
99
+ {label}
100
+ </span>
101
+ </span>
102
+ );
103
+ }
@@ -122,6 +122,10 @@
122
122
  --shadow-hard-square-md-0: 0 0 0 0 var(--shadow-ink);
123
123
  /* The web-swatch hairline uses palette ink, unlike hard shadows. */
124
124
  --shadow-web-swatch: 0 1px 2px 0 rgba(108, 104, 96, 0.05);
125
+ /* A sheet lifted over a dimmed page (ks-Grader 254:15012): a long soft
126
+ drop in the same warm near-black; the scrim is that ink at 55%. */
127
+ --shadow-sheet: 0 28px 80px -20px rgba(42, 36, 29, 0.5);
128
+ --color-scrim: rgba(42, 36, 29, 0.55);
125
129
  }
126
130
 
127
131
  /* Constants shared by more than one file. Section-local constants live