# Tabs
URL: /react/components/tabs
Source: https://github.com/daangn/seed-design/blob/dev/docs/content/react/components/tabs.mdx
A component that allows switching content by tabs within a single screen.
사용 가능 버전: @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 (
Label 1
Label 2
Label 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
When you wrap `TabsContent` components with the `TabsCarousel` component, the content smoothly transitions when tabs change.
```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
Adding the `swipeable` attribute to the `TabsCarousel` component allows moving between tabs with swipe gestures.
```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
Using `Tabs.carouselPreventDrag`, you can set specific elements to not respond to drag gestures.
```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
This is an example used when tabs occupy the full screen and Tabs.List is fixed at the 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
This is an example used when you want to fully own the content area without using TabContent.
The Swipe feature provided by tabs cannot be used.
```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
This is an example used to fit the content below directly under the tabs when each tab has a different height.
If tabs change frequently and tabs have many network requests, please consider caching carefully.
```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}
);
};
```