Fab
A dynamic button that stays visible, offering convenient access to a primary action.
Installation
API Reference
This is an illustration of Fab component.
size
placement
isHovered
isDisabled
isPressed
<Box className="h-[360px] w-80 bg-background-50 rounded-md"><Fabsize="md"placement="bottom right"isHovered={false}isDisabled={false}isPressed={false}><FabIcon as={AddIcon} /><FabLabel>Quick start</FabLabel></Fab></Box>
Installation
CLI
Manual
Run the following command:
npx gluestack-ui add fab
API Reference
To use this component in your project, include the following import statement in your file.
import { Fab, FabLabel, FabIcon } from "@/components/ui/fab"
export default () => (<Fab><FabLabel /><FabIcon /></Fab>)
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.
Data Attributes Table
Component receives states as props as boolean values, which are applied as data-* attributes. These attributes are then used to style the component via classNames, enabling state-based styling.
State | Data Attribute | Values |
---|---|---|
focus | data-focus | true | false |
focusVisible | data-focus-visible | true | false |
Fab
Name | Value | Default |
---|---|---|
size | sm | md | lg | md |
placement | top right | top left | bottom right | bottom left | top center |
bottom center | bottom right |
Important Note
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 className="border rounded-lg border-outline-200 p-6 bg-background-100 min-w-[240px] sm:min-w-[360px] md:min-w-[476px]"><VStack space="md">{data.map((chatData) => {return (<HStack space="sm" className="items-center"><Avatar size="sm"><AvatarImagesource={{uri: chatData.uri,}}/></Avatar><VStack><Heading size="xs">{chatData.name}</Heading><Text size="xs">{chatData.msg}</Text></VStack></HStack>)})}</VStack><Fabsize="lg"className="bg-primary-600 hover:bg-primary-700 active:bg-primary-800">{/* EditIcon is imported from 'lucide-react-native' */}<FabIcon as={EditIcon} color="white" /></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 className="max-w-96 border rounded-lg border-outline-200 py-[56px] px-6 mx-5 bg-background-100"><Fab className="top-4 h-9 bg-primary-600 hover:bg-primary-700 active:bg-primary-900"><FabIcon as={SearchIcon} /><FabLabel>Search</FabLabel></Fab><VStack space="lg"><Box><Text className="text-xs text-primary-600 font-bold">HEALTH</Text><Heading size="sm">Benefits of Oranges</Heading><Text size="xs" className="mt-1.5">Oranges are a great source of vitamin C, which is essential for ahealthy immune system.</Text><HStack space="sm" className="mt-3 h-5"><Text size="xs">Wade Warrem</Text><Divider orientation="vertical" className="bg-background-300" /><Text size="xs">6th Oct, 2019</Text><Divider orientation="vertical" className="bg-background-300" /><Text size="xs">5 mins read</Text></HStack></Box><Divider /><Box><Text className="text-xs text-primary-600 font-bold">TECHNOLOGY</Text><Heading size="sm">How AI can benefit your business</Heading><Text size="xs" className="mt-1.5">AI can automate tasks and processes, allowing for increasing efficiencyand productivity.</Text><HStack space="sm" className="mt-3 h-5"><Text size="xs">Wade Warrem</Text><Divider orientation="vertical" className="bg-background-300" /><Text size="xs">6th Oct, 2019</Text><Divider orientation="vertical" className="bg-background-300" /><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 className="border rounded-lg border-outline-300 py-4 bg-background-0 mx-5"><VStack space="lg" className="mb-2 px-6 py-2"><Checkbox size="sm"><CheckboxIndicator><CheckboxIcon as={CheckIcon} /></CheckboxIndicator><CheckboxLabel><Text fontSize="$sm">Prepare any feedback or updates.</Text></CheckboxLabel></Checkbox><Checkbox size="sm"><CheckboxIndicator><CheckboxIcon as={CheckIcon} /></CheckboxIndicator><CheckboxLabel><Text fontSize="$sm">Review progress on goals and projects.</Text></CheckboxLabel></Checkbox><Checkbox size="sm"><CheckboxIndicator><CheckboxIcon as={CheckIcon} /></CheckboxIndicator><CheckboxLabel><Text fontSize="$sm">Ask challenges and discuss.</Text></CheckboxLabel></Checkbox></VStack><Fab size="sm" placement="bottom center" className="top-0 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 className="max-w-96 border rounded-lg border-outline-200 overflow-hidden mx-5 bg-background-100"><Box><ImageclassName="h-[185px] w-[416px]"source={{uri: "https://images.unsplash.com/photo-1591206369811-4eeb2f03bc95?w=800&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8NDJ8fG9yYW5nZXxlbnwwfHwwfHx8MA%3D%3D",}}fallbackSource={{uri: "https://drive.google.com/uc?export=view&id=1h1e89BtQCp6JdGiKo92dlf5bjHC8hLjt",}}/></Box><VStack className="px-6 pt-4 pb-6"><Heading size="sm">Fresh Orange - Imported (Loose)</Heading><Text className="my-1.5 text-sm">Rs 146(Rs.24.33/pc)</Text><Text className="text-xs">DETAILS</Text><Text className="my-1.5 text-xs">Oranges are a great source of vitamin C, which is essential for a healthyimmune system. Oranges are a great source of vitamin C, which is importantfor maintaining a healthy immune system. Vitamin C also helps with theabsorption of iron and the production of collagen, which supports healthyskin, teeth, and bones.</Text><Link href="https://gluestack.io/" isExternal><Text className="text-xs text-primary-600">READ MORE</Text></Link></VStack><Fabsize="lg"className="bg-primary-600 right-4 bottom-16 hover:bg-primary-700 active:bg-primary-800">{/* ShoppingCartIcon is imported from 'lucide-react-native' */}<FabIcon as={ShoppingCartIcon} className="h-4 w-4" /></Fab></Box>