@noya-app/noya-designsystem 0.1.18 → 0.1.20

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": "@noya-app/noya-designsystem",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -36,7 +36,7 @@
36
36
  "@radix-ui/react-utils": "^0.0.5",
37
37
  "immer": "9.0.5",
38
38
  "kiwi.js": "^1.1.3",
39
- "react-resizable-panels": "2.0.16",
39
+ "react-resizable-panels": "2.0.22",
40
40
  "react-virtualized": "^9.22.3",
41
41
  "react-window": "^1.8.8",
42
42
  "vscode-fuzzy-scorer": "^0.0.4"
@@ -1,4 +1,4 @@
1
- import { Stack, useDesignSystemTheme } from "@noya-app/noya-designsystem";
1
+ import { useDesignSystemTheme } from "@noya-app/noya-designsystem";
2
2
  import { useKeyboardShortcuts } from "@noya-app/noya-keymap";
3
3
  import React, { forwardRef, useImperativeHandle, useRef } from "react";
4
4
  import {
@@ -26,9 +26,24 @@ interface Props {
26
26
  hasRightSidebar?: boolean;
27
27
  hasLeftSidebar?: boolean;
28
28
  onChangeLayoutState?: (layoutState: PanelLayoutState) => void;
29
- leftSidebarInitialSize?: number;
30
- rightSidebarInitialSize?: number;
31
29
  leftSidebarCanResize?: boolean;
30
+ id?: string;
31
+ className?: string;
32
+ style?: React.CSSProperties;
33
+
34
+ /**
35
+ * Accepts a number (px) or % string (e.g. "50%").
36
+ * Use % to avoid flicker server-rendering.
37
+ */
38
+ leftSidebarInitialSize?: number | string;
39
+ leftSidebarMinSize?: number | string;
40
+
41
+ /**
42
+ * Accepts a number (px) or % string (e.g. "50%").
43
+ * Use % to avoid flicker server-rendering.
44
+ */
45
+ rightSidebarInitialSize?: number | string;
46
+ rightSidebarMinSize?: number | string;
32
47
  }
33
48
 
34
49
  export type IWorkspaceLayout = {
@@ -50,15 +65,32 @@ export const WorkspaceLayout = forwardRef(function WorkspaceLayout(
50
65
  onChangeLayoutState,
51
66
  leftSidebarInitialSize = 280,
52
67
  rightSidebarInitialSize = 400,
68
+ leftSidebarMinSize,
69
+ rightSidebarMinSize,
53
70
  leftSidebarCanResize = false,
71
+ id,
72
+ className,
73
+ style,
54
74
  }: Props,
55
75
  forwardedRef: React.ForwardedRef<IWorkspaceLayout>
56
76
  ) {
57
77
  const windowSize = useWindowSize();
58
- const leftSidebarPercentage =
59
- (leftSidebarInitialSize / windowSize.width) * 100;
60
- const rightSidebarPercentage =
61
- (rightSidebarInitialSize / windowSize.width) * 100;
78
+ function getPercentage(size: number | string) {
79
+ return typeof size === "string"
80
+ ? parseFloat(size)
81
+ : (size / windowSize.width) * 100;
82
+ }
83
+ const leftSidebarPercentage = getPercentage(leftSidebarInitialSize);
84
+ const rightSidebarPercentage = getPercentage(rightSidebarInitialSize);
85
+ const leftSidebarMinPercentage =
86
+ leftSidebarMinSize !== undefined
87
+ ? getPercentage(leftSidebarMinSize)
88
+ : undefined;
89
+ const rightSidebarMinPercentage =
90
+ rightSidebarMinSize !== undefined
91
+ ? getPercentage(rightSidebarMinSize)
92
+ : undefined;
93
+
62
94
  const panelGroupRef = useRef<ImperativePanelGroupHandle>(null);
63
95
  const leftSidebarRef = useRef<ImperativePanelHandle>(null);
64
96
  const rightSidebarRef = useRef<ImperativePanelHandle>(null);
@@ -129,8 +161,22 @@ export const WorkspaceLayout = forwardRef(function WorkspaceLayout(
129
161
  },
130
162
  });
131
163
 
164
+ const centerPanelPercentage =
165
+ 100 -
166
+ (leftPanelContent ? leftSidebarPercentage : 0) -
167
+ (rightPanelContent ? rightSidebarPercentage : 0);
168
+
132
169
  return (
133
- <Stack.H flex="1">
170
+ <div
171
+ id={id}
172
+ className={className}
173
+ style={{
174
+ backgroundColor: theme.colors.canvas.background,
175
+ display: "flex",
176
+ flexDirection: "row",
177
+ ...style,
178
+ }}
179
+ >
134
180
  <PanelGroup
135
181
  ref={panelGroupRef}
136
182
  id={EDITOR_PANEL_GROUP_ID}
@@ -138,7 +184,7 @@ export const WorkspaceLayout = forwardRef(function WorkspaceLayout(
138
184
  autoSaveId={
139
185
  autoSavePrefix
140
186
  ? `${autoSavePrefix}--${EDITOR_PANEL_GROUP_ID}`
141
- : EDITOR_PANEL_GROUP_ID
187
+ : undefined
142
188
  }
143
189
  style={{ flex: "1" }}
144
190
  >
@@ -149,7 +195,7 @@ export const WorkspaceLayout = forwardRef(function WorkspaceLayout(
149
195
  order={1}
150
196
  ref={leftSidebarRef}
151
197
  defaultSize={leftSidebarPercentage}
152
- minSize={leftSidebarPercentage}
198
+ minSize={leftSidebarMinPercentage ?? leftSidebarPercentage}
153
199
  {...(!leftSidebarCanResize && { maxSize: leftSidebarPercentage })}
154
200
  collapsible
155
201
  style={{
@@ -172,6 +218,7 @@ export const WorkspaceLayout = forwardRef(function WorkspaceLayout(
172
218
  <Panel
173
219
  id={CONTENT_AREA_ID}
174
220
  order={2}
221
+ defaultSize={centerPanelPercentage}
175
222
  minSize={10}
176
223
  style={{
177
224
  display: "flex",
@@ -194,7 +241,7 @@ export const WorkspaceLayout = forwardRef(function WorkspaceLayout(
194
241
  id={RIGHT_SIDEBAR_ID}
195
242
  order={3}
196
243
  ref={rightSidebarRef}
197
- minSize={rightSidebarPercentage}
244
+ minSize={rightSidebarMinPercentage ?? rightSidebarPercentage}
198
245
  defaultSize={rightSidebarPercentage}
199
246
  collapsible
200
247
  style={{
@@ -207,6 +254,6 @@ export const WorkspaceLayout = forwardRef(function WorkspaceLayout(
207
254
  </>
208
255
  )}
209
256
  </PanelGroup>
210
- </Stack.H>
257
+ </div>
211
258
  );
212
259
  });