@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.
- package/icons.tsx +22 -0
- package/index.css +4 -0
- package/lib/phone.ts +294 -0
- package/package.json +10 -1
- package/primitives/business-picker.css +120 -0
- package/primitives/business-picker.tsx +234 -0
- package/primitives/buttons.css +16 -0
- package/primitives/buttons.tsx +11 -4
- package/primitives/chip.css +121 -0
- package/primitives/chip.tsx +45 -0
- package/primitives/field.css +54 -0
- package/primitives/field.tsx +111 -1
- package/primitives/glyph-toggle.css +62 -0
- package/primitives/glyph-toggle.tsx +42 -0
- package/primitives/grader.css +4 -0
- package/primitives/modal.css +41 -3
- package/primitives/modal.tsx +18 -5
- package/primitives/tooltip.css +56 -0
- package/primitives/tooltip.tsx +103 -0
- package/tokens/semantic.css +4 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
/** Business picker: a set of businesses chosen from the grader's search,
|
|
4
|
+
* as many as the host allows. The chosen ones stand as chips in the
|
|
5
|
+
* field; typing searches Google Places and the web and the menu's pick
|
|
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. */
|
|
10
|
+
|
|
11
|
+
import { useId, useState, type FocusEvent, type KeyboardEvent, type ReactNode } from "react";
|
|
12
|
+
import { IconSearchGlyph } from "../icons";
|
|
13
|
+
import type { GraderSuggestion } from "../lib/grader";
|
|
14
|
+
import { useGraderSearch } from "../lib/use-grader-search";
|
|
15
|
+
import { Chip, ChipAdd } from "./chip";
|
|
16
|
+
import { GraderSelectMenu, type GraderMenuLabels } from "./grader-menu";
|
|
17
|
+
import { Spinner } from "./status";
|
|
18
|
+
|
|
19
|
+
const GROUP_LABELS: GraderMenuLabels = { places: "Google Places", web: "Websites" };
|
|
20
|
+
|
|
21
|
+
interface BusinessPickerProps {
|
|
22
|
+
id: string;
|
|
23
|
+
label: ReactNode;
|
|
24
|
+
/** Shown while nothing is typed; the field's invitation. */
|
|
25
|
+
placeholder: string;
|
|
26
|
+
chosen: readonly GraderSuggestion[];
|
|
27
|
+
onChange: (next: GraderSuggestion[]) => void;
|
|
28
|
+
/** Businesses offered for one tap; those already chosen are not shown. */
|
|
29
|
+
offers?: readonly GraderSuggestion[];
|
|
30
|
+
/** Names the offers row, when there is one. */
|
|
31
|
+
offersLabel?: string;
|
|
32
|
+
/** The most that may be chosen; the field closes once reached. */
|
|
33
|
+
max?: number;
|
|
34
|
+
/** The suggestion listbox's accessible name. */
|
|
35
|
+
menuLabel?: string;
|
|
36
|
+
groupLabels?: GraderMenuLabels;
|
|
37
|
+
/** Spoken on a chip's remove control and an offer's add control. */
|
|
38
|
+
removeLabel?: (name: string) => string;
|
|
39
|
+
addLabel?: (name: string) => string;
|
|
40
|
+
error?: string | null;
|
|
41
|
+
autoFocus?: boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface ActiveRow {
|
|
45
|
+
index: number;
|
|
46
|
+
resultsFor: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The address trimmed to what tells one business from its namesake:
|
|
50
|
+
* the street, or the website's domain. */
|
|
51
|
+
function contextOf(item: GraderSuggestion): string {
|
|
52
|
+
if (item.address) return item.address.split(",")[0]?.trim() ?? "";
|
|
53
|
+
return item.website?.replace(/^https?:\/\//, "").replace(/\/.*$/, "") ?? "";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function BusinessPicker({
|
|
57
|
+
id,
|
|
58
|
+
label,
|
|
59
|
+
placeholder,
|
|
60
|
+
chosen,
|
|
61
|
+
onChange,
|
|
62
|
+
offers = [],
|
|
63
|
+
offersLabel,
|
|
64
|
+
max = Infinity,
|
|
65
|
+
menuLabel = "Business suggestions",
|
|
66
|
+
groupLabels = GROUP_LABELS,
|
|
67
|
+
removeLabel = (name) => `Remove ${name}`,
|
|
68
|
+
addLabel = (name) => `Add ${name}`,
|
|
69
|
+
error,
|
|
70
|
+
autoFocus,
|
|
71
|
+
}: BusinessPickerProps) {
|
|
72
|
+
const baseId = useId();
|
|
73
|
+
const listId = `${baseId}-list`;
|
|
74
|
+
const errorId = `${id}-error`;
|
|
75
|
+
const optionId = (index: number) => `${baseId}-opt-${index}`;
|
|
76
|
+
|
|
77
|
+
const [query, setQuery] = useState("");
|
|
78
|
+
const [focused, setFocused] = useState(false);
|
|
79
|
+
const [dismissed, setDismissed] = useState(false);
|
|
80
|
+
const [active, setActive] = useState<ActiveRow>({ index: 0, resultsFor: "" });
|
|
81
|
+
|
|
82
|
+
const full = chosen.length >= max;
|
|
83
|
+
const search = useGraderSearch(query, !full);
|
|
84
|
+
const activeIndex =
|
|
85
|
+
active.resultsFor === search.resultsFor
|
|
86
|
+
? Math.min(active.index, Math.max(search.results.length - 1, 0))
|
|
87
|
+
: 0;
|
|
88
|
+
const open = focused && !dismissed && !full && search.results.length > 0;
|
|
89
|
+
const searching = search.status === "loading";
|
|
90
|
+
const has = (item: GraderSuggestion) => chosen.some((c) => c.id === item.id);
|
|
91
|
+
const pending = offers.filter((o) => !has(o));
|
|
92
|
+
|
|
93
|
+
function add(item: GraderSuggestion) {
|
|
94
|
+
if (full || has(item)) return;
|
|
95
|
+
onChange([...chosen, item]);
|
|
96
|
+
setQuery("");
|
|
97
|
+
setDismissed(false);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function remove(item: GraderSuggestion) {
|
|
101
|
+
onChange(chosen.filter((c) => c.id !== item.id));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function onKeyDown(e: KeyboardEvent<HTMLInputElement>) {
|
|
105
|
+
if (e.nativeEvent.isComposing) return;
|
|
106
|
+
const count = search.results.length;
|
|
107
|
+
switch (e.key) {
|
|
108
|
+
case "ArrowDown":
|
|
109
|
+
case "ArrowUp": {
|
|
110
|
+
if (!count) return;
|
|
111
|
+
e.preventDefault();
|
|
112
|
+
setDismissed(false);
|
|
113
|
+
const step = e.key === "ArrowDown" ? 1 : count - 1;
|
|
114
|
+
setActive({ index: (activeIndex + step) % count, resultsFor: search.resultsFor });
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
case "Enter": {
|
|
118
|
+
// The picker lives inside a form: Enter picks, never submits.
|
|
119
|
+
e.preventDefault();
|
|
120
|
+
const match = open ? search.results[activeIndex] : undefined;
|
|
121
|
+
if (match) add(match);
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
case "Escape":
|
|
125
|
+
if (!open) return;
|
|
126
|
+
e.preventDefault();
|
|
127
|
+
setDismissed(true);
|
|
128
|
+
break;
|
|
129
|
+
default:
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function onBlur(e: FocusEvent<HTMLDivElement>) {
|
|
135
|
+
if (e.currentTarget.contains(e.relatedTarget)) return;
|
|
136
|
+
setFocused(false);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return (
|
|
140
|
+
<div
|
|
141
|
+
className="picker"
|
|
142
|
+
data-invalid={error ? "" : undefined}
|
|
143
|
+
data-open={open || undefined}
|
|
144
|
+
onFocus={() => setFocused(true)}
|
|
145
|
+
onBlur={onBlur}
|
|
146
|
+
>
|
|
147
|
+
<label className="type type-fixed ts-text-sm-medium picker-label" htmlFor={id}>
|
|
148
|
+
{label}
|
|
149
|
+
</label>
|
|
150
|
+
<div className="picker-box">
|
|
151
|
+
<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
|
+
)}
|
|
166
|
+
{!full && (
|
|
167
|
+
<span className="picker-entry">
|
|
168
|
+
<IconSearchGlyph className="picker-glyph" />
|
|
169
|
+
<input
|
|
170
|
+
className="type type-fixed"
|
|
171
|
+
id={id}
|
|
172
|
+
type="text"
|
|
173
|
+
value={query}
|
|
174
|
+
onChange={(e) => {
|
|
175
|
+
setQuery(e.target.value);
|
|
176
|
+
setFocused(true);
|
|
177
|
+
setDismissed(false);
|
|
178
|
+
}}
|
|
179
|
+
onKeyDown={onKeyDown}
|
|
180
|
+
role="combobox"
|
|
181
|
+
aria-autocomplete="list"
|
|
182
|
+
aria-busy={searching || undefined}
|
|
183
|
+
aria-expanded={open}
|
|
184
|
+
aria-controls={open ? listId : undefined}
|
|
185
|
+
aria-activedescendant={open ? optionId(activeIndex) : undefined}
|
|
186
|
+
aria-invalid={error ? true : undefined}
|
|
187
|
+
aria-describedby={error ? errorId : undefined}
|
|
188
|
+
placeholder={chosen.length ? "" : placeholder}
|
|
189
|
+
autoComplete="off"
|
|
190
|
+
autoCorrect="off"
|
|
191
|
+
spellCheck={false}
|
|
192
|
+
autoFocus={autoFocus}
|
|
193
|
+
/>
|
|
194
|
+
{searching && <Spinner size="sm" />}
|
|
195
|
+
</span>
|
|
196
|
+
)}
|
|
197
|
+
</div>
|
|
198
|
+
{open && (
|
|
199
|
+
<GraderSelectMenu
|
|
200
|
+
id={listId}
|
|
201
|
+
label={menuLabel}
|
|
202
|
+
groups={search.groups}
|
|
203
|
+
groupLabels={groupLabels}
|
|
204
|
+
activeIndex={activeIndex}
|
|
205
|
+
optionId={optionId}
|
|
206
|
+
onActivate={(index) => setActive({ index, resultsFor: search.resultsFor })}
|
|
207
|
+
onChoose={add}
|
|
208
|
+
/>
|
|
209
|
+
)}
|
|
210
|
+
</div>
|
|
211
|
+
{pending.length > 0 && !full && (
|
|
212
|
+
<div className="picker-offers">
|
|
213
|
+
{offersLabel ? (
|
|
214
|
+
<span className="type type-fixed ts-text-xs-regular picker-offers-label">
|
|
215
|
+
{offersLabel}
|
|
216
|
+
</span>
|
|
217
|
+
) : 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>
|
|
225
|
+
</div>
|
|
226
|
+
)}
|
|
227
|
+
{error ? (
|
|
228
|
+
<p className="type type-fixed ts-text-sm-light picker-error" id={errorId} role="alert">
|
|
229
|
+
{error}
|
|
230
|
+
</p>
|
|
231
|
+
) : null}
|
|
232
|
+
</div>
|
|
233
|
+
);
|
|
234
|
+
}
|
package/primitives/buttons.css
CHANGED
|
@@ -87,6 +87,13 @@
|
|
|
87
87
|
.btn-fill[data-shape="box"] .btn-body {
|
|
88
88
|
padding-inline: var(--_pl-box) var(--_pr-box);
|
|
89
89
|
}
|
|
90
|
+
/* No arrow: the label sits centred between equal pads. */
|
|
91
|
+
.btn-fill[data-glyph="none"] .btn-body {
|
|
92
|
+
padding-inline: var(--_pl);
|
|
93
|
+
}
|
|
94
|
+
.btn-fill[data-glyph="none"][data-shape="box"] .btn-body {
|
|
95
|
+
padding-inline: var(--_pl-box);
|
|
96
|
+
}
|
|
90
97
|
.btn-ghost .btn-body {
|
|
91
98
|
padding-inline: var(--_px);
|
|
92
99
|
gap: var(--_gap, var(--space-md));
|
|
@@ -202,6 +209,15 @@
|
|
|
202
209
|
--_ink: var(--color-text-200);
|
|
203
210
|
--_glyph: var(--color-text-500);
|
|
204
211
|
}
|
|
212
|
+
/* The sign-in sheet's button (ks-Grader 254:15012): text/200 ink under
|
|
213
|
+
the page ground's type; hover deepens one step, as the arrow's ink does. */
|
|
214
|
+
.btn-fill[data-chrome="ink"] {
|
|
215
|
+
--_bg: var(--color-text-200);
|
|
216
|
+
--_bg-hover: var(--color-text-100);
|
|
217
|
+
--_ring: var(--color-border-200);
|
|
218
|
+
--_ink: var(--color-bg-100);
|
|
219
|
+
--_glyph: var(--color-bg-300);
|
|
220
|
+
}
|
|
205
221
|
/* The Scale plan's button (1129:17842): blue/250 on blue/800. Hover and
|
|
206
222
|
ring step one swatch like the teal chrome; the design draws rest only. */
|
|
207
223
|
.btn-fill[data-chrome="blue"] {
|
package/primitives/buttons.tsx
CHANGED
|
@@ -18,7 +18,7 @@ type GhostSize = FillSize | "xs";
|
|
|
18
18
|
|
|
19
19
|
interface ButtonFillProps {
|
|
20
20
|
size?: FillSize;
|
|
21
|
-
chrome?: "teal" | "gray" | "blue";
|
|
21
|
+
chrome?: "teal" | "gray" | "blue" | "ink";
|
|
22
22
|
shape?: "pill" | "box";
|
|
23
23
|
type?: "button" | "submit";
|
|
24
24
|
/** Renders link chrome when provided. */
|
|
@@ -30,6 +30,8 @@ interface ButtonFillProps {
|
|
|
30
30
|
disabled?: boolean;
|
|
31
31
|
/** Fill the container's inline size (form submits, product sheets). */
|
|
32
32
|
stretch?: boolean;
|
|
33
|
+
/** The trailing arrow; off for a plain label (a sheet's submit). */
|
|
34
|
+
glyph?: boolean;
|
|
33
35
|
forceState?: ForceableState;
|
|
34
36
|
/** An island's own handler; pages prefer `action`. */
|
|
35
37
|
onClick?: MouseEventHandler<HTMLElement>;
|
|
@@ -51,6 +53,7 @@ export function ButtonFill({
|
|
|
51
53
|
action,
|
|
52
54
|
disabled = false,
|
|
53
55
|
stretch = false,
|
|
56
|
+
glyph = true,
|
|
54
57
|
forceState,
|
|
55
58
|
onClick,
|
|
56
59
|
attrs,
|
|
@@ -59,9 +62,11 @@ export function ButtonFill({
|
|
|
59
62
|
const label = (
|
|
60
63
|
<span className="type type-fixed btn-body">
|
|
61
64
|
{children}
|
|
62
|
-
|
|
63
|
-
<
|
|
64
|
-
|
|
65
|
+
{glyph && (
|
|
66
|
+
<span className="btn-glyph">
|
|
67
|
+
<IconNavTrigger variant="arrow" />
|
|
68
|
+
</span>
|
|
69
|
+
)}
|
|
65
70
|
</span>
|
|
66
71
|
);
|
|
67
72
|
if (href !== undefined) {
|
|
@@ -73,6 +78,7 @@ export function ButtonFill({
|
|
|
73
78
|
data-chrome={chrome}
|
|
74
79
|
data-shape={shape}
|
|
75
80
|
data-stretch={stretch ? "" : undefined}
|
|
81
|
+
data-glyph={glyph ? undefined : "none"}
|
|
76
82
|
data-state={forceState}
|
|
77
83
|
data-action={action}
|
|
78
84
|
onClick={onClick}
|
|
@@ -91,6 +97,7 @@ export function ButtonFill({
|
|
|
91
97
|
data-chrome={chrome}
|
|
92
98
|
data-shape={shape}
|
|
93
99
|
data-stretch={stretch ? "" : undefined}
|
|
100
|
+
data-glyph={glyph ? undefined : "none"}
|
|
94
101
|
data-state={forceState}
|
|
95
102
|
data-action={action}
|
|
96
103
|
disabled={disabled}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/* Chip: a round token on the paper surface — the name, an optional run-on
|
|
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. */
|
|
5
|
+
|
|
6
|
+
:root {
|
|
7
|
+
--chip-h: 32px;
|
|
8
|
+
--chip-remove: 20px;
|
|
9
|
+
--chip-plus: 10px;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.chip {
|
|
13
|
+
display: inline-flex;
|
|
14
|
+
align-items: center;
|
|
15
|
+
box-sizing: border-box;
|
|
16
|
+
max-width: 100%;
|
|
17
|
+
min-height: var(--chip-h);
|
|
18
|
+
gap: var(--space-xs);
|
|
19
|
+
padding-inline: var(--space-lg) var(--space-sm);
|
|
20
|
+
border: 1px solid var(--color-border-000);
|
|
21
|
+
border-radius: var(--radius-full);
|
|
22
|
+
background: var(--color-bg-000);
|
|
23
|
+
color: var(--color-text-200);
|
|
24
|
+
}
|
|
25
|
+
.chip-body {
|
|
26
|
+
display: inline-flex;
|
|
27
|
+
align-items: baseline;
|
|
28
|
+
min-width: 0;
|
|
29
|
+
gap: var(--space-sm);
|
|
30
|
+
}
|
|
31
|
+
.chip-name,
|
|
32
|
+
.chip-sub {
|
|
33
|
+
display: block;
|
|
34
|
+
min-width: 0;
|
|
35
|
+
overflow: hidden;
|
|
36
|
+
white-space: nowrap;
|
|
37
|
+
text-overflow: ellipsis;
|
|
38
|
+
}
|
|
39
|
+
.chip-sub {
|
|
40
|
+
color: var(--color-text-400);
|
|
41
|
+
}
|
|
42
|
+
.chip-remove {
|
|
43
|
+
appearance: none;
|
|
44
|
+
display: grid;
|
|
45
|
+
place-items: center;
|
|
46
|
+
flex: none;
|
|
47
|
+
width: var(--chip-remove);
|
|
48
|
+
height: var(--chip-remove);
|
|
49
|
+
border: 0;
|
|
50
|
+
border-radius: var(--radius-full);
|
|
51
|
+
padding: var(--space-none);
|
|
52
|
+
background: transparent;
|
|
53
|
+
color: var(--color-text-400);
|
|
54
|
+
cursor: pointer;
|
|
55
|
+
transition-property: background-color, color;
|
|
56
|
+
transition-duration: var(--motion-hover-duration);
|
|
57
|
+
transition-timing-function: var(--motion-hover-ease);
|
|
58
|
+
}
|
|
59
|
+
.chip-remove svg {
|
|
60
|
+
width: var(--chip-plus);
|
|
61
|
+
height: var(--chip-plus);
|
|
62
|
+
}
|
|
63
|
+
@media (hover: hover) {
|
|
64
|
+
.chip-remove:hover {
|
|
65
|
+
background: var(--color-bg-300);
|
|
66
|
+
color: var(--color-text-100);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
.chip-remove:focus-visible {
|
|
70
|
+
outline: none;
|
|
71
|
+
box-shadow: 0 0 0 var(--ring-w) var(--color-teal-200);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* The offer: dashed, quieter ink, a plus in place of the remove. */
|
|
75
|
+
.chip-add {
|
|
76
|
+
appearance: none;
|
|
77
|
+
padding-inline: var(--space-md) var(--space-lg);
|
|
78
|
+
border-style: dashed;
|
|
79
|
+
border-color: var(--color-border-100);
|
|
80
|
+
background: transparent;
|
|
81
|
+
color: var(--color-text-300);
|
|
82
|
+
cursor: pointer;
|
|
83
|
+
transition-property: border-color, background-color, color;
|
|
84
|
+
transition-duration: var(--motion-hover-duration);
|
|
85
|
+
transition-timing-function: var(--motion-hover-ease);
|
|
86
|
+
}
|
|
87
|
+
.chip-plus {
|
|
88
|
+
position: relative;
|
|
89
|
+
flex: none;
|
|
90
|
+
width: var(--chip-plus);
|
|
91
|
+
height: var(--chip-plus);
|
|
92
|
+
}
|
|
93
|
+
.chip-plus::before,
|
|
94
|
+
.chip-plus::after {
|
|
95
|
+
content: "";
|
|
96
|
+
position: absolute;
|
|
97
|
+
inset: 0;
|
|
98
|
+
margin: auto;
|
|
99
|
+
background: currentColor;
|
|
100
|
+
border-radius: var(--radius-full);
|
|
101
|
+
}
|
|
102
|
+
.chip-plus::before {
|
|
103
|
+
width: 100%;
|
|
104
|
+
height: 1.5px;
|
|
105
|
+
}
|
|
106
|
+
.chip-plus::after {
|
|
107
|
+
width: 1.5px;
|
|
108
|
+
height: 100%;
|
|
109
|
+
}
|
|
110
|
+
@media (hover: hover) {
|
|
111
|
+
.chip-add:hover {
|
|
112
|
+
border-color: var(--color-teal-300);
|
|
113
|
+
background: var(--color-teal-100);
|
|
114
|
+
color: var(--color-text-100);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
.chip-add:focus-visible {
|
|
118
|
+
outline: none;
|
|
119
|
+
border-color: var(--color-teal-300);
|
|
120
|
+
box-shadow: 0 0 0 var(--ring-w) var(--color-teal-200);
|
|
121
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** Chip: one chosen thing in a selection, with the control that removes
|
|
2
|
+
* it; and the offer of one more (`ChipAdd`), drawn as the same shape with
|
|
3
|
+
* a plus. Styles in chip.css. */
|
|
4
|
+
|
|
5
|
+
import type { ReactNode } from "react";
|
|
6
|
+
import { IconGalleryClose } from "../icons";
|
|
7
|
+
|
|
8
|
+
interface ChipProps {
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
/** A second line's worth of context, run on after the name. */
|
|
11
|
+
sub?: ReactNode;
|
|
12
|
+
/** Spoken on the remove control. */
|
|
13
|
+
removeLabel: string;
|
|
14
|
+
onRemove: () => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function Chip({ children, sub, removeLabel, onRemove }: ChipProps) {
|
|
18
|
+
return (
|
|
19
|
+
<span className="chip">
|
|
20
|
+
<span className="chip-body">
|
|
21
|
+
<span className="type type-fixed ts-text-sm-medium chip-name">{children}</span>
|
|
22
|
+
{sub ? <span className="type type-fixed ts-text-sm-light chip-sub">{sub}</span> : null}
|
|
23
|
+
</span>
|
|
24
|
+
<button type="button" className="chip-remove" aria-label={removeLabel} onClick={onRemove}>
|
|
25
|
+
<IconGalleryClose />
|
|
26
|
+
</button>
|
|
27
|
+
</span>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface ChipAddProps {
|
|
32
|
+
children: ReactNode;
|
|
33
|
+
/** Spoken on the control, naming what it adds. */
|
|
34
|
+
label: string;
|
|
35
|
+
onClick: () => void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function ChipAdd({ children, label, onClick }: ChipAddProps) {
|
|
39
|
+
return (
|
|
40
|
+
<button type="button" className="chip chip-add" aria-label={label} onClick={onClick}>
|
|
41
|
+
<span className="chip-plus" aria-hidden="true" />
|
|
42
|
+
<span className="type type-fixed ts-text-sm-medium chip-name">{children}</span>
|
|
43
|
+
</button>
|
|
44
|
+
);
|
|
45
|
+
}
|
package/primitives/field.css
CHANGED
|
@@ -160,6 +160,60 @@
|
|
|
160
160
|
--_ring: var(--color-teal-150);
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
+
/* Pill: the round control for a sheet whose buttons are round too. */
|
|
164
|
+
.ks-field[data-shape="pill"] .ks-field-control {
|
|
165
|
+
border-radius: var(--radius-full);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/* Phone: flag + tick over an invisible native select, a hairline, the
|
|
169
|
+
calling code, then the national number. The select covers the flag
|
|
170
|
+
and tick so the whole cluster opens the country list. */
|
|
171
|
+
.ks-field-control[data-kind="phone"] {
|
|
172
|
+
gap: var(--space-md);
|
|
173
|
+
padding-inline: var(--space-lg) var(--space-xl);
|
|
174
|
+
}
|
|
175
|
+
.ks-field-country {
|
|
176
|
+
position: relative;
|
|
177
|
+
display: inline-flex;
|
|
178
|
+
align-items: center;
|
|
179
|
+
gap: var(--space-xs);
|
|
180
|
+
flex: none;
|
|
181
|
+
align-self: stretch;
|
|
182
|
+
}
|
|
183
|
+
.ks-field-country .ks-field-tick {
|
|
184
|
+
position: static;
|
|
185
|
+
translate: none;
|
|
186
|
+
}
|
|
187
|
+
.ks-field-flag {
|
|
188
|
+
font: var(--ts-text-lg-regular-font);
|
|
189
|
+
line-height: 1;
|
|
190
|
+
}
|
|
191
|
+
.ks-field-country-select {
|
|
192
|
+
position: absolute;
|
|
193
|
+
inset: 0;
|
|
194
|
+
width: 100%;
|
|
195
|
+
opacity: 0;
|
|
196
|
+
cursor: pointer;
|
|
197
|
+
}
|
|
198
|
+
.ks-field-vr {
|
|
199
|
+
flex: none;
|
|
200
|
+
align-self: stretch;
|
|
201
|
+
width: 1px;
|
|
202
|
+
margin-block: var(--space-md);
|
|
203
|
+
background: var(--color-border-000);
|
|
204
|
+
}
|
|
205
|
+
.ks-field-dial {
|
|
206
|
+
flex: none;
|
|
207
|
+
color: var(--_ph);
|
|
208
|
+
font-variant-numeric: tabular-nums;
|
|
209
|
+
--font: var(--ts-text-md-light-font);
|
|
210
|
+
--ls: var(--ts-text-md-light-ls);
|
|
211
|
+
--opsz: var(--ts-text-md-light-opsz);
|
|
212
|
+
}
|
|
213
|
+
.ks-field-control[data-kind="phone"]:focus-within .ks-field-dial {
|
|
214
|
+
color: var(--color-text-400);
|
|
215
|
+
}
|
|
216
|
+
|
|
163
217
|
.ks-field-check {
|
|
164
218
|
gap: var(--space-sm);
|
|
165
219
|
}
|