// Copyright 2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React, { FunctionComponent, ReactChild, useState } from 'react'; import { noop } from 'lodash'; import type { LocalizerType } from '../types/Util'; import { Button, ButtonVariant } from './Button'; import { Spinner } from './Spinner'; const PADDING_HORIZONTAL = 48; const PADDING_VERTICAL = 12; export enum CallingLobbyJoinButtonVariant { CallIsFull = 'CallIsFull', Join = 'Join', Loading = 'Loading', Start = 'Start', } /** * 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 const CallingLobbyJoinButton: FunctionComponent<{ disabled?: boolean; i18n: LocalizerType; onClick: () => void; variant: CallingLobbyJoinButtonVariant; }> = ({ disabled, i18n, onClick, variant }) => { const [width, setWidth] = useState(); const [height, setHeight] = useState(); const childrenByVariant: Record = { [CallingLobbyJoinButtonVariant.CallIsFull]: i18n('calling__call-is-full'), [CallingLobbyJoinButtonVariant.Loading]: , [CallingLobbyJoinButtonVariant.Join]: i18n('calling__join'), [CallingLobbyJoinButtonVariant.Start]: i18n('calling__start'), }; return ( <> {Boolean(width && height) && ( )}
{Object.values(CallingLobbyJoinButtonVariant).map(candidateVariant => ( ))}
); };