Fab

The Floating Action Button (FAB) is a dynamic button that stays visible and provides access to a primary action throughout the user's journey in the application. It is a powerful UI element that adds a touch of elegance and convenience to the user experience.
Unstyled
Spec Doc
This is an illustration of a Themed Fab component with default configuration.
size
placement
isHovered
isDisabled
isPressed
<Box
h={360}
w={320}
bg="$backgroundLight50"
$dark-bg="$backgroundDark900"
borderRadius="$md"
>
<Fab
size="md"
placement="bottom right"
isHovered={false}
isDisabled={false}
isPressed={false}
>
<FabIcon as={AddIcon} mr="$1" />
<FabLabel>Quick start</FabLabel>
</Fab>
</Box>

Import

To use this component in your project, include the following import statement in your file.
import { Fab } from "@gluestack-ui/themed"

Anatomy

The structure provided below can help you identify and understand a Fab component's various parts.
export default () => (
<Fab>
<FabLabel />
<FabIcon />
</Fab>
)

API Reference

The following section contains a comprehensive list of the component's references, including descriptions, properties, types, and default behavior. This information is readily available for you to access, helping you effectively utilize the component library in your projects.

Fab

Contains all fab related layout style props and actions. It inherits all the properties of React Native's Pressable component.
Prop
Type
Default
Description
placement
"top left" | "top right" | "bottom left" | "bottom right" | "top center" | "bottom center"
"bottom right"
Placement of the Fab
isHovered
bool
false
To manually set hover to the fab.
isPressed
bool
false
To manually set pressable state to the fab.
isFocused
bool
false
To manually set focused state to the fab.
isDisabled
bool
false
To manually set disable to the fab.

FabLabel

Contains all text related layout style props and actions. It inherits all the properties of React Native's Text component.

FabIcon

Contains all Icon related layout style props and actions. It inherits all the properties of Gluestack Style's AsForwarder component.

Features

  • Keyboard support for actions.
  • Support for hover, focus and active states.
  • Option to add your styles or use the default styles.

Accessibility

We have outlined the various features that ensure the Fab component is accessible to all users, including those with disabilities. These features help ensure that your application is inclusive and meets accessibility standards.Adheres to the WAI-ARIA design pattern

Keyboard

  • Tab: Moves focus to the next focusable element.
  • Shift + Tab: Moves focus to the previous focusable element.
  • Enter: Triggers the fab's action.

Screen Reader

  • VoiceOver: When the fab is focused, the screen reader will announce the fab's label and its current state.

Focus Management

  • The onFocus and onBlur props manage focus states and provide visual cues to users. This is especially important for users who rely on keyboard navigation.

Dependencies

The following are the lists of all the libraries and packages the component relies on. This information will help you ensure that your project has all the necessary dependencies installed to use the component.
  • @gluestack-ui/utils
  • @react-native-aria/focus
  • @react-native-aria/interactions

Props

Fab component is created using Pressable component from react-native. It extends all the props supported by React Native Pressable, utility props and the props mentioned below.

Fab

Name
Value
Default
size
sm | md | lg
md
placement
top right | top left | bottom right | bottom left | top center | bottom center
bottom right
Note: These props are exclusively applicable when utilizing the default configuration of gluestack-ui/config. If you are using a custom theme, these props may not be available.

Examples

The Examples section provides visual representations of the different variants of the component, allowing you to quickly and easily determine which one best fits your needs. Simply copy the code and integrate it into your project.

FAB with Icon

A Fab component with an icon adds a visually striking and easily recognizable button that triggers a specific action or function within a user interface.
function App() {
const data = [
{
uri: "https://images.unsplash.com/photo-1599566150163-29194dcaad36?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=774&q=80",
name: "Kevin James",
msg: "Hi Rachel, What's up",
},
{
uri: "https://images.unsplash.com/photo-1527980965255-d3b416303d12?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1180&q=80",
name: "Jacob Jones",
msg: "Good Morning!",
},
{
uri: "https://images.unsplash.com/photo-1633332755192-727a05c4013d?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1180&q=80",
name: "Albert Flores",
msg: "Coffee?",
},
]
return (
<Box
borderColor="$borderLight200"
borderRadius="$lg"
borderWidth="$1"
p="$6"
$dark-bg="$backgroundDark900"
$dark-borderColor="$borderDark800"
$base-minWidth={240}
$sm-minWidth={360}
$md-minWidth={476}
>
<VStack space="md">
{data.map((chatData) => {
return (
<HStack space="sm" alignItems="center">
<Avatar size="sm">
<AvatarImage
source={{
uri: chatData.uri,
}}
/>
</Avatar>
<VStack>
<Heading size="xs">{chatData.name}</Heading>
<Text size="xs">{chatData.msg}</Text>
</VStack>
</HStack>
)
})}
</VStack>
<Fab bg="$emerald600" size="lg">
{/* EditIcon is imported from 'lucide-react-native' */}
<FabIcon as={EditIcon} />
</Fab>
</Box>
)
}

FAB with Icon and Text

