Add "Scroll to Top" component

Signed-off-by: Julius Volz <julius.volz@gmail.com>
This commit is contained in:
Julius Volz 2024-03-14 12:01:19 +01:00
parent 6ff7857313
commit e29ad4a83b

View file

@ -7,6 +7,7 @@ import PrometheusLogo from "./images/prometheus-logo.svg";
import { import {
ActionIcon, ActionIcon,
Affix,
AppShell, AppShell,
Box, Box,
Burger, Burger,
@ -16,12 +17,14 @@ import {
Menu, Menu,
Skeleton, Skeleton,
Text, Text,
Transition,
createTheme, createTheme,
rem, rem,
} from "@mantine/core"; } from "@mantine/core";
import { useDisclosure } from "@mantine/hooks"; import { useDisclosure, useWindowScroll } from "@mantine/hooks";
import { import {
IconAdjustments, IconAdjustments,
IconArrowUp,
IconBellFilled, IconBellFilled,
IconChevronDown, IconChevronDown,
IconChevronRight, IconChevronRight,
@ -169,6 +172,7 @@ const navLinkIconSize = 15;
const navLinkXPadding = "md"; const navLinkXPadding = "md";
function App() { function App() {
const [scroll, scrollTo] = useWindowScroll();
const [opened, { toggle }] = useDisclosure(); const [opened, { toggle }] = useDisclosure();
const { agentMode } = useContext(SettingsContext); const { agentMode } = useContext(SettingsContext);
@ -373,6 +377,23 @@ function App() {
</Routes> </Routes>
</Suspense> </Suspense>
</ErrorBoundary> </ErrorBoundary>
<Affix position={{ bottom: 20, right: 20 }}>
<Transition transition="slide-up" mounted={scroll.y > 0}>
{(transitionStyles) => (
<Button
leftSection={
<IconArrowUp
style={{ width: rem(16), height: rem(16) }}
/>
}
style={transitionStyles}
onClick={() => scrollTo({ y: 0 })}
>
Scroll to top
</Button>
)}
</Transition>
</Affix>
</AppShell.Main> </AppShell.Main>
</AppShell> </AppShell>
{/* <ReactQueryDevtools initialIsOpen={false} /> */} {/* <ReactQueryDevtools initialIsOpen={false} /> */}