@goldenpine/react-form-builder2 0.20.3-build.31 → 0.20.3-build.32

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.
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+
3
+ (function (window, document) {
4
+ 'use strict';
5
+
6
+ var CSS_ID = 'floating-placeholder-styles';
7
+ function injectStyles() {
8
+ if (document.getElementById(CSS_ID)) return;
9
+ var css = "\n.floating-input-wrapper{position:relative}\n.floating-input-wrapper .fb-placeholder{\n position:absolute;\n left:.75rem;\n top:50%;\n transform:translateY(-50%);\n transition:all .15s ease;\n color: #6c757d;\n pointer-events:none;\n font-size:1rem;\n white-space:nowrap;\n overflow:hidden;\n text-overflow:ellipsis;\n}\n.floating-input-wrapper .fb-placeholder.shrunken{\n top:.25rem;\n transform:none;\n font-size:.75rem;\n color:#495057;\n}\n.floating-input-wrapper.has-placeholder input.form-control,\n.floating-input-wrapper.has-placeholder textarea.form-control{\n padding-top:1.5rem;\n}\n";
10
+ var style = document.createElement('style');
11
+ style.id = CSS_ID;
12
+ style.type = 'text/css';
13
+ style.appendChild(document.createTextNode(css));
14
+ (document.head || document.documentElement).appendChild(style);
15
+ }
16
+ function processWrapper(wrapper) {
17
+ if (!wrapper) return;
18
+ var input = wrapper.querySelector('input, textarea');
19
+ if (!input) return;
20
+
21
+ // find existing placeholder span or derive placeholder text
22
+ var placeholderSpan = wrapper.querySelector('.fb-placeholder');
23
+ var derivedPlaceholder = input.getAttribute('data-placeholder') || input.getAttribute('placeholder') || '';
24
+
25
+ // if span not present but placeholder text exists, create it
26
+ if (!placeholderSpan && derivedPlaceholder) {
27
+ placeholderSpan = document.createElement('span');
28
+ placeholderSpan.className = 'fb-placeholder';
29
+ placeholderSpan.textContent = derivedPlaceholder;
30
+ wrapper.appendChild(placeholderSpan);
31
+ }
32
+ if (placeholderSpan) wrapper.classList.add('has-placeholder');
33
+ var update = function update() {
34
+ var val = input.value;
35
+ if (!placeholderSpan) return;
36
+ if (val && String(val).length > 0) {
37
+ placeholderSpan.classList.add('shrunken');
38
+ } else if (document.activeElement === input) {
39
+ // keep shrunken while focused
40
+ placeholderSpan.classList.add('shrunken');
41
+ } else {
42
+ placeholderSpan.classList.remove('shrunken');
43
+ }
44
+ };
45
+ input.addEventListener('input', update);
46
+ input.addEventListener('focus', function () {
47
+ wrapper.classList.add('focused');
48
+ update();
49
+ });
50
+ input.addEventListener('blur', function () {
51
+ wrapper.classList.remove('focused');
52
+ update();
53
+ });
54
+
55
+ // clicking the wrapper focuses inner input
56
+ wrapper.addEventListener('click', function (e) {
57
+ // allow clicks on other controls inside wrapper
58
+ if (e.target === wrapper || e.target === placeholderSpan) {
59
+ input.focus();
60
+ }
61
+ });
62
+
63
+ // initial state
64
+ update();
65
+ }
66
+ function init(options) {
67
+ options = options || {};
68
+ if (options.injectStyles !== false) injectStyles();
69
+ var wrappers = document.querySelectorAll('.floating-input-wrapper');
70
+ wrappers.forEach(processWrapper);
71
+ }
72
+
73
+ // auto init on DOM ready
74
+ if (document.readyState === 'loading') {
75
+ document.addEventListener('DOMContentLoaded', function () {
76
+ return init();
77
+ });
78
+ } else {
79
+ // run on next tick
80
+ setTimeout(function () {
81
+ return init();
82
+ }, 0);
83
+ }
84
+
85
+ // expose API
86
+ window.FloatingPlaceholder = {
87
+ init: init
88
+ };
89
+ })(window, document);