Skip to content

Commit

Permalink
feat: add toolbar and portal
Browse files Browse the repository at this point in the history
  • Loading branch information
remvze committed Apr 8, 2024
1 parent 6dfa998 commit ede4801
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 49 deletions.
6 changes: 2 additions & 4 deletions src/components/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import { Container } from '@/components/container';
import { StoreConsumer } from '@/components/store-consumer';
import { Buttons } from '@/components/buttons';
import { Categories } from '@/components/categories';
import { ScrollToTop } from '@/components/scroll-to-top';
import { SharedModal } from '@/components/modals/shared';
import { Menu } from '@/components/menu/menu';
import { Toolbar } from '@/components/toolbar';
import { SnackbarProvider } from '@/contexts/snackbar';

import { sounds } from '@/data/sounds';
Expand Down Expand Up @@ -77,8 +76,7 @@ export function App() {
<Categories categories={allCategories} />
</Container>

<ScrollToTop />
<Menu />
<Toolbar />
<SharedModal />
</StoreConsumer>
</SnackbarProvider>
Expand Down
4 changes: 4 additions & 0 deletions src/components/container/container.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
&.tight {
max-width: 450px;
}

&.wide {
max-width: 720px;
}
}
17 changes: 15 additions & 2 deletions src/components/container/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,24 @@ interface ContainerProps {
children: React.ReactNode;
className?: string;
tight?: boolean;
wide?: boolean;
}

export function Container({ children, className, tight }: ContainerProps) {
export function Container({
children,
className,
tight,
wide,
}: ContainerProps) {
return (
<div className={cn(styles.container, className, tight && styles.tight)}>
<div
className={cn(
styles.container,
className,
tight && styles.tight,
wide && styles.wide,
)}
>
{children}
</div>
);
Expand Down
9 changes: 0 additions & 9 deletions src/components/menu/menu.module.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
.wrapper {
position: fixed;
right: calc(50vw - 400px);
bottom: 20px;
z-index: 15;

@media (width <= 850px) {
right: 5vw;
}

& .menuButton {
display: flex;
align-items: center;
Expand Down
54 changes: 29 additions & 25 deletions src/components/modal/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { useEffect } from 'react';
import { AnimatePresence, motion } from 'framer-motion';
import { IoClose } from 'react-icons/io5/index';

import { Portal } from '@/components/portal';

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

Expand Down Expand Up @@ -36,35 +38,37 @@ export function Modal({
}, [show, lockBody]);

return (
<AnimatePresence>
{show && (
<>
<motion.div
animate="show"
className={styles.overlay}
exit="hidden"
initial="hidden"
variants={variants.overlay}
onClick={onClose}
onKeyDown={onClose}
/>
<div className={styles.modal}>
<Portal>
<AnimatePresence>
{show && (
<>
<motion.div
animate="show"
className={cn(styles.content, wide && styles.wide)}
className={styles.overlay}
exit="hidden"
initial="hidden"
variants={variants.modal}
>
<button className={styles.close} onClick={onClose}>
<IoClose />
</button>
variants={variants.overlay}
onClick={onClose}
onKeyDown={onClose}
/>
<div className={styles.modal}>
<motion.div
animate="show"
className={cn(styles.content, wide && styles.wide)}
exit="hidden"
initial="hidden"
variants={variants.modal}
>
<button className={styles.close} onClick={onClose}>
<IoClose />
</button>

{children}
</motion.div>
</div>
</>
)}
</AnimatePresence>
{children}
</motion.div>
</div>
</>
)}
</AnimatePresence>
</Portal>
);
}
1 change: 1 addition & 0 deletions src/components/portal/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Portal } from './portal';
14 changes: 14 additions & 0 deletions src/components/portal/portal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { useState, useEffect } from 'react';
import { createPortal } from 'react-dom';

interface PortalProps {
children: React.ReactNode;
}

export function Portal({ children }: PortalProps) {
const [isClientSide, setIsClientSide] = useState(false);

useEffect(() => setIsClientSide(true), []);

return isClientSide ? createPortal(children, document.body) : null;
}
8 changes: 0 additions & 8 deletions src/components/scroll-to-top/scroll-to-top.module.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
.button {
position: fixed;
bottom: 20px;
left: calc(50vw - 400px);
z-index: 10;
display: flex;
align-items: center;
justify-content: center;
Expand All @@ -16,10 +12,6 @@
border-radius: 50%;
transition: 0.2s;

@media (width <= 850px) {
left: 5vw;
}

&:hover {
background-color: var(--color-neutral-200);
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/scroll-to-top/scroll-to-top.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function ScrollToTop() {

return (
<AnimatePresence>
{isVisible && (
{isVisible ? (
<motion.button
animate="show"
aria-label="Scroll to top"
Expand All @@ -43,6 +43,8 @@ export function ScrollToTop() {
>
<BiUpArrowAlt />
</motion.button>
) : (
<div />
)}
</AnimatePresence>
);
Expand Down
1 change: 1 addition & 0 deletions src/components/toolbar/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Toolbar } from './toolbar';
13 changes: 13 additions & 0 deletions src/components/toolbar/toolbar.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.wrapper {
position: fixed;
bottom: 20px;
left: 0;
z-index: 15;
width: 100%;

.container {
display: flex;
align-items: center;
justify-content: space-between;
}
}
16 changes: 16 additions & 0 deletions src/components/toolbar/toolbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Container } from '@/components/container';
import { Menu } from '@/components/menu';
import { ScrollToTop } from '@/components/scroll-to-top';

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

export function Toolbar() {
return (
<div className={styles.wrapper}>
<Container className={styles.container} wide>
<ScrollToTop />
<Menu />
</Container>
</div>
);
}

0 comments on commit ede4801

Please sign in to comment.