mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
feat(post): add post menu component with links to other clients
This commit is contained in:
@@ -0,0 +1 @@
|
||||
export { default } from './post-menu';
|
||||
@@ -0,0 +1,86 @@
|
||||
.postMenu {
|
||||
position: absolute;
|
||||
background-color: var(--post-menu-background-color);
|
||||
border-bottom: 2px solid var(--post-menu-border-color);
|
||||
border-right: 1px solid var(--post-menu-border-color);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.postMenuBtnWrapper {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
padding-left: 15px;
|
||||
}
|
||||
|
||||
.postMenuBtn {
|
||||
color: var(--post-menu-button-color);
|
||||
transition: transform 0.1s;
|
||||
transform: rotate(90deg);
|
||||
position: absolute;
|
||||
bottom: -4px;
|
||||
}
|
||||
|
||||
.postMenuBtn:hover {
|
||||
cursor: pointer;
|
||||
color: var(--post-menu-button-color-hover);
|
||||
}
|
||||
|
||||
.postMenuItem {
|
||||
cursor: pointer;
|
||||
padding: 2px 4px;
|
||||
border: 1px solid var(--post-menu-item-border-color);
|
||||
background-color: var(--post-menu-item-background-color);
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.postMenuItem:hover {
|
||||
background-color: var(--post-menu-item-hover-background-color);
|
||||
}
|
||||
|
||||
.dropdown {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.dropdownMenu {
|
||||
position: absolute;
|
||||
left: 100%;
|
||||
top: -1px;
|
||||
display: none;
|
||||
border-bottom: 2px solid var(--post-menu-border-color);
|
||||
border-right: 1px solid var(--post-menu-border-color);
|
||||
}
|
||||
|
||||
.dropdown a {
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.dropdown:hover .dropdownMenu {
|
||||
display: block;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.postMenuBtn {
|
||||
width: 1em;
|
||||
text-align: center;
|
||||
font-weight: 700;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.postMenuBtnWrapper {
|
||||
position: relative;
|
||||
padding-right: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 640px) {
|
||||
.postMenuBtn {
|
||||
right: -2px;
|
||||
opacity: var(--post-menu-btn-opacity);
|
||||
}
|
||||
|
||||
.stickyIconWrapper {
|
||||
padding-right: 18px;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import { useState } from 'react';
|
||||
import { autoUpdate, flip, FloatingFocusManager, offset, shift, useClick, useDismiss, useFloating, useId, useInteractions, useRole } from '@floating-ui/react';
|
||||
import { Comment } from '@plebbit/plebbit-react-hooks';
|
||||
import styles from './post-menu.module.css';
|
||||
|
||||
const PostMenu = ({ post }: Comment) => {
|
||||
const { cid, isDescription, isRules, link, subplebbitAddress } = post;
|
||||
const [menuBtnRotated, setMenuBtnRotated] = useState(false);
|
||||
const [isClientRedirectMenuOpen, setIsClientRedirectMenuOpen] = useState(false);
|
||||
|
||||
const { refs, floatingStyles, context } = useFloating({
|
||||
placement: 'bottom-start',
|
||||
open: menuBtnRotated,
|
||||
onOpenChange: setMenuBtnRotated,
|
||||
middleware: [offset({ mainAxis: 10, crossAxis: 5 }), flip({ fallbackAxisSideDirection: 'end' }), shift({ padding: 10 })],
|
||||
whileElementsMounted: autoUpdate,
|
||||
});
|
||||
|
||||
const click = useClick(context);
|
||||
const dismiss = useDismiss(context);
|
||||
const role = useRole(context);
|
||||
|
||||
const { getReferenceProps, getFloatingProps } = useInteractions([click, dismiss, role]);
|
||||
|
||||
const headingId = useId();
|
||||
|
||||
const viewOnOtherClientLink = `p/${subplebbitAddress}${isDescription || isRules ? '' : `/c/${cid}`}`;
|
||||
|
||||
return (
|
||||
<>
|
||||
<span className={styles.postMenuBtnWrapper} ref={refs.setReference} {...getReferenceProps()}>
|
||||
<span
|
||||
className={styles.postMenuBtn}
|
||||
title='Post menu'
|
||||
onClick={() => setMenuBtnRotated((prev) => !prev)}
|
||||
style={{ transform: menuBtnRotated ? 'rotate(90deg)' : 'rotate(0deg)' }}
|
||||
>
|
||||
▶
|
||||
</span>
|
||||
</span>
|
||||
{menuBtnRotated && (
|
||||
<FloatingFocusManager context={context} modal={false}>
|
||||
<div className={styles.postMenu} ref={refs.setFloating} style={floatingStyles} aria-labelledby={headingId} {...getFloatingProps()}>
|
||||
<div
|
||||
className={`${styles.postMenuItem} ${styles.dropdown}`}
|
||||
onMouseOver={() => setIsClientRedirectMenuOpen(true)}
|
||||
onMouseLeave={() => setIsClientRedirectMenuOpen(false)}
|
||||
>
|
||||
View on »
|
||||
{isClientRedirectMenuOpen && (
|
||||
<div className={styles.dropdownMenu}>
|
||||
<div className={styles.postMenuItem}>
|
||||
<a href={`https://seedit.app/#/${viewOnOtherClientLink}`} target='_blank' rel='noreferrer'>
|
||||
Seedit
|
||||
</a>
|
||||
</div>
|
||||
<div className={styles.postMenuItem}>
|
||||
<a href={`https://plebones.netlify.app/#/${viewOnOtherClientLink}`} target='_blank' rel='noreferrer'>
|
||||
Plebones
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</FloatingFocusManager>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default PostMenu;
|
||||
Reference in New Issue
Block a user