native-dialogs
v0.1.0
Published
Native UI components and dialogs
Downloads
3
Maintainers
Readme
Native Dialogs
Install
$ npm install native-ui
Require
const ui = require('native-ui');
Alert
ui.alert("Title", "message", "default", function(err, result) {
if (err) {
return console.error(err);
}
// Alert was closed
console.log(result);
});
The 3rd argument is the type
of the alert. There exist 3 different types:
informational
(default)critical
warning
Choose File
ui.chooseFile({
title: "Select File", // Title of dialog box
path: "/Users/mauriceconrad/Desktop", // Path to start at
multiple: true, // Multiple file-select allowed
extensions: ["txt", "json"] // Allowed extensions
}, function(err, result) {
if (err) {
return console.error(err);
}
// Return selected file
console.log(result);
});
Choose Color
ui.chooseColor(function(err, result) {
if (err) {
return console.error(err);
}
// Return RGB array [red, blue, green] of selected color
console.log(result);
});
Choose Folder
ui.chooseFolder({
title: "Select Folder", // Title of dialog box
path: "/Users/mauriceconrad/Desktop", // Path to start at
multiple: true // Multiple folder-select allowed
}, function(err, result) {
if (err) {
return console.error(err);
}
// Return selected folder
console.log(result);
});
Dialog
ui.dialog("Test Dialog", {
buttons: ["Btn A", "Btn B", "Btn C"], // List of buttons (maximum 3)
default: 0 // Index of default button
}, "Input text", function(err, result) {
if (err) {
return console.error(err);
}
// Return pressed button and (if existing entered text)
console.log(result);
});
Important
The 2rd argument, the input text value is not needed. Set it to null
to hide the input field.
List
ui.list("Meine Liste", {
items: [
"Item 1",
"Item 2",
"Item 3",
"Item 4",
"Item 5",
"Item 6",
"Item 7",
"Item 8",
"Item 9"
],
active: 2, // Default selected item of list
okBtn: "Okay", // Label of "Okay" button
cancelBtn: "Cancel" // Label of "Cancel" button
}, function(err, result) {
if (err) {
return console.error(err);
}
// Print selected item
console.log(result);
});
Save File
ui.saveFile({
title: "Save your file", // Title of save dialog
path: "/Users/mauriceconrad" // Path to start at
}, function(err, result) {
if (err) {
return console.error(err);
}
// Print path to save file to
console.log(result);
});