@nuskin/react-search-components 1.0.0-widget-integration.2 → 1.0.0-widget-integration.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +78 -50
- package/dist/index.d.mts +79 -147
- package/dist/index.d.ts +79 -147
- package/dist/index.js +729 -13072
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +716 -13051
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,70 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import React__default, { ComponentPropsWithoutRef, ReactNode } from 'react';
|
|
3
|
-
|
|
4
|
-
declare const SEARCH_MESSAGE_SENDERS: {
|
|
5
|
-
readonly AGENT: "agent";
|
|
6
|
-
readonly USER: "user";
|
|
7
|
-
};
|
|
8
|
-
type SearchMessageSender = (typeof SEARCH_MESSAGE_SENDERS)[keyof typeof SEARCH_MESSAGE_SENDERS];
|
|
9
|
-
|
|
10
|
-
interface SearchMessageProps extends Omit<ComponentPropsWithoutRef<'div'>, 'children'> {
|
|
11
|
-
sender: SearchMessageSender;
|
|
12
|
-
text: string;
|
|
13
|
-
}
|
|
14
|
-
declare function SearchMessage({ sender, text, ...props }: SearchMessageProps): React.JSX.Element;
|
|
15
|
-
|
|
16
|
-
interface SearchMessageInputBaseProps extends Omit<ComponentPropsWithoutRef<'form'>, 'children' | 'onSubmit' | 'onChange'> {
|
|
17
|
-
inputLabel: string;
|
|
18
|
-
/** Called on every keystroke — use for typeahead/debounced search */
|
|
19
|
-
onChange?: (value: string) => void;
|
|
20
|
-
onSubmit: (message: string) => void;
|
|
21
|
-
placeholder: string;
|
|
22
|
-
/** When false, input value is preserved after submit (search mode). Defaults to true (chat mode). */
|
|
23
|
-
clearOnSubmit?: boolean;
|
|
24
|
-
value?: string;
|
|
25
|
-
}
|
|
26
|
-
type SearchMessageInputVoiceProps = {
|
|
27
|
-
onVoiceInput: () => void;
|
|
28
|
-
showVoiceInput: true;
|
|
29
|
-
voiceListening?: boolean;
|
|
30
|
-
voiceInputLabel: string;
|
|
31
|
-
voiceListeningLabel?: string;
|
|
32
|
-
} | {
|
|
33
|
-
onVoiceInput?: never;
|
|
34
|
-
showVoiceInput?: false;
|
|
35
|
-
voiceListening?: never;
|
|
36
|
-
voiceInputLabel?: never;
|
|
37
|
-
voiceListeningLabel?: never;
|
|
38
|
-
};
|
|
39
|
-
type SearchMessageInputProps = SearchMessageInputBaseProps & SearchMessageInputVoiceProps;
|
|
40
|
-
/**
|
|
41
|
-
* The search box. There is no submit button: pressing Enter submits, as in master's search.
|
|
42
|
-
*/
|
|
43
|
-
declare function SearchMessageInput({ clearOnSubmit, inputLabel, onChange, onSubmit, onVoiceInput, placeholder, showVoiceInput, value, voiceInputLabel, voiceListening, voiceListeningLabel, ...props }: SearchMessageInputProps): React.JSX.Element;
|
|
44
|
-
|
|
45
|
-
interface SearchPanelProps extends Omit<ComponentPropsWithoutRef<'section'>, 'aria-label' | 'children'> {
|
|
46
|
-
'aria-label': string;
|
|
47
|
-
children: ReactNode;
|
|
48
|
-
closeLabel: string;
|
|
49
|
-
onClose: () => void;
|
|
50
|
-
initialPrompt?: string;
|
|
51
|
-
messageInputProps?: SearchMessageInputProps;
|
|
52
|
-
inputSlot?: ReactNode;
|
|
53
|
-
logoSlot?: ReactNode;
|
|
54
|
-
/** When true: content scrolls, input fixed at bottom (AI chat layout) */
|
|
55
|
-
chatMode?: boolean;
|
|
56
|
-
/**
|
|
57
|
-
* When true: the panel hosts an embedded agent. Children fill the space below the header
|
|
58
|
-
* and bring their own scrolling and input, so no input, input slot or initial prompt renders.
|
|
59
|
-
*/
|
|
60
|
-
agentMode?: boolean;
|
|
61
|
-
}
|
|
62
|
-
declare function SearchPanel({ 'aria-label': ariaLabel, agentMode, children, chatMode, closeLabel, initialPrompt, inputSlot, logoSlot, messageInputProps, onClose, ...props }: Readonly<SearchPanelProps>): React.JSX.Element;
|
|
1
|
+
import React from 'react';
|
|
63
2
|
|
|
64
3
|
type ProductType = 'bundle' | 'single';
|
|
65
4
|
/**
|
|
66
|
-
* A product suggestion
|
|
67
|
-
*
|
|
5
|
+
* A product suggestion, as the search SDK maps it. The SDK decides stock and add-to-cart
|
|
6
|
+
* availability, so `outOfStock` and `cartActionDisabled` are read as given.
|
|
7
|
+
*
|
|
8
|
+
* It mirrors the SDK's shape in full, and defines it here so this library stays presentational and
|
|
9
|
+
* imports nothing from the SDK. A handler the host types with its own item type therefore accepts
|
|
10
|
+
* these items.
|
|
68
11
|
*/
|
|
69
12
|
interface CatalogSuggestionItem {
|
|
70
13
|
id: string;
|
|
@@ -88,62 +31,68 @@ interface CatalogSuggestionItem {
|
|
|
88
31
|
keywords: string;
|
|
89
32
|
ingredientTerms: string[];
|
|
90
33
|
}
|
|
91
|
-
/**
|
|
92
|
-
|
|
34
|
+
/**
|
|
35
|
+
* A "Did You Mean?" row: a corrected search term, not a product.
|
|
36
|
+
*
|
|
37
|
+
* A type alias rather than an interface, so a host's own item type with extra fields still accepts
|
|
38
|
+
* it where the host types a handler with that richer type.
|
|
39
|
+
*/
|
|
40
|
+
type DidYouMeanItem = {
|
|
93
41
|
id: string;
|
|
94
42
|
value: string;
|
|
95
43
|
suggestionType: 'did-you-mean';
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
imageSrc: string;
|
|
100
|
-
displayLabel: string;
|
|
101
|
-
isBundle: boolean;
|
|
102
|
-
isDidYouMean: boolean;
|
|
103
|
-
isOutOfStock: boolean;
|
|
104
|
-
isCartActionDisabled: boolean;
|
|
105
|
-
}
|
|
106
|
-
interface SuggestionOptionWithTracking extends Omit<CatalogSuggestionItem, 'slug' | 'productSlug' | 'url' | 'href'> {
|
|
107
|
-
slug: string | null | undefined;
|
|
108
|
-
productSlug: string | null | undefined;
|
|
109
|
-
url: string | null | undefined;
|
|
110
|
-
href: string | null | undefined;
|
|
111
|
-
trackingUrl?: string;
|
|
112
|
-
[key: string]: unknown;
|
|
113
|
-
}
|
|
114
|
-
interface SuggestionRowProps {
|
|
115
|
-
inputRef: React__default.RefObject<HTMLElement | null>;
|
|
116
|
-
isHighlighted: boolean;
|
|
117
|
-
isSelected: boolean;
|
|
118
|
-
onHighlightSuggestion: (index: number) => void;
|
|
119
|
-
onRunSuggestionAction: (option: SuggestionOptionWithTracking) => void;
|
|
120
|
-
onSelectSuggestion: (option: SuggestionOptionWithTracking) => void;
|
|
121
|
-
registerSuggestionNode: (node: HTMLElement | null) => void;
|
|
122
|
-
suggestionIndex: number;
|
|
123
|
-
suggestionOption: SuggestionOptionWithTracking;
|
|
124
|
-
suggestionOptionId: string;
|
|
125
|
-
fallbackImageUrl?: string;
|
|
126
|
-
}
|
|
44
|
+
};
|
|
45
|
+
/** One row of suggestions: a product, or a "did you mean" term. */
|
|
46
|
+
type SuggestionOption = CatalogSuggestionItem | DidYouMeanItem;
|
|
127
47
|
|
|
128
|
-
/**
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Every piece of text the panel shows or announces. The panel has no text of its own, so the host
|
|
50
|
+
* supplies all of it, already translated. A function takes the number or name it needs to word the
|
|
51
|
+
* text for the locale.
|
|
52
|
+
*/
|
|
53
|
+
interface SearchPanelCopy {
|
|
54
|
+
/** The button that closes the panel. */
|
|
55
|
+
cancel: string;
|
|
56
|
+
/** Shown in the empty search box. */
|
|
57
|
+
searchPlaceholder: string;
|
|
58
|
+
/** The heading over the corrected search terms. */
|
|
59
|
+
didYouMean: string;
|
|
60
|
+
/** The row shown when nothing matches. Also announced. */
|
|
61
|
+
noSuggestions: string;
|
|
62
|
+
/** The button that shows the full results. */
|
|
63
|
+
seeMoreResults: string;
|
|
64
|
+
/** The heading over the recent searches. */
|
|
65
|
+
recentSearches: string;
|
|
66
|
+
/** The button that clears the recent searches. */
|
|
67
|
+
clearRecentSearches: string;
|
|
68
|
+
/** The chip that shows the rest of the recent searches, given how many are hidden. */
|
|
69
|
+
moreRecentSearches: (count: number) => string;
|
|
70
|
+
/** The accessible name of the dialog, the search landmark and the search box. */
|
|
71
|
+
searchLabel: string;
|
|
72
|
+
/** The accessible name of the magnifier button that submits the search. */
|
|
73
|
+
submitSearch: string;
|
|
74
|
+
/** The accessible name of the button that empties the search box. */
|
|
75
|
+
clearInput: string;
|
|
76
|
+
/** The accessible name of the list of suggestions, when it has no heading. */
|
|
77
|
+
suggestionsLabel: string;
|
|
78
|
+
/** The accessible name of a product's add-to-cart button, given the product's name. */
|
|
79
|
+
addToCart: (productName: string) => string;
|
|
80
|
+
/** The accessible name of a bundle's action button, given the bundle's name. */
|
|
81
|
+
openBundle: (productName: string) => string;
|
|
82
|
+
/** Announced while suggestions load. */
|
|
83
|
+
suggestionsLoading: string;
|
|
84
|
+
/** Announced when suggestions appear, given how many, for example "3 suggestions available". */
|
|
85
|
+
suggestionsCount: (count: number) => string;
|
|
137
86
|
}
|
|
138
87
|
/** The search box, controlled by the host. */
|
|
139
|
-
interface
|
|
88
|
+
interface SearchPanelInputProps {
|
|
140
89
|
value: string;
|
|
141
90
|
onChange: (value: string) => void;
|
|
142
91
|
onSubmit: (value: string) => void;
|
|
143
92
|
}
|
|
144
93
|
/** The suggestions the host has already fetched and filtered. */
|
|
145
|
-
interface
|
|
146
|
-
items: ReadonlyArray<
|
|
94
|
+
interface SearchPanelSuggestionsProps {
|
|
95
|
+
items: ReadonlyArray<SuggestionOption>;
|
|
147
96
|
loading: boolean;
|
|
148
97
|
/** Show the "no suggestions" row (the host decides when a fetch came back empty). */
|
|
149
98
|
showNoResults: boolean;
|
|
@@ -153,61 +102,44 @@ interface SearchModalSuggestionsProps {
|
|
|
153
102
|
hasMore: boolean;
|
|
154
103
|
/** The query the suggestions belong to (passed to the "see more" link). */
|
|
155
104
|
query: string;
|
|
156
|
-
onSelect: (option:
|
|
157
|
-
onRunAction: (option:
|
|
105
|
+
onSelect: (option: SuggestionOption) => void;
|
|
106
|
+
onRunAction: (option: SuggestionOption) => void;
|
|
158
107
|
onSeeMore: () => void;
|
|
159
108
|
}
|
|
160
109
|
/** Recent searches, shown while the search box is empty. */
|
|
161
|
-
interface
|
|
110
|
+
interface SearchPanelRecentSearches {
|
|
162
111
|
items: ReadonlyArray<string>;
|
|
163
112
|
onSelect: (query: string) => void;
|
|
164
113
|
onClear: () => void;
|
|
165
114
|
}
|
|
166
|
-
interface
|
|
115
|
+
interface SearchPanelProps {
|
|
167
116
|
isOpen: boolean;
|
|
168
117
|
onClose: () => void;
|
|
169
|
-
logo?:
|
|
170
|
-
cancelLabel?: string;
|
|
118
|
+
logo?: React.ReactNode;
|
|
171
119
|
fallbackImageUrl?: string;
|
|
172
|
-
copy
|
|
173
|
-
input:
|
|
174
|
-
suggestions:
|
|
175
|
-
recentSearches?:
|
|
120
|
+
copy: SearchPanelCopy;
|
|
121
|
+
input: SearchPanelInputProps;
|
|
122
|
+
suggestions: SearchPanelSuggestionsProps;
|
|
123
|
+
recentSearches?: SearchPanelRecentSearches;
|
|
176
124
|
/**
|
|
177
125
|
* An embedded agent (the NUi widget). When set, the panel switches to its agent layout: the
|
|
178
126
|
* search box, suggestions and recent searches are replaced by this content.
|
|
179
127
|
*/
|
|
180
|
-
agentPanel?:
|
|
128
|
+
agentPanel?: React.ReactNode;
|
|
181
129
|
}
|
|
182
130
|
|
|
183
131
|
/**
|
|
184
|
-
* The search panel: a
|
|
185
|
-
*
|
|
132
|
+
* The search panel: a search box, suggestions and recent searches or, when `agentPanel` is set, a
|
|
133
|
+
* header over an embedded agent. Full screen on small screens, a band across the top from the
|
|
134
|
+
* desktop breakpoint up.
|
|
186
135
|
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
136
|
+
* It is a panel, not a modal: the page behind it keeps scrolling, keyboard focus is not trapped,
|
|
137
|
+
* and the page is not hidden from assistive technology. It closes on Escape and on a press outside
|
|
138
|
+
* it, and puts focus back where it was when it closes.
|
|
139
|
+
*
|
|
140
|
+
* Presentational: it holds only UI state (highlighted row, expanded recent searches). Fetching,
|
|
141
|
+
* routing, navigation and all of its text belong to the host.
|
|
191
142
|
*/
|
|
192
|
-
declare function
|
|
193
|
-
|
|
194
|
-
declare function SuggestionRow({ inputRef, isHighlighted, isSelected, onHighlightSuggestion, onRunSuggestionAction, onSelectSuggestion, registerSuggestionNode, suggestionIndex, suggestionOption, suggestionOptionId, fallbackImageUrl, }: Readonly<SuggestionRowProps>): React__default.ReactElement;
|
|
195
|
-
|
|
196
|
-
declare function getSuggestionDisplayData(option: SuggestionOptionWithTracking): SuggestionDisplayData;
|
|
197
|
-
|
|
198
|
-
interface SeeMoreLinkProps {
|
|
199
|
-
seeMoreLinkRef: React__default.RefObject<HTMLButtonElement | null>;
|
|
200
|
-
seeMoreLinkFocused: boolean;
|
|
201
|
-
inputRef: React__default.RefObject<HTMLElement | null>;
|
|
202
|
-
onBlurSeeMoreLink: () => void;
|
|
203
|
-
onFocusSeeMoreLink: () => void;
|
|
204
|
-
onSeeMoreResults: () => void;
|
|
205
|
-
resetSeeMoreLinkFocus: () => void;
|
|
206
|
-
restoreLastSuggestion: () => void;
|
|
207
|
-
seeMoreResultsText: string;
|
|
208
|
-
searchQuery?: string;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
declare function SeeMoreLink({ seeMoreLinkRef, seeMoreLinkFocused, inputRef, onBlurSeeMoreLink, onFocusSeeMoreLink, onSeeMoreResults, resetSeeMoreLinkFocus, restoreLastSuggestion, seeMoreResultsText, searchQuery, }: Readonly<SeeMoreLinkProps>): React__default.ReactElement;
|
|
143
|
+
declare function SearchPanel({ isOpen, onClose, logo, fallbackImageUrl, copy, input, suggestions, recentSearches, agentPanel, }: Readonly<SearchPanelProps>): React.ReactElement | null;
|
|
212
144
|
|
|
213
|
-
export { type CatalogSuggestionItem, type DidYouMeanItem,
|
|
145
|
+
export { type CatalogSuggestionItem, type DidYouMeanItem, SearchPanel, type SearchPanelCopy, type SearchPanelInputProps, type SearchPanelProps, type SearchPanelRecentSearches, type SearchPanelSuggestionsProps, type SuggestionOption };
|