@uncinc/uncinc-react-kitchen-sink 2.3.1 → 2.3.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.
@@ -17,7 +17,9 @@ const SelectInput = props => {
17
17
  disabled,
18
18
  className,
19
19
  wrapperClassName,
20
- isClearable = true
20
+ isClearable = true,
21
+ multiple = false,
22
+ size
21
23
  } = props;
22
24
  let {
23
25
  selectedOption
@@ -36,10 +38,20 @@ const SelectInput = props => {
36
38
  } // If the selected option is not set, find the currently selected option by value.
37
39
 
38
40
 
39
- if (!selectedOption && value) {
40
- selectedOption = optionsTransformed.find(option => {
41
- return option.value === value;
42
- });
41
+ if (!selectedOption) {
42
+ if (multiple) {
43
+ const _value = value !== undefined ? value : defaultValue || [];
44
+
45
+ selectedOption = optionsTransformed.filter(option => {
46
+ return _value.includes(option.value);
47
+ });
48
+ } else {
49
+ const _value = value !== undefined ? value : defaultValue || '';
50
+
51
+ selectedOption = optionsTransformed.find(option => {
52
+ return option.value === _value;
53
+ });
54
+ }
43
55
  }
44
56
 
45
57
  return /*#__PURE__*/React.createElement(Field, {
@@ -55,27 +67,44 @@ const SelectInput = props => {
55
67
  id: id,
56
68
  className: c("Select__select", className),
57
69
  classNamePrefix: c("Select__inner", wrapperClassName),
58
- value: selectedOption || "",
70
+ value: selectedOption,
59
71
  defaultValue: defaultValue,
60
72
  disabled: disabled,
61
73
  onChange: e => {
74
+ let value = '';
75
+
62
76
  if (e) {
63
- if (onChange) {
64
- onChange(e.value);
77
+ if (multiple) {
78
+ value = e.map(item => {
79
+ return item.value;
80
+ });
81
+ } else {
82
+ value = e.value;
65
83
  }
66
-
67
- form.setFieldValue(fieldName, e.value);
68
84
  } else {
69
- if (onChange) {
70
- onChange('');
85
+ if (multiple) {
86
+ value = [];
71
87
  }
88
+ }
72
89
 
73
- form.setFieldValue(fieldName, null);
90
+ if (onChange) {
91
+ onChange(value);
74
92
  }
93
+
94
+ form.setFieldValue(fieldName, value);
75
95
  },
76
96
  options: optionsTransformed,
97
+ isMulti: multiple,
77
98
  isOptionDisabled: option => {
78
- return option.disabled;
99
+ if (option.disabled) {
100
+ return true;
101
+ }
102
+
103
+ if (size && selectedOption.length >= size) {
104
+ return true;
105
+ }
106
+
107
+ return false;
79
108
  },
80
109
  placeholder: placeholder,
81
110
  isClearable: isClearable,
@@ -18,9 +18,6 @@
18
18
  }
19
19
  }
20
20
  &__option {
21
- &--is-focused {
22
- color: black !important;
23
- }
24
21
  &--is-selected {
25
22
  background-color: transparent !important;
26
23
  color: $color--primary !important;
@@ -17,7 +17,8 @@ const Select = props => {
17
17
  displayRequiredIndicator,
18
18
  className,
19
19
  wrapperClassName,
20
- disabled = false
20
+ disabled = false,
21
+ multiple = false
21
22
  } = props;
22
23
  return /*#__PURE__*/React.createElement(GenericFormElement, {
23
24
  className: c("Select", wrapperClassName),
@@ -32,7 +33,8 @@ const Select = props => {
32
33
  className: c(className, {
33
34
  'error': error && touched
34
35
  }),
35
- disabled: disabled
36
+ disabled: disabled,
37
+ multiple: multiple
36
38
  })));
37
39
  };
38
40
 
@@ -5,22 +5,49 @@ export default {
5
5
  title: 'Molecules/Form'
6
6
  };
7
7
  export const Select = () => {
8
- return /*#__PURE__*/React.createElement(FormikWrapper, {
9
- initialValues: {
10
- poison: 'beer'
8
+ return /*#__PURE__*/React.createElement(FormikWrapper, null, /*#__PURE__*/React.createElement(FormikSelect, {
9
+ title: "Pick your poison",
10
+ required: true,
11
+ description: "This is a test input.",
12
+ placeholder: "Select a value...",
13
+ fieldName: "poison",
14
+ options: {
15
+ beer: 'Beer',
16
+ wine: 'Wine',
17
+ rum: 'Rum',
18
+ whisky: 'Whisk(e)y'
19
+ },
20
+ defaultValue: "wine",
21
+ validation: value => {
22
+ let error;
23
+
24
+ if (!value) {
25
+ error = 'Dit is een vereist veld.';
26
+ }
27
+
28
+ return error;
29
+ },
30
+ onChange: e => {
31
+ console.log(e);
11
32
  }
12
- }, /*#__PURE__*/React.createElement(FormikSelect, {
33
+ }));
34
+ };
35
+ export const SelectMultiple = () => {
36
+ return /*#__PURE__*/React.createElement(FormikWrapper, null, /*#__PURE__*/React.createElement(FormikSelect, {
13
37
  title: "Pick your poison",
14
38
  required: true,
15
39
  description: "This is a test input.",
16
40
  placeholder: "Select a value...",
17
41
  fieldName: "poison",
42
+ multiple: true,
43
+ size: 2,
18
44
  options: {
19
45
  beer: 'Beer',
20
46
  wine: 'Wine',
21
47
  rum: 'Rum',
22
48
  whisky: 'Whisk(e)y'
23
49
  },
50
+ defaultValue: ['wine'],
24
51
  validation: value => {
25
52
  let error;
26
53
 
@@ -1,41 +1,70 @@
1
- import React, { useRef } from 'react';
2
- import { useSearchkit, useSearchkitQueryValue } from '@searchkit/client';
3
- import TextField from '../../Form/TextField';
1
+ import React, { useRef } from "react";
2
+ import { useSearchkit, useSearchkitQueryValue } from "@searchkit/client";
4
3
  import FormikWrapper from '../../Form/FormikWrapper';
4
+ import Button from '../../Button';
5
+ import TextField from '../../Form/TextField';
5
6
 
6
7
  const SearchField = ({
7
- timeout
8
+ timeout,
9
+ autoSearch = true,
10
+ buttonText,
11
+ placeholder
8
12
  }) => {
9
13
  const [query, setQuery] = useSearchkitQueryValue();
10
14
  const api = useSearchkit();
11
15
  const timeoutRef = useRef();
16
+ const fieldLabel = false;
17
+
18
+ const searchQuery = query => {
19
+ setQuery(query);
20
+ api.setQuery(query);
21
+ api.search();
22
+ };
23
+
24
+ const onSubmit = (values, form) => {
25
+ searchQuery(values.query);
26
+ };
12
27
 
13
28
  const onChange = e => {
29
+ e.persist();
30
+
14
31
  if (timeoutRef.current) {
15
32
  clearTimeout(timeoutRef.current);
16
33
  }
17
34
 
18
35
  timeoutRef.current = setTimeout(() => {
19
- setQuery(e.target.value);
20
- api.setQuery(e.target.value);
21
- api.search();
36
+ searchQuery(e.target.value);
22
37
  }, timeout);
23
38
  };
24
39
 
40
+ const handleEnter = event => {
41
+ if (event.key === 'Enter') {
42
+ onSubmit();
43
+ }
44
+ };
45
+
25
46
  return /*#__PURE__*/React.createElement(FormikWrapper, {
26
47
  initialValues: {
27
48
  query: query
28
49
  },
29
50
  displayRequiredIndicator: "required",
30
- enableReinitialize: true
51
+ enableReinitialize: true,
52
+ onSubmit: onSubmit
31
53
  }, /*#__PURE__*/React.createElement(TextField, {
32
54
  fieldName: "query",
33
- title: "Search",
34
- onChange: onChange
35
- }));
55
+ title: fieldLabel,
56
+ placeholder: placeholder,
57
+ onChange: autoSearch ? () => onChange : () => handleEnter
58
+ }), !autoSearch && /*#__PURE__*/React.createElement(Button, {
59
+ type: "submit",
60
+ primary: true
61
+ }, buttonText));
36
62
  };
37
63
 
38
64
  SearchField.defaultProps = {
39
- timeout: 1000
65
+ timeout: 1000,
66
+ autoSearch: true,
67
+ buttonText: '',
68
+ placeholder: ''
40
69
  };
41
70
  export default SearchField;
@@ -1,6 +1,7 @@
1
1
  import React, { useState, useEffect } from 'react';
2
2
  import usePrevious from '../../../hooks/usePrevious';
3
3
  import { useSearchkitVariables } from '@searchkit/client';
4
+ import PropTypes from 'prop-types';
4
5
 
5
6
  const SearchResultItemDefault = ({
6
7
  item
@@ -14,10 +15,11 @@ const SearchResults = ({
14
15
  data,
15
16
  renderItem,
16
17
  renderHeader,
17
- appendResults = false
18
+ appendResults = false,
19
+ scrollView = null
18
20
  }) => {
19
- const SearchResultItem = renderItem || SearchResultItemDefault;
20
- const SearchResultHeader = renderHeader || SearchResultHeaderDefault;
21
+ const SearchResultItem = renderItem;
22
+ const SearchResultHeader = renderHeader;
21
23
  const variables = useSearchkitVariables();
22
24
  const [items, setItems] = useState([]);
23
25
  const [currentPage, setCurrentPage] = useState(-1);
@@ -30,6 +32,11 @@ const SearchResults = ({
30
32
  const previousItems = usePrevious(items);
31
33
  useEffect(() => {
32
34
  if (typeof data.results === 'undefined') return;
35
+ setCurrentPage(data.results.hits.page.pageNumber);
36
+ setPreviousQuery(variables.query);
37
+ setPreviousSortBy(variables.sortBy);
38
+ setPreviousActiveFilters(variables.filters);
39
+ setCurrentData(JSON.stringify(data));
33
40
 
34
41
  if (!appendResults) {
35
42
  // Set items directly if not appendResults
@@ -55,20 +62,30 @@ const SearchResults = ({
55
62
  // Append data if the page has changed and we have previousItems
56
63
  setItems([...previousItems, ...data.results.hits.items]);
57
64
  }
58
-
59
- setCurrentPage(data.results.hits.page.pageNumber);
60
- setPreviousQuery(variables.query);
61
- setPreviousSortBy(variables.sortBy);
62
- setPreviousActiveFilters(variables.filters);
63
- setCurrentData(JSON.stringify(data));
64
65
  }
65
66
  }, [data, appendResults, variables]); // Set the search results when items have changed
66
67
 
67
68
  useEffect(() => {
68
69
  setSearchResultItems(items.map(item => /*#__PURE__*/React.createElement(SearchResultItem, {
70
+ key: item.id,
69
71
  item: item
70
72
  })));
71
- }, [items]);
73
+ }, [items]); // Scroll to top on every page.
74
+
75
+ useEffect(() => {
76
+ if (!currentData) {
77
+ return;
78
+ }
79
+
80
+ const currentPageNumber = currentData.results.hits.page.pageNumber;
81
+
82
+ if (appendResults === false && scrollView && scrollView.current && currentPageNumber !== 0) {
83
+ scrollView.current.scrollIntoView({
84
+ behavior: 'smooth',
85
+ block: 'start'
86
+ });
87
+ }
88
+ }, [currentData]);
72
89
  return /*#__PURE__*/React.createElement("div", {
73
90
  className: "SearchResults"
74
91
  }, data && /*#__PURE__*/React.createElement(SearchResultHeader, {
@@ -76,4 +93,19 @@ const SearchResults = ({
76
93
  }), searchResultItems);
77
94
  };
78
95
 
96
+ SearchResults.defaultProps = {
97
+ renderItem: SearchResultItemDefault,
98
+ renderHeader: SearchResultHeaderDefault,
99
+ appendResults: false,
100
+ scrollView: null
101
+ };
102
+ SearchResults.propTypes = {
103
+ // its turned off due to complex struxture of the object
104
+ // eslint-disable-next-line react/forbid-prop-types
105
+ data: PropTypes.object.isRequired,
106
+ renderItem: PropTypes.elementType,
107
+ renderHeader: PropTypes.elementType,
108
+ appendResults: PropTypes.bool,
109
+ scrollView: PropTypes.element
110
+ };
79
111
  export default SearchResults;
@@ -0,0 +1,25 @@
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
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uncinc/uncinc-react-kitchen-sink",
3
- "version": "2.3.1",
3
+ "version": "2.3.3",
4
4
  "description": "Default React components that are easily extended.",
5
5
  "author": "uncinc",
6
6
  "license": "MIT",
@@ -53,11 +53,11 @@
53
53
  "next-with-apollo": "^5.2.1",
54
54
  "ola": "^1.1.1",
55
55
  "path": "^0.12.7",
56
- "react": "^16.14.0",
56
+ "react": "^16 || ^17 || ^18",
57
57
  "react-animate-height": "^2.0.23",
58
58
  "react-autosuggest": "^10.0.2",
59
59
  "react-datepicker": "^3.0.0",
60
- "react-dom": "^16.4",
60
+ "react-dom": "^16 || ^17 || ^18",
61
61
  "react-global-configuration": "^1.4.0",
62
62
  "react-html-parser": "^2.0.2",
63
63
  "react-i18next": "^11.5.0",
@@ -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;