neo.mjs 4.7.5 → 4.7.7

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.
@@ -144,12 +144,24 @@ class MainContainer extends ConfigurationViewport {
144
144
  labelText: 'required',
145
145
  listeners: {change: me.onConfigChange.bind(me, 'required')},
146
146
  style : {marginTop: '10px'}
147
+ }, {
148
+ module : CheckBox,
149
+ checked : me.exampleComponent.showOptionalText,
150
+ labelText: 'showOptionalText',
151
+ listeners: {change: me.onConfigChange.bind(me, 'showOptionalText')},
152
+ style : {marginTop: '10px'}
147
153
  }, {
148
154
  module : CheckBox,
149
155
  checked : me.exampleComponent.spellCheck,
150
156
  labelText: 'spellCheck',
151
157
  listeners: {change: me.onConfigChange.bind(me, 'spellCheck')},
152
158
  style : {marginTop: '10px'}
159
+ }, {
160
+ module : TextField,
161
+ labelText: 'subLabelText',
162
+ listeners: {change: me.onConfigChange.bind(me, 'subLabelText')},
163
+ style : {marginTop: '10px'},
164
+ value : me.exampleComponent.subLabelText
153
165
  }, {
154
166
  module : NumberField,
155
167
  labelText: 'width',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neo.mjs",
3
- "version": "4.7.5",
3
+ "version": "4.7.7",
4
4
  "description": "The webworkers driven UI framework",
5
5
  "type": "module",
6
6
  "repository": {
@@ -356,4 +356,13 @@
356
356
  flex : 0 0 auto;
357
357
  user-select: none;
358
358
  }
359
+
360
+ .neo-textfield-sublabel {
361
+ color : v(textfield-sublabel-color);
362
+ display : inline-block;
363
+ flex : 0 0 auto;
364
+ font-size : v(textfield-sublabel-font-size);
365
+ margin : v(textfield-sublabel-margin);
366
+ user-select: none;
367
+ }
359
368
  }
@@ -25,7 +25,10 @@ $neoMap: map-merge($neoMap, (
25
25
  'textfield-opacity-disabled' : #{neo(neo-disabled-opacity)},
26
26
  'textfield-opacity-readonly' : 1,
27
27
  'textfield-outline-active' : none,
28
- 'textfield-outline-hovered' : none
28
+ 'textfield-outline-hovered' : none,
29
+ 'textfield-sublabel-color' : #999,
30
+ 'textfield-sublabel-font-size' : 12px,
31
+ 'textfield-sublabel-margin' : 0 0 5px
29
32
  ));
30
33
 
