@uncinc/uncinc-react-kitchen-sink 2.2.10 → 2.2.13
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/components/Button/stories.scss +45 -0
- package/dist/components/Cookie/Checkbox/style.scss +2 -2
- package/dist/components/Cookie/stories.scss +2 -3
- package/dist/components/Cookie/style.scss +2 -2
- package/dist/components/Form/Checkboxes/index.js +35 -15
- package/dist/components/Form/Checkboxes/stories.js +9 -3
- package/dist/components/Form/RadioButtons/index.js +9 -7
- package/dist/components/Form/RadioButtons/stories.js +14 -3
- package/dist/components/Form/Select/Input/index.js +3 -2
- package/dist/components/SearchKit/Facets/ChipFacet/index.js +5 -1
- package/dist/components/SearchKit/Facets/ListFacet/index.js +5 -1
- package/dist/components/SearchKit/Facets/SelectFacet/index.js +42 -9
- package/dist/components/SearchKit/SearchResults/index.js +43 -10
- package/dist/components/SearchKit/SearchSorting/index.js +33 -13
- package/dist/components/SearchKit/index.js +9 -13
- package/dist/components/SearchKit/stories.js +1 -1
- package/dist/components/Share/stories.scss +2 -2
- package/dist/components/WysiwygField/stories.scss +3 -0
- package/dist/helpers/makeSafeForCSS.js +5 -0
- package/dist/index.js +3 -0
- package/package.json +1 -1
- package/dist/pages/api/graphql.js +0 -25
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
@import '../../styles/assets/variables';
|
|
2
|
+
|
|
3
|
+
.Button {
|
|
4
|
+
&.Button--styled {
|
|
5
|
+
display: inline-block;
|
|
6
|
+
border-radius: 5px;
|
|
7
|
+
text-decoration: none;
|
|
8
|
+
text-align: center;
|
|
9
|
+
cursor: pointer;
|
|
10
|
+
|
|
11
|
+
&--primary {
|
|
12
|
+
font-size: 21px;
|
|
13
|
+
background-color: black;
|
|
14
|
+
color: #ffffff;
|
|
15
|
+
font-weight: 600;
|
|
16
|
+
line-height: 1.14;
|
|
17
|
+
padding: 19px 30px;
|
|
18
|
+
|
|
19
|
+
&:hover {
|
|
20
|
+
background-color: #434343;
|
|
21
|
+
}
|
|
22
|
+
&:disabled {
|
|
23
|
+
font-family: inherit;
|
|
24
|
+
background-color: rgba(0, 0, 0, 0.3);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
&--inverted {
|
|
29
|
+
border: solid 1px #888888;
|
|
30
|
+
background-color: #ffffff;
|
|
31
|
+
padding: 18px 34.5px;
|
|
32
|
+
font-size: 18px;
|
|
33
|
+
font-weight: 600;
|
|
34
|
+
color: #000000;
|
|
35
|
+
|
|
36
|
+
&:hover {
|
|
37
|
+
background-color: #f1f1f1;
|
|
38
|
+
}
|
|
39
|
+
&:disabled {
|
|
40
|
+
font-family: inherit;
|
|
41
|
+
opacity: .5;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -30,6 +30,31 @@ function Checkbox(props) {
|
|
|
30
30
|
'icon-checkmark': true,
|
|
31
31
|
'icon-variant-1': checked
|
|
32
32
|
});
|
|
33
|
+
|
|
34
|
+
if (props.value === '__other__') {
|
|
35
|
+
const inputClasses = c({
|
|
36
|
+
hidden: !field.value.includes('__other__')
|
|
37
|
+
});
|
|
38
|
+
return /*#__PURE__*/React.createElement("label", {
|
|
39
|
+
className: classes,
|
|
40
|
+
htmlFor: name
|
|
41
|
+
}, /*#__PURE__*/React.createElement("input", _extends({}, field, {
|
|
42
|
+
name: props.name,
|
|
43
|
+
value: value,
|
|
44
|
+
type: "checkbox",
|
|
45
|
+
id: name,
|
|
46
|
+
checked: checked,
|
|
47
|
+
disabled: disabled,
|
|
48
|
+
className: className
|
|
49
|
+
})), /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement("span", null, props.otherLabel ? props.otherLabel : props.label), props.description && /*#__PURE__*/React.createElement("span", null, props.description)), /*#__PURE__*/React.createElement("textarea", {
|
|
50
|
+
placeholder: props.otherPlaceholder,
|
|
51
|
+
className: inputClasses,
|
|
52
|
+
onChange: e => {
|
|
53
|
+
form.setFieldValue(`${props.name}--other`, e.target.value);
|
|
54
|
+
}
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
|
|
33
58
|
return /*#__PURE__*/React.createElement("label", {
|
|
34
59
|
className: classes,
|
|
35
60
|
htmlFor: name
|
|
@@ -39,21 +64,9 @@ function Checkbox(props) {
|
|
|
39
64
|
type: "checkbox",
|
|
40
65
|
id: name,
|
|
41
66
|
checked: checked,
|
|
42
|
-
onChange: e => {
|
|
43
|
-
const set = new Set(field.value);
|
|
44
|
-
|
|
45
|
-
if (set.has(value)) {
|
|
46
|
-
set.delete(value);
|
|
47
|
-
} else {
|
|
48
|
-
set.add(value);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
form.setFieldValue(field.name, Array.from(set));
|
|
52
|
-
form.setFieldTouched(field.name, true);
|
|
53
|
-
},
|
|
54
67
|
disabled: disabled,
|
|
55
68
|
className: className
|
|
56
|
-
})), props.label);
|
|
69
|
+
})), /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement("span", null, props.label), props.description && /*#__PURE__*/React.createElement("span", null, props.description)));
|
|
57
70
|
});
|
|
58
71
|
}
|
|
59
72
|
|
|
@@ -69,10 +82,13 @@ const Checkboxes = props => {
|
|
|
69
82
|
error,
|
|
70
83
|
type,
|
|
71
84
|
options,
|
|
85
|
+
descriptions = {},
|
|
72
86
|
displayRequiredIndicator,
|
|
73
87
|
className,
|
|
74
88
|
wrapperClassName,
|
|
75
|
-
disabled = false
|
|
89
|
+
disabled = false,
|
|
90
|
+
otherLabel,
|
|
91
|
+
otherPlaceholder
|
|
76
92
|
} = props;
|
|
77
93
|
return /*#__PURE__*/React.createElement(GenericFormElement, {
|
|
78
94
|
className: c("Checkboxes", wrapperClassName),
|
|
@@ -85,9 +101,11 @@ const Checkboxes = props => {
|
|
|
85
101
|
displayRequiredIndicator: displayRequiredIndicator
|
|
86
102
|
}, Object.keys(options).map(value => {
|
|
87
103
|
const label = options[value];
|
|
104
|
+
const description = descriptions[value] || null;
|
|
88
105
|
return /*#__PURE__*/React.createElement(Checkbox, {
|
|
89
106
|
key: value,
|
|
90
107
|
label: label,
|
|
108
|
+
description: description,
|
|
91
109
|
className: c(className, {
|
|
92
110
|
'error': error && touched
|
|
93
111
|
}),
|
|
@@ -96,7 +114,9 @@ const Checkboxes = props => {
|
|
|
96
114
|
value: value,
|
|
97
115
|
placeholder: placeholder,
|
|
98
116
|
validate: validation,
|
|
99
|
-
disabled: disabled
|
|
117
|
+
disabled: disabled,
|
|
118
|
+
otherLabel: otherLabel,
|
|
119
|
+
otherPlaceholder: otherPlaceholder
|
|
100
120
|
});
|
|
101
121
|
}));
|
|
102
122
|
};
|
|
@@ -10,7 +10,8 @@ export const Checkboxes = props => {
|
|
|
10
10
|
return /*#__PURE__*/React.createElement(FormikWrapper, _extends({}, props, {
|
|
11
11
|
initialValues: {
|
|
12
12
|
'poison': []
|
|
13
|
-
}
|
|
13
|
+
},
|
|
14
|
+
onSubmit: values => console.log(values)
|
|
14
15
|
}), /*#__PURE__*/React.createElement(FormikCheckboxes, {
|
|
15
16
|
title: "Pick your poison",
|
|
16
17
|
required: true,
|
|
@@ -20,7 +21,8 @@ export const Checkboxes = props => {
|
|
|
20
21
|
beer: 'Beer',
|
|
21
22
|
wine: 'Wine',
|
|
22
23
|
rum: 'Rum',
|
|
23
|
-
whisky: 'Whisk(e)y'
|
|
24
|
+
whisky: 'Whisk(e)y',
|
|
25
|
+
'__other__': 'Anders'
|
|
24
26
|
},
|
|
25
27
|
validation: value => {
|
|
26
28
|
let error;
|
|
@@ -30,6 +32,10 @@ export const Checkboxes = props => {
|
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
return error;
|
|
33
|
-
}
|
|
35
|
+
},
|
|
36
|
+
otherLabel: "Anders"
|
|
37
|
+
}), /*#__PURE__*/React.createElement("input", {
|
|
38
|
+
type: "submit",
|
|
39
|
+
value: "Verzenden"
|
|
34
40
|
}));
|
|
35
41
|
};
|
|
@@ -22,22 +22,21 @@ const Radio = props => {
|
|
|
22
22
|
const classes = c('WebformRadios__radio__input', {
|
|
23
23
|
'icon-before': true,
|
|
24
24
|
'icon-radio': true,
|
|
25
|
-
'icon-variant-1': field.value && field.value
|
|
25
|
+
'icon-variant-1': field.value && field.value === props.value
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
if (props.value === '__other__') {
|
|
29
29
|
const inputClasses = c({
|
|
30
30
|
hidden: field.value !== '__other__'
|
|
31
31
|
});
|
|
32
|
-
return /*#__PURE__*/React.createElement("
|
|
32
|
+
return /*#__PURE__*/React.createElement("label", {
|
|
33
|
+
htmlFor: name,
|
|
33
34
|
className: classes
|
|
34
|
-
}, /*#__PURE__*/React.createElement("label", {
|
|
35
|
-
htmlFor: name
|
|
36
35
|
}, /*#__PURE__*/React.createElement("input", _extends({}, field, {
|
|
37
36
|
type: "radio",
|
|
38
37
|
id: name,
|
|
39
38
|
value: props.value
|
|
40
|
-
})), props.otherLabel), /*#__PURE__*/React.createElement("textarea", {
|
|
39
|
+
})), /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement("span", null, props.otherLabel ? props.otherLabel : props.label), props.description && /*#__PURE__*/React.createElement("span", null, props.description)), /*#__PURE__*/React.createElement("textarea", {
|
|
41
40
|
placeholder: props.otherPlaceholder,
|
|
42
41
|
className: inputClasses,
|
|
43
42
|
onChange: e => {
|
|
@@ -55,7 +54,7 @@ const Radio = props => {
|
|
|
55
54
|
id: name,
|
|
56
55
|
value: props.value,
|
|
57
56
|
disabled: disabled
|
|
58
|
-
})), props.label);
|
|
57
|
+
})), /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement("span", null, props.label), props.description && /*#__PURE__*/React.createElement("span", null, props.description)));
|
|
59
58
|
});
|
|
60
59
|
};
|
|
61
60
|
|
|
@@ -71,6 +70,7 @@ const RadioButtons = props => {
|
|
|
71
70
|
error,
|
|
72
71
|
type,
|
|
73
72
|
options,
|
|
73
|
+
descriptions = {},
|
|
74
74
|
otherLabel,
|
|
75
75
|
otherPlaceholder,
|
|
76
76
|
displayRequiredIndicator
|
|
@@ -84,11 +84,13 @@ const RadioButtons = props => {
|
|
|
84
84
|
touched: touched,
|
|
85
85
|
error: error,
|
|
86
86
|
displayRequiredIndicator: displayRequiredIndicator
|
|
87
|
-
}, Object.keys(options).map(value => {
|
|
87
|
+
}, Object.keys(options).map((value, index) => {
|
|
88
88
|
const label = options[value];
|
|
89
|
+
const description = descriptions[value] || null;
|
|
89
90
|
return /*#__PURE__*/React.createElement(Radio, {
|
|
90
91
|
key: value,
|
|
91
92
|
label: label,
|
|
93
|
+
description: description,
|
|
92
94
|
className: error && touched ? 'error' : null,
|
|
93
95
|
name: fieldName,
|
|
94
96
|
type: type || 'text',
|
|
@@ -10,7 +10,8 @@ export const RadioButtons = props => {
|
|
|
10
10
|
return /*#__PURE__*/React.createElement(FormikWrapper, _extends({}, props, {
|
|
11
11
|
initialValues: {
|
|
12
12
|
'poison': null
|
|
13
|
-
}
|
|
13
|
+
},
|
|
14
|
+
onSubmit: values => console.log(values)
|
|
14
15
|
}), /*#__PURE__*/React.createElement(FormikRadio, {
|
|
15
16
|
title: "Pick your poison",
|
|
16
17
|
required: true,
|
|
@@ -20,7 +21,13 @@ export const RadioButtons = props => {
|
|
|
20
21
|
beer: 'Beer',
|
|
21
22
|
wine: 'Wine',
|
|
22
23
|
rum: 'Rum',
|
|
23
|
-
whisky: 'Whisk(e)y'
|
|
24
|
+
whisky: 'Whisk(e)y',
|
|
25
|
+
'__other__': 'Anders'
|
|
26
|
+
},
|
|
27
|
+
descriptions: {
|
|
28
|
+
beer: 'Bier is lekker',
|
|
29
|
+
wine: 'Wijn ook wel',
|
|
30
|
+
whisky: 'Maar whiskey is het lekkerst'
|
|
24
31
|
},
|
|
25
32
|
validation: value => {
|
|
26
33
|
let error;
|
|
@@ -30,6 +37,10 @@ export const RadioButtons = props => {
|
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
return error;
|
|
33
|
-
}
|
|
40
|
+
},
|
|
41
|
+
otherLabel: "Anders"
|
|
42
|
+
}), /*#__PURE__*/React.createElement("input", {
|
|
43
|
+
type: "submit",
|
|
44
|
+
value: "Verzenden"
|
|
34
45
|
}));
|
|
35
46
|
};
|
|
@@ -16,7 +16,8 @@ const SelectInput = props => {
|
|
|
16
16
|
placeholder,
|
|
17
17
|
disabled,
|
|
18
18
|
className,
|
|
19
|
-
wrapperClassName
|
|
19
|
+
wrapperClassName,
|
|
20
|
+
isClearable = true
|
|
20
21
|
} = props;
|
|
21
22
|
let {
|
|
22
23
|
selectedOption
|
|
@@ -77,7 +78,7 @@ const SelectInput = props => {
|
|
|
77
78
|
return option.disabled;
|
|
78
79
|
},
|
|
79
80
|
placeholder: placeholder,
|
|
80
|
-
isClearable:
|
|
81
|
+
isClearable: isClearable,
|
|
81
82
|
theme: {
|
|
82
83
|
borderRadius: 0,
|
|
83
84
|
colors: {
|
|
@@ -30,9 +30,13 @@ export const ChipFacet = ({
|
|
|
30
30
|
identifier: facet.identifier,
|
|
31
31
|
value: entry.label
|
|
32
32
|
});
|
|
33
|
+
api.setPage({
|
|
34
|
+
from: 0
|
|
35
|
+
});
|
|
33
36
|
api.search();
|
|
34
37
|
}
|
|
35
38
|
}, entry.label);
|
|
36
39
|
})));
|
|
37
40
|
};
|
|
38
|
-
ChipFacet.DISPLAY = 'ChipFacet';
|
|
41
|
+
ChipFacet.DISPLAY = 'ChipFacet';
|
|
42
|
+
export default ChipFacet;
|
|
@@ -26,10 +26,14 @@ export const ListFacet = ({
|
|
|
26
26
|
identifier: facet.identifier,
|
|
27
27
|
value: entry.label
|
|
28
28
|
});
|
|
29
|
+
api.setPage({
|
|
30
|
+
from: 0
|
|
31
|
+
});
|
|
29
32
|
api.search();
|
|
30
33
|
},
|
|
31
34
|
disabled: parseInt(entry.count) === 0
|
|
32
35
|
}, entry.label, " (", entry.count, ")"));
|
|
33
36
|
})));
|
|
34
37
|
};
|
|
35
|
-
ListFacet.DISPLAY = 'ListFacet';
|
|
38
|
+
ListFacet.DISPLAY = 'ListFacet';
|
|
39
|
+
export default ListFacet;
|
|
@@ -1,32 +1,65 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { useSearchkit } from '@searchkit/client';
|
|
2
|
+
import { useSearchkit, useSearchkitVariables } from '@searchkit/client';
|
|
3
3
|
import Select from '../../../Form/Select';
|
|
4
4
|
import FormikWrapper from '../../../Form/FormikWrapper';
|
|
5
|
+
import { useTranslation } from 'react-i18next';
|
|
6
|
+
import classNames from 'classnames';
|
|
7
|
+
|
|
8
|
+
const useInitialValues = () => {
|
|
9
|
+
const parsed = useSearchkitVariables();
|
|
10
|
+
const filters = {};
|
|
11
|
+
|
|
12
|
+
if (parsed.filters) {
|
|
13
|
+
parsed.filters.forEach(filter => {
|
|
14
|
+
filters[filter.identifier] = filter.value;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return filters;
|
|
19
|
+
};
|
|
20
|
+
|
|
5
21
|
export const SelectFacet = ({
|
|
6
22
|
facet
|
|
7
23
|
}) => {
|
|
24
|
+
const {
|
|
25
|
+
t
|
|
26
|
+
} = useTranslation();
|
|
8
27
|
const api = useSearchkit();
|
|
9
28
|
const options = facet.entries.map(entry => ({
|
|
10
29
|
value: entry.label,
|
|
11
|
-
label: entry.label,
|
|
30
|
+
label: facet.identifier === 'type' ? t(`tags.${entry.label.toLowerCase()}`) : entry.label,
|
|
12
31
|
disabled: parseInt(entry.count) === 0
|
|
13
32
|
}));
|
|
33
|
+
const placeHolder = t(`placeholders.${facet.identifier}.placeholder`);
|
|
34
|
+
const classes = classNames('Facet', 'SelectFacet', `Facet--${facet.identifier}`);
|
|
35
|
+
const initialValues = useInitialValues();
|
|
14
36
|
return /*#__PURE__*/React.createElement("div", {
|
|
15
|
-
className:
|
|
37
|
+
className: classes,
|
|
16
38
|
key: facet.identifier
|
|
17
|
-
}, /*#__PURE__*/React.createElement(FormikWrapper,
|
|
39
|
+
}, /*#__PURE__*/React.createElement(FormikWrapper, {
|
|
40
|
+
initialValues: initialValues
|
|
41
|
+
}, /*#__PURE__*/React.createElement(Select, {
|
|
18
42
|
title: facet.label,
|
|
19
43
|
required: true,
|
|
20
|
-
placeholder:
|
|
44
|
+
placeholder: placeHolder,
|
|
21
45
|
fieldName: facet.identifier,
|
|
22
46
|
options: options,
|
|
23
47
|
onChange: value => {
|
|
24
|
-
api.
|
|
25
|
-
|
|
26
|
-
|
|
48
|
+
api.removeFiltersByIdentifier(facet.identifier);
|
|
49
|
+
api.setPage({
|
|
50
|
+
from: 0
|
|
27
51
|
});
|
|
52
|
+
|
|
53
|
+
if (value) {
|
|
54
|
+
api.addFilter({
|
|
55
|
+
identifier: facet.identifier,
|
|
56
|
+
value: value
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
28
60
|
api.search();
|
|
29
61
|
}
|
|
30
62
|
})));
|
|
31
63
|
};
|
|
32
|
-
SelectFacet.DISPLAY = 'SelectFacet';
|
|
64
|
+
SelectFacet.DISPLAY = 'SelectFacet';
|
|
65
|
+
export default SelectFacet;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import React, { useState, useEffect
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
2
|
import usePrevious from '../../../hooks/usePrevious';
|
|
3
|
+
import { useSearchkitVariables } from '@searchkit/client';
|
|
3
4
|
|
|
4
5
|
const SearchResultItemDefault = ({
|
|
5
6
|
item
|
|
@@ -17,25 +18,57 @@ const SearchResults = ({
|
|
|
17
18
|
}) => {
|
|
18
19
|
const SearchResultItem = renderItem || SearchResultItemDefault;
|
|
19
20
|
const SearchResultHeader = renderHeader || SearchResultHeaderDefault;
|
|
21
|
+
const variables = useSearchkitVariables();
|
|
20
22
|
const [items, setItems] = useState([]);
|
|
21
23
|
const [currentPage, setCurrentPage] = useState(-1);
|
|
24
|
+
const [previousQuery, setPreviousQuery] = useState(variables.query);
|
|
25
|
+
const [previousActiveFilters, setPreviousActiveFilters] = useState(variables.filters);
|
|
26
|
+
const [previousSortBy, setPreviousSortBy] = useState(variables.sortBy);
|
|
27
|
+
const [searchResultItems, setSearchResultItems] = useState( /*#__PURE__*/React.createElement(React.Fragment, null));
|
|
28
|
+
const [currentData, setCurrentData] = useState("");
|
|
22
29
|
const previousPage = usePrevious(currentPage);
|
|
23
30
|
const previousItems = usePrevious(items);
|
|
24
31
|
useEffect(() => {
|
|
32
|
+
if (typeof data.results === 'undefined') return;
|
|
33
|
+
|
|
25
34
|
if (!appendResults) {
|
|
26
|
-
|
|
35
|
+
// Set items directly if not appendResults
|
|
36
|
+
return setItems([...data.results.hits.items]);
|
|
27
37
|
}
|
|
28
38
|
|
|
29
|
-
|
|
30
|
-
|
|
39
|
+
const currentPageNumber = data.results.hits.page.pageNumber;
|
|
40
|
+
const currentQuery = variables.query;
|
|
41
|
+
const currentFiltersLength = variables.filters.length;
|
|
42
|
+
const newData = JSON.stringify(data);
|
|
43
|
+
const currentSortBy = variables.sortBy;
|
|
44
|
+
const queryChanged = previousQuery !== currentQuery;
|
|
45
|
+
const filtersChanged = previousActiveFilters.length !== currentFiltersLength;
|
|
46
|
+
const sortByChanged = currentSortBy !== previousSortBy;
|
|
47
|
+
const pageChanged = currentPageNumber !== previousPage;
|
|
48
|
+
const dataChanged = currentData !== newData; // Determine if we have to reset the results, or should append them to the results
|
|
49
|
+
|
|
50
|
+
if (dataChanged && (queryChanged || filtersChanged || pageChanged || sortByChanged)) {
|
|
51
|
+
if (typeof previousItems === 'undefined' || queryChanged || filtersChanged || sortByChanged) {
|
|
52
|
+
// Overwrite data when Query, Filters or SortBy has changed
|
|
53
|
+
setItems([...data.results.hits.items]);
|
|
54
|
+
} else {
|
|
55
|
+
// Append data if the page has changed and we have previousItems
|
|
56
|
+
setItems([...previousItems, ...data.results.hits.items]);
|
|
57
|
+
}
|
|
58
|
+
|
|
31
59
|
setCurrentPage(data.results.hits.page.pageNumber);
|
|
60
|
+
setPreviousQuery(variables.query);
|
|
61
|
+
setPreviousSortBy(variables.sortBy);
|
|
62
|
+
setPreviousActiveFilters(variables.filters);
|
|
63
|
+
setCurrentData(JSON.stringify(data));
|
|
32
64
|
}
|
|
33
|
-
}, [data,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
65
|
+
}, [data, appendResults, variables]); // Set the search results when items have changed
|
|
66
|
+
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
setSearchResultItems(items.map(item => /*#__PURE__*/React.createElement(SearchResultItem, {
|
|
69
|
+
item: item
|
|
70
|
+
})));
|
|
71
|
+
}, [items]);
|
|
39
72
|
return /*#__PURE__*/React.createElement("div", {
|
|
40
73
|
className: "SearchResults"
|
|
41
74
|
}, data && /*#__PURE__*/React.createElement(SearchResultHeader, {
|
|
@@ -1,20 +1,40 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { useSearchkit, useSearchkitVariables } from '@searchkit/client';
|
|
2
|
+
import React, { useState, useEffect } from 'react';
|
|
3
|
+
import SelectStyled from 'react-select';
|
|
4
|
+
import FormikWrapper from '../../Form/FormikWrapper';
|
|
5
|
+
import Select from '../../Form/Select';
|
|
3
6
|
|
|
4
|
-
const
|
|
7
|
+
const useInitialValues = () => {
|
|
8
|
+
const parsed = useSearchkitVariables();
|
|
9
|
+
return {
|
|
10
|
+
'sortBy': parsed.sortBy
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const SearchSorting = ({
|
|
5
15
|
data,
|
|
6
16
|
loading
|
|
7
17
|
}) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
const api = useSearchkit();
|
|
19
|
+
const initialValues = useInitialValues();
|
|
20
|
+
const options = data?.results?.summary?.sortOptions?.map(sortOption => ({
|
|
21
|
+
value: sortOption.id,
|
|
22
|
+
label: sortOption.label
|
|
23
|
+
})) || [];
|
|
24
|
+
return /*#__PURE__*/React.createElement(FormikWrapper, {
|
|
25
|
+
initialValues: initialValues
|
|
26
|
+
}, /*#__PURE__*/React.createElement(Select, {
|
|
27
|
+
fieldName: "sortBy",
|
|
28
|
+
isClearable: false,
|
|
29
|
+
options: options,
|
|
30
|
+
isLoading: loading,
|
|
31
|
+
onChange: value => {
|
|
32
|
+
api.setSortBy(value);
|
|
33
|
+
api.setPage({
|
|
34
|
+
from: 0
|
|
35
|
+
});
|
|
36
|
+
api.search();
|
|
37
|
+
}
|
|
17
38
|
}));
|
|
18
39
|
};
|
|
19
|
-
|
|
20
40
|
export default SearchSorting;
|
|
@@ -39,19 +39,15 @@ const SearchKit = ({
|
|
|
39
39
|
}, [uri]);
|
|
40
40
|
const skClient = useMemo(() => {
|
|
41
41
|
const skClient = new SearchkitClient();
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
sortBy: defaultSorting
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
42
|
+
skClient.updateBaseSearchState({
|
|
43
|
+
filters: defaultFilters,
|
|
44
|
+
query: defaultQuery,
|
|
45
|
+
page: {
|
|
46
|
+
size: pageSize,
|
|
47
|
+
from: 0
|
|
48
|
+
},
|
|
49
|
+
sortBy: defaultSorting
|
|
50
|
+
});
|
|
55
51
|
return skClient;
|
|
56
52
|
}, [useRouting, defaultFilters, defaultQuery, pageSize, defaultSorting]);
|
|
57
53
|
return /*#__PURE__*/React.createElement(ApolloProvider, {
|
package/dist/index.js
CHANGED
|
@@ -38,6 +38,9 @@ export { default as ViewportContext } from './Context/ViewportContext';
|
|
|
38
38
|
export { default as SearchKit } from './components/SearchKit';
|
|
39
39
|
export { default as SearchField } from './components/SearchKit/SearchField';
|
|
40
40
|
export { default as SearchFacets } from './components/SearchKit/SearchFacets';
|
|
41
|
+
export { default as SelectFacet } from './components/SearchKit/Facets/SelectFacet';
|
|
42
|
+
export { default as ListFacet } from './components/SearchKit/Facets/ListFacet';
|
|
43
|
+
export { default as ChipFacet } from './components/SearchKit/Facets/ChipFacet';
|
|
41
44
|
export { default as SearchSelectedFilters } from './components/SearchKit/SearchSelectedFilters';
|
|
42
45
|
export { default as SearchSorting } from './components/SearchKit/SearchSorting';
|
|
43
46
|
export { default as SearchReset } from './components/SearchKit/SearchReset';
|
package/package.json
CHANGED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { ApolloServer, gql } from 'apollo-server-micro';
|
|
2
|
-
export const config = {
|
|
3
|
-
api: {
|
|
4
|
-
bodyParser: false
|
|
5
|
-
}
|
|
6
|
-
};
|
|
7
|
-
const typeDefs = [gql`
|
|
8
|
-
type Query {
|
|
9
|
-
root: String
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
type Mutation {
|
|
13
|
-
root: String
|
|
14
|
-
}
|
|
15
|
-
`];
|
|
16
|
-
const server = new ApolloServer({
|
|
17
|
-
typeDefs,
|
|
18
|
-
resolvers: {},
|
|
19
|
-
introspection: true,
|
|
20
|
-
playground: true,
|
|
21
|
-
context: {}
|
|
22
|
-
});
|
|
23
|
-
export default server.createHandler({
|
|
24
|
-
path: '/api/graphql'
|
|
25
|
-
});
|