|
| 1 | +import classNames from 'classnames'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | +import React from 'react'; |
| 4 | +import { useTranslation } from 'react-i18next'; |
| 5 | +import { useDispatch, useSelector } from 'react-redux'; |
| 6 | +import LeftArrowIcon from '../../../images/left-arrow.svg'; |
| 7 | +import RightArrowIcon from '../../../images/right-arrow.svg'; |
| 8 | +import UnsavedChangesDotIcon from '../../../images/unsaved-changes-dot.svg'; |
| 9 | +import { collapseSidebar, expandSidebar } from '../actions/ide'; |
| 10 | +import EditorAccessibility from '../components/EditorAccessibility'; |
| 11 | +import Timer from '../components/Timer'; |
| 12 | +// import { selectActiveFile } from '../selectors/files'; |
| 13 | +const selectActiveFile = () => 'fix'; |
| 14 | + |
| 15 | +function EditorSection({ children }) { |
| 16 | + const { t } = useTranslation(); |
| 17 | + |
| 18 | + const dispatch = useDispatch(); |
| 19 | + |
| 20 | + const sidebarIsExpanded = useSelector((state) => state.ide.sidebarIsExpanded); |
| 21 | + const currentFile = useSelector(selectActiveFile); |
| 22 | + const hasUnsavedChanges = useSelector((state) => state.ide.unsavedChanges); |
| 23 | + const lintMessages = useSelector( |
| 24 | + (state) => state.editorAccessibility.lintMessages |
| 25 | + ); |
| 26 | + |
| 27 | + const editorSectionClass = classNames({ |
| 28 | + editor: true, |
| 29 | + 'sidebar--contracted': !sidebarIsExpanded |
| 30 | + }); |
| 31 | + |
| 32 | + return ( |
| 33 | + <section className={editorSectionClass}> |
| 34 | + <header className="editor__header"> |
| 35 | + <button |
| 36 | + aria-label={t('Editor.OpenSketchARIA')} |
| 37 | + className="sidebar__contract" |
| 38 | + onClick={() => dispatch(collapseSidebar())} |
| 39 | + > |
| 40 | + <LeftArrowIcon focusable="false" aria-hidden="true" /> |
| 41 | + </button> |
| 42 | + <button |
| 43 | + aria-label={t('Editor.CloseSketchARIA')} |
| 44 | + className="sidebar__expand" |
| 45 | + onClick={() => dispatch(expandSidebar())} |
| 46 | + > |
| 47 | + <RightArrowIcon focusable="false" aria-hidden="true" /> |
| 48 | + </button> |
| 49 | + <div className="editor__file-name"> |
| 50 | + <span> |
| 51 | + {currentFile.name} |
| 52 | + <span className="editor__unsaved-changes"> |
| 53 | + {hasUnsavedChanges ? ( |
| 54 | + <UnsavedChangesDotIcon |
| 55 | + role="img" |
| 56 | + aria-label={t('Editor.UnsavedChangesARIA')} |
| 57 | + focusable="false" |
| 58 | + /> |
| 59 | + ) : null} |
| 60 | + </span> |
| 61 | + </span> |
| 62 | + <Timer /> |
| 63 | + </div> |
| 64 | + </header> |
| 65 | + {children} |
| 66 | + <EditorAccessibility lintMessages={lintMessages} /> |
| 67 | + </section> |
| 68 | + ); |
| 69 | +} |
| 70 | + |
| 71 | +EditorSection.propTypes = { |
| 72 | + children: PropTypes.node.isRequired |
| 73 | +}; |
| 74 | + |
| 75 | +export default EditorSection; |
0 commit comments