Lynx

Floating Action Button

A button that floats on the screen and executes primary actions.

Engine ≥ 3.9
Available since@seed-design/lynx-react@0.8.0, @seed-design/lynx-css@0.12.0
Loading Lynx example…

Installation

npx @seed-design/cli@latest add ui:floating-action-button

Props

Prop

Type

iconReact.ReactElement<LynxIconElementProps, string | React.JSXElementConstructor<any>>
labelstring
bindtap?EventHandler<BaseTouchEvent<Target>> | undefined
main-thread:bindtap?EventHandler<BaseTouchEvent<Element>> | undefined
style?CSSProperties | undefined
className?string | undefined

Usage

FloatingActionButton combines Root, Icon, Label from the Lynx package. label is required and is used by default as Root's accessibility-label. extended defaults to true.

import IconPlusLine from "@karrotmarket/lynx-monochrome-icon/IconPlusLine";

import { FloatingActionButton } from "@/components/ui/floating-action-button";

function handleTap() {
  "background only";
  // Handle new post creation action.
}

export function NewPostButton() {
  return (
    <FloatingActionButton
      icon={<IconPlusLine />}
      label="Write new post"
      bindtap={handleTap}
    />
  );
}

When extended={false}, the label is hidden on screen and displayed as a 56×56px icon button. Even then, label remains as the accessibility name of Root. If a different description is needed, specify accessibility-label directly.

Examples

Extended

You can switch label display and layout with the extended prop. The default is true.

Loading Lynx example…

Float Composition

Lynx does not have React's <Float> component. Specify position="relative" on the positioning Box, and apply position="absolute", right, bottom to the button wrapper to achieve the same layout.

Loading Lynx example…

Web Version Differences

  • Events: Use native bindtap instead of onClick. If a handler that changes React state is passed through a wrapper, put "background only" on the first line of the handler.
  • Accessibility: Use accessibility-label instead of aria-label. The Registry wrapper uses the required label as the default accessibility name, so it preserves the name even in collapsed state.
  • Rendering: Renders native <view> / <text> and Lynx icon tint instead of HTML <button> / SVG. asChild and DOM button props are not supported.
  • Floating layout: React's <Float> API is not provided. Specify right and bottom positions with your app's native absolute layout.

The 3.9 in compatibility.lynx.engine is the minimum Engine version that the package requires @lynx-js/types >=3.9.0 and the Scale Feedback path. Check the actual runtime version of the native host separately.

Table of contents