@performant-software/semantic-components 1.0.18-beta.9 → 1.0.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@performant-software/semantic-components",
3
- "version": "1.0.18-beta.9",
3
+ "version": "1.0.18",
4
4
  "description": "A package of shared components based on the Semantic UI Framework.",
5
5
  "license": "MIT",
6
6
  "main": "./build/index.js",
@@ -12,7 +12,7 @@
12
12
  "build": "webpack --mode production && flow-copy-source -v src types"
13
13
  },
14
14
  "dependencies": {
15
- "@performant-software/shared-components": "^1.0.18-beta.9",
15
+ "@performant-software/shared-components": "^1.0.18",
16
16
  "@react-google-maps/api": "^2.8.1",
17
17
  "axios": "^0.26.1",
18
18
  "i18next": "^19.4.4",
@@ -1,6 +1,11 @@
1
1
  // @flow
2
2
 
3
- import React, { useState, type Node, useMemo } from 'react';
3
+ import React, {
4
+ useImperativeHandle,
5
+ useMemo,
6
+ useState,
7
+ type Node
8
+ } from 'react';
4
9
  import {
5
10
  Accordion,
6
11
  Divider,
@@ -30,6 +35,13 @@ type Props = {
30
35
  */
31
36
  divided?: boolean,
32
37
 
38
+ /**
39
+ * React ref element to apply to the expand/collapse functions.
40
+ */
41
+ innerRef?: {
42
+ current: ?HTMLElement
43
+ },
44
+
33
45
  /**
34
46
  * Facet title to display at the top.
35
47
  */
@@ -66,6 +78,14 @@ const Facet = (props: Props) => {
66
78
  return classNames.join(' ');
67
79
  }, [props.className, props.visible]);
68
80
 
81
+ /**
82
+ * Expose collapse/expand functions on the ref object to allow parent components to imperatively open/close.
83
+ */
84
+ useImperativeHandle(props.innerRef, () => ({
85
+ collapse: () => setActive(false),
86
+ expand: () => setActive(true)
87
+ }));
88
+
69
89
  return (
70
90
  <>
71
91
  <Accordion
@@ -2,8 +2,10 @@
2
2
 
3
3
  import { Timer } from '@performant-software/shared-components';
4
4
  import React, {
5
+ forwardRef,
5
6
  useCallback,
6
- useEffect, useMemo,
7
+ useEffect,
8
+ useMemo,
7
9
  useRef,
8
10
  useState
9
11
  } from 'react';
@@ -50,7 +52,7 @@ const OPERATOR_AND = 'and';
50
52
  * This component is used with the `useRefinementList` hook from Instant Search Hooks. If the `searchable` prop
51
53
  * is "true", the component will also render a search box used to filter the list of facet values.
52
54
  */
53
- const FacetList = ({ useRefinementList, ...props }: Props) => {
55
+ const FacetList = forwardRef(({ useRefinementList, ...props }: Props, ref: HTMLElement) => {
54
56
  const [operator, setOperator] = useState(props.defaultOperator || OPERATOR_OR);
55
57
 
56
58
  const {
@@ -63,7 +65,7 @@ const FacetList = ({ useRefinementList, ...props }: Props) => {
63
65
  toggleShowMore,
64
66
  } = useRefinementList({ ...props, operator });
65
67
 
66
- const ref = useRef();
68
+ const searchRef = useRef();
67
69
  const [query, setQuery] = useState('');
68
70
 
69
71
  /**
@@ -79,7 +81,7 @@ const FacetList = ({ useRefinementList, ...props }: Props) => {
79
81
  searchForItems();
80
82
 
81
83
  // Refocus the input element
82
- const { current: instance } = ref;
84
+ const { current: instance } = searchRef;
83
85
  if (instance) {
84
86
  instance.focus();
85
87
  }
@@ -129,6 +131,7 @@ const FacetList = ({ useRefinementList, ...props }: Props) => {
129
131
  className='facet-list'
130
132
  defaultActive={props.defaultActive}
131
133
  divided={props.divided}
134
+ innerRef={ref}
132
135
  title={props.title}
133
136
  visible={visible}
134
137
  >
@@ -146,7 +149,7 @@ const FacetList = ({ useRefinementList, ...props }: Props) => {
146
149
  onKeyDown={() => Timer.clearSearchTimer()}
147
150
  onKeyUp={() => Timer.setSearchTimer(onSearch)}
148
151
  placeholder={i18n.t('FacetList.labels.search')}
149
- ref={ref}
152
+ ref={searchRef}
150
153
  value={query}
151
154
  />
152
155
  )}
@@ -202,7 +205,7 @@ const FacetList = ({ useRefinementList, ...props }: Props) => {
202
205
  )}
203
206
  </Facet>
204
207
  );
205
- };
208
+ });
206
209
 
207
210
  FacetList.defaultProps = {
208
211
  ...Facet.defaultProps,
@@ -1,7 +1,12 @@
1
1
  // @flow
2
2
 
3
3
  import Slider from 'rc-slider';
4
- import React, { useEffect, useMemo, useState } from 'react';
4
+ import React, {
5
+ forwardRef,
6
+ useEffect,
7
+ useMemo,
8
+ useState
9
+ } from 'react';
5
10
  import { Grid } from 'semantic-ui-react';
6
11
  import Facet, { type Props as FacetProps } from './Facet';
7
12
  import { type RangeSliderProps } from '../types/InstantSearch';
@@ -13,7 +18,7 @@ type Props = FacetProps & RangeSliderProps;
13
18
  /**
14
19
  * This component can be used with the `useRange` hook from Instant Search Hooks.
15
20
  */
16
- const FacetSlider = ({ useRangeSlider, ...props }: Props) => {
21
+ const FacetSlider = forwardRef(({ useRangeSlider, ...props }: Props, ref: HTMLElement) => {
17
22
  const {
18
23
  start,
19
24
  range,
@@ -42,6 +47,7 @@ const FacetSlider = ({ useRangeSlider, ...props }: Props) => {
42
47
  <Facet
43
48
  defaultActive={props.defaultActive}
44
49
  divided={props.divided}
50
+ innerRef={ref}
45
51
  title={props.title}
46
52
  visible={visible}
47
53
  >
@@ -77,7 +83,7 @@ const FacetSlider = ({ useRangeSlider, ...props }: Props) => {
77
83
  </div>
78
84
  </Facet>
79
85
  );
80
- };
86
+ });
81
87
 
82
88
  FacetSlider.defaultProps = Facet.defaultProps;
83
89
 
@@ -1,6 +1,6 @@
1
1
  // @flow
2
2
 
3
- import React, { useMemo } from 'react';
3
+ import React, { forwardRef, useMemo } from 'react';
4
4
  import { Checkbox, Label } from 'semantic-ui-react';
5
5
  import Facet, { type Props as FacetProps } from './Facet';
6
6
  import { type ToggleRefinementProps } from '../types/InstantSearch';
@@ -10,7 +10,7 @@ type Props = FacetProps & ToggleRefinementProps;
10
10
  /**
11
11
  * This component is used with the `useToggleRefinement` hook from Instant Search Hooks.
12
12
  */
13
- const FacetToggle = ({ useToggleRefinement, ...props }: Props) => {
13
+ const FacetToggle = forwardRef(({ useToggleRefinement, ...props }: Props, ref: HTMLElement) => {
14
14
  const {
15
15
  value: {
16
16
  isRefined,
@@ -30,6 +30,7 @@ const FacetToggle = ({ useToggleRefinement, ...props }: Props) => {
30
30
  <Facet
31
31
  defaultActive={props.defaultActive}
32
32
  divided={props.divided}
33
+ innerRef={ref}
33
34
  title={props.title}
34
35
  visible={visible}
35
36
  >
@@ -49,7 +50,7 @@ const FacetToggle = ({ useToggleRefinement, ...props }: Props) => {
49
50
  />
50
51
  </Facet>
51
52
  );
52
- };
53
+ });
53
54
 
54
55
  FacetToggle.defaultProps = Facet.defaultProps;
55
56
 
@@ -1,6 +1,11 @@
1
1
  // @flow
2
2
 
3
- import React, { useState, type Node, useMemo } from 'react';
3
+ import React, {
4
+ useImperativeHandle,
5
+ useMemo,
6
+ useState,
7
+ type Node
8
+ } from 'react';
4
9
  import {
5
10
  Accordion,
6
11
  Divider,
@@ -30,6 +35,13 @@ type Props = {
30
35
  */
31
36
  divided?: boolean,
32
37
 
38
+ /**
39
+ * React ref element to apply to the expand/collapse functions.
40
+ */
41
+ innerRef?: {
42
+ current: ?HTMLElement
43
+ },
44
+
33
45
  /**
34
46
  * Facet title to display at the top.
35
47
  */
@@ -66,6 +78,14 @@ const Facet = (props: Props) => {
66
78
  return classNames.join(' ');
67
79
  }, [props.className, props.visible]);
68
80
 
81
+ /**
82
+ * Expose collapse/expand functions on the ref object to allow parent components to imperatively open/close.
83
+ */
84
+ useImperativeHandle(props.innerRef, () => ({
85
+ collapse: () => setActive(false),
86
+ expand: () => setActive(true)
87
+ }));
88
+
69
89
  return (
70
90
  <>
71
91
  <Accordion
@@ -2,8 +2,10 @@
2
2
 
3
3
  import { Timer } from '@performant-software/shared-components';
4
4
  import React, {
5
+ forwardRef,
5
6
  useCallback,
6
- useEffect, useMemo,
7
+ useEffect,
8
+ useMemo,
7
9
  useRef,
8
10
  useState
9
11
  } from 'react';
@@ -50,7 +52,7 @@ const OPERATOR_AND = 'and';
50
52
  * This component is used with the `useRefinementList` hook from Instant Search Hooks. If the `searchable` prop
51
53
  * is "true", the component will also render a search box used to filter the list of facet values.
52
54
  */
53
- const FacetList = ({ useRefinementList, ...props }: Props) => {
55
+ const FacetList = forwardRef(({ useRefinementList, ...props }: Props, ref: HTMLElement) => {
54
56
  const [operator, setOperator] = useState(props.defaultOperator || OPERATOR_OR);
55
57
 
56
58
  const {
@@ -63,7 +65,7 @@ const FacetList = ({ useRefinementList, ...props }: Props) => {
63
65
  toggleShowMore,
64
66
  } = useRefinementList({ ...props, operator });
65
67
 
66
- const ref = useRef();
68
+ const searchRef = useRef();
67
69
  const [query, setQuery] = useState('');
68
70
 
69
71
  /**
@@ -79,7 +81,7 @@ const FacetList = ({ useRefinementList, ...props }: Props) => {
79
81
  searchForItems();
80
82
 
81
83
  // Refocus the input element
82
- const { current: instance } = ref;
84
+ const { current: instance } = searchRef;
83
85
  if (instance) {
84
86
  instance.focus();
85
87
  }
@@ -129,6 +131,7 @@ const FacetList = ({ useRefinementList, ...props }: Props) => {
129
131
  className='facet-list'
130
132
  defaultActive={props.defaultActive}
131
133
  divided={props.divided}
134
+ innerRef={ref}
132
135
  title={props.title}
133
136
  visible={visible}
134
137
  >
@@ -146,7 +149,7 @@ const FacetList = ({ useRefinementList, ...props }: Props) => {
146
149
  onKeyDown={() => Timer.clearSearchTimer()}
147
150
  onKeyUp={() => Timer.setSearchTimer(onSearch)}
148
151
  placeholder={i18n.t('FacetList.labels.search')}
149
- ref={ref}
152
+ ref={searchRef}
150
153
  value={query}
151
154
  />
152
155
  )}
@@ -202,7 +205,7 @@ const FacetList = ({ useRefinementList, ...props }: Props) => {
202
205
  )}
203
206
  </Facet>
204
207
  );
205
- };
208
+ });
206
209
 
207
210
  FacetList.defaultProps = {
208
211
  ...Facet.defaultProps,
@@ -1,7 +1,12 @@
1
1
  // @flow
2
2
 
3
3
  import Slider from 'rc-slider';
4
- import React, { useEffect, useMemo, useState } from 'react';
4
+ import React, {
5
+ forwardRef,
6
+ useEffect,
7
+ useMemo,
8
+ useState
9
+ } from 'react';
5
10
  import { Grid } from 'semantic-ui-react';
6
11
  import Facet, { type Props as FacetProps } from './Facet';
7
12
  import { type RangeSliderProps } from '../types/InstantSearch';
@@ -13,7 +18,7 @@ type Props = FacetProps & RangeSliderProps;
13
18
  /**
14
19
  * This component can be used with the `useRange` hook from Instant Search Hooks.
15
20
  */
16
- const FacetSlider = ({ useRangeSlider, ...props }: Props) => {
21
+ const FacetSlider = forwardRef(({ useRangeSlider, ...props }: Props, ref: HTMLElement) => {
17
22
  const {
18
23
  start,
19
24
  range,
@@ -42,6 +47,7 @@ const FacetSlider = ({ useRangeSlider, ...props }: Props) => {
42
47
  <Facet
43
48
  defaultActive={props.defaultActive}
44
49
  divided={props.divided}
50
+ innerRef={ref}
45
51
  title={props.title}
46
52
  visible={visible}
47
53
  >
@@ -77,7 +83,7 @@ const FacetSlider = ({ useRangeSlider, ...props }: Props) => {
77
83
  </div>
78
84
  </Facet>
79
85
  );
80
- };
86
+ });
81
87
 
82
88
  FacetSlider.defaultProps = Facet.defaultProps;
83
89
 
@@ -1,6 +1,6 @@
1
1
  // @flow
2
2
 
3
- import React, { useMemo } from 'react';
3
+ import React, { forwardRef, useMemo } from 'react';
4
4
  import { Checkbox, Label } from 'semantic-ui-react';
5
5
  import Facet, { type Props as FacetProps } from './Facet';
6
6
  import { type ToggleRefinementProps } from '../types/InstantSearch';
@@ -10,7 +10,7 @@ type Props = FacetProps & ToggleRefinementProps;
10
10
  /**
11
11
  * This component is used with the `useToggleRefinement` hook from Instant Search Hooks.
12
12
  */
13
- const FacetToggle = ({ useToggleRefinement, ...props }: Props) => {
13
+ const FacetToggle = forwardRef(({ useToggleRefinement, ...props }: Props, ref: HTMLElement) => {
14
14
  const {
15
15
  value: {
16
16
  isRefined,
@@ -30,6 +30,7 @@ const FacetToggle = ({ useToggleRefinement, ...props }: Props) => {
30
30
  <Facet
31
31
  defaultActive={props.defaultActive}
32
32
  divided={props.divided}
33
+ innerRef={ref}
33
34
  title={props.title}
34
35
  visible={visible}
35
36
  >
@@ -49,7 +50,7 @@ const FacetToggle = ({ useToggleRefinement, ...props }: Props) => {
49
50
  />
50
51
  </Facet>
51
52
  );
52
- };
53
+ });
53
54
 
54
55
  FacetToggle.defaultProps = Facet.defaultProps;
55
56