mirror of
https://github.com/outline/outline.git
synced 2026-11-25 15:15:15 +03:00
* Mobile spacing fixes * Keep mobile selection toolbar sticky above the iOS keyboard The mobile selection toolbar positioned itself with absolute positioning and a bottom calc derived from the document body rect and visual viewport height. On iOS the layout viewport (which fixed/absolute elements anchor to) does not shrink when the software keyboard opens, only the visual viewport does, so the toolbar drifted and lagged relative to the keyboard. Anchor the toolbar with position: fixed; bottom: 0 and introduce useKeyboardStickyOffset, which translates it up by the gap between the layout and visual viewport bottoms. It recomputes on visual viewport resize/scroll and runs a short requestAnimationFrame loop so the toolbar glides with the keyboard's open/close animation, and re-applies after every render so parent re-renders cannot clobber the offset. --------- Co-authored-by: Claude <noreply@anthropic.com>
99 lines
2.8 KiB
TypeScript
99 lines
2.8 KiB
TypeScript
import { IconTitleWrapper } from "@shared/components/Icon";
|
|
import breakpoint from "styled-components-breakpoint";
|
|
import { first } from "es-toolkit/compat";
|
|
import { Suspense, useCallback } from "react";
|
|
import styled from "styled-components";
|
|
import { CollectionValidation } from "@shared/validations";
|
|
import { isRTL } from "@shared/utils/rtl";
|
|
import Heading from "~/components/Heading";
|
|
import ContentEditable from "~/components/ContentEditable";
|
|
import CollectionIcon from "~/components/Icons/CollectionIcon";
|
|
import type Collection from "~/models/Collection";
|
|
import { colorPalette } from "@shared/utils/collections";
|
|
import usePolicy from "~/hooks/usePolicy";
|
|
import { observer } from "mobx-react";
|
|
import lazyWithRetry from "~/utils/lazyWithRetry";
|
|
|
|
const IconPicker = lazyWithRetry(() => import("~/components/IconPicker"));
|
|
|
|
type Props = {
|
|
/** The collection for which to render a header */
|
|
collection: Collection;
|
|
/** Whether the header is in editing mode */
|
|
isEditing?: boolean;
|
|
};
|
|
|
|
export const Header = observer(function Header_({
|
|
collection,
|
|
isEditing,
|
|
}: Props) {
|
|
const can = usePolicy(collection);
|
|
const canEdit = can.update && isEditing;
|
|
const handleIconChange = useCallback(
|
|
(icon: string | null, color: string | null) =>
|
|
collection?.save({ icon, color }),
|
|
[collection]
|
|
);
|
|
|
|
const handleTitleChange = useCallback(
|
|
(text: string) => {
|
|
const trimmed = text.trim();
|
|
if (trimmed.length > 0 && trimmed !== collection.name) {
|
|
void collection.save({ name: trimmed });
|
|
}
|
|
},
|
|
[collection]
|
|
);
|
|
|
|
const fallbackIcon = collection ? (
|
|
<CollectionIcon collection={collection} size={40} expanded />
|
|
) : null;
|
|
|
|
const dir = isRTL(collection.name) ? "rtl" : "ltr";
|
|
|
|
return (
|
|
<StyledHeading dir={dir}>
|
|
<IconTitleWrapper dir={dir}>
|
|
{canEdit ? (
|
|
<Suspense fallback={fallbackIcon}>
|
|
<IconPicker
|
|
icon={collection.icon ?? "collection"}
|
|
color={collection.color ?? (first(colorPalette) as string)}
|
|
initial={collection.initial}
|
|
size={40}
|
|
popoverPosition="bottom-start"
|
|
onChange={handleIconChange}
|
|
borderOnHover
|
|
>
|
|
{fallbackIcon}
|
|
</IconPicker>
|
|
</Suspense>
|
|
) : (
|
|
fallbackIcon
|
|
)}
|
|
</IconTitleWrapper>
|
|
{canEdit ? (
|
|
<ContentEditable
|
|
value={collection.name}
|
|
onChange={handleTitleChange}
|
|
maxLength={CollectionValidation.maxNameLength}
|
|
dir="auto"
|
|
/>
|
|
) : (
|
|
collection.name
|
|
)}
|
|
</StyledHeading>
|
|
);
|
|
});
|
|
|
|
const StyledHeading = styled(Heading)`
|
|
display: flex;
|
|
align-items: center;
|
|
position: relative;
|
|
margin-left: 16px;
|
|
|
|
${breakpoint("tablet")`
|
|
margin-left: 0;
|
|
`}
|
|
`;
|