import type { RcIconButtonProps } from '@ringcentral/juno'; import { RcIconButton, RcTypography, styled } from '@ringcentral/juno'; import { ChevronLeft as chevronLeftSvg } from '@ringcentral/juno-icon'; import clsx from 'clsx'; import type { FunctionComponent } from 'react'; import React, { useEffect, useRef, useState } from 'react'; import styles from './styles.scss'; const initWidth = 67; export interface BackHeaderProps { onBackClick: (...args: any[]) => any; title?: string; backIcon?: RcIconButtonProps['symbol']; rightIcon?: React.ReactNode; className?: string; currentLocale?: string; isWide?: boolean; } const Title = styled(RcTypography)<{ $maxWidth?: number }>` max-width: ${({ $maxWidth }) => $maxWidth}px; `; // TODO: use PageHeader to replace those const BackHeader: FunctionComponent = ({ onBackClick, title = '', rightIcon = null, className, currentLocale = 'en-US', isWide = true, backIcon = chevronLeftSvg, }) => { const [maxWidth, setMaxWidth] = useState(initWidth); const rightRef = useRef(null); const isClassic = !isWide; useEffect(() => { if (isClassic && rightRef.current) { // this smallest clientWidth is 62. setMaxWidth(initWidth - (rightRef.current.clientWidth - 62)); } }, [currentLocale, isClassic]); const rootClass = clsx(styles.root, isClassic && styles.classic, className); // if right icon is empty then should occupy position to make title actually center align const rightIconClass = clsx(styles.rightIcon, { [styles.emptyRightIcon]: !rightIcon, }); return (
{title ? ( {title} ) : null}
{rightIcon}
); }; export default BackHeader;