Skip to content

Commit f3851b1

Browse files
authored
Merge pull request #760 from ZenUml/feature/collapsible-editor
feat(Editor): implement toggle functionality for editor pane visibility
2 parents 480b98b + 8b3ce96 commit f3851b1

File tree

5 files changed

+52
-5
lines changed

5 files changed

+52
-5
lines changed

src/components/ContentWrap.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ export default class ContentWrap extends Component {
995995
}
996996
onDragEnd={this.mainSplitDragEndHandler.bind(this)}
997997
>
998-
<div id="js-code-side">
998+
<div id="js-code-side" className={this.props.isEditorCollapsed ? 'hidden' : ''}>
999999
<Tabs
10001000
keyboardShortcutsBtnClickHandler={
10011001
this.props.keyboardShortcutsBtnClickHandler
@@ -1135,7 +1135,7 @@ export default class ContentWrap extends Component {
11351135
<button
11361136
onClick={() => this.props.layoutBtnClickHandler(1)}
11371137
id="layoutBtn1"
1138-
className="w-7 h-7 hover:text-gray-800 flex items-center justify-center rounded-lg duration-200"
1138+
className={`w-7 h-7 hover:text-gray-800 flex items-center justify-center rounded-lg duration-200 ${this.props.currentLayoutMode === 1 ? 'text-gray-800' : ''}`}
11391139
aria-label="Switch to layout with preview on right"
11401140
>
11411141
<svg className="w-5 h-5">
@@ -1145,7 +1145,7 @@ export default class ContentWrap extends Component {
11451145
<button
11461146
onClick={() => this.props.layoutBtnClickHandler(2)}
11471147
id="layoutBtn2"
1148-
className="w-7 h-7 hover:text-gray-800 flex items-center justify-center rounded-lg duration-200"
1148+
className={`w-7 h-7 hover:text-gray-800 flex items-center justify-center rounded-lg duration-200 ${this.props.currentLayoutMode === 2 ? 'text-gray-800' : ''}`}
11491149
aria-label="Switch to layout with preview on bottom"
11501150
>
11511151
<svg className="w-5 h-5">
@@ -1155,7 +1155,7 @@ export default class ContentWrap extends Component {
11551155
<button
11561156
onClick={() => this.props.layoutBtnClickHandler(3)}
11571157
id="layoutBtn3"
1158-
className="w-7 h-7 hover:text-gray-800 flex items-center justify-center rounded-lg duration-200"
1158+
className={`w-7 h-7 hover:text-gray-800 flex items-center justify-center rounded-lg duration-200 ${this.props.currentLayoutMode === 3 ? 'text-gray-800' : ''}`}
11591159
aria-label="Switch to layout with preview on left"
11601160
>
11611161
<svg className="w-5 h-5">

src/components/Icons.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,12 @@ export function Icons() {
330330
fill="#FDC709"
331331
/>
332332
</symbol>
333+
<symbol id="icon-collapse" viewBox="0 0 24 24">
334+
<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M9 3v18m7-6l-3-3l3-3"/></g>
335+
</symbol>
336+
<symbol id="icon-expand" viewBox="0 0 24 24">
337+
<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M9 3v18m5-12l3 3l-3 3"/></g>
338+
</symbol>
333339
</symbol>
334340
</svg>
335341
);

src/components/MainHeader.jsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@ export function MainHeader(props) {
6262
return (
6363
<div className="main-header text-gray-400 py-2 px-8 flex justify-between border-b border-black-700 bg-black-500">
6464
<div className="flex items-center gap-4">
65+
<button
66+
className="py-1.5 duration-200 font-semibold flex items-center gap-2 rounded-lg"
67+
aria-label="Toggle editor pane"
68+
title={props.isEditorCollapsed ? "Expand editor pane" : "Collapse editor pane"}
69+
onClick={props.onToggleEditorCollapse}
70+
>
71+
<svg
72+
className={`h-8 w-8 transition-transform duration-200 ${
73+
props.currentLayoutMode === 2 ? 'rotate-90' :
74+
props.currentLayoutMode === 3 ? 'rotate-180' :
75+
'rotate-0'
76+
}`}
77+
>
78+
<use xlinkHref={props.isEditorCollapsed ? "#icon-expand" : "#icon-collapse"} />
79+
</svg>
80+
</button>
6581
<DropdownMenu.Root>
6682
<DropdownMenu.Trigger asChild>
6783
<div className="flex items-center p-1 hover:bg-gray-700 data-[state=open]:bg-[#454856] rounded-lg cursor-pointer duration-200">
@@ -243,7 +259,6 @@ export function MainHeader(props) {
243259
className="h-full w-full appearance-none"
244260
crossOrigin="anonymous"
245261
src={props.user.photoURL}
246-
className=""
247262
/>
248263
</div>
249264
{isSubscribed && (

src/components/app.jsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export default class App extends Component {
9494
title: '',
9595
externalLibs: { js: '', css: '' },
9696
},
97+
isEditorCollapsed: false,
9798
};
9899
this.defaultSettings = {
99100
preserveLastCode: true,
@@ -758,6 +759,25 @@ BookLibService.Borrow(id) {
758759
this.toggleLayout(layoutId);
759760
}
760761

762+
async toggleEditorCollapse() {
763+
await this.setState({
764+
isEditorCollapsed: !this.state.isEditorCollapsed,
765+
});
766+
767+
// Apply CSS class to body to control layout
768+
if (this.state.isEditorCollapsed) {
769+
document.body.classList.add('editor-collapsed');
770+
} else {
771+
document.body.classList.remove('editor-collapsed');
772+
}
773+
774+
mixpanel.track({
775+
event: 'toggleEditorCollapse',
776+
category: 'ui',
777+
label: this.state.isEditorCollapsed ? 'collapsed' : 'expanded',
778+
});
779+
}
780+
761781
// Calculates the sizes of html, css & js code panes.
762782
getCodePaneSizes() {
763783
var sizes;
@@ -1661,6 +1681,7 @@ BookLibService.Borrow(id) {
16611681
openCheatSheet={this.openCheatSheet.bind(this)}
16621682
onUpdateImage={this.onUpdateImage.bind(this)}
16631683
currentItem={this.state.currentItem}
1684+
currentLayoutMode={this.state.currentLayoutMode}
16641685
onLogin={this.loginBtnClickHandler.bind(this)}
16651686
externalLibCount={this.state.externalLibCount}
16661687
openBtnHandler={this.openBtnClickHandler.bind(this)}
@@ -1679,6 +1700,8 @@ BookLibService.Borrow(id) {
16791700
user={this.state.user}
16801701
settingsBtnClickHandler={this.handleSettingsBtnClick.bind(this)}
16811702
unsavedEditCount={this.state.unsavedEditCount}
1703+
isEditorCollapsed={this.state.isEditorCollapsed}
1704+
onToggleEditorCollapse={this.toggleEditorCollapse.bind(this)}
16821705
/>
16831706
)}
16841707
{this.isEmbed && (
@@ -1709,6 +1732,8 @@ BookLibService.Borrow(id) {
17091732
this,
17101733
)}
17111734
layoutBtnClickHandler={this.layoutBtnClickHandler.bind(this)}
1735+
isEditorCollapsed={this.state.isEditorCollapsed}
1736+
onToggleEditorCollapse={this.toggleEditorCollapse.bind(this)}
17121737
/>
17131738
{this.isEmbed ? null : (
17141739
<Footer

src/style.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ body:not(.light-version).overlay-visible .main-container {
353353
.code-side,
354354
.demo-side {
355355
flex-basis: inherit;
356+
flex-grow: 1;
356357
position: relative;
357358
width: 50%;
358359
}

0 commit comments

Comments
 (0)