mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-26 05:16:41 +07:00
added node edit menu
This commit is contained in:
parent
f185914c7c
commit
74f4c7562b
16 changed files with 320 additions and 175 deletions
|
@ -1,12 +1,17 @@
|
|||
import React, { VFC } from 'react';
|
||||
|
||||
import Tippy from '@tippyjs/react';
|
||||
import classNames from 'classnames';
|
||||
|
||||
import { Icon } from '~/components/input/Icon';
|
||||
import { MenuButton, MenuItemWithIcon, SeparatedMenu } from '~/components/menu';
|
||||
import { useWindowSize } from '~/hooks/dom/useWindowSize';
|
||||
|
||||
import styles from './styles.module.scss';
|
||||
|
||||
interface NodeEditMenuProps {
|
||||
className?: string;
|
||||
|
||||
canStar: boolean;
|
||||
|
||||
isHeroic: boolean;
|
||||
|
@ -18,36 +23,62 @@ interface NodeEditMenuProps {
|
|||
}
|
||||
|
||||
const NodeEditMenu: VFC<NodeEditMenuProps> = ({
|
||||
className,
|
||||
canStar,
|
||||
isHeroic,
|
||||
isLocked,
|
||||
onStar,
|
||||
onLock,
|
||||
onEdit,
|
||||
}) => (
|
||||
<div className={styles.editor_menu}>
|
||||
<div className={styles.editor_menu_button}>
|
||||
<Icon icon="dots-vertical" size={24} />
|
||||
</div>
|
||||
}) => {
|
||||
const { isMobile } = useWindowSize();
|
||||
|
||||
<div className={styles.editor_buttons}>
|
||||
if (isMobile) {
|
||||
return (
|
||||
<MenuButton
|
||||
icon={<Icon icon="dots-vertical" className={styles.icon} size={24} />}
|
||||
className={className}
|
||||
>
|
||||
{canStar && (
|
||||
<MenuItemWithIcon icon={isHeroic ? 'star_full' : 'star'} onClick={onStar}>
|
||||
{isHeroic ? 'Убрать с главной' : 'На главную'}
|
||||
</MenuItemWithIcon>
|
||||
)}
|
||||
|
||||
<MenuItemWithIcon icon="edit" onClick={onEdit}>
|
||||
Редактировать
|
||||
</MenuItemWithIcon>
|
||||
|
||||
<MenuItemWithIcon icon={isLocked ? 'locked' : 'unlocked'} onClick={onLock}>
|
||||
{isLocked ? 'Восстановить' : 'Удалить'}
|
||||
</MenuItemWithIcon>
|
||||
</MenuButton>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<SeparatedMenu>
|
||||
{canStar && (
|
||||
<div className={classNames(styles.star, { [styles.is_heroic]: isHeroic })}>
|
||||
{isHeroic ? (
|
||||
<Icon icon="star_full" size={24} onClick={onStar} />
|
||||
) : (
|
||||
<Icon icon="star" size={24} onClick={onStar} />
|
||||
)}
|
||||
</div>
|
||||
<Tippy content={isHeroic ? 'Убрать с главной' : 'На главную'}>
|
||||
<button className={className} onClick={onStar}>
|
||||
<Icon icon={isHeroic ? 'star_full' : 'star'} size={24} />
|
||||
</button>
|
||||
</Tippy>
|
||||
)}
|
||||
|
||||
<div>
|
||||
<Icon icon={isLocked ? 'locked' : 'unlocked'} size={24} onClick={onLock} />
|
||||
</div>
|
||||
<Tippy content="Редактировать">
|
||||
<button className={className} onClick={onEdit}>
|
||||
<Icon icon="edit" size={24} />
|
||||
</button>
|
||||
</Tippy>
|
||||
|
||||
<Icon icon="edit" size={24} onClick={onEdit} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
<Tippy content={isLocked ? 'Восстановить' : 'Удалить'}>
|
||||
<button className={className} onClick={onLock}>
|
||||
<Icon icon={isLocked ? 'locked' : 'unlocked'} size={24} />
|
||||
</button>
|
||||
</Tippy>
|
||||
</SeparatedMenu>
|
||||
);
|
||||
};
|
||||
|
||||
export { NodeEditMenu };
|
||||
|
|
|
@ -1,109 +1,3 @@
|
|||
@import "src/styles/variables";
|
||||
@import "src/styles/mixins";
|
||||
|
||||
@mixin button {
|
||||
margin: 12px $gap 0 $gap;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
svg {
|
||||
fill: darken(white, 50%);
|
||||
transition: fill 0.25s;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
svg {
|
||||
fill: $red;
|
||||
}
|
||||
}
|
||||
|
||||
&::after {
|
||||
content: ' ';
|
||||
flex: 0 0 6px;
|
||||
height: $gap;
|
||||
width: 6px;
|
||||
border-radius: 4px;
|
||||
background: transparentize(black, 0.7);
|
||||
margin-left: $gap * 2;
|
||||
}
|
||||
}
|
||||
|
||||
.editor_buttons {
|
||||
flex: 0;
|
||||
padding-right: $gap;
|
||||
fill: transparentize(white, 0.7);
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
& > * {
|
||||
@include button;
|
||||
}
|
||||
|
||||
@include tablet {
|
||||
align-self: center;
|
||||
display: none;
|
||||
|
||||
& > * {
|
||||
&:last-child {
|
||||
margin-right: 0;
|
||||
|
||||
&::after {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
&:first-child {
|
||||
margin-left: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.star {
|
||||
transition: fill, stroke 0.25s;
|
||||
will-change: transform;
|
||||
|
||||
.is_heroic {
|
||||
svg {
|
||||
fill: $orange;
|
||||
}
|
||||
}
|
||||
|
||||
&:hover {
|
||||
fill: $orange;
|
||||
}
|
||||
}
|
||||
|
||||
.editor_menu_button {
|
||||
display: none !important;
|
||||
|
||||
@include button();
|
||||
|
||||
@include tablet {
|
||||
display: flex !important;
|
||||
}
|
||||
}
|
||||
|
||||
.editor_menu {
|
||||
&:hover {
|
||||
.editor_buttons {
|
||||
@include tablet {
|
||||
display: flex;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 100%;
|
||||
background: darken($content_bg, 4%);
|
||||
padding: $gap * 2;
|
||||
border-radius: $radius;
|
||||
box-shadow: transparentize(black, 0.8) 5px 5px 5px;
|
||||
transform: translate(0, -10px);
|
||||
z-index: 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
.icon {
|
||||
fill: currentColor;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ import React, { memo, VFC } from 'react';
|
|||
import classNames from 'classnames';
|
||||
|
||||
import { Icon } from '~/components/input/Icon';
|
||||
import { SeparatedMenu } from '~/components/menu';
|
||||
import { NodeEditMenu } from '~/components/node/NodeEditMenu';
|
||||
import { Placeholder } from '~/components/placeholders/Placeholder';
|
||||
import { getPrettyDate } from '~/utils/dom';
|
||||
|
@ -74,20 +75,23 @@ const NodeTitle: VFC<IProps> = memo(
|
|||
)}
|
||||
</div>
|
||||
|
||||
{canEdit && (
|
||||
<NodeEditMenu
|
||||
canStar={canStar}
|
||||
isHeroic={isHeroic}
|
||||
isLocked={isLocked}
|
||||
onStar={onStar}
|
||||
onLock={onLock}
|
||||
onEdit={onEdit}
|
||||
/>
|
||||
)}
|
||||
<SeparatedMenu className={styles.buttons}>
|
||||
{canEdit && (
|
||||
<NodeEditMenu
|
||||
className={styles.button}
|
||||
canStar={canStar}
|
||||
isHeroic={isHeroic}
|
||||
isLocked={isLocked}
|
||||
onStar={onStar}
|
||||
onLock={onLock}
|
||||
onEdit={onEdit}
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className={styles.buttons}>
|
||||
{canLike && (
|
||||
<div className={classNames(styles.like, { [styles.is_liked]: isLiked })}>
|
||||
<div
|
||||
className={classNames(styles.button, styles.like, { [styles.is_liked]: isLiked })}
|
||||
>
|
||||
{isLiked ? (
|
||||
<Icon icon="heart_full" size={24} onClick={onLike} />
|
||||
) : (
|
||||
|
@ -99,7 +103,7 @@ const NodeTitle: VFC<IProps> = memo(
|
|||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</SeparatedMenu>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -72,7 +72,7 @@
|
|||
}
|
||||
|
||||
.name {
|
||||
font: $font_14_regular;
|
||||
font: $font_12_regular;
|
||||
color: transparentize(white, 0.5);
|
||||
text-transform: lowercase;
|
||||
|
||||
|
@ -95,37 +95,6 @@
|
|||
min-width: 0;
|
||||
}
|
||||
|
||||
.buttons {
|
||||
flex: 0;
|
||||
padding-right: $gap;
|
||||
fill: transparentize(white, 0.7);
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-top: 12px;
|
||||
|
||||
& > * {
|
||||
@include button;
|
||||
}
|
||||
|
||||
@include tablet {
|
||||
align-self: center;
|
||||
}
|
||||
}
|
||||
|
||||
.buttons {
|
||||
& > * {
|
||||
&:last-child {
|
||||
margin-right: 0;
|
||||
|
||||
&::after {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.mark {
|
||||
flex: 0 0 32px;
|
||||
position: relative;
|
||||
|
@ -177,8 +146,11 @@
|
|||
will-change: transform;
|
||||
position: relative;
|
||||
flex: 0 0 32px;
|
||||
fill: currentColor;
|
||||
|
||||
&.is_liked {
|
||||
opacity: 1;
|
||||
|
||||
svg {
|
||||
fill: $red;
|
||||
}
|
||||
|
@ -213,3 +185,13 @@
|
|||
pointer-events: none;
|
||||
touch-action: none;
|
||||
}
|
||||
|
||||
.buttons {
|
||||
margin-top: 12px;
|
||||
margin-right: $gap;
|
||||
}
|
||||
|
||||
.button {
|
||||
color: white;
|
||||
@include hover_opacity;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue