4.4.15 • Published 5 months ago

@conectate/ct-dialog v4.4.15

Weekly downloads
9
License
BSD-3-Clause
Repository
github
Last release
5 months ago

@conectate/ct-dialog

A versatile dialog component system with multiple animation styles, confirmations, prompts, loading indicators, and more. Built with Web Components for maximum compatibility.

Table of Contents

Installation

Install via npm, yarn, or pnpm:

# npm
npm i @conectate/ct-dialog

# yarn
yarn add @conectate/ct-dialog

# pnpm
pnpm i @conectate/ct-dialog

Components

This package includes several dialog components:

ComponentDescription
ct-dialogBase dialog component with multiple animation types
ct-card-dialogDialog with card styling
ct-loadingLoading dialog with spinner
ct-prompPrompt dialog for text input
ct-confirmConfirmation dialog with customizable buttons
ct-confirm-cupertinoiOS-styled confirmation dialog

Basic Usage

Base Dialog

import { showCtDialog, closeCtDialog } from "@conectate/ct-dialog";

// Create content for the dialog
const content = document.createElement('div');
content.innerHTML = `
	<h2>Dialog Title</h2>
	<p>This is a custom dialog content.</p>
	<button onclick="closeCtDialog()">Close</button>
`;

// Show the dialog
const dialog = showCtDialog(content);

// Configure dialog animation
dialog.setAnimation('slide-right');

// Close programmatically
dialog.close();
// Or close by ID
closeCtDialog(dialog);

Card Dialog

import { showCtCardDialog } from "@conectate/ct-dialog";

// Create content for the card dialog
const content = document.createElement('div');
content.innerHTML = `
	<h2>Card Title</h2>
	<p>This is card content with nice styling.</p>
	<button>Close</button>
`;

// Show the card dialog
const dialog = showCtCardDialog(content);

Loading Dialog

import { showCtLoading } from "@conectate/ct-dialog";

// Show a loading dialog
const loadingDialog = showCtLoading();

// Show a loading dialog with custom text
const customLoadingDialog = showCtLoading(undefined, 'Processing');

// Async operation example
async function fetchData() {
	const loading = showCtLoading(undefined, 'Fetching data');
	try {
		await fetch('/api/data');
	} finally {
		loading.close();
	}
}

Prompt Dialog

import { showCtPrompt } from "@conectate/ct-dialog";

// Basic prompt
async function getName() {
	const name = await showCtPrompt("Enter Name", "Please enter your name:");
	console.log("Name:", name);
}

// Prompt with custom buttons and options
async function getEmail() {
	const email = await showCtPrompt(
		"Email Address",
		"Please provide your email:",
		"Submit",
		"Cancel",
		undefined,
		{
			label: "Email",
			placeholder: "user@example.com",
			value: "default@example.com"
		}
	);

	if (email) {
		console.log("Email provided:", email);
	} else {
		console.log("User canceled prompt");
	}
}

Confirmation Dialog

import { showCtConfirm, showCtConfirmCupertino } from "@conectate/ct-dialog";

// Standard Material Design confirmation
async function confirmAction() {
	const confirmed = await showCtConfirm(
		"Confirm Action",
		"Are you sure you want to proceed?",
		"Yes",
		"No"
	);

	if (confirmed) {
		// User clicked "Yes"
		performAction();
	}
}

// Three-option dialog
async function chooseAction() {
	const result = await showCtConfirm(
		"Choose Action",
		"What would you like to do?",
		"Save",
		"Delete",
		"Cancel"
	);

	if (result === true) {
		// User clicked "Save"
		saveData();
	} else if (result === false) {
		// User clicked "Delete"
		deleteData();
	} else {
		// User clicked "Cancel"
		console.log("Action canceled");
	}
}

// iOS-style confirmation
async function confirmIOS() {
	const confirmed = await showCtConfirmCupertino(
		"Confirm Action",
		"Are you sure you want to proceed?",
		"Yes",
		"No"
	);
}

Component API

ct-dialog

The base dialog component that all other dialogs build upon.

Functions

FunctionDescriptionParametersReturns
showCtDialog()Opens a dialog with the provided element as contentelement: HTMLElement, id?: string, history?: ConectateHistoryCtDialog
closeCtDialog()Closes a specific dialog or all dialogsdialog?: CtDialogPromise<void>

Properties

PropertyTypeDefaultDescription
typestring"alert"Animation type for the dialog
interactiveDismissDisabledbooleanfalsePrevents closing by clicking outside
rolestring"alert"ARIA role for the dialog

Methods

MethodDescriptionParameters
show()Shows the dialog-
close()Closes the dialogevent?: Event, source?: string
setAnimation()Sets the animation typetype: string
fullscreenMode()Makes the dialog fullscreen-
fullsizeMode()Makes the dialog 80% of window size-
enableHistoryAPI()Enables or disables browser history integrationvalue: boolean

ct-card-dialog

A card-styled dialog component.

Functions

FunctionDescriptionParametersReturns
showCtCardDialog()Opens a card-styled dialogelement: HTMLElement, id?: string, history?: ConectateHistoryCtDialog

ct-loading

A loading dialog with a spinner.

Functions

FunctionDescriptionParametersReturns
showCtLoading()Shows a loading dialogid?: string, text?: stringCtDialog
showCtLoading2()Shows a loading dialog and returns the componentid?: string, text?: stringCtLoading

Properties

PropertyTypeDefaultDescription
ttlstring"Loading"Text to display next to the spinner

ct-promp

A dialog with an input field for user input.

Functions

FunctionDescriptionParametersReturns
showCtPrompt()Shows a prompt dialogtitle: string, body: string\|TemplateResult, ok?: string, cancel?: string, neutral?: string, options?: PromptOptionsPromise<string\|undefined>

Options

OptionTypeDefaultDescription
wordwrapbooleanfalseWhether to wrap text in the body
valuestring-Initial value for the input
labelstring-Label for the input
placeholderstring-Placeholder text
rawplaceholderstring-Raw placeholder text

ct-confirm

A confirmation dialog with customizable buttons.

Functions

FunctionDescriptionParametersReturns
showCtConfirm()Shows a standard confirmation dialogtitle: string, body: string, ok?: string, cancel?: string, neutral?: string, options?: { history?: boolean }Promise<boolean\|null\|undefined>
showCtConfirmCupertino()Shows an iOS-styled confirmation dialogtitle: string, body: string, ok?: string, cancel?: string, neutral?: stringPromise<boolean\|null\|undefined>

Return Values

ValueDescription
trueUser clicked the positive button (ok)
falseUser clicked the negative button (cancel)
nullUser clicked the neutral button
undefinedDialog was dismissed in another way

Dialog Types

The ct-dialog component supports different animation and display styles:

TypeDescription
alertStandard modal dialog (default)
cupertinoiOS-style dialog animation
slide-rightDialog slides in from the right
slide-leftDialog slides in from the left
bottom-sheetDialog slides up from the bottom
const dialog = showCtDialog(content);
dialog.setAnimation('bottom-sheet');

Styling

You can customize the dialog using CSS variables:

ct-dialog {
	--ct-dialog-width: 600px; /* Dialog width */
	--ct-dialog-height: auto; /* Dialog height */
	--ct-dialog-background: white; /* Dialog background color */
	--ct-dialog-border-radius: 8px; /* Dialog border radius */
	--ct-dialog-box-shadow: 0 11px 15px -7px rgba(0, 0, 0, 0.2), 0 24px 38px 3px rgba(0, 0, 0, 0.14), 0 9px 46px 8px rgba(0, 0, 0, 0.12); /* Dialog shadow */
}

ct-card-dialog {
	--border-radius: 16px; /* Card border radius */
	--color-background: #fff; /* Card background color */
	--color-on-surface: #333; /* Card text color */
	--color-primary: #2cb5e8; /* Scrollbar color */
}

Accessibility

The dialog component supports accessibility features including:

  • ARIA roles and attributes
  • Focus management
  • Keyboard navigation (Escape to close)

Follow Me

Herberth Obregón

https://x.com/herberthobregon

https://dev.to/herberthobregon

Contributing

  1. Fork the repo
  2. Create a new branch: git checkout -b feature-branch
  3. Commit your changes: git commit -m 'Add new feature'
  4. Push to your branch: git push origin feature-branch
  5. Open a pull request!

License

See LICENSE

4.4.0

8 months ago

4.4.3

8 months ago

4.4.14

5 months ago

4.4.13

5 months ago

4.4.12

6 months ago

4.4.15

5 months ago

4.4.9

6 months ago

4.4.8

8 months ago

4.4.5

8 months ago

4.4.4

8 months ago

4.4.7

8 months ago

4.4.6

8 months ago

4.3.2

8 months ago

4.3.1

9 months ago

4.3.4

8 months ago

4.3.3

8 months ago

4.3.0

9 months ago

4.2.6

1 year ago

4.2.5

1 year ago

4.2.3

1 year ago

4.0.0

1 year ago

4.2.1

1 year ago

4.2.0

1 year ago

4.1.4

1 year ago

4.1.3

1 year ago

4.1.5

1 year ago

4.1.0

1 year ago

4.1.1

1 year ago

3.13.1

2 years ago

3.12.9

2 years ago

3.9.3

2 years ago

3.12.4

2 years ago

3.9.0

2 years ago

3.8.1

2 years ago

3.9.5

2 years ago

3.12.8

2 years ago

3.9.4

2 years ago

3.11.0

2 years ago

3.8.0

2 years ago

3.10.0

2 years ago

3.12.1

2 years ago

3.12.0

2 years ago

3.11.1

2 years ago

3.7.6

2 years ago

3.7.5

3 years ago

3.7.4

3 years ago

3.7.3

3 years ago

3.7.2

3 years ago

3.7.1

3 years ago

3.7.0

3 years ago

3.6.4

4 years ago

3.6.0

4 years ago

3.6.3

4 years ago

3.5.12

4 years ago

3.5.11

4 years ago

3.5.7

4 years ago

3.5.5

4 years ago

3.5.8

4 years ago

3.5.1

4 years ago

3.5.0

4 years ago

3.5.4

4 years ago

3.4.0

4 years ago

3.3.0

4 years ago

3.2.1

4 years ago

3.2.0

4 years ago

3.1.0

5 years ago

3.0.0

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago