FlyonUI
repository·main·Indexed 25 days ago
https://github.com/themeselection/flyonuiAn open-source Tailwind CSS component library (version 2.4.1) that combines semantic styling via daisyUI with interactive, accessible headless JavaScript plugins via Preline. It provides over 80 UI components, including form elements, overlays, and navigations, and can be installed as a Tailwind CSS plugin with options to include, exclude, or prefix classes. It features native RTL support and a robust accessibility manager (HSAccessibilityObserver) for keyboard interactions.
What's inside flyonui
- FlyonUI provides a library of over 80 UI components built with Tailwind CSS utility classes. These range from basic elements like buttons and checkboxes to complex overlays and third-party integrations like Apex Charts. Components are categorized into groups such as Form Elements, Overlays, Navigations, and Third-party Plugins.
FlyonUI Core Concepts and Architecture
mainFlyonUI is a Tailwind CSS component library that combines semantic styling with interactive headless JavaScript functionality. It is built upon three core pillars:
- Tailwind CSS: Provides the utility-first foundation.
- daisyUI: Provides semantic class names to make Tailwind code more readable and maintainable.
- Preline: Provides the headless, unstyled, and accessible JavaScript plugins that handle interactivity (e.g., Accordion, Dropdown, Overlay).
This architecture allows developers to use clean, semantic classes for styling while benefiting from robust, accessible JavaScript behaviors without writing custom logic for common UI patterns.
Enable RTL (Right-to-Left) Support
mainFlyonUI components support RTL languages natively. To enable RTL mode, add thedir="rtl"attribute to your HTML element (usually the<html>tag).Include FlyonUI JavaScript for Interactivity
mainTo enable interactive components such as accordions, dropdowns, and modals, include the FlyonUI JavaScript in your HTML file just before the closing
</body>tag.To include the full library:
<script src="../node_modules/flyonui/flyonui.js"></script>To include only a specific component (e.g., accordion) for better performance:
<script src="../node_modules/flyonui/dist/accordion.js"></script>Install FlyonUI via NPM
mainTo use FlyonUI, ensure you have Node.js and Tailwind CSS installed. Follow these steps to integrate FlyonUI into your project:
Install the package as a dependency:
npm install flyonuiAdd FlyonUI as a plugin in your CSS entry point (e.g.,
app.css).To enable interactive JavaScript components (like accordions, dropdowns, or modals), you must also include the FlyonUI JavaScript files in your HTML.
npm install flyonuiHow HSFileUpload works with Dropzone
mainThe
HSFileUploadplugin acts as a wrapper aroundDropzone. It interceptsDropzoneevents to manage FlyonUI-specific UI elements like progress bars, file name displays, and custom preview templates.Internal Lifecycle & UI Mapping
When a file is added, the plugin looks for specific
data-file-upload-*attributes within the preview template to populate information:data-file-upload-file-name: The name of the file.data-file-upload-file-ext: The file extension.data-file-upload-file-size: The formatted file size (e.g., '1.2 MB').data-file-upload-file-icon: The container for the extension-specific icon.data-dz-thumbnail: The image element used if the file is an image.data-file-upload-remove: The button used to triggerdropzone.removeFile().data-file-upload-progress-bar: The progress bar element.data-file-upload-progress-bar-pane: The inner element of the progress bar that changes width.data-file-upload-progress-bar-value: The text element showing the percentage (e.g., '50%').
Configure Tabs via HTML data attributes
mainYou can configure
HSTabsdirectly in your HTML using thedata-tabsattribute. The attribute accepts a JSON string ofITabsOptions.Example:
<div role="tablist" data-tabs='{"eventType": "hover"}'> <button data-tab="tab-1">Tab 1</button> <button data-tab="tab-2">Tab 2</button> </div> <div data-tab="tab-1">Content 1</div> <div data-tab="tab-2" class="hidden">Content 2</div>Additionally, you can link a
<select>element to act as a tab switcher using thedata-tab-selectattribute on the container, pointing to the ID of the select element.How HSOverlay handles accessibility
mainHSOverlayintegrates withHSAccessibilityObserverto manage focus and keyboard interactions:- Focus Management: When an overlay opens, focus is moved to the overlay container or the first element with the
[autofocus]attribute. When closed, focus is restored to the element that originally triggered the overlay. - Keyboard Navigation:
- The
Esckey closes the overlay (ifhasAbilityToCloseOnBackdropClickis true). - Tab key trapping: If
--tab-accessibility-limitedis set totrue, focus is trapped within the overlay's focusable elements.
- The
- ARIA Attributes: The plugin automatically manages
aria-expandedon toggle buttons andaria-overlayon the overlay element itself.
- Focus Management: When an overlay opens, focus is moved to the overlay container or the first element with the
Configure FlyonUI in CSS
mainAdd FlyonUI to your Tailwind CSS configuration by importing it in your CSS file.
If you want to use FlyonUI's interactive JavaScript components, you must also import the variants CSS and define the source path for the JS files so Tailwind can scan them. You can also target specific components to reduce bundle size.
@import "tailwindcss"; @plugin "flyonui"; @import "./node_modules/flyonui/variants.css"; // Require only if you want to use FlyonUI JS components @source "./node_modules/flyonui/dist/index.js"; // Require only if you want to use FlyonUI JS componentsHSAccessibilityObserver is automatically initialized
mainFlyonUI automatically instantiates anHSAccessibilityObserverand attaches it towindow.HSAccessibilityObserverif the code is running in a browser environment. This manager handles accessibility-related observations for the UI components.Configure Scrollspy offset and scrollable parent
mainScrollspy uses specific attributes to manage offsets and the scrollable container:
data-scrollspy-scrollable-parent: Set this on the scrollspy element to specify the ID of the element that is actually scrolling (e.g., adivwithoverflow: auto). If not provided, it defaults to thedocument.--scrollspy-offset: A CSS property that can be set on the scrollspy element (global offset) or on individual sections (local offset) to adjust when a section is considered 'active'.
Initialize the Pin Input component
mainThe Pin Input component manages a group of individual input fields (typically for OTP or PIN codes). It can be initialized automatically via
HSPinInput.autoInit()if your HTML elements use thedata-pin-inputattribute, or manually by instantiating theHSPinInputclass.To use the component, your HTML structure must include a container with the
data-pin-inputattribute and multiple child elements with thedata-pin-input-itemattribute.Automatic Initialization
Call
HSPinInput.autoInit()to find all elements withdata-pin-input(that do not have the--prevent-on-load-initclass) and initialize them.Manual Initialization
Pass the container element and an optional configuration object to the constructor.
const pinInput = new HSPinInput(element, { availableCharsRE: '^[0-9]+$' });