Skip to content

Commit

Permalink
refactor: better item structure for menu
Browse files Browse the repository at this point in the history
  • Loading branch information
remvze committed Jan 2, 2024
1 parent fe2357c commit 26bf016
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 32 deletions.
14 changes: 0 additions & 14 deletions src/components/menu/buttons/button.tsx

This file was deleted.

2 changes: 0 additions & 2 deletions src/components/menu/buttons/index.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/components/menu/buttons/shuffle.tsx

This file was deleted.

1 change: 1 addition & 0 deletions src/components/menu/item/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Item } from './item';
20 changes: 20 additions & 0 deletions src/components/menu/item/item.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.item {
position: flex;
align-items: center;
width: 100%;
padding: 12px 8px;
font-size: var(--font-sm);
font-weight: 500;
color: var(--color-foreground-subtle);
cursor: pointer;
background-color: transparent;
border: 1px solid var(--color-neutral-200);
border-radius: 4px;
outline: none;
transition: 0.2s;

&:hover {
color: var(--color-foreground);
background-color: var(--color-neutral-200);
}
}
14 changes: 14 additions & 0 deletions src/components/menu/item/item.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import styles from './item.module.css';

interface ItemProps {
children: React.ReactNode;
onClick: () => void;
}

export function Item({ children, onClick }: ItemProps) {
return (
<button className={styles.item} onClick={onClick}>
{children}
</button>
);
}
2 changes: 2 additions & 0 deletions src/components/menu/items/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { Shuffle as ShuffleItem } from './shuffle';
export { Share as ShareItem } from './share';
1 change: 1 addition & 0 deletions src/components/menu/items/share/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Share } from './share';
4 changes: 4 additions & 0 deletions src/components/menu/items/share/share.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.heading {
font-family: var(--font-heading);
font-weight: 700;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ import { createPortal } from 'react-dom';

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

import { Button } from './button';
import { Item } from '../../item';

export function ShareButton() {
import styles from './share.module.css';

export function Share() {
const [isModalOpen, setIsModalOpen] = useState(false);

return (
<>
<Button onClick={() => setIsModalOpen(true)}>Share Sounds</Button>
<Item onClick={() => setIsModalOpen(true)}>Share Sounds</Item>

{createPortal(
<Modal show={isModalOpen} onClose={() => setIsModalOpen(false)}>
<h1>Share Sounds!</h1>
<h1 className={styles.heading}>Share Sounds!</h1>
</Modal>,
document.body,
)}
Expand Down
9 changes: 9 additions & 0 deletions src/components/menu/items/shuffle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useSoundStore } from '@/store';

import { Item } from '../item';

export function Shuffle() {
const shuffle = useSoundStore(state => state.shuffle);

return <Item onClick={shuffle}>Shuffle Sounds</Item>;
}
6 changes: 3 additions & 3 deletions src/components/menu/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
FloatingFocusManager,
} from '@floating-ui/react';

import { ShuffleButton, ShareButton } from './buttons';
import { ShuffleItem, ShareItem } from './items';

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

Expand Down Expand Up @@ -70,8 +70,8 @@ export function Menu() {
initial="hidden"
variants={variants}
>
<ShareButton />
<ShuffleButton />
<ShareItem />
<ShuffleItem />
</motion.div>
</div>
</FloatingFocusManager>
Expand Down

0 comments on commit 26bf016

Please sign in to comment.