@uncinc/uncinc-react-kitchen-sink 2.2.11 → 2.2.14

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.
@@ -30,10 +30,11 @@ const AccordionItem = ({
30
30
  iconClassName,
31
31
  duration,
32
32
  easing,
33
- titleComponent
33
+ titleComponent,
34
+ className
34
35
  }) => {
35
36
  const [collapsed, setCollapsed] = useState(true);
36
- const classes = c('Accordion__item', {
37
+ const classes = c(className, 'Accordion__item', {
37
38
  collapsed: collapsed
38
39
  });
39
40
  const iconClasses = c('icon', iconClassName);
@@ -35,9 +35,8 @@ function Checkbox(props) {
35
35
  const inputClasses = c({
36
36
  hidden: !field.value.includes('__other__')
37
37
  });
38
- return /*#__PURE__*/React.createElement("div", {
39
- className: classes
40
- }, /*#__PURE__*/React.createElement("label", {
38
+ return /*#__PURE__*/React.createElement("label", {
39
+ className: classes,
41
40
  htmlFor: name
42
41
  }, /*#__PURE__*/React.createElement("input", _extends({}, field, {
43
42
  name: props.name,
@@ -47,7 +46,7 @@ function Checkbox(props) {
47
46
  checked: checked,
48
47
  disabled: disabled,
49
48
  className: className
50
- })), props.otherLabel), /*#__PURE__*/React.createElement("textarea", {
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", {
51
50
  placeholder: props.otherPlaceholder,
52
51
  className: inputClasses,
53
52
  onChange: e => {
@@ -67,7 +66,7 @@ function Checkbox(props) {
67
66
  checked: checked,
68
67
  disabled: disabled,
69
68
  className: className
70
- })), props.label);
69
+ })), /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement("span", null, props.label), props.description && /*#__PURE__*/React.createElement("span", null, props.description)));
71
70
  });
72
71
  }
73
72
 
@@ -83,6 +82,7 @@ const Checkboxes = props => {
83
82
  error,
84
83
  type,
85
84
  options,
85
+ descriptions = {},
86
86
  displayRequiredIndicator,
87
87
  className,
88
88
  wrapperClassName,
@@ -101,9 +101,11 @@ const Checkboxes = props => {
101
101
  displayRequiredIndicator: displayRequiredIndicator
102
102
  }, Object.keys(options).map(value => {
103
103
  const label = options[value];
104
+ const description = descriptions[value] || null;
104
105
  return /*#__PURE__*/React.createElement(Checkbox, {
105
106
  key: value,
106
107
  label: label,
108
+ description: description,
107
109
  className: c(className, {
108
110
  'error': error && touched
109
111
  }),
@@ -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.includes(props.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("div", {
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',
@@ -24,6 +24,11 @@ export const RadioButtons = props => {
24
24
  whisky: 'Whisk(e)y',
25
25
  '__other__': 'Anders'
26
26
  },
27
+ descriptions: {
28
+ beer: 'Bier is lekker',
29
+ wine: 'Wijn ook wel',
30
+ whisky: 'Maar whiskey is het lekkerst'
31
+ },
27
32
  validation: value => {
28
33
  let error;
29
34
 
@@ -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: true,
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: "Facet SelectFacet",
37
+ className: classes,
16
38
  key: facet.identifier
17
- }, /*#__PURE__*/React.createElement(FormikWrapper, null, /*#__PURE__*/React.createElement(Select, {
39
+ }, /*#__PURE__*/React.createElement(FormikWrapper, {
40
+ initialValues: initialValues
41
+ }, /*#__PURE__*/React.createElement(Select, {
18
42
  title: facet.label,
19
43
  required: true,
20
- placeholder: "Select a value...",
44
+ placeholder: placeHolder,
21
45
  fieldName: facet.identifier,
22
46
  options: options,
23
47
  onChange: value => {
24
- api.toggleFilter({
25
- identifier: facet.identifier,
26
- value: value
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, useRef } from 'react';
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,30 +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
- return;
35
+ // Set items directly if not appendResults
36
+ return setItems([...data.results.hits.items]);
27
37
  }
28
38
 
29
- if (data && previousPage !== undefined && data.results.hits.page.pageNumber !== previousPage) {
30
- if (typeof previousItems === 'undefined') {
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
31
53
  setItems([...data.results.hits.items]);
32
54
  } else {
55
+ // Append data if the page has changed and we have previousItems
33
56
  setItems([...previousItems, ...data.results.hits.items]);
34
57
  }
35
58
 
36
59
  setCurrentPage(data.results.hits.page.pageNumber);
60
+ setPreviousQuery(variables.query);
61
+ setPreviousSortBy(variables.sortBy);
62
+ setPreviousActiveFilters(variables.filters);
63
+ setCurrentData(JSON.stringify(data));
37
64
  }
38
- }, [data, previousPage, previousItems, appendResults]);
39
- const searchResultItems = appendResults ? data && items.map(item => /*#__PURE__*/React.createElement(SearchResultItem, {
40
- item: item
41
- })) : data && data.results.hits.items.map(item => /*#__PURE__*/React.createElement(SearchResultItem, {
42
- item: item
43
- }));
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]);
44
72
  return /*#__PURE__*/React.createElement("div", {
45
73
  className: "SearchResults"
46
74
  }, data && /*#__PURE__*/React.createElement(SearchResultHeader, {
@@ -1,20 +1,40 @@
1
- import React from 'react';
2
- import { SortingSelector } from '@searchkit/elastic-ui';
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 SearchSorting = ({
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
- if (!data) {
9
- return null;
10
- }
11
-
12
- return /*#__PURE__*/React.createElement("div", {
13
- className: "SearchSorting"
14
- }, /*#__PURE__*/React.createElement(SortingSelector, {
15
- data: data.results,
16
- loading: loading
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
- if (!useRouting) {
44
- skClient.updateBaseSearchState({
45
- filters: defaultFilters,
46
- query: defaultQuery,
47
- page: {
48
- size: pageSize,
49
- from: 0
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@uncinc/uncinc-react-kitchen-sink",
3
- "version": "2.2.11",
3
+ "version": "2.2.14",
4
4
  "description": "Default React components that are easily extended.",
5
5
  "author": "uncinc",
6
6
  "license": "MIT",
@@ -1,45 +0,0 @@
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
- }
@@ -1,3 +0,0 @@
1
- .WysiwygField {
2
- margin-right: 200px;
3
- }
@@ -1,5 +0,0 @@
1
- const makeSafeForCSS = value => {
2
- return encodeURIComponent(value).replace(/\.|%[0-9a-z]{2}/gi, '');
3
- };
4
-
5
- export default makeSafeForCSS;