Skip to content

Commit

Permalink
feat: basic structure for share link
Browse files Browse the repository at this point in the history
  • Loading branch information
remvze committed Jan 2, 2024
1 parent 35e3215 commit ef81f19
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 71 deletions.
9 changes: 9 additions & 0 deletions src/components/menu/items/share.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Item } from '../item';

interface ShareProps {
open: () => void;
}

export function Share({ open }: ShareProps) {
return <Item onClick={open}>Share Sounds</Item>;
}
1 change: 0 additions & 1 deletion src/components/menu/items/share/index.ts

This file was deleted.

36 changes: 0 additions & 36 deletions src/components/menu/items/share/share.tsx

This file was deleted.

74 changes: 42 additions & 32 deletions src/components/menu/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '@floating-ui/react';

import { ShuffleItem, ShareItem } from './items';
import { ShareLinkModal } from '@/components/modals/share-link';

import { slideY, fade, mix } from '@/lib/motion';

Expand All @@ -23,6 +24,8 @@ import styles from './menu.module.css';
export function Menu() {
const [isOpen, setIsOpen] = useState(false);

const [showShareLink, setShowShareLink] = useState(false);

const variants = mix(slideY(-20), fade());

const { context, floatingStyles, refs } = useFloating({
Expand All @@ -44,39 +47,46 @@ export function Menu() {
]);

return (
<div className={styles.wrapper}>
<button
aria-label="Menu"
className={styles.menuButton}
ref={refs.setReference}
onClick={() => setIsOpen(prev => !prev)}
{...getReferenceProps()}
>
{isOpen ? <IoClose /> : <IoMenu />}
</button>
<>
<div className={styles.wrapper}>
<button
aria-label="Menu"
className={styles.menuButton}
ref={refs.setReference}
onClick={() => setIsOpen(prev => !prev)}
{...getReferenceProps()}
>
{isOpen ? <IoClose /> : <IoMenu />}
</button>

<AnimatePresence>
{isOpen && (
<FloatingFocusManager context={context}>
<div
ref={refs.setFloating}
style={floatingStyles}
{...getFloatingProps()}
>
<motion.div
animate="show"
className={styles.menu}
exit="hidden"
initial="hidden"
variants={variants}
<AnimatePresence>
{isOpen && (
<FloatingFocusManager context={context} modal={false}>
<div
ref={refs.setFloating}
style={floatingStyles}
{...getFloatingProps()}
>
<ShareItem />
<ShuffleItem />
</motion.div>
</div>
</FloatingFocusManager>
)}
</AnimatePresence>
</div>
<motion.div
animate="show"
className={styles.menu}
exit="hidden"
initial="hidden"
variants={variants}
>
<ShareItem open={() => setShowShareLink(true)} />
<ShuffleItem />
</motion.div>
</div>
</FloatingFocusManager>
)}
</AnimatePresence>
</div>

<ShareLinkModal
show={showShareLink}
onClose={() => setShowShareLink(false)}
/>
</>
);
}
20 changes: 20 additions & 0 deletions src/components/modal/modal.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,35 @@
max-height: 100%;
padding: 50px 0;
overflow-y: auto;
pointer-events: none;
transform: translate(-50%, -50%);

& .content {
position: relative;
width: 90%;
max-width: 500px;
padding: 20px;
padding-top: 40px;
margin: 0 auto;
pointer-events: fill;
background-color: var(--color-neutral-100);
border-radius: 8px;

& .close {
position: absolute;
top: 10px;
right: 10px;
display: flex;
align-items: center;
justify-content: center;
width: 20px;
height: 20px;
font-size: 16px;
color: var(--color-foreground-subtle);
cursor: pointer;
background-color: transparent;
border: none;
outline: none;
}
}
}
9 changes: 8 additions & 1 deletion src/components/modal/modal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AnimatePresence } from 'framer-motion';
import { IoClose } from 'react-icons/io5/index';

import styles from './modal.module.css';

Expand All @@ -19,7 +20,13 @@ export function Modal({ children, onClose, show }: ModalProps) {
onKeyDown={onClose}
/>
<div className={styles.modal}>
<div className={styles.content}>{children}</div>
<div className={styles.content}>
<button className={styles.close} onClick={onClose}>
<IoClose />
</button>

{children}
</div>
</div>
</>
)}
Expand Down
1 change: 1 addition & 0 deletions src/components/modals/share-link/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { ShareLinkModal } from './share-link';
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
align-items: center;
width: 100%;
height: 45px;
padding: 4px;
margin-top: 12px;
background-color: var(--color-neutral-50);
border: 1px solid var(--color-neutral-200);
Expand All @@ -23,9 +24,30 @@
& input {
flex-grow: 1;
height: 100%;
color: red;
padding: 0 10px;
font-size: var(--font-sm);
color: var(--color-foreground);
background: transparent;
border: none;
outline: none;
}

& button {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
aspect-ratio: 1 / 1;
color: var(--color-foreground);
cursor: pointer;
background-color: var(--color-neutral-100);
border: none;
border-radius: 4px;
outline: none;
transition: 0.2s;

&:hover {
background-color: var(--color-neutral-200);
}
}
}
28 changes: 28 additions & 0 deletions src/components/modals/share-link/share-link.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { IoCopyOutline } from 'react-icons/io5/index';

import { Modal } from '@/components/modal';

import styles from './share-link.module.css';

interface ShareLinkModalProps {
onClose: () => void;
show: boolean;
}

export function ShareLinkModal({ onClose, show }: ShareLinkModalProps) {
return (
<Modal show={show} onClose={onClose}>
<h1 className={styles.heading}>Share your sound selection!</h1>
<p className={styles.desc}>
Copy and send the following link to the person you want to share your
selection with.
</p>
<div className={styles.inputWrapper}>
<input type="text" value="https://moodist.app/?share=test" />
<button>
<IoCopyOutline />
</button>
</div>
</Modal>
);
}

0 comments on commit ef81f19

Please sign in to comment.