Simplify layout of full-width images

This commit is contained in:
Tom Moor
2024-05-27 14:12:38 -04:00
parent f9dac3cba1
commit f58f309321
3 changed files with 23 additions and 25 deletions

View File

@@ -17,6 +17,7 @@ import {
import { toast } from "sonner";
import styled from "styled-components";
import breakpoint from "styled-components-breakpoint";
import useComponentSize from "@shared/editor/components/hooks/useComponentSize";
import { s } from "@shared/styles";
import { NavigationNode } from "@shared/types";
import { ProsemirrorHelper, Heading } from "@shared/utils/ProsemirrorHelper";
@@ -437,8 +438,7 @@ class DocumentScene extends React.Component<Props> {
}
}}
/>
<Background
id="full-width-container"
<FullWidthContainer
key={revision ? revision.id : document.id}
column
auto
@@ -564,7 +564,7 @@ class DocumentScene extends React.Component<Props> {
<ConnectionStatus />
</Footer>
)}
</Background>
</FullWidthContainer>
</ErrorBoundary>
);
}
@@ -622,4 +622,20 @@ const MaxWidth = styled(Flex)<MaxWidthProps>`
`};
`;
const FullWidthContainer = (props: React.ComponentProps<typeof Background>) => {
const ref = React.useRef(null);
const rect = useComponentSize(ref.current);
return (
<Background
{...props}
ref={ref}
style={{
"--container-width": `${rect.width}px`,
"--container-left": `${rect.left}px`,
}}
/>
);
};
export default withTranslation()(withStores(withRouter(DocumentScene)));