31
34
  @if $useCssVars == true {
@@ -57,5 +60,8 @@ $neoMap: map-merge($neoMap, (
57
60
  --textfield-opacity-readonly : #{neo(textfield-opacity-readonly)};
58
61
  --textfield-outline-active : #{neo(textfield-outline-active)};
59
62
  --textfield-outline-hovered : #{neo(textfield-outline-hovered)};
63
+ --textfield-sublabel-color : #{neo(textfield-sublabel-color)};
64
+ --textfield-sublabel-font-size : #{neo(textfield-sublabel-font-size)};
65
+ --textfield-sublabel-margin : #{neo(textfield-sublabel-margin)};
60
66
  }
61
67
  }
@@ -25,7 +25,10 @@ $neoMap: map-merge($neoMap, (
25
25
  'textfield-opacity-disabled' : #{neo(neo-disabled-opacity)},
26
26
  'textfield-opacity-readonly' : 1,
27
27
  'textfield-outline-active' : none,
28
- 'textfield-outline-hovered' : none
28
+ 'textfield-outline-hovered' : none,
29
+ 'textfield-sublabel-color' : #666,
30
+ 'textfield-sublabel-font-size' : 12px,
31
+ 'textfield-sublabel-margin' : 0 0 5px
29
32
  ));
30
33
 
31
34
  @if $useCssVars == true {
@@ -57,5 +60,8 @@ $neoMap: map-merge($neoMap, (
57
60
  --textfield-opacity-readonly : #{neo(textfield-opacity-readonly)};
58
61
  --textfield-outline-active : #{neo(textfield-outline-active)};
59
62
  --textfield-outline-hovered : #{neo(textfield-outline-hovered)};
63
+ --textfield-sublabel-color : #{neo(textfield-sublabel-color)};
64
+ --textfield-sublabel-font-size : #{neo(textfield-sublabel-font-size)};
65
+ --textfield-sublabel-margin : #{neo(textfield-sublabel-margin)};
60
66
  }
61
67
  }
@@ -52,13 +52,13 @@ class Range extends Number {
52
52
  super.construct(config);
53
53
 
54
54
  let me = this,
55
- inputEl = me.vdom.cn[1];
55
+ inputEl = me.vdom.cn[2];
56
56
 
57
57
  if (me.useInputEvent) {
58
58
  me.addDomListeners({
59
59
  input: {
60
60
  fn : me.onInputValueChange,
61
- id : me.vdom.cn[1].id,
61
+ id : me.vdom.cn[2].id,
62
62
  scope : me
63
63
  }
64
64
  });
@@ -101,6 +101,10 @@ class Text extends Base {
101
101
  * @member {String[]} labelCls_=[]
102
102
  */
103
103
  labelCls_: [],
104
+ /**
105
+ * @member {String} labelOptionalText_=' (Optional)'
106
+ */
107
+ labelOptionalText_: ' (Optional)',
104
108
  /**
105
109
  * Valid values: 'bottom', 'inline', 'left', 'right', 'top'
106
110
  * @member {String} labelPosition_='left'
@@ -137,11 +141,27 @@ class Text extends Base {
137
141
  * @member {Boolean} required_=false
138
142
  */
139
143
  required_: false,
144
+ /**
145
+ * @member {Boolean} showOptionalText_=false
146
+ */
147
+ showOptionalText_: false,
140
148
  /**
141
149
  * null => Follow the element's default behavior for spell checking
142
150
  * @member {Boolean|null} spellCheck_=false
143
151
  */
144
152
  spellCheck_: false,
153
+ /**
154
+ * @member {String[]} subLabelBaseCls=['neo-textfield-sublabel']
155
+ */
156
+ subLabelBaseCls: ['neo-textfield-sublabel'],
157
+ /**
158
+ * @member {String[]} subLabelCls_=[]
159
+ */
160
+ subLabelCls_: [],
161
+ /**
162
+ * @member {String} subLabelText_=null
163
+ */
164
+ subLabelText_: null,
145
165
  /**
146
166
  * @member {Object|Object[]|null} triggers_=null
147
167
  */
@@ -152,6 +172,7 @@ class Text extends Base {
152
172
  _vdom:
153
173
  {cn: [
154
174
  {tag: 'label', cls: [], style: {}},
175
+ {tag: 'label', cls: []},
155
176
  {tag: 'input', cls: ['neo-textfield-input'], flag: 'neo-real-input', style: {}},
156
177
  {cls: ['neo-textfield-error'], removeDom: true}
157
178
  ]}
@@ -320,6 +341,16 @@ class Text extends Base {
320
341
  me.update();
321
342
  }
322
343
 
344
+ /**
345
+ * Triggered after the labelOptionalText config got changed
346
+ * @param {String} value
347
+ * @param {String} oldValue
348
+ * @protected
349
+ */
350
+ afterSetLabelOptionalText(value, oldValue) {
351
+ this.labelText = this.labelText; // triggers a vdom update
352
+ }
353
+
323
354
  /**
324
355
  * Triggered after the labelPosition config got changed
325
356
  * @param {String} value
@@ -327,17 +358,18 @@ class Text extends Base {
327
358
  * @protected
328
359
  */
329
360
  afterSetLabelPosition(value, oldValue) {
330
- let me = this,
331
- cls = me.cls,
332
- centerBorderElCls, isEmpty, vdom;
361
+ let me = this,
362
+ cls = me.cls,
363
+ vdom = me.vdom,
364
+ centerBorderElCls, isEmpty;
365
+
366
+ vdom.cn[1].removeDom = value !== 'top' ? true : !Boolean(me.subLabelText);
333
367
 
334
368
  NeoArray.remove(cls, 'label-' + oldValue);
335
369
  NeoArray.add(cls, 'label-' + value);
336
370
  me.cls = cls; // todo: silent update if needed
337
371
 
338
372
  if (oldValue === 'inline') {
339
- vdom = me.vdom;
340
-
341
373
  vdom.cn[0] = me.getLabelEl(); // remove the wrapper
342
374
 
343
375
  vdom.cn[0].removeDom = me.hideLabel;
@@ -391,7 +423,7 @@ class Text extends Base {
391
423
  if (!me.hideLabel) {
392
424
  if (me.labelPosition === 'inline') {
393
425
  if (!isEmpty) {
394
- delete me.getCenterBorderEl().width;
426
+ delete me.getCenterBorderEl()?.width;
395
427
  }
396
428
 
397
429
  me.promiseVdomUpdate().then(() => {
@@ -507,8 +539,21 @@ class Text extends Base {
507
539
  * @protected
508
540
  */
509
541
  afterSetRequired(value, oldValue) {
510
- this.validate(); // silent
511
- this.changeInputElKey('required', value ? value : null);
542
+ let me = this;
543
+
544
+ me.validate(); // silent
545
+ me.changeInputElKey('required', value ? value : null, true); // silent update
546
+ me.labelText = me.labelText;
547
+ }
548
+
549
+ /**
550
+ * Triggered after the showOptionalText config got changed
551
+ * @param {Boolean} value
552
+ * @param {Boolean} oldValue
553
+ * @protected
554
+ */
555
+ afterSetShowOptionalText(value, oldValue) {
556
+ this.labelText = this.labelText; // triggers a vdom update
512
557
  }
513
558
 
514
559
  /**
@@ -521,6 +566,39 @@ class Text extends Base {
521
566
  this.changeInputElKey('spellcheck', Neo.isBoolean(value) ? value : null);
522
567
  }
523
568
 
569
+ /**
570
+ * Triggered after the subLabelCls config got changed
571
+ * @param {String[]} value
572
+ * @param {String[]} oldValue
573
+ * @protected
574
+ */
575
+ afterSetSubLabelCls(value, oldValue) {
576
+ let me = this,
577
+ cls = me.vdom.cn[1].cls;
578
+
579
+ NeoArray.remove(cls, oldValue);
580
+ NeoArray.add(cls, value);
581
+
582
+ me.update();
583
+ }
584
+
585
+ /**
586
+ * Triggered after the subLabelText config got changed
587
+ * @param {String|null} value
588
+ * @param {String|null} oldValue
589
+ * @protected
590
+ */
591
+ afterSetSubLabelText(value, oldValue) {
592
+ let me = this,
593
+ showLabel = me.labelPosition === 'top',
594
+ subLabel = me.vdom.cn[1];
595
+
596
+ subLabel.html = value;
597
+ subLabel.removeDom = !showLabel;
598
+
599
+ me.update();
600
+ }
601
+
524
602
  /**
525
603
  * Triggered after the triggers config got changed
526
604
  * @param {Object[]} value
@@ -530,7 +608,7 @@ class Text extends Base {
530
608
  afterSetTriggers(value, oldValue) {
531
609
  let me = this,
532
610
  vdom = me.vdom,
533
- inputEl = vdom.cn[1], // inputEl or inputWrapperEl
611
+ inputEl = vdom.cn[2], // inputEl or inputWrapperEl
534
612
  preTriggers = [],
535
613
  postTriggers = [],
536
614
  width;
@@ -558,7 +636,7 @@ class Text extends Base {
558
636
 
559
637
  if (inputEl.tag === 'input') {
560
638
  // wrap the input tag
561
- vdom.cn[1] = {
639
+ vdom.cn[2] = {
562
640
  cls : ['neo-input-wrapper'],
563
641
  cn : [...preTriggers, inputEl, ...postTriggers],
564
642
  id : me.getInputWrapperId(),
@@ -573,8 +651,8 @@ class Text extends Base {
573
651
  if (inputEl.tag !== 'input') {
574
652
  // replacing the input wrapper div with the input tag
575
653
  width = inputEl.width;
576
- vdom.cn[1] = me.getInputEl();
577
- vdom.cn[1].width = width;
654
+ vdom.cn[2] = me.getInputEl();
655
+ vdom.cn[2].width = width;
578
656
  }
579
657
  }
580
658
 
@@ -673,6 +751,37 @@ class Text extends Base {
673
751
  return this.beforeSetEnumValue(value, oldValue, 'labelPosition');
674
752
  }
675
753
 
754
+ /**
755
+ * Triggered before the labelText config gets changed
756
+ * @param {String|null} value
757
+ * @param {String|null} oldValue
758
+ * @protected
759
+ * @returns {String}
760
+ */
761
+ beforeSetLabelText(value, oldValue) {
762
+ let me = this,
763
+ labelOptionalText = me.labelOptionalText;
764
+
765
+ if (me.showOptionalText && !me.required) {
766
+ return value + labelOptionalText;
767
+ } else if (value && value.endsWith(labelOptionalText)) {
768
+ value = value.replace(labelOptionalText, '');
769
+ }
770
+
771
+ return value;
772
+ }
773
+
774
+ /**
775
+ * Triggered before the subLabelCls config gets changed
776
+ * @param {String[]} value
777
+ * @param {String[]} oldValue
778
+ * @returns {String[]}
779
+ * @protected
780
+ */
781
+ beforeSetSubLabelCls(value, oldValue) {
782
+ return NeoArray.union(value || [], this.subLabelBaseCls);
783
+ }
784
+
676
785
  /**
677
786
  * Triggered before the triggers config gets changed
678
787
  * @param {Object|Object[]} value
@@ -722,8 +831,9 @@ class Text extends Base {
722
831
  * Changes the value of a inputEl vdom object attribute or removes it in case it has no value
723
832
  * @param {String} key
724
833
  * @param {Array|Number|Object|String|null} value
834
+ * @param {Boolean} silent=false
725
835
  */
726
- changeInputElKey(key, value) {
836
+ changeInputElKey(key, value, silent=false) {
727
837
  let me = this;
728
838
 
729
839
  if (value || Neo.isBoolean(value) || value === 0) {
@@ -732,7 +842,7 @@ class Text extends Base {
732
842
  delete me.getInputEl()[key];
733
843
  }
734
844
 
735
- me.update();
845
+ !silent && me.update();
736
846
  }
737
847
 
738
848
  /**