@nuskin/react-search-components 1.0.0-widget-integration.2 → 1.0.0

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 CHANGED
@@ -1,23 +1,24 @@
1
1
  # `@nuskin/react-search-components`
2
2
 
3
- UI-only React component library for Nu Skin header search experiences.
3
+ The Nu Skin header search panel, as a presentational React component.
4
4
 
5
- This repository contains presentational components ranging from internal design
6
- atoms through an eventual complete search widget. Data fetching, search state,
7
- translations, analytics, navigation, and other business behavior belong to a
8
- separate integration layer.
5
+ It renders what it is given and reports what the user does. Fetching suggestions,
6
+ holding search state, routing, and analytics belong to the host, which in practice
7
+ is `react-search-sdk`.
9
8
 
10
- ## Status
9
+ ## What it provides
11
10
 
12
- The repository exposes initial `SearchPanel`, `SearchMessage`, and
13
- `SearchMessageInput` components for iteration. The copied `Button`, `Icon`,
14
- `TextInput`, and `SelectInput` atoms are available in Storybook for development
15
- and validation only.
11
+ One component, `SearchPanel`: a search box, product and "did you mean" suggestions,
12
+ recent searches, and an `agentPanel` slot for an embedded agent such as the NUi
13
+ widget from `react-nui-chat-sdk`.
14
+
15
+ Everything else in the repository, including the search box, the layout, the rows,
16
+ and the `Button`, `Icon`, `TextInput`, and `SelectInput` atoms, is internal. Storybook
17
+ shows them for development.
16
18
 
17
19
  ## Requirements
18
20
 
19
- - Node 22
20
- - Yarn Classic
21
+ - Node `>=22 <25` and Yarn Classic, to develop in this repository
21
22
  - React 18.2 or a compatible React 18 release
22
23
  - The standard Nu Skin foundation theme provider and global stylesheet in the
23
24
  consuming application
@@ -37,55 +38,82 @@ foundation UI peer dependencies.
37
38
  import { SearchPanel } from '@nuskin/react-search-components';
38
39
 
39
40
  <SearchPanel
40
- aria-label="Search"
41
- closeLabel="Close"
42
- initialPrompt="How can I prevent wrinkles?"
43
- messageInputProps={{
44
- inputLabel: 'Message',
45
- onSubmit: handleSubmit,
46
- placeholder: 'Ask anything',
47
- submitLabel: 'Send message',
48
- }}
41
+ isOpen={isOpen}
49
42
  onClose={handleClose}
