Skip to content

Commit 57301df

Browse files
authoredMay 17, 2023
Add resizable editor/layout to playground
1 parent 7fd1d9a commit 57301df

File tree

2 files changed

+75
-26
lines changed

2 files changed

+75
-26
lines changed
 

‎docs/_asset/index.css

+60-14
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,6 @@ pre code,
301301
background-color: #fafafa !important; /* Color from one-light */
302302
}
303303

304-
.frame-body-box-fixed-height {
305-
height: 20rem;
306-
overflow-y: auto;
307-
}
308-
309304
.frame-body-box {
310305
padding: calc(1em + 1ex);
311306
}
@@ -764,8 +759,21 @@ button.success {
764759
border-radius: 10px;
765760
}
766761

762+
.frame-resizeable {
763+
display: flex;
764+
flex-direction: column;
765+
overflow: auto;
766+
767+
min-height: 10rem;
768+
height: 24rem;
769+
resize: vertical;
770+
}
771+
767772
.frame-tab-bar {
773+
flex-shrink: 0;
768774
display: flex;
775+
flex-direction: row;
776+
align-items: stretch;
769777
margin-block-start: calc(1em + 1ex);
770778
list-style-type: none;
771779
margin: 0;
@@ -776,10 +784,6 @@ button.success {
776784
.frame-tab-bar-scroll {
777785
overflow-x: auto;
778786
overflow-y: hidden;
779-
flex: 1;
780-
flex-direction: row;
781-
align-items: stretch;
782-
flex-grow: 1;
783787
mask-image: linear-gradient(
784788
to right,
785789
hsl(0deg 0% 100% / 30%),
@@ -789,11 +793,54 @@ button.success {
789793
);
790794
}
791795

796+
.react-tabs__tab-panel {
797+
}
798+
799+
.react-tabs__tab-panel--selected {
800+
flex-grow: 1;
801+
display: flex;
802+
flex-direction: column;
803+
overflow: hidden;
804+
}
805+
806+
/* Preview / Options */
807+
.react-tabs__tab-panel--selected.tab-panel-scrollable {
808+
overflow: auto;
809+
}
810+
792811
.frame-body {
793812
border-bottom-left-radius: 3px;
794813
border-bottom-right-radius: 3px;
795814
}
796815

816+
.react-tabs__tab-panel--selected > .frame-body {
817+
flex-grow: 1;
818+
display: flex;
819+
flex-direction: column;
820+
}
821+
822+
.react-tabs__tab-panel--selected:not(.tab-panel-scrollable) > .frame-body {
823+
overflow: hidden;
824+
}
825+
826+
.frame-body > .playground-editor-code-mirror,
827+
.frame-body > pre {
828+
flex-grow: 1;
829+
display: flex;
830+
flex-direction: column;
831+
overflow: hidden;
832+
}
833+
834+
.frame-body > div > div.cm-editor {
835+
flex-grow: 1;
836+
overflow: hidden;
837+
}
838+
839+
.frame-body > pre > code {
840+
overflow-x: auto;
841+
overflow-y: auto;
842+
}
843+
797844
.frame-tab-bar + pre {
798845
margin-block-start: 0;
799846
}
@@ -893,6 +940,10 @@ button.success {
893940
background-color: var(--fg);
894941
}
895942

943+
.playground-editor-options-tab-panel label {
944+
margin-block: 0.5em;
945+
}
946+
896947
.playground-result-badge::after {
897948
content: attr(data-count);
898949
display: inline-block;
@@ -923,11 +974,6 @@ button.success {
923974
font-size: 1rem;
924975
}
925976

926-
.ͼ1 .cm-scroller,
927-
.ͼ1 .cm-content {
928-
min-height: 20rem;
929-
}
930-
931977
.ͼo {
932978
border-bottom-left-radius: 2px;
933979
border-bottom-right-radius: 2px;

‎docs/_component/editor.client.js

+15-12
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ function ErrorFallback({error, resetErrorBoundary}) {
8686

8787
const MemoizedCodeMirror = memo((props) => (
8888
<ErrorBoundary FallbackComponent={ErrorFallback}>
89-
<CodeMirror {...props} />
89+
<CodeMirror
90+
{...props}
91+
elementProps={{className: 'playground-editor-code-mirror'}}
92+
/>
9093
</ErrorBoundary>
9194
))
9295

@@ -130,7 +133,7 @@ export function Editor({children}) {
130133

131134
return (
132135
<div>
133-
<Tabs className="frame">
136+
<Tabs className="frame frame-resizeable">
134137
<TabList className="frame-tab-bar frame-tab-bar-scroll">
135138
<Tab
136139
className="frame-tab-item frame-tab-item-dark"
@@ -146,7 +149,7 @@ export function Editor({children}) {
146149
</Tab>
147150
</TabList>
148151
<TabPanel>
149-
<div className="frame-body frame-body-box-fixed-height">
152+
<div className="frame-body">
150153
<noscript>
151154
<pre>
152155
<code className="hljs language-md">
@@ -161,8 +164,8 @@ export function Editor({children}) {
161164
/>
162165
</div>
163166
</TabPanel>
164-
<TabPanel>
165-
<form className="frame-body frame-body-box frame-body-box-fixed-height">
167+
<TabPanel className="tab-panel-scrollable playground-editor-options-tab-panel">
168+
<form className="frame-body frame-body-box">
166169
<label>
167170
<input
168171
checked={state.gfm}
@@ -202,7 +205,7 @@ export function Editor({children}) {
202205
</TabPanel>
203206
</Tabs>
204207

205-
<Tabs className="frame">
208+
<Tabs className="frame frame-resizeable">
206209
<TabList className="frame-tab-bar frame-tab-bar-scroll">
207210
{[
208211
'Run',
@@ -238,16 +241,16 @@ export function Editor({children}) {
238241
})}
239242
</TabList>
240243

241-
<TabPanel>
244+
<TabPanel className="tab-panel-scrollable">
242245
<noscript>Enable JavaScript for the rendered result.</noscript>
243-
<div className="frame-body frame-body-box-fixed-height frame-body-box">
246+
<div className="frame-body frame-body-box">
244247
<ErrorBoundary FallbackComponent={ErrorFallback}>
245248
{state.file && state.file.result ? <Preview /> : null}
246249
</ErrorBoundary>
247250
</div>
248251
</TabPanel>
249252
<TabPanel>
250-
<div className="frame-body frame-body-box-fixed-height">
253+
<div className="frame-body">
251254
{state.file ? (
252255
stats.fatal ? (
253256
<pre>
@@ -267,7 +270,7 @@ export function Editor({children}) {
267270
</div>
268271
</TabPanel>
269272
<TabPanel>
270-
<div className="frame-body frame-body-box-fixed-height">
273+
<div className="frame-body">
271274
{state.file && state.file.data.mdast ? (
272275
<pre>
273276
<code className="hljs language-js">
@@ -284,7 +287,7 @@ export function Editor({children}) {
284287
</div>
285288
</TabPanel>
286289
<TabPanel>
287-
<div className="frame-body frame-body-box-fixed-height">
290+
<div className="frame-body">
288291
{state.file && state.file.data.hast ? (
289292
<pre>
290293
<code className="hljs language-js">
@@ -301,7 +304,7 @@ export function Editor({children}) {
301304
</div>
302305
</TabPanel>
303306
<TabPanel>
304-
<div className="frame-body frame-body-box-fixed-height">
307+
<div className="frame-body">
305308
{state.file && state.file.data.esast ? (
306309
<pre>
307310
<code className="hljs language-js">

1 commit comments

Comments
 (1)

vercel[bot] commented on May 17, 2023

@vercel[bot]

Successfully deployed to the following URLs:

mdx – ./

v2.mdxjs.com
mdx-mdx.vercel.app
mdx-git-main-mdx.vercel.app
mdxjs.com

Please sign in to comment.