convert whiteboard-toolbar component

This commit is contained in:
Ramón Souza 2021-11-02 20:05:49 +00:00
parent e7b282a127
commit 1c084c6b8f
6 changed files with 102 additions and 34 deletions

View File

@ -1,11 +1,11 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import cx from 'classnames';
import { HEXToINTColor, INTToHEXColor } from '/imports/utils/hexInt'; import { HEXToINTColor, INTToHEXColor } from '/imports/utils/hexInt';
import { defineMessages, injectIntl } from 'react-intl'; import { defineMessages, injectIntl } from 'react-intl';
import KEY_CODES from '/imports/utils/keyCodes'; import KEY_CODES from '/imports/utils/keyCodes';
import injectWbResizeEvent from '/imports/ui/components/presentation/resize-wrapper/component'; import injectWbResizeEvent from '/imports/ui/components/presentation/resize-wrapper/component';
import { styles } from './styles.scss'; import { styles } from './styles.scss';
import Styled from './styles';
import ToolbarMenuItem from './toolbar-menu-item/component'; import ToolbarMenuItem from './toolbar-menu-item/component';
import ToolbarSubmenu from './toolbar-submenu/component'; import ToolbarSubmenu from './toolbar-submenu/component';
@ -505,7 +505,6 @@ class WhiteboardToolbar extends Component {
icon="hand" icon="hand"
label={intl.formatMessage(intlMessages.toolbarItemPan)} label={intl.formatMessage(intlMessages.toolbarItemPan)}
onItemClick={() => { }} onItemClick={() => { }}
className={styles.toolbarButton}
/> />
) : ( ) : (
<ToolbarMenuItem <ToolbarMenuItem
@ -517,7 +516,6 @@ class WhiteboardToolbar extends Component {
onItemClick={this.displaySubMenu} onItemClick={this.displaySubMenu}
objectToReturn="annotationList" objectToReturn="annotationList"
onBlur={this.closeSubMenu} onBlur={this.closeSubMenu}
className={cx(styles.toolbarButton, currentSubmenuOpen === 'annotationList' ? styles.toolbarActive : null)}
showCornerTriangle showCornerTriangle
> >
{currentSubmenuOpen === 'annotationList' && annotations.length > 1 {currentSubmenuOpen === 'annotationList' && annotations.length > 1
@ -552,7 +550,6 @@ class WhiteboardToolbar extends Component {
onItemClick={this.displaySubMenu} onItemClick={this.displaySubMenu}
objectToReturn="fontSizeList" objectToReturn="fontSizeList"
onBlur={this.closeSubMenu} onBlur={this.closeSubMenu}
className={cx(styles.toolbarButton, currentSubmenuOpen === 'fontSizeList' ? styles.toolbarActive : null)}
showCornerTriangle showCornerTriangle
> >
{currentSubmenuOpen === 'fontSizeList' {currentSubmenuOpen === 'fontSizeList'
@ -577,8 +574,7 @@ class WhiteboardToolbar extends Component {
renderFontItemIcon() { renderFontItemIcon() {
const { fontSizeSelected, colorSelected } = this.state; const { fontSizeSelected, colorSelected } = this.state;
return ( return (
<p <Styled.TextThickness
className={styles.textThickness}
style={{ style={{
fontSize: fontSizeSelected.value <= 32 ? fontSizeSelected.value : 32, fontSize: fontSizeSelected.value <= 32 ? fontSizeSelected.value : 32,
color: colorSelected.value, color: colorSelected.value,
@ -587,7 +583,7 @@ class WhiteboardToolbar extends Component {
}} }}
> >
Aa Aa
</p> </Styled.TextThickness>
); );
} }
@ -616,7 +612,6 @@ class WhiteboardToolbar extends Component {
onItemClick={this.displaySubMenu} onItemClick={this.displaySubMenu}
objectToReturn="thicknessList" objectToReturn="thicknessList"
onBlur={this.closeSubMenu} onBlur={this.closeSubMenu}
className={cx(styles.toolbarButton, currentSubmenuOpen === 'thicknessList' ? styles.toolbarActive : null)}
customIcon={this.renderThicknessItemIcon()} customIcon={this.renderThicknessItemIcon()}
showCornerTriangle showCornerTriangle
> >
@ -648,7 +643,7 @@ class WhiteboardToolbar extends Component {
} = this.state; } = this.state;
return ( return (
<svg className={styles.customSvgIcon} shapeRendering="geometricPrecision"> <Styled.CustomSvgIcon shapeRendering="geometricPrecision">
<circle <circle
shapeRendering="geometricPrecision" shapeRendering="geometricPrecision"
cx="50%" cx="50%"
@ -681,7 +676,7 @@ class WhiteboardToolbar extends Component {
fill="freeze" fill="freeze"
/> />
</circle> </circle>
</svg> </Styled.CustomSvgIcon>
); );
} }
@ -710,7 +705,6 @@ class WhiteboardToolbar extends Component {
onItemClick={this.displaySubMenu} onItemClick={this.displaySubMenu}
objectToReturn="colorList" objectToReturn="colorList"
onBlur={this.closeSubMenu} onBlur={this.closeSubMenu}
className={cx(styles.toolbarButton, currentSubmenuOpen === 'colorList' ? styles.toolbarActive : null)}
customIcon={this.renderColorItemIcon()} customIcon={this.renderColorItemIcon()}
showCornerTriangle showCornerTriangle
> >
@ -740,7 +734,7 @@ class WhiteboardToolbar extends Component {
} = this.state; } = this.state;
return ( return (
<svg className={styles.customSvgIcon}> <Styled.CustomSvgIcon>
<rect x="25%" y="25%" width="50%" height="50%" stroke="black" strokeWidth="1" fill={colorSelected.value}> <rect x="25%" y="25%" width="50%" height="50%" stroke="black" strokeWidth="1" fill={colorSelected.value}>
<animate <animate
ref={(ref) => { this.colorListIconColor = ref; }} ref={(ref) => { this.colorListIconColor = ref; }}
@ -754,7 +748,7 @@ class WhiteboardToolbar extends Component {
fill="freeze" fill="freeze"
/> />
</rect> </rect>
</svg> </Styled.CustomSvgIcon>
); );
} }
@ -767,7 +761,6 @@ class WhiteboardToolbar extends Component {
label={intl.formatMessage(intlMessages.toolbarUndoAnnotation)} label={intl.formatMessage(intlMessages.toolbarUndoAnnotation)}
icon="undo" icon="undo"
onItemClick={this.handleUndo} onItemClick={this.handleUndo}
className={styles.toolbarButton}
/> />
); );
} }
@ -781,7 +774,6 @@ class WhiteboardToolbar extends Component {
label={intl.formatMessage(intlMessages.toolbarClearAnnotations)} label={intl.formatMessage(intlMessages.toolbarClearAnnotations)}
icon="delete" icon="delete"
onItemClick={this.handleClearAll} onItemClick={this.handleClearAll}
className={styles.toolbarButton}
/> />
); );
} }
@ -795,8 +787,8 @@ class WhiteboardToolbar extends Component {
} = this.props; } = this.props;
return ( return (
<span className={styles.multiUserToolItem} data-test={multiUser ? 'multiWhiteboardTool' : 'whiteboardTool'}> <span data-test={multiUser ? 'multiWhiteboardTool' : 'whiteboardTool'}>
{multiUser && <span className={styles.multiUserTool}>{multiUserSize}</span>} {multiUser && <Styled.MultiUserTool>{multiUserSize}</Styled.MultiUserTool>}
<ToolbarMenuItem <ToolbarMenuItem
disabled={!isMeteorConnected} disabled={!isMeteorConnected}
label={multiUser label={multiUser
@ -805,7 +797,6 @@ class WhiteboardToolbar extends Component {
} }
icon={multiUser ? 'multi_whiteboard' : 'whiteboard'} icon={multiUser ? 'multi_whiteboard' : 'whiteboard'}
onItemClick={this.handleSwitchWhiteboardMode} onItemClick={this.handleSwitchWhiteboardMode}
className={styles.toolbarButton}
/> />
</span> </span>
); );
@ -825,7 +816,6 @@ class WhiteboardToolbar extends Component {
} }
icon={palmRejection ? 'palm_rejection' : 'no_palm_rejection'} icon={palmRejection ? 'palm_rejection' : 'no_palm_rejection'}
onItemClick={this.handleSwitchPalmRejectionMode} onItemClick={this.handleSwitchPalmRejectionMode}
className={styles.toolbarButton}
/> />
); );
} }
@ -834,7 +824,7 @@ class WhiteboardToolbar extends Component {
const { annotationSelected } = this.state; const { annotationSelected } = this.state;
const { isPresenter, intl } = this.props; const { isPresenter, intl } = this.props;
return ( return (
<div className={styles.toolbarContainer} role="region" aria-label={intl.formatMessage(intlMessages.toolbarAriaLabel)}> <Styled.ToolbarContainer role="region" aria-label={intl.formatMessage(intlMessages.toolbarAriaLabel)}>
<div className={styles.toolbarWrapper}> <div className={styles.toolbarWrapper}>
{this.renderToolItem()} {this.renderToolItem()}
{annotationSelected.value === 'text' ? this.renderFontItem() : this.renderThicknessItem()} {annotationSelected.value === 'text' ? this.renderFontItem() : this.renderThicknessItem()}
@ -844,7 +834,7 @@ class WhiteboardToolbar extends Component {
{window.PointerEvent ? this.renderPalmRejectionItem() : null} {window.PointerEvent ? this.renderPalmRejectionItem() : null}
{isPresenter ? this.renderMultiUserItem() : null} {isPresenter ? this.renderMultiUserItem() : null}
</div> </div>
</div> </Styled.ToolbarContainer>
); );
} }
} }

