@erxes/ui 3.2.22-1 → 3.2.25-1

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": "@erxes/ui",
3
- "version": "3.2.22-1",
3
+ "version": "3.2.25-1",
4
4
  "description": "erxes design system: UI primitives, business modules, hooks and shared frontend state",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": {
@@ -32,6 +32,14 @@ const findSidebarPanelSlot = (panel: HTMLElement | null) => {
32
32
  return null;
33
33
  };
34
34
 
35
+ const SidebarPanelInnerTriggerHiddenContext = React.createContext(false);
36
+
37
+ const isSlotAbovePanel = (slot: HTMLElement, panel: HTMLElement | null) =>
38
+ Boolean(
39
+ panel &&
40
+ slot.compareDocumentPosition(panel) & Node.DOCUMENT_POSITION_FOLLOWING,
41
+ );
42
+
35
43
  const useSidebarPanelSlot = (
36
44
  panelRef: React.RefObject<HTMLDivElement | null>,
37
45
  open: boolean,
@@ -40,13 +48,9 @@ const useSidebarPanelSlot = (
40
48
  const [claimed, setClaimed] = React.useState(false);
41
49
 
42
50
  React.useLayoutEffect(() => {
43
- if (open) {
44
- return;
45
- }
46
-
47
51
  const found = findSidebarPanelSlot(panelRef.current);
48
52
 
49
- if (!found) {
53
+ if (!found || (open && !isSlotAbovePanel(found, panelRef.current))) {
50
54
  setSlot(null);
51
55
  setClaimed(false);
52
56
  return;
@@ -68,19 +72,24 @@ const useSidebarPanelSlot = (
68
72
  };
69
73
  }, [open, panelRef]);
70
74
 
71
- return { slot: open ? null : slot, claimed };
75
+ return { slot, claimed };
72
76
  };
73
77
 
74
78
  export const SidebarPanelTrigger = React.forwardRef<
75
79
  React.ElementRef<typeof Button>,
76
80
  React.ComponentProps<typeof Button>
77
81
  >(({ className, onClick, ...props }, ref) => {
82
+ const hidden = React.useContext(SidebarPanelInnerTriggerHiddenContext);
78
83
  const [open, setOpen] = useAtom(sidebarPanelOpenState);
79
84
  const { t } = useTranslation('common', { keyPrefix: 'navigation' });
80
85
  const toggleLabel = open
81
86
  ? t('collapse-sidebar', 'Collapse sidebar')
82
87
  : t('expand-sidebar', 'Expand sidebar');
83
88
 
89
+ if (hidden) {
90
+ return null;
91
+ }
92
+
84
93
  return (
85
94
  <Button
86
95
  ref={ref}
@@ -116,6 +125,7 @@ export const SidebarPanel = React.forwardRef<
116
125
  const open = useAtomValue(sidebarPanelOpenState);
117
126
  const [panelRef, setRefs] = useComposedRef(ref);
118
127
  const { slot, claimed } = useSidebarPanelSlot(panelRef, open);
128
+ const triggerInSlot = Boolean(slot && claimed);
119
129
 
120
130
  return (
121
131
  <div
@@ -138,28 +148,27 @@ export const SidebarPanel = React.forwardRef<
138
148
  </Portal.Root>
139
149
  )}
140
150
  {!open && !slot && (
141
- <div className="absolute top-2 left-2 z-20">
151
+ <div className="absolute top-2.5 left-2 z-20">
142
152
  <SidebarPanelTrigger className="size-7 border bg-background shadow-xs" />
143
153
  </div>
144
154
  )}
145
- {open && label && (
146
- <div className="flex shrink-0 items-center gap-1 pt-3 pr-3 pl-4">
147
- <span className="min-w-0 flex-1 truncate px-2 font-mono text-xs font-semibold uppercase text-accent-foreground">
148
- {label}
149
- </span>
150
- {actions}
151
- <SidebarPanelTrigger />
152
- </div>
153
- )}
154
- <div
155
- hidden={!open}
156
- className={cn(
157
- 'flex min-h-0 flex-1 flex-col overflow-y-auto',
158
- label && '[&>[data-sidebar=group]:first-child]:pt-0',
155
+ <SidebarPanelInnerTriggerHiddenContext.Provider value={triggerInSlot}>
156
+ {open && label && (
157
+ <div className="flex h-12 shrink-0 items-center gap-1 px-2">
158
+ <span className="min-w-0 flex-1 truncate px-2 text-sm font-medium">
159
+ {label}
160
+ </span>
161
+ {actions}
162
+ <SidebarPanelTrigger className="size-8" />
163
+ </div>
159
164
  )}
160
- >
161
- {children}
162
- </div>
165
+ <div
166
+ hidden={!open}
167
+ className="flex min-h-0 flex-1 flex-col overflow-y-auto"
168
+ >
169
+ {children}
170
+ </div>
171
+ </SidebarPanelInnerTriggerHiddenContext.Provider>
163
172
  </div>
164
173
  );
165
174
  });