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,383 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
ActionTabBar - v26.11
|
|
6
|
+
|
|
7
|
+
UI COMPONENT
|
|
8
|
+
- A tab bar for the bottom of a mobile app, with a big round "+" button at its right end: the tabs (an icon over a
|
|
9
|
+
text) change the page, the "+" runs the main action of the app (Ex: add a spending).
|
|
10
|
+
- The selected tab is clear (opacity 1), the others are faded. A short line under the selected tab slides to it
|
|
11
|
+
(0.2 s). Only transform moves; no motion at the first view; none when the system asks for reduced motion.
|
|
12
|
+
- The "+" is drawn in SVG (no image file) and calls onAction. A tap on a tab selects it and calls onChange.
|
|
13
|
+
- KEYBOARD AND ACCESSIBILITY: the tabs are a tablist (role "tab", aria-selected) with one Tab stop (roving tabindex):
|
|
14
|
+
Left / Right arrows, Home, End move between them, Enter / Space select. The "+" is a button (Tab reaches it,
|
|
15
|
+
Enter / Space; its name: actionAriaLabel). A focus ring only for the keyboard.
|
|
16
|
+
- THE SIZES are px of a 600 px design (the page is fitted with page.fit(600, 800)): the tabs
|
|
17
|
+
are 130 px wide from x 30, so three tabs fit next to the "+".
|
|
18
|
+
- onChange is NOT called when the component is created or when the value is set with silent: 1.
|
|
19
|
+
- NEEDS basic.js v26.10.23 (role, aria, tabIndex, setFocusRing).
|
|
20
|
+
|
|
21
|
+
USAGE:
|
|
22
|
+
const tabBar = ActionTabBar({
|
|
23
|
+
bottom: 0,
|
|
24
|
+
items: [
|
|
25
|
+
{ key: "status", text: "STATUS", iconFile: "../assets/tab-bar/status.png" },
|
|
26
|
+
{ key: "receipts", text: "RECEIPTS", iconFile: "../assets/tab-bar/transactions.png" },
|
|
27
|
+
{ key: "tools", text: "TOOLS", iconFile: "../assets/tab-bar/settings.png" },
|
|
28
|
+
],
|
|
29
|
+
value: "status",
|
|
30
|
+
onChange: function (self) { openPage(self.value); },
|
|
31
|
+
onAction: function (self) { openNewSpending(); },
|
|
32
|
+
});
|
|
33
|
+
tabBar.setValue("tools"); // onChange is called
|
|
34
|
+
tabBar.setValue("status", 1); // silent: onChange is not called
|
|
35
|
+
tabBar.getIndex(); // 0: the index of the selected tab
|
|
36
|
+
|
|
37
|
+
Started Date: November 2026
|
|
38
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
39
|
+
|
|
40
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
41
|
+
Licensed under the Apache License, Version 2.0
|
|
42
|
+
SPDX-License-Identifier: Apache-2.0
|
|
43
|
+
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
"use strict";
|
|
47
|
+
|
|
48
|
+
// Default values:
|
|
49
|
+
const ActionTabBarDefaults = {
|
|
50
|
+
key: "0", // Your name for this object: read it in a callback (self.key)
|
|
51
|
+
width: 600,
|
|
52
|
+
height: 150,
|
|
53
|
+
items: [], // [{ key, text, iconFile }] (Only at create time)
|
|
54
|
+
value: null, // The key of the selected tab. null: the first tab
|
|
55
|
+
ariaLabel: "Tabs", // The name of the tab list for a screen reader
|
|
56
|
+
actionAriaLabel: "Add", // The name of the "+" button for a screen reader
|
|
57
|
+
onChange: function (self) { }, // self.value, self.previousValue, self.getIndex()
|
|
58
|
+
onAction: function (self) { }, // The "+" button
|
|
59
|
+
style: {
|
|
60
|
+
bar: {
|
|
61
|
+
space: 20, // From the left, the top and the right of the box
|
|
62
|
+
height: 100,
|
|
63
|
+
background: "linear-gradient(to bottom, #D8D8D8, #D8D8D800)",
|
|
64
|
+
round: 20,
|
|
65
|
+
border: 1,
|
|
66
|
+
borderColor: "#141414",
|
|
67
|
+
},
|
|
68
|
+
item: { // A tab: as high as the bar
|
|
69
|
+
left: 30, // The first tab, from the left of the box
|
|
70
|
+
width: 130,
|
|
71
|
+
gap: 5, // Between the tabs
|
|
72
|
+
round: 16, // The shape of its focus ring
|
|
73
|
+
passiveOpacity: 0.4, // A tab that is not selected
|
|
74
|
+
},
|
|
75
|
+
icon: {
|
|
76
|
+
size: 40,
|
|
77
|
+
top: 12,
|
|
78
|
+
},
|
|
79
|
+
label: {
|
|
80
|
+
bottom: 12,
|
|
81
|
+
fontSize: 23,
|
|
82
|
+
textColor: "#000000",
|
|
83
|
+
opacity: 0.6,
|
|
84
|
+
},
|
|
85
|
+
indicator: { // The line under the selected tab
|
|
86
|
+
top: 106,
|
|
87
|
+
width: 60,
|
|
88
|
+
height: 4,
|
|
89
|
+
color: "#40A5AF",
|
|
90
|
+
opacity: 0.8,
|
|
91
|
+
round: 4,
|
|
92
|
+
motionTime: 0.2, // s: it slides to the selected tab. 0: no motion
|
|
93
|
+
ease: "ease",
|
|
94
|
+
},
|
|
95
|
+
action: { // The round "+" button
|
|
96
|
+
top: 10,
|
|
97
|
+
right: 35,
|
|
98
|
+
size: 120,
|
|
99
|
+
color: "#FFFFFF",
|
|
100
|
+
border: 2,
|
|
101
|
+
borderColor: "#141414",
|
|
102
|
+
round: 100,
|
|
103
|
+
iconSize: 48,
|
|
104
|
+
iconColor: "#000000",
|
|
105
|
+
iconLine: 2.35, // On a 24 px grid
|
|
106
|
+
iconOpacity: 0.65,
|
|
107
|
+
},
|
|
108
|
+
focus: {
|
|
109
|
+
ringColor: "rgba(64, 165, 175, 0.9)", // The ring of the keyboard focus (a tab, the "+")
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const ActionTabBar = function (params = {}) {
|
|
115
|
+
|
|
116
|
+
// Merge params:
|
|
117
|
+
mergeIntoIfMissing(params, ActionTabBarDefaults);
|
|
118
|
+
|
|
119
|
+
// Edit params, if needed:
|
|
120
|
+
params.color = "transparent";
|
|
121
|
+
params.items = ActionTabBar.normalizeItems(params.items); // WHY: A copy: the array of the caller does not change.
|
|
122
|
+
|
|
123
|
+
// BOX: Component container
|
|
124
|
+
const box = startObject(params);
|
|
125
|
+
|
|
126
|
+
// *** PRIVATE VARIABLES:
|
|
127
|
+
const _s = box.style;
|
|
128
|
+
let itemList = []; // A Box for every tab (item.data: { key, text, iconFile }; item.icon, item.label)
|
|
129
|
+
|
|
130
|
+
// *** PUBLIC VARIABLES:
|
|
131
|
+
box.previousValue = null;
|
|
132
|
+
// NOTE: Default values are also public variables. (box.items, box.value)
|
|
133
|
+
|
|
134
|
+
// *** PRIVATE FUNCTIONS:
|
|
135
|
+
|
|
136
|
+
// DRAWING: each function does one job:
|
|
137
|
+
// createItems() -> a Box for every tab (the first drawing)
|
|
138
|
+
// showSelectedItem() -> after box.value changed: the look of the tabs, the line under the selected one
|
|
139
|
+
// and the Tab order (setValue)
|
|
140
|
+
|
|
141
|
+
const findItem = function (key) {
|
|
142
|
+
return itemList.find(function (item) { return item.data.key === key; }) || null;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const isMotionOn = function () {
|
|
146
|
+
const reduceMotion = window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
147
|
+
return !reduceMotion;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// The left of a tab in the box: from style.item.left, one after the other.
|
|
151
|
+
const getItemLeft = function (index) {
|
|
152
|
+
return _s.item.left + index * (_s.item.width + _s.item.gap);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// The line is in the middle under its tab.
|
|
156
|
+
const getIndicatorLeft = function (index) {
|
|
157
|
+
return getItemLeft(index) + (_s.item.width - _s.indicator.width) / 2;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// DATA: one tab, in the tab list. (createIn)
|
|
161
|
+
const createItem = function (data, index) {
|
|
162
|
+
|
|
163
|
+
// BOX: Tab
|
|
164
|
+
const item = startBox({
|
|
165
|
+
left: getItemLeft(index),
|
|
166
|
+
top: _s.bar.space,
|
|
167
|
+
width: _s.item.width,
|
|
168
|
+
height: _s.bar.height,
|
|
169
|
+
color: "transparent",
|
|
170
|
+
round: _s.item.round,
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// ICON:
|
|
174
|
+
item.icon = Icon({
|
|
175
|
+
left: (_s.item.width - _s.icon.size) / 2,
|
|
176
|
+
top: _s.icon.top,
|
|
177
|
+
width: _s.icon.size,
|
|
178
|
+
height: _s.icon.size,
|
|
179
|
+
alt: "",
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// LABEL: Text
|
|
183
|
+
item.label = Label({ ..._s.label, left: 0, width: "100%", textAlign: "center", plainText: data.text });
|
|
184
|
+
|
|
185
|
+
endBox();
|
|
186
|
+
|
|
187
|
+
item.data = data;
|
|
188
|
+
item.cursor = "pointer";
|
|
189
|
+
item.role = "tab";
|
|
190
|
+
item.aria = { label: data.text };
|
|
191
|
+
item.setFocusRing(_s.focus.ringColor);
|
|
192
|
+
if (data.iconFile) item.icon.load(data.iconFile);
|
|
193
|
+
else item.icon.visible = 0;
|
|
194
|
+
|
|
195
|
+
item.on("click", function () { selectByUser(item); });
|
|
196
|
+
item.on("keydown", function (self, event) { onItemKeyDown(item, event); });
|
|
197
|
+
return item;
|
|
198
|
+
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const createItems = function () {
|
|
202
|
+
itemList = box.items.map(function (data, index) {
|
|
203
|
+
return createIn(box.tabList, function () { return createItem(data, index); });
|
|
204
|
+
});
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
// The line slides to the selected tab. (isAnimated: 0 -> it jumps: the first view)
|
|
208
|
+
const moveIndicator = function (isAnimated) {
|
|
209
|
+
const index = box.getIndex();
|
|
210
|
+
box.indicator.visible = (index >= 0) ? 1 : 0;
|
|
211
|
+
if (index < 0) return;
|
|
212
|
+
const seconds = _s.indicator.motionTime;
|
|
213
|
+
const isMoving = (isAnimated && seconds > 0 && isMotionOn());
|
|
214
|
+
box.indicator.setMotionNow((isMoving) ? "transform " + seconds + "s " + _s.indicator.ease : "none");
|
|
215
|
+
box.indicator.css.transform = "translateX(" + getIndicatorLeft(index) + "px)";
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
// Roving tabindex: only one tab is in the Tab order.
|
|
219
|
+
// WHY: The only place that sets the tabIndex of the tabs: with two places, two tabs could be in the Tab order.
|
|
220
|
+
const makeTabbable = function (tabbableItem) {
|
|
221
|
+
itemList.forEach(function (item) {
|
|
222
|
+
item.tabIndex = (item === tabbableItem) ? 0 : -1;
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
// THE SELECTED TAB IS SHOWN: the look of the tabs, the line under the selected one, the Tab order.
|
|
227
|
+
// WHY: One place, so no setter can forget a part.
|
|
228
|
+
const showSelectedItem = function (isAnimated) {
|
|
229
|
+
const selectedItem = findItem(box.value);
|
|
230
|
+
itemList.forEach(function (item) {
|
|
231
|
+
const isSelected = (item === selectedItem);
|
|
232
|
+
item.opacity = (isSelected) ? 1 : _s.item.passiveOpacity;
|
|
233
|
+
item.aria = { selected: isSelected };
|
|
234
|
+
});
|
|
235
|
+
moveIndicator(isAnimated);
|
|
236
|
+
makeTabbable(selectedItem || itemList[0]);
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const focusItem = function (item) {
|
|
240
|
+
makeTabbable(item);
|
|
241
|
+
item.elem.focus({ preventScroll: true });
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// A tap on a tab: it is selected and takes the focus (a ring only for the keyboard).
|
|
245
|
+
const selectByUser = function (item) {
|
|
246
|
+
box.setValue(item.data.key);
|
|
247
|
+
focusItem(item);
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const onItemKeyDown = function (item, event) {
|
|
251
|
+
const index = itemList.indexOf(item);
|
|
252
|
+
const count = itemList.length;
|
|
253
|
+
const key = event.key;
|
|
254
|
+
if (key === "ArrowLeft") focusItem(itemList[(index - 1 + count) % count]); // WHY: % goes round at both ends.
|
|
255
|
+
else if (key === "ArrowRight") focusItem(itemList[(index + 1) % count]);
|
|
256
|
+
else if (key === "Home") focusItem(itemList[0]);
|
|
257
|
+
else if (key === "End") focusItem(itemList[count - 1]);
|
|
258
|
+
else if (key === "Enter" || key === " ") box.setValue(item.data.key);
|
|
259
|
+
else return; // Another key: the browser keeps it.
|
|
260
|
+
event.preventDefault();
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const runAction = function () {
|
|
264
|
+
box.onAction(box);
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
const onActionKeyDown = function (self, event) {
|
|
268
|
+
if (event.key !== "Enter" && event.key !== " ") return;
|
|
269
|
+
event.preventDefault();
|
|
270
|
+
runAction();
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// *** PUBLIC FUNCTIONS:
|
|
274
|
+
|
|
275
|
+
// silent: 1 -> onChange is not called. Returns 1 when the tab exists.
|
|
276
|
+
box.setValue = function (key, silent = 0) {
|
|
277
|
+
if (!findItem(key)) return 0;
|
|
278
|
+
if (box.value === key) return 1;
|
|
279
|
+
box.previousValue = box.value;
|
|
280
|
+
box.value = key;
|
|
281
|
+
showSelectedItem(1);
|
|
282
|
+
if (!silent) box.onChange(box);
|
|
283
|
+
return 1;
|
|
284
|
+
};
|
|
285
|
+
// USAGE: tabBar.setValue("tools")
|
|
286
|
+
|
|
287
|
+
// The index of a tab (default: the selected one). -1: no tab with this key.
|
|
288
|
+
box.getIndex = function (key = box.value) {
|
|
289
|
+
return itemList.findIndex(function (item) { return item.data.key === key; });
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
// *** OBJECT VIEW:
|
|
293
|
+
|
|
294
|
+
const _b = _s.bar;
|
|
295
|
+
const _a = _s.action;
|
|
296
|
+
|
|
297
|
+
// BOX: The bar (a gray that fades to the bottom)
|
|
298
|
+
box.bar = Box({
|
|
299
|
+
left: _b.space,
|
|
300
|
+
top: _b.space,
|
|
301
|
+
width: "calc(100% - " + (_b.space * 2) + "px)",
|
|
302
|
+
height: _b.height,
|
|
303
|
+
color: "transparent",
|
|
304
|
+
round: _b.round,
|
|
305
|
+
border: _b.border,
|
|
306
|
+
borderColor: _b.borderColor,
|
|
307
|
+
css: { background: _b.background },
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
// BOX: The tab list (the tabs are made by createItems())
|
|
311
|
+
box.tabList = Box({ left: 0, top: 0, width: "100%", height: "100%", color: "transparent" });
|
|
312
|
+
box.tabList.role = "tablist";
|
|
313
|
+
box.tabList.aria = { label: box.ariaLabel };
|
|
314
|
+
|
|
315
|
+
// BOX: The line under the selected tab
|
|
316
|
+
box.indicator = Box({
|
|
317
|
+
left: 0,
|
|
318
|
+
top: _s.indicator.top,
|
|
319
|
+
width: _s.indicator.width,
|
|
320
|
+
height: _s.indicator.height,
|
|
321
|
+
color: _s.indicator.color,
|
|
322
|
+
opacity: _s.indicator.opacity,
|
|
323
|
+
round: _s.indicator.round,
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
// LABEL: The round "+" button
|
|
327
|
+
box.btnAction = Label({
|
|
328
|
+
right: _a.right,
|
|
329
|
+
top: _a.top,
|
|
330
|
+
width: _a.size,
|
|
331
|
+
height: _a.size,
|
|
332
|
+
color: _a.color,
|
|
333
|
+
border: _a.border,
|
|
334
|
+
borderColor: _a.borderColor,
|
|
335
|
+
round: _a.round,
|
|
336
|
+
text: ActionTabBar.getPlusSvg(_a.iconColor, _a.iconSize, _a.iconLine, _a.iconOpacity),
|
|
337
|
+
lineHeight: "0",
|
|
338
|
+
clickable: 1,
|
|
339
|
+
cursor: "pointer",
|
|
340
|
+
css: { display: "flex", alignItems: "center", justifyContent: "center" },
|
|
341
|
+
});
|
|
342
|
+
box.btnAction.role = "button";
|
|
343
|
+
box.btnAction.aria = { label: box.actionAriaLabel };
|
|
344
|
+
box.btnAction.tabIndex = 0;
|
|
345
|
+
box.btnAction.setFocusRing(_s.focus.ringColor);
|
|
346
|
+
|
|
347
|
+
// *** OBJECT INIT CODE:
|
|
348
|
+
|
|
349
|
+
box.btnAction.on("click", runAction);
|
|
350
|
+
box.btnAction.on("keydown", onActionKeyDown);
|
|
351
|
+
|
|
352
|
+
createItems();
|
|
353
|
+
if (!findItem(box.value)) box.value = (itemList.length) ? itemList[0].data.key : null;
|
|
354
|
+
showSelectedItem(0);
|
|
355
|
+
|
|
356
|
+
return endObject(box);
|
|
357
|
+
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
// *** STATIC FUNCTIONS:
|
|
361
|
+
|
|
362
|
+
// A tab: { key, text, iconFile }. A text is a tab too: "Home" -> { key: "Home", text: "Home", iconFile: "" }
|
|
363
|
+
ActionTabBar.normalizeItems = function (items) {
|
|
364
|
+
if (!Array.isArray(items)) return [];
|
|
365
|
+
return items.map(function (item) {
|
|
366
|
+
if (typeof item !== "object" || item === null) return { key: String(item), text: String(item), iconFile: "" };
|
|
367
|
+
const text = (item.text === undefined || item.text === null) ? "" : String(item.text);
|
|
368
|
+
const key = (item.key === undefined) ? text : item.key;
|
|
369
|
+
return { key: key, text: text, iconFile: item.iconFile || "" };
|
|
370
|
+
});
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
// The "+" of the action button. line: the width of its lines on the 24 px grid of the icon (round ends).
|
|
374
|
+
ActionTabBar.getPlusSvg = function (color, size, line, opacity) {
|
|
375
|
+
const GRID_SIZE = 24;
|
|
376
|
+
const middle = GRID_SIZE / 2;
|
|
377
|
+
const start = line / 2; // WHY: The round ends touch the edges of the grid.
|
|
378
|
+
const end = GRID_SIZE - line / 2;
|
|
379
|
+
const path = "M" + middle + " " + start + "V" + end + "M" + start + " " + middle + "H" + end;
|
|
380
|
+
return '<svg xmlns="http://www.w3.org/2000/svg" width="' + size + '" height="' + size + '" viewBox="0 0 24 24"' +
|
|
381
|
+
' fill="none" stroke="' + color + '" stroke-width="' + line + '" stroke-linecap="round" opacity="' + opacity + '"' +
|
|
382
|
+
' aria-hidden="true"><path d="' + path + '"/></svg>';
|
|
383
|
+
};
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
AppBar - v26.11
|
|
6
|
+
|
|
7
|
+
THE TOP BAR OF A TAB PAGE of a mobile app.
|
|
8
|
+
- The sizes are px of a 600 px design: the page is fitted with page.fit(600, 800), like the mobile template
|
|
9
|
+
(04-templates/mobile-app-template/classic).
|
|
10
|
+
- A white bar, 105 px high. The title (28 px, bold) in the middle (titleAlign "center") or at the left ("left");
|
|
11
|
+
a long title ends with "...". In the middle it keeps the same room at both sides, so it stays in the middle of
|
|
12
|
+
the bar when only one button is shown.
|
|
13
|
+
- A back button at the left (showBack: 1) and a menu button at the right (showMenu: 1): 40 x 40, 20 px from the
|
|
14
|
+
sides. The buttons and the title stand 24 px from the bottom of the bar.
|
|
15
|
+
- The buttons are SmartButtons (styleName "ozden4": a gray square under the mouse), with only an icon and an
|
|
16
|
+
aria label: the keyboard and the screen readers work as with every SmartButton.
|
|
17
|
+
- The icons are drawn in SVG in iconColor (a back arrow with a shaft, three dots), or your own files
|
|
18
|
+
(backIconFile, menuIconFile: a file keeps its own colors).
|
|
19
|
+
- line: 1 -> a 2 px soft line at the bottom. Its place is always there (a clear line when it is off), so the title
|
|
20
|
+
and the buttons do not move when it changes.
|
|
21
|
+
- NEEDS: comp/smart-button.js, loaded before the bar is created.
|
|
22
|
+
|
|
23
|
+
USAGE:
|
|
24
|
+
const bar = AppBar({ titleText: "Settings", titleAlign: "left", line: 1, onMenu: function (self) { menu.open(); } });
|
|
25
|
+
AppBar({ titleText: "Details", showBack: 1, onBack: function (self) { App.goBack(); } });
|
|
26
|
+
AppBar({ titleText: "Green", color: "#5ABB9F", iconColor: "white", style: { title: { textColor: "white" } } });
|
|
27
|
+
bar.setTitleText("Tasks");
|
|
28
|
+
bar.setTitleAlign("center");
|
|
29
|
+
bar.setLine(0);
|
|
30
|
+
bar.setBackVisible(1);
|
|
31
|
+
bar.setMenuVisible(0);
|
|
32
|
+
|
|
33
|
+
Started Date: November 2026
|
|
34
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
35
|
+
|
|
36
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
37
|
+
Licensed under the Apache License, Version 2.0
|
|
38
|
+
SPDX-License-Identifier: Apache-2.0
|
|
39
|
+
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
"use strict";
|
|
43
|
+
|
|
44
|
+
// Default values:
|
|
45
|
+
const AppBarDefaults = {
|
|
46
|
+
key: "0", // Your name for this object: read it in a callback (self.key)
|
|
47
|
+
left: 0, // The bar stands at the top of its container (a page)
|
|
48
|
+
top: 0,
|
|
49
|
+
width: "100%",
|
|
50
|
+
height: 105,
|
|
51
|
+
color: "white", // The background of the bar
|
|
52
|
+
titleText: "",
|
|
53
|
+
titleAlign: "center", // "center" or "left" (set later with setTitleAlign)
|
|
54
|
+
line: 0, // 1: a soft line at the bottom (setLine)
|
|
55
|
+
showBack: 0, // 1: the back button at the left (setBackVisible)
|
|
56
|
+
showMenu: 1, // 1: the menu button at the right (setMenuVisible)
|
|
57
|
+
backIconFile: "", // "": a back arrow drawn in SVG (Ex: "assets/icons/back.svg")
|
|
58
|
+
menuIconFile: "", // "": three dots drawn in SVG
|
|
59
|
+
iconColor: Black(0.8), // The color of the drawn icons (a file keeps its own colors)
|
|
60
|
+
backAriaLabel: "Back", // What a screen reader says for the buttons
|
|
61
|
+
menuAriaLabel: "Menu",
|
|
62
|
+
onBack: function (self) { },
|
|
63
|
+
onMenu: function (self) { },
|
|
64
|
+
style: {
|
|
65
|
+
layout: {
|
|
66
|
+
side: 20, // The space at the left and the right
|
|
67
|
+
bottom: 24, // The buttons and the title stand this far from the bottom
|
|
68
|
+
titleGap: 10, // The least space between a button and the title
|
|
69
|
+
// WHY: the back arrow is in line with the title, at (side, bottom): in a 40 px button it stands that far only
|
|
70
|
+
// when the button goes 3 px to the left and down
|
|
71
|
+
backShift: 3,
|
|
72
|
+
},
|
|
73
|
+
title: {
|
|
74
|
+
fontSize: 28,
|
|
75
|
+
bold: 1,
|
|
76
|
+
textColor: Black(0.8),
|
|
77
|
+
},
|
|
78
|
+
button: {
|
|
79
|
+
size: 40,
|
|
80
|
+
iconSize: 34, // In the middle of the button
|
|
81
|
+
},
|
|
82
|
+
line: {
|
|
83
|
+
width: 2,
|
|
84
|
+
color: Black(0.1),
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const AppBar = function (params = {}) {
|
|
90
|
+
|
|
91
|
+
// Merge params:
|
|
92
|
+
mergeIntoIfMissing(params, AppBarDefaults);
|
|
93
|
+
|
|
94
|
+
// BOX: Component container
|
|
95
|
+
const box = startObject(params);
|
|
96
|
+
|
|
97
|
+
// *** PRIVATE VARIABLES:
|
|
98
|
+
const _s = box.style;
|
|
99
|
+
|
|
100
|
+
// *** PRIVATE FUNCTIONS:
|
|
101
|
+
|
|
102
|
+
// The room of a button with its gap to the title (0: the button is not shown)
|
|
103
|
+
const getButtonRoom = function (isShown) {
|
|
104
|
+
if (!isShown) return 0;
|
|
105
|
+
return _s.button.size + _s.layout.titleGap;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// TITLE: at the left, or in the middle with the same room at both sides (so it is in the middle of the bar)
|
|
109
|
+
const placeTitle = function () {
|
|
110
|
+
const backRoom = getButtonRoom(box.showBack == 1);
|
|
111
|
+
const menuRoom = getButtonRoom(box.showMenu == 1);
|
|
112
|
+
const isLeft = (box.titleAlign == "left");
|
|
113
|
+
const sideRoom = Math.max(backRoom, menuRoom);
|
|
114
|
+
const leftSpace = _s.layout.side + (isLeft ? backRoom : sideRoom);
|
|
115
|
+
const rightSpace = _s.layout.side + (isLeft ? menuRoom : sideRoom);
|
|
116
|
+
box.lblTitle.left = leftSpace;
|
|
117
|
+
box.lblTitle.width = "calc(100% - " + (leftSpace + rightSpace) + "px)";
|
|
118
|
+
box.lblTitle.textAlign = box.titleAlign;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// WHY always a border: a clear line when it is off, so the title and the buttons stay at the same place
|
|
122
|
+
const paintLine = function () {
|
|
123
|
+
const lineColor = (box.line == 1) ? _s.line.color : "transparent";
|
|
124
|
+
box.css = { borderBottom: _s.line.width + "px solid " + lineColor };
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// BUTTON: only an icon, in the middle (place: { left, bottom } or { right, bottom })
|
|
128
|
+
const createButton = function (iconFile, ariaLabel, onClick, place) {
|
|
129
|
+
const iconSpace = (_s.button.size - _s.button.iconSize) / 2;
|
|
130
|
+
const button = SmartButton({
|
|
131
|
+
styleName: "ozden4",
|
|
132
|
+
labelText: "",
|
|
133
|
+
iconFile: iconFile,
|
|
134
|
+
ariaLabel: ariaLabel,
|
|
135
|
+
width: _s.button.size,
|
|
136
|
+
height: _s.button.size,
|
|
137
|
+
...place,
|
|
138
|
+
style: {
|
|
139
|
+
layout: { padding: [iconSpace, iconSpace] },
|
|
140
|
+
icon: { width: _s.button.iconSize, height: _s.button.iconSize, opacity: 1 },
|
|
141
|
+
},
|
|
142
|
+
onClick: onClick,
|
|
143
|
+
});
|
|
144
|
+
button.icon.alt = ""; // WHY: load() writes the file as the alt text (a drawn icon is a long data URI)
|
|
145
|
+
return button;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// *** PUBLIC FUNCTIONS:
|
|
149
|
+
|
|
150
|
+
box.setTitleText = function (text) {
|
|
151
|
+
box.titleText = text;
|
|
152
|
+
box.lblTitle.plainText = text;
|
|
153
|
+
};
|
|
154
|
+
// USAGE: bar.setTitleText("Settings")
|
|
155
|
+
|
|
156
|
+
box.setTitleAlign = function (align) {
|
|
157
|
+
box.titleAlign = (align == "left") ? "left" : "center";
|
|
158
|
+
placeTitle();
|
|
159
|
+
};
|
|
160
|
+
// USAGE: get: bar.titleAlign, set: bar.setTitleAlign("left")
|
|
161
|
+
|
|
162
|
+
box.setLine = function (value) {
|
|
163
|
+
box.line = basic.isOn(value) ? 1 : 0;
|
|
164
|
+
paintLine();
|
|
165
|
+
};
|
|
166
|
+
// USAGE: bar.setLine(1)
|
|
167
|
+
|
|
168
|
+
box.setBackVisible = function (value) {
|
|
169
|
+
box.showBack = basic.isOn(value) ? 1 : 0;
|
|
170
|
+
box.btnBack.visible = box.showBack;
|
|
171
|
+
placeTitle();
|
|
172
|
+
};
|
|
173
|
+
// USAGE: get: bar.showBack, set: bar.setBackVisible(1)
|
|
174
|
+
|
|
175
|
+
box.setMenuVisible = function (value) {
|
|
176
|
+
box.showMenu = basic.isOn(value) ? 1 : 0;
|
|
177
|
+
box.btnMenu.visible = box.showMenu;
|
|
178
|
+
placeTitle();
|
|
179
|
+
};
|
|
180
|
+
// USAGE: get: bar.showMenu, set: bar.setMenuVisible(0)
|
|
181
|
+
|
|
182
|
+
// *** OBJECT VIEW:
|
|
183
|
+
|
|
184
|
+
// BOX: Bar
|
|
185
|
+
box.shrink = 0; // WHY: in a group with a fixed height the bar keeps its height
|
|
186
|
+
paintLine();
|
|
187
|
+
|
|
188
|
+
// LABEL: Title (placeTitle gives its left and its width)
|
|
189
|
+
box.lblTitle = Label({ bottom: _s.layout.bottom, ..._s.title, ellipsis: 1 });
|
|
190
|
+
box.lblTitle.role = "heading";
|
|
191
|
+
box.lblTitle.aria = { level: 1 };
|
|
192
|
+
|
|
193
|
+
// BUTTON: Back (left)
|
|
194
|
+
const backIconFile = box.backIconFile || AppBar.toSvgFile(AppBar.drawBackArrow(box.iconColor));
|
|
195
|
+
box.btnBack = createButton(backIconFile, box.backAriaLabel, function () {
|
|
196
|
+
box.onBack(box);
|
|
197
|
+
}, { left: _s.layout.side - _s.layout.backShift, bottom: _s.layout.bottom - _s.layout.backShift });
|
|
198
|
+
|
|
199
|
+
// BUTTON: Menu (right)
|
|
200
|
+
const menuIconFile = box.menuIconFile || AppBar.toSvgFile(AppBar.drawMenuDots(box.iconColor));
|
|
201
|
+
box.btnMenu = createButton(menuIconFile, box.menuAriaLabel, function () {
|
|
202
|
+
box.onMenu(box);
|
|
203
|
+
}, { right: _s.layout.side, bottom: _s.layout.bottom });
|
|
204
|
+
|
|
205
|
+
// *** OBJECT INIT CODE:
|
|
206
|
+
|
|
207
|
+
box.setTitleText(box.titleText);
|
|
208
|
+
box.setTitleAlign(box.titleAlign);
|
|
209
|
+
box.setBackVisible(box.showBack);
|
|
210
|
+
box.setMenuVisible(box.showMenu);
|
|
211
|
+
|
|
212
|
+
return endObject(box);
|
|
213
|
+
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
// *** STATIC FUNCTIONS:
|
|
217
|
+
|
|
218
|
+
// An SVG text as a file for an Icon (a data URI)
|
|
219
|
+
AppBar.toSvgFile = function (svg) {
|
|
220
|
+
return "data:image/svg+xml;charset=utf-8," + encodeURIComponent(svg);
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
// A back arrow with a shaft (24 x 24)
|
|
224
|
+
AppBar.drawBackArrow = function (color) {
|
|
225
|
+
return '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="' + color +
|
|
226
|
+
'" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 12H7.6M12 7l-5 5 5 5"/></svg>';
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
// Three dots one under the other (24 x 24)
|
|
230
|
+
AppBar.MENU_DOT_RADIUS = 2.5;
|
|
231
|
+
AppBar.MENU_DOT_PLACES = [2.5, 12, 21.5];
|
|
232
|
+
AppBar.drawMenuDots = function (color) {
|
|
233
|
+
const dots = AppBar.MENU_DOT_PLACES.map(function (y) {
|
|
234
|
+
return '<circle cx="12" cy="' + y + '" r="' + AppBar.MENU_DOT_RADIUS + '"/>';
|
|
235
|
+
});
|
|
236
|
+
return '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="' + color + '">' + dots.join("") + "</svg>";
|
|
237
|
+
};
|