-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathMainContentView.tsx
More file actions
64 lines (54 loc) · 1.86 KB
/
MainContentView.tsx
File metadata and controls
64 lines (54 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Copyright 2025 © BeeAI a Series of LF Projects, LLC
* SPDX-License-Identifier: Apache-2.0
*/
'use client';
import clsx from 'clsx';
import type { PropsWithChildren } from 'react';
import { mergeRefs } from 'react-merge-refs';
import { AppFooter } from '#components/layouts/AppFooter.tsx';
import { useIsScrolled } from '#hooks/useIsScrolled.ts';
import { useScrollbarWidth } from '#hooks/useScrollbarWidth.ts';
import { useToTopButton } from '#hooks/useToTopButton.ts';
import { createScrollbarStyles } from '#utils/createScrollbarStyles.ts';
import { ToTopButton } from '../ToTopButton/ToTopButton';
import classes from './MainContentView.module.scss';
export interface MainContentViewProps extends PropsWithChildren {
spacing?: 'md' | 'lg';
scrollable?: boolean;
enableToTopButton?: boolean;
showFooter?: boolean;
className?: string;
}
export function MainContentView({
spacing = 'lg',
scrollable = true,
enableToTopButton,
showFooter,
className,
children,
}: MainContentViewProps) {
const { scrollElementRef, observeElementRef, isScrolled } = useIsScrolled();
const { ref: toTopRef, showButton, handleToTopClick } = useToTopButton({ enabled: enableToTopButton });
const { ref: scrollbarRef, scrollbarWidth } = useScrollbarWidth();
return (
<div
ref={mergeRefs([toTopRef, scrollbarRef, scrollElementRef])}
className={clsx(
classes.root,
{
[classes[spacing]]: spacing,
[classes.scrollable]: scrollable,
},
className,
)}
{...createScrollbarStyles({ width: scrollbarWidth })}
data-scrolled={isScrolled}
>
<div className={classes.topRef} ref={observeElementRef} />
<div className={classes.body}>{children}</div>
{showButton && <ToTopButton onClick={handleToTopClick} />}
{showFooter && <AppFooter className={classes.footer} />}
</div>
);
}