UNPKG

@sarawebs/sb-components

Version:

SaraWebs components for web apps and tools

227 lines (150 loc) β€’ 5.95 kB
## πŸ“¦ `@sarawebs/sb-components` A lightweight and modular component library from **SaraWebs**, starting with a fully reusable **Dropdown** system and built with flexibility in mind β€” perfect for client dashboards, internal tools, and modern web apps. Designed with **composition**, **zero dependencies**, and **real-world use** in mind. More components coming soon πŸš€. --- ### ✨ Features * 🧱 **Composable Architecture** Clean, class-based structure using best practices in reusable JavaScript. * πŸ” **Multiple Instances** Easily supports multiple dropdowns per page β€” all independently controlled. * πŸ–±οΈ **Click or Hover Triggers** Choose trigger behavior via `data-trigger` β€” no code changes required. * 🧩 **Expandable Design** Built as a foundation for future UI components like modals, tabs, toasts, and tooltips. * βš™οΈ **Zero Dependencies** Lightweight and bundler-friendly. No need for jQuery or bulky UI libs. --- ### πŸ“š API Reference #### Installation ```bash npm install @sarawebs/sb-components ``` --- ### 🧭 Current Component: Dropdown #### HTML Example ```html <div class="dropdown" data-trigger="click"> <button class="dropdown-toggle">Open Menu</button> <ul class="dropdown-menu"> <li><a href="#">Option 1</a></li> <li><a href="#">Option 2</a></li> </ul> </div> ``` > You can switch behavior by using `data-trigger="hover"` instead. --- #### JS Usage ```js import "@sarawebs/sb-components/Dropdown/style"; // basic styles import { Dropdown } from '@sarawebs/sb-components/Dropdown'; document.querySelectorAll('.dropdown').forEach(dropdownEl => { new Dropdown(dropdownEl); }); ``` --- #### Class: `Dropdown` | Method | Description | | ---------- | -------------------------------------- | | `show()` | Opens the dropdown programmatically | | `hide()` | Closes the dropdown | | `toggle()` | Toggles between open and closed states | ##### Data Attributes | Attribute | Values | Description | | -------------- | ---------------------- | ---------------------------------- | | `data-trigger` | `"click"` \| `"hover"` | Sets dropdown interaction behavior | --- ### 🎨 Styling (Basic) ```css .dropdown-menu { display: none; position: absolute; background: white; border: 1px solid #ddd; z-index: 1000; } .dropdown.show .dropdown-menu { display: block; } ``` You can style or animate however you like. The module doesn’t enforce design. --- ### πŸ–ΌοΈ Component: Carousel A lightweight, reusable **Image Carousel** component built with zero dependencies, perfect for showcasing images in client dashboards, landing pages, and web apps. Designed with a clean class-based architecture following the same composition principles as the Dropdown component. --- ### 🎯 Features * β¬…οΈβž‘οΈ **Arrow Controls** β€” Navigate forward and backward through images * πŸ”„ **Auto Slide** β€” Automatically advances every N milliseconds * ⚫ **Navigation Dots** β€” Visual indicators that are clickable to jump to any slide * 🧱 **Composable & Reusable** β€” Easily instantiate multiple carousels on a page * πŸ”§ **Dynamic Content** β€” Accepts an array of image URLs to render slides * ⏱️ **Custom Timer** β€” Configure auto-slide delay via constructor * βš™οΈ **No Dependencies** β€” Pure vanilla JS with modular class design --- ### πŸ“š Usage #### HTML Setup Only an empty container is required. The component will dynamically populate it. ```html <div id="carousel-container"></div> ``` #### JS Initialization ```js import "@sarawebs/sb-components/Carousel/style"; // Basic styles import { Carousel } from "@sarawebs/sb-components/Carousel"; const images = [ 'https://picsum.photos/id/1015/800/300', 'https://picsum.photos/id/1016/800/300', 'https://picsum.photos/id/1018/800/300', ]; const container = document.getElementById('carousel-container'); // 5-second timer (default) new Carousel(container, images); // OR with a custom interval (e.g., 3 seconds) new Carousel(container, images, 3000); ``` --- ![screenshot](./sc.png) ### βš™οΈ Class: `Carousel` | Parameter | Type | Description | | --------------------------- | --------- | ------------------------------------------ | | `root` | Element | HTML element to render the carousel inside | | `images` | string\[] | Array of image URLs | | `autoSlideDelay` (optional) | number | Time in ms between slides (default: 5000) | --- | Method | Description | | ------------------ | ----------------------------------------- | | `moveToSlide(n)` | Moves carousel to the nth slide (0-based) | | `startAutoSlide()` | Starts the auto-slide loop | | `stopAutoSlide()` | Stops the auto-slide loop | --- ### πŸ’‘ Use Cases * Homepage hero sliders * Product image galleries * Testimonials rotators * Portfolio slideshows * Embedded widgets in client dashboards --- ### πŸš€ Integration This component is built in the same modular style as other **SaraWebs** UI primitives like `Dropdown`, `Modal`, and upcoming tools β€” enabling consistent development across internal tools, marketing sites, and client-facing applications. --- Let me know if you’d like to: * Add pause/resume buttons * Support swipe/touch gestures * Export this as an ES module or NPM package ### πŸ› οΈ Planned Components Coming soon: * βœ… Dropdown * ⏳ Modal * ⏳ Tooltip * ⏳ Toast * ⏳ Tab Switcher * ⏳ Collapsible Panels --- ### πŸ’‘ Use Cases * Navigation headers * Action menus (settings, logout, filters) * Admin panels and CMS UI * Reusable frontend patterns for small-to-medium apps --- ### 🌐 Website Built with ❀️ by [SaraWebs](https://sarawebs.com)