@searchcraft/react-sdk 0.1.3 → 0.5.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 +55 -41
- package/dist/index.d.ts +46 -156
- package/dist/index.js +2620 -650
- package/dist/index.js.map +1 -1
- package/package.json +7 -8
- package/dist/style.css +0 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Searchcraft
|
|
1
|
+
# Searchcraft React SDK
|
|
2
2
|
|
|
3
3
|
This kit provides basic tools for building out a simple search interface using the Searchcraft API. Searching, tracking the request state, and displaying results are all available in this kit.
|
|
4
4
|
|
|
@@ -34,7 +34,7 @@ const searchcraftConfig = {
|
|
|
34
34
|
const Main = () => {
|
|
35
35
|
// initialize and pass an instance of SearchcraftCore into the provider
|
|
36
36
|
const searchcraft = useMemo(() => new SearchcraftCore(searchcraftConfig),[]);
|
|
37
|
-
// debug is optional
|
|
37
|
+
// debug is optional and has a default value of false
|
|
38
38
|
return (
|
|
39
39
|
<Searchcraft.Provider {...{ searchcraft, debug: true }}>
|
|
40
40
|
<YourApplicationOrScreenGoHere />
|
|
@@ -48,13 +48,27 @@ const Main = () => {
|
|
|
48
48
|
Once your app is wrapped in the `Searchcraft.Provider`, the `useSearchcraft` hook functionalities are available for use.
|
|
49
49
|
|
|
50
50
|
```jsx
|
|
51
|
-
import Searchcraft, { useSearchcraft, AutoSearchForm } from '@searchcraft/react-sdk'
|
|
51
|
+
import Searchcraft, { useSearchcraft, AutoSearchForm, useTheme } from '@searchcraft/react-sdk'
|
|
52
|
+
|
|
53
|
+
// values available when using the useSearchcraft hook
|
|
54
|
+
const useSearchContextValues = {
|
|
55
|
+
error,
|
|
56
|
+
index,
|
|
57
|
+
isRequesting,
|
|
58
|
+
mode,
|
|
59
|
+
query,
|
|
60
|
+
search,
|
|
61
|
+
searchResults,
|
|
62
|
+
setQuery,
|
|
63
|
+
};
|
|
52
64
|
|
|
53
65
|
// import the styles from the SDK
|
|
54
66
|
import '../node_modules/@searchcraft/react-sdk/dist/style.css'
|
|
55
67
|
|
|
56
68
|
const SearchWithResultsComponent = () => {
|
|
57
|
-
const { isRequesting, query, search, searchResults } = useSearchcraft()
|
|
69
|
+
const { isRequesting, query, search, searchResults } = useSearchcraft();
|
|
70
|
+
// useTheme hook is exposed to control the dark and light UIs available. Configured values are 'light' and 'dark'.
|
|
71
|
+
const { toggleTheme, theme } = useTheme();
|
|
58
72
|
|
|
59
73
|
const handleClearInput = () => {
|
|
60
74
|
setQuery('')
|
|
@@ -62,10 +76,11 @@ const handleClearInput = () => {
|
|
|
62
76
|
|
|
63
77
|
return (
|
|
64
78
|
<>
|
|
79
|
+
<button onClick={toggleTheme}>Toggle Theme</button>
|
|
65
80
|
<AutoSearchForm
|
|
66
81
|
handleSubmit={handleSubmitForm}
|
|
67
82
|
inputCaptionValue="Search here"
|
|
68
|
-
|
|
83
|
+
onClearInput={handleClearInput}
|
|
69
84
|
rightToLeftOrientation
|
|
70
85
|
/>
|
|
71
86
|
<Searchcraft.BaseSearchResults />
|
|
@@ -90,7 +105,9 @@ import {
|
|
|
90
105
|
BaseSearchResults,
|
|
91
106
|
useSearchcraft
|
|
92
107
|
} from '@searchcraft/react-sdk';
|
|
93
|
-
|
|
108
|
+
|
|
109
|
+
// OR
|
|
110
|
+
|
|
94
111
|
import Searchcraft, { useSearchcraft } from '@searchcraft/react-sdk'
|
|
95
112
|
|
|
96
113
|
const AutoSearchImplementation = () => {
|
|
@@ -102,56 +119,53 @@ const AutoSearchImplementation = () => {
|
|
|
102
119
|
|
|
103
120
|
return (
|
|
104
121
|
<>
|
|
122
|
+
// example using compound component pattern
|
|
105
123
|
<Searchcraft.AutoSearchForm
|
|
106
124
|
handleSubmit={handleSubmitForm}
|
|
107
125
|
inputCaptionValue="Search here"
|
|
108
|
-
|
|
126
|
+
onClearInput={handleClearInput}
|
|
109
127
|
rightToLeftOrientation={true}
|
|
110
128
|
/>
|
|
111
129
|
</>
|
|
112
130
|
)
|
|
113
131
|
};
|
|
114
132
|
|
|
115
|
-
const
|
|
116
|
-
const {
|
|
117
|
-
|
|
118
|
-
const handleSubmitForm = async () => await search(query, 'fuzzy');
|
|
133
|
+
const BaseSearchResults: FC = () => {
|
|
134
|
+
const { searchResults, query } = useSearchcraft();
|
|
119
135
|
|
|
120
136
|
return (
|
|
121
137
|
<>
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
) : (
|
|
150
|
-
<div>no search results found</div>
|
|
138
|
+
{searchResults?.data?.hits?.map((document, index) => {
|
|
139
|
+
const { doc: result } = document;
|
|
140
|
+
const callback = () => {
|
|
141
|
+
console.log('interactive element');
|
|
142
|
+
};
|
|
143
|
+
const buttonCallback = () => {
|
|
144
|
+
console.log('button callback');
|
|
145
|
+
};
|
|
146
|
+
return (
|
|
147
|
+
// example using named import component
|
|
148
|
+
<BaseSearchResult
|
|
149
|
+
key={`${result?.id}-${index}`}
|
|
150
|
+
buttonLabel='View More'
|
|
151
|
+
buttonCallbackFn={buttonCallback}
|
|
152
|
+
callbackFn={callback}
|
|
153
|
+
interactiveResult
|
|
154
|
+
imageSrc={result?.poster}
|
|
155
|
+
resultBodyContent={result?.overview}
|
|
156
|
+
resultHeading={result?.title}
|
|
157
|
+
resultSubheading={result?.release_date}
|
|
158
|
+
/>
|
|
159
|
+
);
|
|
160
|
+
})}
|
|
161
|
+
{query.length > 0 && searchResults?.data?.hits?.length === 0 && (
|
|
162
|
+
<ErrorMessage
|
|
163
|
+
errorMessage={`No search results found for ${query} query`}
|
|
164
|
+
/>
|
|
151
165
|
)}
|
|
152
166
|
</>
|
|
153
167
|
);
|
|
154
|
-
}
|
|
168
|
+
};
|
|
155
169
|
```
|
|
156
170
|
|
|
157
171
|
Additionally, you can import individual sub-components that comprise the pre-built UI components.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,169 +1,59 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Dispatch } from 'react';
|
|
1
|
+
import { Components } from '@searchcraft/javascript-sdk';
|
|
3
2
|
import { FC } from 'react';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
declare
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
inputCaptionValue?: string;
|
|
19
|
-
labelForInput?: string;
|
|
20
|
-
onClearInput?: () => void;
|
|
21
|
-
placeholderValue?: string;
|
|
22
|
-
rightToLeftOrientation?: boolean;
|
|
23
|
-
searchContainerClass?: string;
|
|
3
|
+
|
|
4
|
+
export declare const SearchcraftBaseSearchResult: FC<SearchcraftBaseSearchResultProps>;
|
|
5
|
+
|
|
6
|
+
export declare interface SearchcraftBaseSearchResultProps extends Components.SearchcraftBaseSearchResult {
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export declare const SearchcraftBaseSearchResults: FC<SearchcraftBaseSearchResultsProps>;
|
|
10
|
+
|
|
11
|
+
export declare interface SearchcraftBaseSearchResultsProps extends Components.SearchcraftBaseSearchResults {
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export declare const SearchcraftButton: FC<SearchcraftButtonProps>;
|
|
15
|
+
|
|
16
|
+
export declare interface SearchcraftButtonProps extends Components.SearchcraftButton {
|
|
24
17
|
}
|
|
25
18
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
export declare const BaseSearchForm: FC<BaseSearchFormProps>;
|
|
30
|
-
|
|
31
|
-
declare interface BaseSearchFormProps {
|
|
32
|
-
errorMessage?: string;
|
|
33
|
-
handleSubmit: (query: string) => void;
|
|
34
|
-
labelForInput?: string;
|
|
35
|
-
onClearInput?: () => void;
|
|
36
|
-
placeholderValue?: string;
|
|
37
|
-
rightToLeftOrientation?: boolean;
|
|
19
|
+
export declare const SearchcraftErrorMessage: FC<SearchcraftErrorMessageProps>;
|
|
20
|
+
|
|
21
|
+
export declare interface SearchcraftErrorMessageProps extends Components.SearchcraftErrorMessage {
|
|
38
22
|
}
|
|
39
23
|
|
|
40
|
-
export declare const
|
|
41
|
-
|
|
42
|
-
declare interface
|
|
43
|
-
buttonCallbackFn?: () => void;
|
|
44
|
-
buttonLabel?: string;
|
|
45
|
-
imageAltText?: string;
|
|
46
|
-
imageSrc?: string;
|
|
47
|
-
interactiveResult?: boolean;
|
|
48
|
-
callbackFn?: () => void;
|
|
49
|
-
keyDownCallbackFn?: () => void;
|
|
50
|
-
resultBodyContent?: string;
|
|
51
|
-
resultHeading?: string;
|
|
52
|
-
resultSubheading?: string;
|
|
24
|
+
export declare const SearchcraftFacetList: FC<SearchcraftFacetListProps>;
|
|
25
|
+
|
|
26
|
+
export declare interface SearchcraftFacetListProps extends Components.SearchcraftFacetList {
|
|
53
27
|
}
|
|
54
28
|
|
|
55
|
-
export declare const
|
|
56
|
-
|
|
57
|
-
export declare
|
|
58
|
-
|
|
59
|
-
declare type ButtonProps = {
|
|
60
|
-
className?: string;
|
|
61
|
-
iconElement?: ReactNode;
|
|
62
|
-
iconOnly?: boolean;
|
|
63
|
-
iconPosition?: string;
|
|
64
|
-
label?: string;
|
|
65
|
-
onClick?: () => void;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export declare const ErrorMessage: FC<ErrorMessageProps>;
|
|
69
|
-
|
|
70
|
-
declare type ErrorMessageProps = {
|
|
71
|
-
className?: string;
|
|
72
|
-
errorMessage?: string;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export declare const Input: FC<InputProps>;
|
|
76
|
-
|
|
77
|
-
declare type InputCaptionProps = {
|
|
78
|
-
error?: boolean;
|
|
79
|
-
inputCaptionClassName?: string;
|
|
80
|
-
inputCaptionValue: string;
|
|
81
|
-
rightToLeftOrientation?: boolean;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export declare const InputLabel: FC<InputLabelProps>;
|
|
85
|
-
|
|
86
|
-
declare type InputLabelProps = {
|
|
87
|
-
className?: string;
|
|
88
|
-
label: string;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
declare type InputProps = {
|
|
92
|
-
error?: boolean;
|
|
93
|
-
formClassName?: string;
|
|
94
|
-
inputCaptionClassName?: string;
|
|
95
|
-
inputCaptionValue?: string;
|
|
96
|
-
inputClassName?: string;
|
|
97
|
-
onClearInput?: () => void;
|
|
98
|
-
onSearchInputChange: ChangeEventHandler<HTMLInputElement>;
|
|
99
|
-
placeholderValue?: string;
|
|
100
|
-
rightToLeftOrientation?: boolean;
|
|
101
|
-
query: string;
|
|
102
|
-
};
|
|
103
|
-
|
|
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;
|
|
122
|
-
|
|
123
|
-
export { SearchcraftCore }
|
|
124
|
-
|
|
125
|
-
export declare interface SearchcraftProviderConfig {
|
|
126
|
-
index: string[];
|
|
127
|
-
apiKey: string;
|
|
128
|
-
endpointURL: string;
|
|
29
|
+
export declare const SearchcraftFilterPanel: FC<SearchcraftFilterPanelProps>;
|
|
30
|
+
|
|
31
|
+
export declare interface SearchcraftFilterPanelProps extends Components.SearchcraftFilterPanel {
|
|
129
32
|
}
|
|
130
33
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
* Error occurred while making a search query.
|
|
135
|
-
*/
|
|
136
|
-
error: Error | null;
|
|
137
|
-
/**
|
|
138
|
-
* The db name(s) created in Vektron to query.
|
|
139
|
-
*/
|
|
140
|
-
index: string[];
|
|
141
|
-
/**
|
|
142
|
-
* Value exposed when a search is in progress.
|
|
143
|
-
*/
|
|
144
|
-
isRequesting: boolean;
|
|
145
|
-
/**
|
|
146
|
-
* Can be either fuzzy or normal. The default is fuzzy.
|
|
147
|
-
*/
|
|
148
|
-
mode: 'fuzzy' | 'normal';
|
|
149
|
-
/**
|
|
150
|
-
* Input value given by the user to query the DB by.
|
|
151
|
-
*/
|
|
152
|
-
query: string;
|
|
153
|
-
/**
|
|
154
|
-
* Setter function to update the value being sent to the SDK.
|
|
155
|
-
*/
|
|
156
|
-
setQuery: Dispatch<SetStateAction<string>>;
|
|
157
|
-
/**
|
|
158
|
-
* Function for searching that requires search mode and search type.
|
|
159
|
-
*/
|
|
160
|
-
search: (query: string, mode: 'fuzzy' | 'normal') => void;
|
|
161
|
-
/**
|
|
162
|
-
* Object that is returned from the Searchcraft API when a search request has resolved
|
|
163
|
-
*/
|
|
164
|
-
searchResults?: SearchResult | SearchError | null;
|
|
34
|
+
export declare const SearchcraftInputForm: FC<SearchcraftInputFormProps>;
|
|
35
|
+
|
|
36
|
+
export declare interface SearchcraftInputFormProps extends Components.SearchcraftInputForm {
|
|
165
37
|
}
|
|
166
38
|
|
|
167
|
-
export declare const
|
|
39
|
+
export declare const SearchcraftInputLabel: FC<SearchcraftInputLabelProps>;
|
|
40
|
+
|
|
41
|
+
export declare interface SearchcraftInputLabelProps extends Components.SearchcraftInputLabel {
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export declare const SearchcraftResultsInfo: FC<SearchcraftResultsInfoProps>;
|
|
45
|
+
|
|
46
|
+
export declare interface SearchcraftResultsInfoProps extends Components.SearchcraftResultsInfo {
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export declare const SearchcraftSlider: FC<SearchcraftSliderProps>;
|
|
50
|
+
|
|
51
|
+
export declare interface SearchcraftSliderProps extends Components.SearchcraftSlider {
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export declare const SearchcraftToggleButton: FC<SearchcraftToggleButtonProps>;
|
|
55
|
+
|
|
56
|
+
export declare interface SearchcraftToggleButtonProps extends Components.SearchcraftToggleButton {
|
|
57
|
+
}
|
|
168
58
|
|
|
169
59
|
export { }
|