Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

feat(playground): resizable editor/preview panels (#2075)

Cindy Zhang24f5b602aee0
diff --git a/apps/docsite/src/app/playground/PlaygroundClient.tsx b/apps/docsite/src/app/playground/PlaygroundClient.tsx
index bf96584208..cefbc3b8a6 100644
--- a/apps/docsite/src/app/playground/PlaygroundClient.tsx
+++ b/apps/docsite/src/app/playground/PlaygroundClient.tsx
@@ -13,6 +13,7 @@ import {XDSHStack} from "@xds/core/Layout";
import {XDSText} from "@xds/core/Text";
import {XDSStatusDot} from "@xds/core/StatusDot";
import {XDSDivider} from "@xds/core/Divider";
+import {useXDSResizable, XDSResizeHandle} from "@xds/core/Resizable";
import githubLight from "./themes/github-light.json";
import githubDark from "./themes/github-dark.json";
@@ -236,9 +237,9 @@ const s = stylex.create({
},
},
editorPane: {
- flex: 1,
display: "flex",
flexDirection: "column",
+ flexShrink: 0,
minWidth: 0,
minHeight: {
default: 0,
@@ -282,6 +283,14 @@ export function PlaygroundClient() {
const pendingRef = useRef<string | null>(null);
const debounceRef = useRef<ReturnType<typeof setTimeout> | null>(null);
+ const editorPanel = useXDSResizable({
+ defaultSize: "50%",
+ minSizePx: 200,
+ collapsible: true,
+ snaps: [400, 600],
+ autoSaveId: "xds-playground-editor-width",
+ });
+
const [editorTheme, setEditorTheme] = useState("github-dark");
// Sync editor theme with system preference
@@ -422,7 +431,10 @@ export function PlaygroundClient() {
</div>
<XDSDivider />
<div {...stylex.props(s.main)}>
- <div {...stylex.props(s.editorPane)}>
+ <div
+ {...stylex.props(s.editorPane)}
+ style={isMobile ? {height: editorPanel.size} : {width: editorPanel.size}}
+ >
<MonacoEditor
defaultLanguage="typescript"
defaultValue={code}
@@ -434,7 +446,13 @@ export function PlaygroundClient() {
options={editorOptions}
/>
</div>
- <XDSDivider orientation="vertical" />
+ <XDSResizeHandle
+ label="Resize editor panel"
+ direction={isMobile ? "vertical" : "horizontal"}
+ hasDivider
+ pillPlacement={isMobile ? "end" : "auto"}
+ resizable={editorPanel.props}
+ />
<div {...stylex.props(s.previewPane)}>
<div {...stylex.props(s.previewBar)}>
<XDSText color="secondary" type="supporting">Preview</XDSText>