A Fab component with an icon and text combines a visual icon with accompanying text to create a prominent and descriptive button that triggers a specific action or function within a user interface.
<Box
maxWidth="$96"
borderColor="$borderLight200"
rounded="$lg"
borderWidth="$1"
py={56}
px="$6"
$base-mx="$5"
$dark-bg="$backgroundDark900"
$dark-borderColor="$borderDark800"
>
<Fab bg="$indigo600" height="$9" top="$4">
<FabIcon as={SearchIcon} mr="$1.5" />
<FabLabel>Search</FabLabel>
</Fab>
<VStack space="lg">
<Box>
<Text
fontSize="$xs"
color="$darkBlue600"
fontWeight="$bold"
$dark-color="$darkBlue400"
>
HEALTH
</Text>
<Heading size="sm">Benefits of Oranges</Heading>
<Text size="xs" mt="$1.5">
Oranges are a great source of vitamin C, which is essential for a
healthy immune system.
</Text>
<HStack space="sm" mt="$3" h="$5">
<Text size="xs">Wade Warrem</Text>
<Divider
orientation="vertical"
bg="$backgroundLight300"
$dark-bg="$backgroundLight700"
/>
<Text size="xs">6th Oct, 2019</Text>
<Divider
orientation="vertical"
bg="$backgroundLight300"
$dark-bg="$backgroundLight700"
/>
<Text size="xs">5 mins read</Text>
</HStack>
</Box>
<Divider />
<Box>
<Text
fontSize="$xs"
color="$darkBlue600"
fontWeight="$bold"
$dark-color="$darkBlue400"
>
TECHNOLOGY
</Text>
<Heading size="sm">How AI can benefit your business</Heading>
<Text size="xs" mt="$1.5">
AI can automate tasks and processes, allowing for increasing efficiency
and productivity.
</Text>
<HStack space="sm" mt="$3" h="$5">
<Text size="xs">Wade Warrem</Text>
<Divider
orientation="vertical"
bg="$backgroundLight300"
$dark-bg="$backgroundLight700"
/>
<Text size="xs">6th Oct, 2019</Text>
<Divider
orientation="vertical"
bg="$backgroundLight300"
$dark-bg="$backgroundLight700"
/>
<Text size="xs">5 mins read</Text>
</HStack>
</Box>
</VStack>
</Box>

Placement

A Fab component with placement options allows for flexible positioning of the button within a user interface, enabling convenient and intuitive access to key actions or functionalities in various locations.
<Box
borderColor="$borderLight300"
rounded="$lg"
borderWidth="$1"
py="$4"
bg="$white"
$base-mx="$5"
$dark-bg="$backgroundDark900"
$dark-borderColor="$borderDark800"
>
<VStack mb="$2" px="$6" py="$2" space="lg">
<Checkbox size="sm">
<CheckboxIndicator mr="$2">
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel>
<Text fontSize="$sm">Prepare any feedback or updates.</Text>
</CheckboxLabel>
</Checkbox>
<Checkbox size="sm">
<CheckboxIndicator mr="$2">
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel>
<Text fontSize="$sm">Review progress on goals and projects.</Text>
</CheckboxLabel>
</Checkbox>
<Checkbox size="sm">
<CheckboxIndicator mr="$2">
<CheckboxIcon as={CheckIcon} />
</CheckboxIndicator>
<CheckboxLabel>
<Text fontSize="$sm">Ask challenges and discuss.</Text>
</CheckboxLabel>
</Checkbox>
</VStack>
<Fab size="sm" placement="bottom center" top="0" position="relative">
<FabIcon as={AddIcon} size="sm" />
</Fab>
</Box>

Custom Placement

A Fab component with custom placement allows for flexible positioning of the button according to specific design requirements or user interface preferences, providing tailored and intuitive access to key actions or functionalities.
<Box
maxWidth="$96"
borderColor="$borderLight200"
borderRadius="$lg"
borderWidth="$1"
overflow="hidden"
$base-mx="$5"
$dark-bg="$backgroundDark900"
$dark-borderColor="$borderDark800"
>
<Box>
<Image
h={185}
w={416}
source={{
uri: "https://drive.google.com/uc?export=view&id=1h1e89BtQCp6JdGiKo92dlf5bjHC8hLjt",
}}
fallbackSource={{
uri: "https://drive.google.com/uc?export=view&id=1h1e89BtQCp6JdGiKo92dlf5bjHC8hLjt",
}}
/>
</Box>
<VStack px="$6" pt="$4" pb="$6">
<Heading size="sm">Fresh Orange - Imported (Loose)</Heading>
<Text fontSize="$sm" my="$1.5">
Rs 146(Rs.24.33/pc)
</Text>
<Text fontSize="$xs">DETAILS</Text>
<Text fontSize="$xs" my="$1.5">
Oranges are a great source of vitamin C, which is essential for a healthy
immune system. Oranges are a great source of vitamin C, which is important
for maintaining a healthy immune system. Vitamin C also helps with the
absorption of iron and the production of collagen, which supports healthy
skin, teeth, and bones.
</Text>
<Link href="https://gluestack.io/" isExternal>
<Text fontSize="$xs" color="$pink600">
READ MORE
</Text>
</Link>
</VStack>
<Fab bg="$pink600" size="lg" right="$4" bottom="$20">
{/* ShoppingCartIcon is imported from 'lucide-react-native' */}
<FabIcon as={ShoppingCartIcon} h="$4" w="$4" />
</Fab>
</Box>

Unstyled

We provide in-depth information on how to customize and extend the component's functionality to meet your needs. Below, we describe how to modify the component to suit your requirements.

Customizing the Fab

We have a function called createFab which can be used to create a custom fab component. This function takes in a configuration object which contains the styled components that you want to use for the fab. You can refer gluestack.io/style on how to use styled components.

Usage

Default styling of all these components can be found in the components/core/fab file. For reference, you can view the source code of the styled Fab components.
// import the styles
import { Root, Label } from "../components/core/fab/styled-components"
// import the createFab function
import { createFab } from "@gluestack-ui/fab"
// Understanding the API
const Fab = createFab({
Root,
Label,
})
// Using the fab component
export default () => (
<Fab>
<FabLabel />
<FabIcon />
</Fab>
)

Spec Doc

Explore the comprehensive details of the Fab in this document, including its implementation details, checklist, and potential future additions. Dive into the thought process behind the component and gain insights into its development journey.
Edit this page on GitHub