- 소스 파일
- 2
- 버전
- v1.0.0
- 함께 쓰는 항목
- 1
1280px
설치
이 명령 한 줄이면 필요한 파일과 패키지가 함께 설치돼요.
터미널터미널터미널bash
npx shadcn@latest add https://dsui.vercel.app/r/mobile-nav-sheet.json파일
components/arc/blocks/mobile-nav-sheet/mobile-nav-sheet.module.csscomponents/arc/blocks/mobile-nav-sheet/mobile-nav-sheet.tsx
npm 패키지
@hugeicons/core-free-icons@^4.3.5@hugeicons/react@^1.1.10
- v1.0.0처음 공개했어요.
mobile-nav-sheet.module.cssmobile-nav-sheet.module.cssmobile-nav-sheet.module.csscss
/* The bottom sheet supplies the muted ground, its shadow and its matching border; the menu lays out white cards on it. */
.sheet { display: grid; align-content: start; gap: var(--space-5); padding: var(--space-1) 0 var(--space-2); }
.trigger { display: inline-flex; width: var(--control-height-md); height: var(--control-height-md); align-items: center; justify-content: center; border: 0; border-radius: var(--radius-pill); background: var(--surface-muted); color: var(--foreground); cursor: pointer; -webkit-tap-highlight-color: transparent; transition: background var(--duration-fast) var(--ease-standard); }
.card { display: grid; margin: 0; padding: var(--space-1) 0 var(--space-1) var(--space-5); overflow: hidden; border-radius: var(--radius-surface); background: var(--surface); list-style: none; }
/* A hairline between rows, from the text edge to the card's edge. */
.card > * + * { position: relative; }
.card > * + *::before { position: absolute; top: 0; right: 0; left: 0; height: 1px; background: var(--border-subtle); content: ""; }
/* Touch targets are the full width of the card and past 44px, since this is the thumb's menu. */
.link { display: flex; min-height: 3.25rem; align-items: center; gap: var(--space-3); padding-right: var(--space-5); color: var(--foreground); font-size: var(--label-lg); font-weight: var(--label-weight); line-height: var(--leading-body); text-decoration: none; -webkit-tap-highlight-color: transparent; transition: color var(--duration-fast) var(--ease-standard); }
.linkLabel { flex: 1 1 auto; min-width: 0; }
.chevron { flex: none; color: var(--text-secondary); }
.link[aria-current="page"], .link[aria-current="page"] .chevron { color: var(--accent-strong); }
.cta { display: flex; min-height: var(--control-height-lg); align-items: center; justify-content: center; border: 1px solid var(--accent); border-radius: var(--radius-pill); background: var(--accent); color: var(--accent-foreground); box-shadow: var(--shadow-accent-resting); font-size: var(--label-lg); font-weight: var(--label-weight); line-height: var(--leading-body); text-decoration: none; transition: background var(--duration-fast) var(--ease-standard), border-color var(--duration-fast) var(--ease-standard); }
.settingRow { display: flex; min-height: 3.25rem; align-items: center; justify-content: space-between; gap: var(--space-3); padding-right: var(--space-5); }
.settingLabel { flex: 1 1 auto; min-width: 0; font-size: var(--label-lg); font-weight: var(--label-weight); }
.settingControl { display: flex; flex: none; justify-content: flex-end; }
.account { display: flex; min-height: 3.25rem; align-items: center; padding-right: var(--space-5); }
@media (hover: hover) and (pointer: fine) {
.trigger:hover { background: var(--surface-sunken); }
.link:hover { color: var(--text-secondary); }
.link[aria-current="page"]:hover { color: var(--accent-strong); }
.cta:hover { background: var(--accent-pressed); border-color: var(--accent-pressed); }
}
.trigger:active { background: var(--surface-sunken); }
.link:active { color: var(--text-secondary); }
.cta:active { background: var(--accent-pressed); border-color: var(--accent-pressed); }
@media (prefers-reduced-motion: reduce) { .trigger, .link, .cta { transition: none; } }
mobile-nav-sheet.tsxmobile-nav-sheet.tsxmobile-nav-sheet.tsxtsx
"use client";
import { useState } from "react";
import type { ReactNode } from "react";
import { HugeiconsIcon } from "@hugeicons/react";
import { Menu01Icon } from "@hugeicons/core-free-icons";
import { BottomSheet } from "../../bottom-sheet/bottom-sheet";
import { playUiSound } from "../../sound/play";
import { UiIcon } from "../../theme/ui-icon";
import styles from "./mobile-nav-sheet.module.css";
export interface MobileNavLink {
href: string;
label: string;
/** Marks the page the reader is on. */
current?: boolean;
}
export interface MobileNavSettingRow {
label: string;
control: ReactNode;
}
export interface MobileNavSheetProps {
/** The sheet's accessible title, e.g. "메뉴". */
title: string;
links: MobileNavLink[];
/** The accessible name of the list of links, e.g. "주요 메뉴". */
navLabel: string;
cta?: { href: string; label: string };
/** One row per setting, such as language and theme. */
settings?: MobileNavSettingRow[];
/** The account block, pinned to the bottom of the sheet. */
account?: ReactNode;
/** The accessible name of the default menu button, e.g. "메뉴 열기". */
triggerLabel?: string;
/** Replaces the default menu button. Needs to accept a ref and the Radix trigger props. */
trigger?: ReactNode;
/** Kept so existing callers still compile; the menu is a bottom sheet now and has no side. */
side?: "left" | "right";
open?: boolean;
onOpenChange?: (open: boolean) => void;
}
/**
* The header's menu on a narrow screen: the same links, the same call to action, and the settings and account that
* do not fit in the bar. It is a bottom sheet of grouped cards, so focus is trapped while it is open, Escape closes it
* and focus returns to the button. Choosing a link closes it on the press rather than on the route change, so the
* panel never lingers over the next page.
*/
export function MobileNavSheet({
title,
links,
navLabel,
cta,
settings,
account,
triggerLabel = "메뉴 열기",
trigger,
open: openProp,
onOpenChange,
}: MobileNavSheetProps) {
const [openState, setOpenState] = useState(false);
const open = openProp ?? openState;
const setOpen = (next: boolean) => { setOpenState(next); onOpenChange?.(next); };
const close = () => setOpen(false);
const menuButton = (
<button type="button" className={styles.trigger} aria-label={triggerLabel}>
<HugeiconsIcon icon={Menu01Icon} size={20} strokeWidth={1.75} aria-hidden="true" />
</button>
);
return (
<BottomSheet variant="grouped" open={open} onOpenChange={setOpen} title={title} detents={[0.8]} trigger={trigger ?? menuButton}>
<div className={styles.sheet}>
<nav aria-label={navLabel}>
<ul className={styles.card}>
{links.map(link => (
<li key={link.href}>
<a
href={link.href}
aria-current={link.current ? "page" : undefined}
className={styles.link}
onClick={() => { playUiSound("tick"); close(); }}
>
<span className={styles.linkLabel}>{link.label}</span>
{link.current
? <UiIcon iconRole="check" size={16} strokeWidth={2} className={styles.chevron} aria-hidden="true" />
: <UiIcon iconRole="chevron-right" size={16} strokeWidth={1.75} className={styles.chevron} aria-hidden="true" />}
</a>
</li>
))}
</ul>
</nav>
{cta ? (
<a href={cta.href} className={styles.cta} onClick={() => { playUiSound("click"); close(); }}>
{cta.label}
</a>
) : null}
{settings?.length || account ? (
<div className={styles.card}>
{settings?.map(row => (
<div key={row.label} className={styles.settingRow}>
<span className={styles.settingLabel}>{row.label}</span>
<div className={styles.settingControl}>{row.control}</div>
</div>
))}
{account ? <div className={styles.account}>{account}</div> : null}
</div>
) : null}
</div>
</BottomSheet>
);
}
MobileNavSheet.displayName = "MobileNavSheet";
export default MobileNavSheet;
사용된 항목
- 서랍컴포넌트
화면 가장자리에서 밀려 나오는 패널이에요.