mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 21:06:42 +07:00
sticky sidebars
This commit is contained in:
parent
776d4a8992
commit
54f5125b8f
7 changed files with 10659 additions and 24 deletions
|
@ -1,7 +1,4 @@
|
|||
.blur {
|
||||
filter: blur(0);
|
||||
transition: filter 0.25s;
|
||||
will-change: filter;
|
||||
padding-top: $header_height + 2px;
|
||||
display: flex;
|
||||
box-sizing: border-box;
|
||||
|
|
41
src/components/containers/Sticky/index.tsx
Normal file
41
src/components/containers/Sticky/index.tsx
Normal file
|
@ -0,0 +1,41 @@
|
|||
import React, { FC, ReactComponentElement, DetailsHTMLAttributes, useEffect, useRef } from 'react';
|
||||
import styles from './styles.scss';
|
||||
import StickySidebar from 'sticky-sidebar';
|
||||
import classnames from 'classnames';
|
||||
import ResizeSensor from 'resize-sensor';
|
||||
|
||||
interface IProps extends DetailsHTMLAttributes<HTMLDivElement> {}
|
||||
|
||||
(window as any).StickySidebar = StickySidebar;
|
||||
(window as any).ResizeSensor = ResizeSensor;
|
||||
|
||||
const Sticky: FC<IProps> = ({ children }) => {
|
||||
const ref = useRef(null);
|
||||
let sb = null;
|
||||
|
||||
useEffect(() => {
|
||||
if (!ref.current) return;
|
||||
|
||||
sb = new StickySidebar(ref.current, {
|
||||
resizeSensor: true,
|
||||
topSpacing: 72,
|
||||
bottomSpacing: 10,
|
||||
});
|
||||
|
||||
return () => sb.destroy();
|
||||
}, [ref.current, children]);
|
||||
|
||||
if (sb) {
|
||||
sb.updateSticky();
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={classnames(styles.wrap, 'sidebar_container')}>
|
||||
<div className="sidebar" ref={ref}>
|
||||
<div className={classnames(styles.sticky, 'sidebar__inner')}>{children}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export { Sticky };
|
15
src/components/containers/Sticky/styles.scss
Normal file
15
src/components/containers/Sticky/styles.scss
Normal file
|
@ -0,0 +1,15 @@
|
|||
.wrap {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
position: relative;
|
||||
|
||||
:global(.sidebar) {
|
||||
will-change: min-height;
|
||||
}
|
||||
|
||||
:global(.sidebar__inner) {
|
||||
transform: translate(0, 0); /* For browsers don't support translate3d. */
|
||||
transform: translate3d(0, 0, 0);
|
||||
will-change: position, transform;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue