# React Native FAB (floating action button)

> A React Native floating action button for iOS, Android and the web: Material 3's FAB and extended FAB in three sizes, or a raised primary circle, placed in a corner over the content.

# Fab

A floating action button for a screen's one main action: compose, add, scan. With a `label` it extends into a pill. `placement` floats it over the content in a corner.

```tsx
import { Fab } from 'patine-ui';
```

```tsx live
import { Box, Fab, List, ListItem } from 'patine-ui';
import { Icon } from '@patine-ui/icons';

const NOTES = ['Groceries', 'Trip to Lisbon', 'Book club picks', 'Gift ideas', 'Workout plan'];

export default function Example() {
  const [notes, setNotes] = React.useState(NOTES);
  return (
    <Box border radius="lg" style={{ width: '100%', maxWidth: 360, height: 340, paddingTop: 16, overflow: 'hidden' }}>
      <List title="Notes">
        {notes.map((n) => (
          <ListItem key={n} title={n} onPress={() => {}} />
        ))}
      </List>
      <Fab
        placement="bottomEnd"
        icon={({ color }) => <Icon name="edit" color={color} />}
        label="New note"
        onPress={() => setNotes([`Note ${notes.length + 1}`, ...notes])}
      />
    </Box>
  );
}
```

## Example: log an expense

A shared trip budget: the extended button floats over the list, keeps clear of the last row, and adds an expense that updates the total.

```tsx live
import { useState } from 'react';
import { ScrollView } from 'react-native';
import { Box, Fab, HStack, List, ListItem, Text } from 'patine-ui';
import { Icon } from '@patine-ui/icons';

const NEXT = [
  { what: 'Ferry to Paros', who: 'Maya', amount: 84 },
  { what: 'Groceries', who: 'Leo', amount: 46.2 },
  { what: 'Scooter rental', who: 'Ana', amount: 60 },
];

export default function Example() {
  const [expenses, setExpenses] = useState([
    { what: 'Apartment, 4 nights', who: 'Maya', amount: 620 },
    { what: 'Dinner at Taverna', who: 'Leo', amount: 112.5 },
  ]);
  const total = expenses.reduce((sum, e) => sum + e.amount, 0);
  const add = () => setExpenses((all) => [NEXT[all.length % NEXT.length], ...all]);
  return (
    <Box border radius="lg" style={{ width: '100%', maxWidth: 380, height: 360, overflow: 'hidden' }}>
      <HStack justify="space-between" padding="md">
        <Text weight="semibold">Greece, June</Text>
        <Text weight="semibold">€{total.toFixed(2)}</Text>
      </HStack>
      <ScrollView contentContainerStyle={{ paddingBottom: 88 }}>
        <List>
          {expenses.map((e, i) => (
            <ListItem key={i} title={e.what} description={`Paid by ${e.who}`} value={`€${e.amount.toFixed(2)}`} />
          ))}
        </List>
      </ScrollView>
      <Fab placement="bottomEnd" label="Add expense" icon={({ color }) => <Icon name="plus" color={color} />} onPress={add} />
    </Box>
  );
}
```

## Sizes

`sm` (40), `md` (56) and `lg` (96), Material 3's small, regular and large FABs. Without a `label`, give it an `accessibilityLabel`.

## Placement

`placement` is `'bottomEnd'`, `'bottomStart'` or `'bottomCenter'`, floating it `offset` points (16) in from the edges of its parent. Add the safe area's bottom inset to `offset` on phones. Leave `placement` out to put it where you like.

## Designs

- **Material 3**: a rounded square on the tonal primary container, as Android apps draw it.
- **brand**, **iOS** and **web**: a raised primary circle.

## Accessibility

A `button` named by its label or `accessibilityLabel`, with a focus ring on the web. Every size is at least 40pt, and 44pt with its touch area.

## Props

Also takes `Pressable` props.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `icon` | `ReactNode \| ({ color }) => ReactNode` | — | The icon, or a function of the color to draw it in. |
| `label` | `string` | — | Extends it into a pill with this text. |
| `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | 40, 56 or 96 points. |
| `placement` | `'bottomEnd' \| 'bottomStart' \| 'bottomCenter'` | inline | Floats it over its parent. |
| `offset` | `number` | `16` | Space from the edges when placed. |
| `onPress` | `() => void` | — | The action. |
| `disabled` | `boolean` | `false` | Dims it. |
| `style`, `labelStyle` | `StyleProp` | — | The button and its label. |
| `theme`, `design` | | | As every component. |
