feat: use flexbox to center the floating title (#1959)
* use flexbox to center the floating title * simplify breadcumb alignment * small adjustments * fix alignment on actions
This commit is contained in:
@ -12,7 +12,6 @@ import * as React from "react";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
import breakpoint from "styled-components-breakpoint";
|
|
||||||
import Document from "models/Document";
|
import Document from "models/Document";
|
||||||
import CollectionIcon from "components/CollectionIcon";
|
import CollectionIcon from "components/CollectionIcon";
|
||||||
import Flex from "components/Flex";
|
import Flex from "components/Flex";
|
||||||
@ -85,7 +84,7 @@ const Breadcrumb = ({ document, children, onlyText }: Props) => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
if (!collections.isLoaded) {
|
if (!collections.isLoaded) {
|
||||||
return <Wrapper />;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let collection = collections.get(document.collectionId);
|
let collection = collections.get(document.collectionId);
|
||||||
@ -125,7 +124,7 @@ const Breadcrumb = ({ document, children, onlyText }: Props) => {
|
|||||||
const menuPath = isNestedDocument ? path.slice(0, -1) : [];
|
const menuPath = isNestedDocument ? path.slice(0, -1) : [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper justify="flex-start" align="center">
|
<Flex justify="flex-start" align="center">
|
||||||
<Icon document={document} />
|
<Icon document={document} />
|
||||||
<CollectionName to={collectionUrl(collection.id)}>
|
<CollectionName to={collectionUrl(collection.id)}>
|
||||||
<CollectionIcon collection={collection} expanded />
|
<CollectionIcon collection={collection} expanded />
|
||||||
@ -146,7 +145,7 @@ const Breadcrumb = ({ document, children, onlyText }: Props) => {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{children}
|
{children}
|
||||||
</Wrapper>
|
</Flex>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -155,14 +154,6 @@ export const Slash = styled(GoToIcon)`
|
|||||||
fill: ${(props) => props.theme.divider};
|
fill: ${(props) => props.theme.divider};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const Wrapper = styled(Flex)`
|
|
||||||
display: none;
|
|
||||||
|
|
||||||
${breakpoint("tablet")`
|
|
||||||
display: flex;
|
|
||||||
`};
|
|
||||||
`;
|
|
||||||
|
|
||||||
const SmallPadlockIcon = styled(PadlockIcon)`
|
const SmallPadlockIcon = styled(PadlockIcon)`
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
vertical-align: sub;
|
vertical-align: sub;
|
||||||
|
@ -36,36 +36,47 @@ function Header({ breadcrumb, title, actions }: Props) {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper
|
<Wrapper align="center" isCompact={isScrolled} shrink={false}>
|
||||||
align="center"
|
{breadcrumb ? <Breadcrumbs>{breadcrumb}</Breadcrumbs> : null}
|
||||||
justify="space-between"
|
|
||||||
isCompact={isScrolled}
|
|
||||||
shrink={false}
|
|
||||||
>
|
|
||||||
{breadcrumb}
|
|
||||||
{isScrolled ? (
|
{isScrolled ? (
|
||||||
<Title
|
<Title align="center" justify="flex-start" onClick={handleClickTitle}>
|
||||||
align="center"
|
<Fade>{title}</Fade>
|
||||||
justify={breadcrumb ? "center" : "flex-start"}
|
|
||||||
onClick={handleClickTitle}
|
|
||||||
>
|
|
||||||
<Fade>
|
|
||||||
<Flex align="center">{title}</Flex>
|
|
||||||
</Fade>
|
|
||||||
</Title>
|
</Title>
|
||||||
) : (
|
) : (
|
||||||
<div />
|
<div />
|
||||||
)}
|
)}
|
||||||
{actions && <Actions>{actions}</Actions>}
|
{actions && (
|
||||||
|
<Actions align="center" justify="flex-end">
|
||||||
|
{actions}
|
||||||
|
</Actions>
|
||||||
|
)}
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Breadcrumbs = styled("div")`
|
||||||
|
flex-grow: 1;
|
||||||
|
flex-basis: 0;
|
||||||
|
align-items: center;
|
||||||
|
padding-right: 8px;
|
||||||
|
|
||||||
|
/* Don't show breadcrumbs on mobile */
|
||||||
|
display: none;
|
||||||
|
${breakpoint("tablet")`
|
||||||
|
display: flex;
|
||||||
|
`};
|
||||||
|
`;
|
||||||
|
|
||||||
|
const Actions = styled(Flex)`
|
||||||
|
flex-grow: 1;
|
||||||
|
flex-basis: 0;
|
||||||
|
min-width: auto;
|
||||||
|
padding-left: 8px;
|
||||||
|
`;
|
||||||
|
|
||||||
const Wrapper = styled(Flex)`
|
const Wrapper = styled(Flex)`
|
||||||
position: sticky;
|
position: sticky;
|
||||||
top: 0;
|
top: 0;
|
||||||
right: 0;
|
|
||||||
left: 0;
|
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
background: ${(props) => transparentize(0.2, props.theme.background)};
|
background: ${(props) => transparentize(0.2, props.theme.background)};
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
@ -77,33 +88,38 @@ const Wrapper = styled(Flex)`
|
|||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
justify-content: flex-start;
|
||||||
${breakpoint("tablet")`
|
${breakpoint("tablet")`
|
||||||
padding: ${(props) => (props.isCompact ? "12px" : `24px 24px 0`)};
|
padding: ${(props) => (props.isCompact ? "12px" : `24px 24px 0`)};
|
||||||
|
justify-content: "center";
|
||||||
`};
|
`};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const Title = styled(Flex)`
|
const Title = styled("div")`
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
width: 0;
|
min-width: 0;
|
||||||
|
|
||||||
|
/* on mobile, there's always a floating menu button in the top left
|
||||||
|
add some padding here to offset
|
||||||
|
*/
|
||||||
|
padding-left: 40px;
|
||||||
${breakpoint("tablet")`
|
${breakpoint("tablet")`
|
||||||
flex-grow: 1;
|
padding-left: 0;
|
||||||
`};
|
`};
|
||||||
|
|
||||||
|
svg {
|
||||||
|
vertical-align: bottom;
|
||||||
|
}
|
||||||
|
|
||||||
@media (display-mode: standalone) {
|
@media (display-mode: standalone) {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
flex-grow: 0 !important;
|
flex-grow: 0 !important;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const Actions = styled(Flex)`
|
|
||||||
align-self: flex-end;
|
|
||||||
height: 32px;
|
|
||||||
`;
|
|
||||||
|
|
||||||
export default observer(Header);
|
export default observer(Header);
|
||||||
|
@ -28,7 +28,7 @@ export const ToggleButton = styled.button`
|
|||||||
transition: opacity 100ms ease-in-out;
|
transition: opacity 100ms ease-in-out;
|
||||||
transform: translateY(-50%)
|
transform: translateY(-50%)
|
||||||
scaleX(${(props) => (props.$direction === "left" ? 1 : -1)});
|
scaleX(${(props) => (props.$direction === "left" ? 1 : -1)});
|
||||||
position: absolute;
|
position: fixed;
|
||||||
top: 50vh;
|
top: 50vh;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
border: 0;
|
border: 0;
|
||||||
|
@ -138,12 +138,7 @@ function DocumentHeader({
|
|||||||
}
|
}
|
||||||
actions={
|
actions={
|
||||||
<>
|
<>
|
||||||
{!isPublishing && (
|
{!isPublishing && isSaving && <Status>{t("Saving")}…</Status>}
|
||||||
<Action>
|
|
||||||
<Status isSaving={isSaving}>{t("Saving")}…</Status>
|
|
||||||
</Action>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<Fade>
|
<Fade>
|
||||||
<Collaborators
|
<Collaborators
|
||||||
document={document}
|
document={document}
|
||||||
@ -299,9 +294,10 @@ function DocumentHeader({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Status = styled.div`
|
const Status = styled(Action)`
|
||||||
|
padding-left: 0;
|
||||||
|
padding-right: 4px;
|
||||||
color: ${(props) => props.theme.slate};
|
color: ${(props) => props.theme.slate};
|
||||||
visibility: ${(props) => (props.isSaving ? "visible" : "hidden")};
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export default observer(DocumentHeader);
|
export default observer(DocumentHeader);
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
#root {
|
#root {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-height: 100vh;
|
min-height: 100vh;
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
Reference in New Issue
Block a user