ozdenui 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +14 -0
- data/NOTICE +5 -0
- data/README.md +242 -0
- data/exe/ozdenui +17 -0
- data/lib/ozdenui/AGENTS.md +210 -0
- data/lib/ozdenui/COMPONENTS.md +3017 -0
- data/lib/ozdenui/app.rb +749 -0
- data/lib/ozdenui/command.rb +107 -0
- data/lib/ozdenui/components.rb +368 -0
- data/lib/ozdenui/dialogs.rb +212 -0
- data/lib/ozdenui/files.rb +124 -0
- data/lib/ozdenui/icon.png +0 -0
- data/lib/ozdenui/kit.json +1 -0
- data/lib/ozdenui/kit.rb +115 -0
- data/lib/ozdenui/look.rb +229 -0
- data/lib/ozdenui/objects.rb +652 -0
- data/lib/ozdenui/server.rb +270 -0
- data/lib/ozdenui/values.rb +273 -0
- data/lib/ozdenui/version.rb +15 -0
- data/lib/ozdenui/web/basic/LICENSE +14 -0
- data/lib/ozdenui/web/basic/basic.min.css +1 -0
- data/lib/ozdenui/web/basic/basic.min.js +78 -0
- data/lib/ozdenui/web/basic/font/open-sans/LICENSE.txt +206 -0
- data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Bold.ttf +0 -0
- data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Regular.ttf +0 -0
- data/lib/ozdenui/web/basic/scroll-bar.min.js +3 -0
- data/lib/ozdenui/web/bridge.js +584 -0
- data/lib/ozdenui/web/comp/accordion.js +659 -0
- data/lib/ozdenui/web/comp/action-button/add.png +0 -0
- data/lib/ozdenui/web/comp/action-button.js +521 -0
- data/lib/ozdenui/web/comp/action-tab-bar.js +383 -0
- data/lib/ozdenui/web/comp/app-bar.js +237 -0
- data/lib/ozdenui/web/comp/badge.js +292 -0
- data/lib/ozdenui/web/comp/bottom-bar.js +555 -0
- data/lib/ozdenui/web/comp/breadcrumbs.js +524 -0
- data/lib/ozdenui/web/comp/canvas.js +652 -0
- data/lib/ozdenui/web/comp/chat-view.js +827 -0
- data/lib/ozdenui/web/comp/check-box.js +490 -0
- data/lib/ozdenui/web/comp/code-editor.js +965 -0
- data/lib/ozdenui/web/comp/color-picker.js +636 -0
- data/lib/ozdenui/web/comp/context-menu.js +951 -0
- data/lib/ozdenui/web/comp/currency-field.js +209 -0
- data/lib/ozdenui/web/comp/data-table/arrow.svg +2 -0
- data/lib/ozdenui/web/comp/data-table.js +937 -0
- data/lib/ozdenui/web/comp/date-picker.js +1055 -0
- data/lib/ozdenui/web/comp/dialog.js +992 -0
- data/lib/ozdenui/web/comp/email-field.js +65 -0
- data/lib/ozdenui/web/comp/file-picker.js +920 -0
- data/lib/ozdenui/web/comp/filters.js +807 -0
- data/lib/ozdenui/web/comp/form.js +602 -0
- data/lib/ozdenui/web/comp/full-screen-select/arrow.svg +2 -0
- data/lib/ozdenui/web/comp/full-screen-select/cancel.svg +2 -0
- data/lib/ozdenui/web/comp/full-screen-select.js +614 -0
- data/lib/ozdenui/web/comp/gauge.js +439 -0
- data/lib/ozdenui/web/comp/graph-box.js +3911 -0
- data/lib/ozdenui/web/comp/grid-group.js +185 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button/trash-red.png +0 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button/trash.png +0 -0
- data/lib/ozdenui/web/comp/hold-to-confirm-button.js +289 -0
- data/lib/ozdenui/web/comp/image-view.js +598 -0
- data/lib/ozdenui/web/comp/item-list.js +1740 -0
- data/lib/ozdenui/web/comp/json-editor.js +3221 -0
- data/lib/ozdenui/web/comp/json-view.js +597 -0
- data/lib/ozdenui/web/comp/label-editor.js +1140 -0
- data/lib/ozdenui/web/comp/left-menu/data-table.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/home.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/reports.png +0 -0
- data/lib/ozdenui/web/comp/left-menu/setting.png +0 -0
- data/lib/ozdenui/web/comp/left-menu.js +548 -0
- data/lib/ozdenui/web/comp/line-progress-bar.js +343 -0
- data/lib/ozdenui/web/comp/loading-screen.js +413 -0
- data/lib/ozdenui/web/comp/log-view.js +530 -0
- data/lib/ozdenui/web/comp/login-page.js +685 -0
- data/lib/ozdenui/web/comp/markdown-view.js +1045 -0
- data/lib/ozdenui/web/comp/menu-bar.js +624 -0
- data/lib/ozdenui/web/comp/mini-graph-box.js +492 -0
- data/lib/ozdenui/web/comp/minimal-accent.js +208 -0
- data/lib/ozdenui/web/comp/notice.js +229 -0
- data/lib/ozdenui/web/comp/number-field.js +128 -0
- data/lib/ozdenui/web/comp/numeric-keyboard.js +298 -0
- data/lib/ozdenui/web/comp/page-control.js +762 -0
- data/lib/ozdenui/web/comp/page-header.js +191 -0
- data/lib/ozdenui/web/comp/password-field/hide-btn.png +0 -0
- data/lib/ozdenui/web/comp/password-field/hide-btn2.png +0 -0
- data/lib/ozdenui/web/comp/password-field/show-btn.png +0 -0
- data/lib/ozdenui/web/comp/password-field/show-btn2.png +0 -0
- data/lib/ozdenui/web/comp/password-field.js +192 -0
- data/lib/ozdenui/web/comp/period-bar.js +436 -0
- data/lib/ozdenui/web/comp/phone-field.js +322 -0
- data/lib/ozdenui/web/comp/progress-bar.js +992 -0
- data/lib/ozdenui/web/comp/property-panel.js +3639 -0
- data/lib/ozdenui/web/comp/radio-button.js +527 -0
- data/lib/ozdenui/web/comp/range-slider.js +569 -0
- data/lib/ozdenui/web/comp/rich-text-editor.js +1064 -0
- data/lib/ozdenui/web/comp/scroll-area.js +308 -0
- data/lib/ozdenui/web/comp/scrolling-text.js +297 -0
- data/lib/ozdenui/web/comp/search-input/clear-round.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/clear.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/filter.png +0 -0
- data/lib/ozdenui/web/comp/search-input/filter.svg +1 -0
- data/lib/ozdenui/web/comp/search-input/search.svg +1 -0
- data/lib/ozdenui/web/comp/search-input.js +725 -0
- data/lib/ozdenui/web/comp/search-results.js +596 -0
- data/lib/ozdenui/web/comp/select-box.js +1862 -0
- data/lib/ozdenui/web/comp/settings-row.js +299 -0
- data/lib/ozdenui/web/comp/side-panel.js +616 -0
- data/lib/ozdenui/web/comp/slider-field.js +952 -0
- data/lib/ozdenui/web/comp/slider.js +838 -0
- data/lib/ozdenui/web/comp/smart-button/alert-black.png +0 -0
- data/lib/ozdenui/web/comp/smart-button/clock.png +0 -0
- data/lib/ozdenui/web/comp/smart-button.js +981 -0
- data/lib/ozdenui/web/comp/smart-table/clock.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/down.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/scroll.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/sort.png +0 -0
- data/lib/ozdenui/web/comp/smart-table/up.png +0 -0
- data/lib/ozdenui/web/comp/smart-table.js +1883 -0
- data/lib/ozdenui/web/comp/sortable-list.js +1181 -0
- data/lib/ozdenui/web/comp/spark-line-box.js +738 -0
- data/lib/ozdenui/web/comp/splitter.js +411 -0
- data/lib/ozdenui/web/comp/status-bar.js +408 -0
- data/lib/ozdenui/web/comp/step-bar.js +345 -0
- data/lib/ozdenui/web/comp/stepper.js +753 -0
- data/lib/ozdenui/web/comp/tabs.js +1366 -0
- data/lib/ozdenui/web/comp/tag-input.js +1107 -0
- data/lib/ozdenui/web/comp/tap-effect.js +170 -0
- data/lib/ozdenui/web/comp/text-area-field.js +233 -0
- data/lib/ozdenui/web/comp/text-field.js +1006 -0
- data/lib/ozdenui/web/comp/time-line.js +398 -0
- data/lib/ozdenui/web/comp/time-picker.js +1032 -0
- data/lib/ozdenui/web/comp/tiny-select/arrow.svg +1 -0
- data/lib/ozdenui/web/comp/tiny-select.js +322 -0
- data/lib/ozdenui/web/comp/tiny-table.js +283 -0
- data/lib/ozdenui/web/comp/toast.js +891 -0
- data/lib/ozdenui/web/comp/toggle.js +757 -0
- data/lib/ozdenui/web/comp/tool-bar.js +760 -0
- data/lib/ozdenui/web/comp/tooltip.js +534 -0
- data/lib/ozdenui/web/comp/tree-view.js +1179 -0
- data/lib/ozdenui/web/comp/ui-effects.js +1097 -0
- data/lib/ozdenui/web/comp/ui-standards.js +403 -0
- data/lib/ozdenui/web/comp/url-field.js +190 -0
- data/lib/ozdenui/web/comp/web-view.js +588 -0
- data/lib/ozdenui/web/components.js +123 -0
- data/lib/ozdenui/web/index.html +39 -0
- data/lib/ozdenui/window.rb +188 -0
- data/lib/ozdenui/window_cocoa.rb +221 -0
- data/lib/ozdenui.rb +32 -0
- metadata +200 -0
|
@@ -0,0 +1,992 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
Dialog - v26.10
|
|
6
|
+
|
|
7
|
+
A dialog window over the page: a title, a message, your fields (inputs) or any content, and buttons. The page under
|
|
8
|
+
it waits (a modal dialog: a dark cover, the keyboard stays in the dialog).
|
|
9
|
+
NOTE: still in development: more style packages come; their buttons may be animated.
|
|
10
|
+
|
|
11
|
+
- Buttons (SmartButton, load it first): [{ text, type, key, iconFile, align, ask, ariaLabel, onClick }]
|
|
12
|
+
- type: "primary" (the main action), "secondary" (Cancel), "danger" (a delete), "warning", "success", "info"
|
|
13
|
+
(the tones of SmartButton: cyan, orange, yellow, green, blue), "icon" (only an icon: a white square).
|
|
14
|
+
- align: "left": at the left side of the footer (Ex: the trash); the others stay at the right side.
|
|
15
|
+
- ask: "Click again to delete." -> two clicks: the first one turns the button orange and shows the text in a bubble
|
|
16
|
+
over it; the second one runs onClick. It forgets after 5 s. (The ask of SmartButton.)
|
|
17
|
+
- onClick(dialog, button) returns false: the dialog stays open. A Promise: the button waits (its clock), the
|
|
18
|
+
others are disabled, and the dialog closes when it ends (a rejected one keeps it open).
|
|
19
|
+
- Fields: fields: [{ key, titleText, placeholder, value, required, validate(value) -> error text }] make TextField
|
|
20
|
+
fields (comp/text-field.js, load it with comp/tooltip.js; without it a plain Input). A "primary" button checks
|
|
21
|
+
them first: an error is written under the message and the field gets the focus. getValues() -> { key: value }.
|
|
22
|
+
- content(dialog): any objects in the body (under the message).
|
|
23
|
+
- setStatus(text, type): a line under the content: "error" (red), "success" (green) or "info" (gray).
|
|
24
|
+
- Closes with a button, Escape, a click on the cover (closeOnCover) or close(). onClose(self, reason, buttonKey).
|
|
25
|
+
- Keyboard: Tab stays in the dialog; the first field (else the primary button) gets the focus; the focus goes back to
|
|
26
|
+
the opener when it closes. More than one dialog: Escape closes the top one.
|
|
27
|
+
- Dialog.confirm(), Dialog.alert(), Dialog.prompt(): Promises.
|
|
28
|
+
- variant: "centered": the title and the message in the middle, the buttons one under the other
|
|
29
|
+
(as wide as the card; the primary / danger one first, on the gray band of the footer) and an icon at the top
|
|
30
|
+
(topIconFile: a file or an "<svg" text: dark in a light gray circle). The look: style.centered.
|
|
31
|
+
topIconTone: "cyan", "orange", "yellow", "green" or "blue" (the tones of SmartButton) puts
|
|
32
|
+
the icon in three tones of it (Dialog.ICON_TONES): a light circle, and in an "<svg" text the words LIGHT and STRONG
|
|
33
|
+
are filled in with a light and a strong tone (a two-tone icon; currentColor is the strong tone). "": gray.
|
|
34
|
+
CIRCLE in it is the color of the circle: a ring that cuts a part out (Ex: around the dot of a new mail).
|
|
35
|
+
- Motion: the cover comes from nothing and the card rises 50 px while it comes (0.2 s); it goes at once; none with reduced motion.
|
|
36
|
+
- Style packages: "ozden" (default), "ozdenDark" (for a dark page; Dialog.confirm / alert / prompt take styleName too),
|
|
37
|
+
"minimal", "minimalDark" (_designs/minimal-theme.htm: a card with a line, no shadow, the minimal buttons and fields).
|
|
38
|
+
(Dialog.styles)
|
|
39
|
+
- The buttons: style.buttons[type] = { styleName, tone, style }: a template of SmartButton
|
|
40
|
+
("ozden"; Cancel and icon: "ozden3", a faint edge), a tone of it
|
|
41
|
+
(primary: "cyan", danger: "orange"...; icon: "white") and only the keys that differ.
|
|
42
|
+
- Scale: scale multiplies every size of the dialog (its style, width, motion, its buttons and the bubble
|
|
43
|
+
of their ask). null (default): basic.uiScale (1; a page fitted with page.fit() sets 1 / page.zoom: the dialog keeps
|
|
44
|
+
its size on the screen). Dialog.confirm / alert / prompt take it too. The objects of content(dialog) are made by
|
|
45
|
+
the page: dialog.scale is their scale. (The TextField fields keep their own px: TextField has no scale param yet.)
|
|
46
|
+
|
|
47
|
+
USAGE:
|
|
48
|
+
Dialog({
|
|
49
|
+
titleText: "Publish the article?",
|
|
50
|
+
messageText: "Your article will be seen by everyone on the blog.",
|
|
51
|
+
fields: [{ key: "title", titleText: "ARTICLE TITLE", placeholder: "How I started to garden", required: 1 }],
|
|
52
|
+
buttons: [
|
|
53
|
+
{ key: "delete", type: "icon", align: "left", iconFile: TRASH_ICON, ariaLabel: "Delete the draft", ask: "Click again to delete the draft.", onClick: deleteDraft },
|
|
54
|
+
{ key: "cancel", text: "Cancel", type: "secondary" },
|
|
55
|
+
{ key: "publish", text: "Publish", type: "primary", iconFile: PEN_ICON, onClick: function (dialog) { return publish(dialog.getValues()); } },
|
|
56
|
+
],
|
|
57
|
+
onClose: function (self, reason, buttonKey) { },
|
|
58
|
+
});
|
|
59
|
+
if (await Dialog.confirm({ titleText: "Delete the file?", messageText: "It can not be undone.", confirmText: "Delete", danger: 1 })) { }
|
|
60
|
+
const name = await Dialog.prompt({ titleText: "Rename", value: "report.pdf", validate: (text) => (text.trim()) ? "" : "A name is needed." });
|
|
61
|
+
Dialog.alert({ titleText: "Saved", scale: 1.5 }); // every size x 1.5 (default: basic.uiScale)
|
|
62
|
+
|
|
63
|
+
Started Date: October 2026
|
|
64
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
65
|
+
|
|
66
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
67
|
+
Licensed under the Apache License, Version 2.0
|
|
68
|
+
SPDX-License-Identifier: Apache-2.0
|
|
69
|
+
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
"use strict";
|
|
73
|
+
|
|
74
|
+
// Default values:
|
|
75
|
+
const DialogDefaults = {
|
|
76
|
+
key: "0",
|
|
77
|
+
width: 460, // the card (a number); a small screen: as wide as the screen
|
|
78
|
+
titleText: "",
|
|
79
|
+
messageText: "",
|
|
80
|
+
allowHtml: 0, // 1: the title and the message are HTML (only for your own texts)
|
|
81
|
+
fields: [], // [{ key, titleText, placeholder, value, required, validate }]
|
|
82
|
+
content: null, // function (dialog) {}: objects in the body
|
|
83
|
+
buttons: [], // [{ text, type, key, iconFile, align, ask, ariaLabel, onClick }]
|
|
84
|
+
closeOnCover: 1, // a click on the cover closes it
|
|
85
|
+
closeOnEscape: 1,
|
|
86
|
+
autoOpen: 1,
|
|
87
|
+
removeOnClose: 1, // 0: close() only hides it; open() shows it again
|
|
88
|
+
ariaLabel: "", // when there is no title
|
|
89
|
+
variant: "", // "": the buttons in a row at the bottom; "centered": the texts in the middle, the buttons one under the other
|
|
90
|
+
topIconFile: "", // "centered": the icon at the top (a file, or an "<svg" text drawn with currentColor or LIGHT / STRONG)
|
|
91
|
+
topIconTone: "", // "centered": "cyan", "orange", "yellow", "green", "blue": the circle and the icon in its tones; "": gray
|
|
92
|
+
scale: null, // every size multiplied (Ex: 1.5). null: basic.uiScale (1 / page.zoom on a page fitted with page.fit())
|
|
93
|
+
onOpen: function (self) { },
|
|
94
|
+
onClose: function (self, reason, buttonKey) { }, // reason: "button", "escape", "cover", "api"
|
|
95
|
+
styleName: "ozden", // "ozden", "ozdenDark", "minimal", "minimalDark" or a name added to Dialog.styles
|
|
96
|
+
style: { // The ozden style package (default): the first dialog of smart-button-3-ozden.htm
|
|
97
|
+
cover: { color: Black(0.8), zIndex: 4000 },
|
|
98
|
+
card: {
|
|
99
|
+
color: "white",
|
|
100
|
+
round: 8,
|
|
101
|
+
border: 2,
|
|
102
|
+
borderColor: "#232323",
|
|
103
|
+
boxShadow: "0 10px 30px rgba(0, 0, 0, 0.08), inset 0 -3px 0 rgba(0, 0, 0, 0.06)",
|
|
104
|
+
padding: [24, 22], // the body: [left / right, top / bottom]
|
|
105
|
+
gap: 8,
|
|
106
|
+
margin: 20, // to the edges of a small screen
|
|
107
|
+
},
|
|
108
|
+
title: { fontSize: 20, textColor: "#1B1F23", fontFamily: "opensans-bold" },
|
|
109
|
+
message: { fontSize: 16, textColor: Black(0.55), lineHeight: 1.5 },
|
|
110
|
+
// successColor ("it is saved" under the content): the green of SmartButton (#7BC362), deeper.
|
|
111
|
+
// WHY deeper: #7BC362 is 2.2:1 on white; #498335 is 4.6:1, enough for a small text
|
|
112
|
+
// errorColor: #E8796D deeper and calmer (the same hue). WHY: #E8796D is 2.8:1 on white; #C74B3D is 4.7:1
|
|
113
|
+
status: { fontSize: 13, errorColor: "#C74B3D", infoColor: Black(0.55), successColor: "#498335" },
|
|
114
|
+
footer: { color: "#FAFAF9", lineColor: Black(0.1), padding: [16, 14], gap: 10, buttonHeight: 40, iconButtonWidth: 50 },
|
|
115
|
+
fieldStyleName: "ozden", // the styleName of the TextField fields
|
|
116
|
+
// variant: "centered" (the colors of ozden)
|
|
117
|
+
centered: {
|
|
118
|
+
// A light gray circle on white, a dark icon
|
|
119
|
+
iconArea: { height: 116, color: "white", round: 6 }, // the area at the top
|
|
120
|
+
iconCircle: { size: 100, color: "#EEEEEE" },
|
|
121
|
+
icon: { size: 56, color: "#232323", lightColor: "#D2D2D0" }, // lightColor: LIGHT of a two-tone icon (no tone)
|
|
122
|
+
buttonHeight: 48,
|
|
123
|
+
buttonGap: 10,
|
|
124
|
+
// The buttons are on the band of the footer (its color and line), one under the other
|
|
125
|
+
footerPadding: [22, 18],
|
|
126
|
+
},
|
|
127
|
+
// The looks of the buttons: a template of SmartButton, a tone of it and only what differs from them. The colors
|
|
128
|
+
// of the situations are the tones of SmartButton (the draft _designs/smart-button-colors.htm)
|
|
129
|
+
buttons: {
|
|
130
|
+
primary: { styleName: "ozden", tone: "cyan", style: {} },
|
|
131
|
+
// the gray of the template, a faint edge (as the Cancel of 02-comp-examples/smart-button.htm)
|
|
132
|
+
secondary: { styleName: "ozden3", tone: "", style: {} },
|
|
133
|
+
danger: { styleName: "ozden", tone: "orange", style: {} },
|
|
134
|
+
warning: { styleName: "ozden", tone: "yellow", style: {} },
|
|
135
|
+
success: { styleName: "ozden", tone: "green", style: {} },
|
|
136
|
+
info: { styleName: "ozden", tone: "blue", style: {} },
|
|
137
|
+
// white, whitesmoke under the mouse (as the trash of the SmartButton samples). An icon button has no room at
|
|
138
|
+
// its sides by itself. A faint edge as Cancel (ozden3)
|
|
139
|
+
icon: {
|
|
140
|
+
styleName: "ozden3",
|
|
141
|
+
tone: "white",
|
|
142
|
+
style: {
|
|
143
|
+
icon: { opacity: 1 },
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
// A button that asks again (ask): its red look and its bubble (comp/tooltip.js) are the style.ask of
|
|
148
|
+
// SmartButton (its default). A page or a package may give its own here:
|
|
149
|
+
// ask: { button: { color, border, borderColor, boxShadow, textColor, iconFilter }, bubble, time }
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const Dialog = function (params = {}) {
|
|
154
|
+
|
|
155
|
+
// Merge style package: params.style > Dialog.styles[styleName] > DialogDefaults.style (ozden)
|
|
156
|
+
basic.applyStylePackage(params, Dialog.styles, DialogDefaults);
|
|
157
|
+
|
|
158
|
+
// Merge params:
|
|
159
|
+
mergeIntoIfMissing(params, DialogDefaults);
|
|
160
|
+
|
|
161
|
+
// Scale: every size of the dialog multiplied
|
|
162
|
+
params.scale = params.scale ?? basic.uiScale;
|
|
163
|
+
params.style = Dialog.scaleStyle(params.style, params.scale);
|
|
164
|
+
|
|
165
|
+
// WHY: startObject() copies params: the functions and the lists are kept as they are (copies of the lists)
|
|
166
|
+
const contentFunc = params.content;
|
|
167
|
+
const buttonList = (params.buttons || []).map(function (button, index) {
|
|
168
|
+
return Object.assign({ type: "secondary", key: "button" + index, text: "" }, button);
|
|
169
|
+
});
|
|
170
|
+
const fieldList = (params.fields || []).map(function (field, index) {
|
|
171
|
+
return Object.assign({ key: "field" + index, titleText: "", placeholder: "", value: "", required: 0 }, field);
|
|
172
|
+
});
|
|
173
|
+
delete params.content;
|
|
174
|
+
delete params.buttons;
|
|
175
|
+
delete params.fields;
|
|
176
|
+
|
|
177
|
+
// (width is the width of the card; the box itself covers the page)
|
|
178
|
+
const cardWidth = (typeof params.width === "number") ? params.width : DialogDefaults.width;
|
|
179
|
+
const cardWidthPx = cardWidth * params.scale;
|
|
180
|
+
params.left = 0;
|
|
181
|
+
params.top = 0;
|
|
182
|
+
params.width = "100%";
|
|
183
|
+
params.height = "100%";
|
|
184
|
+
|
|
185
|
+
// WHY: the dialog covers the page: it is made on page, even when Dialog() is called inside a group
|
|
186
|
+
const previousContainer = getDefaultContainerBox();
|
|
187
|
+
setDefaultContainerBox(page);
|
|
188
|
+
|
|
189
|
+
// BOX: Component container (the cover)
|
|
190
|
+
let box = startObject(params);
|
|
191
|
+
|
|
192
|
+
// *** PRIVATE VARIABLES:
|
|
193
|
+
const _s = box.style;
|
|
194
|
+
const id = "dialog-" + (Dialog.counter++);
|
|
195
|
+
const OPEN_TIME = "0.2s";
|
|
196
|
+
const OPEN_CURVE = "cubic-bezier(0.2, 0.8, 0.2, 1)"; // fast at first, soft at its place
|
|
197
|
+
const OPEN_MOVE = 50 * box.scale; // px: the card comes up from here
|
|
198
|
+
// The px of the view that are not in the style (multiplied by scale, like the style)
|
|
199
|
+
const LINE_WIDTH = 1 * box.scale; // the line over the footer
|
|
200
|
+
const SECTION_SPACE = 8 * box.scale; // over the fields, under the icon at the top
|
|
201
|
+
const FIELD_GAP = 10 * box.scale; // between the fields (and the objects of content)
|
|
202
|
+
const STATUS_MIN_HEIGHT = 18 * box.scale;
|
|
203
|
+
const INPUT_HEIGHT = 44 * box.scale; // a plain Input (without TextField)
|
|
204
|
+
const isCentered = (params.variant == "centered");
|
|
205
|
+
let isOpen = 0;
|
|
206
|
+
let isBusy = 0;
|
|
207
|
+
let busyRun = 0; // WHY: a Promise of a closed dialog must not close it after it is opened again
|
|
208
|
+
let isCoverPressed = 0; // the mouse went down on the cover (not in the card)
|
|
209
|
+
let openerElement = null; // the focus goes back here
|
|
210
|
+
|
|
211
|
+
// *** PUBLIC VARIABLES:
|
|
212
|
+
box.buttonList = []; // { data, button } (button: the SmartButton)
|
|
213
|
+
box.fieldList = []; // { data, input } (input: TextField or Input)
|
|
214
|
+
|
|
215
|
+
// *** PRIVATE FUNCTIONS:
|
|
216
|
+
|
|
217
|
+
const isReducedMotion = function () {
|
|
218
|
+
return window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const setText = function (label, text) {
|
|
222
|
+
const value = (text === undefined || text === null) ? "" : String(text);
|
|
223
|
+
if (box.allowHtml == 1) label.text = value;
|
|
224
|
+
else label.plainText = value;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
// *** FIELDS
|
|
228
|
+
|
|
229
|
+
const createField = function (field) {
|
|
230
|
+
let input;
|
|
231
|
+
if (typeof TextField !== "undefined") {
|
|
232
|
+
input = TextField({
|
|
233
|
+
styleName: _s.fieldStyleName,
|
|
234
|
+
scale: box.scale, // (taken when TextField has a scale param; its sizes are fixed px today)
|
|
235
|
+
width: "100%",
|
|
236
|
+
titleText: field.titleText,
|
|
237
|
+
placeholder: field.placeholder,
|
|
238
|
+
value: field.value,
|
|
239
|
+
required: field.required ? 1 : 0,
|
|
240
|
+
});
|
|
241
|
+
} else {
|
|
242
|
+
input = Input({ width: "100%", height: INPUT_HEIGHT, placeholder: field.placeholder || field.titleText, value: field.value });
|
|
243
|
+
}
|
|
244
|
+
input.css = { maxWidth: "100%" };
|
|
245
|
+
box.fieldList.push({ data: field, input: input });
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const getFieldValue = function (item) {
|
|
249
|
+
if (item.input.getValue) return item.input.getValue();
|
|
250
|
+
return item.input.value;
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const getFieldElement = function (item) {
|
|
254
|
+
return item.input.elem.querySelector("input, textarea") || item.input.elem;
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
// The first field with an error: its text (else "")
|
|
258
|
+
const checkFields = function () {
|
|
259
|
+
for (const item of box.fieldList) {
|
|
260
|
+
const value = getFieldValue(item);
|
|
261
|
+
let error = "";
|
|
262
|
+
if (item.data.required && String(value).trim() === "") error = (item.data.titleText || "This field") + " is needed.";
|
|
263
|
+
else if (typeof item.data.validate === "function") error = item.data.validate(value) || "";
|
|
264
|
+
if (item.input.showWarningIfNotValid) item.input.showWarningIfNotValid(!error);
|
|
265
|
+
if (error) {
|
|
266
|
+
getFieldElement(item).focus();
|
|
267
|
+
return error;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return "";
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// *** BUTTONS
|
|
274
|
+
|
|
275
|
+
const isLeftButton = function (data) {
|
|
276
|
+
return data.align == "left";
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
const getButtonWidth = function (isIcon) {
|
|
280
|
+
if (isCentered) return "100%";
|
|
281
|
+
if (isIcon) return _s.footer.iconButtonWidth;
|
|
282
|
+
return "auto";
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
// The order of the buttons: in a row, the left ones first (their margin pushes the others to the right side);
|
|
286
|
+
// one under the other, the main action first
|
|
287
|
+
const isMainButton = function (data) {
|
|
288
|
+
return Dialog.MAIN_TYPES.includes(data.type);
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const getButtonOrder = function (list) {
|
|
292
|
+
const firstOnes = list.filter(isCentered ? isMainButton : isLeftButton);
|
|
293
|
+
const otherOnes = list.filter(function (data) { return !firstOnes.includes(data); });
|
|
294
|
+
return firstOnes.concat(otherOnes);
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
// The style of a button: its look, and the ask of the dialog when it has one (else the default of SmartButton)
|
|
298
|
+
const getButtonStyle = function (look) {
|
|
299
|
+
const style = JSON.parse(JSON.stringify(look.style));
|
|
300
|
+
if (_s.ask) style.ask = _s.ask;
|
|
301
|
+
if (box.scale === 1) return style;
|
|
302
|
+
return scaleButtonStyle(style, look);
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
// WHY: SmartButton has no scale param: its whole style (the look over its template and tone) is multiplied here,
|
|
306
|
+
// and the button gets scale 1 (a SmartButton that has one must not multiply it again).
|
|
307
|
+
// The whole style has the colors of the tone: a style given in full wins over a tone.
|
|
308
|
+
const scaleButtonStyle = function (style, look) {
|
|
309
|
+
const fullStyle = SmartButton.applyLook({ styleName: look.styleName, tone: look.tone, style: style }).style;
|
|
310
|
+
const scaled = basic.scaleStyle(fullStyle, box.scale);
|
|
311
|
+
// (the sizes that are not named like one)
|
|
312
|
+
scaled.layout.iconSideTrim = fullStyle.layout.iconSideTrim * box.scale;
|
|
313
|
+
scaled.box.boxShadow = basic.scaleCssText(fullStyle.box.boxShadow, box.scale);
|
|
314
|
+
scaled.ask.button.boxShadow = basic.scaleCssText(fullStyle.ask.button.boxShadow, box.scale);
|
|
315
|
+
// the bubble of the ask: Tooltip.show() multiplies its look itself
|
|
316
|
+
scaled.ask.bubble = Object.assign({}, fullStyle.ask.bubble, { scale: box.scale });
|
|
317
|
+
return scaled;
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
const createButton = function (data) {
|
|
321
|
+
|
|
322
|
+
const isIcon = (data.type == "icon");
|
|
323
|
+
const look = _s.buttons[data.type] || _s.buttons.secondary;
|
|
324
|
+
|
|
325
|
+
const button = SmartButton({
|
|
326
|
+
styleName: look.styleName,
|
|
327
|
+
tone: look.tone || "",
|
|
328
|
+
scale: 1, // WHY: its style is in the px of the dialog already (getButtonStyle)
|
|
329
|
+
width: getButtonWidth(isIcon),
|
|
330
|
+
height: isCentered ? _s.centered.buttonHeight : _s.footer.buttonHeight,
|
|
331
|
+
labelText: isIcon ? "" : data.text,
|
|
332
|
+
ariaLabel: data.ariaLabel || data.text,
|
|
333
|
+
iconFile: data.iconFile || "",
|
|
334
|
+
style: getButtonStyle(look),
|
|
335
|
+
ask: data.ask || "",
|
|
336
|
+
onBeforeClick: function () { return canPressButton(item); },
|
|
337
|
+
onClick: function () { runButton(item); },
|
|
338
|
+
});
|
|
339
|
+
// WHY margin auto: the free room goes after the buttons of the left side, the others stay at the right side
|
|
340
|
+
if (data.align == "left" && !isCentered) button.css = { marginRight: "auto" };
|
|
341
|
+
|
|
342
|
+
const item = { data: data, button: button };
|
|
343
|
+
box.buttonList.push(item);
|
|
344
|
+
return item;
|
|
345
|
+
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
// Before the press of a button (and before its ask: the button asks "Sure?" itself, SmartButton ask)
|
|
349
|
+
const canPressButton = function (item) {
|
|
350
|
+
if (!box || isBusy) return false;
|
|
351
|
+
// WHY the fields first: a form with an error must not ask "Sure?" first
|
|
352
|
+
if (item.data.type == "primary" && box.fieldList.length) {
|
|
353
|
+
const error = checkFields();
|
|
354
|
+
box.setStatus(error, "error");
|
|
355
|
+
if (error) return false;
|
|
356
|
+
}
|
|
357
|
+
return true;
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
// The press went through (its ask too)
|
|
361
|
+
const runButton = function (item) {
|
|
362
|
+
|
|
363
|
+
let result;
|
|
364
|
+
if (typeof item.data.onClick === "function") result = item.data.onClick(box, item.data);
|
|
365
|
+
// WHY: onClick may close (or remove) the dialog itself
|
|
366
|
+
if (!box || !isOpen) return;
|
|
367
|
+
|
|
368
|
+
// A Promise: the button waits until it ends
|
|
369
|
+
if (result && typeof result.then === "function") {
|
|
370
|
+
box.setBusy(1, item.data.key);
|
|
371
|
+
const run = busyRun;
|
|
372
|
+
result.then(function (value) {
|
|
373
|
+
if (!box || run !== busyRun) return;
|
|
374
|
+
box.setBusy(0);
|
|
375
|
+
if (value !== false) box.close("button", item.data.key);
|
|
376
|
+
}, function (error) {
|
|
377
|
+
if (!box || run !== busyRun) return;
|
|
378
|
+
box.setBusy(0);
|
|
379
|
+
console.error(error); // WHY: the page shows the error (Ex: setStatus); the dialog stays open
|
|
380
|
+
});
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (result !== false) box.close("button", item.data.key);
|
|
385
|
+
|
|
386
|
+
};
|
|
387
|
+
|
|
388
|
+
// *** KEYBOARD AND SIZE
|
|
389
|
+
|
|
390
|
+
const getFocusableElements = function () {
|
|
391
|
+
const selector = "input, textarea, select, button, a[href], [tabindex]:not([tabindex='-1'])";
|
|
392
|
+
return Array.from(box.card.elem.querySelectorAll(selector)).filter(function (elem) {
|
|
393
|
+
return !elem.disabled && !elem.closest("[inert]") && elem.offsetParent !== null;
|
|
394
|
+
});
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
// The first field, else the primary button, else the card
|
|
398
|
+
const focusFirst = function () {
|
|
399
|
+
const field = box.fieldList[0];
|
|
400
|
+
const primary = box.buttonList.find(function (item) { return item.data.type == "primary"; });
|
|
401
|
+
const target = field ? getFieldElement(field) : (primary ? primary.button.elem : box.card.elem);
|
|
402
|
+
target.focus({ preventScroll: true });
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
// Tab stays in the dialog
|
|
406
|
+
const onKeyDown = function (self, event) {
|
|
407
|
+
if (!box || !isOpen || Dialog.getTop() !== box || event.key != "Tab") return;
|
|
408
|
+
const list = getFocusableElements();
|
|
409
|
+
if (list.length == 0) {
|
|
410
|
+
event.preventDefault();
|
|
411
|
+
box.card.elem.focus();
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
const first = list[0];
|
|
415
|
+
const last = list[list.length - 1];
|
|
416
|
+
const isFocusOutside = !box.card.elem.contains(document.activeElement);
|
|
417
|
+
if (event.shiftKey && (document.activeElement === first || isFocusOutside)) {
|
|
418
|
+
event.preventDefault();
|
|
419
|
+
last.focus();
|
|
420
|
+
} else if (!event.shiftKey && (document.activeElement === last || isFocusOutside)) {
|
|
421
|
+
event.preventDefault();
|
|
422
|
+
first.focus();
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
// The card is as wide as width, or as the screen (with a margin) on a small one
|
|
427
|
+
const layout = function () {
|
|
428
|
+
if (!box) return;
|
|
429
|
+
box.card.css = { width: cardWidthPx + "px", maxWidth: "calc(100% - " + (_s.card.margin * 2) + "px)" };
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
// *** PUBLIC FUNCTIONS:
|
|
433
|
+
|
|
434
|
+
box.open = function () {
|
|
435
|
+
|
|
436
|
+
if (!box || isOpen) return box;
|
|
437
|
+
isOpen = 1;
|
|
438
|
+
|
|
439
|
+
openerElement = document.activeElement;
|
|
440
|
+
Dialog.stack.push(box);
|
|
441
|
+
box.zIndex = _s.cover.zIndex + (Dialog.zCounter++) * 2; // WHY not stack.length: a dialog opened again went under an open one
|
|
442
|
+
layout();
|
|
443
|
+
box.visible = 1;
|
|
444
|
+
|
|
445
|
+
// The cover comes from nothing, the card rises 50 px while it comes (both in 0.2 s)
|
|
446
|
+
// WHY the cover color, not the opacity of the box: the card is in the box, it has its own fade.
|
|
447
|
+
if (!isReducedMotion()) {
|
|
448
|
+
box.setMotionNow("none");
|
|
449
|
+
box.card.setMotionNow("none");
|
|
450
|
+
box.color = "transparent";
|
|
451
|
+
box.card.opacity = 0;
|
|
452
|
+
box.card.css = { transform: "translateY(" + OPEN_MOVE + "px)" };
|
|
453
|
+
// WHY: the start look must be drawn before the motion is turned on
|
|
454
|
+
void box.elem.offsetHeight;
|
|
455
|
+
box.setMotionNow("background-color " + OPEN_TIME);
|
|
456
|
+
box.card.setMotionNow("opacity " + OPEN_TIME + " " + OPEN_CURVE + ", transform " + OPEN_TIME + " " + OPEN_CURVE);
|
|
457
|
+
box.color = _s.cover.color;
|
|
458
|
+
box.card.opacity = 1;
|
|
459
|
+
box.card.css = { transform: "none" };
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
focusFirst();
|
|
463
|
+
box.onOpen(box);
|
|
464
|
+
return box;
|
|
465
|
+
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
// It goes at once. reason: "button", "escape", "cover", "api"; buttonKey: the pressed button
|
|
469
|
+
box.close = function (reason = "api", buttonKey = "") {
|
|
470
|
+
|
|
471
|
+
if (!box || !isOpen) return;
|
|
472
|
+
isOpen = 0;
|
|
473
|
+
Dialog.stack = Dialog.stack.filter(function (dialog) { return dialog !== box; });
|
|
474
|
+
busyRun++;
|
|
475
|
+
if (isBusy) box.setBusy(0);
|
|
476
|
+
// WHY: an asking button must not stay red (and need one click) when the dialog is opened again
|
|
477
|
+
box.buttonList.forEach(function (item) {
|
|
478
|
+
item.button.cancelAsk();
|
|
479
|
+
});
|
|
480
|
+
const hadFocus = box.elem.contains(document.activeElement) || document.activeElement === document.body;
|
|
481
|
+
box.visible = 0;
|
|
482
|
+
|
|
483
|
+
// WHY: the focus goes back to the object that opened the dialog (keyboard users do not lose their place)
|
|
484
|
+
// WHY hadFocus: a dialog under another one must not take the focus out of the top one
|
|
485
|
+
if (hadFocus && openerElement && openerElement.isConnected && typeof openerElement.focus === "function") {
|
|
486
|
+
openerElement.focus({ preventScroll: true });
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
const self = box;
|
|
490
|
+
self.onClose(self, reason, buttonKey);
|
|
491
|
+
if (basic.isOn(self.removeOnClose)) self.remove();
|
|
492
|
+
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
box.isOpen = function () {
|
|
496
|
+
return isOpen;
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
// Busy: the button of buttonKey waits (its clock), the others are disabled
|
|
500
|
+
box.setBusy = function (busy, buttonKey = "") {
|
|
501
|
+
if (!box) return;
|
|
502
|
+
const wasBusy = isBusy;
|
|
503
|
+
isBusy = busy ? 1 : 0;
|
|
504
|
+
box.buttonList.forEach(function (item) {
|
|
505
|
+
const isTarget = isBusy && item.data.key == buttonKey;
|
|
506
|
+
// WHY: a button the page turned off (getButton(key).setEnabled(0)) stays off after the wait
|
|
507
|
+
if (isBusy && !wasBusy) item.enabledBeforeBusy = item.button.enabled;
|
|
508
|
+
item.button.setWaiting(isTarget ? 1 : 0);
|
|
509
|
+
if (isBusy) item.button.setEnabled(isTarget ? item.enabledBeforeBusy : 0);
|
|
510
|
+
else if (wasBusy) item.button.setEnabled(item.enabledBeforeBusy);
|
|
511
|
+
});
|
|
512
|
+
box.card.aria = { busy: isBusy ? "true" : "false" };
|
|
513
|
+
};
|
|
514
|
+
// USAGE: dialog.setBusy(1, "save") ... dialog.setBusy(0)
|
|
515
|
+
|
|
516
|
+
box.isBusy = function () {
|
|
517
|
+
return isBusy;
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
// A line under the message (and the fields, the content): type "error" (red), "success" (green) or "info"; "" hides it
|
|
521
|
+
box.setStatus = function (text, type = "info") {
|
|
522
|
+
const colors = { error: _s.status.errorColor, success: _s.status.successColor, info: _s.status.infoColor };
|
|
523
|
+
box.lblStatus.plainText = text || "";
|
|
524
|
+
box.lblStatus.textColor = colors[type] || _s.status.infoColor;
|
|
525
|
+
box.lblStatus.visible = text ? 1 : 0;
|
|
526
|
+
};
|
|
527
|
+
// USAGE: dialog.setStatus("Could not save.", "error") / dialog.setStatus("The title is saved.", "success")
|
|
528
|
+
|
|
529
|
+
box.setTitleText = function (text) {
|
|
530
|
+
box.titleText = text;
|
|
531
|
+
setText(box.lblTitle, text);
|
|
532
|
+
box.lblTitle.visible = text ? 1 : 0;
|
|
533
|
+
box.card.aria = { labelledby: text ? box.lblTitle.elem.id : null, label: text ? null : (box.ariaLabel || null) };
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
box.setMessageText = function (text) {
|
|
537
|
+
box.messageText = text;
|
|
538
|
+
setText(box.lblMessage, text);
|
|
539
|
+
box.lblMessage.visible = text ? 1 : 0;
|
|
540
|
+
box.card.aria = { describedby: text ? box.lblMessage.elem.id : null };
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
// { key: value } of the fields
|
|
544
|
+
box.getValues = function () {
|
|
545
|
+
const values = {};
|
|
546
|
+
box.fieldList.forEach(function (item) { values[item.data.key] = getFieldValue(item); });
|
|
547
|
+
return values;
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
box.getButton = function (key) {
|
|
551
|
+
const item = box.buttonList.find(function (b) { return b.data.key == key; });
|
|
552
|
+
return item ? item.button : null;
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
// REMOVE: the static Dialog.stack must not keep a removed dialog (the objects go with basic.js remove())
|
|
556
|
+
const superRemove = box.remove;
|
|
557
|
+
box.superRemove = superRemove;
|
|
558
|
+
box.remove = function () {
|
|
559
|
+
if (!box) return;
|
|
560
|
+
if (isOpen) {
|
|
561
|
+
const keepRemoveOnClose = box.removeOnClose;
|
|
562
|
+
box.removeOnClose = 0; // WHY: close() must not call remove() again
|
|
563
|
+
box.close("api");
|
|
564
|
+
if (!box) return; // (onClose removed it)
|
|
565
|
+
box.removeOnClose = keepRemoveOnClose;
|
|
566
|
+
}
|
|
567
|
+
Dialog.stack = Dialog.stack.filter(function (dialog) { return dialog !== box; });
|
|
568
|
+
superRemove.call(box);
|
|
569
|
+
box = null;
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
// *** OBJECT VIEW:
|
|
573
|
+
|
|
574
|
+
const textAlign = isCentered ? "center" : "left";
|
|
575
|
+
|
|
576
|
+
// A row at the bottom, on a band with a line over it
|
|
577
|
+
const createFooter = function () {
|
|
578
|
+
box.footer = HGroup({ width: "100%", height: "auto", align: "right center", gap: _s.footer.gap, padding: _s.footer.padding, color: _s.footer.color, clipContent: 0 });
|
|
579
|
+
box.footer.css = { borderTop: LINE_WIDTH + "px solid " + _s.footer.lineColor, borderRadius: "0 0 " + _s.card.round + "px " + _s.card.round + "px", flexShrink: "0" };
|
|
580
|
+
};
|
|
581
|
+
|
|
582
|
+
// One under the other, as wide as the card, on the band of the footer (a line over it)
|
|
583
|
+
const createCenteredFooter = function () {
|
|
584
|
+
box.footer = VGroup({ width: "100%", height: "auto", align: "center top", gap: _s.centered.buttonGap, padding: _s.centered.footerPadding, color: _s.footer.color, clipContent: 0 });
|
|
585
|
+
box.footer.css = { alignItems: "stretch", borderTop: LINE_WIDTH + "px solid " + _s.footer.lineColor, borderRadius: "0 0 " + _s.card.round + "px " + _s.card.round + "px", flexShrink: "0" };
|
|
586
|
+
};
|
|
587
|
+
|
|
588
|
+
// The colors of the icon at the top: three tones of topIconTone, else the gray of the style
|
|
589
|
+
const getTopIconLook = function () {
|
|
590
|
+
const tone = Dialog.ICON_TONES[box.topIconTone];
|
|
591
|
+
if (tone) return tone;
|
|
592
|
+
const _c = _s.centered;
|
|
593
|
+
return { circle: _c.iconCircle.color, light: _c.icon.lightColor, strong: _c.icon.color };
|
|
594
|
+
};
|
|
595
|
+
|
|
596
|
+
// WHY: the words LIGHT and STRONG in an "<svg" text are the places of the two colors of a two-tone icon; CIRCLE
|
|
597
|
+
// is the color of the circle behind it (a ring around a part looks cut out of the icon)
|
|
598
|
+
const fillIconColors = function (file, look) {
|
|
599
|
+
const text = String(file);
|
|
600
|
+
if (!text.trim().startsWith("<svg")) return file;
|
|
601
|
+
return text.split("LIGHT").join(look.light).split("STRONG").join(look.strong).split("CIRCLE").join(look.circle);
|
|
602
|
+
};
|
|
603
|
+
|
|
604
|
+
// The icon at the top: in a light circle (gray: a dark icon; topIconTone: the tones of SmartButton)
|
|
605
|
+
const createTopIcon = function () {
|
|
606
|
+
const _c = _s.centered;
|
|
607
|
+
const look = getTopIconLook();
|
|
608
|
+
box.iconArea = HGroup({ width: "100%", height: _c.iconArea.height, align: "center center", color: _c.iconArea.color, round: _c.iconArea.round });
|
|
609
|
+
box.iconArea.css = { flexShrink: "0", marginBottom: SECTION_SPACE + "px" };
|
|
610
|
+
HGroup({ width: _c.iconCircle.size, height: _c.iconCircle.size, align: "center center", color: look.circle, round: _c.iconCircle.size / 2 });
|
|
611
|
+
box.topIcon = createIconView(fillIconColors(box.topIconFile, look), { size: _c.icon.size, color: look.strong });
|
|
612
|
+
endGroup();
|
|
613
|
+
endGroup();
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
// WHY two ways: an "<svg" text takes the color of the style (currentColor); a file keeps its own colors
|
|
617
|
+
const createIconView = function (file, look) {
|
|
618
|
+
if (String(file).trim().startsWith("<svg")) {
|
|
619
|
+
// WHY clipContent 0 and overflow visible: a part that moves (the lid of a bin that lifts) goes out of the
|
|
620
|
+
// drawing for a moment; it was cut at the top
|
|
621
|
+
const label = Label({ width: look.size, height: look.size, text: file, textColor: look.color, clipContent: 0, css: { lineHeight: "0" } });
|
|
622
|
+
const svg = label.elem.querySelector("svg");
|
|
623
|
+
if (svg) {
|
|
624
|
+
svg.setAttribute("width", "100%");
|
|
625
|
+
svg.setAttribute("height", "100%");
|
|
626
|
+
svg.style.overflow = "visible";
|
|
627
|
+
}
|
|
628
|
+
return label;
|
|
629
|
+
}
|
|
630
|
+
const icon = Icon({ width: look.size, height: look.size });
|
|
631
|
+
icon.load(file);
|
|
632
|
+
return icon;
|
|
633
|
+
};
|
|
634
|
+
|
|
635
|
+
box.color = _s.cover.color;
|
|
636
|
+
// WHY: "absolute", not "fixed": the cover is on page, as big as page (page never scrolls). page.fit() / page.zoom give
|
|
637
|
+
// <body> a transform, and a fixed box inside a transformed one is measured on it (a 0 px high body: the
|
|
638
|
+
// dialog is not seen).
|
|
639
|
+
box.css = { position: "absolute" };
|
|
640
|
+
box.elem.style.display = "block"; // WHY: visible keeps the display type: without it, visible: 1 does not show it again
|
|
641
|
+
box.clickable = 1;
|
|
642
|
+
|
|
643
|
+
// GROUP: The card in the middle
|
|
644
|
+
box.layoutGroup = HGroup({ width: "100%", height: "100%", align: "center center", clipContent: 0 });
|
|
645
|
+
|
|
646
|
+
// GROUP: Card
|
|
647
|
+
box.card = VGroup({
|
|
648
|
+
width: cardWidthPx,
|
|
649
|
+
height: "auto",
|
|
650
|
+
align: "left top",
|
|
651
|
+
gap: 0,
|
|
652
|
+
color: _s.card.color,
|
|
653
|
+
round: _s.card.round,
|
|
654
|
+
border: _s.card.border,
|
|
655
|
+
borderColor: _s.card.borderColor,
|
|
656
|
+
boxShadow: _s.card.boxShadow,
|
|
657
|
+
clipContent: 0,
|
|
658
|
+
clickable: 1,
|
|
659
|
+
role: "dialog",
|
|
660
|
+
tabIndex: -1,
|
|
661
|
+
});
|
|
662
|
+
box.card.css = { alignItems: "stretch", maxHeight: "calc(100% - " + (_s.card.margin * 2) + "px)", outline: "none" };
|
|
663
|
+
box.card.aria = { modal: "true" };
|
|
664
|
+
|
|
665
|
+
// GROUP: Body (the title, the message, the fields, the content, the status); it scrolls when it is long
|
|
666
|
+
box.body = VGroup({ width: "100%", height: "auto", align: "left top", gap: _s.card.gap, padding: _s.card.padding, clipContent: 0 });
|
|
667
|
+
box.body.css = { alignItems: "stretch", flex: "1 1 auto", minHeight: "0px", overflowX: "hidden" };
|
|
668
|
+
box.body.scrollY = 1;
|
|
669
|
+
|
|
670
|
+
if (isCentered && box.topIconFile) createTopIcon();
|
|
671
|
+
|
|
672
|
+
// LABEL: Title
|
|
673
|
+
box.lblTitle = Label({ ..._s.title, width: "100%", textAlign: textAlign, css: { overflowWrap: "anywhere" } });
|
|
674
|
+
box.lblTitle.elem.id = id + "-title";
|
|
675
|
+
|
|
676
|
+
// LABEL: Message
|
|
677
|
+
box.lblMessage = Label({ fontSize: _s.message.fontSize, textColor: _s.message.textColor, width: "100%", textAlign: textAlign, css: { whiteSpace: "normal", lineHeight: String(_s.message.lineHeight), textWrap: "balance", overflowWrap: "anywhere" } });
|
|
678
|
+
box.lblMessage.elem.id = id + "-message";
|
|
679
|
+
|
|
680
|
+
// GROUP: Fields and content
|
|
681
|
+
if (fieldList.length || typeof contentFunc === "function") {
|
|
682
|
+
box.content = VGroup({ width: "100%", height: "auto", align: "left top", gap: FIELD_GAP, clipContent: 0 });
|
|
683
|
+
box.content.css = { alignItems: "stretch", marginTop: SECTION_SPACE + "px", flexShrink: "0" };
|
|
684
|
+
fieldList.forEach(createField);
|
|
685
|
+
if (typeof contentFunc === "function") contentFunc(box);
|
|
686
|
+
endGroup();
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
// LABEL: Status (an error of a field, a message of the page)
|
|
690
|
+
box.lblStatus = Label({ fontSize: _s.status.fontSize, bold: 1, width: "100%", textAlign: textAlign, css: { whiteSpace: "normal", minHeight: STATUS_MIN_HEIGHT + "px" } });
|
|
691
|
+
box.lblStatus.role = "status";
|
|
692
|
+
|
|
693
|
+
endGroup();
|
|
694
|
+
|
|
695
|
+
// GROUP: Footer (the buttons)
|
|
696
|
+
if (isCentered) createCenteredFooter();
|
|
697
|
+
else createFooter();
|
|
698
|
+
|
|
699
|
+
if (typeof SmartButton === "undefined") console.warn("Dialog: its buttons need comp/smart-button.js (SmartButton).");
|
|
700
|
+
else getButtonOrder(buttonList).forEach(createButton);
|
|
701
|
+
|
|
702
|
+
endGroup();
|
|
703
|
+
|
|
704
|
+
endGroup();
|
|
705
|
+
|
|
706
|
+
endGroup();
|
|
707
|
+
|
|
708
|
+
// *** OBJECT INIT CODE:
|
|
709
|
+
|
|
710
|
+
box.setTitleText(box.titleText);
|
|
711
|
+
box.setMessageText(box.messageText);
|
|
712
|
+
box.setStatus("");
|
|
713
|
+
box.footer.visible = buttonList.length ? 1 : 0;
|
|
714
|
+
|
|
715
|
+
// A click on the cover (not on the card)
|
|
716
|
+
box.layoutGroup.clickable = 1;
|
|
717
|
+
// WHY mousedown too: a text selection that starts in a field and ends on the cover gives a click on the cover
|
|
718
|
+
box.layoutGroup.on("mousedown", function (self, event) {
|
|
719
|
+
isCoverPressed = (event.target === box.layoutGroup.elem) ? 1 : 0;
|
|
720
|
+
});
|
|
721
|
+
box.layoutGroup.on("click", function (self, event) {
|
|
722
|
+
if (event.target !== box.layoutGroup.elem || !isCoverPressed) return;
|
|
723
|
+
if (basic.isOn(box.closeOnCover) && !isBusy) box.close("cover");
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
// Enter in a field presses the primary button
|
|
727
|
+
box.card.on("keydown", function (self, event) {
|
|
728
|
+
if (event.key != "Enter" || !/INPUT/.test(event.target.tagName)) return;
|
|
729
|
+
// WHY: a held Enter must not pass the ask; an IME Enter or one a component of content() used is not for us
|
|
730
|
+
if (event.repeat || event.isComposing || event.defaultPrevented) return;
|
|
731
|
+
const primary = box.buttonList.find(function (item) { return item.data.type == "primary"; });
|
|
732
|
+
if (!primary) return;
|
|
733
|
+
event.preventDefault();
|
|
734
|
+
primary.button.press(); // WHY the press of the button: its ask and its enabled state count too
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
// WHY on document: after a click on the cover the focus is on body, the box gets no keys
|
|
738
|
+
box.listenTo(document, "keydown", onKeyDown);
|
|
739
|
+
box.onPageResize(layout);
|
|
740
|
+
box.visible = 0;
|
|
741
|
+
|
|
742
|
+
endObject(box);
|
|
743
|
+
setDefaultContainerBox(previousContainer);
|
|
744
|
+
|
|
745
|
+
if (basic.isOn(box.autoOpen)) box.open();
|
|
746
|
+
|
|
747
|
+
return box;
|
|
748
|
+
|
|
749
|
+
};
|
|
750
|
+
|
|
751
|
+
// *** STATIC VARIABLES AND FUNCTIONS:
|
|
752
|
+
|
|
753
|
+
Dialog.stack = []; // The open dialogs (the last one is on top)
|
|
754
|
+
Dialog.counter = 1;
|
|
755
|
+
Dialog.zCounter = 1; // only grows
|
|
756
|
+
|
|
757
|
+
Dialog.getTop = function () {
|
|
758
|
+
return Dialog.stack[Dialog.stack.length - 1] || null;
|
|
759
|
+
};
|
|
760
|
+
|
|
761
|
+
Dialog.closeAll = function () {
|
|
762
|
+
Dialog.stack.slice().reverse().forEach(function (dialog) { dialog.close("api"); });
|
|
763
|
+
};
|
|
764
|
+
|
|
765
|
+
// WHY: one listener for every dialog: Escape closes only the top one, wherever the focus is
|
|
766
|
+
// WHY the bubble phase: a menu inside the dialog (a select, a context menu) closes first with its own Escape
|
|
767
|
+
document.addEventListener("keydown", function (event) {
|
|
768
|
+
if (event.key != "Escape" || event.defaultPrevented) return;
|
|
769
|
+
const top = Dialog.getTop();
|
|
770
|
+
if (!top) return;
|
|
771
|
+
// WHY: the focus in an object made on page over the dialog (Ex: the list of a FullScreenSelect): its Escape
|
|
772
|
+
const target = event.target;
|
|
773
|
+
const isFocusFree = (target === document.body || target === document.documentElement);
|
|
774
|
+
if (!isFocusFree && !top.elem.contains(target)) return;
|
|
775
|
+
// WHY: a modal keeps its Escape even when it does not close (closeOnEscape 0, busy): a SidePanel under it closed
|
|
776
|
+
if (!basic.isOn(top.closeOnEscape) || top.isBusy()) {
|
|
777
|
+
event.preventDefault();
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
event.preventDefault();
|
|
781
|
+
event.stopPropagation();
|
|
782
|
+
top.close("escape");
|
|
783
|
+
});
|
|
784
|
+
|
|
785
|
+
// The buttons of an action (not Cancel): placed first in the centered variant
|
|
786
|
+
Dialog.MAIN_TYPES = ["primary", "danger", "warning", "success", "info"];
|
|
787
|
+
|
|
788
|
+
// The style of a dialog with its sizes multiplied (scale 1: the same style).
|
|
789
|
+
// WHY not buttons and ask: they are styles of SmartButton, multiplied with its package when a button is made
|
|
790
|
+
Dialog.scaleStyle = function (style, scale) {
|
|
791
|
+
if (scale === 1) return style;
|
|
792
|
+
const scaled = basic.scaleStyle(style, scale);
|
|
793
|
+
scaled.buttons = style.buttons;
|
|
794
|
+
if (style.ask) scaled.ask = style.ask;
|
|
795
|
+
scaled.card.boxShadow = basic.scaleCssText(style.card.boxShadow, scale);
|
|
796
|
+
return scaled;
|
|
797
|
+
};
|
|
798
|
+
|
|
799
|
+
// Returns a Promise<boolean>. onConfirm (optional) may return false (it stays) or a Promise (the button waits).
|
|
800
|
+
Dialog.confirm = function (params = {}) {
|
|
801
|
+
return new Promise(function (resolve) {
|
|
802
|
+
let result = false;
|
|
803
|
+
Dialog({
|
|
804
|
+
titleText: params.titleText || "Are you sure?",
|
|
805
|
+
messageText: params.messageText || "",
|
|
806
|
+
styleName: params.styleName,
|
|
807
|
+
style: params.style || {},
|
|
808
|
+
variant: params.variant || "",
|
|
809
|
+
topIconFile: params.topIconFile || "",
|
|
810
|
+
topIconTone: params.topIconTone || "",
|
|
811
|
+
scale: params.scale,
|
|
812
|
+
buttons: [
|
|
813
|
+
{ key: "cancel", text: params.cancelText || "Cancel", type: "secondary" },
|
|
814
|
+
{
|
|
815
|
+
key: "confirm",
|
|
816
|
+
text: params.confirmText || "Confirm",
|
|
817
|
+
type: params.danger ? "danger" : (params.confirmType || "primary"),
|
|
818
|
+
iconFile: params.iconFile || "",
|
|
819
|
+
ask: params.ask || "",
|
|
820
|
+
onClick: function (dialog) {
|
|
821
|
+
if (typeof params.onConfirm !== "function") {
|
|
822
|
+
result = true;
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
// WHY true after the call: an onConfirm that throws leaves the dialog open, Cancel gives false
|
|
826
|
+
const value = params.onConfirm(dialog);
|
|
827
|
+
result = (value !== false);
|
|
828
|
+
if (value && typeof value.then === "function") {
|
|
829
|
+
// WHY: a Promise of false keeps the dialog open; a later Cancel must give false
|
|
830
|
+
return value.then(function (done) {
|
|
831
|
+
if (done === false) result = false;
|
|
832
|
+
return done;
|
|
833
|
+
}, function (error) { result = false; throw error; });
|
|
834
|
+
}
|
|
835
|
+
return value;
|
|
836
|
+
},
|
|
837
|
+
},
|
|
838
|
+
],
|
|
839
|
+
onClose: function () { resolve(result); },
|
|
840
|
+
});
|
|
841
|
+
});
|
|
842
|
+
};
|
|
843
|
+
// USAGE: if (await Dialog.confirm({ titleText: "Delete?", messageText: "It can not be undone.", confirmText: "Delete", danger: 1 })) { }
|
|
844
|
+
// ask: "Click again to delete." (two clicks on the confirm button), style: the style of the Dialog (Ex: the color of
|
|
845
|
+
// its button: { buttons: { danger: { style: { box: { color: "#F8E57A" } } } } })
|
|
846
|
+
// confirmType: "warning" | "success" | "info" (the confirm button in the color of a situation; danger: 1 = "danger")
|
|
847
|
+
|
|
848
|
+
// Returns a Promise (it ends when the dialog closes).
|
|
849
|
+
// USAGE: await Dialog.alert({ titleText: "Done", messageText: "All the files are uploaded.", buttonType: "success" })
|
|
850
|
+
Dialog.alert = function (params = {}) {
|
|
851
|
+
return new Promise(function (resolve) {
|
|
852
|
+
Dialog({
|
|
853
|
+
titleText: params.titleText || "",
|
|
854
|
+
messageText: params.messageText || "",
|
|
855
|
+
styleName: params.styleName,
|
|
856
|
+
style: params.style || {},
|
|
857
|
+
variant: params.variant || "",
|
|
858
|
+
topIconFile: params.topIconFile || "",
|
|
859
|
+
topIconTone: params.topIconTone || "",
|
|
860
|
+
scale: params.scale,
|
|
861
|
+
buttons: [{ key: "ok", text: params.buttonText || "OK", type: params.buttonType || "primary" }],
|
|
862
|
+
onClose: function () { resolve(); },
|
|
863
|
+
});
|
|
864
|
+
});
|
|
865
|
+
};
|
|
866
|
+
|
|
867
|
+
// Returns a Promise<string | null> (null: canceled). validate(text) returns an error text ("" when it is valid).
|
|
868
|
+
Dialog.prompt = function (params = {}) {
|
|
869
|
+
return new Promise(function (resolve) {
|
|
870
|
+
let result = null;
|
|
871
|
+
Dialog({
|
|
872
|
+
titleText: params.titleText || "",
|
|
873
|
+
messageText: params.messageText || "",
|
|
874
|
+
styleName: params.styleName,
|
|
875
|
+
style: params.style || {},
|
|
876
|
+
variant: params.variant || "",
|
|
877
|
+
topIconFile: params.topIconFile || "",
|
|
878
|
+
topIconTone: params.topIconTone || "",
|
|
879
|
+
scale: params.scale,
|
|
880
|
+
fields: [{ key: "value", titleText: params.fieldText || "", placeholder: params.placeholder || "", value: params.value || "", required: params.required ? 1 : 0, validate: params.validate }],
|
|
881
|
+
buttons: [
|
|
882
|
+
{ key: "cancel", text: params.cancelText || "Cancel", type: "secondary" },
|
|
883
|
+
{ key: "ok", text: params.confirmText || "OK", type: "primary", onClick: function (dialog) { result = dialog.getValues().value; } },
|
|
884
|
+
],
|
|
885
|
+
onClose: function () { resolve(result); },
|
|
886
|
+
});
|
|
887
|
+
});
|
|
888
|
+
};
|
|
889
|
+
// USAGE: const name = await Dialog.prompt({ titleText: "Rename", value: "a.pdf", validate: (t) => (t.trim()) ? "" : "A name is needed." })
|
|
890
|
+
|
|
891
|
+
// The tones of an icon at the top (topIconTone): the circle behind it, the LIGHT shape and the STRONG details, made
|
|
892
|
+
// from the tones of SmartButton (the icons of 02-comp-examples/dialog-centered.htm).
|
|
893
|
+
// WHY STRONG this deep: the details read on the light shape (2.6:1) and on the circle (3.6:1), a white mark on it (3.9:1)
|
|
894
|
+
Dialog.ICON_TONES = {
|
|
895
|
+
cyan: { circle: "#EAF6F7", light: "#A5D9DD", strong: "#36898F" },
|
|
896
|
+
orange: { circle: "#FBEFEA", light: "#EDBAA5", strong: "#C4532A" },
|
|
897
|
+
yellow: { circle: "#FDF8E7", light: "#F5D77D", strong: "#9A7409" },
|
|
898
|
+
green: { circle: "#EEF7EB", light: "#B6DEA9", strong: "#4A8F33" },
|
|
899
|
+
blue: { circle: "#E9F4F9", light: "#A0CFE5", strong: "#2E81A8" },
|
|
900
|
+
};
|
|
901
|
+
// USAGE: Dialog({ variant: "centered", topIconTone: "green", topIconFile: '<svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="11" fill="STRONG"/>...</svg>' })
|
|
902
|
+
|
|
903
|
+
// *** STYLE PACKAGES:
|
|
904
|
+
// USAGE: Dialog({ style: { card: { round: 12 } } }) // Change only some keys. (The width of the card is the param width.)
|
|
905
|
+
// NOTE: more packages come; a new one needs only the keys that differ from ozden.
|
|
906
|
+
Dialog.styles = {
|
|
907
|
+
ozden: DialogDefaults.style,
|
|
908
|
+
|
|
909
|
+
// For a dark page: the black tones of the kit; the fields and the buttons take their dark looks.
|
|
910
|
+
ozdenDark: {
|
|
911
|
+
cover: { color: Black(0.65) },
|
|
912
|
+
card: {
|
|
913
|
+
color: "#232322",
|
|
914
|
+
border: 1,
|
|
915
|
+
borderColor: White(0.16),
|
|
916
|
+
boxShadow: "0 10px 30px rgba(0, 0, 0, 0.45)",
|
|
917
|
+
},
|
|
918
|
+
title: { textColor: White(0.92) },
|
|
919
|
+
message: { textColor: White(0.62) },
|
|
920
|
+
// WHY these colors: the errorColor and successColor of ozden are deepened for white; on this card they are too dark.
|
|
921
|
+
status: { errorColor: "#FF9F93", infoColor: White(0.6), successColor: "#7FE3B5" },
|
|
922
|
+
footer: { color: "#1C1C1B", lineColor: White(0.1) },
|
|
923
|
+
fieldStyleName: "ozdenDark",
|
|
924
|
+
centered: {
|
|
925
|
+
iconArea: { color: "#232322" },
|
|
926
|
+
iconCircle: { color: "#32322F" },
|
|
927
|
+
icon: { color: White(0.88), lightColor: White(0.35) },
|
|
928
|
+
},
|
|
929
|
+
buttons: {
|
|
930
|
+
primary: { styleName: "ozdenDark", tone: "cyanDark", style: {} },
|
|
931
|
+
secondary: { styleName: "ozden3Dark", tone: "", style: {} },
|
|
932
|
+
danger: { styleName: "ozdenDark", tone: "orangeDark", style: {} },
|
|
933
|
+
warning: { styleName: "ozdenDark", tone: "yellowDark", style: {} },
|
|
934
|
+
success: { styleName: "ozdenDark", tone: "greenDark", style: {} },
|
|
935
|
+
info: { styleName: "ozdenDark", tone: "blueDark", style: {} },
|
|
936
|
+
icon: {
|
|
937
|
+
styleName: "ozden3Dark",
|
|
938
|
+
tone: "",
|
|
939
|
+
style: {
|
|
940
|
+
icon: { opacity: 1 },
|
|
941
|
+
},
|
|
942
|
+
},
|
|
943
|
+
},
|
|
944
|
+
},
|
|
945
|
+
};
|
|
946
|
+
|
|
947
|
+
// The minimal theme (_designs/minimal-theme.htm): a card on the ground of the window with a line and no shadow, a
|
|
948
|
+
// 14 px title, a 13 px message, the buttons at the right with no band under them: the minimal SmartButtons (the main
|
|
949
|
+
// one "ink", a delete "minimalDanger"), the minimal fields. minimalDark: the same on a dark window.
|
|
950
|
+
Dialog.createMinimalStyle = function (colors) {
|
|
951
|
+
const button = function (tone) {
|
|
952
|
+
return { styleName: colors.buttonName, tone: tone, style: {} };
|
|
953
|
+
};
|
|
954
|
+
return {
|
|
955
|
+
cover: { color: colors.cover },
|
|
956
|
+
card: { color: colors.ground, round: 6, border: 1, borderColor: colors.lineHover, boxShadow: "none", padding: [16, 16], gap: 6, margin: 16 },
|
|
957
|
+
title: { fontSize: 14, textColor: colors.text, fontFamily: "opensans-bold" },
|
|
958
|
+
message: { fontSize: 13, textColor: colors.softText, lineHeight: 1.45 },
|
|
959
|
+
status: { fontSize: 12, errorColor: colors.danger, infoColor: colors.softText, successColor: colors.success },
|
|
960
|
+
footer: { color: "transparent", lineColor: "transparent", padding: [16, 14], gap: 8, buttonHeight: 28, iconButtonWidth: 28 },
|
|
961
|
+
fieldStyleName: colors.fieldName,
|
|
962
|
+
centered: {
|
|
963
|
+
iconArea: { height: 76, color: colors.ground, round: 4 },
|
|
964
|
+
iconCircle: { size: 56, color: colors.iconCircle },
|
|
965
|
+
icon: { size: 28, color: colors.text, lightColor: colors.faintText },
|
|
966
|
+
buttonHeight: 28,
|
|
967
|
+
buttonGap: 8,
|
|
968
|
+
footerPadding: [16, 14],
|
|
969
|
+
},
|
|
970
|
+
buttons: {
|
|
971
|
+
primary: button(colors.inkTone),
|
|
972
|
+
secondary: button(""),
|
|
973
|
+
danger: { styleName: colors.dangerName, tone: "", style: {} },
|
|
974
|
+
warning: button(""),
|
|
975
|
+
success: button(""),
|
|
976
|
+
info: button(""),
|
|
977
|
+
icon: { styleName: colors.buttonName, tone: "", style: { icon: { opacity: 1 } } },
|
|
978
|
+
},
|
|
979
|
+
};
|
|
980
|
+
};
|
|
981
|
+
Dialog.MINIMAL_COLORS = {
|
|
982
|
+
cover: Black(0.3), ground: "#FFFFFF", text: Black(0.85), softText: Black(0.55), faintText: Black(0.54), lineHover: Black(0.45),
|
|
983
|
+
danger: "#C24A36", success: "#2E9E74", iconCircle: Black(0.05),
|
|
984
|
+
buttonName: "minimal", dangerName: "minimalDanger", inkTone: "ink", fieldName: "minimal",
|
|
985
|
+
};
|
|
986
|
+
Dialog.styles.minimal = Dialog.createMinimalStyle(Dialog.MINIMAL_COLORS);
|
|
987
|
+
Dialog.MINIMAL_DARK_COLORS = {
|
|
988
|
+
cover: Black(0.6), ground: "#1A1A19", text: White(0.88), softText: White(0.55), faintText: White(0.48), lineHover: White(0.42),
|
|
989
|
+
danger: "#FF9F93", success: "#7FE3B5", iconCircle: White(0.06),
|
|
990
|
+
buttonName: "minimalDark", dangerName: "minimalDangerDark", inkTone: "inkDark", fieldName: "minimalDark",
|
|
991
|
+
};
|
|
992
|
+
Dialog.styles.minimalDark = Dialog.createMinimalStyle(Dialog.MINIMAL_DARK_COLORS);
|