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,403 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
UI Standards - v26.09
|
|
6
|
+
|
|
7
|
+
The design tokens of a page: colors, text sizes, corner radius, spacing, motion time and screen sizes.
|
|
8
|
+
And the themes (light, dark, your own) of those colors.
|
|
9
|
+
- One file, no CSS file: the theme colors are written into the page as CSS variables (--color-primary...).
|
|
10
|
+
- The color tokens are CSS variables (UI.COLOR_PRIMARY = "var(--color-primary)"), so a theme change updates
|
|
11
|
+
every object at once. There is no need to create the objects again or to reload the page.
|
|
12
|
+
- The names say the job of a token, and the job is the same in every theme: UI.COLOR_SURFACE is the card
|
|
13
|
+
color (white in light, black in dark), UI.COLOR_TEXT is the text color.
|
|
14
|
+
- Themes: "light" (default), "dark", "auto" (follows the operating system) and the themes you define.
|
|
15
|
+
- Style presets: prop lists for labels, buttons and cards. Use them when you create an object or later.
|
|
16
|
+
- Effects (hover, press, animations) are not here: use comp/ui-effects.js (UIEffects).
|
|
17
|
+
|
|
18
|
+
LOAD ORDER: basic.css, basic.js, ui-standards.js, components, page code.
|
|
19
|
+
Load it in <head>: the theme is set before the page is drawn, so there is no white flash in the dark theme.
|
|
20
|
+
|
|
21
|
+
TOKENS:
|
|
22
|
+
Backgrounds: COLOR_PAGE, COLOR_SURFACE, COLOR_SURFACE_SOFT
|
|
23
|
+
Texts: COLOR_TEXT, COLOR_TEXT_STRONG, COLOR_TEXT_SOFT, COLOR_BUTTON_TEXT
|
|
24
|
+
Lines: COLOR_BORDER
|
|
25
|
+
Brand: COLOR_PRIMARY, COLOR_SECONDARY
|
|
26
|
+
States: COLOR_SUCCESS, COLOR_WARNING, COLOR_DANGER, COLOR_INFO
|
|
27
|
+
Palette: COLOR_PINK, COLOR_GREEN, COLOR_BLUE, COLOR_RED, COLOR_YELLOW, COLOR_SAND
|
|
28
|
+
Grays: COLOR_GRAY_100, 200, 300, 500, 700, 900
|
|
29
|
+
Text: FONT_XXL (32), FONT_XL (26), FONT_L (20), FONT_M (16), FONT_S (12), FONT_FAMILY, FONT_FAMILY_BOLD
|
|
30
|
+
Corners: ROUND_XS (2), ROUND_S (4), ROUND_M (8), ROUND_L (13), ROUND_FULL (100)
|
|
31
|
+
Space: PADDING_X, PADDING_Y, MARGIN_X, MARGIN_Y, SPACING_S (8), SPACING_M (16), SPACING_L (32)
|
|
32
|
+
Other: TRANSITION, BREAKPOINTS
|
|
33
|
+
Styles: title, text, caption, tag, invertedTag, badge, button, secondaryButton, textButton, card, panel
|
|
34
|
+
|
|
35
|
+
USAGE:
|
|
36
|
+
page.color = UI.COLOR_PAGE;
|
|
37
|
+
Label({ text: "Title", ...UI.styles.title }); // A style preset when creating.
|
|
38
|
+
Button({ text: "Save", ...UI.styles.button, width: 160 }); // Your props after the preset win.
|
|
39
|
+
UI.style(that, "secondaryButton"); // A style preset after creating.
|
|
40
|
+
Box({ color: UI.alpha(UI.COLOR_PRIMARY, 0.15) }); // A token with alpha (follows the theme).
|
|
41
|
+
UI.setTheme("dark"); UI.setTheme("auto"); UI.toggleTheme();
|
|
42
|
+
UI.loadTheme("light"); // The saved theme (or "light"). Later changes are saved.
|
|
43
|
+
UI.onThemeChange(function (themeName) { ... }); // Returns a remover function.
|
|
44
|
+
UI.isDark(); // 1 or 0
|
|
45
|
+
UI.getColor(UI.COLOR_PRIMARY); // "#689BD2" (for canvas, Chart.js...)
|
|
46
|
+
UI.defineTheme("sepia", { page: "#F4ECD8", primary: "#8B5E3C" }); // Missing colors come from "light".
|
|
47
|
+
UI.motion(["background-color", "opacity"]); // "background-color 0.2s ease, opacity 0.2s ease"
|
|
48
|
+
UI.breakpoint(); // "XS", "SM", "MD", "LG" or "XL" (window width)
|
|
49
|
+
|
|
50
|
+
Started Date: 2025
|
|
51
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
52
|
+
|
|
53
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
54
|
+
Licensed under the Apache License, Version 2.0
|
|
55
|
+
SPDX-License-Identifier: Apache-2.0
|
|
56
|
+
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
"use strict";
|
|
60
|
+
|
|
61
|
+
const UI = {
|
|
62
|
+
|
|
63
|
+
// *** COLORS: (CSS variables, they follow the theme)
|
|
64
|
+
|
|
65
|
+
// Backgrounds:
|
|
66
|
+
COLOR_PAGE: "var(--color-page)", // The page
|
|
67
|
+
COLOR_SURFACE: "var(--color-surface)", // Cards, panels, inputs (white in light, black in dark)
|
|
68
|
+
COLOR_SURFACE_SOFT: "var(--color-surface-soft)", // Soft filled areas: tags, panels, pressed rows
|
|
69
|
+
|
|
70
|
+
// Texts:
|
|
71
|
+
COLOR_TEXT: "var(--color-text)", // Normal text
|
|
72
|
+
COLOR_TEXT_STRONG: "var(--color-text-strong)", // The highest contrast (black in light, white in dark)
|
|
73
|
+
COLOR_TEXT_SOFT: "var(--color-text-soft)", // Descriptions, hints
|
|
74
|
+
COLOR_BUTTON_TEXT: "var(--color-button-text)", // Text on the primary and secondary buttons
|
|
75
|
+
|
|
76
|
+
// Lines:
|
|
77
|
+
COLOR_BORDER: "var(--color-border)",
|
|
78
|
+
|
|
79
|
+
// Brand:
|
|
80
|
+
COLOR_PRIMARY: "var(--color-primary)",
|
|
81
|
+
COLOR_SECONDARY: "var(--color-secondary)",
|
|
82
|
+
|
|
83
|
+
// States:
|
|
84
|
+
COLOR_SUCCESS: "var(--color-success)",
|
|
85
|
+
COLOR_WARNING: "var(--color-warning)",
|
|
86
|
+
COLOR_DANGER: "var(--color-danger)",
|
|
87
|
+
COLOR_INFO: "var(--color-info)",
|
|
88
|
+
|
|
89
|
+
// Palette: (same in every theme; for charts, tags, avatars...)
|
|
90
|
+
COLOR_PINK: "var(--color-pink)",
|
|
91
|
+
COLOR_GREEN: "var(--color-green)",
|
|
92
|
+
COLOR_BLUE: "var(--color-blue)",
|
|
93
|
+
COLOR_RED: "var(--color-red)",
|
|
94
|
+
COLOR_YELLOW: "var(--color-yellow)",
|
|
95
|
+
COLOR_SAND: "var(--color-sand)",
|
|
96
|
+
|
|
97
|
+
// Grays: 100 is near the page color, 900 is near the text color. (So they change places in the dark theme.)
|
|
98
|
+
COLOR_GRAY_100: "var(--color-gray-100)",
|
|
99
|
+
COLOR_GRAY_200: "var(--color-gray-200)",
|
|
100
|
+
COLOR_GRAY_300: "var(--color-gray-300)",
|
|
101
|
+
COLOR_GRAY_500: "var(--color-gray-500)",
|
|
102
|
+
COLOR_GRAY_700: "var(--color-gray-700)",
|
|
103
|
+
COLOR_GRAY_900: "var(--color-gray-900)",
|
|
104
|
+
|
|
105
|
+
// *** TEXT:
|
|
106
|
+
|
|
107
|
+
FONT_XXL: 32,
|
|
108
|
+
FONT_XL: 26,
|
|
109
|
+
FONT_L: 20,
|
|
110
|
+
FONT_M: 16,
|
|
111
|
+
FONT_S: 12,
|
|
112
|
+
|
|
113
|
+
FONT_FAMILY: "opensans",
|
|
114
|
+
FONT_FAMILY_BOLD: "opensans-bold",
|
|
115
|
+
|
|
116
|
+
// *** CORNERS: (round)
|
|
117
|
+
|
|
118
|
+
ROUND_XS: 2,
|
|
119
|
+
ROUND_S: 4,
|
|
120
|
+
ROUND_M: 8,
|
|
121
|
+
ROUND_L: 13,
|
|
122
|
+
ROUND_FULL: 100, // Pills and circles
|
|
123
|
+
|
|
124
|
+
// *** SPACE:
|
|
125
|
+
|
|
126
|
+
PADDING_X: 12, // Inside labels and buttons (left and right)
|
|
127
|
+
PADDING_Y: 4, // Inside labels and buttons (top and bottom)
|
|
128
|
+
|
|
129
|
+
MARGIN_X: 20, // Page edges
|
|
130
|
+
MARGIN_Y: 20,
|
|
131
|
+
|
|
132
|
+
SPACING_S: 8, // Gaps between objects
|
|
133
|
+
SPACING_M: 16,
|
|
134
|
+
SPACING_L: 32,
|
|
135
|
+
|
|
136
|
+
// *** MOTION:
|
|
137
|
+
|
|
138
|
+
TRANSITION: "0.2s ease",
|
|
139
|
+
|
|
140
|
+
// *** SCREEN: Minimum window widths (px).
|
|
141
|
+
|
|
142
|
+
BREAKPOINTS: {
|
|
143
|
+
SM: 480,
|
|
144
|
+
MD: 768,
|
|
145
|
+
LG: 1024,
|
|
146
|
+
XL: 1280,
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// *** THEMES:
|
|
152
|
+
// Each key is a CSS variable: primary -> --color-primary. scheme: "light" or "dark" (native inputs and scroll bars).
|
|
153
|
+
|
|
154
|
+
UI.themes = {
|
|
155
|
+
|
|
156
|
+
light: {
|
|
157
|
+
scheme: "light",
|
|
158
|
+
|
|
159
|
+
"page": "#F6F6F6",
|
|
160
|
+
"surface": "#FFFFFF",
|
|
161
|
+
"surface-soft": "#EBEBEB",
|
|
162
|
+
|
|
163
|
+
"text": "#373836",
|
|
164
|
+
"text-strong": "#000000",
|
|
165
|
+
"button-text": "rgba(0, 0, 0, 0.70)",
|
|
166
|
+
|
|
167
|
+
"primary": "#689BD2",
|
|
168
|
+
"secondary": "cadetblue",
|
|
169
|
+
|
|
170
|
+
"pink": "#CC75AA",
|
|
171
|
+
"green": "#86BA84",
|
|
172
|
+
"blue": "#23ACCF",
|
|
173
|
+
"red": "#FE5D49",
|
|
174
|
+
"yellow": "#F1C74A",
|
|
175
|
+
"sand": "#D3CFC1",
|
|
176
|
+
|
|
177
|
+
"gray-100": "#F6F6F6",
|
|
178
|
+
"gray-200": "#D8D8D8",
|
|
179
|
+
"gray-300": "#B7B7B7",
|
|
180
|
+
"gray-500": "#999",
|
|
181
|
+
"gray-700": "#4A4A4A",
|
|
182
|
+
"gray-900": "#141414",
|
|
183
|
+
},
|
|
184
|
+
|
|
185
|
+
dark: {
|
|
186
|
+
scheme: "dark",
|
|
187
|
+
|
|
188
|
+
"page": "#141414",
|
|
189
|
+
"surface": "#000000",
|
|
190
|
+
"surface-soft": "#373836",
|
|
191
|
+
|
|
192
|
+
"text": "#EBEBEB",
|
|
193
|
+
"text-strong": "#FFFFFF",
|
|
194
|
+
"button-text": "rgba(255, 255, 255, 0.70)",
|
|
195
|
+
|
|
196
|
+
"primary": "#344f6c",
|
|
197
|
+
"secondary": "rgb(57, 96, 97)",
|
|
198
|
+
|
|
199
|
+
"pink": "#CC75AA",
|
|
200
|
+
"green": "#86BA84",
|
|
201
|
+
"blue": "#23ACCF",
|
|
202
|
+
"red": "#FE5D49",
|
|
203
|
+
"yellow": "#F1C74A",
|
|
204
|
+
"sand": "#D3CFC1",
|
|
205
|
+
|
|
206
|
+
"gray-100": "#141414",
|
|
207
|
+
"gray-200": "#4A4A4A",
|
|
208
|
+
"gray-300": "#999",
|
|
209
|
+
"gray-500": "#B7B7B7",
|
|
210
|
+
"gray-700": "#D8D8D8",
|
|
211
|
+
"gray-900": "#F6F6F6",
|
|
212
|
+
},
|
|
213
|
+
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
// The colors that use other colors by default. A theme can give its own values.
|
|
217
|
+
UI.linkedColors = {
|
|
218
|
+
"text-soft": "var(--color-gray-500)",
|
|
219
|
+
"border": "var(--color-gray-200)",
|
|
220
|
+
"success": "var(--color-green)",
|
|
221
|
+
"warning": "var(--color-yellow)",
|
|
222
|
+
"danger": "var(--color-red)",
|
|
223
|
+
"info": "var(--color-blue)",
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
// *** STYLE PRESETS:
|
|
227
|
+
// Prop lists. Button({ text: "OK", ...UI.styles.button }) or UI.style(btn, "button").
|
|
228
|
+
|
|
229
|
+
UI.styles = {
|
|
230
|
+
|
|
231
|
+
// LABELS:
|
|
232
|
+
title: { fontSize: UI.FONT_XL, fontFamily: UI.FONT_FAMILY_BOLD, textColor: UI.COLOR_TEXT },
|
|
233
|
+
text: { fontSize: UI.FONT_M, textColor: UI.COLOR_TEXT },
|
|
234
|
+
caption: { fontSize: UI.FONT_S, textColor: UI.COLOR_TEXT_SOFT },
|
|
235
|
+
tag: { fontSize: UI.FONT_L, textColor: UI.COLOR_TEXT, color: UI.COLOR_SURFACE_SOFT, padding: [UI.PADDING_X, UI.PADDING_Y] },
|
|
236
|
+
invertedTag: { fontSize: UI.FONT_L, textColor: UI.COLOR_SURFACE_SOFT, color: UI.COLOR_TEXT, padding: [UI.PADDING_X, UI.PADDING_Y] },
|
|
237
|
+
badge: { fontSize: UI.FONT_S, textColor: "white", color: UI.COLOR_DANGER, round: UI.ROUND_FULL, padding: [8, 2] },
|
|
238
|
+
|
|
239
|
+
// BUTTONS:
|
|
240
|
+
button: { fontSize: UI.FONT_L, textColor: UI.COLOR_BUTTON_TEXT, color: UI.COLOR_PRIMARY },
|
|
241
|
+
secondaryButton: { fontSize: UI.FONT_L, textColor: UI.COLOR_BUTTON_TEXT, color: UI.COLOR_SECONDARY, minimal: 1 },
|
|
242
|
+
textButton: { fontSize: UI.FONT_M, textColor: UI.COLOR_PRIMARY, color: "transparent", minimal: 1 },
|
|
243
|
+
|
|
244
|
+
// BOXES:
|
|
245
|
+
card: { color: UI.COLOR_SURFACE, round: UI.ROUND_M, border: 1, borderColor: UI.COLOR_BORDER },
|
|
246
|
+
panel: { color: UI.COLOR_SURFACE_SOFT, round: UI.ROUND_S },
|
|
247
|
+
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
// *** SETTINGS:
|
|
251
|
+
UI.storageKey = "ui-theme"; // loadTheme() and the next setTheme() calls save the theme with this key.
|
|
252
|
+
|
|
253
|
+
// *** STATE: (read only)
|
|
254
|
+
UI.theme = "light"; // The selected theme: "light", "dark", "auto" or your theme.
|
|
255
|
+
UI.activeTheme = ""; // The theme on the screen now. ("auto" -> "light" or "dark")
|
|
256
|
+
|
|
257
|
+
// *** PUBLIC FUNCTIONS:
|
|
258
|
+
|
|
259
|
+
// Selects a theme: "light", "dark", "auto" or a theme from defineTheme().
|
|
260
|
+
UI.setTheme = function (themeName = "light") {
|
|
261
|
+
if (themeName !== "auto" && !UI.themes[themeName]) {
|
|
262
|
+
println("UI: Unknown theme: " + themeName, "error");
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
UI.theme = themeName;
|
|
266
|
+
UI._applyActiveTheme();
|
|
267
|
+
if (!UI._isSaving) return;
|
|
268
|
+
// WHY: The storage can throw (a private window, blocked site data). The theme still changes.
|
|
269
|
+
try { basic.storage.save(UI.storageKey, themeName); } catch (e) {}
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
// Selects the saved theme (or defaultThemeName), and saves the next theme changes.
|
|
273
|
+
UI.loadTheme = function (defaultThemeName = "light") {
|
|
274
|
+
let savedThemeName = null;
|
|
275
|
+
try { savedThemeName = basic.storage.load(UI.storageKey); } catch (e) {}
|
|
276
|
+
const isValid = savedThemeName === "auto" || (savedThemeName && UI.themes[savedThemeName]);
|
|
277
|
+
UI._isSaving = 1;
|
|
278
|
+
UI.setTheme(isValid ? savedThemeName : defaultThemeName);
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
// Light <-> dark.
|
|
282
|
+
UI.toggleTheme = function () {
|
|
283
|
+
UI.setTheme(UI.isDark() ? "light" : "dark");
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
UI.isDark = function () {
|
|
287
|
+
const theme = UI.themes[UI.activeTheme];
|
|
288
|
+
return (theme && theme.scheme === "dark") ? 1 : 0;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
// Runs when the theme on the screen changes: fn(themeName). Returns a function that removes it.
|
|
292
|
+
UI.onThemeChange = function (fn) {
|
|
293
|
+
UI._themeListeners.push(fn);
|
|
294
|
+
return function () {
|
|
295
|
+
const index = UI._themeListeners.indexOf(fn);
|
|
296
|
+
if (index > -1) UI._themeListeners.splice(index, 1);
|
|
297
|
+
};
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
// Adds a theme, or changes the colors of a theme. The missing colors come from "light" (or "dark" with scheme: "dark").
|
|
301
|
+
// UI.defineTheme("dark", { primary: "#2B4A6F" }); UI.defineTheme("ocean", { scheme: "dark", page: "#0B1E2D" });
|
|
302
|
+
UI.defineTheme = function (themeName, colors = {}) {
|
|
303
|
+
const base = UI.themes[themeName] || UI.themes[(colors.scheme === "dark") ? "dark" : "light"];
|
|
304
|
+
UI.themes[themeName] = Object.assign({}, base, colors);
|
|
305
|
+
UI._writeThemeCss();
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
// The value of a color in the current theme: UI.getColor(UI.COLOR_PRIMARY) or UI.getColor("primary") -> "#689BD2"
|
|
309
|
+
// Use it where CSS variables do not work (canvas, Chart.js). Read it again after a theme change.
|
|
310
|
+
UI.getColor = function (color) {
|
|
311
|
+
const match = String(color).match(/^var\((--[\w-]+)\)$/);
|
|
312
|
+
const cssName = match ? match[1] : "--color-" + color;
|
|
313
|
+
return getComputedStyle(document.documentElement).getPropertyValue(cssName).trim();
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
// A color with alpha. It works with the tokens too, and follows the theme.
|
|
317
|
+
// UI.alpha(UI.COLOR_PRIMARY, 0.2) -> "color-mix(in srgb, var(--color-primary) 20%, transparent)"
|
|
318
|
+
UI.alpha = function (color, alpha) {
|
|
319
|
+
return "color-mix(in srgb, " + color + " " + Math.round(alpha * 100) + "%, transparent)";
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
// A token for a color that has no constant (your own theme keys): UI.color("brand") -> "var(--color-brand)"
|
|
323
|
+
UI.color = function (name) {
|
|
324
|
+
return "var(--color-" + name + ")";
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
// Applies a style preset to an object. extraProps are applied after it.
|
|
328
|
+
// UI.style(that, "card"); UI.style(btn, "button", { width: 200 });
|
|
329
|
+
UI.style = function (obj, styleName, extraProps = {}) {
|
|
330
|
+
const preset = UI.styles[styleName];
|
|
331
|
+
if (!preset) {
|
|
332
|
+
println("UI: Unknown style: " + styleName, "error");
|
|
333
|
+
return obj;
|
|
334
|
+
}
|
|
335
|
+
const props = Object.assign({}, preset, extraProps);
|
|
336
|
+
for (const key in props) obj[key] = props[key];
|
|
337
|
+
return obj;
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
// A motion string for setMotion(): UI.motion(["opacity", "left"]) -> "opacity 0.2s ease, left 0.2s ease"
|
|
341
|
+
UI.motion = function (names = [], transition = UI.TRANSITION) {
|
|
342
|
+
if (!Array.isArray(names)) names = [names];
|
|
343
|
+
return names.map(function (name) { return name + " " + transition; }).join(", ");
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
// The screen size name of a width: "XS" (smaller than SM), "SM", "MD", "LG", "XL".
|
|
347
|
+
UI.breakpoint = function (width = window.innerWidth) {
|
|
348
|
+
let result = "XS";
|
|
349
|
+
for (const name in UI.BREAKPOINTS) {
|
|
350
|
+
if (width >= UI.BREAKPOINTS[name]) result = name;
|
|
351
|
+
}
|
|
352
|
+
return result;
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
// *** PRIVATE:
|
|
356
|
+
|
|
357
|
+
UI._themeListeners = [];
|
|
358
|
+
UI._isSaving = 0;
|
|
359
|
+
UI._styleElement = null;
|
|
360
|
+
UI._darkQuery = (window.matchMedia) ? window.matchMedia("(prefers-color-scheme: dark)") : null;
|
|
361
|
+
|
|
362
|
+
// Writes all themes into one <style>: ":root[data-theme='dark'] { --color-page: #141414; ... }"
|
|
363
|
+
UI._writeThemeCss = function () {
|
|
364
|
+
let css = "";
|
|
365
|
+
for (const themeName in UI.themes) {
|
|
366
|
+
const theme = Object.assign({}, UI.linkedColors, UI.themes[themeName]);
|
|
367
|
+
let selector = ":root[data-theme=\"" + themeName + "\"]";
|
|
368
|
+
// WHY: The light colors are also the default, before a theme is selected.
|
|
369
|
+
if (themeName === "light") selector = ":root, " + selector;
|
|
370
|
+
css += selector + " {\n";
|
|
371
|
+
for (const key in theme) {
|
|
372
|
+
if (key === "scheme") continue;
|
|
373
|
+
css += " --color-" + key + ": " + theme[key] + ";\n";
|
|
374
|
+
}
|
|
375
|
+
css += " color-scheme: " + (theme.scheme || "light") + ";\n}\n";
|
|
376
|
+
}
|
|
377
|
+
UI._styleElement = basic.addCss("ui-standards-themes", css, 1); // (replace: the themes can change)
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
UI._applyActiveTheme = function () {
|
|
381
|
+
let themeName = UI.theme;
|
|
382
|
+
if (themeName === "auto") {
|
|
383
|
+
const isSystemDark = UI._darkQuery && UI._darkQuery.matches;
|
|
384
|
+
themeName = (isSystemDark) ? "dark" : "light";
|
|
385
|
+
}
|
|
386
|
+
const isChanged = (themeName !== UI.activeTheme);
|
|
387
|
+
UI.activeTheme = themeName;
|
|
388
|
+
document.documentElement.setAttribute("data-theme", themeName);
|
|
389
|
+
if (isChanged) {
|
|
390
|
+
UI._themeListeners.slice().forEach(function (fn) { fn(themeName); });
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
// *** INIT:
|
|
395
|
+
UI._writeThemeCss();
|
|
396
|
+
UI._applyActiveTheme();
|
|
397
|
+
|
|
398
|
+
// "auto": follows the operating system while the page is open.
|
|
399
|
+
if (UI._darkQuery && UI._darkQuery.addEventListener) {
|
|
400
|
+
UI._darkQuery.addEventListener("change", function () {
|
|
401
|
+
if (UI.theme === "auto") UI._applyActiveTheme();
|
|
402
|
+
});
|
|
403
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/* Bismillah */
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
|
|
5
|
+
UrlField - v26.11
|
|
6
|
+
|
|
7
|
+
UI COMPONENT TEMPLATE
|
|
8
|
+
- You can customize, this template code as you need:
|
|
9
|
+
- NEW PROJECTS: styleName "light" (the default) on a light page, "dark" on a dark page (the packages
|
|
10
|
+
of TextField, comp/text-field.js; the look of 02-comp-examples/text-field-8-light-dark.htm), unless the user asks for another one.
|
|
11
|
+
|
|
12
|
+
Started Date: July 2025
|
|
13
|
+
Webpage: https://bug7a.github.io/js-components/
|
|
14
|
+
|
|
15
|
+
Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
|
|
16
|
+
Licensed under the Apache License, Version 2.0
|
|
17
|
+
SPDX-License-Identifier: Apache-2.0
|
|
18
|
+
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
"use strict";
|
|
22
|
+
|
|
23
|
+
// Default values
|
|
24
|
+
const UrlFieldDefaults = {
|
|
25
|
+
width: 400,
|
|
26
|
+
required: 1,
|
|
27
|
+
titleText: "URL",
|
|
28
|
+
placeholder: "example.com",
|
|
29
|
+
warningText: "Invalid URL format",
|
|
30
|
+
warningColor: "#E5885E",
|
|
31
|
+
maxLength: 255,
|
|
32
|
+
rightPadding: 20,
|
|
33
|
+
tinySelectParams: {
|
|
34
|
+
titleText: "",
|
|
35
|
+
list: [
|
|
36
|
+
{ value: "1", label: "http://" },
|
|
37
|
+
{ value: "2", label: "https://" },
|
|
38
|
+
{ value: "3", label: "http://www." },
|
|
39
|
+
{ value: "4", label: "https://www." },
|
|
40
|
+
],
|
|
41
|
+
selectedIndex: 3,
|
|
42
|
+
paddingX: 0,
|
|
43
|
+
arrowSize: 20,
|
|
44
|
+
// NOTE: The colors, the round, the height (selectStyle) and the size of the text (inputFontSize) come from the
|
|
45
|
+
// style package of TextField; a value given here wins.
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const UrlField = function(params = {}) {
|
|
50
|
+
|
|
51
|
+
params.createInput = 0; // WHY: The input is made here, after the TinySelect of the protocol.
|
|
52
|
+
|
|
53
|
+
// WHY the style package of TextField first: a key it sets (warningColor, rightPadding) wins over the defaults here, as
|
|
54
|
+
// over the defaults of TextField
|
|
55
|
+
basic.applyStylePackage(params, TextField.styles, TextFieldDefaults);
|
|
56
|
+
|
|
57
|
+
// BOX: Component container
|
|
58
|
+
const box = startExtendedObject(TextField, UrlFieldDefaults, params);
|
|
59
|
+
|
|
60
|
+
// *** PRIVATE VARIABLES:
|
|
61
|
+
|
|
62
|
+
// *** PUBLIC VARIABLES:
|
|
63
|
+
|
|
64
|
+
// *** PRIVATE FUNCTIONS:
|
|
65
|
+
|
|
66
|
+
// The params of the protocol select: the look of selectStyle (TextField) and the text color of the field,
|
|
67
|
+
// then the tinySelectParams of the page over them.
|
|
68
|
+
const getTinySelectParams = function() {
|
|
69
|
+
const selectStyle = box.selectStyle;
|
|
70
|
+
const lookParams = {
|
|
71
|
+
fontSize: box.inputFontSize, // WHY: not 20 in every package: the 15 px text of light and dark
|
|
72
|
+
color: selectStyle.color,
|
|
73
|
+
round: selectStyle.round,
|
|
74
|
+
invertIconColor: selectStyle.invertIconColor,
|
|
75
|
+
labelTextColor: box.inputTextColor, // WHY: not "#373836": dark on a dark package
|
|
76
|
+
listBackgroundColor: selectStyle.listBackgroundColor,
|
|
77
|
+
listTextColor: selectStyle.listTextColor,
|
|
78
|
+
listOverTextColor: selectStyle.listOverTextColor,
|
|
79
|
+
listBorderColor: selectStyle.listBorderColor,
|
|
80
|
+
};
|
|
81
|
+
// WHY only with a spacing: without it the select keeps its own height, taller than the field, which cuts it
|
|
82
|
+
if (selectStyle.spacing > 0) lookParams.height = box.inputHeight - 2 * selectStyle.spacing;
|
|
83
|
+
const tinySelectParams = Object.assign(lookParams, box.tinySelectParams);
|
|
84
|
+
const pageOnChange = tinySelectParams.onChange;
|
|
85
|
+
// WHY: another protocol is another value, and onChange was not called: a form that listens to it missed it
|
|
86
|
+
tinySelectParams.onChange = function(select) {
|
|
87
|
+
if (pageOnChange) pageOnChange(select);
|
|
88
|
+
if (box.input.text !== "") box.onChange(box);
|
|
89
|
+
};
|
|
90
|
+
return tinySelectParams;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// *** PUBLIC FUNCTIONS:
|
|
94
|
+
box.isValid = function() { // OVERRIDE
|
|
95
|
+
|
|
96
|
+
// WHY a regex literal: in the old text form "\s" was only "s" (a JS text drops the "\"), so every path with
|
|
97
|
+
// an "s" was not valid ("/news") and a path with a space was
|
|
98
|
+
const regex = /^(([a-zA-Z0-9-]+)\.)+[a-zA-Z]{2,}(:\d{2,5})?(\/\S*)?$/; // domain.com, :3000, /path?query=1
|
|
99
|
+
|
|
100
|
+
// WHY: getValue() gives the protocol too ("https://..."): the text alone is box.input.text
|
|
101
|
+
return (regex.test(box.input.text)) ? 1 : 0;
|
|
102
|
+
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
box.getValue = function() { // *** OVERRIDE ***
|
|
106
|
+
// WHY "": an empty field was "https://www." (the protocol alone): never "Required", and a form sent it
|
|
107
|
+
if (box.input.text === "") return "";
|
|
108
|
+
return box.tinySelect.list[box.tinySelect.selectedIndex].label + box.input.text;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// The protocol of the list that starts the value (the longest: "https://www." before "https://"), or -1
|
|
112
|
+
const findProtocolIndex = function(value) {
|
|
113
|
+
const list = box.tinySelect.list;
|
|
114
|
+
let found = -1;
|
|
115
|
+
list.forEach(function(item, index) {
|
|
116
|
+
const isLonger = (found === -1 || item.label.length > list[found].label.length);
|
|
117
|
+
if (value.indexOf(item.label) === 0 && isLonger) found = index;
|
|
118
|
+
});
|
|
119
|
+
return found;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const superSetValue = box.setValue;
|
|
123
|
+
// WHY: getValue() gives the protocol and the text; the setValue of TextField wrote them all into the text,
|
|
124
|
+
// so a saved value came back as "https://www.https://www.example.com" and could not be sent
|
|
125
|
+
box.setValue = function(value) { // *** OVERRIDE ***
|
|
126
|
+
const text = String(value ?? "");
|
|
127
|
+
const index = findProtocolIndex(text);
|
|
128
|
+
if (index === -1) {
|
|
129
|
+
superSetValue(text);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
box.tinySelect.setSelectedIndex(index, 1);
|
|
133
|
+
superSetValue(text.slice(box.tinySelect.list[index].label.length));
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// *** OBJECT VIEW:
|
|
137
|
+
AutoLayout({
|
|
138
|
+
color: "transparent",
|
|
139
|
+
});
|
|
140
|
+
box.inputBox.add(that);
|
|
141
|
+
|
|
142
|
+
box.tinySelect = TinySelect(getTinySelectParams());
|
|
143
|
+
box.tinySelect.lblLabel.css.fontFamily = "opensans";
|
|
144
|
+
|
|
145
|
+
box.input = Input({
|
|
146
|
+
text: box.value,
|
|
147
|
+
minimal: 1,
|
|
148
|
+
fontSize: box.inputFontSize,
|
|
149
|
+
height: 40,
|
|
150
|
+
color: "transparent",
|
|
151
|
+
width: "100%",
|
|
152
|
+
});
|
|
153
|
+
that.inputElement.style.padding = "0px 4px";
|
|
154
|
+
that.inputElement.placeholder = box.placeholder;
|
|
155
|
+
box.applyTextColors(that.inputElement);
|
|
156
|
+
that.inputElement.maxLength = box.maxLength;
|
|
157
|
+
that.inputElement.setAttribute("aria-label", box.titleText);
|
|
158
|
+
|
|
159
|
+
endAutoLayout();
|
|
160
|
+
|
|
161
|
+
// *** OBJECT INIT CODE:
|
|
162
|
+
const inputElem = box.input.inputElement;
|
|
163
|
+
|
|
164
|
+
// WHY: box.paintFocus() of TextField: this copy did not change the border on focus.
|
|
165
|
+
box.focusFunc = function () {
|
|
166
|
+
box.paintFocus(1);
|
|
167
|
+
box.onFocus(box);
|
|
168
|
+
}
|
|
169
|
+
inputElem.addEventListener("focus", function(){ box.focusFunc() });
|
|
170
|
+
|
|
171
|
+
box.blurFunc = function () {
|
|
172
|
+
box.paintFocus(0);
|
|
173
|
+
box.onBlur(box);
|
|
174
|
+
}
|
|
175
|
+
inputElem.addEventListener("blur", function(){ box.blurFunc() });
|
|
176
|
+
|
|
177
|
+
box.inputFunc = function () { // A child component can override it.
|
|
178
|
+
box.applyFormattedValueToInput();
|
|
179
|
+
box.checkIfInputIsRequiredAndEmpty();
|
|
180
|
+
box.showWarningIfNotValid(box.isValid());
|
|
181
|
+
box.onChange(box);
|
|
182
|
+
}
|
|
183
|
+
inputElem.addEventListener("input", function(){ box.inputFunc() });
|
|
184
|
+
|
|
185
|
+
// WHY: a start value with its protocol (as getValue() gives it) was put whole into the text
|
|
186
|
+
if (findProtocolIndex(box.input.text) > -1) box.setValue(box.input.text);
|
|
187
|
+
box.checkInputValue(); // WHY: the valid check too (the start value was only checked for required)
|
|
188
|
+
|
|
189
|
+
return endExtendedObject(box);
|
|
190
|
+
};
|