@indico-data/design-system 2.34.1 → 2.34.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.
- package/lib/index.esm.js +825 -87
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +825 -87
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/floatUI/FloatUI.test.tsx +1 -19
- package/src/components/floatUI/FloatUI.tsx +17 -14
- package/src/components/forms/checkbox/Checkbox.tsx +1 -0
- package/lib/src/hooks/useClickOutside.d.ts +0 -2
- package/src/hooks/useClickOutside.tsx +0 -22
package/package.json
CHANGED
|
@@ -27,24 +27,6 @@ describe('FloatUI Component', () => {
|
|
|
27
27
|
expect(screen.getByText('FloatUI Content')).toBeInTheDocument();
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
-
it('closes the FloatUI when clicked outside in uncontrolled mode', () => {
|
|
31
|
-
render(
|
|
32
|
-
<div>
|
|
33
|
-
<div data-testid="outside">Outside Element</div>
|
|
34
|
-
<FloatUI ariaLabel="Example FloatUI">
|
|
35
|
-
<Button ariaLabel="Toggle FloatUI">Toggle</Button>
|
|
36
|
-
<div>FloatUI Content</div>
|
|
37
|
-
</FloatUI>
|
|
38
|
-
</div>,
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
// Open the FloatUI
|
|
42
|
-
fireEvent.click(screen.getByText('Toggle'));
|
|
43
|
-
|
|
44
|
-
fireEvent.mouseDown(screen.getByTestId('outside'));
|
|
45
|
-
expect(screen.queryByText('FloatUI Content')).not.toBeInTheDocument();
|
|
46
|
-
});
|
|
47
|
-
|
|
48
30
|
it('renders the correct children inside the FloatUI when open in uncontrolled mode', () => {
|
|
49
31
|
render(
|
|
50
32
|
<FloatUI ariaLabel="Example FloatUI">
|
|
@@ -124,6 +106,6 @@ describe('FloatUI Component', () => {
|
|
|
124
106
|
);
|
|
125
107
|
|
|
126
108
|
fireEvent.click(screen.getByText('Toggle'));
|
|
127
|
-
expect(setIsOpen).toHaveBeenCalledWith(true);
|
|
109
|
+
expect(setIsOpen).toHaveBeenCalledWith(true, expect.any(Object), 'click');
|
|
128
110
|
});
|
|
129
111
|
});
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useRef, isValidElement, useState } from 'react';
|
|
2
2
|
import {
|
|
3
|
+
FloatingPortal,
|
|
4
|
+
useClick,
|
|
3
5
|
useFloating,
|
|
6
|
+
useInteractions,
|
|
4
7
|
UseFloatingOptions,
|
|
5
8
|
offset,
|
|
6
9
|
flip,
|
|
7
10
|
shift,
|
|
8
11
|
Placement,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import { useClickOutside } from '@/hooks/useClickOutside';
|
|
12
|
+
useDismiss,
|
|
13
|
+
} from '@floating-ui/react';
|
|
12
14
|
import { FloatUIProps } from './types';
|
|
13
15
|
|
|
14
16
|
const defaultOptions: UseFloatingOptions = {
|
|
@@ -48,24 +50,25 @@ export function FloatUI({
|
|
|
48
50
|
throw new Error('Both children of FloatUI must be valid React elements.');
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
const {
|
|
53
|
+
const { refs, floatingStyles, context } = useFloating({
|
|
54
|
+
...floatingOptions,
|
|
55
|
+
open: isOpen,
|
|
56
|
+
onOpenChange: setIsOpen,
|
|
52
57
|
elements: {
|
|
53
58
|
reference: referenceElementRef.current,
|
|
54
59
|
},
|
|
55
|
-
...floatingOptions,
|
|
56
60
|
});
|
|
57
61
|
|
|
58
|
-
|
|
62
|
+
const click = useClick(context);
|
|
63
|
+
const dismiss = useDismiss(context);
|
|
64
|
+
|
|
65
|
+
const { getReferenceProps, getFloatingProps } = useInteractions([click, dismiss]);
|
|
59
66
|
|
|
60
67
|
const tooltipContent = (
|
|
61
68
|
<div
|
|
62
|
-
// Used to position the floating element relative to the reference element
|
|
63
69
|
ref={refs.setFloating}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
top: y ?? 0,
|
|
67
|
-
left: x ?? 0,
|
|
68
|
-
}}
|
|
70
|
+
{...getFloatingProps()}
|
|
71
|
+
style={floatingStyles}
|
|
69
72
|
role="dialog"
|
|
70
73
|
aria-label={ariaLabel}
|
|
71
74
|
className="floatui-container"
|
|
@@ -78,7 +81,7 @@ export function FloatUI({
|
|
|
78
81
|
|
|
79
82
|
return (
|
|
80
83
|
<>
|
|
81
|
-
<div ref={
|
|
84
|
+
<div ref={refs.setReference} {...getReferenceProps()}>
|
|
82
85
|
{trigger}
|
|
83
86
|
</div>
|
|
84
87
|
{isOpen &&
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import React, { useEffect } from 'react';
|
|
2
|
-
|
|
3
|
-
export const useClickOutside = (
|
|
4
|
-
ref: React.MutableRefObject<HTMLElement>,
|
|
5
|
-
handler: (e: MouseEvent | TouchEvent) => void,
|
|
6
|
-
) => {
|
|
7
|
-
useEffect(() => {
|
|
8
|
-
const listener = (e: MouseEvent | TouchEvent) => {
|
|
9
|
-
if (!ref.current || ref.current.contains(e.target as Node)) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
handler(e);
|
|
13
|
-
};
|
|
14
|
-
document.addEventListener('mousedown', listener);
|
|
15
|
-
document.addEventListener('touchstart', listener);
|
|
16
|
-
|
|
17
|
-
return () => {
|
|
18
|
-
document.removeEventListener('mousedown', listener);
|
|
19
|
-
document.removeEventListener('touchstart', listener);
|
|
20
|
-
};
|
|
21
|
-
}, [ref, handler]);
|
|
22
|
-
};
|