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

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
  )
@@ -658,25 +996,69 @@ function RecentSearches({
658
996
  ] })
659
997
  ] });
660
998
  }
999
+
1000
+ // src/components/SuggestionRow/helpers.ts
1001
+ function getSuggestionUrl(option) {
1002
+ var _a, _b;
1003
+ return "url" in option ? (_b = (_a = option.url) != null ? _a : option.href) != null ? _b : "" : "";
1004
+ }
1005
+ function suggestionRequiresProductPage(option) {
1006
+ var _a;
1007
+ if (option.requiresProductPage === true) {
1008
+ return true;
1009
+ }
1010
+ if (option.requiresProductPage === false) {
1011
+ return false;
1012
+ }
1013
+ if (option.productType === "bundle") {
1014
+ return true;
1015
+ }
1016
+ const skuCount = Number((_a = option.skuCount) != null ? _a : 0);
1017
+ return skuCount > 1;
1018
+ }
1019
+ function getSuggestionDisplayData(option) {
1020
+ if ("suggestionType" in option) {
1021
+ return {
1022
+ imageSrc: "",
1023
+ displayLabel: option.value,
1024
+ requiresProductPage: false,
1025
+ isBundle: false,
1026
+ isDidYouMean: true,
1027
+ isOutOfStock: false,
1028
+ isCartActionDisabled: false
1029
+ };
1030
+ }
1031
+ const requiresProductPage = suggestionRequiresProductPage(option);
1032
+ return {
1033
+ imageSrc: option.imageURL.trim() || option.thumbnail.trim(),
1034
+ displayLabel: option.value,
1035
+ requiresProductPage,
1036
+ isBundle: requiresProductPage,
1037
+ isDidYouMean: false,
1038
+ isOutOfStock: option.outOfStock,
1039
+ isCartActionDisabled: option.cartActionDisabled
1040
+ };
1041
+ }
1042
+ function optionalAddToCartHandlerProps(onAddSuggestionToCart) {
1043
+ if (!onAddSuggestionToCart) {
1044
+ return {};
1045
+ }
1046
+ return { onAddSuggestionToCart };
1047
+ }
661
1048
  var SUGGESTION_MOBILE_MAX_PX = 1024;
662
1049
  var colors4 = {
663
- text: "#111827",
664
- muted: "#6b7280"};
665
- var SuggestionOption = styled4__default.default.li`
666
- display: flex;
1050
+ text: "#111827"
1051
+ };
1052
+ var SuggestionRow = styled4__default.default.li`
1053
+ display: grid;
1054
+ grid-template-columns: minmax(0, 1fr);
667
1055
  align-items: center;
1056
+ justify-items: stretch;
668
1057
  width: 100%;
669
1058
  min-height: 58px;
670
1059
  padding: 4px 24px;
671
1060
  box-sizing: border-box;
672
1061
  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
1062
  background: transparent;
681
1063
 
682
1064
  &[data-highlighted='true'],
@@ -688,23 +1070,25 @@ var SuggestionRow = styled4__default.default(SuggestionOption)`
688
1070
  opacity: 0.75;
689
1071
  }
690
1072
 
691
- &[data-suggestion-type='did-you-mean'] {
692
- grid-template-columns: minmax(0, 1fr);
693
- }
694
-
695
1073
  @media (max-width: ${SUGGESTION_MOBILE_MAX_PX}px) {
696
1074
  padding: 6px 24px;
697
- column-gap: 8px;
1075
+ }
1076
+ `;
1077
+ var SuggestionProductSnippet = styled4__default.default.div`
1078
+ display: block;
1079
+ min-width: 0;
1080
+ width: 100%;
1081
+
1082
+ /* ProductSnippet Icon SVGs default to cursor:default and cover the CTA hit target. */
1083
+ button svg {
1084
+ cursor: inherit;
698
1085
  }
699
1086
  `;
700
1087
  var SuggestionContentWrapper = styled4__default.default.button`
701
1088
  appearance: none;
702
1089
  background: transparent;
703
1090
  border: 0;
704
- display: grid;
705
- grid-template-columns: 50px minmax(0, 1fr);
706
- align-items: center;
707
- column-gap: 16px;
1091
+ display: block;
708
1092
  width: 100%;
709
1093
  min-width: 0;
710
1094
  margin: 0;
@@ -713,32 +1097,12 @@ var SuggestionContentWrapper = styled4__default.default.button`
713
1097
  cursor: pointer;
