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,757 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
Toggle - v25.08
|
|
5
|
+
|
|
6
|
+
UI COMPONENT TEMPLATE
|
|
7
|
+
- An on / off switch: a round knob (box.button) slides on a track (box.background). A click switches it.
|
|
8
|
+
- Style packages: "ozden" (default: the knob is smaller when off), "ozdenDark" (for a dark page), "light" and
|
|
9
|
+
"dark" (the light and dark look of the kit), "classic" and more shapes (toggle-2.htm). Select with styleName.
|
|
10
|
+
(Toggle.styles)
|
|
11
|
+
-- "ozden": a darker line around the colored track when on (selectedBorderColor: the light
|
|
12
|
+
look had no clear edge when on). Its size: 70 x 40, a round knob.
|
|
13
|
+
When on, a shadow to the left of the knob and a thin line around it, so the white knob stands
|
|
14
|
+
out on the track (buttonStyle.selectedShadow). A page with its own selectedShadow keeps that.
|
|
15
|
+
-- "light" / "dark" (_designs/toggle.htm): a flat pill track of 52 x 30 that turns to the accent of the kit when on, a
|
|
16
|
+
white (dark: light gray) knob of the same size on and off with a soft shadow, 12 px marks. A mark in the knob
|
|
17
|
+
(markPlace "knob"): give it a dark color, markStyle: { color: Black(0.6), selectedColor: Black(0.6) }.
|
|
18
|
+
-- "classic": for a 600 px design: 60 x 40, a light
|
|
19
|
+
gray track that turns blue, a white knob of the same size on and off, with a shadow.
|
|
20
|
+
-- A package is a package of params (basic.js v26.10.27): its keys fill the params you did not give, also the
|
|
21
|
+
keys inside backgroundStyle and buttonStyle (Ex: the classic package with your own selectedColor).
|
|
22
|
+
-- "float", "round", "slim", "outline", "square": other shapes, with their sizes, in soft colors
|
|
23
|
+
(the "Soft" palette of basic.js Designer). "float": a knob bigger than its track, "round": a big knob, "slim": a low
|
|
24
|
+
track, "outline": a line around the track when off, "square": small corners.
|
|
25
|
+
-- "tick", "badge", "label": with marks. "tick": a check or a cross on the track, "badge": in the knob, on a green or
|
|
26
|
+
red track, "label": ON / OFF on the track, small corners.
|
|
27
|
+
- onMark, offMark: what shows when on / off: "check", "cross" or a text ("ON"). "": nothing. setMarks() changes them.
|
|
28
|
+
markPlace: "track" (on the free side of the track) or "knob" (in the knob). markStyle: its size and colors.
|
|
29
|
+
- animated: 1 (the default) gives a toggle with marks small motions (not at the first view): a drawn mark (check,
|
|
30
|
+
cross) on the track grows in behind the knob, in the knob it turns in with a small spring, it grows a little under
|
|
31
|
+
the mouse; the knob gets flatter while pressed. A text mark (ON / OFF) has no motion: it shows and goes at once. A
|
|
32
|
+
toggle without marks does not change. Off with prefers-reduced-motion. setAnimated().
|
|
33
|
+
- offButtonScale: the size of the knob when off (1: the same size as on).
|
|
34
|
+
- focusRingColor: the ring of the keyboard focus ("": the ring of basic.js). The ring follows the round of the track.
|
|
35
|
+
- backgroundStyle.selectedBorderColor: the line of the track when on ("": the same as borderColor). A page that gives
|
|
36
|
+
its own borderColor and no selectedBorderColor keeps that line when on too (the line of "ozden" when on is for
|
|
37
|
+
its own colors).
|
|
38
|
+
- backgroundStyle.left, top, width, height: a track of another size than the box (Ex: "float").
|
|
39
|
+
- buttonStyle.shadow / buttonStyle.selectedShadow: the shadow of the knob when off / on.
|
|
40
|
+
|
|
41
|
+
USAGE:
|
|
42
|
+
const toggle = Toggle({ value: 1, onChange: (self) => println(self.value) });
|
|
43
|
+
toggle.switch();
|
|
44
|
+
toggle.setValue(0); // onChange is called
|
|
45
|
+
toggle.setValue(1, 1); // silent: onChange is not called
|
|
46
|
+
toggle.setBackgroundSelectedColor("tomato");
|
|
47
|
+
Toggle({ styleName: "classic" });
|
|
48
|
+
Toggle({ styleName: "classic", backgroundStyle: { selectedColor: "#6AC966" } }); // A green classic toggle
|
|
49
|
+
Toggle({ styleName: "outline" });
|
|
50
|
+
Toggle({ onMark: "check", offMark: "cross", markPlace: "knob" });
|
|
51
|
+
Toggle({ styleName: "label", onMark: "AÇIK", offMark: "KAPALI", width: 92 }); // A param you give wins.
|
|
52
|
+
Toggle({ styleName: "badge", animated: 0 }); // No motion
|
|
53
|
+
|
|
54
|
+
Started Date: August 2025
|
|
55
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
56
|
+
|
|
57
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
58
|
+
Licensed under the Apache License, Version 2.0
|
|
59
|
+
SPDX-License-Identifier: Apache-2.0
|
|
60
|
+
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
"use strict";
|
|
64
|
+
|
|
65
|
+
// Default values:
|
|
66
|
+
const ToggleDefaults = {
|
|
67
|
+
key: "0",
|
|
68
|
+
width: 70, // Standard box features are added automatically.
|
|
69
|
+
height: 40,
|
|
70
|
+
spacing: 3, // px: between the track and the knob
|
|
71
|
+
value: 0,
|
|
72
|
+
invertColor: 0,
|
|
73
|
+
offButtonScale: 0.6, // The size of the knob when off. (1: the same size as on)
|
|
74
|
+
onMark: "", // Shows when on: "check", "cross" or a text ("ON"). "": nothing
|
|
75
|
+
offMark: "", // Shows when off
|
|
76
|
+
markPlace: "track", // "track": on the free side of the track, "knob": in the knob (Only at create time)
|
|
77
|
+
animated: 1, // 1: small motions of a toggle with marks. (box.setAnimated(0/1))
|
|
78
|
+
focusRingColor: "", // the ring of the keyboard focus. "": the ring of basic.js
|
|
79
|
+
markStyle: {
|
|
80
|
+
size: 16, // px: a check or a cross
|
|
81
|
+
lineWidth: 3.5, // of a check or a cross, on a 24 px grid
|
|
82
|
+
fontSize: 12, // a text
|
|
83
|
+
color: Black(0.5), // off
|
|
84
|
+
selectedColor: White(0.95), // on
|
|
85
|
+
},
|
|
86
|
+
onChange: function(self) {}, // self.value changed (a click, a key, setValue()). Not at create time, not with setValue(value, 1)
|
|
87
|
+
backgroundStyle: { // The track
|
|
88
|
+
color: "whitesmoke", // off
|
|
89
|
+
selectedColor: "#689BD2", // on
|
|
90
|
+
border: 1,
|
|
91
|
+
borderColor: Black(0.05),
|
|
92
|
+
selectedBorderColor: "", // on. "": the same as borderColor
|
|
93
|
+
round: 100,
|
|
94
|
+
},
|
|
95
|
+
buttonStyle: { // The knob
|
|
96
|
+
color: Black(0.15), // off
|
|
97
|
+
selectedColor: White(0.95), // on
|
|
98
|
+
border: 0,
|
|
99
|
+
round: 100,
|
|
100
|
+
shadow: "none", // off
|
|
101
|
+
selectedShadow: "-1px 0px 4px rgba(0, 0, 0, 0.15)", // on
|
|
102
|
+
},
|
|
103
|
+
styleName: "ozden", // "ozden", "ozdenDark", "light", "dark", "classic", "float", "round", "slim", "outline", "square", "tick", "badge", "label", "minimal", "minimalDark" or a name added to Toggle.styles
|
|
104
|
+
style: {}, // WHY: the look is in the params above; the packages are packages of params (see Toggle.styles).
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const Toggle = function(params = {}) {
|
|
108
|
+
|
|
109
|
+
// WHY copies: a page gives the same styles to many toggles ({ ...DARK_TOGGLE }); the merges below and
|
|
110
|
+
// setBackgroundSelectedColor() wrote into them, so one toggle changed the others.
|
|
111
|
+
["backgroundStyle", "buttonStyle", "markStyle"].forEach(function(name) {
|
|
112
|
+
if (params[name]) params[name] = Object.assign({}, params[name]);
|
|
113
|
+
});
|
|
114
|
+
// WHY: a page that gives its own line of the track (borderColor) keeps it when on too, as before: the line
|
|
115
|
+
// of a package when on (ozden: selectedBorderColor) is for the colors of that package.
|
|
116
|
+
const ownStyle = params.backgroundStyle || {};
|
|
117
|
+
const keepsOwnLine = (ownStyle.borderColor !== undefined && ownStyle.selectedBorderColor === undefined);
|
|
118
|
+
|
|
119
|
+
// Merge style package: your params > Toggle.styles[styleName] (a package of params) > ToggleDefaults
|
|
120
|
+
basic.applyStylePackage(params, Toggle.styles, ToggleDefaults);
|
|
121
|
+
|
|
122
|
+
// Merge params:
|
|
123
|
+
mergeIntoIfMissing(params, ToggleDefaults);
|
|
124
|
+
if (keepsOwnLine) params.backgroundStyle.selectedBorderColor = ""; // ("": the line of borderColor)
|
|
125
|
+
|
|
126
|
+
// Edit params, if needed:
|
|
127
|
+
// WHY: a switch keeps its size in a row: a narrow row made it narrower than its knob needs (the knob is placed
|
|
128
|
+
// for its width). A page can give shrink: 1.
|
|
129
|
+
if (params.shrink === undefined) params.shrink = 0;
|
|
130
|
+
params.color = "transparent";
|
|
131
|
+
params.clickable = 1;
|
|
132
|
+
params.clipContent = 0;
|
|
133
|
+
|
|
134
|
+
// BOX: Component container
|
|
135
|
+
let box = startObject(params);
|
|
136
|
+
|
|
137
|
+
// NOTE: Parent container is box.containerBox
|
|
138
|
+
|
|
139
|
+
// *** PRIVATE VARIABLES:
|
|
140
|
+
let buttonSize = 0; // Set by box.refresh() from the size of the box.
|
|
141
|
+
let distance = 0; // How far the button moves when it is on.
|
|
142
|
+
const HOVER_BRIGHTNESS = "103%";
|
|
143
|
+
const DISABLED_BRIGHTNESS = "90%";
|
|
144
|
+
const DISABLED_OPACITY = 0.75;
|
|
145
|
+
|
|
146
|
+
const isMarkInKnob = (box.markPlace === "knob");
|
|
147
|
+
let isPressed = false; // The knob gets flatter while it is pressed (animated)
|
|
148
|
+
let wasAnimated = false;
|
|
149
|
+
|
|
150
|
+
// animated: 1
|
|
151
|
+
const MOTION_TIME = "0.2s";
|
|
152
|
+
const MOTION_EASE = "cubic-bezier(0.2, 0.8, 0.2, 1)"; // a fast start and a soft stop
|
|
153
|
+
const SPRING_TIME = "0.25s";
|
|
154
|
+
const SPRING_EASE = "cubic-bezier(0.34, 1.56, 0.64, 1)"; // a small overshoot: a mark that turns in the knob
|
|
155
|
+
const HIDDEN_MARK_SCALE = 0.6;
|
|
156
|
+
const HIDDEN_MARK_TURN = 90; // deg: a mark in the knob
|
|
157
|
+
const HIDDEN_MARK_SHIFT = 6; // px: a mark on the track stays behind the knob that leaves
|
|
158
|
+
const HOVER_ICON_SCALE = 1.1;
|
|
159
|
+
const PRESSED_KNOB_SCALE_X = 1.1;
|
|
160
|
+
const PRESSED_KNOB_SCALE_Y = 0.92;
|
|
161
|
+
|
|
162
|
+
// *** PRIVATE FUNCTIONS:
|
|
163
|
+
|
|
164
|
+
const hasMarks = () => !!(box.onMark || box.offMark);
|
|
165
|
+
|
|
166
|
+
// WHY only a drawn mark (check, cross) moves: a small motion of a text (ON / OFF) looked like a fault.
|
|
167
|
+
const isMovingMark = (mark) => !!Toggle.MARK_PATHS[mark];
|
|
168
|
+
|
|
169
|
+
const isMotionOn = function() {
|
|
170
|
+
if (box.animated != 1 || !hasMarks()) return false;
|
|
171
|
+
const reduceMotion = window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
172
|
+
return !reduceMotion;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
// The knob: its size and its place. Flatter while it is pressed (animated).
|
|
176
|
+
const getKnobTransform = function() {
|
|
177
|
+
const isOn = (box.state === "selected");
|
|
178
|
+
const moved = `translateX(${isOn ? distance : 0}px)`;
|
|
179
|
+
if (isPressed && isMotionOn()) return `${moved} scale(${PRESSED_KNOB_SCALE_X}, ${PRESSED_KNOB_SCALE_Y})`;
|
|
180
|
+
// WHY this order: with animated: 0 the transform text stays as it always was.
|
|
181
|
+
return `scale(${isOn ? 1 : box.offButtonScale}) ${moved}`;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
const getHiddenMarkTransform = function(isOnMark) {
|
|
185
|
+
const direction = isOnMark ? 1 : -1;
|
|
186
|
+
if (isMarkInKnob) return `rotate(${direction * HIDDEN_MARK_TURN}deg) scale(${HIDDEN_MARK_SCALE})`;
|
|
187
|
+
return `translateX(${-direction * HIDDEN_MARK_SHIFT}px) scale(${HIDDEN_MARK_SCALE})`;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const getShownMarkTransform = function() {
|
|
191
|
+
if (box.secondState !== "mouseover") return "none";
|
|
192
|
+
return `scale(${HOVER_ICON_SCALE})`;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
const getMarkTransform = function(mark, isShown, isOnMark) {
|
|
196
|
+
if (!isMovingMark(mark)) return "none";
|
|
197
|
+
return isShown ? getShownMarkTransform() : getHiddenMarkTransform(isOnMark);
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
// The look of the state of the marks. (Nothing when animated is off.)
|
|
201
|
+
const paintMotion = function() {
|
|
202
|
+
box.button.css.transform = getKnobTransform();
|
|
203
|
+
if (!isMotionOn()) return;
|
|
204
|
+
const isOn = (box.state === "selected");
|
|
205
|
+
box.onMarkBox.css.transform = getMarkTransform(box.onMark, isOn, true);
|
|
206
|
+
box.offMarkBox.css.transform = getMarkTransform(box.offMark, !isOn, false);
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
const setPressed = function(value) {
|
|
210
|
+
isPressed = value;
|
|
211
|
+
paintMotion();
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// The transitions and the still look of animated: 0.
|
|
215
|
+
const applyAnimated = function() {
|
|
216
|
+
const isOn = isMotionOn();
|
|
217
|
+
if (!isOn && !wasAnimated) return;
|
|
218
|
+
const transformMotion = isMarkInKnob ? SPRING_TIME + " " + SPRING_EASE : MOTION_TIME + " " + MOTION_EASE;
|
|
219
|
+
[[box.onMarkBox, box.onMark], [box.offMarkBox, box.offMark]].forEach(function([markBox, mark]) {
|
|
220
|
+
const isMoving = isOn && isMovingMark(mark);
|
|
221
|
+
markBox.setMotion(isMoving ? `opacity ${MOTION_TIME} ${MOTION_EASE}, transform ${transformMotion}` : "none");
|
|
222
|
+
if (!isMoving) markBox.css.transform = "none";
|
|
223
|
+
});
|
|
224
|
+
wasAnimated = isOn;
|
|
225
|
+
paintMotion();
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
// The picture of a mark: Toggle.MARK_PATHS, drawn in its color.
|
|
229
|
+
const getMarkIcon = function(path, color) {
|
|
230
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="${color}"`
|
|
231
|
+
+ ` stroke-width="${box.markStyle.lineWidth}" stroke-linecap="round" stroke-linejoin="round"><path d="${path}"/></svg>`;
|
|
232
|
+
return "data:image/svg+xml;charset=utf-8," + encodeURIComponent(svg);
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const drawMark = function(markBox, mark, color) {
|
|
236
|
+
const _m = box.markStyle;
|
|
237
|
+
markBox.children.forEach((child) => child.remove());
|
|
238
|
+
if (!mark) return;
|
|
239
|
+
const path = Toggle.MARK_PATHS[mark];
|
|
240
|
+
createIn(markBox, function() {
|
|
241
|
+
if (path) {
|
|
242
|
+
Icon({ width: _m.size, height: _m.size }).load(getMarkIcon(path, color));
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
Label({ plainText: mark, fontSize: _m.fontSize, bold: 1, textColor: color, css: { whiteSpace: "nowrap" } });
|
|
246
|
+
});
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const createMarkBox = function() {
|
|
250
|
+
const markBox = HGroup({ left: 0, top: 0, width: "100%", height: "100%", align: "center center", opacity: 0 });
|
|
251
|
+
endGroup();
|
|
252
|
+
return markBox;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const createMarks = function() {
|
|
256
|
+
box.onMarkBox = createMarkBox();
|
|
257
|
+
box.offMarkBox = createMarkBox();
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
// WHY only on the track: a mark in the knob fills the knob and moves with it.
|
|
261
|
+
const placeMarks = function() {
|
|
262
|
+
if (isMarkInKnob) return;
|
|
263
|
+
box.onMarkBox.props({ left: box.spacing, width: distance });
|
|
264
|
+
box.offMarkBox.props({ left: box.spacing + buttonSize, width: distance });
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
// *** PUBLIC VARIABLES:
|
|
268
|
+
box.state = ""; // "normal", "selected"
|
|
269
|
+
box.secondState = ""; // "normal", "mouseover", "disabled"
|
|
270
|
+
|
|
271
|
+
// *** PUBLIC FUNCTIONS:
|
|
272
|
+
box.switch = function() {
|
|
273
|
+
box.setValue((box.value === 1) ? 0 : 1);
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
// silent: 1 -> onChange is not called.
|
|
277
|
+
box.setValue = function(value, silent = 0) {
|
|
278
|
+
|
|
279
|
+
if (value === box.value) return; // the same value: nothing to draw, no onChange
|
|
280
|
+
box.value = value;
|
|
281
|
+
|
|
282
|
+
box.setState((value === 1) ? "selected" : "normal");
|
|
283
|
+
if (!silent) box.onChange(box);
|
|
284
|
+
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
box.setBackgroundSelectedColor = function(color) {
|
|
288
|
+
box.backgroundStyle.selectedColor = color;
|
|
289
|
+
if (box.value === 1) box.background.color = color;
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
box.setState = function(state) {
|
|
293
|
+
|
|
294
|
+
box.state = state;
|
|
295
|
+
box.aria = { checked: state === "selected" };
|
|
296
|
+
|
|
297
|
+
switch(state) {
|
|
298
|
+
|
|
299
|
+
case "normal":
|
|
300
|
+
|
|
301
|
+
box.button.color = box.buttonStyle.color;
|
|
302
|
+
box.button.boxShadow = box.buttonStyle.shadow;
|
|
303
|
+
box.background.color = box.backgroundStyle.color;
|
|
304
|
+
box.background.borderColor = box.backgroundStyle.borderColor;
|
|
305
|
+
box.onMarkBox.opacity = 0;
|
|
306
|
+
box.offMarkBox.opacity = 1;
|
|
307
|
+
|
|
308
|
+
break;
|
|
309
|
+
|
|
310
|
+
case "selected":
|
|
311
|
+
|
|
312
|
+
box.button.color = box.buttonStyle.selectedColor;
|
|
313
|
+
box.button.boxShadow = box.buttonStyle.selectedShadow;
|
|
314
|
+
box.background.color = box.backgroundStyle.selectedColor;
|
|
315
|
+
box.background.borderColor = box.backgroundStyle.selectedBorderColor || box.backgroundStyle.borderColor;
|
|
316
|
+
box.onMarkBox.opacity = 1;
|
|
317
|
+
box.offMarkBox.opacity = 0;
|
|
318
|
+
|
|
319
|
+
break;
|
|
320
|
+
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
paintMotion();
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
box.setMarks = function(onMark, offMark) {
|
|
327
|
+
box.onMark = onMark;
|
|
328
|
+
box.offMark = offMark;
|
|
329
|
+
drawMark(box.onMarkBox, onMark, box.markStyle.selectedColor);
|
|
330
|
+
drawMark(box.offMarkBox, offMark, box.markStyle.color);
|
|
331
|
+
applyAnimated();
|
|
332
|
+
};
|
|
333
|
+
// USAGE: toggle.setMarks("ON", "OFF")
|
|
334
|
+
|
|
335
|
+
box.setAnimated = function(value) {
|
|
336
|
+
box.animated = (value == 1) ? 1 : 0;
|
|
337
|
+
applyAnimated();
|
|
338
|
+
};
|
|
339
|
+
// USAGE: toggle.setAnimated(0)
|
|
340
|
+
|
|
341
|
+
box.setSecondState = function(state) {
|
|
342
|
+
|
|
343
|
+
box.secondState = state;
|
|
344
|
+
if (state !== "disabled") {
|
|
345
|
+
box.tabIndex = 0;
|
|
346
|
+
box.aria = { disabled: null };
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
switch(state) {
|
|
350
|
+
|
|
351
|
+
case "normal":
|
|
352
|
+
|
|
353
|
+
box.background.css.filter = "brightness(100%)";
|
|
354
|
+
box.opacity = 1;
|
|
355
|
+
box.clickable = 1;
|
|
356
|
+
paintMotion();
|
|
357
|
+
|
|
358
|
+
break;
|
|
359
|
+
|
|
360
|
+
case "mouseover":
|
|
361
|
+
|
|
362
|
+
box.background.css.filter = `brightness(${HOVER_BRIGHTNESS})`;
|
|
363
|
+
box.opacity = 1;
|
|
364
|
+
box.clickable = 1;
|
|
365
|
+
paintMotion();
|
|
366
|
+
|
|
367
|
+
break;
|
|
368
|
+
|
|
369
|
+
case "disabled":
|
|
370
|
+
|
|
371
|
+
box.background.css.filter = `brightness(${DISABLED_BRIGHTNESS})`;
|
|
372
|
+
box.opacity = DISABLED_OPACITY;
|
|
373
|
+
box.clickable = 0;
|
|
374
|
+
box.tabIndex = -1;
|
|
375
|
+
box.aria = { disabled: true };
|
|
376
|
+
|
|
377
|
+
break;
|
|
378
|
+
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
box.refresh = function() {
|
|
383
|
+
|
|
384
|
+
buttonSize = box.height - (box.spacing * 2);
|
|
385
|
+
distance = box.width - (box.spacing * 2) - buttonSize;
|
|
386
|
+
|
|
387
|
+
box.button.props({
|
|
388
|
+
left: box.spacing,
|
|
389
|
+
top: box.spacing,
|
|
390
|
+
width: buttonSize,
|
|
391
|
+
height: buttonSize,
|
|
392
|
+
});
|
|
393
|
+
placeMarks();
|
|
394
|
+
|
|
395
|
+
box.setState((box.value === 1) ? "selected" : "normal");
|
|
396
|
+
box.setSecondState(box.secondState || "normal");
|
|
397
|
+
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
// *** OBJECT VIEW:
|
|
401
|
+
box.cursor = "pointer";
|
|
402
|
+
box.role = "switch";
|
|
403
|
+
box.setFocusRing(box.focusRingColor || undefined);
|
|
404
|
+
box.round = box.backgroundStyle.round; // WHY: the ring of the focus follows the shape of the track
|
|
405
|
+
if(box.invertColor === 1) box.css.filter = "invert(100%)";
|
|
406
|
+
|
|
407
|
+
// BOX: background
|
|
408
|
+
box.background = Box(0, 0, "100%", "100%", box.backgroundStyle);
|
|
409
|
+
box.background.setMotion("background-color 0.2s, border-color 0.2s");
|
|
410
|
+
|
|
411
|
+
// GROUPS: The marks on the track (under the knob)
|
|
412
|
+
if (!isMarkInKnob) createMarks();
|
|
413
|
+
|
|
414
|
+
// BOX: The round button (it slides to the right when on)
|
|
415
|
+
box.button = Box(box.buttonStyle);
|
|
416
|
+
that.setMotion("transform 0.2s");
|
|
417
|
+
|
|
418
|
+
// GROUPS: The marks in the knob
|
|
419
|
+
if (isMarkInKnob) createIn(box.button, createMarks);
|
|
420
|
+
|
|
421
|
+
// *** OBJECT INIT CODE:
|
|
422
|
+
box.setMarks(box.onMark, box.offMark);
|
|
423
|
+
box.on("pointerdown", () => setPressed(true));
|
|
424
|
+
["pointerup", "pointerleave", "pointercancel"].forEach((name) => box.on(name, () => setPressed(false)));
|
|
425
|
+
box.on("click", function(self, event) {
|
|
426
|
+
if (box.secondState === "disabled") return; // WHY: as the keys: a click from code or assistive tools
|
|
427
|
+
box.switch();
|
|
428
|
+
});
|
|
429
|
+
box.on("keydown", function(self, event) {
|
|
430
|
+
const isPressKey = (event.key === " " || event.key === "Enter");
|
|
431
|
+
if (!isPressKey || event.repeat || box.secondState === "disabled") return;
|
|
432
|
+
event.preventDefault(); // WHY: Space would scroll the page.
|
|
433
|
+
box.switch();
|
|
434
|
+
});
|
|
435
|
+
// WHY the disabled check: a toggle disabled under the mouse (in its own onChange, while saving) was enabled again
|
|
436
|
+
// by the next mouseout (clickable 0 itself fires one; on a phone: the next tap anywhere)
|
|
437
|
+
box.on("mouseover", function(self, event) {
|
|
438
|
+
if (box.secondState === "disabled") return;
|
|
439
|
+
box.setSecondState("mouseover");
|
|
440
|
+
});
|
|
441
|
+
box.on("mouseout", function(self, event) {
|
|
442
|
+
if (box.secondState === "disabled") return;
|
|
443
|
+
box.setSecondState("normal");
|
|
444
|
+
});
|
|
445
|
+
box.onResize(function(self) {
|
|
446
|
+
box.refresh();
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
box.refresh();
|
|
450
|
+
applyAnimated(); // WHY after refresh(): the first paint has its place; the transitions do not move it.
|
|
451
|
+
|
|
452
|
+
return endObject(box);
|
|
453
|
+
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
// *** STYLE PACKAGES:
|
|
457
|
+
// The marks that are drawn: Toggle({ onMark: "check" }). (24 x 24, a line)
|
|
458
|
+
Toggle.MARK_PATHS = {
|
|
459
|
+
check: "M5 12.5l4.5 4.5L19 7.5",
|
|
460
|
+
cross: "M6.5 6.5l11 11M17.5 6.5l-11 11",
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
// USAGE: Toggle({ styleName: "classic" })
|
|
464
|
+
// USAGE: Toggle({ styleName: "classic", backgroundStyle: { selectedColor: "#6AC966" } }) // A param you give wins.
|
|
465
|
+
// NOTE: Every package has "style: {}": that is the mark of a package of params (basic.js v26.10.27).
|
|
466
|
+
// Without it the keys would go into params.style and change nothing.
|
|
467
|
+
// NOTE: A package needs only the params that differ from ToggleDefaults.
|
|
468
|
+
// USAGE: Toggle.styles.myStyle = { style: {}, backgroundStyle: { selectedColor: "tomato" } };
|
|
469
|
+
Toggle.styles = {
|
|
470
|
+
|
|
471
|
+
// The look of ToggleDefaults: a whitesmoke track that turns blue, a small gray knob that grows when on.
|
|
472
|
+
// A darker line around the colored track when on (the light look had no clear edge when on);
|
|
473
|
+
// a page with its own line (borderColor) keeps it.
|
|
474
|
+
// WHY the two shadows of the knob when on (the white knob did not stand out on its track):
|
|
475
|
+
// the first falls only to the left, its negative spread keeps it inside the track. The second is the thin line
|
|
476
|
+
// around the knob, in the strength of the line of the track. A real border would be gray over the white knob (no
|
|
477
|
+
// sharper edge), and it would need a color for each state.
|
|
478
|
+
ozden: {
|
|
479
|
+
style: {},
|
|
480
|
+
height: 36,
|
|
481
|
+
width: 65,
|
|
482
|
+
onMark: "ON", // Shows when on: "check", "cross" or a text ("ON"). "": nothing
|
|
483
|
+
offMark: "OFF", // Shows when off
|
|
484
|
+
backgroundStyle: { selectedBorderColor: Black(0.2) }, // over the color: a darker line of it
|
|
485
|
+
buttonStyle: {
|
|
486
|
+
selectedShadow: "-4px 0px 6px -1px rgba(0, 0, 0, 0.5), 0px 0px 0px 1px rgba(0, 0, 0, 0.2)",
|
|
487
|
+
},
|
|
488
|
+
},
|
|
489
|
+
|
|
490
|
+
// For a dark page: a black track that turns green, a soft knob (the dark card of toggle.htm).
|
|
491
|
+
ozdenDark: {
|
|
492
|
+
style: {},
|
|
493
|
+
height: 36,
|
|
494
|
+
width: 65,
|
|
495
|
+
onMark: "ON", // Shows when on: "check", "cross" or a text ("ON"). "": nothing
|
|
496
|
+
offMark: "OFF", // Shows when off
|
|
497
|
+
backgroundStyle: { color: "black", selectedColor: "#2C5A38", borderColor: White(0.25) },
|
|
498
|
+
buttonStyle: { color: White(0.25), selectedColor: White(0.75) },
|
|
499
|
+
markStyle: { color: White(0.6) }, // WHY: OFF on the black track; the black of the default was not seen
|
|
500
|
+
},
|
|
501
|
+
|
|
502
|
+
// The light look of the kit (_designs/toggle.htm): a flat gray pill that turns to the accent, a white knob of the
|
|
503
|
+
// same size on and off with a soft shadow.
|
|
504
|
+
light: {
|
|
505
|
+
style: {},
|
|
506
|
+
width: 52,
|
|
507
|
+
height: 30,
|
|
508
|
+
spacing: 3,
|
|
509
|
+
offButtonScale: 1,
|
|
510
|
+
focusRingColor: "rgba(61, 122, 107, 0.5)",
|
|
511
|
+
markStyle: { size: 12, lineWidth: 3, fontSize: 11, color: Black(0.45), selectedColor: "#FFFFFF" },
|
|
512
|
+
backgroundStyle: { color: "#D4D5D1", selectedColor: "#3D7A6B", border: 0, borderColor: "transparent", selectedBorderColor: "", round: 100 },
|
|
513
|
+
buttonStyle: { color: "#FFFFFF", selectedColor: "#FFFFFF", round: 100, shadow: "0 1px 2px rgba(0, 0, 0, 0.25)", selectedShadow: "0 1px 2px rgba(0, 0, 0, 0.25)" },
|
|
514
|
+
},
|
|
515
|
+
|
|
516
|
+
// The dark look of the kit: the same shapes on a dark page, a dark gray pill and a light knob.
|
|
517
|
+
dark: {
|
|
518
|
+
style: {},
|
|
519
|
+
width: 52,
|
|
520
|
+
height: 30,
|
|
521
|
+
spacing: 3,
|
|
522
|
+
offButtonScale: 1,
|
|
523
|
+
focusRingColor: "rgba(101, 162, 147, 0.55)",
|
|
524
|
+
markStyle: { size: 12, lineWidth: 3, fontSize: 11, color: White(0.7), selectedColor: "#0F1F1B" },
|
|
525
|
+
backgroundStyle: { color: "#3A3A38", selectedColor: "#65A293", border: 0, borderColor: "transparent", selectedBorderColor: "", round: 100 },
|
|
526
|
+
buttonStyle: { color: "#CFCFCD", selectedColor: "#FFFFFF", round: 100, shadow: "0 1px 2px rgba(0, 0, 0, 0.5)", selectedShadow: "0 1px 2px rgba(0, 0, 0, 0.5)" },
|
|
527
|
+
},
|
|
528
|
+
|
|
529
|
+
// For a 600 px design:
|
|
530
|
+
// a light gray track that turns blue, a white knob of the same size on and off; its shadow falls to the
|
|
531
|
+
// middle of the track.
|
|
532
|
+
classic: {
|
|
533
|
+
style: {},
|
|
534
|
+
width: 60,
|
|
535
|
+
height: 40,
|
|
536
|
+
spacing: 4, // WHY: a 32 px knob (40 - 2 x spacing)
|
|
537
|
+
offButtonScale: 1,
|
|
538
|
+
backgroundStyle: {
|
|
539
|
+
color: "lightgray",
|
|
540
|
+
selectedColor: "#3871E0",
|
|
541
|
+
border: 0,
|
|
542
|
+
},
|
|
543
|
+
buttonStyle: {
|
|
544
|
+
color: "white",
|
|
545
|
+
selectedColor: "white",
|
|
546
|
+
shadow: "1px 0px 6px rgba(0, 0, 0, 0.3)",
|
|
547
|
+
selectedShadow: "-1px 0px 6px rgba(0, 0, 0, 0.6)",
|
|
548
|
+
},
|
|
549
|
+
},
|
|
550
|
+
|
|
551
|
+
// WHY the track has its own place: the 30 px knob is bigger than the 26 px track.
|
|
552
|
+
float: {
|
|
553
|
+
style: {},
|
|
554
|
+
width: 56,
|
|
555
|
+
height: 30,
|
|
556
|
+
spacing: 0,
|
|
557
|
+
offButtonScale: 1,
|
|
558
|
+
backgroundStyle: {
|
|
559
|
+
left: 1,
|
|
560
|
+
top: 2,
|
|
561
|
+
width: 54,
|
|
562
|
+
height: 26,
|
|
563
|
+
color: "#F1F1F1",
|
|
564
|
+
selectedColor: "#CFC3DD", // lavender
|
|
565
|
+
border: 0,
|
|
566
|
+
round: 20,
|
|
567
|
+
},
|
|
568
|
+
buttonStyle: {
|
|
569
|
+
color: "white",
|
|
570
|
+
selectedColor: "#8E8EB3", // periwinkle
|
|
571
|
+
round: 16,
|
|
572
|
+
shadow: "0px 0px 6px rgba(0, 0, 0, 0.4)",
|
|
573
|
+
selectedShadow: "0px 0px 6px rgba(0, 0, 0, 0.4)",
|
|
574
|
+
},
|
|
575
|
+
},
|
|
576
|
+
|
|
577
|
+
round: {
|
|
578
|
+
style: {},
|
|
579
|
+
width: 60,
|
|
580
|
+
height: 40,
|
|
581
|
+
spacing: 2,
|
|
582
|
+
offButtonScale: 1,
|
|
583
|
+
backgroundStyle: {
|
|
584
|
+
color: "lightgray",
|
|
585
|
+
selectedColor: "#68AF8E", // jade
|
|
586
|
+
border: 0,
|
|
587
|
+
round: 20,
|
|
588
|
+
},
|
|
589
|
+
buttonStyle: {
|
|
590
|
+
color: "white",
|
|
591
|
+
selectedColor: "white",
|
|
592
|
+
round: 18,
|
|
593
|
+
shadow: "2px 0px 4px rgba(0, 0, 0, 0.3)",
|
|
594
|
+
selectedShadow: "-2px 0px 4px rgba(0, 0, 0, 0.5)",
|
|
595
|
+
},
|
|
596
|
+
},
|
|
597
|
+
|
|
598
|
+
slim: {
|
|
599
|
+
style: {},
|
|
600
|
+
width: 56,
|
|
601
|
+
height: 28,
|
|
602
|
+
spacing: 2,
|
|
603
|
+
offButtonScale: 1,
|
|
604
|
+
backgroundStyle: {
|
|
605
|
+
color: "lightgray",
|
|
606
|
+
selectedColor: "#60AEAC", // teal
|
|
607
|
+
border: 0,
|
|
608
|
+
round: 28,
|
|
609
|
+
},
|
|
610
|
+
buttonStyle: {
|
|
611
|
+
color: "white",
|
|
612
|
+
selectedColor: "white",
|
|
613
|
+
round: 16,
|
|
614
|
+
shadow: "none",
|
|
615
|
+
selectedShadow: "0px 0px 8px rgba(0, 0, 0, 0.4)",
|
|
616
|
+
},
|
|
617
|
+
},
|
|
618
|
+
|
|
619
|
+
// WHY selectedBorderColor: the line stays when on, in the color of the track: the knob does not move.
|
|
620
|
+
outline: {
|
|
621
|
+
style: {},
|
|
622
|
+
width: 60,
|
|
623
|
+
height: 30,
|
|
624
|
+
spacing: 5,
|
|
625
|
+
offButtonScale: 1,
|
|
626
|
+
backgroundStyle: {
|
|
627
|
+
color: "white",
|
|
628
|
+
selectedColor: "#8FA6BE", // fog blue
|
|
629
|
+
border: 3,
|
|
630
|
+
borderColor: "#8FA6BE",
|
|
631
|
+
selectedBorderColor: "#8FA6BE",
|
|
632
|
+
round: 20,
|
|
633
|
+
},
|
|
634
|
+
buttonStyle: {
|
|
635
|
+
color: "#8FA6BE",
|
|
636
|
+
selectedColor: "white",
|
|
637
|
+
round: 16,
|
|
638
|
+
shadow: "none",
|
|
639
|
+
selectedShadow: "none",
|
|
640
|
+
},
|
|
641
|
+
},
|
|
642
|
+
|
|
643
|
+
square: {
|
|
644
|
+
style: {},
|
|
645
|
+
width: 56,
|
|
646
|
+
height: 34,
|
|
647
|
+
spacing: 1,
|
|
648
|
+
offButtonScale: 1,
|
|
649
|
+
backgroundStyle: {
|
|
650
|
+
color: "lightgray",
|
|
651
|
+
selectedColor: "#C08BBE", // orchid
|
|
652
|
+
border: 0,
|
|
653
|
+
round: 3,
|
|
654
|
+
},
|
|
655
|
+
buttonStyle: {
|
|
656
|
+
color: "white",
|
|
657
|
+
selectedColor: "white",
|
|
658
|
+
round: 3,
|
|
659
|
+
shadow: "2px 0px 3px rgba(0, 0, 0, 0.2)",
|
|
660
|
+
selectedShadow: "-2px 0px 3px rgba(0, 0, 0, 0.2)",
|
|
661
|
+
},
|
|
662
|
+
},
|
|
663
|
+
|
|
664
|
+
// A check or a cross on the free side of the track.
|
|
665
|
+
tick: {
|
|
666
|
+
style: {},
|
|
667
|
+
width: 72,
|
|
668
|
+
height: 36,
|
|
669
|
+
spacing: 3,
|
|
670
|
+
offButtonScale: 1,
|
|
671
|
+
onMark: "check",
|
|
672
|
+
offMark: "cross",
|
|
673
|
+
markStyle: { size: 18, lineWidth: 2.5, color: "#5F6577", selectedColor: "white" },
|
|
674
|
+
backgroundStyle: {
|
|
675
|
+
color: "#D9DCE3",
|
|
676
|
+
selectedColor: "#7A60F0",
|
|
677
|
+
border: 0,
|
|
678
|
+
},
|
|
679
|
+
buttonStyle: {
|
|
680
|
+
color: "white",
|
|
681
|
+
selectedColor: "white",
|
|
682
|
+
shadow: "0px 1px 4px rgba(0, 0, 0, 0.2)",
|
|
683
|
+
selectedShadow: "0px 1px 4px rgba(0, 0, 0, 0.2)",
|
|
684
|
+
},
|
|
685
|
+
},
|
|
686
|
+
|
|
687
|
+
// A check or a cross in the knob: the track tells the state too (green / red).
|
|
688
|
+
badge: {
|
|
689
|
+
style: {},
|
|
690
|
+
width: 72,
|
|
691
|
+
height: 36,
|
|
692
|
+
spacing: 3,
|
|
693
|
+
offButtonScale: 1,
|
|
694
|
+
onMark: "check",
|
|
695
|
+
offMark: "cross",
|
|
696
|
+
markPlace: "knob",
|
|
697
|
+
markStyle: { size: 18, color: "#B55449", selectedColor: "#3A7756" },
|
|
698
|
+
backgroundStyle: {
|
|
699
|
+
color: "#EBC9C4",
|
|
700
|
+
selectedColor: "#C3DBCE",
|
|
701
|
+
border: 0,
|
|
702
|
+
},
|
|
703
|
+
buttonStyle: {
|
|
704
|
+
color: "#F4F4F2",
|
|
705
|
+
selectedColor: "#F4F4F2",
|
|
706
|
+
shadow: "0px 1px 3px rgba(0, 0, 0, 0.25)",
|
|
707
|
+
selectedShadow: "0px 1px 3px rgba(0, 0, 0, 0.25)",
|
|
708
|
+
},
|
|
709
|
+
},
|
|
710
|
+
|
|
711
|
+
// ON / OFF on the free side of the track, small corners.
|
|
712
|
+
label: {
|
|
713
|
+
style: {},
|
|
714
|
+
width: 68,
|
|
715
|
+
height: 30,
|
|
716
|
+
spacing: 2,
|
|
717
|
+
offButtonScale: 1,
|
|
718
|
+
onMark: "ON",
|
|
719
|
+
offMark: "OFF",
|
|
720
|
+
markStyle: { fontSize: 11, color: "#5F6577", selectedColor: "white" },
|
|
721
|
+
backgroundStyle: {
|
|
722
|
+
color: "#D9DBE1",
|
|
723
|
+
selectedColor: "#D46864",
|
|
724
|
+
border: 0,
|
|
725
|
+
round: 6,
|
|
726
|
+
},
|
|
727
|
+
buttonStyle: {
|
|
728
|
+
color: "white",
|
|
729
|
+
selectedColor: "white",
|
|
730
|
+
round: 5,
|
|
731
|
+
shadow: "0px 1px 2px rgba(0, 0, 0, 0.2)",
|
|
732
|
+
selectedShadow: "0px 1px 2px rgba(0, 0, 0, 0.2)",
|
|
733
|
+
},
|
|
734
|
+
},
|
|
735
|
+
|
|
736
|
+
};
|
|
737
|
+
|
|
738
|
+
// The minimal theme (_designs/minimal-theme.htm): a 28 x 16 track of a line, no fill; the 10 px knob is at the left in
|
|
739
|
+
// the line color when off, at the right in ink with an ink line around the track when on.
|
|
740
|
+
Toggle.createMinimalStyle = function (colors) {
|
|
741
|
+
return {
|
|
742
|
+
style: {},
|
|
743
|
+
width: 28,
|
|
744
|
+
height: 16,
|
|
745
|
+
spacing: 3, // WHY: a 10 px knob (16 - 2 x 3)
|
|
746
|
+
offButtonScale: 1,
|
|
747
|
+
focusRingColor: colors.focus,
|
|
748
|
+
backgroundStyle: { color: "transparent", selectedColor: "transparent", border: 1, borderColor: colors.line, selectedBorderColor: colors.ink, round: 100 },
|
|
749
|
+
buttonStyle: { color: colors.knob, selectedColor: colors.ink, border: 0, round: 100, shadow: "none", selectedShadow: "none" },
|
|
750
|
+
markStyle: { color: colors.knob, selectedColor: colors.ink },
|
|
751
|
+
};
|
|
752
|
+
};
|
|
753
|
+
// WHY a strong line: the line of the track shows the toggle (3:1 at least, as WCAG asks of a control)
|
|
754
|
+
Toggle.MINIMAL_COLORS = { line: Black(0.45), knob: Black(0.45), ink: "#1F1F1F", focus: "#3D8BD9" };
|
|
755
|
+
Toggle.styles.minimal = Toggle.createMinimalStyle(Toggle.MINIMAL_COLORS);
|
|
756
|
+
Toggle.MINIMAL_DARK_COLORS = { line: White(0.42), knob: White(0.42), ink: "#EDEDEB", focus: "#7FB6DE" };
|
|
757
|
+
Toggle.styles.minimalDark = Toggle.createMinimalStyle(Toggle.MINIMAL_DARK_COLORS);
|