Floating Action Button
A button that floats on the screen and executes the primary action.
@seed-design/react@0.0.30, @seed-design/css@0.0.30
import { FloatingActionButton } from "seed-design/ui/floating-action-button";
import IconPlusLine from "@karrotmarket/react-monochrome-icon/IconPlusLine";
export default function FloatingActionButtonPreview() {
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
Install dependencies
npm install @seed-design/react
yarn add @seed-design/react
pnpm add @seed-design/react
bun add @seed-design/react
Copy the code below and paste it in
/**
* @file ui:floating-action-button
* @requires @seed-design/react@^2.0.0
* @requires @seed-design/css@^2.0.0
**/
"use client";
import { FloatingActionButton as SeedFloatingActionButton } from "@seed-design/react";
import * as React from "react";
export interface FloatingActionButtonProps
extends Omit<SeedFloatingActionButton.RootProps, "children"> {
icon: React.ReactNode;
label: React.ReactNode;
}
/**
* @see https://crispy.carrot-soft.tech/react/components/floating-action-button
*/
export const FloatingActionButton = React.forwardRef<
React.ElementRef<typeof SeedFloatingActionButton.Root>,
FloatingActionButtonProps
>(({ icon, label, ...otherProps }, ref) => {
return (
<SeedFloatingActionButton.Root ref={ref} {...otherProps}>
<SeedFloatingActionButton.Icon svg={icon} />
<SeedFloatingActionButton.Label>{label}</SeedFloatingActionButton.Label>
</SeedFloatingActionButton.Root>
);
});
FloatingActionButton.displayName = "FloatingActionButton";
/**
* This file is a snippet from Crispy, helping you get started quickly with @seed-design/* packages.
* You can extend this snippet however you want.
*/
iconReact.ReactNode
labelReact.ReactNode
You can control label display and layout using the extended prop.
Regardless of whether extended is used, label is a required prop for accessibility.
import { FloatingActionButton } from "seed-design/ui/floating-action-button";
import { Switch } from "seed-design/ui/switch";
import IconPlusLine from "@karrotmarket/react-monochrome-icon/IconPlusLine";
import { Flex, VStack } from "@seed-design/react";
import { useState } from "react";
export default function FloatingActionButtonExtended() {
const [extended, setExtended] = useState(true);
return (
<VStack align="center" justify="space-between">
<Flex height="100px" align="center" justify="center">
<FloatingActionButton icon={<IconPlusLine />} label="Extended" extended={extended} />
</Flex>
<Switch
size="16"
tone="neutral"
label="Extended"
checked={extended}
onCheckedChange={setExtended}
/>
</VStack>
);
}
Floating Action Button is convenient to use with the <Float> component.
import { FloatingActionButton } from "seed-design/ui/floating-action-button";
import { IconBellFill } from "@karrotmarket/react-monochrome-icon";
import { Box, Float } from "@seed-design/react";
export default function FloatingActionButtonFloatComposition() {
return (
<Box
position="relative"
width="300px"
height="500px"
borderWidth={1}
borderColor="stroke.neutralMuted"
>
<Float placement="bottom-end" offsetX="x4" offsetY="x4">
<FloatingActionButton icon={<IconBellFill />} label="알림 설정" />
</Float>
</Box>
);
}