# AppBar URL: /lynx/components/app-bar Source: https://github.com/daangn/seed-design/blob/dev/docs/content/lynx/components/app-bar.mdx A navigation bar component that displays the current screen's title and navigation actions at the top of the screen. Lynx Engine 최소 버전: 3.6 사용 가능 버전: @seed-design/lynx-react@0.2.0, @seed-design/lynx-css@0.2.0 ## Preview ```tsx import "./styles"; import IconBellLine from "@karrotmarket/lynx-monochrome-icon/IconBellLine"; import { useSeedClassName } from "@seed-design/lynx-react"; import { AppBar, AppBarBackButton, AppBarIconButton, AppBarLeft, AppBarMain, AppBarRight, } from "@/components/ui/app-bar"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( } /> 화면 콘텐츠 ); } ``` ## Installation - npm: npx @seed-design/cli add ui:app-bar - pnpm: pnpm dlx @seed-design/cli add ui:app-bar - yarn: yarn dlx @seed-design/cli add ui:app-bar - bun: bun x @seed-design/cli add ui:app-bar ## Props ### `AppBar` ### `AppBarLeft` ### `AppBarMain` ### `AppBarRight` ### `AppBarSlot` ### `AppBarIconButton` ### `AppBarBackButton` ### `AppBarCloseButton` ## Usage The installed snippet exports the Root and main slots as `AppBar`, `AppBarLeft`, `AppBarMain`, `AppBarRight`. `AppBarBackButton` and `AppBarCloseButton` provide only default icons; actual navigation logic is passed directly via `bindtap`. ```tsx import { AppBar, AppBarBackButton, AppBarLeft, AppBarMain, AppBarRight, } from "@/components/ui/app-bar"; export function Header({ goBack }: { goBack: () => void }) { return ( ); } ``` ### Title / Subtitle Passing `title` and `subtitle` to `AppBarMain` internally assembles `AppBar.Title` and `AppBar.Subtitle`. If `subtitle` exists, `layout="withSubtitle"` is automatically applied. ```tsx import "./styles"; import { useSeedClassName } from "@seed-design/lynx-react"; import { AppBar, AppBarMain } from "@/components/ui/app-bar"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( 제목과 부제목을 함께 표시한 AppBar ); } ``` To directly assemble slots, pass compound components as children to `AppBarMain`. ```tsx import { AppBar, AppBarMain } from "@/components/ui/app-bar"; import { AppBar as SeedAppBar } from "@seed-design/lynx-react"; export function Header() { return ( Title Subtitle ); } ``` ### Left / Right Action Icon buttons or custom slots can be placed on the left and right. In Cupertino theme, slot widths are read to adjust padding so the center title is not offset. Both `AppBarLeft` and `AppBarRight` adjust left padding if the first child is an icon button, and right padding if the last child is an icon button. With only one button, both sides are adjusted. Negative margins equal to the space between 44px touch area and 24px icon are applied to maintain touch area while aligning screen edge and title spacing to React slot adjustment rules. Since slots pass edge position via Context, it applies automatically to `AppBarBackButton` / `AppBarCloseButton` and custom-made `AppBarIconButton`. Fragments and conditional children are supported; automatic adjustment is not passed inside `AppBarSlot` or native layout boxes. Specifying `edge="leading" | "trailing" | "both"` overrides the automatic adjustment direction. ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { useSeedClassName } from "@seed-design/lynx-react"; import { AppBar, AppBarBackButton, AppBarCloseButton, AppBarLeft, AppBarMain, AppBarRight, AppBarSlot, } from "@/components/ui/app-bar"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [lastAction, setLastAction] = useState("없음"); function handleBack() { "background only"; setLastAction("뒤로"); } function handleClose() { "background only"; setLastAction("닫기"); } return ( 완료 마지막 액션: {lastAction} ); } ``` To use an icon other than `AppBarBackButton` / `AppBarCloseButton`, pass a Lynx icon to the `icon` prop of `AppBarIconButton` to construct directly. When placed at the edge, it is automatically aligned the same as above. ```tsx import IconBellLine from "@karrotmarket/lynx-monochrome-icon/IconBellLine"; import { AppBar, AppBarBackButton, AppBarIconButton, AppBarLeft, AppBarMain, AppBarRight, } from "@/components/ui/app-bar"; export function Header({ goBack }: { goBack: () => void }) { return ( } /> ); } ``` ### Multiple / Conditional Actions When multiple buttons are in the slot, edge padding adjustment is applied only to the first and last buttons. The center button's touch area remains unchanged. With conditional rendering, if only one button remains, both sides auto-adjust padding. In the example below, the title remains centered even if search and close buttons are hidden or shown again. You can press each icon button to check the last action. ```tsx import "./styles"; import IconBellLine from "@karrotmarket/lynx-monochrome-icon/IconBellLine"; import IconMagnifyingglassLine from "@karrotmarket/lynx-monochrome-icon/IconMagnifyingglassLine"; import { useState } from "@lynx-js/react"; import { ActionButton, useSeedClassName } from "@seed-design/lynx-react"; import { AppBar, AppBarBackButton, AppBarCloseButton, AppBarIconButton, AppBarLeft, AppBarMain, AppBarRight, } from "@/components/ui/app-bar"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [showExtraActions, setShowExtraActions] = useState(true); const [lastAction, setLastAction] = useState("없음"); function toggleExtraActions() { "background only"; setShowExtraActions((value) => !value); } function recordAction(action: string) { "background only"; setLastAction(action); } return ( recordAction("뒤로")} /> } bindtap={() => recordAction("알림")} /> {showExtraActions && ( <> } bindtap={() => recordAction("검색")} /> recordAction("닫기")} /> )} {showExtraActions ? "검색·닫기 숨기기" : "검색·닫기 표시"} 마지막 액션: {lastAction} ); } ``` ### Custom Slot / Explicit Edge Custom layout boxes or buttons inside `AppBarSlot` do not have automatic edge padding applied. Only specify the direction with `edge` when managing internal layout directly. For typical `AppBarLeft` / `AppBarRight` buttons, no specification is needed. ```tsx ``` `leading` adjusts left padding, `trailing` adjusts right padding, and `both` adjusts both sides. Explicitly set values take priority over automatic adjustment, and the button's touch area size doesn't change. ### Tone The default `tone="layer"` shows the layer background. `tone="transparent"` makes the background transparent and applies bright colors to the title and icons, so use it over photos or dark backgrounds. Tone transitions based on background and scroll are managed at the call site. ```tsx import "./styles"; import { useState } from "@lynx-js/react"; import { useSeedClassName } from "@seed-design/lynx-react"; import { AppBar, AppBarBackButton, AppBarCloseButton, AppBarLeft, AppBarMain, AppBarRight, } from "@/components/ui/app-bar"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); const [lastAction, setLastAction] = useState("배경 위에 겹쳐지는 AppBar"); function handleBack() { "background only"; setLastAction("뒤로 버튼을 눌렀습니다"); } function handleClose() { "background only"; setLastAction("닫기 버튼을 눌렀습니다"); } return ( {lastAction} ); } ``` ### Accessibility In Lynx, use Lynx native accessibility attributes instead of HTML ARIA attributes. `AppBarIconButton` applies `accessibility-element={true}` and `accessibility-traits="button"` by default, and `accessibility-label` must be passed for buttons whose meaning cannot be understood from icons alone. ```tsx import IconBellLine from "@karrotmarket/lynx-monochrome-icon/IconBellLine"; } /> ``` `AppBarBackButton` and `AppBarCloseButton` provide `"Back"` and `"Close"` labels as defaults respectively. ### Theme `theme` can use `"cupertino"` or `"android"`. If not specified, AppBar reads `SystemInfo.platform` internally and uses `"android"` on Android, `"cupertino"` on other platforms or when no value is present. ```tsx ``` Manually specified `theme` takes priority over platform defaults. ```tsx import "./styles"; import { useSeedClassName } from "@seed-design/lynx-react"; import { AppBar, AppBarBackButton, AppBarCloseButton, AppBarLeft, AppBarMain, AppBarRight, } from "@/components/ui/app-bar"; export default function Example() { const seedClassName = useSeedClassName({ colorMode: "system" }); return ( Cupertino Android ); } ``` ## Web Version Differences Lynx `AppBar` provides the same roles and variant names as React `AppBar`, but platform-specific Recipe and screen transition responsibilities differ. - **Event Handling**: Pass Lynx event `bindtap` instead of `onClick`. - **Rendering Elements**: Render native `` / `` elements instead of HTML elements. - **Accessibility Labeling**: Use Lynx native `accessibility-label` instead of `aria-label`. - **Platform Theme**: Does not depend on `data-*` selectors like the web, but applies `"cupertino"` / `"android"` design using recipe variant classNames. - **Navigation Responsibility**: `AppBarBackButton` and `AppBarCloseButton` do not automatically execute navigation. Operations like Stackflow `pop()` are connected at the call site. - **Edge Icon Alignment**: The web uses `iconButton:first-child` / `:last-child` selector to adjust bleed, but Lynx doesn't support these pseudo-classes, so `AppBarLeft` / `AppBarRight` passes edge position via Context and adjusts via Recipe class of icon button. This applies precisely only to edge icon buttons even in multi-button and custom slot cases. ## Unsupported Lynx Features Currently, Lynx AppBar is provided as a pure UI component and does not include the following features. | Feature | Web Equivalent | Alternative Method | | ------------------------------------- | ----------------------------------------------------- | -------------------------------------------------------- | | Stackflow activity integration | `useActivity`, `useActions` based back/close handling | Directly call app's navigation function in `bindtap` | | Swipe-back transition animation | Stackflow screen transition | Handle in navigation layer that owns screen transition | | `data-*` selector based state styling | Web recipe selector | Use `theme`, `tone` variant className | | HTML button attributes | `type`, DOM click event | Use Lynx `` based `AppBarIconButton` and `bindtap` | | HTML ARIA labels | `aria-label` | Use Lynx native `accessibility-label` |