mirror of
https://github.com/outline/outline.git
synced 2026-11-22 05:51:43 +03:00
* fix: Various unlabelled and undescribed interactable elements * fix: guard sort keydown against key repeat and label remaining help button Prevent held Space from repeatedly toggling table sort, and add an accessible name to the "Email subscriptions" help button. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
67 lines
1.8 KiB
TypeScript
67 lines
1.8 KiB
TypeScript
import type { TFunction } from "i18next";
|
|
import { observer } from "mobx-react";
|
|
import { DoneIcon } from "outline-icons";
|
|
import { useTranslation } from "react-i18next";
|
|
import styled, { useTheme } from "styled-components";
|
|
import type Document from "~/models/Document";
|
|
import CircularProgressBar from "~/components/CircularProgressBar";
|
|
import usePrevious from "~/hooks/usePrevious";
|
|
import { bounceIn } from "~/styles/animations";
|
|
import Flex from "./Flex";
|
|
|
|
type Props = {
|
|
document: Document;
|
|
};
|
|
|
|
function getMessage(t: TFunction, total: number, completed: number): string {
|
|
if (completed === 0) {
|
|
return t(`{{ total }} task`, {
|
|
total,
|
|
count: total,
|
|
});
|
|
} else if (completed === total) {
|
|
return t(`{{ completed }} task done`, {
|
|
completed,
|
|
count: completed,
|
|
});
|
|
} else {
|
|
return t(`{{ completed }} of {{ total }} tasks`, {
|
|
total,
|
|
completed,
|
|
});
|
|
}
|
|
}
|
|
|
|
function DocumentTasks({ document }: Props) {
|
|
const { tasks, tasksPercentage } = document;
|
|
const { t } = useTranslation();
|
|
const theme = useTheme();
|
|
const { completed, total } = tasks;
|
|
const done = completed === total;
|
|
const previousDone = usePrevious(done);
|
|
const message = getMessage(t, total, completed);
|
|
|
|
return (
|
|
<Flex align="center" style={{ padding: "0 1px" }} gap={2} shrink={false}>
|
|
{completed === total ? (
|
|
<Done
|
|
color={theme.accent}
|
|
size={20}
|
|
$animated={done && previousDone === false}
|
|
/>
|
|
) : (
|
|
<CircularProgressBar percentage={tasksPercentage} label={message} />
|
|
)}
|
|
{message}
|
|
</Flex>
|
|
);
|
|
}
|
|
|
|
const Done = styled(DoneIcon)<{ $animated: boolean }>`
|
|
margin: -1px;
|
|
animation: ${(props) => (props.$animated ? bounceIn : "none")} 600ms;
|
|
transform-origin: center center;
|
|
`;
|
|
|
|
export default observer(DocumentTasks);
|