From 40637aa3dcc25be6a1a506787dd995882547d93e Mon Sep 17 00:00:00 2001 From: Robert Pintilii Date: Mon, 22 Aug 2022 12:40:59 +0300 Subject: [PATCH] ref(ui-components) Improve Button component (#12015) Bring web and native more in line --- ...aseTheme.native.js => BaseTheme.native.ts} | 2 -- .../base/ui/components/native/Button.tsx | 13 ++++----- react/features/base/ui/components/types.ts | 11 ++++++-- ...eTheme.native.js => updateTheme.native.ts} | 2 -- .../base/ui/components/web/Button.tsx | 15 ++++++---- react/features/base/ui/constants.ts | 4 ++- ...unctions.native.js => functions.native.ts} | 4 +-- react/features/base/ui/utils.ts | 2 +- .../native/LonelyMeetingExperience.js | 6 ++-- .../native/carmode/EndMeetingButton.tsx | 5 ++-- .../native/carmode/SoundDeviceButton.tsx | 5 ++-- .../lobby/components/native/LobbyScreen.js | 20 ++++++------- .../native/AddBreakoutRoomButton.tsx | 4 +-- .../components/native/AutoAssignButton.tsx | 4 +-- .../native/LeaveBreakoutRoomButton.tsx | 4 +-- .../components/web/AddBreakoutRoomButton.tsx | 2 +- .../components/web/AutoAssignButton.tsx | 2 +- .../components/web/JoinQuickActionButton.tsx | 2 +- .../components/web/LeaveButton.tsx | 2 +- .../components/native/LobbyParticipantItem.js | 4 +-- .../components/native/LobbyParticipantList.js | 4 +-- .../native/MeetingParticipantList.js | 4 +-- .../native/ParticipantsPaneFooter.tsx | 4 +-- .../components/web/InviteButton.tsx | 2 +- .../components/web/LobbyParticipantItem.js | 4 +-- .../components/web/ParticipantsPane.tsx | 2 +- .../polls/components/native/PollAnswer.js | 8 +++--- .../polls/components/native/PollCreate.js | 12 ++++---- .../polls/components/native/PollsPane.js | 4 +-- .../polls/components/web/PollAnswer.tsx | 4 +-- .../polls/components/web/PollCreate.tsx | 6 ++-- .../polls/components/web/PollsPane.tsx | 3 +- .../prejoin/components/Prejoin.native.tsx | 8 +++--- .../components/native/RaiseHandButton.js | 4 +-- .../Recording/native/HighlightDialog.js | 8 +++--- .../security-dialog/native/SecurityDialog.js | 28 +++++++++---------- 36 files changed, 110 insertions(+), 108 deletions(-) rename react/features/base/ui/components/{BaseTheme.native.js => BaseTheme.native.ts} (96%) rename react/features/base/ui/components/{updateTheme.native.js => updateTheme.native.ts} (95%) rename react/features/base/ui/{functions.native.js => functions.native.ts} (91%) diff --git a/react/features/base/ui/components/BaseTheme.native.js b/react/features/base/ui/components/BaseTheme.native.ts similarity index 96% rename from react/features/base/ui/components/BaseTheme.native.js rename to react/features/base/ui/components/BaseTheme.native.ts index bdb0ea6f8..097555310 100644 --- a/react/features/base/ui/components/BaseTheme.native.js +++ b/react/features/base/ui/components/BaseTheme.native.ts @@ -1,5 +1,3 @@ -// @flow - import { font, colors, colorMap, spacing, shape, typography } from '../Tokens'; import { createNativeTheme } from '../functions.native'; diff --git a/react/features/base/ui/components/native/Button.tsx b/react/features/base/ui/components/native/Button.tsx index 46caad690..24aa4fc75 100644 --- a/react/features/base/ui/components/native/Button.tsx +++ b/react/features/base/ui/components/native/Button.tsx @@ -8,7 +8,6 @@ import { } from 'react-native-paper'; import { BUTTON_MODES, BUTTON_TYPES } from '../../constants'; -// @ts-ignore import BaseTheme from '../BaseTheme.native'; import { ButtonProps } from '../types'; @@ -17,7 +16,6 @@ import styles from './buttonStyles'; export interface IButtonProps extends ButtonProps { color?: string; labelStyle?: Object | undefined; - onPress?: Function; style?: Object | undefined; } @@ -26,9 +24,9 @@ const Button: React.FC = ({ color: buttonColor, disabled, icon, - label, + labelKey, labelStyle, - onPress, + onClick: onPress, style, type }: IButtonProps) => { @@ -70,7 +68,6 @@ const Button: React.FC = ({ = ({ style = { [ buttonLabelStyles, labelStyle - ] }>{ t(label ?? '') } + ] }>{ t(labelKey ?? '') } ); } return ( - // @ts-ignore | GestureResponderEvent) => void; /** * The type of button to be displayed. diff --git a/react/features/base/ui/components/updateTheme.native.js b/react/features/base/ui/components/updateTheme.native.ts similarity index 95% rename from react/features/base/ui/components/updateTheme.native.js rename to react/features/base/ui/components/updateTheme.native.ts index bdbe074dc..17f62d510 100644 --- a/react/features/base/ui/components/updateTheme.native.js +++ b/react/features/base/ui/components/updateTheme.native.ts @@ -1,5 +1,3 @@ -// @flow - /** * Custom theme for setting client branding. * diff --git a/react/features/base/ui/components/web/Button.tsx b/react/features/base/ui/components/web/Button.tsx index 692379139..91491b1b7 100644 --- a/react/features/base/ui/components/web/Button.tsx +++ b/react/features/base/ui/components/web/Button.tsx @@ -1,6 +1,7 @@ import { makeStyles } from '@material-ui/core'; import clsx from 'clsx'; import React from 'react'; +import { useTranslation } from 'react-i18next'; import Icon from '../../../icons/components/Icon'; import { withPixelLineHeight } from '../../../styles/functions.web'; @@ -8,7 +9,6 @@ import { BUTTON_TYPES } from '../../constants'; import { Theme } from '../../types'; import { ButtonProps } from '../types'; - interface IButtonProps extends ButtonProps { /** @@ -32,9 +32,10 @@ interface IButtonProps extends ButtonProps { isSubmit?: boolean; /** - * Click callback. + * Text to be displayed on the component. + * Used when there's no labelKey. */ - onClick?: (e?: React.MouseEvent) => void; + label?: string; /** * Which size the button should be. @@ -185,19 +186,21 @@ const Button = ({ id, isSubmit, label, + labelKey, onClick = () => null, size = 'medium', testId, type = BUTTON_TYPES.PRIMARY }: IButtonProps) => { const styles = useStyles(); + const { t } = useTranslation(); return ( ); }; diff --git a/react/features/base/ui/constants.ts b/react/features/base/ui/constants.ts index 4664bc769..b8bd8876d 100644 --- a/react/features/base/ui/constants.ts +++ b/react/features/base/ui/constants.ts @@ -13,7 +13,9 @@ export enum BUTTON_TYPES { /** * The modes of the buttons. */ -export const BUTTON_MODES = { +export const BUTTON_MODES: { + CONTAINED: 'contained' +} = { CONTAINED: 'contained' }; diff --git a/react/features/base/ui/functions.native.js b/react/features/base/ui/functions.native.ts similarity index 91% rename from react/features/base/ui/functions.native.js rename to react/features/base/ui/functions.native.ts index 794f6af33..6c3ab9950 100644 --- a/react/features/base/ui/functions.native.js +++ b/react/features/base/ui/functions.native.ts @@ -1,5 +1,3 @@ -// @flow - import { DefaultTheme } from 'react-native-paper'; import { createColorTokens } from './utils'; @@ -10,7 +8,7 @@ import { createColorTokens } from './utils'; * @param {Object} arg - The ui tokens. * @returns {Object} */ -export function createNativeTheme({ font, colors, colorMap, shape, spacing, typography }: Object) { +export function createNativeTheme({ font, colors, colorMap, shape, spacing, typography }: any): any { return { ...DefaultTheme, palette: createColorTokens(colorMap, colors), diff --git a/react/features/base/ui/utils.ts b/react/features/base/ui/utils.ts index 5bc8485ae..e474d702b 100644 --- a/react/features/base/ui/utils.ts +++ b/react/features/base/ui/utils.ts @@ -6,7 +6,7 @@ * @param {Object} colors - An object containing all the theme colors. * @returns {Object} */ -export function createColorTokens(colorMap: Object, colors: Object): Object { +export function createColorTokens(colorMap: Object, colors: Object): any { return Object.entries(colorMap) .reduce((result, [ token, value ]: [any, keyof Object]) => Object.assign(result, { [token]: colors[value] || value }), {}); diff --git a/react/features/conference/components/native/LonelyMeetingExperience.js b/react/features/conference/components/native/LonelyMeetingExperience.js index 8babef756..b2f1a2d07 100644 --- a/react/features/conference/components/native/LonelyMeetingExperience.js +++ b/react/features/conference/components/native/LonelyMeetingExperience.js @@ -21,7 +21,7 @@ type Props = { /** * True if currently in a breakout room. */ - _isInBreakoutRoom: boolean, + _isInBreakoutRoom: boolean, /** * True if the invite functions (dial out, invite, share...etc) are disabled. @@ -98,8 +98,8 @@ class LonelyMeetingExperience extends PureComponent {