// Copyright 2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import type { ReactChild } from 'react'; import React, { useState } from 'react'; import { noop } from 'lodash'; import type { LocalizerType } from '../types/Util'; import { Button, ButtonVariant } from './Button'; import { Spinner } from './Spinner'; export enum CallingLobbyJoinButtonVariant { CallIsFull = 'CallIsFull', Join = 'Join', Loading = 'Loading', Start = 'Start', AskToJoin = 'AskToJoin', } type PropsType = { disabled?: boolean; i18n: LocalizerType; onClick: () => void; variant: CallingLobbyJoinButtonVariant; }; /** * This component is a little weird. Why not just render a button with some children? * * The contents of this component can change but we don't want its size to change, so we * render all the variants invisibly, compute the maximum size, and then render the * "final" button with those dimensions. * * For example, we might initially render "Join call" and then render a spinner when you * click the button. The button shouldn't resize in that situation. */ export function CallingLobbyJoinButton({ disabled, i18n, onClick, variant, }: PropsType): JSX.Element { const [width, setWidth] = useState(); const [height, setHeight] = useState(); const childrenByVariant: Record = { [CallingLobbyJoinButtonVariant.CallIsFull]: i18n( 'icu:CallingLobbyJoinButton--call-full' ), [CallingLobbyJoinButtonVariant.Loading]: ( ), [CallingLobbyJoinButtonVariant.Join]: i18n( 'icu:CallingLobbyJoinButton--join' ), [CallingLobbyJoinButtonVariant.Start]: i18n( 'icu:CallingLobbyJoinButton--start' ), [CallingLobbyJoinButtonVariant.AskToJoin]: i18n( 'icu:CallingLobbyJoinButton--ask-to-join' ), }; return ( <> {Boolean(width && height) && ( )}
{Object.values(CallingLobbyJoinButtonVariant).map(candidateVariant => ( ))}
); }