Floating Action Button / FAB - 图1

Floating Action Button React Component

Floating action buttons (FABs) are used for a promoted action. They are distinguished by a circled icon floating above the UI and have motion behaviors that include morphing, launching, and a transferring anchor point.

Floating Action Button React component represents Floating Action Button element.

FAB Components

There are following components included:

  • **Fab** / **F7Fab** - main FAB element
  • **FabButtons** / **F7FabButtons** - wrapper for multiple FAB buttons used as Speed Dial FAB
  • **FabButton** / **F7FabButton** - single FAB Speed Dial button

FAB Properties

PropTypeDefaultDescription
<Fab> properties
hrefstring
boolean
URL of the page to load (if set). Will set href attribute on main FAB link. In case of boolean href=”false” it won’t add href tag
targetstringValue of link target attribute, e.g. _blank, _self, etc.
positionstringright-bottomFAB position. Can be one of the following:
  • right-bottom
  • center-bottom
  • left-bottom
  • right-center
  • center-center
  • left-center
  • right-top
  • center-top
  • left-top
morphTostringString CSS selector of the FAB morph target
textstringFAB Button text. If specified, then it will be displayed as Extended Fab with text label
tooltipstringFAB tooltip text to show on button hover/press
<FabButtons> properties
positionstringtopSpeed dial buttons position, can be one of the following:
  • top - buttons will appear on top of FAB
  • right - buttons will appear on right of FAB
  • bottom - buttons will appear on bottom of FAB
  • left - buttons will appear on left of FAB
  • center - buttons will appear around of FAB
<FabButton> properties
fabClosebooleanfalseWhen enabled then clicking on this button will close the FAB
targetstringValue of link target attribute, e.g. _blank, _self, etc.
labelstringButton text label
tooltipstringButton tooltip text to show on button hover/press

FAB Events

EventDescription
<Fab> events
clickEvent will be triggered after click on FAB
<FabButton> events
clickEvent will be triggered after click on FAB Speed Dial button

FAB Slots

FAB React component (<Fab>) has additional slots for custom elements:

  • **default** - child element will be inserted inside of the main FAB link <a> element. But if the child is FabButtons, then it will be inserted in the end of the main FAB element
  • **link** - child element will be inserted inside of the main FAB link <a> element
  • **root** - child element will be inserted in the end of the main FAB element
  • **text** - child element will be inserted in the text element of the Extended FAB

Examples

  1. export default () => (
  2. <Page>
  3. <Navbar title="Floating Action Button" />
  4. {/* Toolbar FAB Morph Target */}
  5. <Toolbar bottomMd className="fab-morph-target">
  6. <Link>Link 1</Link>
  7. <Link>Link 2</Link>
  8. <Link>Link 3</Link>
  9. </Toolbar>
  10. {/* FAB Left Top (Yellow) */}
  11. <Fab position="left-top" slot="fixed" color="yellow">
  12. <Icon ios="f7:add" md="material:add"></Icon>
  13. <Icon ios="f7:close" md="material:close"></Icon>
  14. <FabButtons position="bottom">
  15. <FabButton>1</FabButton>
  16. <FabButton>2</FabButton>
  17. <FabButton>3</FabButton>
  18. </FabButtons>
  19. </Fab>
  20. {/* FAB Right Top (Pink) */}
  21. <Fab position="right-top" slot="fixed" color="pink">
  22. <Icon ios="f7:add" md="material:add"></Icon>
  23. <Icon ios="f7:close" md="material:close"></Icon>
  24. <FabButtons position="left">
  25. <FabButton>1</FabButton>
  26. <FabButton>2</FabButton>
  27. <FabButton>3</FabButton>
  28. </FabButtons>
  29. </Fab>
  30. {/* FAB Center (Green) */}
  31. <Fab position="center-center" slot="fixed" color="green">
  32. <Icon ios="f7:add" md="material:add"></Icon>
  33. <Icon ios="f7:close" md="material:close"></Icon>
  34. <FabButtons position="center">
  35. <FabButton>1</FabButton>
  36. <FabButton>2</FabButton>
  37. <FabButton>3</FabButton>
  38. <FabButton>4</FabButton>
  39. </FabButtons>
  40. </Fab>
  41. {/* FAB Left Bottom (Blue) */}
  42. {/* Will morph to Toolbar */}
  43. <Fab position="left-bottom" slot="fixed" morphTo=".toolbar.fab-morph-target">
  44. <Icon ios="f7:add" md="material:add"></Icon>
  45. <Icon ios="f7:close" md="material:close"></Icon>
  46. </Fab>
  47. {/* FAB Right Bottom (Orange) */}
  48. <Fab position="right-bottom" slot="fixed" color="orange">
  49. <Icon ios="f7:add" md="material:add"></Icon>
  50. <Icon ios="f7:close" md="material:close"></Icon>
  51. <FabButtons position="top">
  52. <FabButton label="Action 1">1</FabButton>
  53. <FabButton label="Action 2">2</FabButton>
  54. </FabButtons>
  55. </Fab>
  56. {/* Extended FAB Center Bottom (Red) */}
  57. <Fab position="center-bottom" slot="fixed" text="Create" color="red">
  58. <Icon ios="f7:add" md="material:add"></Icon>
  59. </Fab>
  60. <Block>
  61. <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quia, quo rem beatae, delectus eligendi est saepe molestias ... voluptatibus eligendi.</p>
  62. </Block>
  63. </Page>
  64. )