@uncinc/uncinc-react-kitchen-sink 2.2.0 → 2.2.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.
@@ -1,4 +1,4 @@
1
- import React, { useRef } from 'react';
1
+ import React from 'react';
2
2
  import Lottie from './';
3
3
  import LottieAnimationWithMousePosition from './LottieAnimationWithMousePosition';
4
4
  import exampleLottie from '../../assets/lottie/example.json';
@@ -10,8 +10,7 @@ export default {
10
10
  export const DefaultAnimation = () => /*#__PURE__*/React.createElement(Lottie, {
11
11
  id: "example",
12
12
  data: exampleLottie,
13
- onInit: lottie => console.log(lottie),
14
- autoPlay: false
13
+ onInit: lottie => console.log(lottie)
15
14
  }); // Animation active on hover
16
15
 
17
16
  export const activateOnHoverAnimation = () => /*#__PURE__*/React.createElement(Lottie, {
@@ -34,28 +33,4 @@ export const pauseOnClickAnimation = () => /*#__PURE__*/React.createElement(Lott
34
33
 
35
34
  export const PathLoad = () => /*#__PURE__*/React.createElement(Lottie, {
36
35
  path: "https://maxst.icons8.com/vue-static/landings/animated-icons/icons/checkmark-ok/checkmark-ok.json"
37
- });
38
- export const Custom = () => {
39
- const l = useRef();
40
- const direction = useRef(true);
41
- return /*#__PURE__*/React.createElement("div", {
42
- className: "fooo",
43
- onClick: () => {
44
- console.log('click');
45
-
46
- if (direction.current) {
47
- direction.current = false;
48
- l.current.playSegments([0, 5], true);
49
- } else {
50
- direction.current = true;
51
- l.current.playSegments([5, 0], true);
52
- }
53
- }
54
- }, /*#__PURE__*/React.createElement(Lottie, {
55
- id: "example",
56
- data: exampleLottie,
57
- onInit: lottie => l.current = lottie,
58
- autoPlay: false,
59
- loop: false
60
- }));
61
- };
36
+ });
@@ -0,0 +1,40 @@
1
+ import React from 'react';
2
+ import { useSearchkit } from '@searchkit/client';
3
+ import Button from '../../Button';
4
+
5
+ const SearchLoadMore = ({
6
+ data,
7
+ label,
8
+ className
9
+ }) => {
10
+ const api = useSearchkit();
11
+
12
+ if (!data) {
13
+ return null;
14
+ }
15
+
16
+ const setNextPage = () => {
17
+ if (data) {
18
+ api.setPage({
19
+ size: data.results.hits.page.size,
20
+ from: parseInt(data.results.hits.page.size) * (parseInt(data.results.hits.page.pageNumber) + 1)
21
+ });
22
+ api.search();
23
+ }
24
+ };
25
+
26
+ const currentPage = data.results.hits.page.pageNumber;
27
+ const lastPage = data.results.hits.page.totalPages;
28
+
29
+ if (currentPage + 1 >= lastPage) {
30
+ return null;
31
+ }
32
+
33
+ return /*#__PURE__*/React.createElement("div", {
34
+ className: className
35
+ }, /*#__PURE__*/React.createElement(Button, {
36
+ onClick: setNextPage
37
+ }, label));
38
+ };
39
+
40
+ export default SearchLoadMore;
@@ -1,4 +1,5 @@
1
- import React from 'react';
1
+ import React, { useState, useEffect, useRef } from 'react';
2
+ import usePrevious from '../../../hooks/usePrevious';
2
3
 
3
4
  const SearchResultItemDefault = ({
4
5
  item
@@ -11,17 +12,35 @@ const SearchResultHeaderDefault = ({
11
12
  const SearchResults = ({
12
13
  data,
13
14
  renderItem,
14
- renderHeader
15
+ renderHeader,
16
+ appendResults = false
15
17
  }) => {
16
18
  const SearchResultItem = renderItem || SearchResultItemDefault;
17
19
  const SearchResultHeader = renderHeader || SearchResultHeaderDefault;
20
+ const [items, setItems] = useState([]);
21
+ const [currentPage, setCurrentPage] = useState(-1);
22
+ const previousPage = usePrevious(currentPage);
23
+ const previousItems = usePrevious(items);
24
+ useEffect(() => {
25
+ if (!appendResults) {
26
+ return;
27
+ }
28
+
29
+ if (data && previousPage !== undefined && data.results.hits.page.pageNumber !== previousPage) {
30
+ setItems([...previousItems, ...data.results.hits.items]);
31
+ setCurrentPage(data.results.hits.page.pageNumber);
32
+ }
33
+ }, [data, previousPage, previousItems, appendResults]);
34
+ const searchResultItems = appendResults ? data && items.map(item => /*#__PURE__*/React.createElement(SearchResultItem, {
35
+ item: item
36
+ })) : data && data.results.hits.items.map(item => /*#__PURE__*/React.createElement(SearchResultItem, {
37
+ item: item
38
+ }));
18
39
  return /*#__PURE__*/React.createElement("div", {
19
40
  className: "SearchResults"
20
41
  }, data && /*#__PURE__*/React.createElement(SearchResultHeader, {
21
42
  data: data
22
- }), data && data.results.hits.items.map(item => /*#__PURE__*/React.createElement(SearchResultItem, {
23
- item: item
24
- })));
43
+ }), searchResultItems);
25
44
  };
26
45
 
27
46
  export default SearchResults;
@@ -9,6 +9,7 @@ import SearchFacets from './SearchFacets';
9
9
  import SearchSelectedFilters from './SearchSelectedFilters';
10
10
  import SearchReset from './SearchReset';
11
11
  import SearchSorting from './SearchSorting';
12
+ import SearchLoadMore from './SearchLoadMore';
12
13
  export default {
13
14
  title: 'Molecules/SearchKit'
14
15
  };
@@ -188,15 +189,12 @@ export const Test = () => {
188
189
  uri: "http://localhost:4000/api/graphql",
189
190
  query: query,
190
191
  useRouting: false,
191
- defaultFilters: [{
192
+ filters: [{
192
193
  identifier: 'type',
193
194
  value: 'article'
194
195
  }],
195
- defaultQuery: q
196
- }, (data, loading) => /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(SearchFacets, {
197
- data: data,
198
- loading: loading
199
- }), /*#__PURE__*/React.createElement(SearchResults, {
196
+ searchQuery: q
197
+ }, (data, loading) => /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(SearchResults, {
200
198
  data: data,
201
199
  renderItem: SearchItem,
202
200
  renderHeader: SearchHeader
@@ -206,20 +204,44 @@ export const Test = () => {
206
204
  uri: "http://localhost:4000/api/graphql",
207
205
  query: query,
208
206
  useRouting: false,
209
- pageSize: 5,
210
- defaultFilters: [{
207
+ filters: [{
211
208
  identifier: 'type',
212
209
  value: 'landing_page'
213
210
  }],
214
- defaultQuery: q
215
- }, (data, loading) => /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(SearchFacets, {
216
- data: data,
217
- loading: loading
218
- }), /*#__PURE__*/React.createElement(SearchResults, {
211
+ searchQuery: q
212
+ }, (data, loading) => /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(SearchResults, {
219
213
  data: data,
220
214
  renderItem: SearchItem,
221
215
  renderHeader: SearchHeader
222
216
  }), /*#__PURE__*/React.createElement(SearchPagination, {
223
217
  data: data
224
218
  }))));
219
+ };
220
+ export const LoadMore = () => {
221
+ const api = useSearchkit();
222
+ return /*#__PURE__*/React.createElement(SearchKit, {
223
+ uri: "http://localhost:4000/api/graphql",
224
+ query: query // useRouting={false}
225
+ ,
226
+ pageSize: 5
227
+ }, (data, loading) => {
228
+ const toggleFilter = () => {
229
+ api.toggleFilter({
230
+ identifier: "type",
231
+ value: "22"
232
+ });
233
+ api.search();
234
+ };
235
+
236
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
237
+ onClick: toggleFilter
238
+ }, "Toggle"), /*#__PURE__*/React.createElement(SearchResults, {
239
+ data: data,
240
+ renderItem: SearchItem,
241
+ renderHeader: SearchHeader,
242
+ append: true
243
+ }), /*#__PURE__*/React.createElement(SearchLoadMore, {
244
+ data: data
245
+ }));
246
+ });
225
247
  };
@@ -7,10 +7,17 @@ import Button from '../Button';
7
7
 
8
8
  const WysiwygField = ({
9
9
  html,
10
+ customElementHandler,
10
11
  ...props
11
12
  }) => {
12
13
  const parsedHtml = ReactHtmlParser(html, {
13
14
  transform: node => {
15
+ const customHandler = customElementHandler(node);
16
+
17
+ if (customHandler) {
18
+ return customHandler;
19
+ }
20
+
14
21
  switch (node.name) {
15
22
  case 'a':
16
23
  {
@@ -42,7 +49,12 @@ const WysiwygField = ({
42
49
  }, props), parsedHtml);
43
50
  };
44
51
 
45
- PropTypes.propTypes = {
46
- html: PropTypes.string.isRequired
52
+ WysiwygField.propTypes = {
53
+ html: PropTypes.string.isRequired,
54
+ customElementHandler: PropTypes.func
55
+ };
56
+ WysiwygField.defaultProps = {
57
+ html: '',
58
+ customElementHandler: () => {}
47
59
  };
48
60
  export default WysiwygField;
@@ -6,4 +6,38 @@ export default {
6
6
  const html = "<p>This is <em>some</em> example <a href='https://www.uncinc.nl'>HTML</a>.</p>";
7
7
  export const Primary = () => /*#__PURE__*/React.createElement(WysiwygField, {
8
8
  html: html
9
+ });
10
+
11
+ const Abbr = ({
12
+ title,
13
+ children
14
+ }) => {
15
+ return /*#__PURE__*/React.createElement("abbr", {
16
+ title: title
17
+ }, children);
18
+ };
19
+
20
+ const htmlCustomHandler = `
21
+ <p>Lorem ipsum dolor sit amet, <abbr title="Ut ut tellus et augue feugiat sollicitudin sit amet viverra nisi.">consectetur adipiscing</abbr> elit. Aliquam in sodales tellus. Ut ut tellus et augue feugiat sollicitudin sit amet viverra nisi. Nulla malesuada erat non massa pellentesque, ut ultricies tellus sodales. Fusce ac feugiat ligula. In vel metus diam. Maecenas diam ex, tincidunt tempor nibh sed, suscipit semper lectus. Sed eu enim vel erat tempus mollis. Integer eget gravida orci. Nunc volutpat velit id dui semper tincidunt. Nulla maximus nisl nec volutpat faucibus. Integer vitae ullamcorper ex. Vestibulum facilisis convallis arcu, ac interdum libero malesuada eget.</p>
22
+ <p>Donec feugiat, nunc vitae euismod posuere, urna nisl elementum nibh, quis ultricies libero leo sed neque. Praesent vel vestibulum sem, eget congue purus. Nunc non volutpat urna, vitae ullamcorper justo. Suspendisse in tortor ex. Phasellus euismod eget neque vitae consequat. Vestibulum sem mi, dictum id consectetur at, hendrerit in massa. Mauris quis sem condimentum, condimentum enim sed, varius sem. Curabitur convallis tempus nulla, eget consectetur quam sagittis at. Nulla a feugiat tortor. Mauris fermentum lectus ac mauris cursus ornare.</p>
23
+ <p>Nam venenatis est eget lorem laoreet, id tempor urna hendrerit. Quisque suscipit in magna nec condimentum. Duis id tempor nisi. Sed rutrum urna elit, vitae placerat enim volutpat nec. Vivamus volutpat, magna sit amet commodo ultricies, enim turpis pretium libero, quis molestie nibh augue a ex. Nulla vestibulum vestibulum tellus, vel molestie libero vehicula nec. Sed maximus tortor vel ipsum cursus egestas. Proin suscipit tortor id luctus bibendum.</p>
24
+ `;
25
+ export const CustomHandlers = () => /*#__PURE__*/React.createElement(WysiwygField, {
26
+ html: htmlCustomHandler,
27
+ customElementHandler: element => {
28
+ switch (element.name) {
29
+ case 'abbr':
30
+ {
31
+ console.log(element);
32
+ return /*#__PURE__*/React.createElement(Abbr, {
33
+ title: element.attribs.title
34
+ }, element.children[0].data);
35
+ }
36
+
37
+ default:
38
+ {
39
+ return null;
40
+ }
41
+ }
42
+ }
9
43
  });
@@ -0,0 +1,3 @@
1
+ .WysiwygField {
2
+ margin-right: 200px;
3
+ }
@@ -0,0 +1,11 @@
1
+ import { useEffect, useState } from 'react';
2
+ export default function useOnScreen(ref) {
3
+ const [isIntersecting, setIntersecting] = useState(false);
4
+ const observer = new IntersectionObserver(([entry]) => setIntersecting(entry.isIntersecting));
5
+ useEffect(() => {
6
+ observer.observe(ref.current); // Remove the observer as soon as the component is unmounted
7
+
8
+ return () => observer.disconnect();
9
+ }, [observer, ref]);
10
+ return isIntersecting;
11
+ }
@@ -0,0 +1,14 @@
1
+ import { useEffect, useRef } from 'react';
2
+ export default function usePrevious(value) {
3
+ // The ref object is a generic container whose current property is mutable ...
4
+ // ... and can hold any value, similar to an instance property on a class
5
+ const ref = useRef(); // Store current value in ref
6
+
7
+ useEffect(() => {
8
+ ref.current = value;
9
+ }, [value]); // Only re-run if value changes
10
+ // Return previous value (happens before update in useEffect above)
11
+
12
+ return ref.current;
13
+ }
14
+ ;
@@ -0,0 +1,17 @@
1
+ import { useEffect, useState } from 'react';
2
+
3
+ const useScrollPosition = () => {
4
+ const [scrollPosition, setScrollPosition] = useState(0);
5
+ useEffect(() => {
6
+ const updatePosition = () => {
7
+ setScrollPosition(window.pageYOffset);
8
+ };
9
+
10
+ window.addEventListener('scroll', updatePosition);
11
+ updatePosition();
12
+ return () => window.removeEventListener('scroll', updatePosition);
13
+ }, []);
14
+ return scrollPosition;
15
+ };
16
+
17
+ export default useScrollPosition;
@@ -0,0 +1,25 @@
1
+ import { useState, useEffect } from 'react';
2
+
3
+ function getWindowDimensions() {
4
+ const {
5
+ innerWidth: width,
6
+ innerHeight: height
7
+ } = window;
8
+ return {
9
+ width,
10
+ height
11
+ };
12
+ }
13
+
14
+ export default function useWindowDimensions() {
15
+ const [windowDimensions, setWindowDimensions] = useState(getWindowDimensions());
16
+ useEffect(() => {
17
+ function handleResize() {
18
+ setWindowDimensions(getWindowDimensions());
19
+ }
20
+
21
+ window.addEventListener('resize', handleResize);
22
+ return () => window.removeEventListener('resize', handleResize);
23
+ }, []);
24
+ return windowDimensions;
25
+ }
package/dist/index.js CHANGED
@@ -43,4 +43,9 @@ export { default as SearchSorting } from './components/SearchKit/SearchSorting';
43
43
  export { default as SearchReset } from './components/SearchKit/SearchReset';
44
44
  export { default as SearchResults } from './components/SearchKit/SearchResults';
45
45
  export { default as SearchPagination } from './components/SearchKit/SearchPagination';
46
- export { default as Cookie } from './components/Cookie';
46
+ export { default as SearchLoadMore } from './components/SearchKit/SearchLoadMore';
47
+ export { default as Cookie } from './components/Cookie';
48
+ export { default as useOnScreen } from './hooks/useOnScreen';
49
+ export { default as usePrevious } from './hooks/usePrevious';
50
+ export { default as useScrollPosition } from './hooks/useScrollPosition';
51
+ export { default as useWindowDimensions } from './hooks/useWindowDimensions';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uncinc/uncinc-react-kitchen-sink",
3
- "version": "2.2.0",
3
+ "version": "2.2.3",
4
4
  "description": "Default React components that are easily extended.",
5
5
  "author": "uncinc",
6
6
  "license": "MIT",