import clsx from 'clsx'; import throttle from 'lodash/throttle'; import React, { useCallback, useEffect, useState } from 'react'; import { useHistory } from 'react-router-dom'; import Helmet from 'soapbox/components/helmet'; import { useSoapboxConfig } from 'soapbox/hooks'; import { Card, CardBody, CardHeader, CardTitle, type CardSizes } from '../card/card'; type IColumnHeader = Pick; /** Contains the column title with optional back button. */ const ColumnHeader: React.FC = ({ label, backHref, className, action }) => { const history = useHistory(); const handleBackClick = () => { if (backHref) { history.push(backHref); return; } if (history.length === 1) { history.push('/'); } else { history.goBack(); } }; return ( {action && (
{action}
)}
); }; export interface IColumn { /** Route the back button goes to. */ backHref?: string /** Column title text. */ label?: string /** Whether this column should have a transparent background. */ transparent?: boolean /** Whether this column should have a title and back button. */ withHeader?: boolean /** Extra class name for top
element. */ className?: string /** Extra class name for the element. */ bodyClassName?: string /** Ref forwarded to column. */ ref?: React.Ref /** Children to display in the column. */ children?: React.ReactNode /** Action for the ColumnHeader, displayed at the end. */ action?: React.ReactNode /** Column size, inherited from Card. */ size?: CardSizes } /** A backdrop for the main section of the UI. */ const Column: React.FC = React.forwardRef((props, ref: React.ForwardedRef): JSX.Element => { const { backHref, children, label, transparent = false, withHeader = true, className, bodyClassName, action, size } = props; const soapboxConfig = useSoapboxConfig(); const [isScrolled, setIsScrolled] = useState(false); const handleScroll = useCallback(throttle(() => { setIsScrolled(window.pageYOffset > 32); }, 50), []); useEffect(() => { window.addEventListener('scroll', handleScroll); return () => { window.removeEventListener('scroll', handleScroll); }; }, []); return (
{label} {soapboxConfig.appleAppId && ( )} {withHeader && ( )} {children}
); }); export { Column, ColumnHeader, };