50
- >
51
- Search response placeholder
52
- </SearchPanel>;
43
+ copy={copy}
44
+ input={{ value: query, onChange: setQuery, onSubmit: handleSubmit }}
45
+ suggestions={{
46
+ items,
47
+ loading,
48
+ showNoResults,
49
+ showDidYouMean,
50
+ hasMore,
51
+ query,
52
+ onSelect: handleSelect,
53
+ onRunAction: handleRunAction,
54
+ onSeeMore: handleSeeMore,
55
+ }}
56
+ recentSearches={{ items: recentSearches, onSelect: handleRecent, onClear: handleClear }}
57
+ />;
53
58
  ```
54
59
 
55
- The consuming header controls when and where the panel is rendered.
56
-
57
- ## Commands
58
-
59
- | Command | Purpose |
60
- | ---------------------- | ----------------------------------------------------- |
61
- | `yarn typecheck` | Run strict TypeScript checks |
62
- | `yarn lint` | Run ESLint |
63
- | `yarn format` | Format source and documentation |
64
- | `yarn format:check` | Verify formatting |
65
- | `yarn test` | Run Jest with coverage |
66
- | `yarn storybook` | Start Storybook on port 6006 |
67
- | `yarn build-storybook` | Build Storybook into `dist/storybook/` |
68
- | `yarn build:package` | Type-check and build the package into `package-dist/` |
69
- | `yarn check:package` | Validate ESM, CommonJS, types, and packed contents |
70
- | `yarn validate` | Run the complete local quality workflow |
71
-
72
- ## Outputs
60
+ | Prop | Purpose |
61
+ | ------------------ | ------------------------------------------------------------------------------------ |
62
+ | `isOpen` | Whether the panel is shown |
63
+ | `onClose` | Called on Cancel, on Escape, and on a press outside the panel |
64
+ | `input` | The search box: the host owns `value` and receives `onChange` and `onSubmit` |
65
+ | `suggestions` | The suggestions the host has already fetched and filtered, and the handlers for them |
66
+ | `recentSearches` | Recent searches, shown while the search box is empty |
67
+ | `agentPanel` | An embedded agent. When set, it replaces the search box and suggestions |
68
+ | `copy` | All of the panel's text, already translated. Required |
69
+ | `logo` | The logo shown in the panel header |
70
+ | `fallbackImageUrl` | The image shown for a suggestion that has none |
71
+
72
+ `SearchPanelCopy` lists every string. A few are functions that take a number or a
73
+ product name, so each locale controls its own wording. The exported types describe
74
+ each prop in full.
75
+
76
+ ## Behavior
77
+
78
+ - **A panel, not a modal.** It is full screen on small screens and a band across the
79
+ top from the desktop breakpoint up. The page behind it keeps scrolling, and
80
+ keyboard focus is not trapped.
81
+ - **Closing.** It closes on Escape and on a press outside it, and returns focus to
82
+ where it was when it opened.
83
+ - **Keyboard.** ArrowDown moves from the search box into the suggestions, the arrow
84
+ keys move between rows, and ArrowUp from the first row returns to the search box.
85
+ - **Announcements.** Screen readers are told when suggestions are loading, how many
86
+ there are, and when there are none, using the `copy` the host supplies.
87
+ - **Server rendering.** The panel renders through a portal to `document.body`, so it
88
+ renders nothing on the server and appears after mount.
89
+ - **Styles.** The package owns no global CSS and exports no stylesheet.
90
+
91
+ ## Development
92
+
93
+ | Command | Purpose |
94
+ | ---------------------- | -------------------------------------------------- |
95
+ | `yarn typecheck` | Run strict TypeScript checks |
96
+ | `yarn lint` | Run ESLint |
97
+ | `yarn format` | Format source and documentation |
98
+ | `yarn format:check` | Verify formatting |
99
+ | `yarn test` | Run Jest with coverage |
100
+ | `yarn storybook` | Start Storybook on port 6006 |
101
+ | `yarn build-storybook` | Build Storybook into `dist/storybook/` |
102
+ | `yarn build:package` | Type-check and build the package into `dist/` |
103
+ | `yarn check:package` | Validate ESM, CommonJS, types, and packed contents |
104
+ | `yarn validate` | Run the complete local quality workflow |
73
105
 
74
106
  | Output | Location |
75
107
  | -------------------------------------------- | ----------------- |
76
- | CommonJS, ESM, declarations, and source maps | `package-dist/` |
108
+ | CommonJS, ESM, declarations, and source maps | `dist/` |
77
109
  | Static Storybook | `dist/storybook/` |
78
110
  | Test coverage | `coverage/` |
79
111
 
80
- The package owns no global CSS and exports no stylesheet.
81
-
82
112
  ## Documentation
83
113
 
84
- - [Architecture](docs/architecture.md)
85
- - [Component contracts](docs/component-contracts.md)
86
- - [Contributing](CONTRIBUTING.md)
87
- - [Initialization plan](docs/initialization-plan.md)
88
- - [Architecture decisions](docs/decisions/)
114
+ - [Contributing](CONTRIBUTING.md): how to work in this repository
115
+ - [Constitution](.specify/memory/constitution.md): the rules every change must follow
116
+ - [Architecture decisions](docs/decisions/): why the repository is shaped this way
89
117
 
90
118
  ## License
91
119
 
package/dist/index.d.mts CHANGED
@@ -1,70 +1,13 @@
1
- import * as React from 'react';
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 row. Structurally the shape the search SDK's catalog mapping produces;
67
- * defined here so this library stays presentational and imports nothing from the SDK.
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
- /** A "Did You Mean?" row. Extra fields from the API are preserved via the index signature. */
92
- interface DidYouMeanItem {
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
- [key: string]: unknown;
97
- }
98
- interface SuggestionDisplayData {
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
- /** Copy shown by the modal. Every key falls back to an English default. */
129
- interface SearchModalCopy {
130
- extended_search_textbox_desktop?: string;
131
- extended_search_box_aria_label?: string;
132
- clear_all_label?: string;
133
- no_suggestions_text?: string;
134
- see_more_results_text?: string;
135
- did_you_mean_text?: string;
136
- recent_searches_label?: string;
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 SearchModalInputProps {
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 SearchModalSuggestionsProps {
146
- items: ReadonlyArray<SuggestionOptionWithTracking>;
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: SuggestionOptionWithTracking) => void;
157
- onRunAction: (option: SuggestionOptionWithTracking) => void;
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 SearchModalRecentSearches {
110
+ interface SearchPanelRecentSearches {
162
111
  items: ReadonlyArray<string>;
163
112
  onSelect: (query: string) => void;
164
113
  onClear: () => void;
165
114
  }
166
- interface SearchModalProps {
115
+ interface SearchPanelProps {
167
116
  isOpen: boolean;
168
117
  onClose: () => void;
169
- logo?: React__default.ReactNode;
170
- cancelLabel?: string;
118
+ logo?: React.ReactNode;
171
119
  fallbackImageUrl?: string;
172
- copy?: SearchModalCopy;
173
- input: SearchModalInputProps;
174
- suggestions: SearchModalSuggestionsProps;
175
- recentSearches?: SearchModalRecentSearches;
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?: React__default.ReactNode;
128
+ agentPanel?: React.ReactNode;
181
129
  }
182
130
 
183
131
  /**
184
- * The search panel: a full-width overlay with a search box, suggestions and recent searches, or,
185
- * when `agentPanel` is set, a header over an embedded agent.
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
- * Presentational: it holds only UI state (highlighted row, expanded recent searches). Modal
188
- * behaviour (portal, backdrop, Escape, focus trap, returning focus to the opener, scroll lock,
189
- * hiding the page from assistive technology) comes from MUI's `Modal`. Fetching, routing and
190
- * navigation belong to the host.
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 SearchModal({ isOpen, onClose, logo, cancelLabel, fallbackImageUrl, copy, input, suggestions, recentSearches, agentPanel, }: Readonly<SearchModalProps>): React__default.ReactElement | null;
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, SEARCH_MESSAGE_SENDERS, SearchMessage, SearchMessageInput, type SearchMessageInputProps, type SearchMessageProps, type SearchMessageSender, SearchModal, type SearchModalCopy, type SearchModalInputProps, type SearchModalProps, type SearchModalRecentSearches, type SearchModalSuggestionsProps, SearchPanel, type SearchPanelProps, SeeMoreLink, type SeeMoreLinkProps, type SuggestionDisplayData, type SuggestionOptionWithTracking, SuggestionRow, type SuggestionRowProps, getSuggestionDisplayData };
145
+ export { type CatalogSuggestionItem, type DidYouMeanItem, SearchPanel, type SearchPanelCopy, type SearchPanelInputProps, type SearchPanelProps, type SearchPanelRecentSearches, type SearchPanelSuggestionsProps, type SuggestionOption };