From 1b5eb340cc0a93aa6ba9174733499741d0981b07 Mon Sep 17 00:00:00 2001 From: Agata Brok Date: Wed, 18 Sep 2024 15:28:37 +0200 Subject: [PATCH 01/31] mapp.ui.elements.alert method; --- lib/ui/elements/_elements.mjs | 3 + lib/ui/elements/alert.mjs | 108 ++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 lib/ui/elements/alert.mjs diff --git a/lib/ui/elements/_elements.mjs b/lib/ui/elements/_elements.mjs index 8d41c7c48..d8372a2ac 100644 --- a/lib/ui/elements/_elements.mjs +++ b/lib/ui/elements/_elements.mjs @@ -14,6 +14,7 @@ import dropdown_multi from './dropdown_multi.mjs'; import btnPanel from './btnPanel.mjs'; import legendIcon from './legendIcon.mjs'; import dialog from './dialog.mjs'; +import alert from './alert.mjs'; import helpDialog from './helpDialog.mjs'; import searchbox from './searchbox.mjs'; import slider from './slider.mjs'; @@ -35,6 +36,7 @@ UI elements object containing various UI components. @property {Function} dropdown_multi - Multi-select dropdown component. @property {Function} legendIcon - Legend icon component. @property {Function} dialog - Dialog component. +@property {Function} alert - Alert component. @property {Function} helpDialog - Help Dialog component. @property {Function} searchbox - Searchbox component. @property {Function} slider - Slider component. @@ -57,6 +59,7 @@ export default { layerStyle, legendIcon, dialog, + alert, pills, helpDialog, searchbox, diff --git a/lib/ui/elements/alert.mjs b/lib/ui/elements/alert.mjs new file mode 100644 index 000000000..c83fee8a0 --- /dev/null +++ b/lib/ui/elements/alert.mjs @@ -0,0 +1,108 @@ +/** +### mapp.ui.elements.alert() + +Exports the alert dialog method as mapp.ui.elements.alert() + +@module /ui/elements/alert +*/ + +/** +@function alert + +@description +This is an alert element to display information to the user. +It is a framework alternative way to using window.alert() browser function. + +```js +mapp.ui.elements.alert({ + text: "Drivetimes have been created." +}) +``` + +@param {Object} alert The alert configuration object. +@property {string} [alert.css_style] The CSS styles to apply to the dialog dialog. +@property {string} [alert.data_id='alert'] The data-id attribute value for the dialog. +@property {string} [alert.title] Text to display in the alert header. Defaults to 'Information'. +@property {string} [alert.text] Text to display in the alert content. +@returns {HTMLElement} alert The alert element. +*/ + +export default function alert(params) { + + params.title ??= 'Information'; + + const css = ` + dialog.alert { + margin: auto; + box-shadow: rgba(0, 0, 0, 0.15) 1.95px 1.95px 2.6px; + border: none !important; + border-radius: 2px; + min-width: 350px; + max-width: 70%; + max-height: 70%; + z-index: 1001; + user-select: none; + } + + dialog.alert::-webkit-scrollbar { + display: none; + } + + dialog.alert h4 { + padding: 0.5em 1em; + position: sticky; + top: 0; + left: 0; + z-index: 10001; + background-color: var(--color-primary); + border-bottom: solid 2px var(--color-primary-light); + color: var(--color-light) + } + + dialog.alert div { + padding: 1em; + } + + dialog.alert p { + white-space: pre; + text-align: center; + padding: 1em; + } + + dialog.alert button { + float: right; + font-size: 0.9em; + color: var(--color-primary); + z-index: 1005; + } + + dialog.alert:focus { + outline: none; + } + `; + + document.head.prepend(mapp.utils.html.node`