import React, { useCallback } from 'react'; import cn from 'classnames'; import { Flex } from 'indigo-react'; import { FooterTarget } from './Footer'; import useBreakpoints from 'lib/useBreakpoints'; import { MiniBackButton } from './MiniBackButton'; import { useHistory } from 'store/history'; import { NavHeaderTarget } from './NavHeader'; import { noop } from 'lodash'; interface ViewProps { className?: string; children: React.ReactNode; inset?: boolean; full?: boolean; hideBack?: boolean; pop?: VoidFunction; header?: React.ReactNode; centered?: boolean; id?: string; rest?: React.HTMLAttributes; } // View is a top-level component that all Views must render to inherit styling function View({ className, children, inset = false, full = false, hideBack = false, pop = noop, header = React.Fragment, id, centered = false, ...rest }: ViewProps) { const { reset }: any = useHistory(); const isMobile: boolean = useBreakpoints([true, false, false]); const shouldInset = inset && !isMobile; const insetPadding = cn({ pt7: shouldInset, pt5: !shouldInset, }); const goBack = useCallback(() => pop(), [pop]); const goLogout = reset; const showBackButton = !!pop; const Header = useCallback( ({ logout }) => { return showBackButton ? ( Logout ) : ( ); }, [goLogout, insetPadding, showBackButton] ); return ( {showBackButton && !hideBack && ( )} {header ||
} {children} ); } // View.Full is sugar for to help with readability View.Full = function FullView(props: ViewProps) { return ; }; export default View;