mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
made simple tiny slider
This commit is contained in:
parent
5da9a0547d
commit
3808f2f516
7 changed files with 95 additions and 36 deletions
|
@ -2,7 +2,11 @@ import React, { FC, useCallback, useEffect, useMemo, useRef, useState } from 're
|
|||
import styles from './styles.module.scss';
|
||||
import ResizeSensor from 'resize-sensor';
|
||||
|
||||
const FullWidth: FC = ({ children }) => {
|
||||
interface IProps {
|
||||
onRefresh?: (width: number) => void;
|
||||
}
|
||||
|
||||
const FullWidth: FC<IProps> = ({ children, onRefresh }) => {
|
||||
const sample = useRef<HTMLDivElement>(null);
|
||||
const [clientWidth, setClientWidth] = useState(document.documentElement.clientWidth);
|
||||
|
||||
|
@ -12,11 +16,13 @@ const FullWidth: FC = ({ children }) => {
|
|||
const { width } = sample.current.getBoundingClientRect();
|
||||
const { clientWidth } = document.documentElement;
|
||||
|
||||
onRefresh(clientWidth);
|
||||
|
||||
return {
|
||||
width: clientWidth,
|
||||
transform: `translate(-${(clientWidth - width) / 2}px, 0)`,
|
||||
};
|
||||
}, [sample.current, clientWidth]);
|
||||
}, [sample.current, clientWidth, onRefresh]);
|
||||
|
||||
const onResize = useCallback(() => setClientWidth(document.documentElement.clientWidth), []);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue