Skip to content

Commit 1255ac0

Browse files
authored
Improve playground layout (#2098)
Some adjustments to the CSS so that the playground elements shrink and grow in a more intuitive way. - So far I've tested on Edge (Windows) and Safari (Mac). I haven't tested on Firefox. - I wasn't sure how to refactor the CSS to leave it better than I found it. I'm happy to make more changes, please give me feedback about how I can improve the code organization. ![2025-01-09_11-46-50](https://github.com/user-attachments/assets/33993415-7e33-4f4c-8776-fe4040da6fae)
1 parent d021574 commit 1255ac0

File tree

6 files changed

+145
-78
lines changed

6 files changed

+145
-78
lines changed

npm/qsharp/ux/qsharp-ux.css

Lines changed: 82 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ modern-normalize (see https://mattbrictson.com/blog/css-normalize-and-reset for
6363

6464
html {
6565
box-sizing: border-box;
66+
overflow: hidden;
6667
font-size: 16px;
6768
}
6869

@@ -72,17 +73,17 @@ html {
7273

7374
.qs-play-body {
7475
position: relative;
75-
min-height: 100vh;
76+
height: 100vh;
7677
font-family: system-ui, "Segoe UI", "SegoeUI", Roboto, Helvetica, Arial,
7778
sans-serif;
7879
color: var(--main-color);
7980
background-color: var(--main-background);
8081
display: grid;
8182
grid-template-areas:
82-
"header header header"
83-
"nav editor results";
83+
"header header"
84+
"nav content";
8485
grid-template-rows: auto 1fr;
85-
grid-template-columns: minmax(180px, auto) 8fr 8fr;
86+
grid-template-columns: minmax(180px, auto) 1fr;
8687
column-gap: 16px;
8788
}
8889

@@ -99,6 +100,12 @@ html {
99100
padding-bottom: 8px;
100101
}
101102

103+
.content {
104+
grid-area: content;
105+
height: 100%;
106+
overflow: auto;
107+
}
108+
102109
#popup {
103110
position: absolute;
104111
display: none;
@@ -113,6 +120,7 @@ html {
113120

114121
.nav-column {
115122
grid-area: nav;
123+
overflow: auto;
116124
background-color: var(--nav-background);
117125
}
118126

@@ -143,12 +151,60 @@ html {
143151
background-color: var(--nav-current-background);
144152
}
145153

154+
/* Samples layout */
155+
156+
.samples {
157+
position: relative;
158+
height: 100%;
159+
display: grid;
160+
grid-template-areas:
161+
"editor-header results-labels"
162+
"editor-code output"
163+
"editor-commands ."
164+
"editor-diags .";
165+
grid-template-rows: 35px 1fr 35px 150px;
166+
grid-template-columns: 3fr 4fr;
167+
column-gap: 16px;
168+
padding-right: 16px;
169+
padding-top: 16px;
170+
}
171+
172+
.samples .code-editor {
173+
/* This position attribute allows the monaco editor
174+
to shrink when the window is resized to be smaller.
175+
https://stackoverflow.com/a/71876526 */
176+
position: absolute !important;
177+
grid-area: editor-code;
178+
height: 100%;
179+
width: 100%;
180+
}
181+
182+
.samples .button-row {
183+
grid-area: editor-commands;
184+
}
185+
186+
.samples .editor-header {
187+
grid-area: editor-header;
188+
}
189+
190+
.samples .diag-list {
191+
overflow: auto;
192+
grid-area: editor-diags;
193+
}
194+
195+
.samples .output {
196+
grid-area: output;
197+
height: 100%;
198+
min-height: 400px;
199+
resize: none;
200+
}
201+
146202
/* Editor section */
147203

148-
.editor-column {
149-
grid-area: editor;
150-
margin: 16px;
151-
margin-top: 32px;
204+
.editor-header {
205+
display: flex;
206+
justify-content: space-between;
207+
align-items: end;
152208
}
153209

154210
.file-name {
@@ -235,29 +291,35 @@ html {
235291
/* Katas */
236292

237293
.kata-override {
294+
/* The padding is just to shrink the width
295+
to make the content more readable */
296+
padding-right: 40%;
297+
background-color: var(--main-background);
298+
}
299+
300+
/* Documentation */
301+
302+
.doc-container {
303+
/* The padding is just to shrink the width
304+
to make the content more readable */
305+
padding-right: 40%;
238306
background-color: var(--main-background);
239307
}
240308

241309
/* TODO: Update all components with specific prefixes */
242310

243311
/* Results panels */
244312

245-
.results-column {
246-
grid-area: results;
247-
margin-left: 0px;
248-
margin-top: 32px;
249-
margin-right: 120px;
250-
}
251-
252313
.active-tab {
253314
font-size: 1.1rem;
254315
font-weight: 600;
255316
text-decoration: underline;
256317
}
257318

258319
.results-labels {
320+
grid-area: results-labels;
259321
display: flex;
260-
height: 32px;
322+
align-items: center;
261323
}
262324

263325
.results-labels > div {
@@ -268,24 +330,21 @@ html {
268330
}
269331

270332
.ast-output {
271-
height: 40vh;
272-
min-height: 400px;
333+
height: 100%;
273334
width: 100%;
274335
resize: none;
275336
white-space: pre;
276337
}
277338

278339
.hir-output {
279-
height: 40vh;
280-
min-height: 400px;
340+
height: 100%;
281341
width: 100%;
282342
resize: none;
283343
white-space: pre;
284344
}
285345

286346
.qir-output {
287-
height: 40vh;
288-
min-height: 400px;
347+
height: 100%;
289348
width: 100%;
290349
resize: none;
291350
white-space: pre;
@@ -298,11 +357,10 @@ html {
298357
font-weight: 400;
299358
margin-top: 16px;
300359
margin-bottom: 16px;
301-
display: flex;
302-
justify-content: space-between;
303360
}
304361

305362
.prev-next {
363+
margin-bottom: 16px;
306364
font-weight: 200;
307365
cursor: pointer;
308366
}

playground/src/docs.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,9 @@ export function DocumentationDisplay(props: {
5353
}) {
5454
const docsMd = props.documentation?.get(props.currentNamespace) ?? "";
5555

56-
return <Markdown markdown={docsMd} />;
56+
return (
57+
<div class="markdown-body doc-container">
58+
<Markdown markdown={docsMd} className="doc-container" />
59+
</div>
60+
);
5761
}

playground/src/editor.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ export function Editor(props: {
235235
const newEditor = monaco.editor.create(editorDiv.current, {
236236
minimap: { enabled: false },
237237
lineNumbersMinChars: 3,
238+
automaticLayout: true,
238239
});
239240

240241
editor.current = newEditor;
@@ -398,8 +399,8 @@ export function Editor(props: {
398399
}
399400

400401
return (
401-
<div class="editor-column">
402-
<div style="display: flex; justify-content: space-between; align-items: center;">
402+
<>
403+
<div class="editor-header">
403404
<div class="file-name">main.qs</div>
404405
<div class="icon-row">
405406
<svg
@@ -504,6 +505,6 @@ export function Editor(props: {
504505
</div>
505506
))}
506507
</div>
507-
</div>
508+
</>
508509
);
509510
}

playground/src/main.tsx

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -161,52 +161,54 @@ function App(props: { katas: Kata[]; linkedCode?: string }) {
161161
samples={sampleTitles}
162162
namespaces={getNamespaces(documentation)}
163163
></Nav>
164-
{sampleCode ? (
165-
<>
166-
<Editor
167-
code={sampleCode}
164+
<div class="content">
165+
{sampleCode ? (
166+
<div class="samples">
167+
<Editor
168+
code={sampleCode}
169+
compiler={compiler}
170+
compiler_worker_factory={compiler_worker_factory}
171+
compilerState={compilerState}
172+
onRestartCompiler={onRestartCompiler}
173+
evtTarget={evtTarget}
174+
defaultShots={defaultShots}
175+
showShots={true}
176+
showExpr={true}
177+
shotError={shotError}
178+
profile={getProfile()}
179+
setAst={setAst}
180+
setHir={setHir}
181+
setQir={setQir}
182+
activeTab={activeTab}
183+
languageService={languageService}
184+
></Editor>
185+
<OutputTabs
186+
evtTarget={evtTarget}
187+
showPanel={true}
188+
onShotError={(diag?: VSDiagnostic) => setShotError(diag)}
189+
ast={ast}
190+
hir={hir}
191+
qir={qir}
192+
activeTab={activeTab}
193+
setActiveTab={setActiveTab}
194+
></OutputTabs>
195+
</div>
196+
) : activeKata ? (
197+
<Katas
198+
kata={activeKata!}
168199
compiler={compiler}
169200
compiler_worker_factory={compiler_worker_factory}
170201
compilerState={compilerState}
171202
onRestartCompiler={onRestartCompiler}
172-
evtTarget={evtTarget}
173-
defaultShots={defaultShots}
174-
showShots={true}
175-
showExpr={true}
176-
shotError={shotError}
177-
profile={getProfile()}
178-
setAst={setAst}
179-
setHir={setHir}
180-
setQir={setQir}
181-
activeTab={activeTab}
182203
languageService={languageService}
183-
></Editor>
184-
<OutputTabs
185-
evtTarget={evtTarget}
186-
showPanel={true}
187-
onShotError={(diag?: VSDiagnostic) => setShotError(diag)}
188-
ast={ast}
189-
hir={hir}
190-
qir={qir}
191-
activeTab={activeTab}
192-
setActiveTab={setActiveTab}
193-
></OutputTabs>
194-
</>
195-
) : activeKata ? (
196-
<Katas
197-
kata={activeKata!}
198-
compiler={compiler}
199-
compiler_worker_factory={compiler_worker_factory}
200-
compilerState={compilerState}
201-
onRestartCompiler={onRestartCompiler}
202-
languageService={languageService}
203-
></Katas>
204-
) : (
205-
<DocumentationDisplay
206-
currentNamespace={currentNavItem}
207-
documentation={documentation}
208-
></DocumentationDisplay>
209-
)}
204+
></Katas>
205+
) : (
206+
<DocumentationDisplay
207+
currentNamespace={currentNavItem}
208+
documentation={documentation}
209+
></DocumentationDisplay>
210+
)}
211+
</div>
210212
<div id="popup"></div>
211213
</>
212214
);

playground/src/results.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,13 @@ export function ResultsTab(props: {
225225
{props.kataMode ? null : (
226226
<>
227227
<div class="output-header">
228-
<div>
229-
Shot {currIndex + 1} of {countForFilter}
230-
</div>
231228
<div class="prev-next">
232229
<span onClick={onPrev}>Prev</span> |{" "}
233230
<span onClick={onNext}>Next</span>
234231
</div>
232+
<div>
233+
Shot {currIndex + 1} of {countForFilter}
234+
</div>
235235
</div>
236236
<div class="result-label">Result: {resultLabel}</div>
237237
</>

playground/src/tabs.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function OutputTabs(props: {
4848
setActiveTab: (tab: ActiveTab) => void;
4949
}) {
5050
return (
51-
<div class="results-column">
51+
<>
5252
{props.showPanel ? (
5353
<div class="results-labels">
5454
{tabArray.map((elem) => (
@@ -61,10 +61,12 @@ export function OutputTabs(props: {
6161
))}
6262
</div>
6363
) : null}
64-
<ResultsTab {...props} />
65-
<AstTab {...props} />
66-
<HirTab {...props} />
67-
<QirTab {...props} />
68-
</div>
64+
<div class="output">
65+
<ResultsTab {...props} />
66+
<AstTab {...props} />
67+
<HirTab {...props} />
68+
<QirTab {...props} />
69+
</div>
70+
</>
6971
);
7072
}

0 commit comments

Comments
 (0)