@conectate/ct-dialog
Version:
HTML dialog made with Web Components
153 lines (152 loc) • 4.75 kB
TypeScript
/**
@license
Copyright (c) 2020 Herberth Obregón. All rights reserved.
This code may only be used under the BSD style license found at
https://open.grupoconectate.com/LICENSE.txt The complete set of authors may be found at
https://open.grupoconectate.com/AUTHORS.txt The complete set of contributors may be
found at https://open.grupoconectate.com/CONTRIBUTORS.txt Code distributed by Herberth Obregón as
part of the Conectate Open Source Project is also subject to an additional IP rights grant
found at https://open.grupoconectate.com/PATENTS.txt
*/
import "@conectate/ct-button";
import "@conectate/ct-card";
import "@conectate/ct-input";
import "@conectate/ct-input/ct-textarea.js";
import { CtLit } from "@conectate/ct-lit";
import { TemplateResult } from "lit";
import { CtDialog } from "./ct-dialog.js";
/**
* Displays a prompt dialog with an input field and returns user input
*
* @param {string} title - Dialog title
* @param {string|TemplateResult} body - Content to display in the dialog
* @param {string} [ok="OK"] - Text for the positive button
* @param {string} [cancel="Cancel"] - Text for the negative button (will not display if not provided)
* @param {string} [neutral] - Text for the neutral button (will not display if not provided)
* @param {Object} [options] - Additional options
* @param {boolean} [options.wordwrap=false] - Whether to allow text wrapping in the body
* @param {string} [options.value] - Initial value for the input field
* @param {string} [options.label] - Label for the input field
* @param {string} [options.placeholder] - Placeholder text for the input field
* @param {string} [options.rawplaceholder] - Raw placeholder text for the input field
* @returns {Promise<string|undefined>} Promise that resolves with the input value, or undefined if canceled
*
* @example
* ```javascript
* // Basic prompt
* const name = await showCtPrompt("Enter Name", "Please enter your name:");
*
* // Prompt with custom buttons and initial value
* const email = await showCtPrompt(
* "Email Address",
* "Please provide your email:",
* "Submit",
* "Cancel",
* undefined,
* { label: "Email", placeholder: "user@example.com" }
* );
*
* if (email) {
* console.log("Email provided:", email);
* } else {
* console.log("User canceled prompt");
* }
* ```
*/
export declare function showCtPrompt(title: string, body: string | TemplateResult, ok?: string, cancel?: string, neutral?: string, options?: {
wordwrap?: boolean;
value?: string;
label?: string;
placeholder?: string;
rawplaceholder?: string;
textarea?: boolean;
}): Promise<string | undefined>;
/**
* ## `ct-promp`
* A dialog component that displays a prompt with an input field for user input.
*
* This component is typically used through the `showCtPrompt` function rather than directly.
*
* @group ct-elements
* @element ct-promp
*/
declare class CTPromp extends CtLit {
/**
* Content to display in the dialog
*/
body: string | TemplateResult;
/**
* Dialog title text
*/
ttl: string;
/**
* Text for the positive button
*/
ok: string;
/**
* Text for the neutral button (not displayed if empty)
*/
neutral?: string;
/**
* Text for the negative button (not displayed if empty)
*/
cancel?: string;
/**
* Whether to allow text wrapping in the body
*/
wordwrap: boolean;
/**
* Additional configuration options
*/
options?: {
wordwrap?: boolean;
value?: string;
label?: string;
placeholder?: string;
rawplaceholder?: string;
textarea?: boolean;
};
/**
* Reference to the buttons container
*/
$buttons: HTMLDivElement;
/**
* Reference to the neutral button
*/
$neutral: HTMLButtonElement;
/**
* Reference to the cancel button
*/
$cancel: HTMLButtonElement;
/**
* Reference to the input field
*/
$in: HTMLElementTagNameMap["ct-textarea"];
/**
* Function to reject the promise
* @private
*/
reject: (reason?: any) => void;
/**
* Function to resolve the promise
* @private
*/
solve: (param?: string | null) => void;
/**
* Reference to the dialog instance
*/
dialog: CtDialog;
static styles: import("lit").CSSResult[];
render(): TemplateResult<1>;
firstUpdated(): void;
computeBtns(ok: string, neutral?: string, cancel?: string): void;
okbtn(e: Event): Promise<void>;
cancelbtn(e: Event): Promise<void>;
onResult(): Promise<string | undefined>;
}
declare global {
interface HTMLElementTagNameMap {
"ct-promp": CTPromp;
}
}
export {};