feat(toolbar-buttons) Add optional background color (#13691)

pull/13694/head jitsi-meet_8888
Horatiu Muresan 2 years ago committed by GitHub
parent 85fb7513db
commit 91de33550d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      config.js
  2. 2
      react/features/base/config/configType.ts
  3. 12
      react/features/base/toolbox/components/AbstractButton.tsx
  4. 15
      react/features/base/toolbox/components/ToolboxItem.web.tsx
  5. 9
      react/features/base/ui/components/web/ContextMenuItem.tsx
  6. 2
      react/features/toolbox/components/web/CustomOptionButton.tsx
  7. 2
      react/features/toolbox/components/web/Toolbox.tsx
  8. 4
      react/features/toolbox/functions.web.ts

@ -871,7 +871,7 @@ var config = {
// customParticipantMenuButtons: [], // customParticipantMenuButtons: [],
// An array with custom option buttons for the toolbar // An array with custom option buttons for the toolbar
// type: Array<{ icon: string; id: string; text: string; }> // type: Array<{ icon: string; id: string; text: string; backgroundColor?: string; }>
// customToolbarButtons: [], // customToolbarButtons: [],
// Stats // Stats

@ -270,7 +270,7 @@ export interface IConfig {
}; };
corsAvatarURLs?: Array<string>; corsAvatarURLs?: Array<string>;
customParticipantMenuButtons?: Array<{ icon: string; id: string; text: string; }>; customParticipantMenuButtons?: Array<{ icon: string; id: string; text: string; }>;
customToolbarButtons?: Array<{ icon: string; id: string; text: string; }>; customToolbarButtons?: Array<{ backgroundColor?: string; icon: string; id: string; text: string; }>;
deeplinking?: IDeeplinkingConfig; deeplinking?: IDeeplinkingConfig;
defaultLanguage?: string; defaultLanguage?: string;
defaultLocalDisplayName?: string; defaultLocalDisplayName?: string;

@ -16,6 +16,11 @@ export interface IProps extends WithTranslation {
*/ */
afterClick?: Function; afterClick?: Function;
/**
* The button's background color.
*/
backgroundColor?: string;
/** /**
* The button's key. * The button's key.
*/ */
@ -108,6 +113,13 @@ export default class AbstractButton<P extends IProps, S=any> extends Component<P
visible: true visible: true
}; };
/**
* The button's background color.
*
* @abstract
*/
backgroundColor?: string;
/** /**
* A succinct description of what the button does. Used by accessibility * A succinct description of what the button does. Used by accessibility
* tools and torture tests. * tools and torture tests.

@ -9,6 +9,11 @@ import type { IProps as AbstractToolboxItemProps } from './AbstractToolboxItem';
interface IProps extends AbstractToolboxItemProps { interface IProps extends AbstractToolboxItemProps {
/**
* The button's background color.
*/
backgroundColor?: string;
/** /**
* Whether or not the item is displayed in a context menu. * Whether or not the item is displayed in a context menu.
*/ */
@ -60,6 +65,7 @@ export default class ToolboxItem extends AbstractToolboxItem<IProps> {
*/ */
_renderItem() { _renderItem() {
const { const {
backgroundColor,
contextMenu, contextMenu,
disabled, disabled,
elementAfter, elementAfter,
@ -90,6 +96,7 @@ export default class ToolboxItem extends AbstractToolboxItem<IProps> {
return ( return (
<ContextMenuItem <ContextMenuItem
accessibilityLabel = { this.accessibilityLabel } accessibilityLabel = { this.accessibilityLabel }
backgroundColor = { backgroundColor }
disabled = { disabled } disabled = { disabled }
icon = { icon } icon = { icon }
onClick = { onClick } onClick = { onClick }
@ -128,14 +135,18 @@ export default class ToolboxItem extends AbstractToolboxItem<IProps> {
* @returns {ReactElement} * @returns {ReactElement}
*/ */
_renderIcon() { _renderIcon() {
const { customClass, disabled, icon, showLabel, toggled } = this.props; const { backgroundColor, customClass, disabled, icon, showLabel, toggled } = this.props;
const iconComponent = (<Icon const iconComponent = (<Icon
size = { showLabel ? undefined : 24 } size = { showLabel ? undefined : 24 }
src = { icon } />); src = { icon } />);
const elementType = showLabel ? 'span' : 'div'; const elementType = showLabel ? 'span' : 'div';
const className = `${showLabel ? 'overflow-menu-item-icon' : 'toolbox-icon'} ${ const className = `${showLabel ? 'overflow-menu-item-icon' : 'toolbox-icon'} ${
toggled ? 'toggled' : ''} ${disabled ? 'disabled' : ''} ${customClass ?? ''}`; toggled ? 'toggled' : ''} ${disabled ? 'disabled' : ''} ${customClass ?? ''}`;
const style = backgroundColor && !showLabel ? { backgroundColor } : {};
return React.createElement(elementType, { className }, iconComponent); return React.createElement(elementType, {
className,
style
}, iconComponent);
} }
} }

@ -16,6 +16,11 @@ export interface IProps {
*/ */
accessibilityLabel: string; accessibilityLabel: string;
/**
* The context menu item background color.
*/
backgroundColor?: string;
/** /**
* Component children. * Component children.
*/ */
@ -163,6 +168,7 @@ const useStyles = makeStyles()(theme => {
const ContextMenuItem = ({ const ContextMenuItem = ({
accessibilityLabel, accessibilityLabel,
backgroundColor,
children, children,
className, className,
controls, controls,
@ -181,7 +187,7 @@ const ContextMenuItem = ({
textClassName }: IProps) => { textClassName }: IProps) => {
const { classes: styles, cx } = useStyles(); const { classes: styles, cx } = useStyles();
const _overflowDrawer: boolean = useSelector(showOverflowDrawer); const _overflowDrawer: boolean = useSelector(showOverflowDrawer);
const style = backgroundColor ? { backgroundColor } : {};
const onKeyPressHandler = useCallback(e => { const onKeyPressHandler = useCallback(e => {
// only trigger the fallback behavior (onClick) if we dont have any explicit keyboard event handler // only trigger the fallback behavior (onClick) if we dont have any explicit keyboard event handler
if (onClick && !onKeyPress && !onKeyDown && (e.key === 'Enter' || e.key === ' ')) { if (onClick && !onKeyPress && !onKeyDown && (e.key === 'Enter' || e.key === ' ')) {
@ -223,6 +229,7 @@ const ContextMenuItem = ({
onKeyDown = { disabled ? undefined : onKeyDown } onKeyDown = { disabled ? undefined : onKeyDown }
onKeyPress = { disabled ? undefined : onKeyPressHandler } onKeyPress = { disabled ? undefined : onKeyPressHandler }
role = { onClick ? role : undefined } role = { onClick ? role : undefined }
style = { style }
tabIndex = { onClick ? tabIndex : undefined }> tabIndex = { onClick ? tabIndex : undefined }>
{customIcon ? customIcon {customIcon ? customIcon
: icon && <Icon : icon && <Icon

@ -4,6 +4,7 @@ import AbstractButton, { IProps as AbstractButtonProps } from '../../../base/too
interface IProps extends AbstractButtonProps { interface IProps extends AbstractButtonProps {
backgroundColor?: string;
icon: string; icon: string;
id?: string; id?: string;
text: string; text: string;
@ -18,6 +19,7 @@ class CustomOptionButton extends AbstractButton<IProps> {
iconSrc = this.props.icon; iconSrc = this.props.icon;
id = this.props.id; id = this.props.id;
text = this.props.text; text = this.props.text;
backgroundColor = this.props.backgroundColor;
accessibilityLabel = this.text; accessibilityLabel = this.text;

@ -63,7 +63,7 @@ interface IProps extends WithTranslation {
/** /**
* Custom Toolbar buttons. * Custom Toolbar buttons.
*/ */
_customToolbarButtons?: Array<{ icon: string; id: string; text: string; }>; _customToolbarButtons?: Array<{ backgroundColor?: string; icon: string; id: string; text: string; }>;
/** /**
* Whether or not a dialog is displayed. * Whether or not a dialog is displayed.

@ -199,6 +199,7 @@ export function getToolbarTimeout(state: IReduxState) {
* @returns {Object} The button maps mainMenuButtons and overflowMenuButtons. * @returns {Object} The button maps mainMenuButtons and overflowMenuButtons.
*/ */
export function getAllToolboxButtons(_customToolbarButtons?: { export function getAllToolboxButtons(_customToolbarButtons?: {
backgroundColor?: string;
icon: string; icon: string;
id: string; id: string;
text: string; text: string;
@ -395,10 +396,11 @@ export function getAllToolboxButtons(_customToolbarButtons?: {
group: 4 group: 4
}; };
const customButtons = _customToolbarButtons?.reduce((prev, { icon, id, text }) => { const customButtons = _customToolbarButtons?.reduce((prev, { backgroundColor, icon, id, text }) => {
return { return {
...prev, ...prev,
[id]: { [id]: {
backgroundColor,
key: id, key: id,
Content: CustomOptionButton, Content: CustomOptionButton,
group: 4, group: 4,

Loading…
Cancel
Save