# Chip Tabs URL: /lynx/components/chip-tabs Source: https://github.com/daangn/seed-design/blob/dev/docs/content/lynx/components/chip-tabs.mdx A tab component displayed in chip form. It is used to switch content by selecting categories or filters. Lynx Engine 최소 버전: 3.9 사용 XElement: , 사용 가능 버전: @seed-design/lynx-react@0.8.0, @seed-design/lynx-css@0.12.0 ## Preview ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { useSeedClassName } from "@seed-design/lynx-react"; import { ChipTabsList, ChipTabsRoot, ChipTabsTrigger } from "@/components/ui/chip-tabs"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [value, setValue] = useState("1"); function handleValueChange(nextValue: string) { "background only"; setValue(nextValue); } return ( 라벨1 라벨2 라벨3 {value === "1" && content 1} {value === "2" && content 2} {value === "3" && content 3} ); } ``` ## Installation - npm: npx @seed-design/cli add ui:chip-tabs - pnpm: pnpm dlx @seed-design/cli add ui:chip-tabs - yarn: yarn dlx @seed-design/cli add ui:chip-tabs - bun: bun x @seed-design/cli add ui:chip-tabs ## Props ### `ChipTabsRoot` ### `ChipTabsList` ### `ChipTabsTrigger` ### `ChipTabsCarousel` ### `ChipTabsContent` ## Usage ```tsx import { useState } from "@lynx-js/react"; import { ChipTabsList, ChipTabsRoot, ChipTabsTrigger, } from "@/components/ui/chip-tabs"; export function App() { const [value, setValue] = useState("1"); function handleValueChange(nextValue: string) { "background only"; setValue(nextValue); } return ( <> Label 1 Label 2 Label 3 {value === "1" && content 1} {value === "2" && content 2} {value === "3" && content 3} ); } ``` `ChipTabsRoot` can be controlled with `value` and `onValueChange` or set the initial selected value with `defaultValue`. The `notification` boolean of `ChipTabsTrigger` displays a small `NotificationBadge` at 6px spacing next to the label. `ChipTabsCarousel` assembles `ChipTabsCarouselCamera` in the Registry, so only `ChipTabsContent` is passed as children. Since Carousel is a native ``, you must specify a height matching your app layout on the Carousel or Camera, and enable left/right swipe with `swipeable`. The range where the iOS back gesture from the left edge of the screen takes priority is set with `iosBackGestureEdgeWidth`. When you need to use the Camera's native `bindchange`, `bindwillchange`, and `bindoffsetchange` directly in the public package API, you can compose `ChipTabs.CarouselCamera`. `onSwipeStart`, `onSwipeEnd`, and `onSettle` can be passed to Carousel to handle swipe start, end, and settle. ```tsx import { useState } from "@lynx-js/react"; import { ChipTabs } from "@seed-design/lynx-react"; export function App() { const [lastEvent, setLastEvent] = useState("Waiting"); function handleSwipeStart() { "background only"; setLastEvent("Swipe Started"); } function handleSwipeEnd() { "background only"; setLastEvent("Swipe Ended"); } function handleSettle() { "background only"; setLastEvent("Settled"); } return ( Label 1 Label 2 content 1 content 2 {lastEvent} ); } ``` ## Scroll Alignment The `scrollAlign` of `ChipTabsList` is how to align the selected chip to the horizontal list. You can use `"nearest"`, `"start"`, `"center"`, and `"end"`, with the default being `"nearest"`. - `"start"`, `"center"`, and `"end"` align the selected chip to the start, center, and end of the list, respectively. - `"nearest"` behaves like React Web's minimal scroll action: if the selected chip is completely visible, it maintains the current position. When the left side is cut off, it moves to the start boundary; when the right side is cut off, it moves to the end boundary only as much as needed, so it does not always align to the end like `"end"`. It calculates based on the actual chip width, position, and viewport, and preserves variable width chips as is. To center-align the first and last items of the list, it does not add empty space and only scrolls within the scrollable range without changing the item order. In the example below, selecting a mode resets the selection to `Label 1`. Then tap `Label 6` or `Select 6` to verify the actual scrollAlign difference with controlled `value` change. If you choose `nearest`, omit the `scrollAlign` prop to also verify the default behavior. ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { ActionButton, Box, HStack, Text, useSeedClassName, VStack } from "@seed-design/lynx-react"; import { ChipTabsList, ChipTabsRoot, ChipTabsTrigger, type ChipTabsListProps, } from "@/components/ui/chip-tabs"; type ScrollAlign = NonNullable; const ALIGNMENTS: ScrollAlign[] = ["nearest", "start", "center", "end"]; const LABELS = Array.from({ length: 15 }, (_, index) => String(index + 1)); export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [value, setValue] = useState("1"); const [scrollAlign, setScrollAlign] = useState("nearest"); function handleValueChange(nextValue: string) { "background only"; setValue(nextValue); } function selectScrollAlign(nextScrollAlign: ScrollAlign) { "background only"; setScrollAlign(nextScrollAlign); setValue("1"); } function selectSixthChip() { "background only"; setValue("6"); } return ( {ALIGNMENTS.map((nextScrollAlign) => ( { "background only"; selectScrollAlign(nextScrollAlign); }} > {nextScrollAlign} ))} 6번 선택 {`선택: 라벨${value}`} {LABELS.map((label) => ( {`라벨${label}`} ))} ); } ``` When you reselect a chip that is already completely visible with `nearest`, it does not scroll. Even after manually scrolling the list, it only scrolls when the next selection requires it. ## Examples ### Size=Medium The minimum height for `medium` is 36px. ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { useSeedClassName } from "@seed-design/lynx-react"; import { ChipTabsList, ChipTabsRoot, ChipTabsTrigger } from "@/components/ui/chip-tabs"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [value, setValue] = useState("1"); function handleValueChange(nextValue: string) { "background only"; setValue(nextValue); } return ( 라벨1 라벨2 라벨3 {value === "1" && content 1} {value === "2" && content 2} {value === "3" && content 3} ); } ``` ### Size=Large The minimum height for `large` is 40px. ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { useSeedClassName } from "@seed-design/lynx-react"; import { ChipTabsList, ChipTabsRoot, ChipTabsTrigger } from "@/components/ui/chip-tabs"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [value, setValue] = useState("1"); function handleValueChange(nextValue: string) { "background only"; setValue(nextValue); } return ( 라벨1 라벨2 라벨3 {value === "1" && content 1} {value === "2" && content 2} {value === "3" && content 3} ); } ``` ### Variant=Neutral Solid ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { useSeedClassName } from "@seed-design/lynx-react"; import { ChipTabsList, ChipTabsRoot, ChipTabsTrigger } from "@/components/ui/chip-tabs"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [value, setValue] = useState("1"); function handleValueChange(nextValue: string) { "background only"; setValue(nextValue); } return ( 라벨1 라벨2 라벨3 {value === "1" && content 1} {value === "2" && content 2} {value === "3" && content 3} ); } ``` ### Variant=Neutral Outline ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { useSeedClassName } from "@seed-design/lynx-react"; import { ChipTabsList, ChipTabsRoot, ChipTabsTrigger } from "@/components/ui/chip-tabs"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [value, setValue] = useState("1"); function handleValueChange(nextValue: string) { "background only"; setValue(nextValue); } return ( 라벨1 라벨2 라벨3 {value === "1" && content 1} {value === "2" && content 2} {value === "3" && content 3} ); } ``` ### Notification ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { useSeedClassName } from "@seed-design/lynx-react"; import { ChipTabsList, ChipTabsRoot, ChipTabsTrigger } from "@/components/ui/chip-tabs"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [value, setValue] = useState("1"); function handleValueChange(nextValue: string) { "background only"; setValue(nextValue); } return ( 라벨1 라벨2 라벨3 {value === "1" && content 1} {value === "2" && content 2} {value === "3" && content 3} ); } ``` ### With Scroll Fog `ScrollFog` is a package-only public component provided directly from the `@seed-design/lynx-react` package without a Registry snippet or Recipe. When you wrap `ChipTabsList` with `ScrollFog` where `placement={["left", "right"]}`, a default 20px fog is displayed at both edges. The internal left/right padding of 16px for the List is maintained as is. ```tsx import "./styles"; import { ScrollFog, useSeedClassName } from "@seed-design/lynx-react"; import { ChipTabsList, ChipTabsRoot, ChipTabsTrigger } from "@/components/ui/chip-tabs"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 라벨1 라벨2 라벨3 라벨4 라벨5 라벨6 라벨7 라벨8 라벨9 라벨10 라벨11 라벨12 라벨13 라벨14 라벨15 ); } ``` ## Web Version Differences | Item | React Web | Lynx | | ------------------- | --------------------------------------------- | ---------------------------------------------------------------- | | Rendering Elements | HTML `div`, `button` | Native `view`, `text`, `scroll-view`, `viewpager` | | Tab Selection Event | `onClick`-based | `bindtap`-based, public state event is `onValueChange` | | Content | Conditional `div` outside Root also available | Can render conditional native `text` based on value outside Root | | Horizontal List | CSS overflow | Native horizontal `scroll-view` | | Carousel | Web Carousel | Native `` | Like the React example, you can render conditional native `text` content based on the selected value outside the Root in Lynx. No separate AppBar, screen shell, CTA, or asset is provided. ## Unsupported Lynx Features - Keyboard focus and roving focus - RTL order and swipe direction reversal - `lazyMount`, `unmountOnExit`: native viewpager maintains all page slots. - Carousel's `loop`, `autoHeight`, `dragThreshold`, `carouselPreventDrag` - Content transition animations