@sarawebs/sb-components
Version:
SaraWebs components for web apps and tools
227 lines (150 loc) β’ 5.95 kB
Markdown
## π¦ `@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);
```

### βοΈ 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)