Skip to content

Repository files navigation

createDOMBlocks

Magyar README

A TypeScript library for creating complex HTML blocks and form elements using JavaScript. Built on top of DOMelemJS.

50+ components – form inputs, buttons, navigation, content blocks, custom pickers, drawers, modals, carousels, and more.

Features

  • 50+ UI components – inputs, buttons, tables, modals, navigation, alerts, and more
  • Framework-agnostic – works with any JS framework or vanilla JS
  • Type-safe – full TypeScript support with IntelliSense
  • Tree-shakable – import only what you need
  • Portal support – drawers and modals render to document.body automatically

Installation

npm

npm install createdomblocks

CDN (unpkg)

<linkrel="stylesheet" href="https://unpkg.com/createdomblocks/dist/style.css" /><scriptsrc="https://unpkg.com/createdomblocks/dist/index.js"></script>

This exposes a global CreateDOMBlocks object with all exported functions.

Quick Start

import{createTextInput,createButton,createCard}from"createdomblocks";import"createdomblocks/style.css";constparent=document.getElementById("app");createTextInput({
parent,id: "name",labelText: "Name:",placeholder: "Enter your name",});createButton({
parent,id: "submitBtn",text: "Submit",click: ()=>console.log("Clicked!"),});createCard({
parent,id: "infoCard",title: "Welcome",body: {tag: "p",text: "Hello from createDOMBlocks!"},});

API

Form Inputs

FunctionDescription
createTextInput(params)Text input with label
createTelInput(params)Telephone input
createUrlInput(params)URL input
createSearchInput(params)Search input
createEmailInput(params)Email input
createPasswordInput(params)Password input
createNumberInput(params)Number input
createDateInput(params)Date input
createDatetimeInput(params)Datetime-local input
createTimeInput(params)Time input
createMonthInput(params)Month input
createWeekInput(params)Week input
createCheckbox(params)Checkbox input
createColorInput(params)Color input
createFileInput(params)File input
createRangeInput(params)Range slider (min/max/step)
createHiddenInput(params)Hidden input

Buttons

FunctionDescription
createButton(params)<button> element with click handler
createButtonInput(params)<input type="button">
createSubmitInput(params)<input type="submit">
createResetInput(params)<input type="reset">

Selection & Textarea

FunctionDescription
createSelect(params)Native <select> dropdown
createRadio(params)Radio button group
createCustomSelect(params)Styled custom dropdown
createTextarea(params)Textarea input element

Custom Pickers

FunctionDescription
createCustomDatePicker(params)Interactive date picker
createCustomDateTimePicker(params)Date + time picker
createCustomDateRangePicker(params)Date range picker
createCustomMonthPicker(params)Month picker
createCustomWeekPicker(params)Week picker

Layout & Containers

FunctionDescription
createCard(params)Card with header / body / footer
createContainer(params)Max-width wrapper container
createGrid(params)CSS grid with configurable columns
createDivider(params)Horizontal rule <hr>

Navigation

FunctionDescription
createNav(params)Navigation bar with items and dropdowns
createBreadcrumb(params)Breadcrumb trail
createTabs(params)Tabbed interface
createMenu(params)Menu list (used inside drawers)
createDrawer(params)Side panel (portal – renders to body)
openDrawer(id)Open a drawer by ID
closeDrawer(id)Close a drawer by ID

Feedback

FunctionDescription
createAlert(params)Alert box (success/error/warning/info)
createToast(params)Auto-dismissing notification
createBadge(params)Status badge / pill
createSpinner(params)Loading spinner (sm/md/lg)
createProgressBar(params)Progress bar with percentage

Content

FunctionDescription
createParagraph(params)<p> element
createTitle(params, level)Heading (h1–h6)
createImage(params)Figure with image + optional caption
createLink(params)Styled <a> link
createCodeBlock(params)Code block with syntax highlighting
createBlockquote(params)Blockquote with optional author
createAccordion(params)Collapsible accordion sections
createTooltip(params)Tooltip (hover or click trigger)
createAvatar(params)User avatar (image or initials)
createUnorderedList(data, params)Unordered (bulleted) list
createOrderedList(data, params)Ordered (numbered) list
newLine(parent)Line break <br>
asyncImage(params)Lazy-loaded image

Data Display

FunctionDescription
createTable(data, params)Table with header/footer/sum/row numbers

Overlays (Portal)

FunctionDescription
createModal(content, actions, params)Modal dialog (portal – renders to body)
openModal(id)Open a modal by ID
closeModal(id)Close a modal by ID

Forms

FunctionDescription
createForm(params)Form element with input configs

Interactive

FunctionDescription
createCarousel(params)3D carousel with navigation and touch
createDragAndDropFileInput(params)Drag & drop file uploader

Common Parameters

All components accept a params object. Common fields:

ParameterTypeDescription
parentHTMLElement | stringParent element or CSS selector (required)
idstringElement ID (required)
classstringAdditional CSS class
handleEventEventHandler | EventHandler[]Event handlers

Input components additionally support:

ParameterTypeDefaultDescription
labelTextstringLabel text
labelfirstbooleantrueLabel before input
valuestring | numberInitial value
namestringInput name attribute
placeholderstringPlaceholder text
onChange(e: Event) => voidChange handler
click(e: Event) => voidClick handler

Table Options

ParameterTypeDefaultDescription
hasHeaderbooleantrueFirst row is header
showFooterbooleantrueShow footer row
addRowNumbersbooleanfalseAdd row number column
sumRowValuesbooleanfalseAdd sum column
cellNamesobjectCustom header names

Drawer / Modal (Portal)

createDrawer and createModal are portal components – they automatically render their HTML to document.body. They do not accept a parent parameter.

// Drawer with menucreateDrawer({id: "sidebar",title: "Menu",children: [createMenu({id: "nav",items: menuItems})],mode: "push",defaultState: "closed",});openDrawer("sidebar");// ModalcreateModal({modalTitle: "Confirm",body: {tag: "p",text: "Are you sure?"}},{okAction: ()=>console.log("OK"),cancelAction: ()=>console.log("Cancelled")},{id: "confirmModal"});openModal("confirmModal");

Example

import{createTextInput,createSelect,createButton,createTable,createCard,createToast}from"createdomblocks";constparent=document.getElementById("app");createCard({
parent,id: "formCard",title: "User Form",body: [createTextInput({ parent,id: "name",labelText: "Name:",placeholder: "Enter name"}),createSelect({ parent,id: "role",labelText: "Role:",options: [{text: "Admin",value: "admin"},{text: "User",value: "user"},]}),createButton({ parent,id: "saveBtn",text: "Save",click: ()=>{createToast({parent: document.body,message: "Saved!",type: "success"});}}),],});

License

MIT © Viktor Bozzay

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages