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,981 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
Smart Button - v26.11
|
|
6
|
+
|
|
7
|
+
THE DEFAULT BUTTON of new pages and projects.
|
|
8
|
+
|
|
9
|
+
THE MODEL PAGE: 02-comp-examples/smart-button.htm: new pages and projects take their buttons from it.
|
|
10
|
+
The other samples: smart-button-alternatif.htm (pill and outlined with the colors of the page), smart-button-3-ozden.htm
|
|
11
|
+
(the templates), smart-button-4-dark.htm (the dark templates and tones), smart-button-5-features.htm.
|
|
12
|
+
|
|
13
|
+
- A button with an icon and a text (or only one of them); the icon on the left or on top (iconPosition).
|
|
14
|
+
- THE LOOK IN THREE STEPS. The order: style > tone > the template.
|
|
15
|
+
1. styleName: the template (the shape), gray. "ozden" (THE DEFAULT: #E3E3E3, a thin dark edge and a darker
|
|
16
|
+
line at the bottom), "ozden2" (no bottom line), "ozden3" (a faint edge), "ozden4" (a ghost: no
|
|
17
|
+
surface, no edge, only its hover is gray), "pill" (round, no edge, a bold text), "outlined" (round, a thicker
|
|
18
|
+
edge with a line at its bottom). For a dark page (the draft _designs/smart-button-dark.htm):
|
|
19
|
+
"ozdenDark" ... "ozden4Dark" (#2E2E2C, a white text and icon, the dark waiting clock).
|
|
20
|
+
"minimal" / "minimalDark" (the minimal theme, _designs/minimal-theme.htm): 28 px high, a 13 px text, only a line
|
|
21
|
+
that gets darker under the mouse; the main action takes the tone "ink" / "inkDark"; a delete "minimalDanger" /
|
|
22
|
+
"minimalDangerDark" (the line and the text in the danger color).
|
|
23
|
+
A template is only a style (SmartButton.styles); the minimal ones also give the height.
|
|
24
|
+
2. tone: a color of the kit (SmartButton.tones), three colors: the button, the button under the mouse, its text.
|
|
25
|
+
"white", "cyan" (the main action), "orange" (a delete, a reject), "yellow" (go on, but look first), "green"
|
|
26
|
+
(after a good result), "blue" (nothing changes). For a dark page: "cyanDark", "orangeDark", "yellowDark",
|
|
27
|
+
"greenDark", "blueDark" (deeper, a light text and a white icon). "": the gray of the template. setTone().
|
|
28
|
+
"ink" / "inkDark" (the main action of the minimal templates) color the edge too (a tone with edge / hoverEdge).
|
|
29
|
+
A tone looks the same on every template: its text (and its icon) come with it.
|
|
30
|
+
3. style: your own look, only the keys you change. A color is two colors: the button and the button under the mouse.
|
|
31
|
+
style: { box: { color: "#9DC7B5" }, hover: { color: "#91BCA9" } }
|
|
32
|
+
Pressed, a button gets a little smaller and darker (animated: 1, style.press): a press has no color of its own.
|
|
33
|
+
- AN ICON BUTTON: labelText: "" -> the icon in the middle, no room at the sides; with no width it is a square
|
|
34
|
+
(44 x 44). The same template and tone as a text button. Give it an ariaLabel.
|
|
35
|
+
An "auto" height keeps the room of style.layout.padding (Ex: padding [10, 10] -> 44 x 44).
|
|
36
|
+
- HEIGHT: 44 by default (40 looked narrow); every template, pill and outlined too. An icon on
|
|
37
|
+
top of a text makes it "auto" (as high as its padding and content).
|
|
38
|
+
- KEYBOARD AND ACCESSIBILITY: role "button", Tab reaches it, Enter / Space press it (Space when it goes up), a focus
|
|
39
|
+
ring only for the keyboard; a click of the mouse does not take the focus (as the buttons of macOS: Enter and Space
|
|
40
|
+
stay with the page or the field that had them); ariaLabel for a button with only an icon (else labelText is read).
|
|
41
|
+
- setEnabled(0): no click, no hover, out of the Tab order (aria-disabled): a flat light gray button, a faint edge, no
|
|
42
|
+
bottom line, the text and the icon faint gray (the same for every color; chosen on
|
|
43
|
+
experimental/smart-button-bench.htm).
|
|
44
|
+
- ASK (two clicks): ask: "Click again to delete." -> the first click turns the button orange (style.ask.button) and
|
|
45
|
+
shows the text in a bubble over it (comp/tooltip.js, Tooltip.show(): it stays inside the screen; without
|
|
46
|
+
tooltip.js only the orange button); the second click runs onClick. It forgets after style.ask.time. One button asks
|
|
47
|
+
at a time. setAsk(text), cancelAsk(), isAsking. onBeforeClick(self) returns false: no ask and no onClick (Ex: a
|
|
48
|
+
form with an error must not ask "Sure?" first). press(): a press like a click (the ask too), Ex: Enter in a field.
|
|
49
|
+
- WAITING: setWaiting(1) while a job runs (a download, a save): the text and the icon fade and a small animation is
|
|
50
|
+
in the middle; the button can not be clicked. waitingType: "clock" (the default: the clock of the waiting views
|
|
51
|
+
with moving hands; style.waiting.clock "ozden", or "ozdenDark" in the dark templates) or "dots" (three dots one
|
|
52
|
+
after the other).
|
|
53
|
+
setWaiting(0) ends it (after delay ms, if given). Nothing turns with prefers-reduced-motion.
|
|
54
|
+
(comp/loading-screen.js draws its clock and its dots with SmartButton.createClockSvg / createDots)
|
|
55
|
+
- MOTION: animated: 1 (default): pressed 0.94 and a little darker. ripple: 0 (default; 1 gives a wave from the
|
|
56
|
+
pressed point, from the middle for the keyboard; its color fits the button). setAnimated(0/1), setRipple(0/1).
|
|
57
|
+
- setStyle(style): changes the look after create with only the keys it gets.
|
|
58
|
+
|
|
59
|
+
USAGE:
|
|
60
|
+
SmartButton({ labelText: "Cancel", onClick: function (self) { } }); // the default: ozden, gray
|
|
61
|
+
SmartButton({ tone: "cyan", labelText: "Send", iconFile: "../assets/icons/send.png", onClick: send });
|
|
62
|
+
SmartButton({ styleName: "pill", tone: "blue", labelText: "Follow" });
|
|
63
|
+
SmartButton({ styleName: "ozdenDark", tone: "blueDark", labelText: "Send" }); // on a dark page
|
|
64
|
+
SmartButton({ styleName: "ozden2", tone: "white", labelText: "", iconFile: "trash.svg", ariaLabel: "Delete", ask: "Click again to delete.", onClick: deleteFile });
|
|
65
|
+
SmartButton({ labelText: "Archive", style: { box: { color: "#C3DBCE" }, hover: { color: "#B5D0C1" } } }); // your own color
|
|
66
|
+
const btnDownload = SmartButton({ labelText: "Download", onClick: function (self) {
|
|
67
|
+
self.setWaiting(1);
|
|
68
|
+
download().then(function () { self.setWaiting(0); });
|
|
69
|
+
} });
|
|
70
|
+
btnSave.setTone("green"); // another color after create ("": the gray of its template)
|
|
71
|
+
|
|
72
|
+
Started Date: January 2026
|
|
73
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
74
|
+
|
|
75
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
76
|
+
Licensed under the Apache License, Version 2.0
|
|
77
|
+
SPDX-License-Identifier: Apache-2.0
|
|
78
|
+
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
"use strict";
|
|
82
|
+
|
|
83
|
+
// Default values:
|
|
84
|
+
const SmartButtonDefaults = {
|
|
85
|
+
key: "0",
|
|
86
|
+
styleName: "ozden", // the template (SmartButton.styles): "ozden" (the default) ... "ozden4", "pill", "outlined", "ozdenDark" ... "ozden4Dark", "minimal", "minimalDark", "minimalDanger", "minimalDangerDark"
|
|
87
|
+
tone: "", // a color of the kit (SmartButton.tones): "white", "cyan", "orange", "yellow", "green", "blue", "cyanDark"..., "ink" / "inkDark" (minimal). "": the gray of the template. setTone()
|
|
88
|
+
width: "auto", // an icon button (labelText: "") is a square
|
|
89
|
+
height: 44, // "auto": as high as its padding and content (an icon on top of a text is "auto")
|
|
90
|
+
labelText: "Button", // "": an icon button
|
|
91
|
+
allowHtml: 0, // 1: labelText is HTML (only for your own texts)
|
|
92
|
+
iconFile: "", // "": no icon (Ex: "comp/smart-button/alert-black.png")
|
|
93
|
+
iconPosition: "left", // "left", "top"
|
|
94
|
+
enabled: 1, // 0: gray, can not be pressed (set later with setEnabled)
|
|
95
|
+
ariaLabel: "", // "": labelText is read. An icon button needs it (Ex: "Delete")
|
|
96
|
+
waiting: 0, // 1: it waits (set later with setWaiting)
|
|
97
|
+
waitingType: "clock", // "clock" (the default wait) or "dots"
|
|
98
|
+
animated: 1, // 1: pressed it gets smaller and darker (style.press). setAnimated()
|
|
99
|
+
ripple: 0, // 1: a wave from the pressed point (it works with animated: 0 too). setRipple()
|
|
100
|
+
ask: "", // "Click again to delete.": two clicks (the first one asks with an orange button and this text in a bubble). setAsk()
|
|
101
|
+
onBeforeClick: null, // function (self): false stops the press, with no ask either
|
|
102
|
+
onClick: function (self) { }, // Not called while waiting
|
|
103
|
+
onWaitingEnd: function (self) { }, // The wait ended (setWaiting(0))
|
|
104
|
+
style: { // ozden (the default template)
|
|
105
|
+
layout: {
|
|
106
|
+
gap: 8,
|
|
107
|
+
padding: [16, 0],
|
|
108
|
+
align: "center center",
|
|
109
|
+
// px less space on the side of the icon (an icon left of a text): the empty edge in an icon file and its
|
|
110
|
+
// thin lines made that side look wider (measured 1 - 3 px). 0: the same on both sides
|
|
111
|
+
iconSideTrim: 2,
|
|
112
|
+
},
|
|
113
|
+
icon: {
|
|
114
|
+
width: 24,
|
|
115
|
+
height: 24,
|
|
116
|
+
opacity: 0.8,
|
|
117
|
+
filter: "none", // a CSS filter: the dark templates turn the icon white ("brightness(0) invert(1)")
|
|
118
|
+
},
|
|
119
|
+
label: {
|
|
120
|
+
fontSize: 20,
|
|
121
|
+
textColor: Black(0.7),
|
|
122
|
+
fontFamily: "opensans",
|
|
123
|
+
},
|
|
124
|
+
box: {
|
|
125
|
+
color: "#E3E3E3",
|
|
126
|
+
border: 1,
|
|
127
|
+
borderColor: Black(0.35),
|
|
128
|
+
round: 4,
|
|
129
|
+
boxShadow: "inset 0 -2px 0 rgba(0, 0, 0, 0.25)",
|
|
130
|
+
},
|
|
131
|
+
hover: {
|
|
132
|
+
color: "#D9D9D9", // under the mouse (pressed: this color, darker)
|
|
133
|
+
borderColor: "", // the edge under the mouse. "": the edge of box (the minimal templates darken it)
|
|
134
|
+
},
|
|
135
|
+
// ask: the look of the button while it asks, and the bubble over it (Tooltip.BUBBLE_LOOK keys).
|
|
136
|
+
// #DE815B (the orange of danger); its own value, not the orange tone,
|
|
137
|
+
// so the two can be changed apart.
|
|
138
|
+
ask: {
|
|
139
|
+
button: {
|
|
140
|
+
color: "#DE815B", // also under the mouse and pressed
|
|
141
|
+
// WHY no border width: the edge of the template stays, so a pill (0) or an outlined (2) button keeps
|
|
142
|
+
// its size while it asks (border: 1 made an "auto" pill 2 px wider)
|
|
143
|
+
borderColor: "#DE815B",
|
|
144
|
+
boxShadow: "none",
|
|
145
|
+
textColor: "white",
|
|
146
|
+
iconFilter: "brightness(0) invert(1)", // the icon turns white, whatever color its file has
|
|
147
|
+
},
|
|
148
|
+
bubble: { color: "#DE815B", textColor: "white", fontSize: 13, bold: 1, round: 8, padding: [12, 7], border: 0, borderColor: "", shadow: "0 6px 16px rgba(0, 0, 0, 0.18)", arrow: 12, gap: 6, edge: 8, grow: 1 },
|
|
149
|
+
time: 5000, // ms: it forgets the question
|
|
150
|
+
},
|
|
151
|
+
focus: {
|
|
152
|
+
ringColor: "rgba(95, 158, 160, 0.6)", // the ring of the keyboard focus
|
|
153
|
+
},
|
|
154
|
+
disabled: {
|
|
155
|
+
color: "#EBEBEA",
|
|
156
|
+
borderColor: "rgba(0, 0, 0, 0.1)",
|
|
157
|
+
textColor: "rgba(0, 0, 0, 0.3)",
|
|
158
|
+
iconOpacity: 0.25, // (and no color)
|
|
159
|
+
},
|
|
160
|
+
// The press (animated: 1). WHY no color for it: two colors are enough, the press
|
|
161
|
+
// only darkens the color of the moment
|
|
162
|
+
press: {
|
|
163
|
+
scale: 0.94, // while pressed
|
|
164
|
+
brightness: 0.92, // while pressed
|
|
165
|
+
time: 0.15, // s
|
|
166
|
+
},
|
|
167
|
+
ripple: {
|
|
168
|
+
color: "", // "": light on a dark button, dark on a light one
|
|
169
|
+
lightColor: White(0.45),
|
|
170
|
+
darkColor: Black(0.12),
|
|
171
|
+
time: 0.6, // s
|
|
172
|
+
},
|
|
173
|
+
waiting: {
|
|
174
|
+
clock: "ozden", // the look of the clock: "ozden" (a white face, dark lines), "ozdenDark", or the ring of "minimal" / "minimalDark" (SmartButton.clocks)
|
|
175
|
+
contentOpacity: 0.18, // the text and the icon while waiting
|
|
176
|
+
clockSize: 30, // at most; a small button gets a smaller clock
|
|
177
|
+
space: 14, // the room around the clock in a small button
|
|
178
|
+
dots: { size: 6, gap: 4, color: "indianred" },
|
|
179
|
+
},
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const SmartButton = function (params = {}) {
|
|
184
|
+
|
|
185
|
+
// Merge params: style > tone > the template (styleName) > the defaults
|
|
186
|
+
SmartButton.applyLook(params);
|
|
187
|
+
const hasText = (params.labelText !== "");
|
|
188
|
+
// WHY: 44 is the height of a row; an icon above its text needs more (about 60)
|
|
189
|
+
if (params.iconPosition === "top" && hasText && params.height === undefined) params.height = "auto";
|
|
190
|
+
mergeIntoIfMissing(params, SmartButtonDefaults);
|
|
191
|
+
// AN ICON BUTTON (no text): a square when no width is given.
|
|
192
|
+
// WHY only with a number height: an "auto" one is as big as its padding and its icon (Ex: 10 + 24 + 10)
|
|
193
|
+
const isIconButton = !hasText && (typeof params.height === "number");
|
|
194
|
+
if (isIconButton && params.width === "auto") params.width = params.height;
|
|
195
|
+
|
|
196
|
+
// BOX: Component container
|
|
197
|
+
const box = startObject(params);
|
|
198
|
+
|
|
199
|
+
// *** PRIVATE VARIABLES:
|
|
200
|
+
const WAITING_MOTION = "opacity 0.2s"; // the content fades while waiting
|
|
201
|
+
const ASK_ANSWER_DELAY = 400; // ms: a click this soon after the question is the second click of a double click
|
|
202
|
+
const STILL_MOTION = "background-color 0.2s"; // the color under the mouse (animated: 0 too)
|
|
203
|
+
let cancelWaitingEnd = null;
|
|
204
|
+
let cancelAskTimer = null;
|
|
205
|
+
let askBubble = null;
|
|
206
|
+
let askStartTime = 0; // when the question was shown (isAnswerTooSoon)
|
|
207
|
+
let isHover = 0;
|
|
208
|
+
let isPressed = 0;
|
|
209
|
+
let isSpaceDown = 0; // Space went down on this button (it presses when it goes up, like a real button)
|
|
210
|
+
let isMotionStarted = 0; // the transitions are on after the first view (startMotion)
|
|
211
|
+
|
|
212
|
+
// *** PRIVATE FUNCTIONS:
|
|
213
|
+
|
|
214
|
+
const setText = function (label, text) {
|
|
215
|
+
const value = (text === undefined || text === null) ? "" : String(text);
|
|
216
|
+
if (box.allowHtml == 1) label.text = value;
|
|
217
|
+
else label.plainText = value;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
const canPress = function () {
|
|
221
|
+
return box.enabled == 1 && box.waiting != 1;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const isReducedMotion = function () {
|
|
225
|
+
return SmartButton.isReducedMotion();
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
const isMotionOn = function () {
|
|
229
|
+
return box.animated == 1 && !isReducedMotion();
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
// THE LOOK OF THE STATE: the normal look, and over it the keys of the state: disabled > asking > under the mouse.
|
|
233
|
+
// (style.disabled and style.ask.button have the key names of the look; pressed: getPressCss darkens it)
|
|
234
|
+
// WHY one order: an ask never meets a disabled or waiting button (setEnabled(0) and setWaiting(1) end it)
|
|
235
|
+
const getLook = function () {
|
|
236
|
+
const _s = box.style;
|
|
237
|
+
const look = {
|
|
238
|
+
color: _s.box.color,
|
|
239
|
+
border: _s.box.border,
|
|
240
|
+
borderColor: _s.box.borderColor,
|
|
241
|
+
boxShadow: _s.box.boxShadow,
|
|
242
|
+
textColor: _s.label.textColor,
|
|
243
|
+
iconOpacity: _s.icon.opacity,
|
|
244
|
+
iconFilter: _s.icon.filter,
|
|
245
|
+
};
|
|
246
|
+
// WHY no shadow when disabled: a flat button is not one that can be pressed in
|
|
247
|
+
if (box.enabled != 1) return Object.assign(look, _s.disabled, { boxShadow: "none" });
|
|
248
|
+
if (box.isAsking == 1) return Object.assign(look, _s.ask.button);
|
|
249
|
+
// WHY not while waiting: the button stays in its own color under the animation
|
|
250
|
+
if (isHover && box.waiting != 1) {
|
|
251
|
+
look.color = _s.hover.color;
|
|
252
|
+
if (_s.hover.borderColor) look.borderColor = _s.hover.borderColor;
|
|
253
|
+
}
|
|
254
|
+
return look;
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
// The press: smaller and darker while pressed (only with animated: 1)
|
|
258
|
+
const getPressCss = function () {
|
|
259
|
+
const isPressedNow = isPressed && canPress() && isMotionOn();
|
|
260
|
+
return {
|
|
261
|
+
transform: isPressedNow ? "scale(" + box.style.press.scale + ")" : "none",
|
|
262
|
+
filter: isPressedNow ? "brightness(" + box.style.press.brightness + ")" : "none",
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
// Everything that changes with the state: the box, the content, the press, the keyboard and the screen reader
|
|
267
|
+
const render = function () {
|
|
268
|
+
const isEnabled = (box.enabled == 1);
|
|
269
|
+
const look = getLook();
|
|
270
|
+
box.color = look.color;
|
|
271
|
+
box.border = look.border;
|
|
272
|
+
box.borderColor = look.borderColor;
|
|
273
|
+
box.boxShadow = look.boxShadow;
|
|
274
|
+
box.css = getPressCss();
|
|
275
|
+
if (box.label) box.label.textColor = look.textColor;
|
|
276
|
+
if (box.icon) {
|
|
277
|
+
box.icon.opacity = look.iconOpacity;
|
|
278
|
+
box.icon.css = { filter: look.iconFilter };
|
|
279
|
+
}
|
|
280
|
+
box.layout.css = { filter: isEnabled ? "none" : "grayscale(1)" };
|
|
281
|
+
box.layout.opacity = (box.waiting == 1) ? box.style.waiting.contentOpacity : 1;
|
|
282
|
+
box.cursor = isEnabled ? "pointer" : "default";
|
|
283
|
+
box.tabIndex = isEnabled ? 0 : -1;
|
|
284
|
+
box.aria = { disabled: !isEnabled, label: box.ariaLabel || box.labelText || "" };
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
// The room inside: an icon button has none (its icon in the middle); an icon left of a text has a little less
|
|
288
|
+
// on its side (style.layout.iconSideTrim)
|
|
289
|
+
const paintPadding = function () {
|
|
290
|
+
if (isIconButton) {
|
|
291
|
+
box.layout.padding = 0;
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
const _l = box.style.layout;
|
|
295
|
+
const isIconLeft = box.icon && box.label && box.iconPosition !== "top";
|
|
296
|
+
const padding = Array.isArray(_l.padding) ? _l.padding[0] : _l.padding;
|
|
297
|
+
const trim = isIconLeft ? _l.iconSideTrim : 0;
|
|
298
|
+
box.layout.css = { paddingLeft: Math.max(0, padding - trim) + "px" };
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
// The style on the objects (box, layout, icon, label, focus ring); render() gives the colors of the state.
|
|
302
|
+
const applyStyle = function () {
|
|
303
|
+
const _s = box.style;
|
|
304
|
+
box.props(_s.box);
|
|
305
|
+
box.layout.props(_s.layout);
|
|
306
|
+
paintPadding();
|
|
307
|
+
if (box.icon) box.icon.props(_s.icon);
|
|
308
|
+
if (box.label) box.label.props(_s.label);
|
|
309
|
+
box.setFocusRing(_s.focus.ringColor);
|
|
310
|
+
render();
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
// WHY: the second click of a double click answered the ask before it was read (SmartButton({ ask }) and a
|
|
314
|
+
// Dialog.confirm with danger and ask ran at once)
|
|
315
|
+
const isAnswerTooSoon = function (event) {
|
|
316
|
+
if (event && event.detail > 1) return true;
|
|
317
|
+
return (Date.now() - askStartTime < ASK_ANSWER_DELAY);
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
const press = function (event) {
|
|
321
|
+
if (!canPress()) return;
|
|
322
|
+
if (box.isAsking == 1 && isAnswerTooSoon(event)) return;
|
|
323
|
+
if (typeof box.onBeforeClick === "function" && box.onBeforeClick(box) === false) return;
|
|
324
|
+
if (box.ask && box.isAsking != 1) {
|
|
325
|
+
startAsk();
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
box.cancelAsk();
|
|
329
|
+
if (box.onClick) box.onClick(box, event);
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
// *** ASK (two clicks): the orange look (render) and the bubble (Tooltip.show)
|
|
333
|
+
|
|
334
|
+
const startAsk = function () {
|
|
335
|
+
// WHY one at a time: the bubble of another button would stay over this one
|
|
336
|
+
if (SmartButton.askingButton) SmartButton.askingButton.cancelAsk();
|
|
337
|
+
SmartButton.askingButton = box;
|
|
338
|
+
box.isAsking = 1;
|
|
339
|
+
askStartTime = Date.now();
|
|
340
|
+
render();
|
|
341
|
+
if (typeof Tooltip !== "undefined") askBubble = Tooltip.show(box, box.ask, box.style.ask.bubble);
|
|
342
|
+
cancelAskTimer = box.after(box.style.ask.time, box.cancelAsk);
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
// *** THE RIPPLE (a wave from the pressed point)
|
|
346
|
+
|
|
347
|
+
const getRippleColor = function () {
|
|
348
|
+
const _r = box.style.ripple;
|
|
349
|
+
if (_r.color) return _r.color;
|
|
350
|
+
return SmartButton.isDarkColor(getComputedStyle(box.elem).backgroundColor) ? _r.lightColor : _r.darkColor;
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
// The pressed point in the button (px), also when the page is zoomed (page.fit) or the button is pressed (scale)
|
|
354
|
+
const getLocalPoint = function (event) {
|
|
355
|
+
const elem = box.elem;
|
|
356
|
+
if (!event || event.clientX === undefined) return { x: elem.clientWidth / 2, y: elem.clientHeight / 2 };
|
|
357
|
+
const rect = elem.getBoundingClientRect();
|
|
358
|
+
const scaleX = rect.width ? elem.offsetWidth / rect.width : 1;
|
|
359
|
+
const scaleY = rect.height ? elem.offsetHeight / rect.height : 1;
|
|
360
|
+
return { x: (event.clientX - rect.left) * scaleX - elem.clientLeft, y: (event.clientY - rect.top) * scaleY - elem.clientTop };
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
// A layer for a moment over the content; the mouse goes through it
|
|
364
|
+
const showRipple = function (event) {
|
|
365
|
+
if (box.ripple != 1 || !canPress() || isReducedMotion()) return;
|
|
366
|
+
const elem = box.elem;
|
|
367
|
+
const point = getLocalPoint(event);
|
|
368
|
+
// WHY: the radius reaches the farthest corner, so the wave covers the whole button
|
|
369
|
+
const radius = Math.hypot(Math.max(point.x, elem.clientWidth - point.x), Math.max(point.y, elem.clientHeight - point.y));
|
|
370
|
+
const layer = document.createElement("span");
|
|
371
|
+
layer.style.cssText = "position: absolute; left: 0; top: 0; right: 0; bottom: 0; overflow: hidden; border-radius: inherit; pointer-events: none;";
|
|
372
|
+
const dot = document.createElement("span");
|
|
373
|
+
dot.style.cssText = "position: absolute; border-radius: 50%; pointer-events: none; background: " + getRippleColor() + ";" +
|
|
374
|
+
" left: " + (point.x - radius) + "px; top: " + (point.y - radius) + "px; width: " + (radius * 2) + "px; height: " + (radius * 2) + "px;";
|
|
375
|
+
layer.appendChild(dot);
|
|
376
|
+
// WHY under the waiting cover: onClick often starts it (no cover yet: the layer goes last, the cover comes over it)
|
|
377
|
+
elem.insertBefore(layer, box.waitingCover ? box.waitingCover.elem : null);
|
|
378
|
+
const wave = dot.animate([
|
|
379
|
+
{ transform: "scale(0)", opacity: 1 },
|
|
380
|
+
{ transform: "scale(1)", opacity: 0.7, offset: 0.6 },
|
|
381
|
+
{ transform: "scale(1)", opacity: 0 },
|
|
382
|
+
], { duration: box.style.ripple.time * 1000, easing: "cubic-bezier(0.2, 0.6, 0.35, 1)" });
|
|
383
|
+
wave.onfinish = function () { layer.remove(); };
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
// *** THE MOTION
|
|
387
|
+
|
|
388
|
+
// The transitions: the press (animated: 1, not with reduced motion) and the color under the mouse (always)
|
|
389
|
+
// WHY not setMotion(): it starts after a timer, and the press must answer the first click
|
|
390
|
+
const applyAnimated = function () {
|
|
391
|
+
if (!isMotionStarted) return; // (startMotion turns them on)
|
|
392
|
+
const time = box.style.press.time + "s";
|
|
393
|
+
const pressMotion = isMotionOn() ? "transform " + time + ", filter " + time + ", box-shadow " + time + ", " : "";
|
|
394
|
+
box.setMotionNow(pressMotion + STILL_MOTION);
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
// The transitions start after the first view: a state set while the button is made (Ex: setEnabled(0) right
|
|
398
|
+
// after a Dialog is made) is drawn at once, not as a move from its first look (the Save
|
|
399
|
+
// button of a dialog turned from blue to gray when the dialog opened)
|
|
400
|
+
// WHY the frame and the read: the look of now must be the start of a transition, not the look before it
|
|
401
|
+
const startMotion = function () {
|
|
402
|
+
requestAnimationFrame(function () {
|
|
403
|
+
if (box._isRemoved) return;
|
|
404
|
+
void box.elem.offsetWidth; // (the browser takes the look of now)
|
|
405
|
+
isMotionStarted = 1;
|
|
406
|
+
box.layout.setMotionNow(WAITING_MOTION);
|
|
407
|
+
applyAnimated();
|
|
408
|
+
});
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
// *** WAITING
|
|
412
|
+
|
|
413
|
+
// The clock fits the button: at most its size, smaller in a small button (the dots keep their size)
|
|
414
|
+
const fitWaitingIcon = function () {
|
|
415
|
+
const icon = box.waitingCover.icon;
|
|
416
|
+
if (box.waitingType == "clock") {
|
|
417
|
+
const _w = box.style.waiting;
|
|
418
|
+
const room = Math.min(box.width, box.height) - _w.space;
|
|
419
|
+
const size = basic.clamp(room, 0, _w.clockSize);
|
|
420
|
+
icon.setSize(size, size);
|
|
421
|
+
}
|
|
422
|
+
icon.center();
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
// BOX: Waiting cover, made at the first wait: most buttons never wait (it is 2/3 of the objects of a button).
|
|
426
|
+
// Clear: the content fades under it; it holds the animation and takes the mouse.
|
|
427
|
+
const createWaitingCover = function () {
|
|
428
|
+
saveCurrentThat(); // WHY: a wait must not change `that` (Ex: that.setWaiting(1) right after create)
|
|
429
|
+
box.waitingCover = createIn(box, function () {
|
|
430
|
+
const cover = startBox(0, 0, "100%", "100%", {
|
|
431
|
+
color: "transparent",
|
|
432
|
+
clickable: 1, // WHY: it takes the mouse, so its "progress" cursor shows (the hover color: render())
|
|
433
|
+
cursor: "progress",
|
|
434
|
+
});
|
|
435
|
+
if (box.waitingType == "dots") {
|
|
436
|
+
cover.icon = SmartButton.createDots(box.style.waiting.dots);
|
|
437
|
+
} else {
|
|
438
|
+
const clockStyle = SmartButton.clocks[box.style.waiting.clock] || SmartButton.clocks.ozden;
|
|
439
|
+
cover.icon = Box(0, 0, 0, 0, { color: "transparent", html: SmartButton.createClockSvg(clockStyle) });
|
|
440
|
+
}
|
|
441
|
+
endBox();
|
|
442
|
+
return cover;
|
|
443
|
+
});
|
|
444
|
+
restoreThatFromSaved();
|
|
445
|
+
box.onResize(function () {
|
|
446
|
+
if (box.waiting == 1) fitWaitingIcon();
|
|
447
|
+
});
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
const startWaiting = function () {
|
|
451
|
+
box.cancelAsk();
|
|
452
|
+
box.waiting = 1;
|
|
453
|
+
box.aria = { busy: true };
|
|
454
|
+
if (!box.waitingCover) createWaitingCover();
|
|
455
|
+
box.waitingCover.visible = 1;
|
|
456
|
+
fitWaitingIcon();
|
|
457
|
+
render();
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
const endWaiting = function () {
|
|
461
|
+
box.waiting = 0;
|
|
462
|
+
box.aria = { busy: false };
|
|
463
|
+
box.waitingCover.visible = 0;
|
|
464
|
+
render();
|
|
465
|
+
if (typeof box.onWaitingEnd === "function") box.onWaitingEnd(box);
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
// *** PUBLIC FUNCTIONS:
|
|
469
|
+
|
|
470
|
+
box.isAsking = 0; // 1: the first click of ask was made, the button is red
|
|
471
|
+
|
|
472
|
+
box.setLabelText = function (text) {
|
|
473
|
+
box.labelText = text;
|
|
474
|
+
if (box.label) setText(box.label, text);
|
|
475
|
+
render(); // (the label read by a screen reader)
|
|
476
|
+
};
|
|
477
|
+
// USAGE: button.setLabelText("Save")
|
|
478
|
+
|
|
479
|
+
box.setIcon = function (file) {
|
|
480
|
+
box.iconFile = file;
|
|
481
|
+
if (box.icon) box.icon.load(file);
|
|
482
|
+
};
|
|
483
|
+
// USAGE: button.setIcon("comp/smart-button/alert-black.png")
|
|
484
|
+
|
|
485
|
+
box.setAnimated = function (value) {
|
|
486
|
+
box.animated = basic.isOn(value) ? 1 : 0;
|
|
487
|
+
applyAnimated();
|
|
488
|
+
render(); // WHY: a button pressed now loses its press look with animated: 0
|
|
489
|
+
};
|
|
490
|
+
// USAGE: get: button.animated, set: button.setAnimated(0)
|
|
491
|
+
|
|
492
|
+
box.setRipple = function (value) {
|
|
493
|
+
box.ripple = basic.isOn(value) ? 1 : 0;
|
|
494
|
+
};
|
|
495
|
+
// USAGE: get: button.ripple, set: button.setRipple(1)
|
|
496
|
+
|
|
497
|
+
box.setEnabled = function (value) {
|
|
498
|
+
box.enabled = basic.isOn(value) ? 1 : 0;
|
|
499
|
+
if (box.enabled != 1) {
|
|
500
|
+
box.cancelAsk();
|
|
501
|
+
isPressed = 0;
|
|
502
|
+
isSpaceDown = 0;
|
|
503
|
+
}
|
|
504
|
+
render();
|
|
505
|
+
};
|
|
506
|
+
// USAGE: get: button.enabled, set: button.setEnabled(0)
|
|
507
|
+
|
|
508
|
+
// Back to its own look, without onClick (the ask is forgotten)
|
|
509
|
+
box.cancelAsk = function () {
|
|
510
|
+
if (box.isAsking != 1) return;
|
|
511
|
+
box.isAsking = 0;
|
|
512
|
+
if (cancelAskTimer) cancelAskTimer();
|
|
513
|
+
cancelAskTimer = null;
|
|
514
|
+
if (askBubble) askBubble.remove();
|
|
515
|
+
askBubble = null;
|
|
516
|
+
if (SmartButton.askingButton === box) SmartButton.askingButton = null;
|
|
517
|
+
render();
|
|
518
|
+
};
|
|
519
|
+
// USAGE: button.cancelAsk()
|
|
520
|
+
|
|
521
|
+
box.setAsk = function (text) {
|
|
522
|
+
box.ask = text || "";
|
|
523
|
+
if (!box.ask) box.cancelAsk();
|
|
524
|
+
};
|
|
525
|
+
// USAGE: button.setAsk("Click again to delete."), button.setAsk("") (one click)
|
|
526
|
+
|
|
527
|
+
// A press like a click: onBeforeClick, the ask, onClick (Ex: Enter in a field of a dialog)
|
|
528
|
+
box.press = function () {
|
|
529
|
+
press(null);
|
|
530
|
+
};
|
|
531
|
+
// USAGE: button.press()
|
|
532
|
+
|
|
533
|
+
// WHY its own remove: the bubble is on the page and SmartButton.askingButton is static
|
|
534
|
+
const superRemove = box.remove;
|
|
535
|
+
box.superRemove = superRemove;
|
|
536
|
+
box.remove = function () {
|
|
537
|
+
if (box.isRemoved) return;
|
|
538
|
+
box.cancelAsk();
|
|
539
|
+
superRemove.call(box);
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
// Only the given keys change; the other keys of the style stay, inside a part too (ask.button, waiting.dots).
|
|
543
|
+
// WHY a new object for each part: the old one can be shared with other buttons (the same style object of a page)
|
|
544
|
+
// WHY not Object.assign: it replaces ask.button whole, so { ask: { button: { color } } } would lose
|
|
545
|
+
// the white text and the white icon of the ask
|
|
546
|
+
box.setStyle = function (style) {
|
|
547
|
+
Object.keys(style || {}).forEach(function (part) {
|
|
548
|
+
const merged = {};
|
|
549
|
+
mergeIntoIfMissing(merged, style[part]); // the new keys first
|
|
550
|
+
mergeIntoIfMissing(merged, box.style[part]); // then the old ones under them
|
|
551
|
+
box.style[part] = merged;
|
|
552
|
+
});
|
|
553
|
+
applyStyle();
|
|
554
|
+
applyAnimated(); // WHY: style.press.time is in the transitions
|
|
555
|
+
};
|
|
556
|
+
// USAGE: button.setStyle({ box: { color: "tomato", borderColor: "red" }, hover: { color: "tomato" } })
|
|
557
|
+
|
|
558
|
+
// The two colors of a tone (a color of the page given with style goes)
|
|
559
|
+
box.setTone = function (toneName) {
|
|
560
|
+
box.tone = toneName || "";
|
|
561
|
+
box.setStyle(SmartButton.getToneStyle(box.tone, box.styleName));
|
|
562
|
+
};
|
|
563
|
+
// USAGE: button.setTone("green"), button.setTone("") (the gray of its template)
|
|
564
|
+
|
|
565
|
+
// delay: ms before the wait ends (only for 0)
|
|
566
|
+
box.setWaiting = function (value, delay = 0) {
|
|
567
|
+
if (cancelWaitingEnd) cancelWaitingEnd();
|
|
568
|
+
cancelWaitingEnd = null;
|
|
569
|
+
if (basic.isOn(value)) {
|
|
570
|
+
startWaiting();
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
if (box.waiting != 1) return;
|
|
574
|
+
if (delay <= 0) {
|
|
575
|
+
endWaiting();
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
cancelWaitingEnd = box.after(delay, endWaiting);
|
|
579
|
+
};
|
|
580
|
+
// USAGE: get: button.waiting, set: button.setWaiting(1) / button.setWaiting(0, 1000)
|
|
581
|
+
|
|
582
|
+
// *** OBJECT VIEW:
|
|
583
|
+
|
|
584
|
+
// BOX: Container (its look: applyStyle(), when its objects are made)
|
|
585
|
+
box.clickable = 1;
|
|
586
|
+
box.role = "button";
|
|
587
|
+
|
|
588
|
+
// GROUP: Layout (icon, label). iconPosition "top" puts the icon above the label.
|
|
589
|
+
// WHY "100%" for a fixed size: the group fills the inside of the border; with the size of the box itself it was
|
|
590
|
+
// as big as the border box and its content sat 1 px too low (a border of 1 px)
|
|
591
|
+
box.layout = AutoLayout({
|
|
592
|
+
flow: (box.iconPosition === "top") ? "vertical" : "horizontal",
|
|
593
|
+
width: (params.width === "auto") ? "auto" : "100%",
|
|
594
|
+
height: (params.height === "auto") ? "auto" : "100%",
|
|
595
|
+
position: "relative", // WHY: The box (width / height "auto") grows with it.
|
|
596
|
+
...box.style.layout,
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
// ICON: only when there is an icon file
|
|
600
|
+
if (box.iconFile) {
|
|
601
|
+
box.icon = Icon(0, 0, box.style.icon);
|
|
602
|
+
box.icon.load(box.iconFile);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
// LABEL: only when there is a text
|
|
606
|
+
if (box.labelText) {
|
|
607
|
+
box.label = Label(0, 0, box.style.label);
|
|
608
|
+
setText(box.label, box.labelText);
|
|
609
|
+
box.label.css.whiteSpace = "nowrap";
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
endAutoLayout();
|
|
613
|
+
// (the waiting cover: createWaitingCover(), at the first wait)
|
|
614
|
+
|
|
615
|
+
// *** OBJECT INIT CODE:
|
|
616
|
+
|
|
617
|
+
// WHY the look before the transitions: nothing fades in at the first view
|
|
618
|
+
applyStyle();
|
|
619
|
+
startMotion();
|
|
620
|
+
|
|
621
|
+
box.on("click", function (self, event) {
|
|
622
|
+
press(event);
|
|
623
|
+
});
|
|
624
|
+
|
|
625
|
+
// KEYBOARD: Enter / Space press it (Space: when the key goes up, like a real button)
|
|
626
|
+
box.on("keydown", function (self, event) {
|
|
627
|
+
if (event.key == "Enter") {
|
|
628
|
+
event.preventDefault();
|
|
629
|
+
if (event.repeat) return; // WHY: a held Enter must not pass an ask (two clicks)
|
|
630
|
+
showRipple(null);
|
|
631
|
+
press(event);
|
|
632
|
+
}
|
|
633
|
+
if (event.key == " ") {
|
|
634
|
+
event.preventDefault(); // WHY: no page scroll
|
|
635
|
+
isSpaceDown = 1;
|
|
636
|
+
}
|
|
637
|
+
});
|
|
638
|
+
box.on("keyup", function (self, event) {
|
|
639
|
+
if (event.key != " " || !isSpaceDown) return;
|
|
640
|
+
isSpaceDown = 0;
|
|
641
|
+
showRipple(null);
|
|
642
|
+
press(event);
|
|
643
|
+
});
|
|
644
|
+
box.on("blur", function () {
|
|
645
|
+
isSpaceDown = 0;
|
|
646
|
+
});
|
|
647
|
+
|
|
648
|
+
// THE MOUSE: hover, pressed, back to normal (render)
|
|
649
|
+
box.onHoverChange(function (self, isOver) {
|
|
650
|
+
isHover = isOver;
|
|
651
|
+
if (!isOver) isPressed = 0;
|
|
652
|
+
render();
|
|
653
|
+
});
|
|
654
|
+
box.on("mousedown", function (self, event) {
|
|
655
|
+
// WHY: a button clicked with the mouse kept the focus, and a later Enter pressed it again (a calculator that
|
|
656
|
+
// takes Enter as "=" pressed the clicked key too). The focus stays where it was.
|
|
657
|
+
event.preventDefault();
|
|
658
|
+
if (!canPress() || event.button !== 0) return; // WHY: a right click gives no click
|
|
659
|
+
isPressed = 1;
|
|
660
|
+
render();
|
|
661
|
+
showRipple(event);
|
|
662
|
+
});
|
|
663
|
+
box.on("mouseup", function () {
|
|
664
|
+
isPressed = 0;
|
|
665
|
+
render();
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
if (box.waiting == 1) box.setWaiting(1);
|
|
669
|
+
|
|
670
|
+
return endObject(box);
|
|
671
|
+
|
|
672
|
+
};
|
|
673
|
+
|
|
674
|
+
// *** STATIC FUNCTIONS:
|
|
675
|
+
|
|
676
|
+
SmartButton.askingButton = null; // the button that asks now (ask: one at a time)
|
|
677
|
+
|
|
678
|
+
// WHY one query for the page: render() asks it at every hover and press
|
|
679
|
+
SmartButton.isReducedMotion = function () {
|
|
680
|
+
if (!window.matchMedia) return false;
|
|
681
|
+
if (!SmartButton.reducedMotionQuery) SmartButton.reducedMotionQuery = window.matchMedia("(prefers-reduced-motion: reduce)");
|
|
682
|
+
return SmartButton.reducedMotionQuery.matches;
|
|
683
|
+
};
|
|
684
|
+
|
|
685
|
+
// 1: a dark color (the ripple is light on it). A color of the browser: "rgb(r, g, b)" or "rgba(r, g, b, a)".
|
|
686
|
+
// A transparent color is not dark (the page under it shows).
|
|
687
|
+
SmartButton.DARK_LIMIT = 0.45; // the brightness (0 - 1) under it a color is dark
|
|
688
|
+
SmartButton.isDarkColor = function (cssColor) {
|
|
689
|
+
const text = String(cssColor).trim();
|
|
690
|
+
const isSrgb = /^color\(srgb\s/.test(text);
|
|
691
|
+
if (!isSrgb && !/^rgba?\(/.test(text)) return 0; // WHY: oklch(), lab()... are not read (0: not dark)
|
|
692
|
+
// WHY the scale: color-mix() (Alpha(), UI.alpha) is computed as color(srgb 0.95 0.95 0.95 / 0.9), channels 0 - 1
|
|
693
|
+
const channelScale = isSrgb ? 255 : 1;
|
|
694
|
+
const parts = (isSrgb ? text.slice(11) : text).match(/[\d.]+/g);
|
|
695
|
+
if (!parts || parts.length < 3) return 0;
|
|
696
|
+
const alpha = (parts.length > 3) ? parseFloat(parts[3]) : 1;
|
|
697
|
+
if (alpha < 0.5) return 0;
|
|
698
|
+
for (let i = 0; i < 3; i++) parts[i] = parseFloat(parts[i]) * channelScale;
|
|
699
|
+
// WHY these weights: the eye sees green brighter than red, and red brighter than blue
|
|
700
|
+
const brightness = (0.299 * parts[0] + 0.587 * parts[1] + 0.114 * parts[2]) / 255;
|
|
701
|
+
return (brightness < SmartButton.DARK_LIMIT) ? 1 : 0;
|
|
702
|
+
};
|
|
703
|
+
|
|
704
|
+
// The turns of the clock and the dots (once for the page). Nothing moves with reduced motion.
|
|
705
|
+
SmartButton.injectCss = function () {
|
|
706
|
+
basic.addCss("smart-button-css",
|
|
707
|
+
"@keyframes smart-button-turn { to { transform: rotate(360deg); } }" +
|
|
708
|
+
"@keyframes smart-button-dot { 0%, 80%, 100% { transform: scale(0.6); opacity: 0.35; } 40% { transform: scale(1); opacity: 1; } }" +
|
|
709
|
+
// WHY view-box: a hand of the clock turns around the middle of the clock, not around its own box
|
|
710
|
+
".smart-button-hand { transform-box: view-box; transform-origin: 50% 50%; animation-name: smart-button-turn;" +
|
|
711
|
+
" animation-timing-function: linear; animation-iteration-count: infinite; }" +
|
|
712
|
+
"@media (prefers-reduced-motion: reduce) { .smart-button-hand, .smart-button-dot { animation: none !important; } }");
|
|
713
|
+
};
|
|
714
|
+
|
|
715
|
+
// *** THE TEMPLATES (the shapes), all gray. A template is a style with only the keys that differ from the default
|
|
716
|
+
// (ozden); its color comes from a tone or from style. Every template has the default height (44).
|
|
717
|
+
SmartButton.WHITE_ICON = "brightness(0) invert(1)"; // a CSS filter: any icon file turns white
|
|
718
|
+
SmartButton.ROUND = 100; // pill, outlined: always round, at any height
|
|
719
|
+
SmartButton.EDGE_WIDTH = 2; // outlined: the edge and the line at its bottom
|
|
720
|
+
|
|
721
|
+
SmartButton.styles = {
|
|
722
|
+
// (the buttons of 02-comp-examples/smart-button-3-ozden.htm)
|
|
723
|
+
ozden: SmartButtonDefaults.style, // an edge and a bottom line
|
|
724
|
+
ozden2: { box: { boxShadow: "none" } }, // only the edge
|
|
725
|
+
ozden3: { box: { borderColor: Black(0.1), boxShadow: "none" } }, // a faint edge
|
|
726
|
+
ozden4: { box: { color: White(0), border: 0, borderColor: "transparent", boxShadow: "none" } }, // a ghost
|
|
727
|
+
// ROUND (the buttons of 02-comp-examples/smart-button-alternatif.htm). WHY a smaller text
|
|
728
|
+
// and icon: they were 52 px high with a 30 px icon; now as high as the other buttons
|
|
729
|
+
pill: { // no edge, a bold text
|
|
730
|
+
layout: { gap: 10, padding: [18, 0] },
|
|
731
|
+
icon: { width: 26, height: 26, opacity: 1 },
|
|
732
|
+
label: { fontSize: 18, fontFamily: "opensans-bold" },
|
|
733
|
+
box: { border: 0, borderColor: "transparent", round: SmartButton.ROUND, boxShadow: "none" },
|
|
734
|
+
},
|
|
735
|
+
outlined: { // a thicker edge with a line at its bottom
|
|
736
|
+
layout: { gap: 8, padding: [14, 0] },
|
|
737
|
+
icon: { width: 26, height: 26, opacity: 1 },
|
|
738
|
+
label: { fontSize: 18 },
|
|
739
|
+
box: { border: SmartButton.EDGE_WIDTH, round: SmartButton.ROUND, boxShadow: "inset 0 -" + SmartButton.EDGE_WIDTH + "px 0 " + Black(0.35) },
|
|
740
|
+
},
|
|
741
|
+
};
|
|
742
|
+
|
|
743
|
+
// THE DARK TEMPLATES (the draft _designs/smart-button-dark.htm): the shapes of ozden ... ozden4 with the
|
|
744
|
+
// colors of a dark page (the cards of Ozden Panel / Ozden Manager, #1A1A19). The icon turns white, the waiting clock
|
|
745
|
+
// is the dark one, the dots yellow; the ask stays orange.
|
|
746
|
+
// THE EDGE AND THE BOTTOM LINE: the edge of ozden in white and its 2 px line in white, a
|
|
747
|
+
// little fainter. A light tone on a dark template keeps them too.
|
|
748
|
+
// WHY 0.2 / 0.12 (0.35 / 0.2 were too bright on a dark page; a white edge on a dark page is
|
|
749
|
+
// much stronger than the same black on a light one): still twice the faint edge of ozden3Dark (0.1).
|
|
750
|
+
SmartButton.DARK_EDGE = White(0.2);
|
|
751
|
+
SmartButton.DARK_BOTTOM_LINE = "inset 0 -2px 0 " + White(0.12);
|
|
752
|
+
// boxKeys: only the keys of the box that differ from ozdenDark (as the light templates from ozden)
|
|
753
|
+
SmartButton.createDarkTemplate = function (boxKeys, hoverColor = "#383835") {
|
|
754
|
+
return {
|
|
755
|
+
box: Object.assign({ color: "#2E2E2C", borderColor: SmartButton.DARK_EDGE, boxShadow: SmartButton.DARK_BOTTOM_LINE }, boxKeys),
|
|
756
|
+
hover: { color: hoverColor },
|
|
757
|
+
label: { textColor: White(0.85) },
|
|
758
|
+
icon: { opacity: 0.85, filter: SmartButton.WHITE_ICON },
|
|
759
|
+
focus: { ringColor: "rgba(101, 162, 147, 0.75)" },
|
|
760
|
+
disabled: { color: "#232322", borderColor: White(0.06), textColor: White(0.28), iconOpacity: 0.25 },
|
|
761
|
+
press: { brightness: 0.88 },
|
|
762
|
+
waiting: { clock: "ozdenDark", dots: { color: "#F1C74A" } },
|
|
763
|
+
};
|
|
764
|
+
};
|
|
765
|
+
SmartButton.styles.ozdenDark = SmartButton.createDarkTemplate({}); // an edge and a bottom line
|
|
766
|
+
SmartButton.styles.ozden2Dark = SmartButton.createDarkTemplate({ boxShadow: "none" }); // only the edge
|
|
767
|
+
SmartButton.styles.ozden3Dark = SmartButton.createDarkTemplate({ borderColor: White(0.1), boxShadow: "none" }); // a faint edge: the 0.1 of ozden3 in white
|
|
768
|
+
SmartButton.styles.ozden4Dark = SmartButton.createDarkTemplate({ color: White(0), border: 0, borderColor: "transparent", boxShadow: "none" }, White(0.08)); // a ghost
|
|
769
|
+
|
|
770
|
+
// THE MINIMAL TEMPLATES (the draft _designs/minimal-theme.htm): small (28 px, a 13 px text, a 14 px icon) and made of
|
|
771
|
+
// lines: no fill, the edge gets darker under the mouse, a blue focus ring, a ring that waits. The main action takes the
|
|
772
|
+
// tone "ink" (inkDark on a dark page): the only filled button of the theme.
|
|
773
|
+
SmartButton.MINIMAL_DANGER = "#C24A36"; // the ask of the minimal templates (on light and dark windows: a white text)
|
|
774
|
+
SmartButton.createMinimalTemplate = function (colors) {
|
|
775
|
+
const danger = SmartButton.MINIMAL_DANGER;
|
|
776
|
+
return {
|
|
777
|
+
height: 28,
|
|
778
|
+
style: {
|
|
779
|
+
layout: { gap: 6, padding: [10, 0], iconSideTrim: 0 },
|
|
780
|
+
icon: { width: 14, height: 14, opacity: 1, filter: colors.iconFilter },
|
|
781
|
+
label: { fontSize: 13, textColor: colors.text },
|
|
782
|
+
box: { color: "transparent", border: 1, borderColor: colors.line, round: 4, boxShadow: "none" },
|
|
783
|
+
hover: { color: "transparent", borderColor: colors.lineHover },
|
|
784
|
+
focus: { ringColor: colors.focus },
|
|
785
|
+
disabled: { color: "transparent", borderColor: colors.disabledLine, textColor: colors.disabledText, iconOpacity: 0.4 },
|
|
786
|
+
press: { scale: 0.97, brightness: 1 },
|
|
787
|
+
waiting: { clock: colors.clock, contentOpacity: 0.12, clockSize: 16, space: 6 },
|
|
788
|
+
ask: {
|
|
789
|
+
button: { color: danger, borderColor: danger, boxShadow: "none", textColor: "white", iconFilter: SmartButton.WHITE_ICON },
|
|
790
|
+
bubble: { color: danger, textColor: "white", fontSize: 12, bold: 0, round: 4, padding: [8, 4], border: 0, borderColor: "", shadow: "none", arrow: 8, gap: 4, edge: 6 },
|
|
791
|
+
},
|
|
792
|
+
},
|
|
793
|
+
};
|
|
794
|
+
};
|
|
795
|
+
SmartButton.styles.minimal = SmartButton.createMinimalTemplate({
|
|
796
|
+
text: Black(0.85), line: Black(0.2), lineHover: Black(0.45), focus: "#3D8BD9",
|
|
797
|
+
disabledLine: Black(0.08), disabledText: Black(0.34), iconFilter: "none", clock: "minimal",
|
|
798
|
+
});
|
|
799
|
+
SmartButton.styles.minimalDark = SmartButton.createMinimalTemplate({
|
|
800
|
+
text: White(0.88), line: White(0.18), lineHover: White(0.42), focus: "#7FB6DE",
|
|
801
|
+
disabledLine: White(0.07), disabledText: White(0.35), iconFilter: SmartButton.WHITE_ICON, clock: "minimalDark",
|
|
802
|
+
});
|
|
803
|
+
// A delete in the minimal theme: the line and the text in the danger color (the line half of it, all of it under the
|
|
804
|
+
// mouse). The icon keeps the color of its file: give it an icon drawn in the danger color.
|
|
805
|
+
SmartButton.styles.minimalDanger = SmartButton.createMinimalTemplate({
|
|
806
|
+
text: "#C24A36", line: "rgba(194, 74, 54, 0.5)", lineHover: "#C24A36", focus: "#3D8BD9",
|
|
807
|
+
disabledLine: Black(0.08), disabledText: Black(0.34), iconFilter: "none", clock: "minimal",
|
|
808
|
+
});
|
|
809
|
+
SmartButton.styles.minimalDangerDark = SmartButton.createMinimalTemplate({
|
|
810
|
+
text: "#FF9F93", line: "rgba(255, 159, 147, 0.5)", lineHover: "#FF9F93", focus: "#7FB6DE",
|
|
811
|
+
disabledLine: White(0.07), disabledText: White(0.35), iconFilter: "none", clock: "minimalDark",
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
// *** THE TONES: the colors of the kit, with simple color names; a tone for a dark page ends
|
|
815
|
+
// with "Dark". A tone is three colors: the button, the button under the mouse and its text (DARK_TEXT, or LIGHT_TEXT:
|
|
816
|
+
// it turns the icon white too). The light ones are white and the colors of the situations (chosen on the draft
|
|
817
|
+
// _designs/smart-button-colors.htm). Any other color: style (Ex: 02-comp-examples/smart-button-alternatif.htm).
|
|
818
|
+
SmartButton.DARK_TEXT = Black(0.75);
|
|
819
|
+
SmartButton.LIGHT_TEXT = White(0.9);
|
|
820
|
+
SmartButton.tones = {
|
|
821
|
+
white: { color: "white", hover: "whitesmoke", text: SmartButton.DARK_TEXT },
|
|
822
|
+
cyan: { color: "#5BBAC1", hover: "#50AEB5", text: SmartButton.DARK_TEXT }, // the main action: Save, Send
|
|
823
|
+
orange: { color: "#DE815B", hover: "#D4724B", text: SmartButton.DARK_TEXT }, // a delete, a reject
|
|
824
|
+
yellow: { color: "#F1C74A", hover: "#E6BB3C", text: SmartButton.DARK_TEXT }, // go on, but look first
|
|
825
|
+
green: { color: "#7BC362", hover: "#70B756", text: SmartButton.DARK_TEXT }, // after a good result: Done
|
|
826
|
+
blue: { color: "#52A8D0", hover: "#479CC4", text: SmartButton.DARK_TEXT }, // nothing changes: Details, Help
|
|
827
|
+
// For a dark page: the same colors, 45 % over the dark card #1A1A19 (53 % under the mouse); chosen by the user on
|
|
828
|
+
// the draft _designs/smart-button2-dark-tones.htm.
|
|
829
|
+
// WHY 45 %: the light text reads on every one of them (contrast 4.8 - 6.7; 4.5 is enough)
|
|
830
|
+
cyanDark: { color: "#376265", hover: "#3C6F72", text: SmartButton.LIGHT_TEXT },
|
|
831
|
+
orangeDark: { color: "#724837", hover: "#82513C", text: SmartButton.LIGHT_TEXT },
|
|
832
|
+
yellowDark: { color: "#7B682F", hover: "#8C7633", text: SmartButton.LIGHT_TEXT },
|
|
833
|
+
greenDark: { color: "#46663A", hover: "#4D7440", text: SmartButton.LIGHT_TEXT },
|
|
834
|
+
blueDark: { color: "#335A6B", hover: "#38657A", text: SmartButton.LIGHT_TEXT },
|
|
835
|
+
// The main action of the minimal templates (the ink of the theme). edge / hoverEdge: the edge in the color of the
|
|
836
|
+
// button (a line of the template around a filled button looked like a frame)
|
|
837
|
+
ink: { color: "#1F1F1F", hover: "#3A3A3A", text: SmartButton.LIGHT_TEXT, edge: "#1F1F1F", hoverEdge: "#3A3A3A" },
|
|
838
|
+
inkDark: { color: "#EDEDEB", hover: "#FFFFFF", text: "#1A1A19", edge: "#EDEDEB", hoverEdge: "#FFFFFF" },
|
|
839
|
+
};
|
|
840
|
+
|
|
841
|
+
// THE LOOK, the one place of its order: style > tone > the template (styleName) > the defaults. It fills params.style
|
|
842
|
+
// and returns params (getTemplateColors reads a template with it too).
|
|
843
|
+
SmartButton.applyLook = function (params) {
|
|
844
|
+
SmartButton.applyTone(params);
|
|
845
|
+
basic.applyStylePackage(params, SmartButton.styles, SmartButtonDefaults);
|
|
846
|
+
mergeIntoIfMissing(params.style, SmartButtonDefaults.style);
|
|
847
|
+
return params;
|
|
848
|
+
};
|
|
849
|
+
|
|
850
|
+
// A tone as a style. No tone: the colors of the template (setTone("") makes a button gray again).
|
|
851
|
+
SmartButton.getToneStyle = function (toneName, styleName) {
|
|
852
|
+
if (!toneName) return SmartButton.getTemplateColors(styleName);
|
|
853
|
+
const tone = SmartButton.tones[toneName];
|
|
854
|
+
if (!tone) {
|
|
855
|
+
console.warn("SmartButton: tone not found: " + toneName);
|
|
856
|
+
return {};
|
|
857
|
+
}
|
|
858
|
+
// WHY the icon: an icon file is drawn dark; with a light text it turns white
|
|
859
|
+
const isLightText = (tone.text === SmartButton.LIGHT_TEXT);
|
|
860
|
+
const toneStyle = {
|
|
861
|
+
box: { color: tone.color },
|
|
862
|
+
hover: { color: tone.hover },
|
|
863
|
+
label: { textColor: tone.text },
|
|
864
|
+
icon: { filter: isLightText ? SmartButton.WHITE_ICON : "none" },
|
|
865
|
+
};
|
|
866
|
+
if (tone.edge) {
|
|
867
|
+
toneStyle.box.borderColor = tone.edge;
|
|
868
|
+
toneStyle.hover.borderColor = tone.hoverEdge || tone.edge;
|
|
869
|
+
}
|
|
870
|
+
return toneStyle;
|
|
871
|
+
};
|
|
872
|
+
|
|
873
|
+
// The colors of a template: the button, the button under the mouse, its text and its icon
|
|
874
|
+
SmartButton.getTemplateColors = function (styleName) {
|
|
875
|
+
const template = SmartButton.applyLook({ styleName: styleName }).style;
|
|
876
|
+
return {
|
|
877
|
+
box: { color: template.box.color },
|
|
878
|
+
hover: { color: template.hover.color },
|
|
879
|
+
label: { textColor: template.label.textColor },
|
|
880
|
+
icon: { filter: template.icon.filter },
|
|
881
|
+
};
|
|
882
|
+
};
|
|
883
|
+
|
|
884
|
+
// The tone goes under the style of the page, so a color the page gives still wins.
|
|
885
|
+
// WHY a new object: params.style can be a template given as it is (style: SmartButton.styles.ozden2)
|
|
886
|
+
SmartButton.applyTone = function (params) {
|
|
887
|
+
if (!params.tone) return;
|
|
888
|
+
const ownStyle = {};
|
|
889
|
+
mergeIntoIfMissing(ownStyle, params.style || {});
|
|
890
|
+
mergeIntoIfMissing(ownStyle, SmartButton.getToneStyle(params.tone));
|
|
891
|
+
params.style = ownStyle;
|
|
892
|
+
};
|
|
893
|
+
|
|
894
|
+
// *** THE WAITING DRAWINGS: the clock and the dots (comp/loading-screen.js uses them too)
|
|
895
|
+
|
|
896
|
+
// The clocks of the waiting views with moving hands. The sizes are px on a 30 px clock.
|
|
897
|
+
SmartButton.clocks = {
|
|
898
|
+
ozden: { // a white face, dark lines
|
|
899
|
+
faceColor: "#FFFFFF",
|
|
900
|
+
lineColor: "#141414", // the edge (and the hour hand, when there is no hourColor)
|
|
901
|
+
edgeWidth: 2,
|
|
902
|
+
hourWidth: 2, // the short hand
|
|
903
|
+
hourLength: 7.5, // from the middle
|
|
904
|
+
minuteWidth: 2, // the long hand
|
|
905
|
+
minuteLength: 10,
|
|
906
|
+
minuteColor: "indianred",
|
|
907
|
+
centerColor: "indianred", // the dot in the middle: it hides where the hands meet
|
|
908
|
+
centerSize: 4,
|
|
909
|
+
minuteTurn: 1.6, // seconds for one turn of the minute hand
|
|
910
|
+
hourTurn: 19.2, // seconds for one turn of the hour hand (12 x minuteTurn: a real clock)
|
|
911
|
+
},
|
|
912
|
+
};
|
|
913
|
+
// a dark face, light lines; WHY yellow: indianred was weak on the dark face (contrast 3.6,
|
|
914
|
+
// #F1C74A 8.9); the hour hand is dimmer, so the yellow minute hand leads (as the red one on the light clock)
|
|
915
|
+
SmartButton.clocks.ozdenDark = Object.assign({}, SmartButton.clocks.ozden, {
|
|
916
|
+
faceColor: "#2A2A2A",
|
|
917
|
+
lineColor: "rgba(255, 255, 255, 0.9)",
|
|
918
|
+
hourColor: "rgba(255, 255, 255, 0.6)",
|
|
919
|
+
minuteColor: "#F1C74A",
|
|
920
|
+
centerColor: "#F1C74A",
|
|
921
|
+
});
|
|
922
|
+
|
|
923
|
+
// The waiting ring of the minimal templates: a faint circle and a quarter arc turning on it, in the color of the text
|
|
924
|
+
// (isRing: SmartButton.createRingSvg draws it in place of a clock).
|
|
925
|
+
SmartButton.clocks.minimal = {
|
|
926
|
+
isRing: 1,
|
|
927
|
+
lineColor: Black(0.85),
|
|
928
|
+
edgeWidth: 3, // on the 30 px drawing (1.6 px at 16 px)
|
|
929
|
+
trackOpacity: 0.2, // the circle under the arc
|
|
930
|
+
turnTime: 0.8, // seconds for one turn of the arc
|
|
931
|
+
};
|
|
932
|
+
SmartButton.clocks.minimalDark = Object.assign({}, SmartButton.clocks.minimal, { lineColor: White(0.88) });
|
|
933
|
+
|
|
934
|
+
// The clock as an SVG text (as wide as its box): a face with an edge, the minute hand up, the hour hand to the right.
|
|
935
|
+
SmartButton.CLOCK_SIZE = 30; // the px of the drawing
|
|
936
|
+
SmartButton.createClockSvg = function (clockStyle) {
|
|
937
|
+
SmartButton.injectCss();
|
|
938
|
+
if (clockStyle.isRing) return SmartButton.createRingSvg(clockStyle);
|
|
939
|
+
const c = clockStyle;
|
|
940
|
+
const size = SmartButton.CLOCK_SIZE;
|
|
941
|
+
const middle = size / 2;
|
|
942
|
+
const faceRadius = middle - c.edgeWidth / 2; // WHY: the edge is drawn on the circle line: it stays inside
|
|
943
|
+
const hand = function (x2, y2, width, color, turnTime) {
|
|
944
|
+
return '<line class="smart-button-hand" x1="' + middle + '" y1="' + middle + '" x2="' + x2 + '" y2="' + y2 + '" stroke="' + color +
|
|
945
|
+
'" stroke-width="' + width + '" stroke-linecap="round" style="animation-duration: ' + turnTime + 's"/>';
|
|
946
|
+
};
|
|
947
|
+
return '<svg viewBox="0 0 ' + size + ' ' + size + '" width="100%" height="100%" aria-hidden="true" style="display: block">' +
|
|
948
|
+
'<circle cx="' + middle + '" cy="' + middle + '" r="' + faceRadius + '" fill="' + c.faceColor + '" stroke="' + c.lineColor + '" stroke-width="' + c.edgeWidth + '"/>' +
|
|
949
|
+
hand(middle + c.hourLength, middle, c.hourWidth, c.hourColor || c.lineColor, c.hourTurn) + // the hour hand (under)
|
|
950
|
+
hand(middle, middle - c.minuteLength, c.minuteWidth, c.minuteColor, c.minuteTurn) + // the minute hand
|
|
951
|
+
'<circle cx="' + middle + '" cy="' + middle + '" r="' + (c.centerSize / 2) + '" fill="' + c.centerColor + '"/>' +
|
|
952
|
+
"</svg>";
|
|
953
|
+
};
|
|
954
|
+
|
|
955
|
+
// A ring that waits: a faint circle and a quarter arc turning on it (the turn of the hands of the clock)
|
|
956
|
+
SmartButton.createRingSvg = function (ring) {
|
|
957
|
+
const size = SmartButton.CLOCK_SIZE;
|
|
958
|
+
const middle = size / 2;
|
|
959
|
+
const radius = middle - ring.edgeWidth / 2;
|
|
960
|
+
const arc = "M" + middle + " " + (middle - radius) + " A" + radius + " " + radius + " 0 0 1 " + (middle + radius) + " " + middle;
|
|
961
|
+
return '<svg viewBox="0 0 ' + size + ' ' + size + '" width="100%" height="100%" aria-hidden="true" style="display: block">' +
|
|
962
|
+
'<circle cx="' + middle + '" cy="' + middle + '" r="' + radius + '" fill="none" stroke="' + ring.lineColor + '" stroke-opacity="' + ring.trackOpacity + '" stroke-width="' + ring.edgeWidth + '"/>' +
|
|
963
|
+
'<path class="smart-button-hand" d="' + arc + '" fill="none" stroke="' + ring.lineColor + '" stroke-width="' + ring.edgeWidth + '" stroke-linecap="round" style="animation-duration: ' + ring.turnTime + 's"/>' +
|
|
964
|
+
"</svg>";
|
|
965
|
+
};
|
|
966
|
+
|
|
967
|
+
// GROUP: Three dots that grow one after the other. dots: { size, gap, color }
|
|
968
|
+
SmartButton.DOT_COUNT = 3;
|
|
969
|
+
SmartButton.DOT_TIME = 1.2; // seconds for one bounce of a dot
|
|
970
|
+
SmartButton.DOT_DELAY = 0.16; // seconds between two dots
|
|
971
|
+
SmartButton.createDots = function (dots) {
|
|
972
|
+
SmartButton.injectCss();
|
|
973
|
+
const group = HGroup({ hug: 1, align: "center center", gap: dots.gap });
|
|
974
|
+
for (let i = 0; i < SmartButton.DOT_COUNT; i++) {
|
|
975
|
+
const dot = Box({ width: dots.size, height: dots.size, color: dots.color, round: 100 });
|
|
976
|
+
dot.elem.classList.add("smart-button-dot");
|
|
977
|
+
dot.css = { animation: "smart-button-dot " + SmartButton.DOT_TIME + "s ease-in-out " + (i * SmartButton.DOT_DELAY) + "s infinite" };
|
|
978
|
+
}
|
|
979
|
+
endGroup();
|
|
980
|
+
return group;
|
|
981
|
+
};
|