@passui/react 0.1.44 → 0.1.46
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/README.md +57 -46
- package/dist/types/src/components/accordion/accordion.d.ts +1 -1
- package/dist/types/src/components/breadcrumb/breadcrumb.d.ts +1 -1
- package/dist/types/src/components/inline-disclosure/inline-disclosure.d.ts +1 -1
- package/dist/types/src/components/popover/anchored-surface.d.ts +5 -1
- package/dist/types/src/components/popover/index.d.ts +41 -0
- package/dist/types/src/components/popover/popover-content.d.ts +32 -0
- package/dist/types/src/components/popover/popover-root.d.ts +22 -0
- package/dist/types/src/components/popover/popover-trigger.d.ts +23 -0
- package/dist/types/src/components/stepper/rolling-digit.d.ts +1 -1
- package/dist/types/src/components/table/table.d.ts +1 -1
- package/dist/types/src/components/view-controller/view-controller.d.ts +2 -2
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/machines/popover.machine.d.ts +30 -0
- package/package.json +307 -307
- package/src/appearance/index.ts +2 -2
- package/src/appearance/platform.tsx +76 -60
- package/src/appearance/theme.tsx +409 -377
- package/src/components/accordion/accordion.tsx +58 -49
- package/src/components/ambient/ambient.tsx +25 -25
- package/src/components/ambient/index.ts +1 -1
- package/src/components/aspect-ratio/aspect-ratio.tsx +21 -16
- package/src/components/breadcrumb/breadcrumb.tsx +63 -57
- package/src/components/button/button-styles.ts +39 -32
- package/src/components/button/button.tsx +91 -84
- package/src/components/button/icon-button.tsx +27 -25
- package/src/components/button/pending-spinner.tsx +8 -8
- package/src/components/button/use-pending-indicator.ts +11 -11
- package/src/components/chip/chip.tsx +35 -30
- package/src/components/code-block/code-block.tsx +40 -39
- package/src/components/combo-box/combo-box.tsx +5 -5
- package/src/components/command/command.tsx +124 -94
- package/src/components/compact-date-picker/calendar-month.ts +75 -53
- package/src/components/compact-date-picker/compact-date-picker.tsx +308 -289
- package/src/components/compact-time-picker/compact-time-picker.tsx +288 -281
- package/src/components/compact-time-picker/time-value.ts +32 -29
- package/src/components/content-unavailable-view/content-unavailable-view.tsx +64 -48
- package/src/components/content-view/content-view.tsx +168 -159
- package/src/components/content-view/index.ts +1 -1
- package/src/components/context-menu/conceal-menu-source.ts +25 -25
- package/src/components/context-menu/context-menu-host.tsx +439 -398
- package/src/components/context-menu/context-menu-store.ts +125 -123
- package/src/components/context-menu/menu-navigation.ts +25 -18
- package/src/components/context-menu/menu-position.ts +33 -29
- package/src/components/context-menu/menu-reveal.ts +32 -32
- package/src/components/context-menu/use-context-menu.ts +63 -56
- package/src/components/conversation/conversation.tsx +265 -263
- package/src/components/conversation/index.ts +1 -1
- package/src/components/date-picker/date-picker.tsx +95 -94
- package/src/components/date-picker/date-value.ts +20 -10
- package/src/components/dialog/dialog-host.tsx +105 -103
- package/src/components/dialog/dialog-store.ts +37 -36
- package/src/components/dialog/dialog.tsx +192 -179
- package/src/components/dialog/index.ts +1 -1
- package/src/components/disclosure-group/disclosure-group.tsx +93 -86
- package/src/components/divider/divider.tsx +24 -22
- package/src/components/inline-disclosure/inline-disclosure.tsx +40 -36
- package/src/components/keyboard-shortcut/keyboard-shortcut.tsx +23 -19
- package/src/components/labeled-content/labeled-content.tsx +68 -68
- package/src/components/locale-switcher/index.ts +1 -1
- package/src/components/locale-switcher/locale-switcher.tsx +279 -251
- package/src/components/menu/menu.tsx +75 -58
- package/src/components/morph/index.ts +2 -2
- package/src/components/morph/morph.tsx +227 -201
- package/src/components/morph/use-morph-disclosure.ts +19 -19
- package/src/components/one-time-code/one-time-code.tsx +216 -200
- package/src/components/picker/picker-trigger.ts +16 -13
- package/src/components/picker/picker.tsx +371 -345
- package/src/components/popover/anchored-surface.tsx +253 -229
- package/src/components/popover/index.ts +50 -0
- package/src/components/popover/popover-content.tsx +334 -0
- package/src/components/popover/popover-fit.ts +58 -53
- package/src/components/popover/popover-root.tsx +97 -0
- package/src/components/popover/popover-trigger.tsx +71 -0
- package/src/components/profile-image/profile-image.tsx +80 -64
- package/src/components/progress-view/progress-view.tsx +61 -59
- package/src/components/progress-view/use-liquid-progress.ts +38 -38
- package/src/components/radio-group/radio-group.tsx +71 -68
- package/src/components/search-field/expanding-search-field.tsx +191 -177
- package/src/components/search-field/search-field.tsx +59 -50
- package/src/components/search-list/search-list.tsx +246 -236
- package/src/components/section/section.tsx +58 -58
- package/src/components/secure-field/secure-field.tsx +3 -3
- package/src/components/segmented-control/segmented-control.tsx +136 -136
- package/src/components/sheet/modal-environment.ts +71 -64
- package/src/components/sheet/sheet-portal.tsx +58 -53
- package/src/components/sheet/sheet.tsx +146 -141
- package/src/components/sheet/use-sheet-focus.ts +97 -82
- package/src/components/sidebar/sidebar.tsx +78 -78
- package/src/components/skeleton/skeleton.tsx +30 -21
- package/src/components/slider/slider.tsx +113 -104
- package/src/components/slosh-slider/liquid-step.ts +32 -31
- package/src/components/slosh-slider/slosh-slider.tsx +265 -228
- package/src/components/stat-tile/index.ts +1 -1
- package/src/components/stat-tile/stat-tile.tsx +79 -68
- package/src/components/status-indicator/status-indicator.tsx +40 -37
- package/src/components/stepper/rolling-digit.tsx +82 -68
- package/src/components/stepper/stepper.tsx +122 -113
- package/src/components/swatch-picker/swatch-picker.tsx +120 -120
- package/src/components/tab-bar/tab-bar.tsx +149 -148
- package/src/components/tab-view/tab-view.tsx +140 -137
- package/src/components/table/table.tsx +117 -98
- package/src/components/text-editor/text-editor.tsx +34 -29
- package/src/components/text-field/text-field.tsx +182 -180
- package/src/components/toast/toast-store.ts +127 -115
- package/src/components/toast/toaster.tsx +361 -347
- package/src/components/toggle/toggle.tsx +297 -282
- package/src/components/tooltip/tooltip-host.tsx +157 -150
- package/src/components/view-controller/index.ts +1 -1
- package/src/components/view-controller/view-controller.tsx +64 -53
- package/src/components/wake-slider/wake-slider.tsx +220 -205
- package/src/hooks/scroll/minimize-decision.ts +11 -7
- package/src/hooks/use-anchored-disclosure.ts +19 -19
- package/src/hooks/use-anchored-placement.ts +29 -25
- package/src/hooks/use-dismiss.ts +33 -29
- package/src/hooks/use-floating-dismiss.ts +24 -22
- package/src/hooks/use-media-query.ts +67 -60
- package/src/hooks/use-minimize-on-scroll.ts +69 -60
- package/src/hooks/use-visual-viewport.ts +63 -63
- package/src/hooks/viewport/types.ts +16 -16
- package/src/hooks/viewport/viewport-metrics.ts +16 -10
- package/src/icons/icons.tsx +440 -328
- package/src/index.ts +91 -91
- package/src/lib/anchored-placement.ts +70 -65
- package/src/lib/class-names.ts +14 -13
- package/src/lib/clipboard.ts +8 -7
- package/src/lib/date.ts +61 -60
- package/src/lib/floating-layers.ts +39 -24
- package/src/lib/haptics.ts +10 -10
- package/src/lib/language.ts +9 -9
- package/src/lib/range-value.ts +27 -21
- package/src/lib/screen-edges.ts +33 -30
- package/src/lib/shapes.ts +38 -34
- package/src/machines/popover.machine.ts +51 -0
- package/src/motion/transitions.ts +46 -43
- package/src/styles/code-block.css +69 -43
- package/src/styles/motion-controls.css +393 -191
- package/src/tokens.ts +1 -1
- package/dist/types/src/components/popover/popover.d.ts +0 -21
- package/src/components/popover/popover.tsx +0 -322
|
@@ -1,183 +1,197 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "react"
|
|
9
|
-
import { useMediaQuery } from "../../hooks/use-media-query"
|
|
10
|
-
import { SearchIcon } from "../../icons/icons"
|
|
11
|
-
import { cn } from "../../lib/class-names"
|
|
12
|
-
import { springs } from "@passui/tokens/motion"
|
|
2
|
+
type InputHTMLAttributes,
|
|
3
|
+
type Ref,
|
|
4
|
+
useEffect,
|
|
5
|
+
useLayoutEffect,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
} from "react";
|
|
9
|
+
import { useMediaQuery } from "../../hooks/use-media-query";
|
|
10
|
+
import { SearchIcon } from "../../icons/icons";
|
|
11
|
+
import { cn } from "../../lib/class-names";
|
|
12
|
+
import { springs } from "@passui/tokens/motion";
|
|
13
13
|
|
|
14
14
|
/** One object: the field stays inside the pill, and the lens never moves within it. */
|
|
15
15
|
export function ExpandingSearchField({
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}: InputHTMLAttributes<HTMLInputElement> & {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
16
|
+
inputRef,
|
|
17
|
+
className,
|
|
18
|
+
placeholder = "Search",
|
|
19
|
+
...props
|
|
20
|
+
}: InputHTMLAttributes<HTMLInputElement> & {
|
|
21
|
+
inputRef: Ref<HTMLInputElement>;
|
|
22
|
+
}) {
|
|
23
|
+
const [expanded, setExpanded] = useState(
|
|
24
|
+
Boolean(props.value ?? props.defaultValue),
|
|
25
|
+
);
|
|
26
|
+
const reduced = useMediaQuery("(prefers-reduced-motion: reduce)");
|
|
27
|
+
const frame = useRef<HTMLDivElement>(null);
|
|
28
|
+
const pill = useRef<HTMLLabelElement>(null);
|
|
29
|
+
const input = useRef<HTMLInputElement>(null);
|
|
30
|
+
const geometry = useRef({
|
|
31
|
+
width: expanded ? 320 : 44,
|
|
32
|
+
velocity: 0,
|
|
33
|
+
x: 0,
|
|
34
|
+
y: 0,
|
|
35
|
+
vx: 0,
|
|
36
|
+
vy: 0,
|
|
37
|
+
pullX: 0,
|
|
38
|
+
pullY: 0,
|
|
39
|
+
capacity: 320,
|
|
40
|
+
raf: 0,
|
|
41
|
+
});
|
|
42
|
+
const current = useRef({ expanded, reduced });
|
|
43
|
+
const wake = useRef<() => void>(() => {});
|
|
44
|
+
useLayoutEffect(() => {
|
|
45
|
+
const box = frame.current;
|
|
46
|
+
const label = pill.current;
|
|
47
|
+
const field = input.current;
|
|
48
|
+
if (!box || !label || !field) return;
|
|
49
|
+
const s = geometry.current;
|
|
50
|
+
let previous = 0;
|
|
51
|
+
const tick = (now: number) => {
|
|
52
|
+
const dt = previous ? Math.min(0.032, (now - previous) / 1000) : 1 / 60;
|
|
53
|
+
previous = now;
|
|
54
|
+
const target = current.current.expanded
|
|
55
|
+
? s.capacity
|
|
56
|
+
: Math.min(44, s.capacity);
|
|
57
|
+
const pullX = current.current.expanded ? 0 : s.pullX;
|
|
58
|
+
const pullY = current.current.expanded ? 0 : s.pullY;
|
|
59
|
+
const { stiffness, damping, mass } = springs.smooth;
|
|
60
|
+
if (current.current.reduced) {
|
|
61
|
+
s.width = target;
|
|
62
|
+
s.x = 0;
|
|
63
|
+
s.y = 0;
|
|
64
|
+
s.velocity = 0;
|
|
65
|
+
s.vx = 0;
|
|
66
|
+
s.vy = 0;
|
|
67
|
+
} else {
|
|
68
|
+
s.velocity +=
|
|
69
|
+
(((target - s.width) * stiffness - s.velocity * damping) / mass) * dt;
|
|
70
|
+
s.width += s.velocity * dt;
|
|
71
|
+
s.vx += (((pullX - s.x) * stiffness - s.vx * damping) / mass) * dt;
|
|
72
|
+
s.vy += (((pullY - s.y) * stiffness - s.vy * damping) / mass) * dt;
|
|
73
|
+
s.x += s.vx * dt;
|
|
74
|
+
s.y += s.vy * dt;
|
|
75
|
+
}
|
|
76
|
+
label.style.width = `${Math.max(0, s.width)}px`;
|
|
77
|
+
label.style.transform = `translate(${s.x}px, ${s.y}px)`;
|
|
78
|
+
/* One number drives the field's reveal; focus lands with the
|
|
72
79
|
expansion, so the caret arrives while the shape is growing. */
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
80
|
+
const progress = (s.width - 44) / Math.max(1, s.capacity - 44);
|
|
81
|
+
field.style.opacity = String(
|
|
82
|
+
Math.max(0, Math.min(1, (progress - 0.55) / 0.45)),
|
|
83
|
+
);
|
|
84
|
+
if (
|
|
85
|
+
Math.abs(s.width - target) < 0.05 &&
|
|
86
|
+
Math.abs(s.velocity) < 0.05 &&
|
|
87
|
+
Math.abs(s.x - pullX) +
|
|
88
|
+
Math.abs(s.y - pullY) +
|
|
89
|
+
Math.abs(s.vx) +
|
|
90
|
+
Math.abs(s.vy) <
|
|
91
|
+
0.05
|
|
92
|
+
) {
|
|
93
|
+
label.style.width = `${target}px`;
|
|
94
|
+
s.raf = 0;
|
|
95
|
+
previous = 0;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
s.raf = requestAnimationFrame(tick);
|
|
99
|
+
};
|
|
100
|
+
wake.current = () => {
|
|
101
|
+
if (!s.raf) s.raf = requestAnimationFrame(tick);
|
|
102
|
+
};
|
|
103
|
+
const measure = () => {
|
|
104
|
+
s.capacity = Math.min(320, box.clientWidth);
|
|
105
|
+
wake.current();
|
|
106
|
+
};
|
|
107
|
+
measure();
|
|
108
|
+
const observer = new ResizeObserver(measure);
|
|
109
|
+
observer.observe(box);
|
|
110
|
+
return () => {
|
|
111
|
+
observer.disconnect();
|
|
112
|
+
cancelAnimationFrame(s.raf);
|
|
113
|
+
s.raf = 0;
|
|
114
|
+
};
|
|
115
|
+
}, []);
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
current.current = { expanded, reduced };
|
|
118
|
+
wake.current();
|
|
119
|
+
}, [expanded, reduced]);
|
|
120
|
+
return (
|
|
121
|
+
<div
|
|
122
|
+
ref={frame}
|
|
123
|
+
className={cn(
|
|
124
|
+
"relative flex h-11 w-full max-w-xs items-center justify-center",
|
|
125
|
+
className,
|
|
126
|
+
)}
|
|
127
|
+
onPointerMove={(event) => {
|
|
128
|
+
if (expanded || reduced || event.pointerType !== "mouse") return;
|
|
129
|
+
// Measure the frame, which stays still; measuring the object being
|
|
130
|
+
// moved creates a feedback loop and a visible shiver.
|
|
131
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
132
|
+
const dx = event.clientX - rect.left - rect.width / 2;
|
|
133
|
+
const dy = event.clientY - rect.top - rect.height / 2;
|
|
134
|
+
const distance = Math.hypot(dx, dy);
|
|
135
|
+
const pull = Math.max(0, 1 - distance / 72) ** 1.4 * 7;
|
|
136
|
+
geometry.current.pullX = distance ? (dx / distance) * pull : 0;
|
|
137
|
+
geometry.current.pullY = distance ? (dy / distance) * pull : 0;
|
|
138
|
+
wake.current();
|
|
139
|
+
}}
|
|
140
|
+
onPointerLeave={() => {
|
|
141
|
+
geometry.current.pullX = 0;
|
|
142
|
+
geometry.current.pullY = 0;
|
|
143
|
+
wake.current();
|
|
144
|
+
}}
|
|
145
|
+
>
|
|
146
|
+
<label
|
|
147
|
+
ref={pill}
|
|
148
|
+
className={cn(
|
|
149
|
+
"passui-search-pill control-field relative block h-11 max-w-full overflow-hidden rounded-full",
|
|
150
|
+
props.disabled && "opacity-40",
|
|
151
|
+
)}
|
|
152
|
+
style={{ width: expanded ? 320 : 44 }}
|
|
153
|
+
>
|
|
154
|
+
<SearchIcon
|
|
155
|
+
aria-hidden="true"
|
|
156
|
+
size={18}
|
|
157
|
+
className="text-label-secondary pointer-events-none absolute start-[13px] top-1/2 -translate-y-1/2"
|
|
158
|
+
/>
|
|
159
|
+
<input
|
|
160
|
+
{...props}
|
|
161
|
+
ref={(node) => {
|
|
162
|
+
input.current = node;
|
|
163
|
+
if (typeof inputRef === "function") inputRef(node);
|
|
164
|
+
else if (inputRef) inputRef.current = node;
|
|
165
|
+
}}
|
|
166
|
+
type="search"
|
|
167
|
+
placeholder={placeholder}
|
|
168
|
+
aria-label={
|
|
169
|
+
props["aria-labelledby"]
|
|
170
|
+
? undefined
|
|
171
|
+
: (props["aria-label"] ?? placeholder)
|
|
172
|
+
}
|
|
173
|
+
className="text-subheadline text-label placeholder:text-label-tertiary h-11 w-full min-w-0 bg-transparent ps-11 pe-3 outline-none"
|
|
174
|
+
onFocus={(event) => {
|
|
175
|
+
setExpanded(true);
|
|
176
|
+
props.onFocus?.(event);
|
|
177
|
+
}}
|
|
178
|
+
onBlur={(event) => {
|
|
179
|
+
if (!event.currentTarget.value) setExpanded(false);
|
|
180
|
+
props.onBlur?.(event);
|
|
181
|
+
}}
|
|
182
|
+
onKeyDown={(event) => {
|
|
183
|
+
props.onKeyDown?.(event);
|
|
184
|
+
if (
|
|
185
|
+
!event.defaultPrevented &&
|
|
186
|
+
event.key === "Escape" &&
|
|
187
|
+
!event.currentTarget.value
|
|
188
|
+
) {
|
|
189
|
+
setExpanded(false);
|
|
190
|
+
event.currentTarget.blur();
|
|
191
|
+
}
|
|
192
|
+
}}
|
|
193
|
+
/>
|
|
194
|
+
</label>
|
|
195
|
+
</div>
|
|
196
|
+
);
|
|
183
197
|
}
|
|
@@ -1,57 +1,66 @@
|
|
|
1
|
-
import { forwardRef, type InputHTMLAttributes } from "react"
|
|
2
|
-
import { SearchIcon } from "../../icons/icons"
|
|
3
|
-
import { cn } from "../../lib/class-names"
|
|
4
|
-
import { ExpandingSearchField } from "./expanding-search-field"
|
|
1
|
+
import { forwardRef, type InputHTMLAttributes } from "react";
|
|
2
|
+
import { SearchIcon } from "../../icons/icons";
|
|
3
|
+
import { cn } from "../../lib/class-names";
|
|
4
|
+
import { ExpandingSearchField } from "./expanding-search-field";
|
|
5
5
|
|
|
6
|
-
export type SearchFieldSize = "sm" | "md" | "lg"
|
|
6
|
+
export type SearchFieldSize = "sm" | "md" | "lg";
|
|
7
7
|
|
|
8
8
|
const pillSizes: Record<SearchFieldSize, string> = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
9
|
+
sm: "control-field flex items-center gap-1.5 rounded-full px-2.5 py-1 text-caption text-label-tertiary",
|
|
10
|
+
md: "control-field flex items-center gap-2 rounded-full px-3 py-2 text-subheadline text-label-tertiary",
|
|
11
|
+
lg: "control-field flex items-center gap-2.5 rounded-full px-4 py-2.5 text-body text-label-tertiary",
|
|
12
|
+
};
|
|
13
13
|
const iconSizes: Record<SearchFieldSize, number> = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
14
|
+
sm: 13,
|
|
15
|
+
md: 15,
|
|
16
|
+
lg: 17,
|
|
17
|
+
};
|
|
18
18
|
|
|
19
|
-
export interface SearchFieldProps
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
export interface SearchFieldProps
|
|
20
|
+
extends Omit<InputHTMLAttributes<HTMLInputElement>, "size"> {
|
|
21
|
+
/** Expand a single pill from its search icon on focus. @default false */
|
|
22
|
+
collapsible?: boolean;
|
|
23
|
+
/** Pill height, icon size and text scale (non-collapsible variant). @default "md" */
|
|
24
|
+
size?: SearchFieldSize;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
export const SearchField = forwardRef<HTMLInputElement, SearchFieldProps>(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
27
|
+
export const SearchField = forwardRef<HTMLInputElement, SearchFieldProps>(
|
|
28
|
+
function SearchField(
|
|
29
|
+
{
|
|
30
|
+
className,
|
|
31
|
+
placeholder = "Search",
|
|
32
|
+
collapsible = false,
|
|
33
|
+
size = "md",
|
|
34
|
+
...props
|
|
35
|
+
},
|
|
36
|
+
ref,
|
|
37
|
+
) {
|
|
38
|
+
if (collapsible)
|
|
39
|
+
return (
|
|
40
|
+
<ExpandingSearchField
|
|
41
|
+
{...props}
|
|
42
|
+
inputRef={ref}
|
|
43
|
+
className={className}
|
|
44
|
+
placeholder={placeholder}
|
|
45
|
+
/>
|
|
46
|
+
);
|
|
47
|
+
const accessibleName = props["aria-labelledby"]
|
|
48
|
+
? undefined
|
|
49
|
+
: (props["aria-label"] ?? placeholder);
|
|
50
|
+
return (
|
|
51
|
+
<label className={cn(pillSizes[size], className)}>
|
|
52
|
+
<span aria-hidden="true" className="shrink-0">
|
|
53
|
+
<SearchIcon size={iconSizes[size]} strokeWidth={2} />
|
|
54
|
+
</span>
|
|
55
|
+
<input
|
|
56
|
+
ref={ref}
|
|
57
|
+
type="search"
|
|
58
|
+
placeholder={placeholder}
|
|
59
|
+
aria-label={accessibleName}
|
|
60
|
+
className="text-label placeholder:text-label-tertiary min-w-0 grow bg-transparent outline-none"
|
|
61
|
+
{...props}
|
|
62
|
+
/>
|
|
63
|
+
</label>
|
|
64
|
+
);
|
|
65
|
+
},
|
|
66
|
+
);
|