714
1098
  font: inherit;
715
1099
  outline: none;
716
- border-radius: 6px;
717
1100
  text-align: start;
718
1101
 
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
1102
  &:focus-visible {
728
1103
  outline: 2px solid ${colors4.text};
729
1104
  outline-offset: 3px;
730
1105
  }
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
1106
  `;
743
1107
  var SuggestionLabel = styled4__default.default.span`
744
1108
  display: block;
@@ -755,202 +1119,153 @@ var SuggestionLabel = styled4__default.default.span`
755
1119
  line-height: 20px;
756
1120
  }
757
1121
  `;
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
-
806
- // src/components/SuggestionRow/helpers.ts
807
- function getSuggestionUrl(option) {
808
- var _a, _b;
809
- return "url" in option ? (_b = (_a = option.url) != null ? _a : option.href) != null ? _b : "" : "";
1122
+ var useIsomorphicLayoutEffect = typeof window === "undefined" ? react.useEffect : react.useLayoutEffect;
1123
+ function assignProductControlRef(node, controlRef) {
1124
+ const productButton = node == null ? void 0 : node.querySelector("button");
1125
+ controlRef == null ? void 0 : controlRef(productButton != null ? productButton : null);
810
1126
  }
811
- function getSuggestionDisplayData(option) {
812
- if ("suggestionType" in option) {
1127
+ function snippetCtaProps(display, addToCartLabel, openBundleLabel, logos) {
1128
+ if (display.requiresProductPage) {
813
1129
  return {
814
- imageSrc: "",
815
- displayLabel: option.value,
816
- isBundle: false,
817
- isDidYouMean: true,
818
- isOutOfStock: false,
819
- isCartActionDisabled: false
1130
+ ctaDisabled: false,
1131
+ ctaLogo: logos.PRODUCT_PAGE_LOGO,
1132
+ ctaAriaLabel: openBundleLabel(display.displayLabel)
820
1133
  };
821
1134
  }
822
1135
  return {
823
- imageSrc: option.imageURL.trim() || option.thumbnail.trim(),
824
- displayLabel: option.value,
825
- isBundle: option.productType === "bundle",
826
- isDidYouMean: false,
827
- isOutOfStock: option.outOfStock,
828
- isCartActionDisabled: option.cartActionDisabled
1136
+ ctaDisabled: display.isCartActionDisabled,
1137
+ ctaLogo: logos.CART_LOGO,
1138
+ ctaAriaLabel: addToCartLabel(display.displayLabel)
829
1139
  };
830
1140
  }
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);
838
- }
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
- );
859
- }
860
- function SuggestionContent({
1141
+ function ProductSuggestionSnippet({
1142
+ addToCartLabel,
861
1143
  controlRef,
862
1144
  display,
863
1145
  fallbackImageUrl,
864
1146
  onHighlightSuggestion,
1147
+ onNavigate,
1148
+ onRunSuggestionAction,
1149
+ onAddSuggestionToCart,
865
1150
  onSelectSuggestion,
1151
+ openBundleLabel,
1152
+ openProductPageLabel,
866
1153
  suggestionIndex,
867
1154
  suggestionOption
868
1155
  }) {
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
- ]
1156
+ const [productModule, setProductModule] = react.useState(null);
1157
+ const hostRef = react.useRef(null);
1158
+ react.useEffect(() => {
1159
+ if (typeof window === "undefined") {
1160
+ return void 0;
898
1161
  }
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
1162
+ let canceled = false;
1163
+ void import('@nuskin/react-product-components').then((module) => {
1164
+ if (!canceled) {
1165
+ setProductModule(module);
1166
+ }
1167
+ });
1168
+ return () => {
1169
+ canceled = true;
1170
+ };
1171
+ }, []);
1172
+ useIsomorphicLayoutEffect(() => {
1173
+ if (productModule) {
1174
+ assignProductControlRef(hostRef.current, controlRef);
914
1175
  }
1176
+ }, [productModule, controlRef]);
1177
+ const { displayLabel, imageSrc } = display;
1178
+ const imageUrl = imageSrc || fallbackImageUrl;
1179
+ const setSnippetRef = react.useCallback(
1180
+ (node) => {
1181
+ hostRef.current = node;
1182
+ assignProductControlRef(node, controlRef);
1183
+ },
1184
+ [controlRef]
915
1185
  );
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) {
1186
+ const onFocusCapture = react.useCallback(
1187
+ () => onHighlightSuggestion(suggestionIndex),
1188
+ [onHighlightSuggestion, suggestionIndex]
1189
+ );
1190
+ const onKeyDownCapture = react.useCallback(
1191
+ (event) => {
1192
+ const direction = getArrowDirection(event);
1193
+ if (direction === null) return;
1194
+ event.preventDefault();
1195
+ onNavigate(direction);
1196
+ },
1197
+ [onNavigate]
1198
+ );
1199
+ if (!productModule) {
931
1200
  return /* @__PURE__ */ jsxRuntime.jsx(
932
- SuggestionActionIcon,
1201
+ SuggestionProductSnippet,
933
1202
  {
934
- "data-testid": testId,
935
- "data-suggestion-type": kind,
936
- "data-cart-disabled": "true",
937
- children: icon
1203
+ ref: setSnippetRef,
1204
+ "data-testid": "suggestion-product-snippet",
1205
+ onFocusCapture,
1206
+ onKeyDownCapture,
1207
+ "aria-busy": "true",
1208
+ children: /* @__PURE__ */ jsxRuntime.jsx(SuggestionLabel, { children: displayLabel })
938
1209
  }
939
1210
  );
940
1211
  }
1212
+ const { ProductSnippet, PRODUCT_SNIPPET_CTA_LOGOS } = productModule;
1213
+ const { ctaDisabled, ctaLogo, ctaAriaLabel } = snippetCtaProps(
1214
+ display,
1215
+ addToCartLabel,
1216
+ openBundleLabel,
1217
+ PRODUCT_SNIPPET_CTA_LOGOS
1218
+ );
941
1219
  return /* @__PURE__ */ jsxRuntime.jsx(
942
- SuggestionActionButton,
1220
+ SuggestionProductSnippet,
943
1221
  {
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
1222
+ ref: setSnippetRef,
1223
+ "data-testid": "suggestion-product-snippet",
1224
+ onFocusCapture,
1225
+ onKeyDownCapture,
1226
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1227
+ ProductSnippet,
1228
+ {
1229
+ title: displayLabel,
1230
+ imageUrl,
1231
+ imageAlt: "",
1232
+ productAriaLabel: openProductPageLabel(displayLabel),
1233
+ ctaLogo,
1234
+ ctaAriaLabel,
1235
+ ctaDisabled,
1236
+ onProductClick: () => onSelectSuggestion(suggestionOption),
1237
+ onCtaClick: () => {
1238
+ onHighlightSuggestion(suggestionIndex);
1239
+ if (ctaDisabled) {
1240
+ return;
1241
+ }
1242
+ if (display.requiresProductPage) {
1243
+ onRunSuggestionAction(suggestionOption);
1244
+ return;
1245
+ }
1246
+ if (onAddSuggestionToCart) {
1247
+ onAddSuggestionToCart(suggestionOption);
1248
+ return;
1249
+ }
1250
+ onRunSuggestionAction(suggestionOption);
1251
+ }
1252
+ }
1253
+ )
951
1254
  }
952
1255
  );
953
1256
  }
