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,1006 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
TextField - v26.11
|
|
6
|
+
|
|
7
|
+
UI COMPONENT TEMPLATE
|
|
8
|
+
- You can customize, this template code as you need:
|
|
9
|
+
- NEW PROJECTS: use the default styleName "light" on a light page and "dark" on a dark page (the
|
|
10
|
+
look of 02-comp-examples/text-field-8-light-dark.htm), unless the user asks for another one. The fields made from TextField
|
|
11
|
+
(EmailField, PhoneField, PasswordField, UrlField, NumberField, CurrencyField, TextAreaField) take the same
|
|
12
|
+
packages: give them the same styleName. The default is light; the pages made before name modern.
|
|
13
|
+
- comp/tooltip.js, loaded before this file, shows the hint of the warning ball in a bubble; without it the ball
|
|
14
|
+
has no bubble.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
Started Date: July 2025
|
|
18
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
19
|
+
|
|
20
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
21
|
+
Licensed under the Apache License, Version 2.0
|
|
22
|
+
SPDX-License-Identifier: Apache-2.0
|
|
23
|
+
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/*
|
|
27
|
+
|
|
28
|
+
- .status
|
|
29
|
+
-- 0: okay, 1: empty but required, 2: not valid
|
|
30
|
+
|
|
31
|
+
- input.applyFormattedValueToInput(value);
|
|
32
|
+
-- If you want to reformat the value override this func.
|
|
33
|
+
|
|
34
|
+
- input.isValid(value);
|
|
35
|
+
|
|
36
|
+
- input.setValue("Text"); // Set value programmatically
|
|
37
|
+
|
|
38
|
+
- input.getValue(); // Get current value
|
|
39
|
+
|
|
40
|
+
- input.setPlaceholder("Text"); // Change placeholder
|
|
41
|
+
|
|
42
|
+
- input.setTitleText("Title"); // Set title text
|
|
43
|
+
|
|
44
|
+
- input.setDescriptionText("Description"); // Add description
|
|
45
|
+
|
|
46
|
+
- input.setRequired(1); // Mark as required
|
|
47
|
+
|
|
48
|
+
- input.setMaxLength(40); // The most letters of the value
|
|
49
|
+
|
|
50
|
+
- input.setWarningText("Warning text"); // Set invalid input warning
|
|
51
|
+
|
|
52
|
+
- input.setRequiredIcon("icons/required.svg"); // Icon for required state (warningBallType: "icon")
|
|
53
|
+
|
|
54
|
+
- input.setWarningIcon("icons/warning.svg"); // Icon for invalid state (warningBallType: "icon")
|
|
55
|
+
|
|
56
|
+
- onChange(self): the user changed the text (not at create time, not by setValue()). onFocus(self), onBlur(self).
|
|
57
|
+
|
|
58
|
+
- warningBallType: "color" | "icon"
|
|
59
|
+
-- "color": Top-right colored ball (requiredColor / warningColor).
|
|
60
|
+
-- "icon": Top-right icon (requiredIconFile / warningIconFile). Empty path uses the built-in icon.
|
|
61
|
+
|
|
62
|
+
- tooltipStyle: { color, hintColor, textColor, border, borderColor, round, fontSize }
|
|
63
|
+
-- hintColor: the bubble of a button of the field (the show password button of PasswordField) when color is "".
|
|
64
|
+
-- The tooltip of the warning ball. color "": requiredColor / warningColor.
|
|
65
|
+
|
|
66
|
+
- styleName: "light" (default) | "dark" | "modern" | "modernDark" | "ozden" | "ozdenDark" | "minimal" | "minimalDark" (TextField.styles)
|
|
67
|
+
-- light / dark (_designs/text-field.htm): the light and dark look of the kit: the title over a 44 px field with one
|
|
68
|
+
thin line and round 8, the accent while typing, the marks as icons, the hint in a white (dark: gray) bubble.
|
|
69
|
+
-- modern / modernDark: the first look, a line under the field ("classic": the old name of modern).
|
|
70
|
+
-- minimal / minimalDark (_designs/minimal-theme.htm): the title over a 28 px field of a line (titlePosition "above").
|
|
71
|
+
- The sizes: titleFontSize, inputFontSize, inputHeight, fieldPadding, descriptionFontSize (the defaults: 16, 20, 40, 14, 14).
|
|
72
|
+
- titlePosition: "inside" (default: the title in the field) | "above" (the title over the field, titleGap under it).
|
|
73
|
+
"above" with titleText "": no title row, the field starts at the top (a title set later with setTitleText() is not shown).
|
|
74
|
+
- hoverBackBorderColor: the edge under the mouse ("": no change).
|
|
75
|
+
- warningBorderColor: the edge while a warning shows, not while typing ("": no change). warningBallSize, warningBallBorder:
|
|
76
|
+
the colored ball (16, 2; minimal: an 8 px dot).
|
|
77
|
+
- The children (EmailField, PhoneField, UrlField, PasswordField, TextAreaField) apply the style package before their own
|
|
78
|
+
defaults: a key the package sets (warningColor, unitStyle, rightPadding) wins over them.
|
|
79
|
+
-- The look of TextField is in flat params (backgroundColor, lineColor, titleTextColor...), not in one
|
|
80
|
+
"style" object. So its packages are packages of params (basic.js v26.10.27: a package with a
|
|
81
|
+
"style" key): any param can be in it, also an image (requiredIconFile, warningIconFile).
|
|
82
|
+
Order: your params > the package > TextFieldDefaults.
|
|
83
|
+
-- TextField({ styleName: "dark" })
|
|
84
|
+
-- TextField({ styleName: "dark", focusBackBorderColor: "#588ABE" }) // one param of the package changed
|
|
85
|
+
-- TextField.styles.myStyle = { style: {}, backgroundColor: "#FFF8E8", requiredIconFile: "icons/star.svg" };
|
|
86
|
+
(style: {} marks a package of params; without it the keys would go into params.style)
|
|
87
|
+
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
"use strict";
|
|
91
|
+
|
|
92
|
+
// Default values
|
|
93
|
+
const TextFieldDefaults = {
|
|
94
|
+
|
|
95
|
+
key: "0",
|
|
96
|
+
styleName: "light", // "light", "dark", "modern" ("classic": its old name), "modernDark", "ozden", "ozdenDark", "minimal", "minimalDark" or a name added to TextField.styles
|
|
97
|
+
type: "text",
|
|
98
|
+
width: 350,
|
|
99
|
+
height: "auto",
|
|
100
|
+
leftPadding: 20,
|
|
101
|
+
rightPadding: 60,
|
|
102
|
+
// THE SIZES (the minimal packages make them small)
|
|
103
|
+
titleFontSize: 16,
|
|
104
|
+
inputFontSize: 20,
|
|
105
|
+
inputHeight: 40, // px: the row of the text
|
|
106
|
+
fieldPadding: 14, // px: over and under the title and the text (titlePosition "inside")
|
|
107
|
+
descriptionFontSize: 14,
|
|
108
|
+
titlePosition: "inside", // "inside": the title in the field, over the text. "above": the title over the field (the field is only the row of the text). (Only at create time)
|
|
109
|
+
titleGap: 4, // px between the title and the field (titlePosition "above")
|
|
110
|
+
titleText: "INPUT NAME",
|
|
111
|
+
placeholder: "input value",
|
|
112
|
+
value: "",
|
|
113
|
+
maxLength: 30,
|
|
114
|
+
showDescription: 0,
|
|
115
|
+
descriptionText: "",
|
|
116
|
+
allowHtml: 0, // 1: titleText, descriptionText and unitText are HTML (only for your own texts)
|
|
117
|
+
|
|
118
|
+
backgroundColor: "#F6F6F6",
|
|
119
|
+
focusBackgroundColor: "#F3F4E0",
|
|
120
|
+
hoverBackgroundColor: "", // the field under the mouse (not while it is selected). "": no change
|
|
121
|
+
lineColor: "#373836",
|
|
122
|
+
focusLineColor: "#65A293",
|
|
123
|
+
backBorderColor: Black(0),
|
|
124
|
+
focusBackBorderColor: Black(0),
|
|
125
|
+
hoverBackBorderColor: "", // the edge under the mouse (not while it is selected). "": no change
|
|
126
|
+
backBorderTopRound: 2,
|
|
127
|
+
backBorderBottomRound: 0,
|
|
128
|
+
|
|
129
|
+
titleTextColor: "#555555",
|
|
130
|
+
titleBold: 0, // 1: the title in bold (opensans-bold)
|
|
131
|
+
titleLetterSpacing: "", // "": normal. Ex: "0.06em"
|
|
132
|
+
inputTextColor: "#373836",
|
|
133
|
+
inputColorScheme: "", // "": the page's. "dark": the autofill colors of the browser stay dark (on a dark field)
|
|
134
|
+
placeholderColor: "", // "": the color of the browser
|
|
135
|
+
descriptionTextColor: "#999999",
|
|
136
|
+
warningBallBorderColor: "#373836",
|
|
137
|
+
|
|
138
|
+
required: 0,
|
|
139
|
+
requiredText: "Required",
|
|
140
|
+
requiredColor: "white",
|
|
141
|
+
warningText: "Invalid value format",
|
|
142
|
+
warningColor: "#E5885E",
|
|
143
|
+
animatedWarningBall: 1,
|
|
144
|
+
|
|
145
|
+
warningBallType: "color", // "color": colored ball, "icon": icon image
|
|
146
|
+
warningBallSize: 16, // px: the colored ball (warningBallType "color")
|
|
147
|
+
warningBallBorder: 2, // px: the edge of the colored ball (warningBallBorderColor)
|
|
148
|
+
warningBorderColor: "", // the edge of the field while it shows a warning (not while typing). "": no change
|
|
149
|
+
warningIconSize: 20,
|
|
150
|
+
requiredIconFile: "", // image path or data URI. "": built-in icon
|
|
151
|
+
warningIconFile: "", // image path or data URI. "": built-in icon
|
|
152
|
+
requiredIconColor: "#373836", // built-in required icon color (built-in warning icon uses warningColor)
|
|
153
|
+
|
|
154
|
+
// The tooltip of the warning ball (required / warning text), and of the buttons of the field (the show password
|
|
155
|
+
// button of PasswordField)
|
|
156
|
+
tooltipStyle: {
|
|
157
|
+
color: "", // "": requiredColor / warningColor
|
|
158
|
+
hintColor: "white", // a button of the field has no ball: its bubble when color is ""
|
|
159
|
+
textColor: "#141414",
|
|
160
|
+
border: 1,
|
|
161
|
+
borderColor: "#141414",
|
|
162
|
+
round: 4, // the round of the hints of Form (hintRound)
|
|
163
|
+
fontSize: 14,
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
// The select inside the field (the protocol of UrlField, a TinySelect) and its open list
|
|
167
|
+
// WHY a ground a little darker than the field (in every package but minimal): it shows that there is something to
|
|
168
|
+
// choose, and the space at the start of the select sits right on it (with no ground it looked pushed in).
|
|
169
|
+
selectStyle: {
|
|
170
|
+
color: "rgba(0,0,0,0.05)",
|
|
171
|
+
round: 3,
|
|
172
|
+
spacing: 0, // px: between the select and the top and the bottom of the field (0: it fills the height of the field)
|
|
173
|
+
invertIconColor: 0, // 1: a white arrow (on a dark field)
|
|
174
|
+
listBackgroundColor: "whitesmoke",
|
|
175
|
+
listTextColor: "rgba(0, 0, 0, 0.8)",
|
|
176
|
+
listOverTextColor: "#65A293",
|
|
177
|
+
listBorderColor: "rgba(0, 0, 0, 0.6)",
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
showLeftBox: 0,
|
|
181
|
+
showRightBox: 0,
|
|
182
|
+
showUnit: 0,
|
|
183
|
+
createInput: 1,
|
|
184
|
+
unitText: "",
|
|
185
|
+
unitStyle: {
|
|
186
|
+
padding: [12, 4],
|
|
187
|
+
color: "#373836",
|
|
188
|
+
textColor: "white",
|
|
189
|
+
round: 40,
|
|
190
|
+
fontSize: 14,
|
|
191
|
+
},
|
|
192
|
+
|
|
193
|
+
onFocus: function(self) {},
|
|
194
|
+
onBlur: function(self) {},
|
|
195
|
+
onChange: function(self) {}, // the user changed the text (not at create time, not by setValue())
|
|
196
|
+
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const TextField = function(params = {}) {
|
|
200
|
+
|
|
201
|
+
// Merge style package: your params > TextField.styles[styleName] (a package of params) > TextFieldDefaults
|
|
202
|
+
basic.applyStylePackage(params, TextField.styles, TextFieldDefaults);
|
|
203
|
+
|
|
204
|
+
// Merge params:
|
|
205
|
+
mergeIntoIfMissing(params, TextFieldDefaults);
|
|
206
|
+
// WHY read here: box.height never reads "auto" (it gives the measured size)
|
|
207
|
+
const isAutoHeight = (String(params.height) === "auto");
|
|
208
|
+
|
|
209
|
+
// BOX: Component container
|
|
210
|
+
const box = startObject(params);
|
|
211
|
+
|
|
212
|
+
// *** DATA CONTROL:
|
|
213
|
+
if (box.descriptionText != "") {
|
|
214
|
+
box.showDescription = 1;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (box.showUnit == 1 || box.unitText != "") {
|
|
218
|
+
box.showUnit = 1;
|
|
219
|
+
box.showRightBox = 1;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// *** PRIVATE VARIABLES:
|
|
223
|
+
const SHOWN_BALL_SCALE = "scale(1)";
|
|
224
|
+
const HIDDEN_BALL_SCALE = "scale(0.3)"; // WHY: The ball grows from small when it is shown.
|
|
225
|
+
const WARNING_BALL_MOTION = "opacity 0.2s, transform 0.2s";
|
|
226
|
+
const OUT_OF_SCREEN_TOP = -1000;
|
|
227
|
+
const TITLE_LINE_HEIGHT = 1.35; // of the title font size (titlePosition "above": the place of the field is known)
|
|
228
|
+
const isTitleAbove = (box.titlePosition === "above");
|
|
229
|
+
// WHY: an empty title kept its row (and the gap under it) over the field; the field slid out of an "auto" box
|
|
230
|
+
const hasTitleRow = isTitleAbove && String(box.titleText) !== "";
|
|
231
|
+
const titleLineHeight = Math.round(box.titleFontSize * TITLE_LINE_HEIGHT);
|
|
232
|
+
const fieldTop = hasTitleRow ? titleLineHeight + box.titleGap : 0; // px: where the field starts
|
|
233
|
+
|
|
234
|
+
// *** PUBLIC VARIABLES:
|
|
235
|
+
|
|
236
|
+
// [var] 0: okay, 1: empty but required, 2: not valid
|
|
237
|
+
box.status = 0;
|
|
238
|
+
// [var] px: where the field starts under the title (titlePosition "above"; 0 "inside"). TextAreaField reads it.
|
|
239
|
+
box.fieldTop = fieldTop;
|
|
240
|
+
|
|
241
|
+
// *** PRIVATE FUNCTIONS:
|
|
242
|
+
|
|
243
|
+
const setText = function (label, text) {
|
|
244
|
+
const value = (text === undefined || text === null) ? "" : String(text);
|
|
245
|
+
if (box.allowHtml == 1) label.text = value;
|
|
246
|
+
else label.plainText = value;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const makeWarningBallVisible = function() {
|
|
250
|
+
// WHY: withMotion() shows the ball a moment later; a fast typing or a paste may make the value valid before it
|
|
251
|
+
if (box.status == 0) return;
|
|
252
|
+
box.warningBall.opacity = 1;
|
|
253
|
+
box.warningBall.clickable = 1;
|
|
254
|
+
box.warningBall.css.transform = SHOWN_BALL_SCALE;
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
// WHY: Only the showing is animated (hideWarningBall() turns the motion off).
|
|
258
|
+
const showWarningBall = function() {
|
|
259
|
+
if (box.animatedWarningBall == 1) {
|
|
260
|
+
box.warningBall.withMotion(makeWarningBallVisible);
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
makeWarningBallVisible();
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
const hideWarningBall = function() {
|
|
267
|
+
if (box.animatedWarningBall == 1) box.warningBall.dontMotion();
|
|
268
|
+
box.warningBall.opacity = 0;
|
|
269
|
+
box.warningBall.clickable = 0;
|
|
270
|
+
box.warningBall.css.transform = HIDDEN_BALL_SCALE;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// Built-in icons (SVG data URI): "required" (asterisk), "warning" (exclamation)
|
|
274
|
+
const createBuiltInIcon = function(kind, color) {
|
|
275
|
+
const glyph = (kind == "required")
|
|
276
|
+
? '<path d="M12 6.5v11M7.2 9.25l9.6 5.5M7.2 14.75l9.6-5.5" stroke="white" stroke-width="2.2" stroke-linecap="round"/>'
|
|
277
|
+
: '<path d="M12 6.5v7" stroke="white" stroke-width="2.6" stroke-linecap="round"/><circle cx="12" cy="17.4" r="1.5" fill="white"/>';
|
|
278
|
+
const svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><circle cx="12" cy="12" r="11" fill="' + color + '"/>' + glyph + '</svg>';
|
|
279
|
+
return "data:image/svg+xml;charset=utf-8," + encodeURIComponent(svg);
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
const getWarningIconFile = function(kind) {
|
|
283
|
+
if (kind == "required") {
|
|
284
|
+
return box.requiredIconFile || createBuiltInIcon("required", box.requiredIconColor);
|
|
285
|
+
}
|
|
286
|
+
return box.warningIconFile || createBuiltInIcon("warning", box.warningColor);
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
// kind: "required" or "warning"
|
|
290
|
+
const applyWarningBallStyle = function(kind) {
|
|
291
|
+
if (box.warningBallType != "icon") {
|
|
292
|
+
box.warningBall.color = (kind == "required") ? box.requiredColor : box.warningColor;
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
const iconFile = getWarningIconFile(kind);
|
|
296
|
+
// WHY: Loaded again only when it changed, so the icon does not flicker.
|
|
297
|
+
if (box.warningBall.icon.imageElement.getAttribute("src") != iconFile) {
|
|
298
|
+
box.warningBall.icon.load(iconFile);
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
// kind: "required" or "warning"
|
|
303
|
+
const showWarningBallOf = function(kind, hintText, ballColor) {
|
|
304
|
+
hideWarningBall();
|
|
305
|
+
applyWarningBallStyle(kind);
|
|
306
|
+
if (box.warningBall.tooltip) {
|
|
307
|
+
box.warningBall.tooltip.setHintText(hintText);
|
|
308
|
+
box.warningBall.tooltip.setLbl_color(box.tooltipStyle.color || ballColor);
|
|
309
|
+
}
|
|
310
|
+
showWarningBall();
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
const showWarning = function() {
|
|
314
|
+
// (the status first: the ball is shown only while there is a warning)
|
|
315
|
+
if (box.required && box.getValue().length === 0) {
|
|
316
|
+
box.status = 1;
|
|
317
|
+
showWarningBallOf("required", box.requiredText, box.requiredColor);
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
box.status = 2;
|
|
321
|
+
showWarningBallOf("warning", box.warningText, box.warningColor);
|
|
322
|
+
if (box.warningBorderColor) paintBackBorder();
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
const hideWarning = function() {
|
|
326
|
+
hideWarningBall();
|
|
327
|
+
box.status = 0;
|
|
328
|
+
if (box.warningBorderColor) paintBackBorder();
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
// *** PUBLIC FUNCTIONS:
|
|
332
|
+
|
|
333
|
+
// A child component formats the value here: it reads getValue() and puts it back with setValue().
|
|
334
|
+
box.applyFormattedValueToInput = function(value) {
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
box.checkIfInputIsRequiredAndEmpty = function() {
|
|
338
|
+
if (box.required && box.getValue().length === 0) {
|
|
339
|
+
showWarning();
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
hideWarning();
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
box.isValid = function() {
|
|
346
|
+
return 1;
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
// Both checks of a value (required, valid). WHY both: the required check hides the warning of any value that is
|
|
350
|
+
// not empty: an invalid e-mail got status 0 and a Form sent it.
|
|
351
|
+
// A child that overrides isValid() calls it at the end of its own init code too.
|
|
352
|
+
box.checkInputValue = function() {
|
|
353
|
+
box.checkIfInputIsRequiredAndEmpty();
|
|
354
|
+
box.showWarningIfNotValid(box.isValid());
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
box.showWarningIfNotValid = function(isValid) {
|
|
358
|
+
if (box.getValue().length === 0) return;
|
|
359
|
+
|
|
360
|
+
if (isValid) {
|
|
361
|
+
hideWarning();
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
// WHY: The open hint (window.lblHint of Tooltip) goes out of the screen; the next mousemove places it again.
|
|
365
|
+
if (window.lblHint) {
|
|
366
|
+
window.lblHint.top = OUT_OF_SCREEN_TOP;
|
|
367
|
+
}
|
|
368
|
+
showWarning();
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
// Sets the title text for the input component
|
|
372
|
+
box.setTitleText = function(titleText) {
|
|
373
|
+
box.titleText = titleText;
|
|
374
|
+
if (!box.title || typeof box.title.text === "undefined") return;
|
|
375
|
+
|
|
376
|
+
setText(box.title, titleText);
|
|
377
|
+
if (box.input) {
|
|
378
|
+
box.input.inputElement.setAttribute("aria-label", box.titleText);
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
// Sets the description below or next to the input field
|
|
383
|
+
box.setDescriptionText = function(descriptionText) {
|
|
384
|
+
box.descriptionText = descriptionText;
|
|
385
|
+
if (!box.description || typeof box.description.text === "undefined") return;
|
|
386
|
+
|
|
387
|
+
setText(box.description, descriptionText);
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
// Sets the maximum number of characters allowed in the input
|
|
391
|
+
box.setMaxLength = function(count) {
|
|
392
|
+
box.maxLength = count;
|
|
393
|
+
box.input.inputElement.maxLength = count;
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
// Sets the placeholder text for the input field
|
|
397
|
+
box.setPlaceholder = function(text) {
|
|
398
|
+
box.placeholder = text;
|
|
399
|
+
box.input.inputElement.placeholder = text;
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
// Sets the input's current value programmatically
|
|
403
|
+
box.setValue = function(value) {
|
|
404
|
+
if (value != box.input.text) {
|
|
405
|
+
box.value = value;
|
|
406
|
+
box.input.text = value;
|
|
407
|
+
box.checkIfInputIsRequiredAndEmpty();
|
|
408
|
+
box.showWarningIfNotValid(box.isValid());
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
// Returns the current value inside the input field
|
|
413
|
+
box.getValue = function() {
|
|
414
|
+
return box.input.text;
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
let isFieldFocused = 0;
|
|
418
|
+
let isFieldHover = 0;
|
|
419
|
+
|
|
420
|
+
// A selected field keeps its own color; under the mouse it takes hoverBackgroundColor
|
|
421
|
+
const getBackgroundColor = function() {
|
|
422
|
+
if (isFieldFocused) return box.focusBackgroundColor;
|
|
423
|
+
if (isFieldHover && box.hoverBackgroundColor) return box.hoverBackgroundColor;
|
|
424
|
+
return box.backgroundColor;
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
// titlePosition "above": a box of the whole component (the left / right box) covers only the field
|
|
428
|
+
const placeOverField = function(object) {
|
|
429
|
+
if (!isTitleAbove) return;
|
|
430
|
+
object.top = fieldTop;
|
|
431
|
+
object.height = isAutoHeight ? box.inputHeight : "calc(100% - " + fieldTop + "px)";
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
// The edge: selected, with a warning (warningBorderColor), under the mouse (hoverBackBorderColor), or its own
|
|
435
|
+
const getBackBorderColor = function() {
|
|
436
|
+
if (isFieldFocused) return box.focusBackBorderColor;
|
|
437
|
+
if (box.status == 2 && box.warningBorderColor) return box.warningBorderColor;
|
|
438
|
+
if (isFieldHover && box.hoverBackBorderColor) return box.hoverBackBorderColor;
|
|
439
|
+
return box.backBorderColor;
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
const paintBackBorder = function() {
|
|
443
|
+
if (box.background) box.background.borderColor = getBackBorderColor();
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
// The colors of the field while it is focused (1) or not (0): background, border and line.
|
|
447
|
+
// NOTE: A component made from TextField (PhoneField, UrlField, TextAreaField) calls this in its own focusFunc / blurFunc.
|
|
448
|
+
box.paintFocus = function(isFocused) {
|
|
449
|
+
isFieldFocused = isFocused ? 1 : 0;
|
|
450
|
+
box.background.color = getBackgroundColor();
|
|
451
|
+
paintBackBorder();
|
|
452
|
+
box.line.color = (isFocused) ? box.focusLineColor : box.lineColor;
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
// The text colors of a field element (<input> or <textarea>): inputTextColor, placeholderColor, inputColorScheme.
|
|
456
|
+
// NOTE: A component that makes its own field element (UrlField, TextAreaField) calls this for it.
|
|
457
|
+
box.applyTextColors = function(fieldElement) {
|
|
458
|
+
fieldElement.style.color = box.inputTextColor;
|
|
459
|
+
if (box.placeholderColor) TextField.setPlaceholderColor(fieldElement, box.placeholderColor);
|
|
460
|
+
if (box.inputColorScheme) fieldElement.style.colorScheme = box.inputColorScheme;
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
// Sets the background color of the input element itself
|
|
464
|
+
box.setBackgroundColor = function(color) {
|
|
465
|
+
box.backgroundColor = color;
|
|
466
|
+
box.background.color = getBackgroundColor();
|
|
467
|
+
};
|
|
468
|
+
|
|
469
|
+
// Sets the background color of the input when selected/focused
|
|
470
|
+
box.setFocusBackgroundColor = function(color) {
|
|
471
|
+
box.focusBackgroundColor = color;
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
// Sets the line color displayed under the input by default
|
|
475
|
+
box.setLineColor = function(color) {
|
|
476
|
+
box.lineColor = color;
|
|
477
|
+
box.line.color = color;
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
// Sets the underline color when input is selected/focused
|
|
481
|
+
box.setFocusLineColor = function(color) {
|
|
482
|
+
box.focusLineColor = color;
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
// Enables required field validation and sets the custom message
|
|
486
|
+
box.setRequired = function(isRequired) {
|
|
487
|
+
box.required = isRequired ? 1 : 0;
|
|
488
|
+
box.checkInputValue();
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
box.setRequiredText = function(text) {
|
|
492
|
+
box.requiredText = text;
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
// Updates the external warning text shown to the user
|
|
496
|
+
box.setWarningText = function(text) {
|
|
497
|
+
box.warningText = text;
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
// Sets the color used for displaying warning tooltips or icons
|
|
501
|
+
box.setWarningColor = function(color) {
|
|
502
|
+
box.warningColor = color;
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
// Sets the icon shown when input is required and empty (warningBallType: "icon")
|
|
506
|
+
box.setRequiredIcon = function(path) {
|
|
507
|
+
box.requiredIconFile = path;
|
|
508
|
+
if (box.warningBallType == "icon" && box.status == 1) applyWarningBallStyle("required");
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
// Sets the icon shown when input value is not valid (warningBallType: "icon")
|
|
512
|
+
box.setWarningIcon = function(path) {
|
|
513
|
+
box.warningIconFile = path;
|
|
514
|
+
if (box.warningBallType == "icon" && box.status == 2) applyWarningBallStyle("warning");
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
// Sets the unit label (e.g., KG) displayed near the input field
|
|
518
|
+
box.setUnitText = function(text) {
|
|
519
|
+
box.unitText = text;
|
|
520
|
+
if (!box.unit || typeof box.unit.text === "undefined") return;
|
|
521
|
+
|
|
522
|
+
setText(box.unit, text);
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
// *** OBJECT VIEW:
|
|
526
|
+
|
|
527
|
+
// BOX: Background
|
|
528
|
+
box.background = Box(0, 0, "100%", "100%", {
|
|
529
|
+
color: box.backgroundColor,
|
|
530
|
+
border: 1,
|
|
531
|
+
borderColor: box.backBorderColor,
|
|
532
|
+
});
|
|
533
|
+
box.background.css = {
|
|
534
|
+
borderTopRightRadius: box.backBorderTopRound + "px",
|
|
535
|
+
borderTopLeftRadius: box.backBorderTopRound + "px",
|
|
536
|
+
borderBottomRightRadius: box.backBorderBottomRound + "px",
|
|
537
|
+
borderBottomLeftRadius: box.backBorderBottomRound + "px",
|
|
538
|
+
};
|
|
539
|
+
// titlePosition "above": the background is only the field, under the title
|
|
540
|
+
if (isTitleAbove) {
|
|
541
|
+
box.background.top = fieldTop;
|
|
542
|
+
box.background.height = isAutoHeight ? box.inputHeight : "calc(100% - " + fieldTop + "px)";
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// BOX: Bottom Line
|
|
546
|
+
box.line = Box({
|
|
547
|
+
left: 0,
|
|
548
|
+
bottom: 0,
|
|
549
|
+
width: "100%",
|
|
550
|
+
height: 2,
|
|
551
|
+
color: box.lineColor,
|
|
552
|
+
});
|
|
553
|
+
if (isTitleAbove && isAutoHeight) box.line.css = { bottom: "auto", top: (fieldTop + box.inputHeight - 2) + "px" };
|
|
554
|
+
|
|
555
|
+
// GROUP: Title, input, description
|
|
556
|
+
box.inputGroup = AutoLayout({
|
|
557
|
+
flow: "vertical",
|
|
558
|
+
align: "left top",
|
|
559
|
+
height: "auto",
|
|
560
|
+
padding: isTitleAbove ? [box.leftPadding, 0, box.rightPadding, 0] : [box.leftPadding, box.fieldPadding, box.rightPadding, box.fieldPadding],
|
|
561
|
+
gap: isTitleAbove ? box.titleGap : 0,
|
|
562
|
+
});
|
|
563
|
+
that.position = "relative";
|
|
564
|
+
|
|
565
|
+
// LABEL: Title
|
|
566
|
+
box.title = Label({
|
|
567
|
+
fontSize: box.titleFontSize,
|
|
568
|
+
textColor: box.titleTextColor,
|
|
569
|
+
bold: box.titleBold,
|
|
570
|
+
});
|
|
571
|
+
setText(box.title, box.titleText);
|
|
572
|
+
if (box.titleLetterSpacing) that.css.letterSpacing = box.titleLetterSpacing;
|
|
573
|
+
// WHY: over the field the title starts at its edge, not at the text inside it
|
|
574
|
+
if (isTitleAbove) that.css = { lineHeight: titleLineHeight + "px", marginLeft: -box.leftPadding + "px", whiteSpace: "nowrap" };
|
|
575
|
+
if (isTitleAbove && !hasTitleRow) that.visible = 0;
|
|
576
|
+
|
|
577
|
+
// INPUT: Main object
|
|
578
|
+
if(box.createInput == 1) {
|
|
579
|
+
box.input = Input({
|
|
580
|
+
text: box.value,
|
|
581
|
+
minimal: 1,
|
|
582
|
+
fontSize: box.inputFontSize,
|
|
583
|
+
height: box.inputHeight,
|
|
584
|
+
color: "transparent",
|
|
585
|
+
width: "100%",
|
|
586
|
+
textColor: box.inputTextColor,
|
|
587
|
+
});
|
|
588
|
+
that.inputElement.style.padding = "0px 0px";
|
|
589
|
+
that.inputElement.placeholder = box.placeholder;
|
|
590
|
+
box.applyTextColors(that.inputElement);
|
|
591
|
+
that.inputElement.maxLength = box.maxLength;
|
|
592
|
+
that.inputElement.setAttribute("aria-label", box.titleText);
|
|
593
|
+
} else {
|
|
594
|
+
box.inputBox = Box({
|
|
595
|
+
color: "transparent",
|
|
596
|
+
height: box.inputHeight,
|
|
597
|
+
width: "100%",
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
// LABEL: Description
|
|
602
|
+
if (box.showDescription == 1) {
|
|
603
|
+
box.description = Label({
|
|
604
|
+
fontSize: box.descriptionFontSize,
|
|
605
|
+
textColor: box.descriptionTextColor,
|
|
606
|
+
});
|
|
607
|
+
setText(box.description, box.descriptionText);
|
|
608
|
+
box.description.css.fontStyle = "italic";
|
|
609
|
+
if (isTitleAbove) box.description.css = { marginLeft: -box.leftPadding + "px" };
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
endAutoLayout();
|
|
613
|
+
|
|
614
|
+
// GROUP: right box
|
|
615
|
+
if (box.showRightBox == 1) {
|
|
616
|
+
box.rightBox = AutoLayout({
|
|
617
|
+
flow: "horizontal",
|
|
618
|
+
align: "right bottom",
|
|
619
|
+
padding: [5, 7],
|
|
620
|
+
gap: 0,
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
// LABEL: Unit
|
|
624
|
+
if (box.showUnit == 1) {
|
|
625
|
+
box.unit = Label(box.unitStyle);
|
|
626
|
+
setText(box.unit, box.unitText);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
endAutoLayout();
|
|
630
|
+
placeOverField(box.rightBox);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
// GROUP: left box
|
|
634
|
+
if (box.showLeftBox == 1) {
|
|
635
|
+
box.leftBox = AutoLayout({
|
|
636
|
+
flow: "horizontal",
|
|
637
|
+
align: "left center",
|
|
638
|
+
padding: [20, isTitleAbove ? 0 : 14],
|
|
639
|
+
gap: 6,
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
endAutoLayout();
|
|
643
|
+
placeOverField(box.leftBox);
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
// BOX: Warning Ball:
|
|
647
|
+
const isIconBall = (box.warningBallType == "icon");
|
|
648
|
+
const ballSize = isIconBall ? box.warningIconSize : box.warningBallSize;
|
|
649
|
+
// WHY in the middle of the right padding over a field under its title: the ball belongs to the row of the text
|
|
650
|
+
const ballRight = isTitleAbove ? Math.round((box.rightPadding - ballSize) / 2) : 5;
|
|
651
|
+
box.warningBall = Box({
|
|
652
|
+
right: ballRight,
|
|
653
|
+
top: isTitleAbove ? fieldTop + Math.round((box.inputHeight - ballSize) / 2) : 5,
|
|
654
|
+
width: ballSize,
|
|
655
|
+
height: ballSize,
|
|
656
|
+
border: isIconBall ? 0 : box.warningBallBorder,
|
|
657
|
+
color: isIconBall ? "transparent" : box.requiredColor,
|
|
658
|
+
borderColor: box.warningBallBorderColor,
|
|
659
|
+
round: 100,
|
|
660
|
+
opacity: 0,
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
// ICON: Warning icon (only in icon mode)
|
|
664
|
+
if (isIconBall) {
|
|
665
|
+
box.warningBall.icon = Icon({
|
|
666
|
+
left: 0,
|
|
667
|
+
top: 0,
|
|
668
|
+
width: "100%",
|
|
669
|
+
height: "100%",
|
|
670
|
+
});
|
|
671
|
+
box.warningBall.add(that);
|
|
672
|
+
}
|
|
673
|
+
box.warningBall.css.transform = HIDDEN_BALL_SCALE;
|
|
674
|
+
if (box.animatedWarningBall == 1) {
|
|
675
|
+
box.warningBall.setMotion(WARNING_BALL_MOTION);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
// TOOLTIP: warningBall
|
|
679
|
+
// WHY the check: a page without comp/tooltip.js gets the ball with no bubble, not an error.
|
|
680
|
+
if (typeof Tooltip !== "undefined") {
|
|
681
|
+
box.warningBall.tooltip = Tooltip({
|
|
682
|
+
target: box.warningBall,
|
|
683
|
+
hintText: "",
|
|
684
|
+
hintPosition: "left",
|
|
685
|
+
lbl_border: box.tooltipStyle.border,
|
|
686
|
+
lbl_color: box.tooltipStyle.color || "white",
|
|
687
|
+
lbl_textColor: box.tooltipStyle.textColor,
|
|
688
|
+
lbl_borderColor: box.tooltipStyle.borderColor,
|
|
689
|
+
lbl_fontSize: box.tooltipStyle.fontSize,
|
|
690
|
+
lbl_round: box.tooltipStyle.round,
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
// *** OBJECT INIT CODE:
|
|
695
|
+
|
|
696
|
+
// Event bindings
|
|
697
|
+
if(box.createInput == 1) {
|
|
698
|
+
|
|
699
|
+
const inputElem = box.input.inputElement;
|
|
700
|
+
|
|
701
|
+
box.focusFunc = function () {
|
|
702
|
+
box.paintFocus(1);
|
|
703
|
+
box.onFocus(box);
|
|
704
|
+
}
|
|
705
|
+
inputElem.addEventListener("focus", function(){ box.focusFunc() });
|
|
706
|
+
|
|
707
|
+
box.blurFunc = function () {
|
|
708
|
+
box.paintFocus(0);
|
|
709
|
+
box.onBlur(box);
|
|
710
|
+
}
|
|
711
|
+
inputElem.addEventListener("blur", function(){ box.blurFunc() });
|
|
712
|
+
|
|
713
|
+
box.inputFunc = function () { // A child component can override it.
|
|
714
|
+
box.applyFormattedValueToInput();
|
|
715
|
+
box.checkIfInputIsRequiredAndEmpty();
|
|
716
|
+
box.showWarningIfNotValid(box.isValid());
|
|
717
|
+
box.value = inputElem.value;
|
|
718
|
+
box.onChange(box);
|
|
719
|
+
}
|
|
720
|
+
inputElem.addEventListener("input", function(){ box.inputFunc() });
|
|
721
|
+
|
|
722
|
+
box.checkInputValue();
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
// WHY on box: the field and the warning ball are one field for the user (the title gets no mouse: pointer-events none)
|
|
726
|
+
box.onHoverChange(function(self, isHover) {
|
|
727
|
+
isFieldHover = isHover ? 1 : 0;
|
|
728
|
+
box.background.color = getBackgroundColor();
|
|
729
|
+
// WHY only with hoverBackBorderColor: a page that colors the edge itself (background.borderColor) keeps it
|
|
730
|
+
if (box.hoverBackBorderColor) paintBackBorder();
|
|
731
|
+
});
|
|
732
|
+
|
|
733
|
+
return endObject(box);
|
|
734
|
+
|
|
735
|
+
};
|
|
736
|
+
|
|
737
|
+
// The color of the placeholder text: a CSS variable on the <input>, read by one CSS rule.
|
|
738
|
+
TextField.setPlaceholderColor = function(inputElement, color) {
|
|
739
|
+
basic.addCss("text-field-placeholder", ".text-field-placeholder::placeholder { color: var(--text-field-placeholder); opacity: 1; }");
|
|
740
|
+
inputElement.classList.add("text-field-placeholder");
|
|
741
|
+
inputElement.style.setProperty("--text-field-placeholder", color);
|
|
742
|
+
};
|
|
743
|
+
|
|
744
|
+
// *** STYLE PACKAGES:
|
|
745
|
+
// WHY style: {} in every package: TextField has no "style" object, its look is in flat params. A package with
|
|
746
|
+
// a "style" key is a package of params (basic.applyStylePackage, v26.10.27): its keys fill the params
|
|
747
|
+
// that were not given. Without the key they would go into params.style and change nothing.
|
|
748
|
+
TextField.styles = {
|
|
749
|
+
|
|
750
|
+
// The light look of the kit (_designs/text-field.htm), the default: the title over a 44 px white field with one
|
|
751
|
+
// thin line and round 8, no line under it; a stronger edge under the mouse, the accent while typing; the marks
|
|
752
|
+
// are icons (required: a small gray one), the hint in a white bubble.
|
|
753
|
+
light: {
|
|
754
|
+
style: {},
|
|
755
|
+
leftPadding: 15, // WHY 15 and 45: the draft has 14 and 44 inside the 1 px line of the field
|
|
756
|
+
rightPadding: 45, // the room of the mark
|
|
757
|
+
titleFontSize: 13,
|
|
758
|
+
inputFontSize: 15,
|
|
759
|
+
inputHeight: 44,
|
|
760
|
+
descriptionFontSize: 13,
|
|
761
|
+
titlePosition: "above",
|
|
762
|
+
titleGap: 6,
|
|
763
|
+
backgroundColor: "#FFFFFF",
|
|
764
|
+
focusBackgroundColor: "#FFFFFF",
|
|
765
|
+
hoverBackgroundColor: "",
|
|
766
|
+
lineColor: "transparent",
|
|
767
|
+
focusLineColor: "transparent",
|
|
768
|
+
backBorderColor: Black(0.12),
|
|
769
|
+
focusBackBorderColor: "#3D7A6B", // the accent of the kit
|
|
770
|
+
hoverBackBorderColor: Black(0.3),
|
|
771
|
+
backBorderTopRound: 8,
|
|
772
|
+
backBorderBottomRound: 8,
|
|
773
|
+
titleTextColor: Black(0.65),
|
|
774
|
+
titleBold: 1,
|
|
775
|
+
inputTextColor: Black(0.88),
|
|
776
|
+
placeholderColor: Black(0.38),
|
|
777
|
+
descriptionTextColor: Black(0.55),
|
|
778
|
+
warningBallType: "icon",
|
|
779
|
+
warningIconSize: 20,
|
|
780
|
+
eyeIconSize: 24, // PasswordField: the eye as wide as the marks (its picture is 20 px wide at 24)
|
|
781
|
+
warningColor: "#E5885E",
|
|
782
|
+
warningBorderColor: "#E5885E",
|
|
783
|
+
requiredIconColor: Black(0.35),
|
|
784
|
+
tooltipStyle: { color: "#FFFFFF", hintColor: "#FFFFFF", textColor: Black(0.88), border: 1, borderColor: Black(0.15), round: 6, fontSize: 13 },
|
|
785
|
+
unitStyle: { padding: [10, 3], color: "#F2F3F0", textColor: Black(0.7), round: 6, fontSize: 13 },
|
|
786
|
+
// WHY spacing: the select is a chip on the field; the white of the field shows over and under it
|
|
787
|
+
selectStyle: { color: Black(0.04), round: 6, spacing: 6, invertIconColor: 0, listBackgroundColor: "#FFFFFF", listTextColor: Black(0.88), listOverTextColor: "#3D7A6B", listBorderColor: Black(0.12) },
|
|
788
|
+
},
|
|
789
|
+
|
|
790
|
+
// The dark look of the kit: the same shapes on the dark surface.
|
|
791
|
+
dark: {
|
|
792
|
+
style: {},
|
|
793
|
+
leftPadding: 15, // WHY 15 and 45: the draft has 14 and 44 inside the 1 px line of the field
|
|
794
|
+
rightPadding: 45, // the room of the mark
|
|
795
|
+
titleFontSize: 13,
|
|
796
|
+
inputFontSize: 15,
|
|
797
|
+
inputHeight: 44,
|
|
798
|
+
descriptionFontSize: 13,
|
|
799
|
+
titlePosition: "above",
|
|
800
|
+
titleGap: 6,
|
|
801
|
+
backgroundColor: "#232322",
|
|
802
|
+
focusBackgroundColor: "#232322",
|
|
803
|
+
hoverBackgroundColor: "",
|
|
804
|
+
lineColor: "transparent",
|
|
805
|
+
focusLineColor: "transparent",
|
|
806
|
+
backBorderColor: White(0.12),
|
|
807
|
+
focusBackBorderColor: "#65A293", // the accent of the kit on a dark page
|
|
808
|
+
hoverBackBorderColor: White(0.32),
|
|
809
|
+
backBorderTopRound: 8,
|
|
810
|
+
backBorderBottomRound: 8,
|
|
811
|
+
titleTextColor: White(0.65),
|
|
812
|
+
titleBold: 1,
|
|
813
|
+
inputTextColor: White(0.9),
|
|
814
|
+
inputColorScheme: "dark",
|
|
815
|
+
placeholderColor: White(0.35),
|
|
816
|
+
descriptionTextColor: White(0.5),
|
|
817
|
+
warningBallType: "icon",
|
|
818
|
+
warningIconSize: 20,
|
|
819
|
+
eyeIconSize: 24, // PasswordField: the eye as wide as the marks (its picture is 20 px wide at 24)
|
|
820
|
+
warningColor: "#F0A07A",
|
|
821
|
+
warningBorderColor: "#F0A07A",
|
|
822
|
+
requiredIconColor: White(0.35),
|
|
823
|
+
tooltipStyle: { color: "#2C2C2B", hintColor: "#2C2C2B", textColor: White(0.9), border: 1, borderColor: White(0.2), round: 6, fontSize: 13 },
|
|
824
|
+
unitStyle: { padding: [10, 3], color: White(0.1), textColor: White(0.85), round: 6, fontSize: 13 },
|
|
825
|
+
selectStyle: { color: White(0.06), round: 6, spacing: 6, invertIconColor: 1, listBackgroundColor: "#2C2C2B", listTextColor: White(0.9), listOverTextColor: "#65A293", listBorderColor: White(0.12) },
|
|
826
|
+
},
|
|
827
|
+
|
|
828
|
+
// The first look (TextFieldDefaults): a light field with a line under it.
|
|
829
|
+
modern: { style: {} },
|
|
830
|
+
|
|
831
|
+
// The dark theme of modern: the same shape (a line under the field, no border, the warning as a colored
|
|
832
|
+
// ball), each color of modern turned to its dark side. (The rounded, bordered dark fields are ozdenDark.)
|
|
833
|
+
modernDark: {
|
|
834
|
+
style: {},
|
|
835
|
+
backgroundColor: "#232322", // modern #F6F6F6
|
|
836
|
+
focusBackgroundColor: "#2A2C27", // modern #F3F4E0: the same soft green tint, on dark
|
|
837
|
+
lineColor: White(0.75), // modern #373836: the strong line under the field
|
|
838
|
+
focusLineColor: "#65A293", // the same accent
|
|
839
|
+
backBorderColor: Black(0),
|
|
840
|
+
focusBackBorderColor: Black(0),
|
|
841
|
+
|
|
842
|
+
titleTextColor: White(0.6), // modern #555555
|
|
843
|
+
inputTextColor: White(0.9), // modern #373836
|
|
844
|
+
placeholderColor: White(0.3),
|
|
845
|
+
descriptionTextColor: White(0.4), // modern #999999
|
|
846
|
+
warningBallBorderColor: White(0.75), // modern #373836: the color of the line
|
|
847
|
+
|
|
848
|
+
requiredColor: "#141414", // modern white: the ball takes the color of the page under it
|
|
849
|
+
requiredIconColor: White(0.75), // modern #373836
|
|
850
|
+
warningColor: "indianred", // modern #E5885E
|
|
851
|
+
|
|
852
|
+
tooltipStyle: {
|
|
853
|
+
hintColor: "#262624", // the show password button: a dark bubble
|
|
854
|
+
textColor: White(0.9), // modern #141414 on a white ball
|
|
855
|
+
borderColor: White(0.75), // modern #141414
|
|
856
|
+
},
|
|
857
|
+
|
|
858
|
+
unitStyle: {
|
|
859
|
+
color: White(0.85), // modern #373836: a light pill on the dark field
|
|
860
|
+
textColor: "#1A1A19", // modern white
|
|
861
|
+
},
|
|
862
|
+
|
|
863
|
+
selectStyle: {
|
|
864
|
+
color: White(0.06), // modern rgba(0,0,0,0.05)
|
|
865
|
+
invertIconColor: 1,
|
|
866
|
+
listBackgroundColor: "#232322",
|
|
867
|
+
listTextColor: White(0.85),
|
|
868
|
+
listBorderColor: White(0.12),
|
|
869
|
+
},
|
|
870
|
+
},
|
|
871
|
+
|
|
872
|
+
// A gray rounded field,
|
|
873
|
+
// no line, a soft dark border on focus, the warning shown as an icon.
|
|
874
|
+
ozden: {
|
|
875
|
+
style: {},
|
|
876
|
+
backgroundColor: "#F6F6F6",
|
|
877
|
+
focusBackgroundColor: "#FFFFFF", // F6F6F6
|
|
878
|
+
hoverBackgroundColor: "#F6F6F6", // a little darker under the mouse EFEFEF
|
|
879
|
+
lineColor: Black(0),
|
|
880
|
+
focusLineColor: Black(0),
|
|
881
|
+
backBorderColor: Black(0.05), // a faint edge
|
|
882
|
+
focusBackBorderColor: Black(0.4),
|
|
883
|
+
backBorderTopRound: 8,
|
|
884
|
+
backBorderBottomRound: 8,
|
|
885
|
+
titleBold: 1, // as ozdenDark
|
|
886
|
+
warningBallType: "icon",
|
|
887
|
+
warningColor: "#E5885E", // E5885E, F1C74A
|
|
888
|
+
|
|
889
|
+
tooltipStyle: {
|
|
890
|
+
round: 6, // as ozdenDark
|
|
891
|
+
},
|
|
892
|
+
|
|
893
|
+
unitStyle: {
|
|
894
|
+
color: "#373836EE", // the count of the message (TextAreaField)
|
|
895
|
+
textColor: "white",
|
|
896
|
+
},
|
|
897
|
+
},
|
|
898
|
+
|
|
899
|
+
// A see-through field. The popups and the edge of the warning ball are the black of the kit (the dark cards
|
|
900
|
+
// #1A1A19); the focus line is white.
|
|
901
|
+
ozdenDark: {
|
|
902
|
+
style: {},
|
|
903
|
+
backgroundColor: "rgba(255, 255, 255, 0.04)", // FIELD_BG
|
|
904
|
+
focusBackgroundColor: "rgba(255, 255, 255, 0.07)", // FIELD_BG_SELECTED
|
|
905
|
+
hoverBackgroundColor: "rgba(255, 255, 255, 0.04)", // a little lighter under the mouse
|
|
906
|
+
lineColor: Black(0),
|
|
907
|
+
focusLineColor: Black(0),
|
|
908
|
+
backBorderColor: "rgba(255, 255, 255, 0.10)", // FIELD_LINE
|
|
909
|
+
focusBackBorderColor: White(0.45), // the focus line: a white one
|
|
910
|
+
backBorderTopRound: 10,
|
|
911
|
+
backBorderBottomRound: 10,
|
|
912
|
+
|
|
913
|
+
titleTextColor: "rgba(255, 255, 255, 0.62)", // SITE.ON_DARK_SOFT
|
|
914
|
+
titleBold: 1, // SITE.BOLD
|
|
915
|
+
titleLetterSpacing: "0.06em",
|
|
916
|
+
inputTextColor: "rgba(255, 255, 255, 0.94)", // SITE.ON_DARK
|
|
917
|
+
inputColorScheme: "dark",
|
|
918
|
+
placeholderColor: "rgba(255, 255, 255, 0.35)", // SITE.ON_DARK_FAINT (the site leaves it to the browser)
|
|
919
|
+
descriptionTextColor: "rgba(255, 255, 255, 0.35)", // SITE.ON_DARK_FAINT
|
|
920
|
+
warningBallBorderColor: "#1A1A19", // the page under the field: a dark card of the kit
|
|
921
|
+
|
|
922
|
+
warningBallType: "icon",
|
|
923
|
+
warningColor: "#E5885E", // SITE.ACCENT
|
|
924
|
+
requiredIconColor: "rgba(255, 255, 255, 0.28)",
|
|
925
|
+
|
|
926
|
+
tooltipStyle: {
|
|
927
|
+
color: "#262624", // a popup: a little lighter than the dark card #1A1A19
|
|
928
|
+
textColor: "rgba(255, 255, 255, 0.94)", // SITE.ON_DARK
|
|
929
|
+
borderColor: "rgba(255, 255, 255, 0.22)", // FIELD_LINE_HOVER
|
|
930
|
+
round: 6,
|
|
931
|
+
},
|
|
932
|
+
|
|
933
|
+
unitStyle: {
|
|
934
|
+
color: "rgba(255, 255, 255, 0.07)", // FIELD_BG_SELECTED
|
|
935
|
+
textColor: "rgba(255, 255, 255, 0.94)", // SITE.ON_DARK
|
|
936
|
+
},
|
|
937
|
+
|
|
938
|
+
selectStyle: {
|
|
939
|
+
color: "rgba(255, 255, 255, 0.07)", // FIELD_BG_SELECTED
|
|
940
|
+
invertIconColor: 1,
|
|
941
|
+
listBackgroundColor: "#262624", // as the tooltip
|
|
942
|
+
listTextColor: "rgba(255, 255, 255, 0.94)", // SITE.ON_DARK
|
|
943
|
+
listBorderColor: "rgba(255, 255, 255, 0.22)", // FIELD_LINE_HOVER
|
|
944
|
+
},
|
|
945
|
+
},
|
|
946
|
+
|
|
947
|
+
};
|
|
948
|
+
TextField.styles.classic = TextField.styles.modern; // the old name of modern: the pages made with it keep their look
|
|
949
|
+
|
|
950
|
+
// The minimal theme (_designs/minimal-theme.htm): the title (12 px) over the field, a 28 px field of a line with a
|
|
951
|
+
// 13 px text, no fill; the line gets darker under the mouse and turns ink while typing. minimalDark: the same on a
|
|
952
|
+
// dark window. (EmailField, PasswordField, TextAreaField... take them too.)
|
|
953
|
+
TextField.createMinimalStyle = function (colors) {
|
|
954
|
+
return {
|
|
955
|
+
style: {},
|
|
956
|
+
leftPadding: 10,
|
|
957
|
+
rightPadding: 26, // WHY: the room of the warning dot
|
|
958
|
+
titleFontSize: 12,
|
|
959
|
+
inputFontSize: 13,
|
|
960
|
+
inputHeight: 28,
|
|
961
|
+
fieldPadding: 0,
|
|
962
|
+
descriptionFontSize: 12,
|
|
963
|
+
titlePosition: "above",
|
|
964
|
+
titleGap: 4,
|
|
965
|
+
backgroundColor: "transparent",
|
|
966
|
+
focusBackgroundColor: "transparent",
|
|
967
|
+
hoverBackgroundColor: "",
|
|
968
|
+
lineColor: "transparent",
|
|
969
|
+
focusLineColor: "transparent",
|
|
970
|
+
backBorderColor: colors.edge, // WHY edge: the line that shows the field (3:1 at least, as WCAG asks of a control)
|
|
971
|
+
focusBackBorderColor: colors.ink,
|
|
972
|
+
hoverBackBorderColor: colors.edgeHover,
|
|
973
|
+
backBorderTopRound: 4,
|
|
974
|
+
backBorderBottomRound: 4,
|
|
975
|
+
titleTextColor: colors.softText,
|
|
976
|
+
titleBold: 0,
|
|
977
|
+
inputTextColor: colors.text,
|
|
978
|
+
inputColorScheme: colors.colorScheme,
|
|
979
|
+
placeholderColor: colors.faintText,
|
|
980
|
+
descriptionTextColor: colors.softText,
|
|
981
|
+
requiredColor: colors.faintText, // a small gray dot: the field is required
|
|
982
|
+
warningBallBorderColor: "transparent",
|
|
983
|
+
warningColor: colors.danger, // a small dot in the danger color, and the edge of the field in it
|
|
984
|
+
warningBorderColor: colors.danger,
|
|
985
|
+
warningBallType: "color",
|
|
986
|
+
warningBallSize: 8,
|
|
987
|
+
warningBallBorder: 0,
|
|
988
|
+
requiredIconColor: colors.softText,
|
|
989
|
+
tooltipStyle: { color: colors.ground, hintColor: colors.ground, textColor: colors.text, border: 1, borderColor: colors.line, round: 4, fontSize: 12 },
|
|
990
|
+
selectStyle: { color: "transparent", invertIconColor: colors.invertIcons, listBackgroundColor: colors.ground, listTextColor: colors.text, listOverTextColor: colors.ink, listBorderColor: colors.line },
|
|
991
|
+
invertIconColor: colors.invertIcons,
|
|
992
|
+
unitStyle: { padding: [6, 1], color: "transparent", textColor: colors.softText, round: 4, fontSize: 11 },
|
|
993
|
+
// TextAreaField: a thin scroll bar in the color of the text, with no dots
|
|
994
|
+
scrollBarStyle: { bar_color: colors.scrollBar, bar_mouseOverColor: colors.scrollBar, bar_width: 3, bar_mouseOverWidth: 4, bar_opacity: 0.45, bar_mouseOverOpacity: 0.9, bar_padding: 2, showDots: 0 },
|
|
995
|
+
};
|
|
996
|
+
};
|
|
997
|
+
TextField.MINIMAL_COLORS = {
|
|
998
|
+
ground: "#FFFFFF", text: Black(0.85), softText: Black(0.55), faintText: Black(0.54), line: Black(0.2),
|
|
999
|
+
lineHover: Black(0.45), edge: Black(0.45), edgeHover: Black(0.65), ink: "#1F1F1F", danger: "#C24A36", colorScheme: "", invertIcons: 0, scrollBar: "#373836",
|
|
1000
|
+
};
|
|
1001
|
+
TextField.styles.minimal = TextField.createMinimalStyle(TextField.MINIMAL_COLORS);
|
|
1002
|
+
TextField.MINIMAL_DARK_COLORS = {
|
|
1003
|
+
ground: "#1A1A19", text: White(0.88), softText: White(0.55), faintText: White(0.48), line: White(0.18),
|
|
1004
|
+
lineHover: White(0.42), edge: White(0.42), edgeHover: White(0.62), ink: "#EDEDEB", danger: "#FF9F93", colorScheme: "dark", invertIcons: 1, scrollBar: "#CFCFCD",
|
|
1005
|
+
};
|
|
1006
|
+
TextField.styles.minimalDark = TextField.createMinimalStyle(TextField.MINIMAL_DARK_COLORS);
|