ui-optago 1.0.3 → 1.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.
- package/README.md +24 -4
- package/optago-credit-dark.html +99 -0
- package/optago-credit-light.html +98 -0
- package/package.json +5 -3
- package/ui-optago.css +2073 -1990
- package/ui-optago.js +75 -10
package/ui-optago.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* ============================================================================
|
|
2
|
-
UI ÓPTAGO
|
|
2
|
+
UI ÓPTAGO: Design System v1.1.0 (JavaScript)
|
|
3
3
|
Sem dependências de build. Carregue no <head> SEM defer para evitar
|
|
4
4
|
flash de tema errado (FOUC):
|
|
5
5
|
|
|
@@ -24,6 +24,12 @@
|
|
|
24
24
|
data-op-loading-form → no <form>: mostra a tela de carregamento
|
|
25
25
|
sozinho ao submeter (mensagem opcional em
|
|
26
26
|
data-op-loading-message="Enviando...")
|
|
27
|
+
data-op-reveal / data-op-reveal-toggle → mostrar/ocultar senha (envolva o
|
|
28
|
+
input com data-op-reveal e ponha o botão
|
|
29
|
+
com data-op-reveal-toggle dentro)
|
|
30
|
+
data-op-toast='[{"type":"success","message":"Oi"}]' → dispara toasts a
|
|
31
|
+
partir de flash messages do servidor,
|
|
32
|
+
sem precisar de <script> inline (CSP-safe)
|
|
27
33
|
|
|
28
34
|
API global: OptagoUI.toast(msg, tipo, ms) · OptagoUI.openModal(sel)
|
|
29
35
|
OptagoUI.closeModal(sel) · OptagoUI.setTheme('dark'|'light')
|
|
@@ -34,8 +40,13 @@
|
|
|
34
40
|
|
|
35
41
|
var OptagoUI = {};
|
|
36
42
|
|
|
43
|
+
// Fonte única da versão exibida no badge do header e no rodapé
|
|
44
|
+
// (elementos com o atributo data-op-version). Atualize só aqui.
|
|
45
|
+
var VERSION = '1.1.0';
|
|
46
|
+
OptagoUI.version = VERSION;
|
|
47
|
+
|
|
37
48
|
/* --------------------------------------------------------------------------
|
|
38
|
-
1. TEMA
|
|
49
|
+
1. TEMA: aplicado imediatamente (antes do primeiro paint)
|
|
39
50
|
-------------------------------------------------------------------------- */
|
|
40
51
|
var THEME_KEY = 'op-theme';
|
|
41
52
|
|
|
@@ -127,7 +138,7 @@
|
|
|
127
138
|
};
|
|
128
139
|
|
|
129
140
|
/* --------------------------------------------------------------------------
|
|
130
|
-
4. TOASTS
|
|
141
|
+
4. TOASTS: OptagoUI.toast('Mensagem', 'success'|'error'|'warning'|'info')
|
|
131
142
|
-------------------------------------------------------------------------- */
|
|
132
143
|
var TOAST_ICONS = {
|
|
133
144
|
success: 'ph-check-circle',
|
|
@@ -155,11 +166,17 @@
|
|
|
155
166
|
toast.innerHTML =
|
|
156
167
|
'<div class="op-toast-icon"><i class="ph ' + (TOAST_ICONS[type] || TOAST_ICONS.info) + '"></i></div>' +
|
|
157
168
|
'<span></span>' +
|
|
158
|
-
'<button class="op-toast-close" aria-label="Fechar"><i class="ph ph-x"></i></button>'
|
|
169
|
+
'<button class="op-toast-close" aria-label="Fechar"><i class="ph ph-x"></i></button>' +
|
|
170
|
+
'<div class="op-toast-progress"><div class="op-toast-progress-bar"></div></div>';
|
|
159
171
|
toast.querySelector('span').textContent = message;
|
|
160
172
|
container.appendChild(toast);
|
|
161
173
|
|
|
174
|
+
var bar = toast.querySelector('.op-toast-progress-bar');
|
|
162
175
|
var removed = false;
|
|
176
|
+
var timer = null;
|
|
177
|
+
var remaining = duration;
|
|
178
|
+
var startedAt = 0;
|
|
179
|
+
|
|
163
180
|
var dismiss = function () {
|
|
164
181
|
if (removed) return;
|
|
165
182
|
removed = true;
|
|
@@ -167,13 +184,43 @@
|
|
|
167
184
|
setTimeout(function () { toast.remove(); }, 320);
|
|
168
185
|
};
|
|
169
186
|
|
|
187
|
+
// Anima a barra de largura atual até 0 ao longo de `ms`; usar
|
|
188
|
+
// transition (não @keyframes) permite congelar no valor exato em pause().
|
|
189
|
+
var run = function (ms) {
|
|
190
|
+
startedAt = Date.now();
|
|
191
|
+
timer = setTimeout(dismiss, ms);
|
|
192
|
+
requestAnimationFrame(function () {
|
|
193
|
+
bar.style.transitionDuration = ms + 'ms';
|
|
194
|
+
bar.style.width = '0%';
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
var pause = function () {
|
|
199
|
+
if (removed || !timer) return;
|
|
200
|
+
clearTimeout(timer);
|
|
201
|
+
timer = null;
|
|
202
|
+
remaining -= Date.now() - startedAt;
|
|
203
|
+
// Congela a barra no ponto exato em px (transition-duration 0 = sem salto).
|
|
204
|
+
bar.style.width = getComputedStyle(bar).width;
|
|
205
|
+
bar.style.transitionDuration = '0ms';
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
var resume = function () {
|
|
209
|
+
if (removed || timer || remaining <= 0) return;
|
|
210
|
+
run(remaining);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
toast.addEventListener('mouseenter', pause);
|
|
214
|
+
toast.addEventListener('mouseleave', resume);
|
|
215
|
+
toast.addEventListener('focusin', pause);
|
|
216
|
+
toast.addEventListener('focusout', resume);
|
|
170
217
|
toast.querySelector('.op-toast-close').addEventListener('click', dismiss);
|
|
171
218
|
|
|
172
219
|
requestAnimationFrame(function () {
|
|
173
220
|
requestAnimationFrame(function () { toast.classList.add('is-visible'); });
|
|
174
221
|
});
|
|
175
222
|
|
|
176
|
-
|
|
223
|
+
run(duration);
|
|
177
224
|
|
|
178
225
|
return toast;
|
|
179
226
|
};
|
|
@@ -198,7 +245,7 @@
|
|
|
198
245
|
};
|
|
199
246
|
|
|
200
247
|
/* --------------------------------------------------------------------------
|
|
201
|
-
5b. TABULATOR
|
|
248
|
+
5b. TABULATOR: tabela avançada com tema Óptago
|
|
202
249
|
Uso: OptagoUI.tabulator('#minhaTabela', { data: [...], columns: [...] })
|
|
203
250
|
Carrega a biblioteca (CDN) sob demanda; o CSS base do Tabulator é
|
|
204
251
|
inserido ANTES do ui-optago.css para que o tema personalizado
|
|
@@ -246,7 +293,7 @@
|
|
|
246
293
|
};
|
|
247
294
|
|
|
248
295
|
/* --------------------------------------------------------------------------
|
|
249
|
-
5c. TELA DE CARREGAMENTO
|
|
296
|
+
5c. TELA DE CARREGAMENTO: overlay em tela cheia
|
|
250
297
|
Uso: OptagoUI.showLoading('Salvando...') ... OptagoUI.hideLoading()
|
|
251
298
|
ou data-op-loading-form no <form> para acionar sozinho no submit.
|
|
252
299
|
-------------------------------------------------------------------------- */
|
|
@@ -293,7 +340,7 @@
|
|
|
293
340
|
});
|
|
294
341
|
|
|
295
342
|
/* --------------------------------------------------------------------------
|
|
296
|
-
6. HELPERS DO SHOWCASE
|
|
343
|
+
6. HELPERS DO SHOWCASE: copiar HTML / ver código
|
|
297
344
|
-------------------------------------------------------------------------- */
|
|
298
345
|
function dedentHTML(el) {
|
|
299
346
|
var html = el.innerHTML.replace(/^\n+|\s+$/g, '');
|
|
@@ -482,9 +529,27 @@
|
|
|
482
529
|
8. INICIALIZAÇÃO no DOM pronto
|
|
483
530
|
-------------------------------------------------------------------------- */
|
|
484
531
|
function init() {
|
|
485
|
-
//
|
|
532
|
+
// Versão exibida no badge do header e no rodapé
|
|
533
|
+
document.querySelectorAll('[data-op-version]').forEach(function (el) {
|
|
534
|
+
el.textContent = 'v' + VERSION;
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
// Toasts vindos do servidor (flash messages), sem precisar de <script>
|
|
538
|
+
// inline: importante para funcionar com Content-Security-Policy estrito.
|
|
539
|
+
// Uso: <div hidden data-op-toast='[{"type":"success","message":"Oi!"}]'></div>
|
|
540
|
+
document.querySelectorAll('[data-op-toast]').forEach(function (el) {
|
|
541
|
+
try {
|
|
542
|
+
var items = JSON.parse(el.getAttribute('data-op-toast'));
|
|
543
|
+
(Array.isArray(items) ? items : [items]).forEach(function (t) {
|
|
544
|
+
OptagoUI.toast(t.message, t.type, t.duration);
|
|
545
|
+
});
|
|
546
|
+
} catch (e) { /* atributo malformado: ignora silenciosamente */ }
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
// Sidebar (desktop): fechada por padrão, mas respeita a escolha do
|
|
550
|
+
// usuário salva no localStorage assim que ele abrir/fechar uma vez.
|
|
486
551
|
var sb = getSidebar();
|
|
487
|
-
if (sb && window.innerWidth >= 1024 && localStorage.getItem(SIDEBAR_KEY)
|
|
552
|
+
if (sb && window.innerWidth >= 1024 && localStorage.getItem(SIDEBAR_KEY) !== '0') {
|
|
488
553
|
sb.classList.add('is-collapsed');
|
|
489
554
|
}
|
|
490
555
|
|