@norges-domstoler/dds-components 10.0.1 → 10.0.2
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/cjs/components/Typography/Paragraph/Paragraph.stories.d.ts +1 -0
- package/dist/cjs/index.js +45 -8
- package/dist/components/Search/Search.js +1 -1
- package/dist/components/Search/SearchAutocompleteWrapper.js +5 -2
- package/dist/components/Tooltip/Tooltip.js +40 -6
- package/dist/components/Typography/Paragraph/Paragraph.stories.d.ts +1 -0
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -5639,7 +5639,7 @@ var Search$1 = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
5639
5639
|
type: 'search',
|
|
5640
5640
|
id: uniqueId,
|
|
5641
5641
|
'aria-describedby': spaceSeparatedIdListGenerator([tip ? tipId : undefined, context.suggestions ? suggestionsDescriptionId : undefined, ariaDescribedby]),
|
|
5642
|
-
value: context.inputValue !== undefined ? context.inputValue : value
|
|
5642
|
+
value: context.inputValue !== undefined ? context.inputValue : value,
|
|
5643
5643
|
onChange: handleChange,
|
|
5644
5644
|
autoComplete: 'off'
|
|
5645
5645
|
});
|
|
@@ -5733,7 +5733,7 @@ var SearchAutocompleteWrapper = function SearchAutocompleteWrapper(props) {
|
|
|
5733
5733
|
};
|
|
5734
5734
|
var handleChange = function handleChange(e) {
|
|
5735
5735
|
var query = e.target.value;
|
|
5736
|
-
|
|
5736
|
+
handleSetInputValue(query);
|
|
5737
5737
|
var finalSuggestions = [];
|
|
5738
5738
|
if (query.length >= queryLength) {
|
|
5739
5739
|
if (data) {
|
|
@@ -5767,10 +5767,13 @@ var SearchAutocompleteWrapper = function SearchAutocompleteWrapper(props) {
|
|
|
5767
5767
|
};
|
|
5768
5768
|
var handleSuggestionClick = function handleSuggestionClick(e) {
|
|
5769
5769
|
setSuggestions([]);
|
|
5770
|
-
|
|
5770
|
+
handleSetInputValue(e.target.innerText);
|
|
5771
5771
|
onSuggestionSelection && onSuggestionSelection();
|
|
5772
5772
|
closeSuggestions();
|
|
5773
5773
|
};
|
|
5774
|
+
var handleSetInputValue = function handleSetInputValue(value) {
|
|
5775
|
+
setInputValue(value || '');
|
|
5776
|
+
};
|
|
5774
5777
|
var inputRef = React.useRef(null);
|
|
5775
5778
|
var suggestionsRef = React.useRef(null);
|
|
5776
5779
|
useOnClickOutside([inputRef.current, suggestionsRef.current], function () {
|
|
@@ -7757,17 +7760,51 @@ var Tooltip = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
7757
7760
|
_useState2 = _slicedToArray(_useState, 2),
|
|
7758
7761
|
open = _useState2[0],
|
|
7759
7762
|
setOpen = _useState2[1];
|
|
7760
|
-
var _useState3 = React.useState(
|
|
7763
|
+
var _useState3 = React.useState(false),
|
|
7761
7764
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
7762
|
-
|
|
7763
|
-
|
|
7765
|
+
inView = _useState4[0],
|
|
7766
|
+
setInView = _useState4[1];
|
|
7767
|
+
var _useState5 = React.useState(null),
|
|
7768
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
7769
|
+
arrowElement = _useState6[0],
|
|
7770
|
+
setArrowElement = _useState6[1];
|
|
7764
7771
|
var _useFloatPosition = useFloatPosition(arrowElement, {
|
|
7765
7772
|
placement: placement
|
|
7766
7773
|
}),
|
|
7767
7774
|
reference = _useFloatPosition.reference,
|
|
7768
7775
|
floating = _useFloatPosition.floating,
|
|
7769
7776
|
styles = _useFloatPosition.styles;
|
|
7770
|
-
var
|
|
7777
|
+
var tooltipRef = React.useRef(null);
|
|
7778
|
+
var combinedRef = useCombinedRef(ref, floating, tooltipRef);
|
|
7779
|
+
var closeWhenNotInView = function closeWhenNotInView(entries) {
|
|
7780
|
+
var _entries = _slicedToArray(entries, 1),
|
|
7781
|
+
entry = _entries[0];
|
|
7782
|
+
entry.isIntersecting ? setInView(true) : setInView(false);
|
|
7783
|
+
};
|
|
7784
|
+
React.useEffect(function () {
|
|
7785
|
+
var options = {
|
|
7786
|
+
root: null,
|
|
7787
|
+
rootMargin: '0px'
|
|
7788
|
+
};
|
|
7789
|
+
var ref = tooltipRef.current;
|
|
7790
|
+
var observer = new IntersectionObserver(closeWhenNotInView, options);
|
|
7791
|
+
if (ref) observer.observe(ref);
|
|
7792
|
+
return function () {
|
|
7793
|
+
if (ref) observer.unobserve(ref);
|
|
7794
|
+
};
|
|
7795
|
+
}, [tooltipRef]);
|
|
7796
|
+
React.useEffect(function () {
|
|
7797
|
+
if (tooltipRef.current) {
|
|
7798
|
+
window.addEventListener('scroll', function () {
|
|
7799
|
+
closeTooltip();
|
|
7800
|
+
});
|
|
7801
|
+
}
|
|
7802
|
+
return function () {
|
|
7803
|
+
if (tooltipRef.current) {
|
|
7804
|
+
window.removeEventListener('scroll', function () {});
|
|
7805
|
+
}
|
|
7806
|
+
};
|
|
7807
|
+
}, []);
|
|
7771
7808
|
var timer;
|
|
7772
7809
|
React.useEffect(function () {
|
|
7773
7810
|
return function () {
|
|
@@ -7806,7 +7843,7 @@ var Tooltip = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
7806
7843
|
ref: combinedRef,
|
|
7807
7844
|
role: 'tooltip',
|
|
7808
7845
|
'aria-hidden': !open,
|
|
7809
|
-
open: open,
|
|
7846
|
+
open: open && inView,
|
|
7810
7847
|
style: Object.assign({}, styles.floating)
|
|
7811
7848
|
};
|
|
7812
7849
|
var arrowWrapperProps = {
|
|
@@ -107,7 +107,7 @@ var Search = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
|
107
107
|
type: 'search',
|
|
108
108
|
id: uniqueId,
|
|
109
109
|
'aria-describedby': spaceSeparatedIdListGenerator([tip ? tipId : undefined, context.suggestions ? suggestionsDescriptionId : undefined, ariaDescribedby]),
|
|
110
|
-
value: context.inputValue !== undefined ? context.inputValue : value
|
|
110
|
+
value: context.inputValue !== undefined ? context.inputValue : value,
|
|
111
111
|
onChange: handleChange,
|
|
112
112
|
autoComplete: 'off'
|
|
113
113
|
});
|
|
@@ -48,7 +48,7 @@ var SearchAutocompleteWrapper = function SearchAutocompleteWrapper(props) {
|
|
|
48
48
|
};
|
|
49
49
|
var handleChange = function handleChange(e) {
|
|
50
50
|
var query = e.target.value;
|
|
51
|
-
|
|
51
|
+
handleSetInputValue(query);
|
|
52
52
|
var finalSuggestions = [];
|
|
53
53
|
if (query.length >= queryLength) {
|
|
54
54
|
if (data) {
|
|
@@ -82,10 +82,13 @@ var SearchAutocompleteWrapper = function SearchAutocompleteWrapper(props) {
|
|
|
82
82
|
};
|
|
83
83
|
var handleSuggestionClick = function handleSuggestionClick(e) {
|
|
84
84
|
setSuggestions([]);
|
|
85
|
-
|
|
85
|
+
handleSetInputValue(e.target.innerText);
|
|
86
86
|
onSuggestionSelection && onSuggestionSelection();
|
|
87
87
|
closeSuggestions();
|
|
88
88
|
};
|
|
89
|
+
var handleSetInputValue = function handleSetInputValue(value) {
|
|
90
|
+
setInputValue(value || '');
|
|
91
|
+
};
|
|
89
92
|
var inputRef = useRef(null);
|
|
90
93
|
var suggestionsRef = useRef(null);
|
|
91
94
|
useOnClickOutside([inputRef.current, suggestionsRef.current], function () {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { slicedToArray as _slicedToArray } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
2
2
|
import { __rest } from 'tslib';
|
|
3
3
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
4
|
-
import { forwardRef, useId, useState, useEffect, Children, isValidElement, cloneElement } from 'react';
|
|
4
|
+
import { forwardRef, useId, useState, useRef, useEffect, Children, isValidElement, cloneElement } from 'react';
|
|
5
5
|
import { useCombinedRef } from '../../hooks/useCombinedRefs.js';
|
|
6
6
|
import { useOnKeyDown } from '../../hooks/useOnKeyDown.js';
|
|
7
7
|
import { useFloatPosition } from '../../hooks/useFloatPosition.js';
|
|
@@ -34,17 +34,51 @@ var Tooltip = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
34
34
|
_useState2 = _slicedToArray(_useState, 2),
|
|
35
35
|
open = _useState2[0],
|
|
36
36
|
setOpen = _useState2[1];
|
|
37
|
-
var _useState3 = useState(
|
|
37
|
+
var _useState3 = useState(false),
|
|
38
38
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
inView = _useState4[0],
|
|
40
|
+
setInView = _useState4[1];
|
|
41
|
+
var _useState5 = useState(null),
|
|
42
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
43
|
+
arrowElement = _useState6[0],
|
|
44
|
+
setArrowElement = _useState6[1];
|
|
41
45
|
var _useFloatPosition = useFloatPosition(arrowElement, {
|
|
42
46
|
placement: placement
|
|
43
47
|
}),
|
|
44
48
|
reference = _useFloatPosition.reference,
|
|
45
49
|
floating = _useFloatPosition.floating,
|
|
46
50
|
styles = _useFloatPosition.styles;
|
|
47
|
-
var
|
|
51
|
+
var tooltipRef = useRef(null);
|
|
52
|
+
var combinedRef = useCombinedRef(ref, floating, tooltipRef);
|
|
53
|
+
var closeWhenNotInView = function closeWhenNotInView(entries) {
|
|
54
|
+
var _entries = _slicedToArray(entries, 1),
|
|
55
|
+
entry = _entries[0];
|
|
56
|
+
entry.isIntersecting ? setInView(true) : setInView(false);
|
|
57
|
+
};
|
|
58
|
+
useEffect(function () {
|
|
59
|
+
var options = {
|
|
60
|
+
root: null,
|
|
61
|
+
rootMargin: '0px'
|
|
62
|
+
};
|
|
63
|
+
var ref = tooltipRef.current;
|
|
64
|
+
var observer = new IntersectionObserver(closeWhenNotInView, options);
|
|
65
|
+
if (ref) observer.observe(ref);
|
|
66
|
+
return function () {
|
|
67
|
+
if (ref) observer.unobserve(ref);
|
|
68
|
+
};
|
|
69
|
+
}, [tooltipRef]);
|
|
70
|
+
useEffect(function () {
|
|
71
|
+
if (tooltipRef.current) {
|
|
72
|
+
window.addEventListener('scroll', function () {
|
|
73
|
+
closeTooltip();
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return function () {
|
|
77
|
+
if (tooltipRef.current) {
|
|
78
|
+
window.removeEventListener('scroll', function () {});
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}, []);
|
|
48
82
|
var timer;
|
|
49
83
|
useEffect(function () {
|
|
50
84
|
return function () {
|
|
@@ -83,7 +117,7 @@ var Tooltip = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
83
117
|
ref: combinedRef,
|
|
84
118
|
role: 'tooltip',
|
|
85
119
|
'aria-hidden': !open,
|
|
86
|
-
open: open,
|
|
120
|
+
open: open && inView,
|
|
87
121
|
style: Object.assign({}, styles.floating)
|
|
88
122
|
};
|
|
89
123
|
var arrowWrapperProps = {
|