@awesome-cordova-library/dialogs
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@awesome-cordova-library/dialogs

This plugin provides access to some native dialog UI elements via a global navigator.notification object.

Cordova documentation

Installation

cordova plugin add cordova-plugin-dialogs
npm i @awesome-cordova-library/dialogs

Vanilla

Declaration

class Dialogs {
  static alert(message: string, alertCallback: () => void, title?: string, buttonName?: string): void;
  static confirm(
    message: string,
    confirmCallback: (buttonIndex: number) => void,
    title?: string,
    buttonLabels?: string[],
  ): boolean | void;
  static prompt(
    message: string,
    promptCallback: (results: { buttonIndex: number; input1: string }) => void,
    title?: string,
    buttonLabels?: string[],
    defaultText?: string,
  ): string | null | undefined;
  static beep(times?: number): void;
}

Usages

import Dialogs from '@awesome-cordova-library/dialogs';

Dialogs.alert('Alert content', () => {}, 'Alert', 'OK');
Dialogs.confirm(
  'Confirm content',
  (buttonIndex) => {
    console.log('confirm buttonIndex  ' + buttonIndex);
  },
  'Confirm',
  ['OK', 'May be later', 'No'],
);
Dialogs.prompt(
  'Hello Prompt',
  (results) => {
    console.log(JSON.stringify(results));
  },
  'Prompt',
  ['OK', 'Cancel'],
  '42',
);
Dialogs.beep();

React

Declaration

const useDialogs: () => {
  alert: (message: string, alertCallback: () => void, title?: string, buttonName?: string) => void;
  confirm: (
    message: string,
    confirmCallback: (buttonIndex: number) => void,
    title?: string,
    buttonLabels?: string[],
  ) => boolean | void;
  prompt: (
    message: string,
    promptCallback: (results: { buttonIndex: number; input1: string }) => void,
    title?: string,
    buttonLabels?: string[],
    defaultText?: string,
  ) => void;
  beep: (times?: number) => void;
};

Usages

import useDialogs from '@awesome-cordova-library/dialogs/lib/react';

function App() {
  const { alert, confirm, prompt, beep } = useDialogs();

  const openDialogs = () => {
    alert('Alert content', () => {}, 'Alert', 'OK');
    const c = confirm(
      'Confirm content',
      (buttonIndex) => {
        console.log('confirm buttonIndex  ' + buttonIndex);
      },
      'Confirmer?',
      ['OK', 'May be later', 'No'],
    );
    if (c) {
      console.log('confirme');
    }
    prompt(
      'Hello Prompt',
      (results) => {
        console.log(JSON.stringify(results));
      },
      'Prompt',
      ['OK', 'Cancel'],
      '42',
    );
    beep();
  };

  return (
    <div>
      <button onClick={openDialogs}>Open Dialogs</button>
    </div>
  );
}

Install

npm i @awesome-cordova-library/dialogs

DownloadsWeekly Downloads

7

Version

1.0.0

License

SEE LICENSE IN LICENSE

Unpacked Size

14.8 kB

Total Files

7

Last publish

Collaborators

  • joazco