Skip to main 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.

import { Fab } from 'patine-ui';
Loading…
<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>

Try the props​

Props
label
size
design
<Fab
icon={({ color }) => <Icon
name="edit"
color={color} />}
accessibilityLabel="Compose"
/>

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.

Loading…
<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.

PropTypeDefaultDescription
iconReactNode | ({ color }) => ReactNode—The icon, or a function of the color to draw it in.
labelstring—Extends it into a pill with this text.
size'sm' | 'md' | 'lg''md'40, 56 or 96 points.
placement'bottomEnd' | 'bottomStart' | 'bottomCenter'inlineFloats it over its parent.
offsetnumber16Space from the edges when placed.
onPress() => void—The action.
disabledbooleanfalseDims it.
style, labelStyleStyleProp—The button and its label.
theme, designAs every component.