Floating Action Button 화면 위에 떠 있으며 주요 액션을 실행하는 버튼입니다.
import IconPlusLine from "@karrotmarket/lynx-monochrome-icon/IconPlusLine" ;
import { FloatingActionButton } from "@/components/ui/floating-action-button" ;
export default function Example () {
return < FloatingActionButton icon = {< IconPlusLine />} label = "Example FAB" />;
}
npx @seed-design/cli@latest add ui:floating-action-button pnpm dlx @seed-design/cli@latest add ui:floating-action-button yarn dlx @seed-design/cli@latest add ui:floating-action-button bun x @seed-design/cli@latest add ui:floating-action-button
의존성 설치
npm install @seed-design/lynx-react yarn add @seed-design/lynx-react pnpm add @seed-design/lynx-react bun add @seed-design/lynx-react 아래 코드를 복사 후 붙여넣고 사용하세요 /**
* @file ui:floating-action-button
* @requires @seed-design/lynx-react@^1.0.0
* @requires @seed-design/lynx-css@^1.0.0
**/
import * as React from "@lynx-js/react" ;
import { FloatingActionButton as SeedFloatingActionButton } from "@seed-design/lynx-react" ;
export interface FloatingActionButtonProps
extends Omit < SeedFloatingActionButton . RootProps , "children" > {
icon : SeedFloatingActionButton . IconProps [ "icon" ];
label : string ;
}
/**
* @see https://seed-design.io/lynx/components/floating-action-button
*/
export const FloatingActionButton = React. forwardRef < unknown , FloatingActionButtonProps >(
({ icon , label , "accessibility-label" : accessibilityLabel , ... otherProps }, ref ) => {
return (
< SeedFloatingActionButton.Root
ref = {ref}
accessibility-label = {accessibilityLabel ?? label}
{ ... otherProps}
>
< SeedFloatingActionButton.Icon icon = {icon} />
< SeedFloatingActionButton.Label >{label}</ SeedFloatingActionButton.Label >
</ SeedFloatingActionButton.Root >
);
},
);
FloatingActionButton.displayName = "FloatingActionButton" ;
/**
* This file is a snippet from SEED Design, helping you get started quickly with @seed-design/* packages.
* You can extend this snippet however you want.
*/
iconReact.ReactElement < LynxIconElementProps, string | React.JSXElementConstructor < any >>
labelstring
label은 필수이며 기본 접근성 이름으로도 사용됩니다. extended의 기본값은 true입니다.
import IconPlusLine from "@karrotmarket/lynx-monochrome-icon/IconPlusLine" ;
import { FloatingActionButton } from "@/components/ui/floating-action-button" ;
function handleTap () {
"background only" ;
// 새 글 작성 동작을 처리합니다.
}
export function NewPostButton () {
return (
< FloatingActionButton
icon = {< IconPlusLine />}
label = "새 글 작성"
bindtap = {handleTap}
/>
);
}
extended={false}이면 label은 화면에서 숨겨지고 56×56px 아이콘 버튼으로 표시됩니다. 이때도 label은 Root의 접근성 이름으로 남습니다. 다른 설명이 필요하면 accessibility-label을 직접 지정하세요.
extended prop으로 label 표시와 레이아웃을 전환할 수 있습니다. 기본값은 true입니다.
import IconPlusLine from "@karrotmarket/lynx-monochrome-icon/IconPlusLine" ;
import { useState } from "@lynx-js/react" ;
import { VStack } from "@seed-design/lynx-react" ;
import { FloatingActionButton } from "@/components/ui/floating-action-button" ;
import { Switch } from "@/components/ui/switch" ;
export default function Example () {
const [ extended , setExtended ] = useState ( true );
function handleCheckedChange ( checked : boolean ) {
"background only" ;
setExtended (checked);
}
return (
< VStack align = "center" gap = "x6" >
< FloatingActionButton icon = {< IconPlusLine />} label = "Extended" extended = {extended} />
< Switch
size = "16"
tone = "neutral"
label = "Extended"
checked = {extended}
onCheckedChange = {handleCheckedChange}
/>
</ VStack >
);
}
Lynx에는 React의 <Float> 컴포넌트가 없습니다. 위치 기준 Box에 position="relative"를 지정하고, 버튼 wrapper에 position="absolute", right, bottom을 적용해 같은 배치를 구성하세요.
import IconBellFill from "@karrotmarket/lynx-monochrome-icon/IconBellFill" ;
import { Box } from "@seed-design/lynx-react" ;
import { FloatingActionButton } from "@/components/ui/floating-action-button" ;
export default function Example () {
return (
< Box
position = "relative"
display = "flex"
flexDirection = "column"
width = "full"
flexGrow
minHeight = "0"
borderWidth = { 1 }
borderColor = "stroke.neutralMuted"
>
< Box position = "absolute" right = "16px" bottom = "16px" >
< FloatingActionButton icon = {< IconBellFill />} label = "알림 설정" />
</ Box >
</ Box >
);
}
onClick 대신 bindtap을 사용합니다. React state를 바꾸는 handler의 첫 줄에는 "background only"를 두세요.
aria-label 대신 accessibility-label을 사용합니다. Registry는 필수 label을 기본 접근성 이름으로 사용합니다.
HTML button prop과 asChild는 지원하지 않습니다.
React의 Float은 제공하지 않습니다. native absolute layout으로 위치를 지정하세요.