From 9ae236a0104828b6df3fa66a14f1db214f7ac72f Mon Sep 17 00:00:00 2001 From: Robert Pintilii Date: Tue, 18 Oct 2022 13:56:26 +0300 Subject: [PATCH] ref(keyboard-shortcuts) Change Dialog to function component (#12403) Use makeStyles instead of withStyles Fix style --- .../web/KeyboardShortcutsDialog.tsx | 102 +++++++----------- 1 file changed, 39 insertions(+), 63 deletions(-) diff --git a/react/features/keyboard-shortcuts/components/web/KeyboardShortcutsDialog.tsx b/react/features/keyboard-shortcuts/components/web/KeyboardShortcutsDialog.tsx index cf1728e7f..42528382a 100644 --- a/react/features/keyboard-shortcuts/components/web/KeyboardShortcutsDialog.tsx +++ b/react/features/keyboard-shortcuts/components/web/KeyboardShortcutsDialog.tsx @@ -1,22 +1,16 @@ import { Theme } from '@mui/material'; -import { withStyles } from '@mui/styles'; -import clsx from 'clsx'; -import React, { Component } from 'react'; -import { WithTranslation } from 'react-i18next'; +import React from 'react'; +import { useTranslation } from 'react-i18next'; +import { makeStyles } from 'tss-react/mui'; -import { translate } from '../../../base/i18n/functions'; +import { withPixelLineHeight } from '../../../base/styles/functions.web'; import Dialog from '../../../base/ui/components/web/Dialog'; /** * The type of the React {@code Component} props of * {@link KeyboardShortcutsDialog}. */ -interface Props extends WithTranslation { - - /** - * An object containing the CSS classes. - */ - classes: any; +interface Props { /** * A Map with keyboard keys as keys and translation keys as values. @@ -31,7 +25,7 @@ interface Props extends WithTranslation { * * @returns {Object} */ -const styles = (theme: Theme) => { +const useStyles = makeStyles()((theme: Theme) => { return { list: { listStyleType: 'none', @@ -40,7 +34,9 @@ const styles = (theme: Theme) => { '& .shortcuts-list__item': { display: 'flex', justifyContent: 'space-between', - marginBottom: theme.spacing(2) + marginBottom: theme.spacing(2), + ...withPixelLineHeight(theme.typography.labelRegular), + color: theme.palette.text01 }, '& .item-action': { @@ -51,51 +47,14 @@ const styles = (theme: Theme) => { } } }; -}; +}); -/** - * Implements a React {@link Component} which displays a dialog describing - * registered keyboard shortcuts. - * - * @augments Component - */ -class KeyboardShortcutsDialog extends Component { - /** - * Implements React's {@link Component#render()}. - * - * @inheritdoc - * @returns {ReactElement} - */ - render() { - const shortcuts = Array.from(this.props.shortcutDescriptions) - .map(description => this._renderShortcutsListItem(...description)); +const KeyboardShortcutsDialog = ({ shortcutDescriptions }: Props) => { + const { classes, cx } = useStyles(); + const { t } = useTranslation(); - return ( - -
-
    - {shortcuts} -
-
-
- ); - } - - /** - * Creates a {@code ReactElement} for describing a single keyboard shortcut. - * - * @param {string} keyboardKey - The keyboard key that triggers an action. - * @param {string} translationKey - A description of what the action does. - * @private - * @returns {ReactElement} - */ - _renderShortcutsListItem(keyboardKey: string, translationKey: string) { + // eslint-disable-next-line react/no-multi-comp + const _renderShortcutsListItem = (keyboardKey: string, translationKey: string) => { let modifierKey = 'Alt'; if (window.navigator?.platform) { @@ -109,18 +68,35 @@ class KeyboardShortcutsDialog extends Component { className = 'shortcuts-list__item' key = { keyboardKey }> - { this.props.t(translationKey) } + {t(translationKey)} - { keyboardKey.startsWith(':') + {keyboardKey.startsWith(':') ? `${modifierKey} + ${keyboardKey.slice(1)}` - : keyboardKey } + : keyboardKey} ); - } -} + }; -export default translate(withStyles(styles)(KeyboardShortcutsDialog)); + return ( + +
+
    + {Array.from(shortcutDescriptions) + .map(description => _renderShortcutsListItem(...description))} +
+
+
+ ); +}; + +export default KeyboardShortcutsDialog;