@nuskin/react-search-components 1.0.0 → 1.1.0-cx130-2624.1

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/dist/index.js CHANGED
@@ -139,6 +139,7 @@ function Icon({
139
139
  }
140
140
  var { colors } = foundationTheme.nuskinTheme;
141
141
  var DESKTOP_MIN_PX = 1025;
142
+ var DESKTOP_SEARCH_COLUMN_MAX = "860px";
142
143
  var AGENT_DESKTOP_BLOCK_SIZE = "70dvh";
143
144
  var SearchPanelLayoutRoot = styled4__default.default.dialog`
144
145
  background-color: ${colors.primary.white};
@@ -178,26 +179,46 @@ var SearchPanelLayoutRoot = styled4__default.default.dialog`
178
179
  `}
179
180
  `;
180
181
  var SearchPanelLayoutInner = styled4__default.default.div`
182
+ align-items: ${({ $agentMode }) => $agentMode ? "stretch" : "center"};
181
183
  box-sizing: border-box;
182
184
  display: grid;
183
- gap: 1.5rem;
184
- inline-size: min(100%, 75rem);
185
+ justify-items: stretch;
186
+ grid-template-areas:
187
+ 'input cancel'
188
+ 'content content';
189
+ grid-template-columns: minmax(0, 1fr) auto;
190
+ inline-size: 100%;
185
191
  margin-inline: auto;
186
- padding: clamp(1rem, 2vw, 2rem);
192
+ padding: 30px 0;
193
+ row-gap: 0;
194
+
195
+ @media (min-width: ${DESKTOP_MIN_PX}px) {
196
+ grid-template-areas:
197
+ 'logo cancel'
198
+ 'input input'
199
+ 'content content';
200
+ padding: 20px clamp(12px, 4vw, 32px) 30px;
201
+ }
202
+
187
203
  ${({ $agentMode }) => $agentMode && `
188
204
  display: flex;
189
205
  flex-direction: column;
190
206
  flex: 1;
207
+ gap: 1.5rem;
191
208
  min-block-size: 0;
192
209
  overflow: hidden;
210
+ padding: clamp(1rem, 2vw, 2rem);
193
211
  `}
194
212
  `;
195
213
  var SearchPanelLayoutAgentContent = styled4__default.default.div`
214
+ align-self: stretch;
196
215
  flex: 1;
216
+ inline-size: 100%;
197
217
  min-block-size: 0;
198
218
  min-inline-size: 0;
199
219
  overflow: hidden;
200
220
  position: relative;
221
+ width: 100%;
201
222
  `;
202
223
  var SearchPanelLayoutHeader = styled4__default.default.header`
203
224
  display: flex;
@@ -209,9 +230,23 @@ var SearchPanelLayoutHeader = styled4__default.default.header`
209
230
  `}
210
231
  `;
211
232
  var SearchPanelLayoutLogoSlot = styled4__default.default.div`
233
+ display: none;
212
234
  flex: 0 0 auto;
213
- /* when header is flex-end (agent mode), push the logo to the far left */
235
+ grid-area: logo;
214
236
  margin-inline-end: auto;
237
+
238
+ @media (min-width: ${DESKTOP_MIN_PX}px) {
239
+ display: block;
240
+ }
241
+
242
+ ${({ $agentMode }) => $agentMode && `display: block;`}
243
+ `;
244
+ var SearchPanelLayoutCloseIcon = styled4__default.default.span`
245
+ display: none;
246
+
247
+ @media (min-width: ${DESKTOP_MIN_PX}px) {
248
+ display: inline-flex;
249
+ }
215
250
  `;
216
251
  var SearchPanelLayoutCloseButton = styled4__default.default.button`
217
252
  align-items: center;
@@ -223,32 +258,91 @@ var SearchPanelLayoutCloseButton = styled4__default.default.button`
223
258
  display: inline-flex;
224
259
  font: inherit;
225
260
  gap: 0.375rem;
226
- padding: 0.5rem;
261
+ grid-area: cancel;
262
+ justify-self: end;
263
+ padding: 0.5rem 20px 0.5rem 12px;
264
+ text-transform: uppercase;
227
265
 
228
266
  &:focus-visible {
229
267
  outline: 2px solid ${colors.primary.black};
230
268
  outline-offset: 2px;
231
269
  }
270
+
271
+ @media (min-width: ${DESKTOP_MIN_PX}px) {
272
+ padding: 0.5rem;
273
+ text-transform: none;
274
+ }
232
275
  `;
233
276
  var SearchPanelLayoutContent = styled4__default.default.div`
277
+ grid-area: content;
234
278
  min-inline-size: 0;
279
+ width: 100%;
280
+
281
+ @media (min-width: ${DESKTOP_MIN_PX}px) {
282
+ inline-size: min(100%, ${DESKTOP_SEARCH_COLUMN_MAX});
283
+ justify-self: center;
284
+ }
235
285
  `;
236
286
  var SearchPanelLayoutInputSlot = styled4__default.default.div`
237
- inline-size: min(100%, 44rem);
238
- justify-self: center;
287
+ grid-area: input;
288
+ min-inline-size: 0;
289
+ overflow: visible;
290
+ padding-inline: 20px 0;
239
291
  width: 100%;
292
+
293
+ @media (min-width: ${DESKTOP_MIN_PX}px) {
294
+ inline-size: min(100%, ${DESKTOP_SEARCH_COLUMN_MAX});
295
+ justify-self: center;
296
+ margin-block-start: 30px;
297
+ padding-inline: 0;
298
+ }
240
299
  `;
300
+ function SearchPanelCloseControl({
301
+ cancelLabelTag,
302
+ cancelShowIconTag,
303
+ closeLabel,
304
+ onClose,
305
+ showCancelIcon
306
+ }) {
307
+ return /* @__PURE__ */ jsxRuntime.jsxs(
308
+ SearchPanelLayoutCloseButton,
309
+ {
310
+ type: "button",
311
+ onMouseDown: (event) => event.preventDefault(),
312
+ onClick: onClose,
313
+ ...showCancelIcon ? {} : cancelShowIconTag != null ? cancelShowIconTag : {},
314
+ children: [
315
+ showCancelIcon ? /* @__PURE__ */ jsxRuntime.jsx(SearchPanelLayoutCloseIcon, { ...cancelShowIconTag != null ? cancelShowIconTag : {}, children: /* @__PURE__ */ jsxRuntime.jsx(Icon, { cursor: ICON_CURSORS.POINTER, size: ICON_SIZES.SMALL, type: ICON_TYPES.CLOSE }) }) : null,
316
+ /* @__PURE__ */ jsxRuntime.jsx("span", { ...cancelLabelTag != null ? cancelLabelTag : {}, children: closeLabel })
317
+ ]
318
+ }
319
+ );
320
+ }
241
321
  var SearchPanelLayout = react.forwardRef(
242
322
  function SearchPanelLayout2({
243
323
  "aria-label": ariaLabel,
244
324
  agentMode = false,
245
325
  children,
246
326
  closeLabel,
327
+ showCancelIcon = true,
328
+ cancelLabelTag,
329
+ cancelShowIconTag,
247
330
  inputSlot,
248
331
  logoSlot,
249
332
  onClose,
250
333
  ...props
251
334
  }, ref) {
335
+ const logo = logoSlot ? /* @__PURE__ */ jsxRuntime.jsx(SearchPanelLayoutLogoSlot, { $agentMode: agentMode, children: logoSlot }) : null;
336
+ const closeControl = /* @__PURE__ */ jsxRuntime.jsx(
337
+ SearchPanelCloseControl,
338
+ {
339
+ closeLabel,
340
+ onClose,
341
+ showCancelIcon,
342
+ ...cancelLabelTag ? { cancelLabelTag } : {},
343
+ ...cancelShowIconTag ? { cancelShowIconTag } : {}
344
+ }
345
+ );
252
346
  return /* @__PURE__ */ jsxRuntime.jsx(
253
347
  SearchPanelLayoutRoot,
254
348
  {
@@ -258,22 +352,14 @@ var SearchPanelLayout = react.forwardRef(
258
352
  "aria-label": ariaLabel,
259
353
  $agentMode: agentMode,
260
354
  children: /* @__PURE__ */ jsxRuntime.jsxs(SearchPanelLayoutInner, { $agentMode: agentMode, children: [
261
- /* @__PURE__ */ jsxRuntime.jsxs(SearchPanelLayoutHeader, { $agentMode: agentMode, children: [
262
- logoSlot && /* @__PURE__ */ jsxRuntime.jsx(SearchPanelLayoutLogoSlot, { children: logoSlot }),
263
- /* @__PURE__ */ jsxRuntime.jsxs(
264
- SearchPanelLayoutCloseButton,
265
- {
266
- type: "button",
267
- onMouseDown: (e) => e.preventDefault(),
268
- onClick: onClose,
269
- children: [
270
- /* @__PURE__ */ jsxRuntime.jsx(Icon, { cursor: ICON_CURSORS.POINTER, size: ICON_SIZES.SMALL, type: ICON_TYPES.CLOSE }),
271
- closeLabel
272
- ]
273
- }
274
- )
355
+ agentMode ? /* @__PURE__ */ jsxRuntime.jsxs(SearchPanelLayoutHeader, { $agentMode: true, children: [
356
+ logo,
357
+ closeControl
358
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
359
+ logo,
360
+ closeControl
275
361
  ] }),
276
- !agentMode && inputSlot && /* @__PURE__ */ jsxRuntime.jsx(SearchPanelLayoutInputSlot, { children: inputSlot }),
362
+ !agentMode && inputSlot ? /* @__PURE__ */ jsxRuntime.jsx(SearchPanelLayoutInputSlot, { children: inputSlot }) : null,
277
363
  agentMode ? /* @__PURE__ */ jsxRuntime.jsx(SearchPanelLayoutAgentContent, { "data-agent-container": "", children }) : /* @__PURE__ */ jsxRuntime.jsx(SearchPanelLayoutContent, { children })
278
364
  ] })
279
365
  }
@@ -298,9 +384,11 @@ var SearchMessageInputRoot = styled4__default.default.form`
298
384
  border-radius: 999px;
299
385
  box-sizing: border-box;
300
386
  display: flex;
387
+ flex-wrap: nowrap;
301
388
  gap: 0.25rem;
302
389
  inline-size: 100%;
303
390
  min-block-size: 3rem;
391
+ min-inline-size: 0;
304
392
  padding: 0.25rem 0.5rem;
305
393
 
306
394
  &:focus-within {
@@ -314,15 +402,26 @@ var SearchMessageInputField = styled4__default.default.input`
314
402
  border: 0;
315
403
  box-sizing: border-box;
316
404
  color: ${colors2.primary.black};
317
- flex: 1 1 auto;
405
+ display: block;
318
406
  font: inherit;
407
+ inline-size: 100%;
319
408
  min-inline-size: 0;
320
409
  outline: 0;
321
410
  padding: 0.5rem;
411
+ text-overflow: clip;
412
+ white-space: nowrap;
322
413
 
323
414
  &::placeholder {
324
415
  color: ${colors2.neutral[20]};
325
416
  opacity: 1;
417
+ overflow: visible;
418
+ text-overflow: clip;
419
+ white-space: nowrap;
420
+ }
421
+
422
+ &[type='search']::-webkit-search-cancel-button,
423
+ &[type='search']::-webkit-search-decoration {
424
+ appearance: none;
326
425
  }
327
426
  `;
328
427
  var SearchMessageInputSubmit = styled4__default.default.button`
@@ -371,6 +470,200 @@ var SearchMessageInputClear = styled4__default.default.button`
371
470
  outline-offset: 2px;
372
471
  }
373
472
  `;
473
+ var SearchMessageInputAuxiliary = styled4__default.default.span`
474
+ align-items: center;
475
+ display: inline-flex;
476
+ flex: 0 0 auto;
477
+ gap: 0.25rem;
478
+ margin-inline-start: auto;
479
+
480
+ > span {
481
+ align-items: center;
482
+ display: inline-flex;
483
+ flex-shrink: 0;
484
+ inline-size: 2.125rem;
485
+ block-size: 2.125rem;
486
+ justify-content: center;
487
+ line-height: 0;
488
+ }
489
+
490
+ svg {
491
+ display: block;
492
+ overflow: visible;
493
+ }
494
+
495
+ [data-testid='search-nui-voice'] svg {
496
+ block-size: 2.125rem;
497
+ inline-size: 2.125rem;
498
+ }
499
+
500
+ @media (max-width: 1024px) {
501
+ > span {
502
+ block-size: 1.75rem;
503
+ inline-size: 1.75rem;
504
+ }
505
+
506
+ [data-testid='search-nui-voice'] svg {
507
+ block-size: 1.75rem;
508
+ inline-size: 1.75rem;
509
+ }
510
+ }
511
+ `;
512
+ var SearchMessageInputFieldWrap = styled4__default.default.span`
513
+ display: block;
514
+ flex: 1 1 auto;
515
+ min-inline-size: 0;
516
+ position: relative;
517
+ `;
518
+ var SearchMessageInputRotatingPlaceholder = styled4__default.default.span`
519
+ color: ${colors2.neutral[20]};
520
+ inset-block-start: 50%;
521
+ inset-inline: 0.5rem;
522
+ overflow: hidden;
523
+ pointer-events: none;
524
+ position: absolute;
525
+ text-overflow: ellipsis;
526
+ transform: translateY(-50%);
527
+ white-space: nowrap;
528
+ `;
529
+ function BrandedSparkleIcon() {
530
+ const reactId = react.useId();
531
+ const largeId = `${reactId}-sparkle-large`;
532
+ const smallId = `${reactId}-sparkle-small`;
533
+ return /* @__PURE__ */ jsxRuntime.jsxs(
534
+ "svg",
535
+ {
536
+ width: "18",
537
+ height: "26",
538
+ viewBox: "0 0 18 26",
539
+ fill: "none",
540
+ xmlns: "http://www.w3.org/2000/svg",
541
+ "aria-hidden": "true",
542
+ focusable: "false",
543
+ children: [
544
+ /* @__PURE__ */ jsxRuntime.jsx(
545
+ "path",
546
+ {
547
+ d: "M7.72184 7.28096C7.74702 7.14678 8.02273 7.14678 8.04791 7.28096C8.29593 8.60232 8.86587 10.8381 10.0145 11.9867C11.1631 13.1353 13.3989 13.7053 14.7202 13.9533C14.8544 13.9785 14.8544 14.2542 14.7202 14.2794C13.3989 14.5274 11.1631 15.0973 10.0145 16.246C8.86587 17.3946 8.29593 19.6303 8.04791 20.9517C8.02273 21.0859 7.74702 21.0859 7.72184 20.9517C7.47382 19.6303 6.90388 17.3946 5.75524 16.246C4.60661 15.0973 2.37088 14.5274 1.04952 14.2794C0.915335 14.2542 0.915335 13.9785 1.04952 13.9533C2.37088 13.7053 4.60661 13.1353 5.75524 11.9867C6.90388 10.8381 7.47382 8.60232 7.72184 7.28096Z",
548
+ fill: `url(#${largeId})`
549
+ }
550
+ ),
551
+ /* @__PURE__ */ jsxRuntime.jsx(
552
+ "path",
553
+ {
554
+ d: "M14.0975 4.49258C14.1092 4.42963 14.2378 4.42963 14.2495 4.49258C14.3682 5.13172 14.6448 6.23139 15.2073 6.79394C15.7699 7.35648 16.8696 7.63311 17.5087 7.7518C17.5716 7.76349 17.5716 7.89209 17.5087 7.90378C16.8696 8.02246 15.7699 8.29909 15.2073 8.86164C14.6448 9.42418 14.3682 10.5239 14.2495 11.163C14.2378 11.2259 14.1092 11.2259 14.0975 11.163C13.9788 10.5239 13.7022 9.42418 13.1396 8.86164C12.5771 8.29909 11.4774 8.02246 10.8383 7.90378C10.7753 7.89209 10.7753 7.76349 10.8383 7.7518C11.4774 7.63311 12.5771 7.35648 13.1396 6.79394C13.7022 6.23139 13.9788 5.13172 14.0975 4.49258Z",
555
+ fill: `url(#${smallId})`
556
+ }
557
+ ),
558
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
559
+ /* @__PURE__ */ jsxRuntime.jsxs(
560
+ "linearGradient",
561
+ {
562
+ id: largeId,
563
+ x1: "0.985745",
564
+ y1: "8.72141",
565
+ x2: "15.9969",
566
+ y2: "10.2253",
567
+ gradientUnits: "userSpaceOnUse",
568
+ children: [
569
+ /* @__PURE__ */ jsxRuntime.jsx("stop", { stopColor: "#6964F1" }),
570
+ /* @__PURE__ */ jsxRuntime.jsx("stop", { offset: "0.361696", stopColor: "#7561F3" }),
571
+ /* @__PURE__ */ jsxRuntime.jsx("stop", { offset: "0.743652", stopColor: "#855EF5" })
572
+ ]
573
+ }
574
+ ),
575
+ /* @__PURE__ */ jsxRuntime.jsxs(
576
+ "linearGradient",
577
+ {
578
+ id: smallId,
579
+ x1: "10.8242",
580
+ y1: "5.20877",
581
+ x2: "18.1115",
582
+ y2: "5.93885",
583
+ gradientUnits: "userSpaceOnUse",
584
+ children: [
585
+ /* @__PURE__ */ jsxRuntime.jsx("stop", { stopColor: "#6964F1" }),
586
+ /* @__PURE__ */ jsxRuntime.jsx("stop", { offset: "0.361696", stopColor: "#7561F3" }),
587
+ /* @__PURE__ */ jsxRuntime.jsx("stop", { offset: "0.743652", stopColor: "#855EF5" })
588
+ ]
589
+ }
590
+ )
591
+ ] })
592
+ ]
593
+ }
594
+ );
595
+ }
596
+ function BrandedVoiceSearchIcon() {
597
+ return /* @__PURE__ */ jsxRuntime.jsxs(
598
+ "svg",
599
+ {
600
+ width: "32",
601
+ height: "32",
602
+ viewBox: "0 0 32 32",
603
+ fill: "none",
604
+ xmlns: "http://www.w3.org/2000/svg",
605
+ "aria-hidden": "true",
606
+ focusable: "false",
607
+ children: [
608
+ /* @__PURE__ */ jsxRuntime.jsx("rect", { width: "32", height: "32", rx: "16", fill: "#EDEDED" }),
609
+ /* @__PURE__ */ jsxRuntime.jsx(
610
+ "path",
611
+ {
612
+ d: "M12.125 21V11H13.625V21H12.125ZM15.25 24V8H16.75V24H15.25ZM9 18V14H10.5V18H9ZM18.375 21V11H19.875V21H18.375ZM21.5 18V14H23V18H21.5Z",
613
+ fill: "#5F5F5F"
614
+ }
615
+ )
616
+ ]
617
+ }
618
+ );
619
+ }
620
+ var SEARCH_MOBILE_MAX_PX = 1024;
621
+ var MOBILE_QUERY = `(max-width: ${SEARCH_MOBILE_MAX_PX}px)`;
622
+ function useMobileSearchLayout(mediaQuery = MOBILE_QUERY) {
623
+ const [isMobile, setIsMobile] = react.useState(() => {
624
+ if (typeof window === "undefined") return false;
625
+ return window.matchMedia(mediaQuery).matches;
626
+ });
627
+ react.useEffect(() => {
628
+ if (typeof window === "undefined") return void 0;
629
+ const mq = window.matchMedia(mediaQuery);
630
+ const onChange = () => setIsMobile(mq.matches);
631
+ onChange();
632
+ mq.addEventListener("change", onChange);
633
+ return () => mq.removeEventListener("change", onChange);
634
+ }, [mediaQuery]);
635
+ return isMobile;
636
+ }
637
+ var DEFAULT_PLACEHOLDER_ROTATION_MS = 3e3;
638
+ function normalizeMessages(messages) {
639
+ if (!messages) return [];
640
+ return messages.filter((message) => message.trim() !== "");
641
+ }
642
+ function useRotatingPlaceholder(enabled, messages, intervalMs) {
643
+ var _a;
644
+ const [index, setIndex] = react.useState(0);
645
+ const rotationMs = intervalMs && intervalMs > 0 ? intervalMs : DEFAULT_PLACEHOLDER_ROTATION_MS;
646
+ const safeMessages = normalizeMessages(messages);
647
+ const messagesKey = safeMessages.join("\0");
648
+ react.useEffect(() => {
649
+ if (!enabled || safeMessages.length <= 1) {
650
+ setIndex(0);
651
+ return void 0;
652
+ }
653
+ const prefersReducedMotion = typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
654
+ if (prefersReducedMotion) {
655
+ setIndex(0);
656
+ return void 0;
657
+ }
658
+ const timerId = window.setInterval(
659
+ () => setIndex((current) => (current + 1) % safeMessages.length),
660
+ rotationMs
661
+ );
662
+ return () => window.clearInterval(timerId);
663
+ }, [enabled, rotationMs, messagesKey, safeMessages.length]);
664
+ if (!enabled || safeMessages.length === 0) return "";
665
+ return (_a = safeMessages[index % safeMessages.length]) != null ? _a : "";
666
+ }
374
667
  function SearchMessageInput({
375
668
  clearLabel,
376
669
  inputLabel,
@@ -381,8 +674,16 @@ function SearchMessageInput({
381
674
  placeholder,
382
675
  submitLabel,
383
676
  value,
677
+ showNuiIcons = false,
678
+ voiceSearchLabel = "",
679
+ askNuiLabel = "",
680
+ rotatingPlaceholders,
681
+ rotatingPlaceholderIntervalMs,
682
+ placeholderTag,
683
+ rotatingPlaceholderTag,
384
684
  ...props
385
685
  }) {
686
+ var _a;
386
687
  const field = react.useRef(null);
387
688
  const setField = react.useCallback(
388
689
  (node) => {
@@ -402,6 +703,14 @@ function SearchMessageInput({
402
703
  event.preventDefault();
403
704
  submitMessage();
404
705
  }
706
+ const isMobile = useMobileSearchLayout();
707
+ const hasQuery = value.trim() !== "";
708
+ const showRotatingPlaceholder = isMobile && !hasQuery && ((_a = rotatingPlaceholders == null ? void 0 : rotatingPlaceholders.length) != null ? _a : 0) > 0;
709
+ const rotatingPlaceholderText = useRotatingPlaceholder(
710
+ showRotatingPlaceholder,
711
+ rotatingPlaceholders,
712
+ rotatingPlaceholderIntervalMs
713
+ );
405
714
  function handleKeyDown(event) {
406
715
  if (event.key === "Enter" && !event.nativeEvent.isComposing) {
407
716
  event.preventDefault();
@@ -428,19 +737,40 @@ function SearchMessageInput({
428
737
  type: ICON_TYPES.SEARCH_FIELD
429
738
  }
430
739
  ) }),
431
- /* @__PURE__ */ jsxRuntime.jsx(
432
- SearchMessageInputField,
740
+ /* @__PURE__ */ jsxRuntime.jsxs(
741
+ SearchMessageInputFieldWrap,
433
742
  {
434
- ref: setField,
435
- "aria-label": inputLabel,
436
- autoComplete: "off",
437
- enterKeyHint: "search",
438
- onChange: (event) => onChange(event.target.value),
439
- onKeyDown: handleKeyDown,
440
- placeholder,
441
- spellCheck: false,
442
- type: "text",
443
- value
743
+ "data-testid": "search-message-input-wrap",
744
+ "data-rotating-placeholder": showRotatingPlaceholder ? "true" : void 0,
745
+ children: [
746
+ showRotatingPlaceholder ? /* @__PURE__ */ jsxRuntime.jsx(
747
+ SearchMessageInputRotatingPlaceholder,
748
+ {
749
+ "data-testid": "search-rotating-placeholder",
750
+ ...rotatingPlaceholderTag != null ? rotatingPlaceholderTag : {},
751
+ children: rotatingPlaceholderText
752
+ }
753
+ ) : null,
754
+ /* @__PURE__ */ jsxRuntime.jsx(
755
+ SearchMessageInputField,
756
+ {
757
+ ...placeholderTag != null ? placeholderTag : {},
758
+ ref: setField,
759
+ id: "header-product-search",
760
+ name: "header-product-search",
761
+ "aria-label": inputLabel,
762
+ autoComplete: "off",
763
+ autoCorrect: "off",
764
+ enterKeyHint: "search",
765
+ onChange: (event) => onChange(event.target.value),
766
+ onKeyDown: handleKeyDown,
767
+ placeholder: showRotatingPlaceholder ? "" : placeholder,
768
+ spellCheck: false,
769
+ type: "text",
770
+ value
771
+ }
772
+ )
773
+ ]
444
774
  }
445
775
  ),
446
776
  value !== "" && /* @__PURE__ */ jsxRuntime.jsx(
@@ -449,9 +779,9 @@ function SearchMessageInput({
449
779
  type: "button",
450
780
  "aria-label": clearLabel,
451
781
  onClick: () => {
452
- var _a;
782
+ var _a2;
453
783
  onChange("");
454
- (_a = field.current) == null ? void 0 : _a.focus();
784
+ (_a2 = field.current) == null ? void 0 : _a2.focus();
455
785
  },
456
786
  children: /* @__PURE__ */ jsxRuntime.jsx(
457
787
  Icon,
@@ -462,7 +792,11 @@ function SearchMessageInput({
462
792
  }
463
793
  )
464
794
  }
465
- )
795
+ ),
796
+ showNuiIcons ? /* @__PURE__ */ jsxRuntime.jsxs(SearchMessageInputAuxiliary, { "data-testid": "search-nui-icons", children: [
797
+ /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-label": voiceSearchLabel, "data-testid": "search-nui-voice", children: /* @__PURE__ */ jsxRuntime.jsx(BrandedVoiceSearchIcon, {}) }),
798
+ /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-label": askNuiLabel, "data-testid": "search-nui-sparkle", children: /* @__PURE__ */ jsxRuntime.jsx(BrandedSparkleIcon, {}) })
799
+ ] }) : null
466
800
  ]
467
801
  }
468
802
  );
@@ -618,19 +952,23 @@ function RecentSearches({
618
952
  clearLabel,
619
953
  moreLabel,
620
954
  onSelect,
621
- onClear
955
+ onClear,
956
+ titleTag,
957
+ clearTag,
958
+ enableTag
622
959
  }) {
623
960
  const [showAll, setShowAll] = react.useState(false);
624
961
  const visible = showAll ? items : items.slice(0, MAX_RECENT);
625
- return /* @__PURE__ */ jsxRuntime.jsxs(RecentSearchesSection, { "aria-label": title, children: [
962
+ return /* @__PURE__ */ jsxRuntime.jsxs(RecentSearchesSection, { "aria-label": title, ...enableTag != null ? enableTag : {}, children: [
626
963
  /* @__PURE__ */ jsxRuntime.jsxs(RecentSearchesHeader, { children: [
627
- /* @__PURE__ */ jsxRuntime.jsx(RecentSearchesTitle, { children: title }),
964
+ /* @__PURE__ */ jsxRuntime.jsx(RecentSearchesTitle, { ...titleTag != null ? titleTag : {}, children: title }),
628
965
  /* @__PURE__ */ jsxRuntime.jsx(
629
966
  RecentSearchesClearButton,
630
967
  {
631
968
  type: "button",
632
969
  onMouseDown: (e) => e.preventDefault(),
633
970
  onClick: onClear,
971
+ ...clearTag != null ? clearTag : {},
634
972
  children: clearLabel
635
973
  }
636
974
  )
@@ -660,23 +998,18 @@ function RecentSearches({
660
998
  }
661
999
  var SUGGESTION_MOBILE_MAX_PX = 1024;
662
1000
  var colors4 = {
663
- text: "#111827",
664
- muted: "#6b7280"};
665
- var SuggestionOption = styled4__default.default.li`
666
- display: flex;
1001
+ text: "#111827"
1002
+ };
1003
+ var SuggestionRow = styled4__default.default.li`
1004
+ display: grid;
1005
+ grid-template-columns: minmax(0, 1fr);
667
1006
  align-items: center;
1007
+ justify-items: stretch;
668
1008
  width: 100%;
669
1009
  min-height: 58px;
670
1010
  padding: 4px 24px;
671
1011
  box-sizing: border-box;
672
1012
  color: ${colors4.text};
673
- `;
674
- var SuggestionRow = styled4__default.default(SuggestionOption)`
675
- display: grid;
676
- grid-template-columns: minmax(0, 1fr) 18px;
677
- align-items: center;
678
- column-gap: 12px;
679
- width: 100%;
680
1013
  background: transparent;
681
1014
 
682
1015
  &[data-highlighted='true'],
@@ -688,23 +1021,20 @@ var SuggestionRow = styled4__default.default(SuggestionOption)`
688
1021
  opacity: 0.75;
689
1022
  }
690
1023
 
691
- &[data-suggestion-type='did-you-mean'] {
692
- grid-template-columns: minmax(0, 1fr);
693
- }
694
-
695
1024
  @media (max-width: ${SUGGESTION_MOBILE_MAX_PX}px) {
696
1025
  padding: 6px 24px;
697
- column-gap: 8px;
698
1026
  }
699
1027
  `;
1028
+ var SuggestionProductSnippet = styled4__default.default.div`
1029
+ display: block;
1030
+ min-width: 0;
1031
+ width: 100%;
1032
+ `;
700
1033
  var SuggestionContentWrapper = styled4__default.default.button`
701
1034
  appearance: none;
702
1035
  background: transparent;
703
1036
  border: 0;
704
- display: grid;
705
- grid-template-columns: 50px minmax(0, 1fr);
706
- align-items: center;
707
- column-gap: 16px;
1037
+ display: block;
708
1038
  width: 100%;
709
1039
  min-width: 0;
710
1040
  margin: 0;
@@ -713,32 +1043,12 @@ var SuggestionContentWrapper = styled4__default.default.button`
713
1043
  cursor: pointer;
714
1044
  font: inherit;
715
1045
  outline: none;
716
- border-radius: 6px;
717
1046
  text-align: start;
718
1047
 
719
- &[data-out-of-stock='true'] {
720
- cursor: default;
721
- }
722
-
723
- &[data-has-image='false'] {
724
- grid-template-columns: minmax(0, 1fr);
725
- }
726
-
727
1048
  &:focus-visible {
728
1049
  outline: 2px solid ${colors4.text};
729
1050
  outline-offset: 3px;
730
1051
  }
731
-
732
- &[data-suggestion-type='did-you-mean'] {
733
- grid-template-columns: minmax(0, 1fr);
734
- }
735
- `;
736
- var SuggestionThumbnail = styled4__default.default.img`
737
- width: 50px;
738
- height: 50px;
739
- object-fit: contain;
740
- flex-shrink: 0;
741
- align-self: center;
742
1052
  `;
743
1053
  var SuggestionLabel = styled4__default.default.span`
744
1054
  display: block;
@@ -755,202 +1065,187 @@ var SuggestionLabel = styled4__default.default.span`
755
1065
  line-height: 20px;
756
1066
  }
757
1067
  `;
758
- var SuggestionActionIcon = styled4__default.default.span`
759
- display: inline-flex;
760
- align-items: center;
761
- justify-content: center;
762
- width: 24px;
763
- height: 24px;
764
- color: var(--suggestion-icon-color, ${colors4.text});
765
- flex-shrink: 0;
766
- align-self: center;
767
-
768
- &[data-cart-disabled='true'] {
769
- color: var(--suggestion-muted, ${colors4.muted});
770
- }
771
-
772
- svg {
773
- width: 24px;
774
- height: 24px;
775
- display: block;
776
- }
777
- `;
778
- var SuggestionActionButton = styled4__default.default.button`
779
- display: inline-flex;
780
- align-items: center;
781
- justify-content: center;
782
- width: 24px;
783
- height: 24px;
784
- margin: 0;
785
- padding: 0;
786
- border: none;
787
- background: transparent;
788
- color: var(--suggestion-icon-color, ${colors4.text});
789
- flex-shrink: 0;
790
- align-self: center;
791
- cursor: pointer;
792
-
793
- &:focus-visible {
794
- outline: 2px solid ${colors4.text};
795
- outline-offset: 3px;
796
- border-radius: 4px;
797
- }
798
-
799
- svg {
800
- width: 24px;
801
- height: 24px;
802
- display: block;
803
- }
804
- `;
805
1068
 
806
1069
  // src/components/SuggestionRow/helpers.ts
807
1070
  function getSuggestionUrl(option) {
808
1071
  var _a, _b;
809
1072
  return "url" in option ? (_b = (_a = option.url) != null ? _a : option.href) != null ? _b : "" : "";
810
1073
  }
1074
+ function suggestionRequiresProductPage(option) {
1075
+ var _a;
1076
+ if (option.requiresProductPage === true) {
1077
+ return true;
1078
+ }
1079
+ if (option.requiresProductPage === false) {
1080
+ return false;
1081
+ }
1082
+ if (option.productType === "bundle") {
1083
+ return true;
1084
+ }
1085
+ const skuCount = Number((_a = option.skuCount) != null ? _a : 0);
1086
+ return skuCount > 1;
1087
+ }
811
1088
  function getSuggestionDisplayData(option) {
812
1089
  if ("suggestionType" in option) {
813
1090
  return {
814
1091
  imageSrc: "",
815
1092
  displayLabel: option.value,
1093
+ requiresProductPage: false,
816
1094
  isBundle: false,
817
1095
  isDidYouMean: true,
818
1096
  isOutOfStock: false,
819
1097
  isCartActionDisabled: false
820
1098
  };
821
1099
  }
1100
+ const requiresProductPage = suggestionRequiresProductPage(option);
822
1101
  return {
823
1102
  imageSrc: option.imageURL.trim() || option.thumbnail.trim(),
824
1103
  displayLabel: option.value,
825
- isBundle: option.productType === "bundle",
1104
+ requiresProductPage,
1105
+ isBundle: requiresProductPage,
826
1106
  isDidYouMean: false,
827
1107
  isOutOfStock: option.outOfStock,
828
1108
  isCartActionDisabled: option.cartActionDisabled
829
1109
  };
830
1110
  }
831
- var GTM_SEARCH_RESULT_CLICK = "searchResultClick";
832
- var flag = (value) => value ? "true" : "false";
833
- function passArrowKeysToList(event, onNavigate) {
834
- const direction = getArrowDirection(event);
835
- if (direction === null) return;
836
- event.preventDefault();
837
- onNavigate(direction);
1111
+ var useIsomorphicLayoutEffect = typeof window === "undefined" ? react.useEffect : react.useLayoutEffect;
1112
+ function assignProductControlRef(node, controlRef) {
1113
+ const productButton = node == null ? void 0 : node.querySelector("button");
1114
+ controlRef == null ? void 0 : controlRef(productButton != null ? productButton : null);
838
1115
  }
839
- function SuggestionImage({
840
- fallbackImageUrl,
841
- id,
842
- src
843
- }) {
844
- return /* @__PURE__ */ jsxRuntime.jsx(
845
- SuggestionThumbnail,
846
- {
847
- src: src || fallbackImageUrl,
848
- alt: "",
849
- "aria-hidden": true,
850
- "data-testid": `suggestion-thumbnail-${id}`,
851
- onError: (event) => {
852
- const image = event.currentTarget;
853
- if (fallbackImageUrl && image.getAttribute("src") !== fallbackImageUrl) {
854
- image.src = fallbackImageUrl;
855
- }
856
- }
857
- }
858
- );
1116
+ function snippetCtaProps(display, addToCartLabel, openBundleLabel, logos) {
1117
+ if (display.requiresProductPage) {
1118
+ return {
1119
+ ctaDisabled: false,
1120
+ ctaLogo: logos.PRODUCT_PAGE_LOGO,
1121
+ ctaAriaLabel: openBundleLabel(display.displayLabel)
1122
+ };
1123
+ }
1124
+ return {
1125
+ ctaDisabled: display.isCartActionDisabled,
1126
+ ctaLogo: logos.CART_LOGO,
1127
+ ctaAriaLabel: addToCartLabel(display.displayLabel)
1128
+ };
859
1129
  }
860
- function SuggestionContent({
1130
+ function ProductSuggestionSnippet({
1131
+ addToCartLabel,
861
1132
  controlRef,
862
1133
  display,
863
1134
  fallbackImageUrl,
864
1135
  onHighlightSuggestion,
1136
+ onNavigate,
1137
+ onRunSuggestionAction,
865
1138
  onSelectSuggestion,
1139
+ openBundleLabel,
1140
+ openProductPageLabel,
866
1141
  suggestionIndex,
867
1142
  suggestionOption
868
1143
  }) {
869
- const { displayLabel, imageSrc, isDidYouMean, isOutOfStock } = display;
870
- return /* @__PURE__ */ jsxRuntime.jsxs(
871
- SuggestionContentWrapper,
872
- {
873
- ref: controlRef,
874
- type: "button",
875
- "aria-disabled": isOutOfStock ? true : void 0,
876
- "data-testid": `suggestion-content-${suggestionOption.id}`,
877
- "data-suggestion-type": isDidYouMean ? "did-you-mean" : "product",
878
- "data-has-image": flag(!isDidYouMean),
879
- "data-out-of-stock": flag(isOutOfStock),
880
- "data-gtm-type": GTM_SEARCH_RESULT_CLICK,
881
- "data-gtm-result-title": displayLabel,
882
- "data-gtm-result-url": getSuggestionUrl(suggestionOption),
883
- onFocus: () => onHighlightSuggestion(suggestionIndex),
884
- onClick: () => {
885
- if (!isOutOfStock) onSelectSuggestion(suggestionOption);
886
- },
887
- children: [
888
- !isDidYouMean && /* @__PURE__ */ jsxRuntime.jsx(
889
- SuggestionImage,
890
- {
891
- fallbackImageUrl,
892
- id: suggestionOption.id,
893
- src: imageSrc
894
- }
895
- ),
896
- /* @__PURE__ */ jsxRuntime.jsx(SuggestionLabel, { children: displayLabel })
897
- ]
1144
+ const [productModule, setProductModule] = react.useState(null);
1145
+ const hostRef = react.useRef(null);
1146
+ react.useEffect(() => {
1147
+ if (typeof window === "undefined") {
1148
+ return void 0;
898
1149
  }
899
- );
900
- }
901
- function ActionIcon({
902
- id,
903
- isBundle,
904
- isInteractive
905
- }) {
906
- return /* @__PURE__ */ jsxRuntime.jsx(
907
- Icon,
908
- {
909
- color: "currentColor",
910
- cursor: isInteractive ? ICON_CURSORS.POINTER : ICON_CURSORS.DEFAULT,
911
- size: ICON_SIZES.LARGE,
912
- testId: isBundle ? `suggestion-bundle-icon-${id}` : `suggestion-cart-icon-${id}`,
913
- type: isBundle ? ICON_TYPES.SUGGESTION_TASK : ICON_TYPES.SUGGESTION_CART
1150
+ let canceled = false;
1151
+ void import('@nuskin/react-product-components').then((module) => {
1152
+ if (!canceled) {
1153
+ setProductModule(module);
1154
+ }
1155
+ });
1156
+ return () => {
1157
+ canceled = true;
1158
+ };
1159
+ }, []);
1160
+ useIsomorphicLayoutEffect(() => {
1161
+ if (productModule) {
1162
+ assignProductControlRef(hostRef.current, controlRef);
914
1163
  }
1164
+ }, [productModule, controlRef]);
1165
+ const { displayLabel, imageSrc } = display;
1166
+ const imageUrl = imageSrc || fallbackImageUrl;
1167
+ const setSnippetRef = react.useCallback(
1168
+ (node) => {
1169
+ hostRef.current = node;
1170
+ assignProductControlRef(node, controlRef);
1171
+ },
1172
+ [controlRef]
915
1173
  );
916
- }
917
- function SuggestionAction({
918
- actionLabel,
919
- isBundle,
920
- isCartActionDisabled,
921
- onHighlightSuggestion,
922
- onRunSuggestionAction,
923
- suggestionIndex,
924
- suggestionOption
925
- }) {
926
- const { id } = suggestionOption;
927
- const icon = /* @__PURE__ */ jsxRuntime.jsx(ActionIcon, { id, isBundle, isInteractive: !isCartActionDisabled });
928
- const testId = `suggestion-icon-${id}`;
929
- const kind = isBundle ? "bundle" : "single";
930
- if (isCartActionDisabled) {
1174
+ const onFocusCapture = react.useCallback(
1175
+ () => onHighlightSuggestion(suggestionIndex),
1176
+ [onHighlightSuggestion, suggestionIndex]
1177
+ );
1178
+ const onKeyDownCapture = react.useCallback(
1179
+ (event) => {
1180
+ const direction = getArrowDirection(event);
1181
+ if (direction === null) return;
1182
+ event.preventDefault();
1183
+ onNavigate(direction);
1184
+ },
1185
+ [onNavigate]
1186
+ );
1187
+ if (!productModule) {
931
1188
  return /* @__PURE__ */ jsxRuntime.jsx(
932
- SuggestionActionIcon,
1189
+ SuggestionProductSnippet,
933
1190
  {
934
- "data-testid": testId,
935
- "data-suggestion-type": kind,
936
- "data-cart-disabled": "true",
937
- children: icon
1191
+ ref: setSnippetRef,
1192
+ "data-testid": "suggestion-product-snippet",
1193
+ onFocusCapture,
1194
+ onKeyDownCapture,
1195
+ "aria-busy": "true",
1196
+ children: /* @__PURE__ */ jsxRuntime.jsx(SuggestionLabel, { children: displayLabel })
938
1197
  }
939
1198
  );
940
1199
  }
1200
+ const { ProductSnippet, PRODUCT_SNIPPET_CTA_LOGOS } = productModule;
1201
+ const { ctaDisabled, ctaLogo, ctaAriaLabel } = snippetCtaProps(
1202
+ display,
1203
+ addToCartLabel,
1204
+ openBundleLabel,
1205
+ PRODUCT_SNIPPET_CTA_LOGOS
1206
+ );
941
1207
  return /* @__PURE__ */ jsxRuntime.jsx(
942
- SuggestionActionButton,
1208
+ SuggestionProductSnippet,
943
1209
  {
944
- type: "button",
945
- "data-testid": testId,
946
- "data-suggestion-type": kind,
947
- "aria-label": actionLabel,
948
- onFocus: () => onHighlightSuggestion(suggestionIndex),
949
- onClick: () => onRunSuggestionAction(suggestionOption),
950
- children: icon
1210
+ ref: setSnippetRef,
1211
+ "data-testid": "suggestion-product-snippet",
1212
+ onFocusCapture,
1213
+ onKeyDownCapture,
1214
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1215
+ ProductSnippet,
1216
+ {
1217
+ title: displayLabel,
1218
+ imageUrl,
1219
+ imageAlt: "",
1220
+ productAriaLabel: openProductPageLabel(displayLabel),
1221
+ ctaLogo,
1222
+ ctaAriaLabel,
1223
+ ctaDisabled,
1224
+ onProductClick: () => onSelectSuggestion(suggestionOption),
1225
+ onCtaClick: () => {
1226
+ onHighlightSuggestion(suggestionIndex);
1227
+ if (ctaDisabled) {
1228
+ return;
1229
+ }
1230
+ onRunSuggestionAction(suggestionOption);
1231
+ }
1232
+ }
1233
+ )
951
1234
  }
952
1235
  );
953
1236
  }
1237
+ var GTM_SEARCH_RESULT_CLICK = "searchResultClick";
1238
+ var flag = (value) => value ? "true" : "false";
1239
+ function passArrowKeysToList(event, onNavigate) {
1240
+ const direction = getArrowDirection(event);
1241
+ if (direction === null) return;
1242
+ event.preventDefault();
1243
+ onNavigate(direction);
1244
+ }
1245
+ function cartDisabledAttr(isDidYouMean, display) {
1246
+ if (isDidYouMean || display.requiresProductPage) return "false";
1247
+ return flag(display.isCartActionDisabled);
1248
+ }
954
1249
  function SuggestionRow2({
955
1250
  addToCartLabel,
956
1251
  controlRef,
@@ -960,44 +1255,53 @@ function SuggestionRow2({
960
1255
  onRunSuggestionAction,
961
1256
  onSelectSuggestion,
962
1257
  openBundleLabel,
1258
+ openProductPageLabel,
963
1259
  suggestionIndex,
964
1260
  suggestionOption,
965
1261
  fallbackImageUrl = ""
966
1262
  }) {
967
1263
  const display = getSuggestionDisplayData(suggestionOption);
968
- const { displayLabel, isBundle, isDidYouMean, isOutOfStock, isCartActionDisabled } = display;
1264
+ const { displayLabel, isDidYouMean, isOutOfStock } = display;
969
1265
  const controls = { onHighlightSuggestion, suggestionIndex, suggestionOption };
970
- return /* @__PURE__ */ jsxRuntime.jsxs(
1266
+ return /* @__PURE__ */ jsxRuntime.jsx(
971
1267
  SuggestionRow,
972
1268
  {
973
1269
  "data-testid": `suggestion-row-${suggestionOption.id}`,
974
1270
  "data-highlighted": flag(isHighlighted),
975
1271
  "data-suggestion-type": isDidYouMean ? "did-you-mean" : "product",
1272
+ "data-product-snippet": isDidYouMean ? "false" : "true",
1273
+ "data-cart-disabled": cartDisabledAttr(isDidYouMean, display),
976
1274
  onMouseEnter: () => onHighlightSuggestion(suggestionIndex),
977
1275
  onKeyDown: (event) => passArrowKeysToList(event, onNavigate),
978
1276
  "data-out-of-stock": flag(isOutOfStock),
979
- children: [
980
- /* @__PURE__ */ jsxRuntime.jsx(
981
- SuggestionContent,
982
- {
983
- ...controls,
984
- controlRef,
985
- display,
986
- fallbackImageUrl,
987
- onSelectSuggestion
988
- }
989
- ),
990
- !isDidYouMean && /* @__PURE__ */ jsxRuntime.jsx(
991
- SuggestionAction,
992
- {
993
- ...controls,
994
- actionLabel: isBundle ? openBundleLabel(displayLabel) : addToCartLabel(displayLabel),
995
- isBundle,
996
- isCartActionDisabled,
997
- onRunSuggestionAction
998
- }
999
- )
1000
- ]
1277
+ "data-gtm-type": GTM_SEARCH_RESULT_CLICK,
1278
+ "data-gtm-result-title": displayLabel,
1279
+ "data-gtm-result-url": getSuggestionUrl(suggestionOption),
1280
+ children: isDidYouMean ? /* @__PURE__ */ jsxRuntime.jsx(
1281
+ SuggestionContentWrapper,
1282
+ {
1283
+ type: "button",
1284
+ "data-testid": `suggestion-content-${suggestionOption.id}`,
1285
+ "data-suggestion-type": "did-you-mean",
1286
+ onFocus: () => onHighlightSuggestion(suggestionIndex),
1287
+ onClick: () => onSelectSuggestion(suggestionOption),
1288
+ children: /* @__PURE__ */ jsxRuntime.jsx(SuggestionLabel, { children: displayLabel })
1289
+ }
1290
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
1291
+ ProductSuggestionSnippet,
1292
+ {
1293
+ ...controls,
1294
+ addToCartLabel,
1295
+ controlRef,
1296
+ display,
1297
+ fallbackImageUrl,
1298
+ onNavigate,
1299
+ onRunSuggestionAction,
1300
+ onSelectSuggestion,
1301
+ openBundleLabel,
1302
+ openProductPageLabel
1303
+ }
1304
+ )
1001
1305
  }
1002
1306
  );
1003
1307
  }
@@ -1091,6 +1395,7 @@ var SearchSuggestions = react.forwardRef(function SearchSuggestions2({
1091
1395
  didYouMeanText,
1092
1396
  noSuggestionsText,
1093
1397
  openBundleLabel,
1398
+ openProductPageLabel,
1094
1399
  seeMoreText,
1095
1400
  suggestionsLabel,
1096
1401
  fallbackImageUrl,
@@ -1103,32 +1408,53 @@ var SearchSuggestions = react.forwardRef(function SearchSuggestions2({
1103
1408
  const headingId = react.useId();
1104
1409
  const rowControls = react.useRef([]);
1105
1410
  const seeMoreButton = react.useRef(null);
1411
+ const pendingFirstFocus = react.useRef(false);
1106
1412
  const rowCount = loading ? 0 : items.length;
1107
1413
  const showSeeMore = !loading && hasMore && !showDidYouMean;
1414
+ const showDidYouMeanHeading = showDidYouMean && didYouMeanText.trim() !== "";
1108
1415
  const stopCount = rowCount + (showSeeMore ? 1 : 0);
1109
1416
  function focusStop(index) {
1110
1417
  const stop = index < rowCount ? rowControls.current[index] : seeMoreButton.current;
1111
1418
  stop == null ? void 0 : stop.focus();
1419
+ return Boolean(stop);
1112
1420
  }
1113
1421
  function moveFrom(index, direction) {
1114
- const next = index + direction;
1115
- if (next < 0) onLeaveTop();
1116
- else if (next < stopCount) focusStop(next);
1422
+ let next = index + direction;
1423
+ while (next >= 0 && next < stopCount) {
1424
+ if (focusStop(next)) return;
1425
+ next += direction;
1426
+ }
1427
+ if (next < 0) {
1428
+ if (index === 0) onLeaveTop();
1429
+ else focusStop(index);
1430
+ }
1117
1431
  }
1118
1432
  react.useImperativeHandle(ref, () => ({
1119
1433
  focusFirst() {
1120
- if (stopCount === 0) return false;
1121
- focusStop(0);
1122
- return true;
1434
+ if (rowCount > 0) {
1435
+ const stop = rowControls.current[0];
1436
+ if (!stop) {
1437
+ pendingFirstFocus.current = true;
1438
+ return false;
1439
+ }
1440
+ pendingFirstFocus.current = false;
1441
+ stop.focus();
1442
+ return true;
1443
+ }
1444
+ if (showSeeMore && seeMoreButton.current) {
1445
+ seeMoreButton.current.focus();
1446
+ return true;
1447
+ }
1448
+ return false;
1123
1449
  }
1124
1450
  }));
1125
1451
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1126
- showDidYouMean && /* @__PURE__ */ jsxRuntime.jsx(SuggestionSectionHeading, { id: headingId, "data-testid": "autocomplete-did-you-mean-heading", children: didYouMeanText }),
1452
+ showDidYouMeanHeading ? /* @__PURE__ */ jsxRuntime.jsx(SuggestionSectionHeading, { id: headingId, "data-testid": "autocomplete-did-you-mean-heading", children: didYouMeanText }) : null,
1127
1453
  /* @__PURE__ */ jsxRuntime.jsxs(
1128
1454
  SearchSuggestionsList,
1129
1455
  {
1130
- "aria-label": showDidYouMean ? void 0 : suggestionsLabel,
1131
- "aria-labelledby": showDidYouMean ? headingId : void 0,
1456
+ "aria-label": showDidYouMeanHeading ? void 0 : suggestionsLabel,
1457
+ "aria-labelledby": showDidYouMeanHeading ? headingId : void 0,
1132
1458
  "aria-busy": loading,
1133
1459
  "data-testid": "autocomplete-results-list",
1134
1460
  children: [
@@ -1137,8 +1463,13 @@ var SearchSuggestions = react.forwardRef(function SearchSuggestions2({
1137
1463
  {
1138
1464
  addToCartLabel,
1139
1465
  openBundleLabel,
1466
+ openProductPageLabel,
1140
1467
  controlRef: (control) => {
1141
1468
  rowControls.current[index] = control;
1469
+ if (control && index === 0 && pendingFirstFocus.current) {
1470
+ pendingFirstFocus.current = false;
1471
+ control.focus();
1472
+ }
1142
1473
  },
1143
1474
  isHighlighted: index === highlightedIndex,
1144
1475
  onHighlightSuggestion: setHighlightedIndex,
@@ -1167,6 +1498,10 @@ var SearchSuggestions = react.forwardRef(function SearchSuggestions2({
1167
1498
  )
1168
1499
  ] });
1169
1500
  });
1501
+ function shouldShowRecentSearches(hasQuery, recentSearches) {
1502
+ if (hasQuery || !recentSearches) return false;
1503
+ return recentSearches.items.length > 0 || Boolean(recentSearches.showWhenEmpty);
1504
+ }
1170
1505
  function useIsMounted() {
1171
1506
  const [isMounted, setIsMounted] = react.useState(false);
1172
1507
  react.useEffect(() => {
@@ -1208,6 +1543,83 @@ function getStatusText({ loading, showNoResults, items }, copy) {
1208
1543
  if (showNoResults) return copy.noSuggestions;
1209
1544
  return items.length > 0 ? copy.suggestionsCount(items.length) : "";
1210
1545
  }
1546
+ function messageInputEditProps(editTags) {
1547
+ if (!editTags) return {};
1548
+ const props = {};
1549
+ if (editTags.searchPlaceholder) props.placeholderTag = editTags.searchPlaceholder;
1550
+ if (editTags.mobileRotatingPlaceholder) {
1551
+ props.rotatingPlaceholderTag = editTags.mobileRotatingPlaceholder;
1552
+ }
1553
+ return props;
1554
+ }
1555
+ function layoutCancelEditProps(editTags) {
1556
+ if (!editTags) return {};
1557
+ const props = {};
1558
+ if (editTags.cancelLabel) props.cancelLabelTag = editTags.cancelLabel;
1559
+ if (editTags.cancelShowIcon) props.cancelShowIconTag = editTags.cancelShowIcon;
1560
+ return props;
1561
+ }
1562
+ function recentSearchesEditProps(editTags) {
1563
+ if (!editTags) return {};
1564
+ const props = {};
1565
+ if (editTags.recentSearchesHeading) props.titleTag = editTags.recentSearchesHeading;
1566
+ if (editTags.clearAllLabel) props.clearTag = editTags.clearAllLabel;
1567
+ if (editTags.enableRecentSearches) props.enableTag = editTags.enableRecentSearches;
1568
+ return props;
1569
+ }
1570
+ function SearchPanelAutocompleteBody({
1571
+ copy,
1572
+ editTags,
1573
+ fallbackImageUrl,
1574
+ hasQuery,
1575
+ inputRef,
1576
+ recentSearches,
1577
+ showSuggestions,
1578
+ suggestions,
1579
+ suggestionsRef
1580
+ }) {
1581
+ var _a;
1582
+ const showRecent = shouldShowRecentSearches(hasQuery, recentSearches);
1583
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1584
+ SearchSuggestionsPanel,
1585
+ {
1586
+ "data-testid": "autocomplete-suggestions-panel",
1587
+ ...(_a = editTags == null ? void 0 : editTags.enableAutocomplete) != null ? _a : {},
1588
+ children: [
1589
+ /* @__PURE__ */ jsxRuntime.jsx(SearchPanelStatus, { "aria-atomic": "true", "data-testid": "search-panel-status", children: showSuggestions ? getStatusText(suggestions, copy) : "" }),
1590
+ showSuggestions ? /* @__PURE__ */ jsxRuntime.jsx(
1591
+ SearchSuggestions,
1592
+ {
1593
+ ...suggestions,
1594
+ ref: suggestionsRef,
1595
+ onLeaveTop: () => {
1596
+ var _a2;
1597
+ return (_a2 = inputRef.current) == null ? void 0 : _a2.focus();
1598
+ },
1599
+ addToCartLabel: copy.addToCart,
1600
+ didYouMeanText: copy.didYouMean,
1601
+ noSuggestionsText: copy.noSuggestions,
1602
+ openBundleLabel: copy.openBundle,
1603
+ openProductPageLabel: copy.openProductPage,
1604
+ seeMoreText: copy.seeMoreResults,
1605
+ suggestionsLabel: copy.suggestionsLabel,
1606
+ fallbackImageUrl
1607
+ }
1608
+ ) : null,
1609
+ showRecent && recentSearches ? /* @__PURE__ */ jsxRuntime.jsx(
1610
+ RecentSearches,
1611
+ {
1612
+ ...recentSearches,
1613
+ title: copy.recentSearches,
1614
+ clearLabel: copy.clearRecentSearches,
1615
+ moreLabel: copy.moreRecentSearches,
1616
+ ...recentSearchesEditProps(editTags)
1617
+ }
1618
+ ) : null
1619
+ ]
1620
+ }
1621
+ );
1622
+ }
1211
1623
  function SearchPanel({
1212
1624
  isOpen,
1213
1625
  onClose,
@@ -1216,10 +1628,15 @@ function SearchPanel({
1216
1628
  copy,
1217
1629
  input,
1218
1630
  suggestions,
1631
+ showSuggestions = true,
1219
1632
  recentSearches,
1220
- agentPanel
1633
+ agentPanel,
1634
+ showNuiIcons = false,
1635
+ showCancelIcon = true,
1636
+ rotatingPlaceholders,
1637
+ rotatingPlaceholderIntervalMs,
1638
+ editTags
1221
1639
  }) {
1222
- var _a;
1223
1640
  const inputRef = react.useRef(null);
1224
1641
  const layoutRef = react.useRef(null);
1225
1642
  const suggestionsRef = react.useRef(null);
@@ -1231,7 +1648,6 @@ function SearchPanel({
1231
1648
  useFocusOnOpen(hasAgent ? layoutRef : inputRef, isShown);
1232
1649
  if (!isShown) return null;
1233
1650
  const hasQuery = input.value.trim() !== "";
1234
- const hasRecentSearches = ((_a = recentSearches == null ? void 0 : recentSearches.items.length) != null ? _a : 0) > 0;
1235
1651
  const searchInput = /* @__PURE__ */ jsxRuntime.jsx(
1236
1652
  SearchMessageInput,
1237
1653
  {
@@ -1239,14 +1655,20 @@ function SearchPanel({
1239
1655
  inputLabel: copy.searchLabel,
1240
1656
  inputRef,
1241
1657
  onArrowDown: () => {
1242
- var _a2, _b;
1243
- return (_b = (_a2 = suggestionsRef.current) == null ? void 0 : _a2.focusFirst()) != null ? _b : false;
1658
+ var _a, _b;
1659
+ return (_b = (_a = suggestionsRef.current) == null ? void 0 : _a.focusFirst()) != null ? _b : false;
1244
1660
  },
1245
1661
  onChange: input.onChange,
1246
1662
  onSubmit: input.onSubmit,
1247
1663
  placeholder: copy.searchPlaceholder,
1248
1664
  submitLabel: copy.submitSearch,
1249
1665
  value: input.value,
1666
+ showNuiIcons,
1667
+ voiceSearchLabel: copy.voiceSearch,
1668
+ askNuiLabel: copy.askNui,
1669
+ ...messageInputEditProps(editTags),
1670
+ ...rotatingPlaceholders ? { rotatingPlaceholders } : {},
1671
+ ...rotatingPlaceholderIntervalMs != null ? { rotatingPlaceholderIntervalMs } : {},
1250
1672
  "data-testid": "search-panel-input"
1251
1673
  }
1252
1674
  );
@@ -1265,40 +1687,26 @@ function SearchPanel({
1265
1687
  "aria-label": copy.searchLabel,
1266
1688
  tabIndex: -1,
1267
1689
  closeLabel: copy.cancel,
1690
+ showCancelIcon,
1691
+ ...layoutCancelEditProps(editTags),
1268
1692
  onClose,
1269
1693
  logoSlot: logo,
1270
1694
  agentMode: hasAgent,
1271
1695
  inputSlot: hasAgent ? void 0 : searchInput,
1272
- children: agentPanel != null ? agentPanel : /* @__PURE__ */ jsxRuntime.jsxs(SearchSuggestionsPanel, { "data-testid": "autocomplete-suggestions-panel", children: [
1273
- /* @__PURE__ */ jsxRuntime.jsx(SearchPanelStatus, { "aria-atomic": "true", "data-testid": "search-panel-status", children: getStatusText(suggestions, copy) }),
1274
- /* @__PURE__ */ jsxRuntime.jsx(
1275
- SearchSuggestions,
1276
- {
1277
- ...suggestions,
1278
- ref: suggestionsRef,
1279
- onLeaveTop: () => {
1280
- var _a2;
1281
- return (_a2 = inputRef.current) == null ? void 0 : _a2.focus();
1282
- },
1283
- addToCartLabel: copy.addToCart,
1284
- didYouMeanText: copy.didYouMean,
1285
- noSuggestionsText: copy.noSuggestions,
1286
- openBundleLabel: copy.openBundle,
1287
- seeMoreText: copy.seeMoreResults,
1288
- suggestionsLabel: copy.suggestionsLabel,
1289
- fallbackImageUrl
1290
- }
1291
- ),
1292
- !hasQuery && recentSearches && hasRecentSearches && /* @__PURE__ */ jsxRuntime.jsx(
1293
- RecentSearches,
1294
- {
1295
- ...recentSearches,
1296
- title: copy.recentSearches,
1297
- clearLabel: copy.clearRecentSearches,
1298
- moreLabel: copy.moreRecentSearches
1299
- }
1300
- )
1301
- ] })
1696
+ children: agentPanel != null ? agentPanel : /* @__PURE__ */ jsxRuntime.jsx(
1697
+ SearchPanelAutocompleteBody,
1698
+ {
1699
+ copy,
1700
+ editTags,
1701
+ fallbackImageUrl,
1702
+ hasQuery,
1703
+ inputRef,
1704
+ recentSearches,
1705
+ showSuggestions,
1706
+ suggestions,
1707
+ suggestionsRef
1708
+ }
1709
+ )
1302
1710
  }
1303
1711
  )
1304
1712
  }