1257
+ var GTM_SEARCH_RESULT_CLICK = "searchResultClick";
1258
+ var flag = (value) => value ? "true" : "false";
1259
+ function passArrowKeysToList(event, onNavigate) {
1260
+ const direction = getArrowDirection(event);
1261
+ if (direction === null) return;
1262
+ event.preventDefault();
1263
+ onNavigate(direction);
1264
+ }
1265
+ function cartDisabledAttr(isDidYouMean, display) {
1266
+ if (isDidYouMean || display.requiresProductPage) return "false";
1267
+ return flag(display.isCartActionDisabled);
1268
+ }
954
1269
  function SuggestionRow2({
955
1270
  addToCartLabel,
956
1271
  controlRef,
@@ -958,46 +1273,58 @@ function SuggestionRow2({
958
1273
  onHighlightSuggestion,
959
1274
  onNavigate,
960
1275
  onRunSuggestionAction,
1276
+ onAddSuggestionToCart,
961
1277
  onSelectSuggestion,
962
1278
  openBundleLabel,
1279
+ openProductPageLabel,
963
1280
  suggestionIndex,
964
1281
  suggestionOption,
965
1282
  fallbackImageUrl = ""
966
1283
  }) {
967
1284
  const display = getSuggestionDisplayData(suggestionOption);
968
- const { displayLabel, isBundle, isDidYouMean, isOutOfStock, isCartActionDisabled } = display;
1285
+ const { displayLabel, isDidYouMean, isOutOfStock } = display;
969
1286
  const controls = { onHighlightSuggestion, suggestionIndex, suggestionOption };
970
- return /* @__PURE__ */ jsxRuntime.jsxs(
1287
+ const addToCartHandlerProps = optionalAddToCartHandlerProps(onAddSuggestionToCart);
1288
+ return /* @__PURE__ */ jsxRuntime.jsx(
971
1289
  SuggestionRow,
972
1290
  {
973
1291
  "data-testid": `suggestion-row-${suggestionOption.id}`,
974
1292
  "data-highlighted": flag(isHighlighted),
975
1293
  "data-suggestion-type": isDidYouMean ? "did-you-mean" : "product",
1294
+ "data-product-snippet": isDidYouMean ? "false" : "true",
1295
+ "data-cart-disabled": cartDisabledAttr(isDidYouMean, display),
976
1296
  onMouseEnter: () => onHighlightSuggestion(suggestionIndex),
977
1297
  onKeyDown: (event) => passArrowKeysToList(event, onNavigate),
978
1298
  "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
- ]
1299
+ "data-gtm-type": GTM_SEARCH_RESULT_CLICK,
1300
+ "data-gtm-result-title": displayLabel,
1301
+ "data-gtm-result-url": getSuggestionUrl(suggestionOption),
1302
+ children: isDidYouMean ? /* @__PURE__ */ jsxRuntime.jsx(
1303
+ SuggestionContentWrapper,
1304
+ {
1305
+ type: "button",
1306
+ "data-testid": `suggestion-content-${suggestionOption.id}`,
1307
+ "data-suggestion-type": "did-you-mean",
1308
+ onFocus: () => onHighlightSuggestion(suggestionIndex),
1309
+ onClick: () => onSelectSuggestion(suggestionOption),
1310
+ children: /* @__PURE__ */ jsxRuntime.jsx(SuggestionLabel, { children: displayLabel })
1311
+ }
1312
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
1313
+ ProductSuggestionSnippet,
1314
+ {
1315
+ ...controls,
1316
+ addToCartLabel,
1317
+ controlRef,
1318
+ display,
1319
+ fallbackImageUrl,
1320
+ onNavigate,
1321
+ onRunSuggestionAction,
1322
+ ...addToCartHandlerProps,
1323
+ onSelectSuggestion,
1324
+ openBundleLabel,
1325
+ openProductPageLabel
1326
+ }
1327
+ )
1001
1328
  }
1002
1329
  );
1003
1330
  }
@@ -1091,11 +1418,13 @@ var SearchSuggestions = react.forwardRef(function SearchSuggestions2({
1091
1418
  didYouMeanText,
1092
1419
  noSuggestionsText,
1093
1420
  openBundleLabel,
1421
+ openProductPageLabel,
1094
1422
  seeMoreText,
1095
1423
  suggestionsLabel,
1096
1424
  fallbackImageUrl,
1097
1425
  onSelect,
1098
1426
  onRunAction,
1427
+ onAddToCartAction,
1099
1428
  onSeeMore,
1100
1429
  onLeaveTop
1101
1430
  }, ref) {
@@ -1103,54 +1432,84 @@ var SearchSuggestions = react.forwardRef(function SearchSuggestions2({
1103
1432
  const headingId = react.useId();
1104
1433
  const rowControls = react.useRef([]);
1105
1434
  const seeMoreButton = react.useRef(null);
1435
+ const pendingFirstFocus = react.useRef(false);
1106
1436
  const rowCount = loading ? 0 : items.length;
1107
1437
  const showSeeMore = !loading && hasMore && !showDidYouMean;
1438
+ const showDidYouMeanHeading = showDidYouMean && didYouMeanText.trim() !== "";
1108
1439
  const stopCount = rowCount + (showSeeMore ? 1 : 0);
1109
1440
  function focusStop(index) {
1110
1441
  const stop = index < rowCount ? rowControls.current[index] : seeMoreButton.current;
1111
1442
  stop == null ? void 0 : stop.focus();
1443
+ return Boolean(stop);
1112
1444
  }
1113
1445
  function moveFrom(index, direction) {
1114
- const next = index + direction;
1115
- if (next < 0) onLeaveTop();
1116
- else if (next < stopCount) focusStop(next);
1446
+ let next = index + direction;
1447
+ while (next >= 0 && next < stopCount) {
1448
+ if (focusStop(next)) return;
1449
+ next += direction;
1450
+ }
1451
+ if (next < 0) {
1452
+ if (index === 0) onLeaveTop();
1453
+ else focusStop(index);
1454
+ }
1117
1455
  }
1118
1456
  react.useImperativeHandle(ref, () => ({
1119
1457
  focusFirst() {
1120
- if (stopCount === 0) return false;
1121
- focusStop(0);
1122
- return true;
1458
+ if (rowCount > 0) {
1459
+ const stop = rowControls.current[0];
1460
+ if (!stop) {
1461
+ pendingFirstFocus.current = true;
1462
+ return false;
1463
+ }
1464
+ pendingFirstFocus.current = false;
1465
+ stop.focus();
1466
+ return true;
1467
+ }
1468
+ if (showSeeMore && seeMoreButton.current) {
1469
+ seeMoreButton.current.focus();
1470
+ return true;
1471
+ }
1472
+ return false;
1123
1473
  }
1124
1474
  }));
1125
1475
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1126
- showDidYouMean && /* @__PURE__ */ jsxRuntime.jsx(SuggestionSectionHeading, { id: headingId, "data-testid": "autocomplete-did-you-mean-heading", children: didYouMeanText }),
1476
+ showDidYouMeanHeading ? /* @__PURE__ */ jsxRuntime.jsx(SuggestionSectionHeading, { id: headingId, "data-testid": "autocomplete-did-you-mean-heading", children: didYouMeanText }) : null,
1127
1477
  /* @__PURE__ */ jsxRuntime.jsxs(
1128
1478
  SearchSuggestionsList,
1129
1479
  {
1130
- "aria-label": showDidYouMean ? void 0 : suggestionsLabel,
1131
- "aria-labelledby": showDidYouMean ? headingId : void 0,
1480
+ "aria-label": showDidYouMeanHeading ? void 0 : suggestionsLabel,
1481
+ "aria-labelledby": showDidYouMeanHeading ? headingId : void 0,
1132
1482
  "aria-busy": loading,
1133
1483
  "data-testid": "autocomplete-results-list",
1134
1484
  children: [
1135
- !loading && items.map((option, index) => /* @__PURE__ */ jsxRuntime.jsx(
1136
- SuggestionRow2,
1137
- {
1138
- addToCartLabel,
1139
- openBundleLabel,
1140
- controlRef: (control) => {
1141
- rowControls.current[index] = control;
1485
+ !loading && items.map((option, index) => {
1486
+ const addToCartHandlerProps = optionalAddToCartHandlerProps(onAddToCartAction);
1487
+ return /* @__PURE__ */ jsxRuntime.jsx(
1488
+ SuggestionRow2,
1489
+ {
1490
+ addToCartLabel,
1491
+ openBundleLabel,
1492
+ openProductPageLabel,
1493
+ controlRef: (control) => {
1494
+ rowControls.current[index] = control;
1495
+ if (control && index === 0 && pendingFirstFocus.current) {
1496
+ pendingFirstFocus.current = false;
1497
+ control.focus();
1498
+ }
1499
+ },
1500
+ isHighlighted: index === highlightedIndex,
1501
+ onHighlightSuggestion: setHighlightedIndex,
1502
+ onNavigate: (direction) => moveFrom(index, direction),
1503
+ onRunSuggestionAction: onRunAction,
1504
+ ...addToCartHandlerProps,
1505
+ onSelectSuggestion: onSelect,
1506
+ suggestionIndex: index,
1507
+ suggestionOption: option,
1508
+ fallbackImageUrl
1142
1509
  },
1143
- isHighlighted: index === highlightedIndex,
1144
- onHighlightSuggestion: setHighlightedIndex,
1145
- onNavigate: (direction) => moveFrom(index, direction),
1146
- onRunSuggestionAction: onRunAction,
1147
- onSelectSuggestion: onSelect,
1148
- suggestionIndex: index,
1149
- suggestionOption: option,
1150
- fallbackImageUrl
1151
- },
1152
- option.id
1153
- )),
1510
+ option.id
1511
+ );
1512
+ }),
1154
1513
  showNoResults && /* @__PURE__ */ jsxRuntime.jsx(PassiveSuggestionOption, { "data-highlighted": "false", children: noSuggestionsText })
1155
1514
  ]
1156
1515
  }
@@ -1167,6 +1526,10 @@ var SearchSuggestions = react.forwardRef(function SearchSuggestions2({
1167
1526
  )
1168
1527
  ] });
1169
1528
  });
1529
+ function shouldShowRecentSearches(hasQuery, recentSearches) {
1530
+ if (hasQuery || !recentSearches) return false;
1531
+ return recentSearches.items.length > 0 || Boolean(recentSearches.showWhenEmpty);
1532
+ }
1170
1533
  function useIsMounted() {
1171
1534
  const [isMounted, setIsMounted] = react.useState(false);
1172
1535
  react.useEffect(() => {
@@ -1208,6 +1571,83 @@ function getStatusText({ loading, showNoResults, items }, copy) {
1208
1571
  if (showNoResults) return copy.noSuggestions;
1209
1572
  return items.length > 0 ? copy.suggestionsCount(items.length) : "";
1210
1573
  }
1574
+ function messageInputEditProps(editTags) {
1575
+ if (!editTags) return {};
1576
+ const props = {};
1577
+ if (editTags.searchPlaceholder) props.placeholderTag = editTags.searchPlaceholder;
1578
+ if (editTags.mobileRotatingPlaceholder) {
1579
+ props.rotatingPlaceholderTag = editTags.mobileRotatingPlaceholder;
1580
+ }
1581
+ return props;
1582
+ }
1583
+ function layoutCancelEditProps(editTags) {
1584
+ if (!editTags) return {};
1585
+ const props = {};
1586
+ if (editTags.cancelLabel) props.cancelLabelTag = editTags.cancelLabel;
1587
+ if (editTags.cancelShowIcon) props.cancelShowIconTag = editTags.cancelShowIcon;
1588
+ return props;
1589
+ }
1590
+ function recentSearchesEditProps(editTags) {
1591
+ if (!editTags) return {};
1592
+ const props = {};
1593
+ if (editTags.recentSearchesHeading) props.titleTag = editTags.recentSearchesHeading;
1594
+ if (editTags.clearAllLabel) props.clearTag = editTags.clearAllLabel;
1595
+ if (editTags.enableRecentSearches) props.enableTag = editTags.enableRecentSearches;
1596
+ return props;
1597
+ }
1598
+ function SearchPanelAutocompleteBody({
1599
+ copy,
1600
+ editTags,
1601
+ fallbackImageUrl,
1602
+ hasQuery,
1603
+ inputRef,
1604
+ recentSearches,
1605
+ showSuggestions,
1606
+ suggestions,
1607
+ suggestionsRef
1608
+ }) {
1609
+ var _a;
1610
+ const showRecent = shouldShowRecentSearches(hasQuery, recentSearches);
1611
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1612
+ SearchSuggestionsPanel,
1613
+ {
1614
+ "data-testid": "autocomplete-suggestions-panel",
1615
+ ...(_a = editTags == null ? void 0 : editTags.enableAutocomplete) != null ? _a : {},
1616
+ children: [
1617
+ /* @__PURE__ */ jsxRuntime.jsx(SearchPanelStatus, { "aria-atomic": "true", "data-testid": "search-panel-status", children: showSuggestions ? getStatusText(suggestions, copy) : "" }),
1618
+ showSuggestions ? /* @__PURE__ */ jsxRuntime.jsx(
1619
+ SearchSuggestions,
1620
+ {
1621
+ ...suggestions,
1622
+ ref: suggestionsRef,
1623
+ onLeaveTop: () => {
1624
+ var _a2;
1625
+ return (_a2 = inputRef.current) == null ? void 0 : _a2.focus();
1626
+ },
1627
+ addToCartLabel: copy.addToCart,
1628
+ didYouMeanText: copy.didYouMean,
1629
+ noSuggestionsText: copy.noSuggestions,
1630
+ openBundleLabel: copy.openBundle,
1631
+ openProductPageLabel: copy.openProductPage,
1632
+ seeMoreText: copy.seeMoreResults,
1633
+ suggestionsLabel: copy.suggestionsLabel,
1634
+ fallbackImageUrl
1635
+ }
1636
+ ) : null,
1637
+ showRecent && recentSearches ? /* @__PURE__ */ jsxRuntime.jsx(
1638
+ RecentSearches,
1639
+ {
1640
+ ...recentSearches,
1641
+ title: copy.recentSearches,
1642
+ clearLabel: copy.clearRecentSearches,
1643
+ moreLabel: copy.moreRecentSearches,
1644
+ ...recentSearchesEditProps(editTags)
1645
+ }
1646
+ ) : null
1647
+ ]
1648
+ }
1649
+ );
1650
+ }
1211
1651
  function SearchPanel({
1212
1652
  isOpen,
1213
1653
  onClose,
@@ -1216,10 +1656,15 @@ function SearchPanel({
1216
1656
  copy,
1217
1657
  input,
1218
1658
  suggestions,
1659
+ showSuggestions = true,
1219
1660
  recentSearches,
1220
- agentPanel
1661
+ agentPanel,
1662
+ showNuiIcons = false,
1663
+ showCancelIcon = true,
1664
+ rotatingPlaceholders,
1665
+ rotatingPlaceholderIntervalMs,
1666
+ editTags
1221
1667
  }) {
1222
- var _a;
1223
1668
  const inputRef = react.useRef(null);
1224
1669
  const layoutRef = react.useRef(null);
1225
1670
  const suggestionsRef = react.useRef(null);
@@ -1231,7 +1676,6 @@ function SearchPanel({
1231
1676
  useFocusOnOpen(hasAgent ? layoutRef : inputRef, isShown);
1232
1677
  if (!isShown) return null;
1233
1678
  const hasQuery = input.value.trim() !== "";
1234
- const hasRecentSearches = ((_a = recentSearches == null ? void 0 : recentSearches.items.length) != null ? _a : 0) > 0;
1235
1679
  const searchInput = /* @__PURE__ */ jsxRuntime.jsx(
1236
1680
  SearchMessageInput,
1237
1681
  {
@@ -1239,14 +1683,20 @@ function SearchPanel({
1239
1683
  inputLabel: copy.searchLabel,
1240
1684
  inputRef,
1241
1685
  onArrowDown: () => {
1242
- var _a2, _b;
1243
- return (_b = (_a2 = suggestionsRef.current) == null ? void 0 : _a2.focusFirst()) != null ? _b : false;
1686
+ var _a, _b;
1687
+ return (_b = (_a = suggestionsRef.current) == null ? void 0 : _a.focusFirst()) != null ? _b : false;
1244
1688
  },
1245
1689
  onChange: input.onChange,
1246
1690
  onSubmit: input.onSubmit,
1247
1691
  placeholder: copy.searchPlaceholder,
1248
1692
  submitLabel: copy.submitSearch,
1249
1693
  value: input.value,
1694
+ showNuiIcons,
1695
+ voiceSearchLabel: copy.voiceSearch,
1696
+ askNuiLabel: copy.askNui,
1697
+ ...messageInputEditProps(editTags),
1698
+ ...rotatingPlaceholders ? { rotatingPlaceholders } : {},
1699
+ ...rotatingPlaceholderIntervalMs != null ? { rotatingPlaceholderIntervalMs } : {},
1250
1700
  "data-testid": "search-panel-input"
1251
1701
  }
1252
1702
  );
@@ -1265,40 +1715,26 @@ function SearchPanel({
1265
1715
  "aria-label": copy.searchLabel,
1266
1716
  tabIndex: -1,
1267
1717
  closeLabel: copy.cancel,
1718
+ showCancelIcon,
1719
+ ...layoutCancelEditProps(editTags),
1268
1720
  onClose,
1269
1721
  logoSlot: logo,
1270
1722
  agentMode: hasAgent,
1271
1723
  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
- ] })
1724
+ children: agentPanel != null ? agentPanel : /* @__PURE__ */ jsxRuntime.jsx(
1725
+ SearchPanelAutocompleteBody,
1726
+ {
1727
+ copy,
1728
+ editTags,
1729
+ fallbackImageUrl,
1730
+ hasQuery,
1731
+ inputRef,
1732
+ recentSearches,
1733
+ showSuggestions,
1734
+ suggestions,
1735
+ suggestionsRef
1736
+ }
1737
+ )
1302
1738
  }
1303
1739
  )
1304
1740
  }