Skip to content

Commit 94e4fa8

Browse files
committed
Add fileList option to editor pane
1 parent d56d074 commit 94e4fa8

File tree

3 files changed

+85
-33
lines changed

3 files changed

+85
-33
lines changed

src/components/workspace/WorkspacesList.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,14 @@ const styles = prefixObject(rawStyles)
8888

8989
export interface Step {
9090
title: string
91-
description: string
91+
description?: string
9292
}
9393

9494
interface Props {
9595
steps: Step[]
9696
activeStepIndex: number
9797
onChangeActiveStepIndex: (index: number) => void
98+
showNextButton?: boolean
9899
style?: CSSProperties
99100
rowStyle?: CSSProperties
100101
rowStyleActive?: CSSProperties
@@ -210,7 +211,11 @@ export default class WorkspacesList extends PureComponent<Props> {
210211
}
211212

212213
renderStep = (step: Step, index: number, list: Step[]) => {
213-
const { activeStepIndex, onChangeActiveStepIndex } = this.props
214+
const {
215+
activeStepIndex,
216+
onChangeActiveStepIndex,
217+
showNextButton = true,
218+
} = this.props
214219
const { title, description } = step
215220

216221
const isActive = index === activeStepIndex
@@ -223,7 +228,7 @@ export default class WorkspacesList extends PureComponent<Props> {
223228
>
224229
<div style={this.getComputedRowTitleStyle(isActive)}>{title}</div>
225230
</div>
226-
{isActive && (
231+
{description && isActive && (
227232
<div style={this.getComputedDescriptionStyle()}>
228233
<div
229234
className={'markdown'}
@@ -232,7 +237,7 @@ export default class WorkspacesList extends PureComponent<Props> {
232237
/>
233238
</div>
234239
)}
235-
{isActive && index !== list.length - 1 && (
240+
{showNextButton && isActive && index !== list.length - 1 && (
236241
<div style={this.getComputedButtonWrapperStyle()}>
237242
<Button
238243
inverse={true}

src/components/workspace/panes/EditorPane.tsx

Lines changed: 75 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { memo, useState } from 'react'
22
import screenfull from 'screenfull'
33
import { LogCommand } from '../../../types/Messages'
44
import { EditorPaneOptions } from '../../../utils/Panes'
5-
import { columnStyle, mergeStyles, prefixObject } from '../../../utils/Styles'
5+
import { columnStyle, mergeStyles, prefixObject, rowStyle } from '../../../utils/Styles'
66
import {
77
compareTabs,
88
getTabChanged,
@@ -24,6 +24,7 @@ import { useOptions } from '../../../contexts/OptionsContext'
2424
import { CodeSandboxButton } from '../CodeSandboxButton'
2525
import { CubeIcon, EnterFullScreenIcon, ExternalLinkIcon } from '../Icons'
2626
import { HorizontalSpacer } from '../Spacer'
27+
import WorkspacesList from '../WorkspacesList'
2728

2829
const toggleFullscreen = () => (screenfull as any).toggle()
2930

@@ -59,6 +60,11 @@ const styles = prefixObject({
5960
backgroundColor: 'rgba(0,0,0,0.02)',
6061
border: '1px solid rgba(0,0,0,0.05)',
6162
},
63+
sidebar: mergeStyles(columnStyle, {
64+
flex: '0 0 220px',
65+
overflowX: 'hidden',
66+
overflowY: 'auto',
67+
}),
6268
})
6369

6470
interface Props {
@@ -116,6 +122,10 @@ export default memo(function EditorPane({
116122
const isError = !!error
117123

118124
const style = mergeStyles(styles.editorPane, options.style)
125+
const sidebarStyle = mergeStyles(
126+
styles.sidebar,
127+
externalStyles.workspacesList
128+
)
119129

120130
const headerElements = (
121131
<>
@@ -147,6 +157,39 @@ export default memo(function EditorPane({
147157
</>
148158
)
149159

160+
const tabsElement = fileTabs.length > 1 && (
161+
<Tabs
162+
tabs={fileTabs}
163+
getTitle={getTabTitle}
164+
getChanged={getTabChanged}
165+
activeTab={activeFileTab}
166+
compareTabs={compareTabs}
167+
onClickTab={onClickTab}
168+
tabStyle={externalStyles.tab}
169+
textStyle={externalStyles.tabText}
170+
activeTextStyle={externalStyles.tabTextActive}
171+
changedTextStyle={externalStyles.tabTextChanged}
172+
>
173+
{!title && headerElements}
174+
</Tabs>
175+
)
176+
177+
const editorElement = (
178+
<Editor
179+
key={activeFile}
180+
initialValue={files[activeFile]}
181+
filename={activeStepIndex + ':' + activeFile}
182+
onChange={onChange}
183+
errorLineNumber={error?.lineNumber}
184+
showDiff={true}
185+
diff={fileDiff}
186+
logs={playgroundOptions.enabled ? logs : undefined}
187+
playgroundOptions={playgroundOptions}
188+
getTypeInfo={typescriptOptions.enabled ? getTypeInfo : undefined}
189+
tooltipStyle={externalStyles.tooltip}
190+
/>
191+
)
192+
150193
return (
151194
<div style={style}>
152195
{title && (
@@ -158,35 +201,38 @@ export default memo(function EditorPane({
158201
{headerElements}
159202
</Header>
160203
)}
161-
{fileTabs.length > 1 && (
162-
<Tabs
163-
tabs={fileTabs}
164-
getTitle={getTabTitle}
165-
getChanged={getTabChanged}
166-
activeTab={activeFileTab}
167-
compareTabs={compareTabs}
168-
onClickTab={onClickTab}
169-
tabStyle={externalStyles.tab}
170-
textStyle={externalStyles.tabText}
171-
activeTextStyle={externalStyles.tabTextActive}
172-
changedTextStyle={externalStyles.tabTextChanged}
173-
>
174-
{!title && headerElements}
175-
</Tabs>
204+
{options.fileList === 'sidebar' ? (
205+
<div style={rowStyle}>
206+
<WorkspacesList
207+
activeStepIndex={
208+
// Index of active tab
209+
fileTabs.findIndex((tab) => tab === activeFileTab)
210+
}
211+
onChangeActiveStepIndex={(index) => {
212+
onClickTab(fileTabs[index])
213+
}}
214+
showNextButton={false}
215+
steps={fileTabs}
216+
style={sidebarStyle}
217+
rowStyle={externalStyles.workspacesRow}
218+
rowStyleActive={externalStyles.workspacesRowActive}
219+
rowTitleStyle={externalStyles.workspacesRowTitle}
220+
rowTitleStyleActive={externalStyles.workspacesRowTitleActive}
221+
descriptionStyle={externalStyles.workspacesDescription}
222+
descriptionTextStyle={externalStyles.workspacesDescriptionText}
223+
buttonTextStyle={externalStyles.workspacesButtonText}
224+
buttonContainerStyle={externalStyles.workspacesButtonContainer}
225+
buttonWrapperStyle={externalStyles.workspacesButtonWrapper}
226+
dividerStyle={externalStyles.workspacesDivider}
227+
/>
228+
{editorElement}
229+
</div>
230+
) : (
231+
<React.Fragment>
232+
{tabsElement}
233+
{editorElement}
234+
</React.Fragment>
176235
)}
177-
<Editor
178-
key={activeFile}
179-
initialValue={files[activeFile]}
180-
filename={activeStepIndex + ':' + activeFile}
181-
onChange={onChange}
182-
errorLineNumber={error?.lineNumber}
183-
showDiff={true}
184-
diff={fileDiff}
185-
logs={playgroundOptions.enabled ? logs : undefined}
186-
playgroundOptions={playgroundOptions}
187-
getTypeInfo={typescriptOptions.enabled ? getTypeInfo : undefined}
188-
tooltipStyle={externalStyles.tooltip}
189-
/>
190236
{showDetails && (
191237
<div style={styles.overlayContainer}>
192238
<div style={styles.overlay}>

src/utils/Panes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export type StackPaneOptions = PaneBaseOptions & {
2929

3030
export type EditorPaneOptions = PaneBaseOptions & {
3131
type: 'editor'
32+
fileList?: 'tabs' | 'sidebar'
3233
}
3334

3435
export type TranspilerPaneOptions = PaneBaseOptions & {

0 commit comments

Comments
 (0)