@moda/om 15.11.3 → 15.11.4

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": "@moda/om",
3
- "version": "15.11.3",
3
+ "version": "15.11.4",
4
4
  "description": "Moda Operandi design system",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -27,7 +27,7 @@ export const Popover: React.FC<PopoverProps> = ({
27
27
  className,
28
28
  children,
29
29
  content,
30
- open = false,
30
+ open,
31
31
  anchor = 'topLeft',
32
32
  zIndex,
33
33
  autoPreview = false,
@@ -52,21 +52,30 @@ export const Popover: React.FC<PopoverProps> = ({
52
52
 
53
53
  const timeout = useRef<ReturnType<typeof setTimeout> | null>(null);
54
54
 
55
+ const handleOpen = useCallback(() => {
56
+ if (smoothTransitioning) setMode(Mode.Opening);
57
+
58
+ if (!smoothTransitioning) setMode(Mode.Open);
59
+ }, [smoothTransitioning]);
60
+
61
+ const handleClose = useCallback(() => {
62
+ if (smoothTransitioning) setMode(Mode.Closing);
63
+
64
+ if (!smoothTransitioning) setMode(Mode.Closed);
65
+ }, [smoothTransitioning]);
66
+
55
67
  const handleMouseEnter = useCallback(() => {
56
68
  if (!open) {
57
69
  timeout.current && clearTimeout(timeout.current);
58
- setMode(smoothTransitioning ? Mode.Opening : Mode.Open);
70
+ handleOpen();
59
71
  }
60
- }, [open, smoothTransitioning]);
72
+ }, [handleOpen, open]);
61
73
 
62
74
  const handleMouseLeave = useCallback(() => {
63
75
  if (open) return;
64
76
 
65
- timeout.current = setTimeout(
66
- () => setMode(smoothTransitioning ? Mode.Closing : Mode.Closed),
67
- POPOVER_MOUSEOUT_DELAY_MS
68
- );
69
- }, [open, smoothTransitioning]);
77
+ timeout.current = setTimeout(handleClose, POPOVER_MOUSEOUT_DELAY_MS);
78
+ }, [handleClose, open]);
70
79
 
71
80
  useEffect(() => {
72
81
  if (mode !== Mode.Closing) return;
@@ -95,31 +104,16 @@ export const Popover: React.FC<PopoverProps> = ({
95
104
  useEffect(() => {
96
105
  if (mode !== Mode.AutoOpen) return;
97
106
 
98
- const stayingTimeout = setTimeout(
99
- () => setMode(smoothTransitioning ? Mode.Closing : Mode.Closed),
100
- 5000
101
- );
107
+ const stayingTimeout = setTimeout(handleClose, 5000);
102
108
 
103
109
  return () => clearTimeout(stayingTimeout);
104
- }, [mode, smoothTransitioning]);
110
+ }, [handleClose, mode, smoothTransitioning]);
105
111
 
106
112
  useEffect(() => {
107
- if (open && smoothTransitioning) {
108
- setMode(Mode.Opening);
109
- }
113
+ if (open === undefined) return;
110
114
 
111
- if (open && !smoothTransitioning) {
112
- setMode(Mode.Open);
113
- }
114
-
115
- if (!open && smoothTransitioning) {
116
- setMode(Mode.Closing);
117
- }
118
-
119
- if (!open && !smoothTransitioning) {
120
- setMode(Mode.Closed);
121
- }
122
- }, [open, smoothTransitioning]);
115
+ open ? handleOpen() : handleClose();
116
+ }, [handleClose, handleOpen, open]);
123
117
 
124
118
  const isOpen =
125
119
  mode === Mode.AutoOpen || mode === Mode.Opening || mode === Mode.Open || mode === Mode.Closing;