View File

@ -0,0 +1,82 @@
import styled from 'styled-components';
import {
toolbarListColor,
toolbarListBgFocus,
colorDanger,
colorWhite,
colorGrayDark,
} from '/imports/ui/stylesheets/styled-components/palette';
import {
toolbarButtonWidth,
toolbarButtonHeight,
lgPaddingX,
borderSizeLarge,
smPaddingX,
toolbarMargin,
} from '/imports/ui/stylesheets/styled-components/general';
import { smallOnly } from '/imports/ui/stylesheets/styled-components/breakpoints';
const TextThickness = styled.p`
font-family: Arial, sans-serif;
font-weight: normal;
text-shadow: -1px 0 ${toolbarListBgFocus}, 0 1px ${toolbarListBgFocus}, 1px 0 ${toolbarListBgFocus}, 0 -1px ${toolbarListBgFocus};
margin: auto;
color: ${toolbarListColor};
`;
const CustomSvgIcon = styled.svg`
position: absolute;
width: ${toolbarButtonWidth};
height: ${toolbarButtonHeight};
left: 0;
top: 0;
`;
const MultiUserTool = styled.span`
background-color: ${colorDanger};
border-radius: 50%;
width: ${lgPaddingX};
height: ${lgPaddingX};
position: absolute;
z-index: 2;
right: 0px;
color: ${colorWhite};
display: flex;
justify-content: center;
align-items: center;
box-shadow: 1px 1px ${borderSizeLarge} ${colorGrayDark};
font-size: ${smPaddingX};
`;
const ToolbarContainer = styled.div`
display: flex;
flex-direction: column;
justify-content: center;
margin: 0 ${toolbarMargin} 0 0;
position: absolute;
top: 0;
right: 0;
left: auto;
bottom: 0;
pointer-events: none;
z-index: 3;
[dir="rtl"] & {
margin: 0 0 0 ${toolbarMargin};
right: auto;
left: 0;
}
@media ${smallOnly} {
transform: scale(.75);
transform-origin: right;
}
`;
export default {
TextThickness,
CustomSvgIcon,
MultiUserTool,
ToolbarContainer,
};

