Skip to content

Commit a993fce

Browse files
alexpelanoutoftime
authored andcommitted
Introduce CollapsedComponent for minified component (#1673)
* Introduce `CollapsedComponent` for minified component This is the some groundwork for allowing the preview to be minimized. `CollapsedComponent` unifies the collapsed UI for the currently collapsible components (the 3 editors and the console). Starts to fix: #1340 * Pull Request feedback: - Pull out BEM block for `CollapsedComponent` - Unnecessary `key` - Pass full component name rather than constructing
1 parent 7ed21f2 commit a993fce

File tree

5 files changed

+94
-28
lines changed

5 files changed

+94
-28
lines changed

locales/en/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"css": "CSS",
7272
"javascript": "JS"
7373
},
74+
"console": "Console",
7475
"output": "Output",
7576
"instructions": {
7677
"cancel": "Cancel",
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import {faChevronUp} from '@fortawesome/free-solid-svg-icons';
2+
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
3+
import React from 'react';
4+
import PropTypes from 'prop-types';
5+
import partial from 'lodash-es/partial';
6+
import classnames from 'classnames';
7+
8+
export default function CollapsedComponent({
9+
component,
10+
isRightJustified,
11+
onComponentUnhide,
12+
projectKey,
13+
text,
14+
}) {
15+
return (
16+
<div
17+
className="collapsed-component"
18+
onClick={partial(
19+
onComponentUnhide,
20+
projectKey,
21+
component,
22+
)}
23+
>
24+
<div
25+
className={classnames(
26+
'label',
27+
'collapsed-component__label',
28+
{'collapsed-component__label_left': !isRightJustified},
29+
)}
30+
>
31+
{text}
32+
{' '}
33+
<FontAwesomeIcon icon={faChevronUp} />
34+
</div>
35+
</div>
36+
);
37+
}
38+
39+
CollapsedComponent.propTypes = {
40+
component: PropTypes.string.isRequired,
41+
isRightJustified: PropTypes.bool.isRequired,
42+
projectKey: PropTypes.string.isRequired,
43+
text: PropTypes.string.isRequired,
44+
onComponentUnhide: PropTypes.func.isRequired,
45+
};
46+
47+
CollapsedComponent.defaultProps = {
48+
isRightJustified: true,
49+
};

src/components/Console.jsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ import classnames from 'classnames';
22
import {
33
faBan,
44
faChevronDown,
5-
faChevronUp,
65
} from '@fortawesome/free-solid-svg-icons';
76
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
87
import partial from 'lodash-es/partial';
98
import React from 'react';
109
import PropTypes from 'prop-types';
1110
import ImmutablePropTypes from 'react-immutable-proptypes';
11+
import {t} from 'i18next';
1212

1313
import {EditorLocation} from '../records';
1414

1515
import ConsoleEntry from './ConsoleEntry';
1616
import ConsoleInput from './ConsoleInput';
17+
import CollapsedComponent from './CollapsedComponent';
1718

1819
export default function Console({
1920
currentCompiledProjectKey,
@@ -33,6 +34,18 @@ export default function Console({
3334
onToggleVisible,
3435
requestedFocusedLine,
3536
}) {
37+
if (!isOpen) {
38+
return (
39+
<CollapsedComponent
40+
component="console"
41+
isRightJustified={false}
42+
projectKey={currentProjectKey}
43+
text={t('workspace.components.console')}
44+
onComponentUnhide={onToggleVisible}
45+
/>
46+
);
47+
}
48+
3649
const console = (
3750
<div
3851
className="console__scroll-container output__item"
@@ -65,8 +78,6 @@ export default function Console({
6578
</div>
6679
);
6780

68-
const chevron = isOpen ? faChevronDown : faChevronUp;
69-
7081
return (
7182
<div
7283
className={classnames(
@@ -79,9 +90,9 @@ export default function Console({
7990
onClick={partial(onToggleVisible, currentProjectKey)}
8091
>
8192
<div>
82-
Console
93+
{t('workspace.components.console')}
8394
{' '}
84-
<FontAwesomeIcon icon={chevron} />
95+
<FontAwesomeIcon icon={faChevronDown} />
8596
</div>
8697
<div
8798
onClick={(e) => {
@@ -92,7 +103,7 @@ export default function Console({
92103
<FontAwesomeIcon icon={faBan} />
93104
</div>
94105
</div>
95-
{isOpen ? console : null}
106+
{console}
96107
</div>
97108
);
98109
}

src/components/EditorsColumn.jsx

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
import {faChevronUp} from '@fortawesome/free-solid-svg-icons';
2-
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
31
import {DraggableCore} from 'react-draggable';
42
import React from 'react';
53
import PropTypes from 'prop-types';
64
import ImmutablePropTypes from 'react-immutable-proptypes';
75
import prefixAll from 'inline-style-prefixer/static';
8-
import {t} from 'i18next';
96
import classnames from 'classnames';
107
import clone from 'lodash-es/clone';
118
import isEmpty from 'lodash-es/isEmpty';
129
import includes from 'lodash-es/includes';
1310
import map from 'lodash-es/map';
1411
import partial from 'lodash-es/partial';
1512
import partition from 'lodash-es/partition';
13+
import {t} from 'i18next';
1614

1715
import {EditorLocation} from '../records';
1816

17+
import CollapsedComponent from './CollapsedComponent';
1918
import EditorContainer from './EditorContainer';
2019
import Editor from './Editor';
2120

@@ -100,21 +99,13 @@ export default function EditorsColumn({
10099

101100
hiddenLanguages.forEach(({language}) => {
102101
children.push((
103-
<div
104-
className="editors__collapsed-editor"
102+
<CollapsedComponent
103+
component={`editor.${language}`}
105104
key={language}
106-
onClick={partial(
107-
onComponentUnhide,
108-
currentProject.projectKey,
109-
`editor.${language}`,
110-
)}
111-
>
112-
<div className="label editors__label editors__label_collapsed">
113-
{t(`languages.${language}`)}
114-
{' '}
115-
<FontAwesomeIcon icon={faChevronUp} />
116-
</div>
117-
</div>
105+
projectKey={currentProject.projectKey}
106+
text={t(`languages.${language}`)}
107+
onComponentUnhide={onComponentUnhide}
108+
/>
118109
));
119110
});
120111

src/css/application.css

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,6 @@ body {
490490
flex: 1;
491491
}
492492

493-
.editors__collapsed-editor {
494-
border-top: 4px solid var(--color-light-gray);
495-
flex: none;
496-
}
497-
498493
.editors__label {
499494
text-align: right;
500495
}
@@ -508,6 +503,10 @@ body {
508503
z-index: 1;
509504
}
510505

506+
.editors__label_left {
507+
text-align: left;
508+
}
509+
511510
.editors__column-divider {
512511
background-color: var(--color-light-gray);
513512
width: 0.5vh;
@@ -540,6 +539,21 @@ body {
540539
pointer-events: none;
541540
}
542541

542+
/** @define collapsed-component */
543+
544+
.collapsed-component {
545+
border-top: 4px solid var(--color-light-gray);
546+
flex: none;
547+
}
548+
549+
.collapsed-component__label {
550+
text-align: right;
551+
}
552+
553+
.collapsed-component__label_left {
554+
text-align: left;
555+
}
556+
543557
/** @define output */
544558

545559
.output {

0 commit comments

Comments
 (0)