Dynamic bottom padding
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
|
|
||||||
const ClickablePadding = styled.div<{ grow?: boolean }>`
|
const ClickablePadding = styled.div<{ grow?: boolean; minHeight?: string }>`
|
||||||
min-height: 50vh;
|
min-height: ${(props) => props.minHeight || "50vh"};
|
||||||
cursor: ${({ onClick }) => (onClick ? "text" : "default")};
|
flex-grow: 100;
|
||||||
${({ grow }) => grow && `flex-grow: 100;`};
|
cursor: text;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export default ClickablePadding;
|
export default ClickablePadding;
|
||||||
|
|||||||
@@ -50,10 +50,10 @@ export type Props = Optional<
|
|||||||
> & {
|
> & {
|
||||||
shareId?: string | undefined;
|
shareId?: string | undefined;
|
||||||
embedsDisabled?: boolean;
|
embedsDisabled?: boolean;
|
||||||
grow?: boolean;
|
|
||||||
onHeadingsChange?: (headings: Heading[]) => void;
|
onHeadingsChange?: (headings: Heading[]) => void;
|
||||||
onSynced?: () => Promise<void>;
|
onSynced?: () => Promise<void>;
|
||||||
onPublish?: (event: React.MouseEvent) => any;
|
onPublish?: (event: React.MouseEvent) => any;
|
||||||
|
bottomPadding?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
function Editor(props: Props, ref: React.RefObject<SharedEditor> | null) {
|
function Editor(props: Props, ref: React.RefObject<SharedEditor> | null) {
|
||||||
@@ -301,12 +301,12 @@ function Editor(props: Props, ref: React.RefObject<SharedEditor> | null) {
|
|||||||
placeholder={props.placeholder || ""}
|
placeholder={props.placeholder || ""}
|
||||||
defaultValue={props.defaultValue || ""}
|
defaultValue={props.defaultValue || ""}
|
||||||
/>
|
/>
|
||||||
{props.grow && !props.readOnly && (
|
{props.bottomPadding && !props.readOnly && (
|
||||||
<ClickablePadding
|
<ClickablePadding
|
||||||
onClick={focusAtEnd}
|
onClick={focusAtEnd}
|
||||||
onDrop={handleDrop}
|
onDrop={handleDrop}
|
||||||
onDragOver={handleDragOver}
|
onDragOver={handleDragOver}
|
||||||
grow
|
minHeight={props.bottomPadding}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{activeLinkEvent && !shareId && (
|
{activeLinkEvent && !shareId && (
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ function DocumentEditor(props: Props, ref: React.RefObject<any>) {
|
|||||||
...rest
|
...rest
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
|
const childRef = React.useRef<HTMLDivElement>(null);
|
||||||
const focusAtStart = React.useCallback(() => {
|
const focusAtStart = React.useCallback(() => {
|
||||||
if (ref.current) {
|
if (ref.current) {
|
||||||
ref.current.focusAtStart();
|
ref.current.focusAtStart();
|
||||||
@@ -115,10 +116,10 @@ function DocumentEditor(props: Props, ref: React.RefObject<any>) {
|
|||||||
readOnly={readOnly}
|
readOnly={readOnly}
|
||||||
shareId={shareId}
|
shareId={shareId}
|
||||||
extensions={fullPackage}
|
extensions={fullPackage}
|
||||||
grow
|
bottomPadding={`calc(50vh - ${childRef.current?.offsetHeight || 0}px)`}
|
||||||
{...rest}
|
{...rest}
|
||||||
/>
|
/>
|
||||||
{children}
|
<div ref={childRef}>{children}</div>
|
||||||
</Flex>
|
</Flex>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user