View File

@ -71,7 +71,6 @@ export default class ToolbarMenuItem extends Component {
icon, icon,
customIcon, customIcon,
onBlur, onBlur,
toolbarActive,
children, children,
showCornerTriangle, showCornerTriangle,
expanded, expanded,
@ -84,7 +83,7 @@ export default class ToolbarMenuItem extends Component {
hidden={disabled} hidden={disabled}
> >
<Styled.ToolbarButton <Styled.ToolbarButton
state={toolbarActive ? 'active' : 'inactive'} state={expanded ? 'active' : 'inactive'}
aria-expanded={expanded} aria-expanded={expanded}
aria-haspopup={haspopup} aria-haspopup={haspopup}
hideLabel hideLabel

View File

@ -50,13 +50,13 @@ export default class ToolbarSubmenuItem extends Component {
customIcon, customIcon,
icon, icon,
label, label,
selected, toolbarActive,
} = this.props; } = this.props;
return ( return (
<Styled.ButtonWrapper> <Styled.ButtonWrapper>
<Styled.SubmenuButton <Styled.SubmenuButton
state={selected ? 'selected' : 'unselected'} state={toolbarActive ? 'selected' : 'unselected'}
hideLabel hideLabel
role="button" role="button"
color="default" color="default"

View File

@ -11,7 +11,7 @@ import {
toolbarButtonBorderColor, toolbarButtonBorderColor,
toolbarListColor, toolbarListColor,
toolbarButtonColor, toolbarButtonColor,
toolbarButtonBg, toolbarListBg,
toolbarListBgFocus, toolbarListBgFocus,
} from '/imports/ui/stylesheets/styled-components/palette'; } from '/imports/ui/stylesheets/styled-components/palette';
import { toolbarButtonFontSize } from '/imports/ui/stylesheets/styled-components/typography'; import { toolbarButtonFontSize } from '/imports/ui/stylesheets/styled-components/typography';
@ -31,13 +31,7 @@ const ButtonWrapper = styled.div`
&:first-child > button { &:first-child > button {
border-top-left-radius: ${toolbarButtonBorderRadius}; border-top-left-radius: ${toolbarButtonBorderRadius};
border-top-right-radius: ${toolbarButtonBorderRadius};
}
&:last-child > button {
border-bottom: 0;
border-bottom-left-radius: ${toolbarButtonBorderRadius}; border-bottom-left-radius: ${toolbarButtonBorderRadius};
border-bottom-right-radius: ${toolbarButtonBorderRadius};
} }
`; `;
@ -56,8 +50,8 @@ const SubmenuButton = styled(Button)`
z-index: 1; z-index: 1;
font-size: ${toolbarButtonFontSize}; font-size: ${toolbarButtonFontSize};
color: ${toolbarButtonColor}; color: ${toolbarButtonColor};
background-color: ${toolbarButtonBg};
border-color: ${toolbarButtonBorderColor}; border-color: ${toolbarButtonBorderColor};
background-color: ${toolbarListBg};
&:focus, &:focus,
&:hover { &:hover {
@ -65,11 +59,12 @@ const SubmenuButton = styled(Button)`
} }
& > i { & > i {
color: ${toolbarButtonColor}; color: ${toolbarListColor};
} }
${({ state }) => state === 'selected' && ` ${({ state }) => state === 'selected' && `
background-color: ${toolbarListColor} !important; background-color: ${toolbarListColor} !important;
background:red;
& > i { & > i {
color: ${toolbarListBgFocus} !important; color: ${toolbarListBgFocus} !important;

View File

@ -37,6 +37,7 @@ const toolbarItemOutlineOffset = '-.19rem';
const toolbarButtonBorder = '1px'; const toolbarButtonBorder = '1px';
const toolbarButtonBorderRadius = '5px'; const toolbarButtonBorderRadius = '5px';
const toolbarItemTrianglePadding = '2px'; const toolbarItemTrianglePadding = '2px';
const toolbarMargin = '.8rem';
export { export {
borderSizeSmall, borderSizeSmall,
@ -75,4 +76,5 @@ export {
toolbarButtonBorder, toolbarButtonBorder,
toolbarButtonBorderRadius, toolbarButtonBorderRadius,
toolbarItemTrianglePadding, toolbarItemTrianglePadding,
toolbarMargin,
}; };