Skip to content

Commit

Permalink
fix: Properties of buttons in the menu overlay component can't be cus…
Browse files Browse the repository at this point in the history
…tomized
  • Loading branch information
ZhijieZhang committed Sep 9, 2020
1 parent e042227 commit 7387032
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 62 deletions.
8 changes: 6 additions & 2 deletions src/components/ActionButton/ActionButton.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { connect } from 'react-redux';
import classNames from 'classnames';

import Button from 'components/Button';

const mapStateToProps = (state, { isNotClickableSelector }) => ({
className: 'ActionButton',
const mapStateToProps = (state, { isNotClickableSelector, className }) => ({
className: classNames({
ActionButton: true,
[className]: !!className,
}),
disabled: isNotClickableSelector && isNotClickableSelector(state),
});

Expand Down
92 changes: 45 additions & 47 deletions src/components/MenuOverlay/MenuOverlay.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import actions from 'actions';
import DataElementWrapper from 'components/DataElementWrapper';
import Icon from 'components/Icon';
import ActionButton from 'components/ActionButton';
import { workerTypes } from 'constants/types';
import core from 'core';
import { isIOS, isIE } from 'helpers/device';
Expand All @@ -23,8 +22,9 @@ function MenuOverlay() {

const activeTheme = useSelector(selectors.getActiveTheme);
const isEmbedPrintSupported = useSelector(selectors.isEmbedPrintSupported);
const colorMap = useSelector(selectors.getColorMap);
const sortStrategy = useSelector(selectors.getSortStrategy);
const isFullScreen = useSelector(selectors.isFullScreen);
const isFilePickerButtonDisabled = useSelector(state => selectors.isElementDisabled(state, 'filePickerButton'));

const closeMenuOverlay = useCallback(() => dispatch(actions.closeElements(['menuOverlay'])), [dispatch]);
const setActiveLightTheme = useCallback(() => dispatch(actions.setActiveTheme('light')), [dispatch]);
Expand All @@ -40,7 +40,7 @@ function MenuOverlay() {

const handlePrintButtonClick = () => {
closeMenuOverlay();
print(dispatch, isEmbedPrintSupported);
print(dispatch, isEmbedPrintSupported, sortStrategy, colorMap);
};

const downloadDocument = () => {
Expand All @@ -49,54 +49,52 @@ function MenuOverlay() {

return (
<FlyoutMenu menu="menuOverlay" trigger="menuButton" onClose={undefined}>
{!isFilePickerButtonDisabled && (
<DataElementWrapper className="row" dataElement="filePickerButton">
<button className="MenuItem" onClick={openFilePicker} aria-label={t('action.openFile')}>
<Icon className="MenuIcon" glyph="icon-header-file-picker-line" />
<div className="MenuLabel">{t('action.openFile')}</div>
</button>
</DataElementWrapper>
)}
<ActionButton
dataElement="filePickerButton"
className="row"
img="icon-header-file-picker-line"
label={t('action.openFile')}
ariaLabel={t('action.openFile')}
onClick={openFilePicker}
/>
{!isIOS && (
<div className="row">
<button
className="MenuItem"
onClick={toggleFullscreen}
aria-label={isFullScreen ? t('action.exitFullscreen') : t('action.enterFullscreen')}
>
<Icon
className="MenuIcon"
glyph={isFullScreen ? 'icon-header-full-screen-exit' : 'icon-header-full-screen'}
/>
<div className="MenuLabel">{isFullScreen ? t('action.exitFullscreen') : t('action.enterFullscreen')}</div>
</button>
</div>
<ActionButton
dataElement="fullscreenButton"
className="row"
img={isFullScreen ? 'icon-header-full-screen-exit' : 'icon-header-full-screen'}
label={isFullScreen ? t('action.exitFullscreen') : t('action.enterFullscreen')}
ariaLabel={isFullScreen ? t('action.exitFullscreen') : t('action.enterFullscreen')}
onClick={toggleFullscreen}
/>
)}
{documentType !== workerTypes.XOD && (
<DataElementWrapper className="row" dataElement="downloadButton">
<button className="MenuItem" onClick={downloadDocument} aria-label={t('action.download')}>
<Icon className="MenuIcon" glyph="icon-header-download" />
<div className="MenuLabel">{t('action.download')}</div>
</button>
</DataElementWrapper>
<ActionButton
dataElement="downloadButton"
className="row"
img="icon-header-download"
label={t('action.download')}
ariaLabel={t('action.download')}
onClick={downloadDocument}
/>
)}
<DataElementWrapper className="row" dataElement="printButton">
<button className="MenuItem" onClick={handlePrintButtonClick} aria-label={t('action.print')}>
<Icon className="MenuIcon" glyph="icon-header-print-line" />
<div className="MenuLabel">{t('action.print')}</div>
</button>
</DataElementWrapper>
<ActionButton
dataElement="printButton"
className="row"
img="icon-header-print-line"
label={t('action.print')}
ariaLabel={t('action.print')}
onClick={handlePrintButtonClick}
/>
{!isIE && (
<div className="row">
<button
className="MenuItem"
onClick={activeTheme === 'dark' ? setActiveLightTheme : setActiveDarkTheme}
aria-label={activeTheme === 'dark' ? t('action.lightMode') : t('action.darkMode')}
>
<Icon className="MenuIcon" glyph={`icon - header - mode - ${activeTheme === 'dark' ? 'day' : 'night'}`} />
<div className="MenuLabel">{activeTheme === 'dark' ? t('action.lightMode') : t('action.darkMode')}</div>
</button>
</div>)}
<ActionButton
dataElement="themeChangeButton"
className="row"
img={`icon - header - mode - ${activeTheme === 'dark' ? 'day' : 'night'}`}
label={activeTheme === 'dark' ? t('action.lightMode') : t('action.darkMode')}
ariaLabel={activeTheme === 'dark' ? t('action.lightMode') : t('action.darkMode')}
onClick={activeTheme === 'dark' ? setActiveLightTheme : setActiveDarkTheme}
/>
)}
</FlyoutMenu>
);
}
Expand Down
28 changes: 15 additions & 13 deletions src/components/MenuOverlay/MenuOverlay.scss
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
@import '../../constants/styles';
@import '../../constants/overlay';

.MenuItem {
@include button-reset;
width: 100%;
display: flex;
flex-direction: row;
align-items: center;
cursor: pointer;
border-radius: 4px;
.FlyoutMenu[data-element="menuOverlay"] {
.ActionButton {
justify-content: flex-start;

.MenuIcon {
margin: 4px;
.Icon {
margin: 4px;
}

span {
margin: 0 4px;
}
}

.MenuLabel {
margin: 0 4px;
// override the styles defined in FlyoutMenu.scss
.ActionButton.row.disabled:hover {
background: none;
cursor: default;
}
}
}

0 comments on commit 7387032

Please sign in to comment.