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,527 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
Radio Button - v26.11
|
|
6
|
+
|
|
7
|
+
UI COMPONENT TEMPLATE
|
|
8
|
+
- A customizable radio button with a label.
|
|
9
|
+
- Radio buttons with the same "group" name work together: only one can be selected.
|
|
10
|
+
- Mark is drawn with code (no image files needed).
|
|
11
|
+
- Supports: checked, enabled, value, label position (left/right),
|
|
12
|
+
keyboard (Space/Enter to select, Arrow keys to move in the group).
|
|
13
|
+
- Whole object background can change on hover and checked states (style.hoverBox, style.checkedBox).
|
|
14
|
+
- The empty circle under the mouse: style.hoverMark (its borderColor, and its color when given; v26.11).
|
|
15
|
+
- style.focus.ringColor: the keyboard focus shows on the mark (its edge in this color, 2 px). "": none (the old
|
|
16
|
+
packages); "minimal" / "minimalDark" have it.
|
|
17
|
+
- Style packages: "light" (default; the old name "classic" works too), "modern", "dark", "minimal", "minimalDark". Select with styleName. (RadioButton.styles)
|
|
18
|
+
NEW PROJECTS: use "light" on a light page and "dark" on a dark page, unless the user
|
|
19
|
+
asks for another one ("modern" only when asked).
|
|
20
|
+
|
|
21
|
+
Started Date: September 2026
|
|
22
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
23
|
+
|
|
24
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
25
|
+
Licensed under the Apache License, Version 2.0
|
|
26
|
+
SPDX-License-Identifier: Apache-2.0
|
|
27
|
+
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
"use strict";
|
|
31
|
+
|
|
32
|
+
// Default values:
|
|
33
|
+
const RadioButtonDefaults = {
|
|
34
|
+
key: "0",
|
|
35
|
+
width: "auto",
|
|
36
|
+
height: "auto",
|
|
37
|
+
group: "default", // Radio buttons with the same group name work together.
|
|
38
|
+
value: "", // Returned by RadioButton.getValue(group)
|
|
39
|
+
checked: 0, // 0, 1
|
|
40
|
+
enabled: 1, // 0, 1
|
|
41
|
+
labelText: "",
|
|
42
|
+
allowHtml: 0, // 1: labelText is HTML (only for your own texts)
|
|
43
|
+
labelPosition: "right", // "right", "left"
|
|
44
|
+
onChange: function (self) { }, // Called when this radio button is selected.
|
|
45
|
+
styleName: "light", // "light" ("classic": its old name), "modern", "dark", "minimal", "minimalDark" or a name added to RadioButton.styles
|
|
46
|
+
style: { // Light style package (default)
|
|
47
|
+
box: { // Whole object background
|
|
48
|
+
color: "transparent",
|
|
49
|
+
round: 0,
|
|
50
|
+
},
|
|
51
|
+
hoverBox: { // Mouse over (whole object background)
|
|
52
|
+
color: null, // null: uses box.color
|
|
53
|
+
},
|
|
54
|
+
checkedBox: { // Checked (whole object background)
|
|
55
|
+
color: null, // null: uses box.color
|
|
56
|
+
},
|
|
57
|
+
hoverCheckedBox: { // Checked and mouse over (whole object background)
|
|
58
|
+
color: null, // null: uses checkedBox.color
|
|
59
|
+
},
|
|
60
|
+
layout: {
|
|
61
|
+
gap: 10,
|
|
62
|
+
padding: [0, 4],
|
|
63
|
+
align: "left center",
|
|
64
|
+
},
|
|
65
|
+
mark: { // Unchecked circle
|
|
66
|
+
width: 22,
|
|
67
|
+
height: 22,
|
|
68
|
+
color: White(1),
|
|
69
|
+
border: 2,
|
|
70
|
+
borderColor: Black(0.35),
|
|
71
|
+
round: 100,
|
|
72
|
+
},
|
|
73
|
+
checkedMark: { // Checked circle
|
|
74
|
+
color: White(1),
|
|
75
|
+
borderColor: "#242424", // the checked color of CheckBox
|
|
76
|
+
},
|
|
77
|
+
hoverMark: { // Mouse over (the empty circle)
|
|
78
|
+
color: null, // null: uses mark.color (a package could not change it)
|
|
79
|
+
borderColor: Black(0.7),
|
|
80
|
+
},
|
|
81
|
+
dot: {
|
|
82
|
+
color: "#242424", // (as the edge above)
|
|
83
|
+
size: 0.5, // Ratio of the inner circle size (0 - 1)
|
|
84
|
+
round: 100,
|
|
85
|
+
},
|
|
86
|
+
label: {
|
|
87
|
+
fontSize: 16,
|
|
88
|
+
textColor: Black(0.8),
|
|
89
|
+
},
|
|
90
|
+
disabled: {
|
|
91
|
+
opacity: 0.4,
|
|
92
|
+
},
|
|
93
|
+
focus: { // The keyboard focus: the edge of the mark in this color, 2 px. "": no ring
|
|
94
|
+
ringColor: "",
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const RadioButton = function (params = {}) {
|
|
100
|
+
|
|
101
|
+
// Merge style package: params.style > RadioButton.styles[styleName] > RadioButtonDefaults.style (light)
|
|
102
|
+
basic.applyStylePackage(params, RadioButton.styles, RadioButtonDefaults);
|
|
103
|
+
|
|
104
|
+
// Merge params:
|
|
105
|
+
mergeIntoIfMissing(params, RadioButtonDefaults);
|
|
106
|
+
|
|
107
|
+
// Edit params, if needed:
|
|
108
|
+
params.color = params.style.box.color;
|
|
109
|
+
params.round = params.style.box.round;
|
|
110
|
+
|
|
111
|
+
// BOX: Component container
|
|
112
|
+
let box = startObject(params);
|
|
113
|
+
|
|
114
|
+
// *** PRIVATE VARIABLES:
|
|
115
|
+
let isMouseOver = 0;
|
|
116
|
+
const MOTION_DURATION = "0.15s";
|
|
117
|
+
const DOT_HIDDEN_SCALE = 0.3; // The dot grows from this size when checked.
|
|
118
|
+
|
|
119
|
+
// *** PUBLIC VARIABLES:
|
|
120
|
+
// NOTE: Default values are also public variables. (box.checked, box.value, box.group)
|
|
121
|
+
|
|
122
|
+
// *** PRIVATE FUNCTIONS:
|
|
123
|
+
|
|
124
|
+
const setText = function (label, text) {
|
|
125
|
+
const value = (text === undefined || text === null) ? "" : String(text);
|
|
126
|
+
if (box.allowHtml == 1) label.text = value;
|
|
127
|
+
else label.plainText = value;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// The keyboard focus (style.focus.ringColor) on the mark: its edge in that color and 1 px more inside it.
|
|
131
|
+
// WHY on the mark, inside it: a ring around the whole object hid its text, and an outer ring was cut by the groups.
|
|
132
|
+
// WHY a CSS rule: only :focus-visible knows a focus of the keyboard (not of a click).
|
|
133
|
+
const showFocusOnMark = function () {
|
|
134
|
+
const ringColor = box.style.focus.ringColor;
|
|
135
|
+
if (!ringColor) return;
|
|
136
|
+
RadioButton.addFocusCss();
|
|
137
|
+
box.elem.classList.add("radio-button-focus");
|
|
138
|
+
box.mark.elem.classList.add("radio-button-mark");
|
|
139
|
+
box.elem.style.setProperty("--radio-button-focus", ringColor);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const getGroupList = function () {
|
|
143
|
+
return RadioButton.getGroup(box.group);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// The whole object background. A null color uses the color of the state below it.
|
|
147
|
+
const getBoxColor = function (isHover) {
|
|
148
|
+
const boxColor = box.style.box.color;
|
|
149
|
+
const checkedBoxColor = box.style.checkedBox.color || boxColor;
|
|
150
|
+
if (box.checked == 1) {
|
|
151
|
+
if (isHover) return box.style.hoverCheckedBox.color || checkedBoxColor;
|
|
152
|
+
return checkedBoxColor;
|
|
153
|
+
}
|
|
154
|
+
if (isHover) return box.style.hoverBox.color || boxColor;
|
|
155
|
+
return boxColor;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const paintMark = function (isHover) {
|
|
159
|
+
if (box.checked == 1) {
|
|
160
|
+
box.mark.color = box.style.checkedMark.color;
|
|
161
|
+
box.mark.borderColor = box.style.checkedMark.borderColor;
|
|
162
|
+
box.dot.css = { opacity: "1", transform: "scale(1)" };
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const hoverColor = box.style.hoverMark.color;
|
|
166
|
+
box.mark.color = (isHover && hoverColor) ? hoverColor : box.style.mark.color;
|
|
167
|
+
box.mark.borderColor = (isHover) ? box.style.hoverMark.borderColor : box.style.mark.borderColor;
|
|
168
|
+
box.dot.css = { opacity: "0", transform: "scale(" + DOT_HIDDEN_SCALE + ")" };
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const paintEnabled = function () {
|
|
172
|
+
const isEnabled = (box.enabled == 1);
|
|
173
|
+
box.opacity = (isEnabled) ? 1 : box.style.disabled.opacity;
|
|
174
|
+
box.cursor = (isEnabled) ? "pointer" : "default";
|
|
175
|
+
box.tabIndex = (isEnabled) ? 0 : -1;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
// The look of the current state (checked, mouse over, enabled).
|
|
179
|
+
const paint = function () {
|
|
180
|
+
const isHover = (isMouseOver && box.enabled == 1);
|
|
181
|
+
box.color = getBoxColor(isHover);
|
|
182
|
+
paintMark(isHover);
|
|
183
|
+
paintEnabled();
|
|
184
|
+
box.aria = { checked: (box.checked == 1), disabled: (box.enabled != 1) };
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// Move selection to the next/previous enabled radio button in the group.
|
|
188
|
+
const moveSelection = function (direction) {
|
|
189
|
+
|
|
190
|
+
const list = getGroupList().filter(function (radio) { return radio.enabled == 1; });
|
|
191
|
+
if (list.length == 0) return;
|
|
192
|
+
|
|
193
|
+
let index = list.indexOf(box) + direction;
|
|
194
|
+
if (index < 0) index = list.length - 1;
|
|
195
|
+
if (index >= list.length) index = 0;
|
|
196
|
+
|
|
197
|
+
list[index].select();
|
|
198
|
+
list[index].elem.focus();
|
|
199
|
+
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const removeFromGroup = function () {
|
|
203
|
+
const list = getGroupList();
|
|
204
|
+
const index = list.indexOf(box);
|
|
205
|
+
if (index > -1) list.splice(index, 1);
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
// *** PUBLIC FUNCTIONS:
|
|
209
|
+
|
|
210
|
+
// Select this radio button and unselect the others in the same group.
|
|
211
|
+
box.select = function (silent = 0) {
|
|
212
|
+
box.setChecked(1, silent);
|
|
213
|
+
};
|
|
214
|
+
// USAGE: radio.select()
|
|
215
|
+
|
|
216
|
+
box.setChecked = function (checked, silent = 0) {
|
|
217
|
+
|
|
218
|
+
checked = basic.isOn(checked) ? 1 : 0;
|
|
219
|
+
if (box.checked == checked) return;
|
|
220
|
+
|
|
221
|
+
if (checked == 1) {
|
|
222
|
+
getGroupList().forEach(function (radio) {
|
|
223
|
+
if (radio !== box && radio.checked == 1) radio._uncheck();
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
box.checked = checked;
|
|
228
|
+
paint();
|
|
229
|
+
|
|
230
|
+
if (checked == 1 && !silent) box.onChange(box);
|
|
231
|
+
|
|
232
|
+
};
|
|
233
|
+
// USAGE: get: radio.checked, set: radio.setChecked(1)
|
|
234
|
+
// NOTE: setChecked(1, 1) changes the value without calling onChange.
|
|
235
|
+
// NOTE: setChecked(0) leaves the group with no selection.
|
|
236
|
+
|
|
237
|
+
// Used by the group. (No event)
|
|
238
|
+
box._uncheck = function () {
|
|
239
|
+
box.checked = 0;
|
|
240
|
+
paint();
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
box.setEnabled = function (enabled) {
|
|
244
|
+
box.enabled = basic.isOn(enabled) ? 1 : 0;
|
|
245
|
+
paint();
|
|
246
|
+
};
|
|
247
|
+
// USAGE: get: radio.enabled, set: radio.setEnabled(0)
|
|
248
|
+
|
|
249
|
+
box.setLabelText = function (text) {
|
|
250
|
+
box.labelText = text;
|
|
251
|
+
setText(box.label, text);
|
|
252
|
+
box.label.visible = (text) ? 1 : 0;
|
|
253
|
+
};
|
|
254
|
+
// USAGE: get: radio.labelText, set: radio.setLabelText("Option A")
|
|
255
|
+
|
|
256
|
+
box.refresh = function () {
|
|
257
|
+
paint();
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
// WHY: remove() can not know the static group list (RadioButton.groups).
|
|
261
|
+
// box.superRemove is overwritten by a component that extends this one, so the local copy is called below.
|
|
262
|
+
const superRemove = box.remove;
|
|
263
|
+
box.superRemove = superRemove;
|
|
264
|
+
box.remove = function () {
|
|
265
|
+
if (!box) return; // WHY: remove() can be called twice (also by the parent's remove()).
|
|
266
|
+
removeFromGroup();
|
|
267
|
+
superRemove.call(box);
|
|
268
|
+
box = null;
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
// *** OBJECT VIEW:
|
|
272
|
+
box.clickable = 1;
|
|
273
|
+
box.role = "radio";
|
|
274
|
+
box.css = { outline: "none", userSelect: "none" };
|
|
275
|
+
box.setMotion("background-color " + MOTION_DURATION);
|
|
276
|
+
|
|
277
|
+
// GROUP: mark, label
|
|
278
|
+
box.contentBox = HGroup({
|
|
279
|
+
width: "auto",
|
|
280
|
+
height: "auto",
|
|
281
|
+
position: "relative",
|
|
282
|
+
...box.style.layout,
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
// LABEL: label (left or right of the mark)
|
|
286
|
+
const createLabel = function () {
|
|
287
|
+
box.label = Label(box.style.label);
|
|
288
|
+
setText(box.label, box.labelText);
|
|
289
|
+
box.label.css.whiteSpace = "nowrap";
|
|
290
|
+
if (!box.labelText) box.label.visible = 0;
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
if (box.labelPosition === "left") createLabel();
|
|
294
|
+
|
|
295
|
+
// BOX: mark (circle)
|
|
296
|
+
box.mark = startBox({
|
|
297
|
+
width: box.style.mark.width,
|
|
298
|
+
height: box.style.mark.height,
|
|
299
|
+
color: box.style.mark.color,
|
|
300
|
+
border: box.style.mark.border,
|
|
301
|
+
borderColor: box.style.mark.borderColor,
|
|
302
|
+
round: box.style.mark.round,
|
|
303
|
+
});
|
|
304
|
+
box.mark.setMotion("background-color " + MOTION_DURATION + ", border-color " + MOTION_DURATION);
|
|
305
|
+
box.mark.css.boxSizing = "border-box";
|
|
306
|
+
showFocusOnMark();
|
|
307
|
+
|
|
308
|
+
// BOX: dot (inner circle)
|
|
309
|
+
const innerWidth = box.style.mark.width - (box.style.mark.border * 2);
|
|
310
|
+
const innerHeight = box.style.mark.height - (box.style.mark.border * 2);
|
|
311
|
+
// WHY: The space is rounded first and the dot size comes from it,
|
|
312
|
+
// so the space is the same on both sides and the dot stays in the exact center.
|
|
313
|
+
const spaceX = Math.round((innerWidth - (innerWidth * box.style.dot.size)) / 2);
|
|
314
|
+
const spaceY = Math.round((innerHeight - (innerHeight * box.style.dot.size)) / 2);
|
|
315
|
+
|
|
316
|
+
box.dot = Box({
|
|
317
|
+
left: spaceX,
|
|
318
|
+
top: spaceY,
|
|
319
|
+
width: innerWidth - (spaceX * 2),
|
|
320
|
+
height: innerHeight - (spaceY * 2),
|
|
321
|
+
color: box.style.dot.color,
|
|
322
|
+
round: box.style.dot.round,
|
|
323
|
+
});
|
|
324
|
+
box.dot.css.transition = "transform " + MOTION_DURATION + ", opacity " + MOTION_DURATION;
|
|
325
|
+
|
|
326
|
+
endBox();
|
|
327
|
+
|
|
328
|
+
if (box.labelPosition !== "left") createLabel();
|
|
329
|
+
|
|
330
|
+
endGroup();
|
|
331
|
+
|
|
332
|
+
// *** OBJECT INIT CODE:
|
|
333
|
+
|
|
334
|
+
box.on("click", function (self, event) {
|
|
335
|
+
if (box.enabled == 1) box.select();
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
box.on("keydown", function (self, event) {
|
|
339
|
+
if (box.enabled != 1) return;
|
|
340
|
+
switch (event.key) {
|
|
341
|
+
case " ":
|
|
342
|
+
case "Enter":
|
|
343
|
+
event.preventDefault();
|
|
344
|
+
box.select();
|
|
345
|
+
break;
|
|
346
|
+
case "ArrowDown":
|
|
347
|
+
case "ArrowRight":
|
|
348
|
+
event.preventDefault();
|
|
349
|
+
moveSelection(1);
|
|
350
|
+
break;
|
|
351
|
+
case "ArrowUp":
|
|
352
|
+
case "ArrowLeft":
|
|
353
|
+
event.preventDefault();
|
|
354
|
+
moveSelection(-1);
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
box.on("mouseover", function () {
|
|
360
|
+
isMouseOver = 1;
|
|
361
|
+
paint();
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
box.on("mouseout", function () {
|
|
365
|
+
isMouseOver = 0;
|
|
366
|
+
paint();
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
getGroupList().push(box);
|
|
370
|
+
|
|
371
|
+
box.enabled = basic.isOn(box.enabled) ? 1 : 0;
|
|
372
|
+
const isCheckedAtStart = basic.isOn(box.checked);
|
|
373
|
+
// WHY: setChecked() below must see a change, so it unchecks the others (the last checked one in the group wins).
|
|
374
|
+
box.checked = 0;
|
|
375
|
+
paint();
|
|
376
|
+
if (isCheckedAtStart) box.setChecked(1, 1);
|
|
377
|
+
|
|
378
|
+
return endObject(box);
|
|
379
|
+
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
// *** STATIC FUNCTIONS (GROUP):
|
|
383
|
+
|
|
384
|
+
// Shared group list: { groupName: [radioButton, ...] }
|
|
385
|
+
RadioButton.groups = {};
|
|
386
|
+
|
|
387
|
+
// Returns the radio button list of a group.
|
|
388
|
+
RadioButton.getGroup = function (group = "default") {
|
|
389
|
+
if (!RadioButton.groups[group]) RadioButton.groups[group] = [];
|
|
390
|
+
return RadioButton.groups[group];
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
// Returns the selected radio button of a group. (or null)
|
|
394
|
+
RadioButton.getSelected = function (group = "default") {
|
|
395
|
+
return RadioButton.getGroup(group).find(function (radio) { return radio.checked == 1; }) || null;
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
// Returns the value of the selected radio button. (or "")
|
|
399
|
+
RadioButton.getValue = function (group = "default") {
|
|
400
|
+
const selected = RadioButton.getSelected(group);
|
|
401
|
+
return (selected) ? selected.value : "";
|
|
402
|
+
};
|
|
403
|
+
// USAGE: RadioButton.getValue("size")
|
|
404
|
+
|
|
405
|
+
// Selects the radio button that has this value.
|
|
406
|
+
RadioButton.setValue = function (group = "default", value, silent = 0) {
|
|
407
|
+
const radio = RadioButton.getGroup(group).find(function (r) { return r.value === value; });
|
|
408
|
+
if (radio) radio.setChecked(1, silent);
|
|
409
|
+
};
|
|
410
|
+
// USAGE: RadioButton.setValue("size", "M")
|
|
411
|
+
|
|
412
|
+
// Unselects all radio buttons of a group.
|
|
413
|
+
RadioButton.clear = function (group = "default") {
|
|
414
|
+
RadioButton.getGroup(group).forEach(function (radio) { radio._uncheck(); });
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
// *** STYLE PACKAGES:
|
|
418
|
+
// USAGE: RadioButton({ styleName: "modern" })
|
|
419
|
+
// USAGE: RadioButton({ styleName: "modern", style: { dot: { color: "tomato" } } }) // Change only some keys.
|
|
420
|
+
// USAGE: RadioButton({ style: RadioButton.styles.modern }) // The same as styleName: "modern". (The package is copied, never changed.)
|
|
421
|
+
// NOTE: A new package needs only the keys that differ from the default (classic) style.
|
|
422
|
+
// USAGE: RadioButton.styles.myStyle = { dot: { color: "red" } };
|
|
423
|
+
RadioButton.styles = {
|
|
424
|
+
|
|
425
|
+
// White circle with a border. When checked, dark border and dark dot. No background.
|
|
426
|
+
light: RadioButtonDefaults.style,
|
|
427
|
+
|
|
428
|
+
// Light circle, thin border. When checked, the dot in a white circle with an edge.
|
|
429
|
+
modern: {
|
|
430
|
+
box: { // Whole object background
|
|
431
|
+
color: "transparent",
|
|
432
|
+
round: 8,
|
|
433
|
+
},
|
|
434
|
+
hoverBox: { // Mouse over (whole object background)
|
|
435
|
+
color: "whitesmoke", // null: uses box.color
|
|
436
|
+
},
|
|
437
|
+
checkedBox: { // Checked (whole object background)
|
|
438
|
+
color: "#EFF5F6", // 10% of dot color on white. null: uses box.color
|
|
439
|
+
},
|
|
440
|
+
hoverCheckedBox: { // Checked and mouse over (whole object background)
|
|
441
|
+
color: "#DFECEC", // 20% of dot color on white. null: uses checkedBox.color
|
|
442
|
+
},
|
|
443
|
+
layout: {
|
|
444
|
+
gap: 12,
|
|
445
|
+
padding: [12, 10],
|
|
446
|
+
align: "left center",
|
|
447
|
+
},
|
|
448
|
+
mark: { // Unchecked circle
|
|
449
|
+
width: 22,
|
|
450
|
+
height: 22,
|
|
451
|
+
color: "whitesmoke",
|
|
452
|
+
border: 1,
|
|
453
|
+
borderColor: Black(0.7),
|
|
454
|
+
round: 100,
|
|
455
|
+
},
|
|
456
|
+
checkedMark: { // Checked circle: white with an edge, behind the dot
|
|
457
|
+
color: "white",
|
|
458
|
+
borderColor: Black(0.7),
|
|
459
|
+
},
|
|
460
|
+
hoverMark: { // Mouse over: the empty circle turns white
|
|
461
|
+
color: "white",
|
|
462
|
+
borderColor: Black(0.7),
|
|
463
|
+
},
|
|
464
|
+
dot: {
|
|
465
|
+
color: "cadetblue", // #5F9EA0
|
|
466
|
+
size: 0.5, // Ratio of the inner circle size (0 - 1)
|
|
467
|
+
round: 100,
|
|
468
|
+
},
|
|
469
|
+
label: {
|
|
470
|
+
fontSize: 16,
|
|
471
|
+
textColor: Black(0.85),
|
|
472
|
+
},
|
|
473
|
+
disabled: {
|
|
474
|
+
opacity: 0.4,
|
|
475
|
+
},
|
|
476
|
+
},
|
|
477
|
+
|
|
478
|
+
// Dark theme (the Ozden Panel colors, same as CheckBox "dark"): the classic shape on a dark page.
|
|
479
|
+
// NOTE: Only the keys that differ from classic.
|
|
480
|
+
dark: {
|
|
481
|
+
mark: { // Unchecked circle
|
|
482
|
+
color: "#2A2A29",
|
|
483
|
+
borderColor: White(0.3),
|
|
484
|
+
},
|
|
485
|
+
checkedMark: { // Checked circle
|
|
486
|
+
color: "#2A2A29",
|
|
487
|
+
borderColor: "#65A293", // WHY: lighter than the CheckBox fill (#3D7A6B): a thin line and a small dot need it.
|
|
488
|
+
},
|
|
489
|
+
hoverMark: { // Mouse over (only border)
|
|
490
|
+
borderColor: White(0.6),
|
|
491
|
+
},
|
|
492
|
+
dot: {
|
|
493
|
+
color: "#65A293",
|
|
494
|
+
},
|
|
495
|
+
label: {
|
|
496
|
+
textColor: White(0.85),
|
|
497
|
+
},
|
|
498
|
+
},
|
|
499
|
+
|
|
500
|
+
};
|
|
501
|
+
RadioButton.styles.classic = RadioButton.styles.light; // the old name of light: the pages made with it keep their look
|
|
502
|
+
|
|
503
|
+
// The minimal theme (_designs/minimal-theme.htm): a 14 px circle of a line, darker under the mouse; when checked an ink
|
|
504
|
+
// line and a 6 px ink dot inside it, no fill; a 13 px text.
|
|
505
|
+
// WHY a strong line: the line is the only thing that shows an empty mark (3:1 at least, as WCAG asks of a control)
|
|
506
|
+
RadioButton.createMinimalStyle = function (colors) {
|
|
507
|
+
return {
|
|
508
|
+
layout: { gap: 8, padding: [0, 2], align: "left center" },
|
|
509
|
+
mark: { width: 14, height: 14, color: "transparent", border: 1, borderColor: colors.line, round: 100 },
|
|
510
|
+
checkedMark: { color: "transparent", borderColor: colors.ink },
|
|
511
|
+
hoverMark: { color: null, borderColor: colors.lineHover },
|
|
512
|
+
dot: { color: colors.ink, size: 0.5, round: 100 },
|
|
513
|
+
label: { fontSize: 13, textColor: colors.text },
|
|
514
|
+
disabled: { opacity: 0.4 },
|
|
515
|
+
focus: { ringColor: colors.focus },
|
|
516
|
+
};
|
|
517
|
+
};
|
|
518
|
+
RadioButton.MINIMAL_COLORS = { line: Black(0.45), lineHover: Black(0.65), ink: "#1F1F1F", text: Black(0.85), focus: "#3D8BD9" };
|
|
519
|
+
RadioButton.styles.minimal = RadioButton.createMinimalStyle(RadioButton.MINIMAL_COLORS);
|
|
520
|
+
RadioButton.MINIMAL_DARK_COLORS = { line: White(0.42), lineHover: White(0.62), ink: "#EDEDEB", text: White(0.88), focus: "#7FB6DE" };
|
|
521
|
+
RadioButton.styles.minimalDark = RadioButton.createMinimalStyle(RadioButton.MINIMAL_DARK_COLORS);
|
|
522
|
+
|
|
523
|
+
// The rule of the keyboard focus (style.focus.ringColor). WHY !important: the edge of the mark is an inline style.
|
|
524
|
+
RadioButton.addFocusCss = function () {
|
|
525
|
+
basic.addCss("radio-button-focus", ".radio-button-focus:focus { outline: none; }" +
|
|
526
|
+
".radio-button-focus:focus-visible .radio-button-mark { border-color: var(--radio-button-focus) !important; box-shadow: inset 0 0 0 1px var(--radio-button-focus); }");
|
|
527
|
+
};
|