The prompt function is a part of the @ymlluo/bs5dialog package and is exported as a module. It creates a prompt dialog box with customizable options and returns an object containing the dialog element, content, and options.
import { prompt } from '@ymlluo/bs5dialog';
const { el, content, options } = prompt('Enter your name:', {
title: 'Please enter your name',
type: 'primary',
size: 'md',
btnText: 'Submit',
icon: 'person',
iconClass: 'bi',
iconStyle: 'color: blue',
required: true,
secret: false,
onConfirm: (value) => {
console.log(`Hello, ${value}!`);
},
onCancel: () => {
console.log('Prompt dialog box was cancelled.');
}
});
const { prompt } = require('@ymlluo/bs5dialog');
const { el, content, options } = prompt('Enter your name:', {
title: 'Please enter your name',
type: 'primary',
size: 'md',
btnText: 'Submit',
icon: 'person',
iconClass: 'bi',
iconStyle: 'color: blue',
required: true,
secret: false,
onConfirm: (value) => {
console.log(`Hello, ${value}!`);
},
onCancel: () => {
console.log('Prompt dialog box was cancelled.');
}
});
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>bs5dialog Prompt Example</title>
<!-- Include Bootstrap 5 CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="../bs5dialog.css">
<script src="../bs5dialog.js"></script>
</head>
<body>
<div class="container">
<h1>bs5dialog Prompt Example</h1>
<button id="prompt-btn" class="btn btn-primary">Open Prompt Dialog</button>
</div>
<script>
const promptBtn = document.getElementById('prompt-btn');
promptBtn.addEventListener('click', () => {
const { el, content, options } = bs5dialog.prompt('Enter your name:', {
title: 'Please enter your name',
type: 'primary',
size: 'md',
btnText: 'Submit',
icon: '',
iconClass: '',
iconStyle: '',
required: true,
secret: false,
onConfirm: (value) => {
console.log(`Hello, ${value}!`);
},
onCancel: () => {
console.log('Prompt dialog box was cancelled.');
}
});
});
</script>
</body>
</html>
The prompt function takes two parameters: