@searchcraft/react-sdk 0.1.2 → 0.1.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 CHANGED
@@ -16,13 +16,13 @@ Install with NPM:
16
16
  $ npm install @searchcraft/react-sdk
17
17
  ```
18
18
 
19
- Wrap your app or target a specific interface and wrap them with the `SearchcraftProvider` to expose the functionalities of the SDK.
19
+ Wrap your app or target a specific interface and wrap them with the `Searchcraft.Provider` to expose the functionalities of the SDK.
20
20
 
21
21
  ```jsx
22
22
 
23
23
  import { useMemo } from 'react'
24
24
 
25
- import { SearchcraftProvider, Searchcraft } from '@searchcraft/react-sdk'
25
+ import Searchcraft, { SearchcraftCore } from '@searchcraft/react-sdk'
26
26
 
27
27
  // values are created via the Searchcraft Vektron Customer Portal
28
28
  const searchcraftConfig = {
@@ -32,24 +32,23 @@ const searchcraftConfig = {
32
32
  }
33
33
 
34
34
  const Main = () => {
35
- // initialize and pass an instance of Searchcraft into the provider
36
- const searchcraft = useMemo(() => new Searchcraft(searchcraftConfig),[]);
35
+ // initialize and pass an instance of SearchcraftCore into the provider
36
+ const searchcraft = useMemo(() => new SearchcraftCore(searchcraftConfig),[]);
37
+ // debug is optional
37
38
  return (
38
- <SearchcraftProvider {...{ searchcraft }}>
39
+ <Searchcraft.Provider {...{ searchcraft, debug: true }}>
39
40
  <YourApplicationOrScreenGoHere />
40
- </SearchcraftProvider>
41
+ </Searchcraft.Provider>
41
42
  )
42
43
  }
43
44
 
44
45
  ```
45
46
  ### Quickstart with useSearchcraft hook
46
47
 
47
- Once your app is wrapped in the `SearchcraftProvider`, the `useSearchcraft` hook functionalities are available for use.
48
+ Once your app is wrapped in the `Searchcraft.Provider`, the `useSearchcraft` hook functionalities are available for use.
48
49
 
49
50
  ```jsx
50
- import {
51
- useSearchcraft
52
- } from '@searchcraft/react-sdk';
51
+ import Searchcraft, { useSearchcraft, AutoSearchForm } from '@searchcraft/react-sdk'
53
52
 
54
53
  // import the styles from the SDK
55
54
  import '../node_modules/@searchcraft/react-sdk/dist/style.css'
@@ -69,7 +68,7 @@ const handleClearInput = () => {
69
68
  onClearedInput={handleClearInput}
70
69
  rightToLeftOrientation
71
70
  />
72
- <BaseSearchResults />
71
+ <Searchcraft.BaseSearchResults />
73
72
  </>
74
73
  )
75
74
  };
