flowbite-vue Documentation

repository·main·Indexed 21 days ago

https://github.com/themesberg/flowbite-vue

A Vue 3 UI component library built on top of Tailwind CSS and Flowbite. It provides an open-source collection of components including navigation, layout, data display, feedback overlays, and form elements to help build user interfaces and websites quickly.

Tokens
87K
Snippets
239
Records
287
Agent score
72%

What's inside flowbite-vue

  1. Explore Flowbite Vue components

    main

    Flowbite Vue provides a wide range of UI components built with Vue and Tailwind CSS. You can find detailed documentation, usage examples, and visual previews for each component on the official website.

    Available Components:

    • Navigation & Layout: Navbar, Breadcrumbs, Sidebar, Footer, Tabs, Accordion, Carousel
    • Data Display: Badge, Card, List group, Table, Timeline, Avatar, Rating, Progress bar
    • Feedback & Overlays: Alert, Modal, Toast, Tooltip, Spinner
    • Form Elements:
      • Inputs: Input Field, File Input, Select, Textarea, Checkbox, Radio, Toggle, Range Slider, Search Input (external), Floating Label (external)
      • Date/Time: Datepicker (external)
    • Buttons: Button, Button group
    • Other: Dropdown, Pagination
  2. Accessibility for Radio components

    main

    The FwbRadio and FwbRadioGroup components are designed with accessibility in mind:

    • Grouping: FwbRadioGroup renders as a <fieldset> with a <legend>, providing semantic grouping for screen readers.
    • Validation: When FwbRadioGroup has validationStatus="error", it automatically manages aria-invalid for all child radios and links aria-describedby to validation and helper messages.
    • Labeling: For radios without a visible text label, you should pass an aria-label attribute to the FwbRadio component. This attribute is forwarded directly to the underlying <input type="radio"> element.
  3. How to use the Footer component

    main

    The FwbFooter component is a wrapper used to display brand information, sitemap links, copyright notices, and social media icons at the bottom of a page. You can customize the layout using the footer-type prop to switch between different presets.

    Available footer-type presets:

    • Default: A simple footer with a copyright notice and navigation links.
    • logo: Displays a brand logo and name alongside navigation links.
    • socialmedia: Renders social platform links alongside multi-column link groups.
    • sitemap: A dark, full-width footer with multi-column link groups, social icons, and a copyright notice.
    <template>
      <fwb-footer footer-type="logo">
        <!-- Content here -->
      </fwb-footer>
    </template>
    
    <script setup>
    import { FwbFooter } from 'flowbite-vue'
    </script>
  4. Build rich alert layouts with FwbAlert slots

    main

    The FwbAlert component supports several slots to build complex layouts including headings, custom icons, and structured body content.

    Available Slots

    • title: Renders content above the main body.
    • icon: Allows you to provide a custom icon to replace the default type-based icon.
    • close-icon: Allows you to provide a custom icon for the close button.
    • default: The main body content. When using the closable prop, the default slot provides an onCloseClick function via scoped slots to manually trigger dismissal.

    Example: Rich Alert with Title and Custom Body

    <template>
      <fwb-alert type="info">
        <template #icon>
          <!-- Your custom SVG icon here -->
        </template>
        <template #title>
          <h3 class="text-lg font-medium">Alert Title</h3>
        </template>
        <template #default="{ onCloseClick }">
          <p>Detailed information goes here.</p>
          <button @click="onCloseClick">Dismiss</button>
        </template>
      </fwb-alert>
    </template>
    <template>
      <fwb-alert type="info">
        <template #icon>
          <svg
            class="shrink-0 w-4 h-4 mr-2"
            aria-hidden="true"
            xmlns="http://www.w3.org/2000/svg"
            fill="currentColor"
            viewBox="0 0 20 20"
          >
            <path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5ZM9.5 4a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3ZM12 15H8a1 1 0 0 1 0-2h1v-3H8a1 1 0 0 1 0-2h2a1 1 0 0 1 1 1v4h1a1 1 0 0 1 0 2Z" />
          </svg>
          <span class="sr-only">Info</span>
        </template>
        <template #title>
          <h3 class="text-lg font-medium">
            This is a info alert
          </h3>
        </template>
        <template #default="{ onCloseClick }">
          <div class="mt-2 mb-4 text-sm">
            More info about this info alert goes here. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.
          </div>
          <div class="flex">
            <fwb-button
              color="blue"
              size="sm"
              class="mr-2 inline-flex items-center"
            >
              <template #prefix>
                <svg
                  class="size-3"
                  aria-hidden="true"
                  xmlns="http://www.w3.org/2000/svg"
                  fill="currentColor"
                  viewBox="0 0 20 14"
                >
                  <path d="M10 0C4.612 0 0 5.336 0 7c0 1.742 3.546 7 10 7 6.454 0 10-5.258 10-7 0-1.664-4.612-7-10-7Zm0 10a3 3 0 1 1 0-6 3 3 0 0 1 0 6Z" />
                </svg>
              </template>
              View more
            </fwb-button>
            <fwb-button
              size="sm"
              outline
              data-dismiss-target="#alert-additional-content-1"
              aria-label="Close"
              @click="onCloseClick"
            >
              Dismiss
            </fwb-button>
          </div>
        </template>
      </fwb-alert>
    </template>
    
    <script setup>
    import { FwbAlert, FwbButton } from 'flowbite-vue'
    </script>
  5. Control Modal dismissal behavior (Escapable and Persistent)

    main

    You can control how users interact with and dismiss the modal using the not-escapable and persistent props.

    Escapable Behavior

    By default, a modal can be closed by clicking the close button, clicking the overlay, or pressing the Escape key.

    • Set not-escapable to true to disable the outside-click and Escape key behaviors. The close button remains visible, and you must close the modal programmatically.

    Persistent Behavior

    • Set persistent to true to prevent the close event from firing when clicking the overlay or pressing Escape.
    • The close button is automatically hidden when persistent is active. Use this for flows where the user MUST interact with the content before proceeding.
    <template>
      <!-- Default behavior -->
      <fwb-modal />
    
      <!-- Disables Escape and outside click, but shows close button -->
      <fwb-modal not-escapable />
    
      <!-- Disables all passive dismissal and hides close button -->
      <fwb-modal persistent />
    </template>
    
    <script setup>
    import { FwbModal } from 'flowbite-vue'
    </script>
  6. Configure Pagination layouts and windows

    main

    You can customize the visual structure and density of the pagination component using the following props:

    • Custom Page Window: Use slice-length to control how many page numbers are shown on each side of the current page. The total visible count is sliceLength + 1 + sliceLength (default is 2).
    • Navigation Layout: Set layout="navigation" to render only the previous and next buttons, omitting individual page numbers.
    • Table Layout: Set layout="table" to display a summary (e.g., "Showing X to Y of Z"). This layout requires both :per-page and :total-items instead of :total-pages.
    <!-- Navigation Layout -->
    <fwb-pagination
      v-model="currentPage"
      :layout="'navigation'"
      :total-pages="100"
    />
    
    <!-- Table Layout -->
    <fwb-pagination
      v-model="currentPage"
      :layout="'table'"
      :per-page="20"
      :total-items="100"
    />
    
    <!-- Custom Page Window -->
    <fwb-pagination
      v-model="currentPage"
      :slice-length="4"
      :total-pages="100"
    />
  7. How the Accordion component works

    main

    The Accordion component is a composite UI element used to show and hide content panels. It is built using four specialized sub-components that work together:

    1. FwbAccordion: The root wrapper component.
    2. FwbAccordionPanel: Represents an individual collapsible section.
    3. FwbAccordionHeader: The clickable trigger element that toggles the panel.
    4. FwbAccordionContent: The body containing the content to be shown or hidden.

    By default, the first panel is open on render, and activating a new panel will automatically collapse any currently open panel.

    <template>
      <fwb-accordion>
        <fwb-accordion-panel>
          <fwb-accordion-header>Title</fwb-accordion-header>
          <fwb-accordion-content>
            Content goes here.
          </fwb-accordion-content>
        </fwb-accordion-panel>
      </fwb-accordion>
    </template>
    
    <script setup>
    import {
      FwbAccordion,
      FwbAccordionPanel,
      FwbAccordionHeader,
      FwbAccordionContent,
    } from 'flowbite-vue'
    </script>
  8. Position the progress value (inside vs outside)

    main

    The value-position prop determines where the percentage text is rendered:

    • inside: Renders the value inside the progress bar. It is recommended to use size="lg" or larger to ensure enough space. At very low progress values, the text is clipped to the bar's width or skipped entirely at 0.
    • outside: Renders the value to the right of the label text above the bar.
    <template>
      <!-- Value Inside -->
      <fwb-progress
        :progress="50"
        value-position="inside"
        show-value
        size="lg"
      />
    
      <!-- Value Outside -->
      <fwb-progress
        :progress="42"
        value-position="outside"
        show-value
        label="Flowbite Vue 3"
      />
    </template>
    
    <script setup>
    import { FwbProgress } from 'flowbite-vue'
    </script>
  9. Customize FwbToggle with slots

    main

    Use slots to add descriptive or feedback content below the toggle:

    • helper: Renders hint text below the toggle.
    • validationMessage: Renders validation feedback below the toggle. This slot is styled based on the validationStatus prop and takes priority over the validationMessage prop.
    <template>
      <fwb-toggle v-model="toggle" label="Dark mode">
        <template #helper>
          Switches the interface between light and dark themes.
        </template>
      </fwb-toggle>
    </template>
  10. Handle validation and accessibility in FwbInput

    main

    The FwbInput component provides built-in accessibility features for validation states:

    • Error State: When validationStatus="error" is applied, aria-invalid="true" is automatically set on the native input.
    • Descriptions: The aria-describedby attribute is automatically wired to the IDs of any rendered validationMessage (via slot or prop) and helper slots. This value is merged with any aria-describedby attribute you pass manually.
    • Feedback Priority: If you use both the validationMessage prop and the validationMessage slot, the slot content takes priority.
  11. Use FwbSelect slots for customization

    main

    Use slots to inject custom content into specific parts of the FwbSelect component:

    • #chevron: Replace the default dropdown arrow icon with your own content (e.g., a custom SVG).
    • #helper: Render supplementary text (like privacy notices or hints) below the select component. This text is automatically linked via aria-describedby for accessibility.
    • #validationMessage: Render rich HTML content for validation feedback below the select.
    <template>
      <!-- Custom Chevron Slot -->
      <fwb-select v-model="selected" :options="countries">
        <template #chevron>
          <svg class="size-4 text-gray-500" fill="currentColor" viewBox="0 0 24 24">
            <path d="M12 2a1 1 0 0 1 .707.293l4 4a1 1 0 0 1-1.414 1.414L12 4.414 8.707 7.707a1 1 0 0 1-1.414-1.414l4-4A1 1 0 0 1 12 2Z" />
          </svg>
        </template>
      </fwb-select>
    
      <!-- Helper Slot -->
      <fwb-select v-model="selected" :options="countries" label="Select a country">
        <template #helper>
          We'll never share your details.
        </template>
      </fwb-select>
    </template>
  12. Handle validation in Radio groups

    main

    You can manage validation states for a group of radios using the validationStatus and validationMessage properties on FwbRadioGroup.

    When validationStatus="error" is applied to the FwbRadioGroup:

    1. Error color styles are applied to the group.
    2. aria-invalid="true" is automatically set on every child FwbRadio input.
    3. The aria-describedby attribute on the fieldset is automatically wired to the IDs of any rendered validationMessage (via slot or prop) or helper slots.

    You can provide the error message via the validationMessage prop or by using the validationMessage slot for custom rich content.