* fix: add disclosure and transition * fix: keep collections expanded * fix: tune transition and collapsing conditions * fix: collectionIcon expanded props is no longer driven by expanded state * fix: sync issue * fix: managing state together * fix: remove comment * fix: simplify expanded state * fix: remove extra state * fix: remove animation and retain expanded state * fix: remove isCollectionDropped * fix: don't use ref * review suggestions * fix many functional and design issues * don't render every single document in the sidebar, just ones that the user has seen before * chore: Sidebar refinement (#3154) * stash * wip: More sidebar tweaks * Simplify draft bubble * disclosure refactor * wip wip * lint * tweak menu position * Use document emoji for starred docs where available * feat: Trigger cmd+k from sidebar (#3149) * feat: Trigger cmd+k from sidebar * Add hint when opening command bar from sidebar * fix: Clicking internal links in shared documents sometimes reroutes to Login * fix: Spacing issues on connected slack channels list * Merge * fix: Do not prefetch JS bundles on public share links * fix: Buttons show on collection empty state when user does not have permission to edit * fix: the hover area for the "collections" subheading was being obfuscated by the initial collection drop cursor * fix: top-align disclosures * fix: Disclosure color PR feedback fix: Starred no longer draggable * fix: Overflow on sidebar button * fix: Scrollbar in sidebar when command menu is open * Minor alignment issues, clarify back in settings sidebar * fix: Fade component causes SidebarButton missizing Co-authored-by: Nan Yu <thenanyu@gmail.com> Co-authored-by: Tom Moor <tom.moor@gmail.com> Co-authored-by: Nan Yu <thenanyu@gmail.com>
174 lines
3.8 KiB
TypeScript
174 lines
3.8 KiB
TypeScript
import { throttle } from "lodash";
|
|
import { observer } from "mobx-react";
|
|
import { MenuIcon } from "outline-icons";
|
|
import { transparentize } from "polished";
|
|
import * as React from "react";
|
|
import styled from "styled-components";
|
|
import breakpoint from "styled-components-breakpoint";
|
|
import Button from "~/components/Button";
|
|
import Fade from "~/components/Fade";
|
|
import Flex from "~/components/Flex";
|
|
import useMobile from "~/hooks/useMobile";
|
|
import useStores from "~/hooks/useStores";
|
|
import { supportsPassiveListener } from "~/utils/browser";
|
|
|
|
type Props = {
|
|
breadcrumb?: React.ReactNode;
|
|
title: React.ReactNode;
|
|
actions?: React.ReactNode;
|
|
hasSidebar?: boolean;
|
|
};
|
|
|
|
function Header({ breadcrumb, title, actions, hasSidebar }: Props) {
|
|
const { ui } = useStores();
|
|
const isMobile = useMobile();
|
|
|
|
const hasMobileSidebar = hasSidebar && isMobile;
|
|
|
|
const passThrough = !actions && !breadcrumb && !title;
|
|
|
|
const [isScrolled, setScrolled] = React.useState(false);
|
|
const handleScroll = React.useCallback(
|
|
throttle(() => setScrolled(window.scrollY > 75), 50),
|
|
[]
|
|
);
|
|
|
|
React.useEffect(() => {
|
|
window.addEventListener(
|
|
"scroll",
|
|
handleScroll,
|
|
supportsPassiveListener ? { passive: true } : false
|
|
);
|
|
return () => window.removeEventListener("scroll", handleScroll);
|
|
}, [handleScroll]);
|
|
|
|
const handleClickTitle = React.useCallback(() => {
|
|
window.scrollTo({
|
|
top: 0,
|
|
behavior: "smooth",
|
|
});
|
|
}, []);
|
|
|
|
return (
|
|
<Wrapper align="center" shrink={false} $passThrough={passThrough}>
|
|
{breadcrumb || hasMobileSidebar ? (
|
|
<Breadcrumbs>
|
|
{hasMobileSidebar && (
|
|
<MobileMenuButton
|
|
onClick={ui.toggleMobileSidebar}
|
|
icon={<MenuIcon />}
|
|
iconColor="currentColor"
|
|
neutral
|
|
/>
|
|
)}
|
|
{breadcrumb}
|
|
</Breadcrumbs>
|
|
) : null}
|
|
|
|
{isScrolled ? (
|
|
<Title onClick={handleClickTitle}>
|
|
<Fade>{title}</Fade>
|
|
</Title>
|
|
) : (
|
|
<div />
|
|
)}
|
|
<Actions align="center" justify="flex-end">
|
|
{actions}
|
|
</Actions>
|
|
</Wrapper>
|
|
);
|
|
}
|
|
|
|
const Breadcrumbs = styled("div")`
|
|
flex-grow: 1;
|
|
flex-basis: 0;
|
|
align-items: center;
|
|
padding-right: 8px;
|
|
display: flex;
|
|
`;
|
|
|
|
const Actions = styled(Flex)`
|
|
flex-grow: 1;
|
|
flex-basis: 0;
|
|
min-width: auto;
|
|
padding-left: 8px;
|
|
|
|
${breakpoint("tablet")`
|
|
position: unset;
|
|
`};
|
|
`;
|
|
|
|
const Wrapper = styled(Flex)<{ $passThrough?: boolean }>`
|
|
top: 0;
|
|
z-index: ${(props) => props.theme.depths.header};
|
|
position: sticky;
|
|
background: ${(props) => props.theme.background};
|
|
|
|
${(props) =>
|
|
props.$passThrough
|
|
? `
|
|
background: transparent;
|
|
pointer-events: none;
|
|
`
|
|
: `
|
|
background: ${transparentize(0.2, props.theme.background)};
|
|
backdrop-filter: blur(20px);
|
|
`};
|
|
|
|
padding: 12px;
|
|
transition: all 100ms ease-out;
|
|
transform: translate3d(0, 0, 0);
|
|
min-height: 64px;
|
|
justify-content: flex-start;
|
|
|
|
@supports (backdrop-filter: blur(20px)) {
|
|
backdrop-filter: blur(20px);
|
|
background: ${(props) => transparentize(0.2, props.theme.background)};
|
|
}
|
|
|
|
@media print {
|
|
display: none;
|
|
}
|
|
|
|
${breakpoint("tablet")`
|
|
padding: 16px;
|
|
justify-content: center;
|
|
`};
|
|
`;
|
|
|
|
const Title = styled("div")`
|
|
display: none;
|
|
font-size: 16px;
|
|
font-weight: 600;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
cursor: pointer;
|
|
min-width: 0;
|
|
|
|
${breakpoint("tablet")`
|
|
padding-left: 0;
|
|
display: block;
|
|
`};
|
|
|
|
svg {
|
|
vertical-align: bottom;
|
|
}
|
|
|
|
@media (display-mode: standalone) {
|
|
overflow: hidden;
|
|
flex-grow: 0 !important;
|
|
}
|
|
`;
|
|
|
|
const MobileMenuButton = styled(Button)`
|
|
margin-right: 8px;
|
|
pointer-events: auto;
|
|
|
|
@media print {
|
|
display: none;
|
|
}
|
|
`;
|
|
|
|
export default observer(Header);
|