# Tabs URL: /react/components/tabs Source: https://github.com/daangn/seed-design/blob/dev/docs/content/react/components/tabs.mdx 한 화면 내에서 콘텐츠를 탭 단위로 구분하여 전환할 수 있는 컴포넌트입니다. 사용 가능 버전: @seed-design/react@0.0.1, @seed-design/css@0.0.1 ## Preview ```tsx import { TabsContent, TabsList, TabsRoot, TabsTrigger } from "seed-design/ui/tabs"; export default function TabsPreview() { return (
라벨1 라벨2 라벨3 Content 1 Content 2 Content 3
); } const Content = (props: React.PropsWithChildren) => { return (
{props.children}
); }; ``` ## Installation - npm: npx @seed-design/cli@latest add ui:tabs - pnpm: pnpm dlx @seed-design/cli@latest add ui:tabs - yarn: yarn dlx @seed-design/cli@latest add ui:tabs - bun: bun x @seed-design/cli@latest add ui:tabs ## Props ### `TabsRoot` ### `TabsList` ### `TabsTrigger` ### `TabsCarousel` ### `TabsContent` ## Examples ### Layout Fill (Default) ```tsx import { TabsContent, TabsList, TabsRoot, TabsTrigger } from "seed-design/ui/tabs"; export default function TabsLayoutFill() { return (
라벨1 라벨2 라벨3 Content 1 Content 2 Content 3
); } const Content = (props: React.PropsWithChildren) => { return (
{props.children}
); }; ``` ### Layout Hug ```tsx import { TabsContent, TabsList, TabsRoot, TabsTrigger } from "seed-design/ui/tabs"; export default function TabsLayoutHug() { return (
라벨1 라벨2 라벨3 Content 1 Content 2 Content 3
); } const Content = (props: React.PropsWithChildren) => { return (
{props.children}
); }; ``` ### Size Medium ```tsx import { TabsContent, TabsList, TabsRoot, TabsTrigger } from "seed-design/ui/tabs"; export default function TabsSizeMedium() { return (
라벨1 라벨2 라벨3 Content 1 Content 2 Content 3
); } const Content = (props: React.PropsWithChildren) => { return (
{props.children}
); }; ``` ### Size Small (Default) ```tsx import { TabsContent, TabsList, TabsRoot, TabsTrigger } from "seed-design/ui/tabs"; export default function TabsSizeSmall() { return (
라벨1 라벨2 라벨3 Content 1 Content 2 Content 3
); } const Content = (props: React.PropsWithChildren) => { return (
{props.children}
); }; ``` ### Transition `TabsCarousel` 컴포넌트로 `TabsContent` 컴포넌트들을 감싸면 탭 변경시 컨텐츠가 자연스럽게 전환됩니다. ```tsx import { TabsRoot, TabsList, TabsTrigger, TabsCarousel, TabsContent } from "seed-design/ui/tabs"; export default function TabsTransition() { return (
라벨1 라벨2 라벨3 Content 1 Content 2 Content 3
); } const Content = (props: React.PropsWithChildren) => { return (
{props.children}
); }; ``` ### Swipeable `TabsCarousel` 컴포넌트에 `swipeable` 속성을 추가하면 스와이프 제스처로 탭을 이동할 수 있습니다. ```tsx import { TabsRoot, TabsList, TabsTrigger, TabsCarousel, TabsContent } from "seed-design/ui/tabs"; export default function TabsSwipeable() { return (
라벨1 라벨2 라벨3 Content 1 Content 2 Content 3
); } const Content = (props: React.PropsWithChildren) => { return (
{props.children}
); }; ``` ### Carousel Prevent Drag `Tabs.carouselPreventDrag`를 사용하면 특정 요소가 드래그 제스처에 반응하지 않도록 설정할 수 있습니다. ```tsx import { Box, Tabs } from "@seed-design/react"; import { TabsCarousel, TabsContent, TabsList, TabsRoot, TabsTrigger } from "seed-design/ui/tabs"; export default function TabsCarouselPreventDrag() { return ( Tab 1 Tab 2 Scrollable area Lorem ipsum dolor sit, amet consectetur adipisicing elit. Reiciendis ab ex accusantium sit. Amet maxime eum molestiae nemo. Beatae sint omnis aut cumque doloremque fugit perspiciatis rerum possimus, reiciendis eaque? Lorem ipsum dolor sit amet consectetur adipisicing elit. ); } ``` ### Disabled ```tsx import { TabsContent, TabsList, TabsRoot, TabsTrigger } from "seed-design/ui/tabs"; export default function TabsDisabled() { return (
라벨1 라벨2 라벨3 Content 1 Content 2 Content 3
); } const Content = (props: React.PropsWithChildren) => { return (
{props.children}
); }; ``` ### Notification ```tsx import { TabsContent, TabsList, TabsRoot, TabsTrigger } from "seed-design/ui/tabs"; export default function TabsNotification() { return (
라벨1 라벨2 라벨3 Content 1 Content 2 Content 3
); } const Content = (props: React.PropsWithChildren) => { return (
{props.children}
); }; ``` ### Sticky List 탭이 전체화면을 차지하고, Tabs.List가 top에 고정되어 있는 경우 사용하는 예시입니다. ```tsx import { TabsContent, TabsList, TabsRoot, TabsTrigger } from "seed-design/ui/tabs"; export default function TabsStickyList() { return ( // 600은 화면 높이라고 가정합니다. 실제 앱에서는 화면(body)이 스크롤 컨테이너 역할을 하므로 // 예제에서는 overflowY로 이를 흉내냅니다. TabsList는 이 컨테이너의 top에 고정됩니다.
라벨1 라벨2 라벨3 Content 1 Content 2 Content 3
); } const Content = (props: React.PropsWithChildren<{ height: string }>) => { const { height, children } = props; return (
{children}
); }; ``` ### Standalone TabContent를 사용하지 않고, 컨텐츠 영역을 온전히 소유하고 싶을 때 사용하는 예시입니다. 탭에서 제공하는 Swipe 기능을 사용할 수 없습니다. ```tsx import { useState } from "react"; import { TabsList, TabsRoot, TabsTrigger } from "seed-design/ui/tabs"; export default function TabsStandalone() { const [activeTab, setActiveTab] = useState("1"); return (
라벨1 라벨2 라벨3 {activeTab === "1" && (
Content 1
)} {activeTab === "2" && (
Content 2
)} {activeTab === "3" && (
Content 3
)}
); } const Content = (props: React.PropsWithChildren) => { return (
{props.children}
); }; ``` ### Dynamic Height 각 탭의 높이가 다를 때, 아래의 컨텐츠를 탭 아래에 바로 맞추기 위해서 사용하는 예시입니다. 탭이 자주 바뀌고, 탭에 네트워크 요청이 많은 경우 캐싱을 잘 고려해주세요. ```tsx import { TabsCarousel, TabsContent, TabsList, TabsRoot, TabsTrigger } from "seed-design/ui/tabs"; export default function TabsDynamicHeight() { return (
라벨1 라벨2 라벨3 Content 1 Content 2 Content 3
아래 컨텐츠
); } const Content = (props: React.PropsWithChildren<{ height: string }>) => { const { height, children } = props; return (
{children}
); }; ``` ### Scroll to Top ```tsx import { RefObject, useRef, useState } from "react"; import { TabsCarousel, TabsContent, TabsList, TabsRoot, TabsTrigger } from "seed-design/ui/tabs"; export default function TabsScrollTop() { const [currentTab, setCurrentTab] = useState("1"); const contentRefs: Record> = { "1": useRef(null), "2": useRef(null), }; const handleTriggerClick = (value: string) => { if (value === currentTab) { contentRefs[value].current?.scrollTo({ top: 0, behavior: "smooth" }); } }; return (
handleTriggerClick("1")} value="1"> 라벨1 handleTriggerClick("2")} value="2"> 라벨2 Content 1 Content 2
); } const Content = (props: React.PropsWithChildren<{ height: string }>) => { const { height, children } = props; return (
{children}
); }; ```