Files
outline/app/scenes/Document/components/ObservingBanner.tsx
Tom Moor 9a7b5ea1f4 feat: Added ability to click another user to observe them (sync scroll position) (#2858)
* feat: Added ability to click another user to observe them, mainly for fun

* language, lower debounce, prevent tooltip from hiding when toggling observation

* fix: Don't allow observing self, added banner at top of screen

* Dont edit tooltip as it's confusing between our actions and theirs

* snapshots
2021-12-16 17:36:39 -08:00

61 lines
1.5 KiB
TypeScript

import { m, AnimatePresence } from "framer-motion";
import { observer } from "mobx-react";
import * as React from "react";
import { useTranslation } from "react-i18next";
import styled from "styled-components";
import useStores from "~/hooks/useStores";
const transition = {
type: "spring",
stiffness: 500,
damping: 30,
};
/**
* A small banner that is displayed at the top of the screen when the user is
* observing another user while editing a document
*/
function ObservingBanner() {
const { ui, users } = useStores();
const { t } = useTranslation();
const user = ui.observingUserId ? users.get(ui.observingUserId) : undefined;
return (
<Positioner>
<AnimatePresence>
{user && (
<Banner
$color={user.color}
transition={transition}
initial={{ opacity: 0, y: -20 }}
animate={{ opacity: 1, y: -5 }}
exit={{ opacity: 0, y: -30 }}
>
{t("Observing {{ userName }}", { userName: user.name })}
</Banner>
)}
</AnimatePresence>
</Positioner>
);
}
const Positioner = styled.div`
position: fixed;
top: 0;
left: 50%;
transform: translateX(-50%);
`;
const Banner = styled(m.div)<{ $color: string }>`
padding: 6px 6px 1px;
font-size: 13px;
font-weight: 500;
z-index: ${(props) => props.theme.depths.header + 1};
color: ${(props) => props.theme.white};
background: ${(props) => props.$color};
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
`;
export default observer(ObservingBanner);