mirror of
https://github.com/outline/outline.git
synced 2026-11-27 16:08:58 +03:00
* feat: Auto-save General and Profile settings, add settings sections - Save General and Profile fields on change and remove the Save button - Add SettingsSection with consistent spacing and a tinted Danger block - Right-align setting controls and center switches in their row - Let descriptions use the full row width beside switches * fix: Avoid settings autosave overwrites and IME Enter saves - Send only the changed team preference so concurrent saves do not revert each other - Save separate editing as a single preference instead of the whole team - Treat a cleared color input as empty so the default is restored - Ignore Enter during IME composition * feat: Add change and remove icon buttons below image inputs - Replace the Remove button with edit and trash icon buttons with tooltips - Show an upload icon on the image hover overlay - Re-render ImageInput when the image changes so the remove action appears immediately * feat: Use footer buttons in the change profile picture dialog - Add Replace and Delete buttons beside Done in the admin avatar dialog - Add showActions and an open handle to ImageInput so dialogs can supply their own controls * fix: Style the danger section with an outer shadow instead of tinted text
151 lines
3.8 KiB
TypeScript
151 lines
3.8 KiB
TypeScript
import { observer } from "mobx-react";
|
|
import { EditIcon, ExportIcon, TrashIcon } from "outline-icons";
|
|
import * as React from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import styled from "styled-components";
|
|
import { s } from "@shared/styles";
|
|
import type { IAvatar } from "~/components/Avatar";
|
|
import { Avatar, AvatarSize } from "~/components/Avatar";
|
|
import { AvatarVariant } from "~/components/Avatar/Avatar";
|
|
import Flex from "~/components/Flex";
|
|
import NudeButton from "~/components/NudeButton";
|
|
import Tooltip from "~/components/Tooltip";
|
|
import type {
|
|
ImageUploadHandle,
|
|
Props as ImageUploadProps,
|
|
} from "./ImageUpload";
|
|
import ImageUpload from "./ImageUpload";
|
|
|
|
type Props = ImageUploadProps & {
|
|
/** The model whose avatar is displayed and updated by this input. */
|
|
model: IAvatar;
|
|
/** Alt text for the avatar image. */
|
|
alt: string;
|
|
/** The shape of the avatar preview. Defaults to round. */
|
|
variant?: AvatarVariant;
|
|
/**
|
|
* Whether to render the change and remove buttons below the image. Hide
|
|
* them when the parent provides its own controls. Defaults to true.
|
|
*/
|
|
showActions?: boolean;
|
|
/** Handle to open the file picker from the parent. */
|
|
ref?: React.Ref<ImageUploadHandle>;
|
|
};
|
|
|
|
function ImageInput({
|
|
model,
|
|
onSuccess,
|
|
alt,
|
|
variant = AvatarVariant.Round,
|
|
showActions = true,
|
|
ref,
|
|
...rest
|
|
}: Props) {
|
|
const { t } = useTranslation();
|
|
const uploadRef = React.useRef<ImageUploadHandle>(null);
|
|
|
|
React.useImperativeHandle(
|
|
ref,
|
|
() => ({ open: () => uploadRef.current?.open() }),
|
|
[]
|
|
);
|
|
|
|
const handleChange = React.useCallback(() => {
|
|
uploadRef.current?.open();
|
|
}, []);
|
|
|
|
const handleRemove = React.useCallback(() => {
|
|
void onSuccess(null);
|
|
}, [onSuccess]);
|
|
|
|
return (
|
|
<Wrapper column align="center" gap={4}>
|
|
<ImageBox $variant={variant}>
|
|
<ImageUpload
|
|
ref={uploadRef}
|
|
onSuccess={onSuccess}
|
|
submitText={t("Crop image")}
|
|
{...rest}
|
|
>
|
|
<Avatar
|
|
model={model}
|
|
size={AvatarSize.Upload}
|
|
variant={variant}
|
|
alt={alt}
|
|
/>
|
|
<Flex auto align="center" justify="center" className="upload">
|
|
<ExportIcon />
|
|
</Flex>
|
|
</ImageUpload>
|
|
</ImageBox>
|
|
{showActions && (
|
|
<Actions gap={4} justify="center">
|
|
<Tooltip content={t("Change image")}>
|
|
<NudeButton aria-label={t("Change image")} onClick={handleChange}>
|
|
<EditIcon />
|
|
</NudeButton>
|
|
</Tooltip>
|
|
{model.avatarUrl && (
|
|
<Tooltip content={t("Remove image")}>
|
|
<NudeButton aria-label={t("Remove image")} onClick={handleRemove}>
|
|
<TrashIcon />
|
|
</NudeButton>
|
|
</Tooltip>
|
|
)}
|
|
</Actions>
|
|
)}
|
|
</Wrapper>
|
|
);
|
|
}
|
|
|
|
export default observer(ImageInput);
|
|
|
|
const Wrapper = styled(Flex)`
|
|
width: fit-content;
|
|
`;
|
|
|
|
const Actions = styled(Flex)`
|
|
color: ${s("textSecondary")};
|
|
|
|
button:hover,
|
|
button:focus-visible {
|
|
color: ${s("text")};
|
|
}
|
|
`;
|
|
|
|
const avatarStyles = `
|
|
width: ${AvatarSize.Upload}px;
|
|
height: ${AvatarSize.Upload}px;
|
|
`;
|
|
|
|
const ImageBox = styled(Flex)<{ $variant: AvatarVariant }>`
|
|
${avatarStyles};
|
|
position: relative;
|
|
font-size: 14px;
|
|
border-radius: ${(props) =>
|
|
props.$variant === AvatarVariant.Round
|
|
? "50%"
|
|
: `${AvatarSize.Upload / 8}px`};
|
|
box-shadow: 0 0 0 1px ${s("backgroundSecondary")};
|
|
background: ${s("background")};
|
|
overflow: hidden;
|
|
|
|
.upload {
|
|
${avatarStyles};
|
|
position: absolute;
|
|
top: 0;
|
|
right: 0;
|
|
bottom: 0;
|
|
left: 0;
|
|
opacity: 0;
|
|
cursor: var(--pointer);
|
|
transition: all 250ms;
|
|
}
|
|
|
|
&:hover .upload {
|
|
opacity: 1;
|
|
background: rgba(0, 0, 0, 0.75);
|
|
color: ${(props) => props.theme.white};
|
|
}
|
|
`;
|