@@ -77,20 +76,22 @@ const handleClearInput = () => {
77
76
 
78
77
  ## UI Components
79
78
 
80
- The SDK provides 4 pre-built UI components with data provided to them via the `SearchcraftProvider` and `useSearchcraft` hook.
79
+ The SDK provides 4 pre-built UI components with data provided to them via the `Searchcraft.Provider` and `useSearchcraft` hook.
81
80
 
82
81
  ```jsx
83
82
  import {
84
83
  // Search input without submit button
85
84
  AutoSearchForm,
86
85
  // Search input with submit button
87
- BasicSearchForm,
86
+ BaseSearchForm,
88
87
  // Single Search Result component that can be customized while iterating over SearchResults
89
- BasicSearchResult,
88
+ BaseSearchResult,
90
89
  // Fully encapsulated list of search results with no iteration required
91
- BasicSearchResults,
90
+ BaseSearchResults,
92
91
  useSearchcraft
93
92
  } from '@searchcraft/react-sdk';
93
+ OR
94
+ import Searchcraft, { useSearchcraft } from '@searchcraft/react-sdk'
94
95
 
95
96
  const AutoSearchImplementation = () => {
96
97
  const { query, search, searchResults } = useSearchcraft()
@@ -101,7 +102,7 @@ const AutoSearchImplementation = () => {
101
102
 
102
103
  return (
103
104
  <>
104
- <AutoSearchForm
105
+ <Searchcraft.AutoSearchForm
105
106
  handleSubmit={handleSubmitForm}
106
107
  inputCaptionValue="Search here"
107
108
  onClearedInput={handleClearInput}
@@ -111,14 +112,14 @@ const AutoSearchImplementation = () => {
111
112
  )
112
113
  };
113
114
 
114
- const BasicSearchAndResultsImplementation = () => {
115
+ const BaseSearchAndResultsImplementation = () => {
115
116
  const { query, search, searchResults } = useSearchcraft();
116
117
 
117
118
  const handleSubmitForm = async () => await search(query, 'fuzzy');
118
119
 
119
120
  return (
120
121
  <>
121
- <BaseSearchForm
122
+ <Searchcraft.BaseSearchForm
122
123
  rightToLeftOrientation={false}
123
124
  handleSubmit={handleSubmitForm}
124
125
  />
@@ -132,7 +133,7 @@ const BasicSearchAndResultsImplementation = () => {
132
133
  console.log('button callback');
133
134
  };
134
135
  return (
135
- <BaseSearchResult
136
+ <Searchcraft.BaseSearchResult
136
137
  key={`${result?.id}-${index}`}
137
138
  buttonLabel='View More'
138
139
  buttonCallbackFn={buttonCallback}
@@ -152,3 +153,42 @@ const BasicSearchAndResultsImplementation = () => {
152
153
  );
153
154
  }
154
155
  ```
156
+
157
+ Additionally, you can import individual sub-components that comprise the pre-built UI components.
158
+
159
+ ```jsx
160
+ import { Input, useSearchcraft } from '@searchcraft/react-sdk';
161
+
162
+ const InputComponent = () => {
163
+ const { query, setQuery } = useSearchcraft();
164
+ const [error, setError] = useState<boolean>(false);
165
+
166
+ const handleFormSubmit = (e: { preventDefault: () => void }) => {
167
+ e.preventDefault();
168
+ if (query.trim() === '') {
169
+ setError(true);
170
+ } else {
171
+ setError(false);
172
+ handleSubmit(query);
173
+ }
174
+ };
175
+
176
+ const handleSearchInputChange = (event: { target: { value: string } }) =>
177
+ setQuery(event.target.value);
178
+
179
+ const handleClearInput = () => setQuery('');
180
+
181
+ return (
182
+ <>
183
+ <Input
184
+ error={error}
185
+ onClearInput={handleClearInput}
186
+ onSearchInputChange={handleSearchInputChange}
187
+ placeholderValue={placeholderValue}
188
+ query={query}
189
+ rightToLeftOrientation={rightToLeftOrientation}
190
+ />
191
+ </>
192
+ )
193
+ };
194
+ ```
package/dist/index.d.ts CHANGED
@@ -1,11 +1,8 @@
1
1
  import { ChangeEventHandler } from 'react';
2
2
  import { Dispatch } from 'react';
3
3
  import { FC } from 'react';
4
- import { JSX as JSX_2 } from 'react/jsx-runtime';
5
- import { PropsWithChildren } from 'react';
6
4
  import { ReactNode } from 'react';
7
- import { CoreSDK as Searchcraft } from '@searchcraft/core';
8
- import { SearchcraftInstance } from '@searchcraft/core';
5
+ import { CoreSDK as SearchcraftCore } from '@searchcraft/core';
9
6
  import { SearchError } from '@searchcraft/core';
10
7
  import { SearchResult } from '@searchcraft/core';
11
8
  import { SetStateAction } from 'react';
@@ -20,7 +17,7 @@ declare interface AutoSearchFormProps {
20
17
  handleSubmit: (query: string) => void;
21
18
  inputCaptionValue?: string;
22
19
  labelForInput?: string;
23
- onClearedInput?: () => void;
20
+ onClearInput?: () => void;
24
21
  placeholderValue?: string;
25
22
  rightToLeftOrientation?: boolean;
26
23
  searchContainerClass?: string;
@@ -35,6 +32,7 @@ declare interface BaseSearchFormProps {
35
32
  errorMessage?: string;
36
33
  handleSubmit: (query: string) => void;
37
34
  labelForInput?: string;
35
+ onClearInput?: () => void;
38
36
  placeholderValue?: string;
39
37
  rightToLeftOrientation?: boolean;
40
38
  }
@@ -76,6 +74,13 @@ declare type ErrorMessageProps = {
76
74
 
77
75
  export declare const Input: FC<InputProps>;
78
76
 
77
+ declare type InputCaptionProps = {
78
+ error?: boolean;
79
+ inputCaptionClassName?: string;
80
+ inputCaptionValue: string;
81
+ rightToLeftOrientation?: boolean;
82
+ };
83
+
79
84
  export declare const InputLabel: FC<InputLabelProps>;
80
85
 
81
86
  declare type InputLabelProps = {
@@ -96,9 +101,26 @@ declare type InputProps = {
96
101
  query: string;
97
102
  };
98
103
 
99
- export { Searchcraft }
104
+ declare const Searchcraft: FC & {
105
+ AutoSearchForm: FC<AutoSearchFormProps>;
106
+ BaseSearchForm: FC<BaseSearchFormProps>;
107
+ BaseSearchResult: FC<BaseSearchResultProps>;
108
+ BaseSearchResults: FC;
109
+ Button: FC;
110
+ ClearInputButton: FC;
111
+ ErrorMessage: FC;
112
+ Input: FC<InputProps>;
113
+ InputCaption: FC<InputCaptionProps>;
114
+ InputIcon: FC;
115
+ InputLabel: FC<InputLabelProps>;
116
+ Provider: FC<{
117
+ searchcraft: SearchcraftCore;
118
+ debug?: boolean;
119
+ }>;
120
+ };
121
+ export default Searchcraft;
100
122
 
101
- export declare const SearchcraftProvider: ({ children, searchcraft, }: PropsWithChildren & SearchcraftInstance) => JSX_2.Element;
123
+ export { SearchcraftCore }
102
124
 
103
125
  export declare interface SearchcraftProviderConfig {
104
126
  index: string[];