mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
made arrows and keyboard triggers to move eveything
This commit is contained in:
parent
7109db0a52
commit
47ed05999a
2 changed files with 79 additions and 11 deletions
|
@ -1,4 +1,4 @@
|
||||||
import React, { FC, useMemo, useState, useEffect, useRef, useCallback } from 'react';
|
import React, { FC, useMemo, useState, useEffect, useRef, useCallback, KeyboardEvent } from 'react';
|
||||||
import { ImageSwitcher } from '../ImageSwitcher';
|
import { ImageSwitcher } from '../ImageSwitcher';
|
||||||
import * as styles from './styles.scss';
|
import * as styles from './styles.scss';
|
||||||
import { INode } from '~/redux/types';
|
import { INode } from '~/redux/types';
|
||||||
|
@ -233,6 +233,38 @@ const NodeImageSlideBlock: FC<IProps> = ({
|
||||||
[wrap]
|
[wrap]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const onPrev = useCallback(() => changeCurrent(current > 0 ? current - 1 : images.length - 1), [
|
||||||
|
changeCurrent,
|
||||||
|
current,
|
||||||
|
images,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const onNext = useCallback(() => changeCurrent(current < images.length - 1 ? current + 1 : 0), [
|
||||||
|
changeCurrent,
|
||||||
|
current,
|
||||||
|
images,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const onKeyDown = useCallback(
|
||||||
|
event => {
|
||||||
|
if (event.target.tagName && ['TEXTAREA', 'INPUT'].includes(event.target.tagName)) return;
|
||||||
|
|
||||||
|
switch (event.key) {
|
||||||
|
case 'ArrowLeft':
|
||||||
|
return onPrev();
|
||||||
|
case 'ArrowRight':
|
||||||
|
return onNext();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[onNext, onPrev]
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
window.addEventListener('keydown', onKeyDown);
|
||||||
|
|
||||||
|
return () => window.removeEventListener('keydown', onKeyDown);
|
||||||
|
}, [onKeyDown]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.wrap}>
|
<div className={styles.wrap}>
|
||||||
<div className={classNames(styles.cutter, { [styles.is_loading]: is_loading })} ref={wrap}>
|
<div className={classNames(styles.cutter, { [styles.is_loading]: is_loading })} ref={wrap}>
|
||||||
|
@ -298,13 +330,17 @@ const NodeImageSlideBlock: FC<IProps> = ({
|
||||||
*/}
|
*/}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={classNames(styles.image_arrow)}>
|
{images.length > 0 && (
|
||||||
|
<div className={classNames(styles.image_arrow)} onClick={onPrev}>
|
||||||
<Icon icon="left" size={40} />
|
<Icon icon="left" size={40} />
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<div className={classNames(styles.image_arrow, styles.image_arrow_right)}>
|
{images.length > 0 && (
|
||||||
|
<div className={classNames(styles.image_arrow, styles.image_arrow_right)} onClick={onNext}>
|
||||||
<Icon icon="right" size={40} />
|
<Icon icon="right" size={40} />
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,6 +16,11 @@
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@include tablet {
|
||||||
|
margin-left: 0;
|
||||||
|
margin-right: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.image_container {
|
.image_container {
|
||||||
|
@ -61,6 +66,10 @@
|
||||||
&:global(.is_active) {
|
&:global(.is_active) {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@include tablet {
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.image_count {
|
.image_count {
|
||||||
|
@ -68,10 +77,10 @@
|
||||||
color: transparentize(white, 0.5);
|
color: transparentize(white, 0.5);
|
||||||
bottom: $gap * 3;
|
bottom: $gap * 3;
|
||||||
right: 50%;
|
right: 50%;
|
||||||
padding: $gap / 2 $gap * 1.2;
|
padding: $gap / 3 $gap;
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
background: $content_bg;
|
background: $content_bg;
|
||||||
font: $font_14_semibold;
|
font: $font_12_semibold;
|
||||||
transform: translate(50%, 0);
|
transform: translate(50%, 0);
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
@ -80,7 +89,7 @@
|
||||||
|
|
||||||
small {
|
small {
|
||||||
font-size: 0.8em;
|
font-size: 0.8em;
|
||||||
padding: 0 5px;
|
padding: 0 3px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +104,13 @@
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
transform: translate(-100%, -50%);
|
transform: translate(-100%, -50%);
|
||||||
display: none;
|
cursor: pointer;
|
||||||
|
opacity: 0.7;
|
||||||
|
transition: opacity 0.5s;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
&_right {
|
&_right {
|
||||||
right: -$gap;
|
right: -$gap;
|
||||||
|
@ -103,6 +118,23 @@
|
||||||
transform: translate(100%, -50%);
|
transform: translate(100%, -50%);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (max-width: $content_width + 80px + 40px) {
|
||||||
|
background: $content_bg;
|
||||||
|
left: 0;
|
||||||
|
transform: translate(0, -50%);
|
||||||
|
border-radius: 0 $radius $radius 0;
|
||||||
|
|
||||||
|
&_right {
|
||||||
|
right: 0;
|
||||||
|
left: auto;
|
||||||
|
border-radius: $radius 0 0 $radius;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@include tablet {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
position: relative;
|
position: relative;
|
||||||
left: -2px;
|
left: -2px;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue