Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

3.0 KB
Raw Blame
import React from 'react';
import { GestureResponderEvent } from 'react-native';

import { StyleType } from '../../../base/styles/functions.native';
import Button from '../../../base/ui/components/native/Button';
import IconButton from '../../../base/ui/components/native/IconButton';
import { BUTTON_TYPES } from '../../../base/ui/constants.native';

import { navigationStyles } from './styles';


interface IProps {

    /**
     * An accessibility label for the button.
     */
    accessibilityLabel?: string;

    /**
     * Icon button color.
     */
    color?: string;

    /**
     * Is the button disabled?
     */
    disabled?: boolean;

    /**
     * ID of the header navigation button.
     */
    id?: string;

    /**
     * Label of the button.
     */
    label?: string;

    /**
     * Callback to invoke when the {@code HeaderNavigationButton} is clicked/pressed.
     */
    onPress?: (e?: GestureResponderEvent | React.MouseEvent) => void;

    /**
     * The ImageSource to be rendered as image.
     */
    src?: any;

    /**
     * Style of the button.
     */
    style?: StyleType;

    /**
     * Header has two actions.
     */
    twoActions?: boolean;
}

const HeaderNavigationButton = ({
    accessibilityLabel,
    color,
    disabled,
    id,
    label,
    onPress,
    src,
    style,
    twoActions
}: IProps) => {

    let btnStyle;
    let labelStyle;

    if (disabled) {
        btnStyle = navigationStyles.headerNavigationButtonDisabled;
        labelStyle = twoActions
            ? navigationStyles.headerNavigationButtonLabelBoldDisabled
            : navigationStyles.headerNavigationButtonLabelDisabled;
    } else {
        btnStyle = navigationStyles.headerNavigationButton;
        labelStyle = twoActions
            ? navigationStyles.headerNavigationButtonLabelBold
            : navigationStyles.headerNavigationButtonLabel;
    }

    return (
        <>
            {
                src ? (
                    <IconButton
                        accessibilityLabel = { accessibilityLabel }
                        color = { color }
                        id = { id }
                        onPress = { onPress }
                        size = { 24 }
                        src = { src }
                        style = { [
                            navigationStyles.headerNavigationButtonIcon,
                            style
                        ] } />
                ) : (
                    <Button
                        accessibilityLabel = { accessibilityLabel }
                        disabled = { disabled }
                        id = { id }
                        labelKey = { label }
                        labelStyle = { labelStyle }
                        onClick = { onPress }
                        style = { [
                            btnStyle,
                            style
                        ] }
                        type = { BUTTON_TYPES.TERTIARY } />
                )}
        </>
    );
};

export default HeaderNavigationButton;