simp-select 1.1.23 → 1.2.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.
@@ -63,6 +63,8 @@ export class SimpleSelectItemDOM {
63
63
 
64
64
  elemTitle!: HTMLDivElement; // not native
65
65
 
66
+ elemAlwaysLabel!: HTMLDivElement; // not native
67
+
66
68
  confirmWrap: HTMLElement | null = null; // not native
67
69
 
68
70
  confirmOk: HTMLButtonElement | null = null; // not native
@@ -208,6 +210,11 @@ export class SimpleSelectItemDOM {
208
210
  }
209
211
  }
210
212
 
213
+ /** Placeholder показывается всегда (не меняется даже если что-то выбрано). Отдельный DOM элемент */
214
+ if (this.$select.hasAttribute('data-is-label-mode')) {
215
+ this.options.isLabelMode = ifTrueDataAttr(this.$select.getAttribute('data-is-label-mode'));
216
+ }
217
+
211
218
  if (this.$select.hasAttribute('data-simple-always-open')) {
212
219
  this.options.isAlwaysOpen = ifTrueDataAttr(this.$select.getAttribute('data-simple-always-open'));
213
220
 
@@ -324,6 +331,9 @@ export class SimpleSelectItemDOM {
324
331
  resClassesWrap += ` ${getClass('up', true)}`;
325
332
  }
326
333
  resClassesWrap += ` ${this.isMulti ? getClass('multi', true) : getClass('single', true)}`;
334
+ if (this.options.isLabelMode) {
335
+ resClassesWrap += ' ' + getClass('label_mode', true);
336
+ }
327
337
  this.elemWrap.className = resClassesWrap;
328
338
  this.elemWrap.dataset.countAll = this.$select.options.length.toString();
329
339
 
@@ -471,10 +481,35 @@ export class SimpleSelectItemDOM {
471
481
  }
472
482
 
473
483
  private createTitleHTML() {
484
+ const itemsChecked = this.getChecked();
485
+ const isSelectedValue = !!itemsChecked.filter((item) => item.value).length;
486
+ const classFillValue = getClass('fill_with_value', true);
487
+ const classFillNoValue = getClass('fill_without_value', true);
488
+ if (isSelectedValue) {
489
+ this.elemWrap.classList.add(classFillValue);
490
+ this.elemWrap.classList.remove(classFillNoValue);
491
+ } else {
492
+ this.elemWrap.classList.add(classFillNoValue);
493
+ this.elemWrap.classList.remove(classFillValue);
494
+ }
495
+
474
496
  if (this.options.isRemoveTop) {
475
497
  return;
476
498
  }
477
499
 
500
+ if (this.options.isLabelMode && !this.elemAlwaysLabel) {
501
+ this.elemAlwaysLabel = document.createElement('div');
502
+ let classesTitle = getClass('label');
503
+ if (this.options.isOnlyPlaceholder) {
504
+ alert('111');
505
+ classesTitle += ` ${getClass('always-placeholder', true, classesTitle)}`;
506
+ }
507
+ this.elemAlwaysLabel.className = classesTitle;
508
+ this.elemAlwaysLabel.innerHTML = this.titlePlaceholder;
509
+ // this.elemTopBody.prepend(this.elemTitle);
510
+ this.elemTopBody.insertBefore(this.elemAlwaysLabel, this.elemTopBody.childNodes[0]);
511
+ }
512
+
478
513
  if (!this.elemTitle) {
479
514
  this.elemTitle = document.createElement('div');
480
515
  let classesTitle = getClass('title');
@@ -486,14 +521,10 @@ export class SimpleSelectItemDOM {
486
521
  this.elemTopBody.insertBefore(this.elemTitle, this.elemTopBody.childNodes[0]);
487
522
  }
488
523
 
489
- const itemsChecked = this.getChecked();
490
-
491
524
  this.elemTop.title = '';
492
525
 
493
526
  const isPlaceholder = !itemsChecked.length;
494
527
 
495
- const isSelectedValue = !!itemsChecked.filter((item) => item.value).length;
496
-
497
528
  let title:string = this.titlePlaceholder;
498
529
  if (itemsChecked.length && !this.options.isOnlyPlaceholder) {
499
530
  let attrTitle = '';
@@ -532,12 +563,7 @@ export class SimpleSelectItemDOM {
532
563
 
533
564
  this.elemTitle.innerHTML = title;
534
565
 
535
- const classFillValue = getClass('fill_with_value', true);
536
- if (isSelectedValue) {
537
- this.elemWrap.classList.add(classFillValue);
538
- } else {
539
- this.elemWrap.classList.remove(classFillValue);
540
- }
566
+
541
567
 
542
568
  if (isPlaceholder) {
543
569
  this.elemTitle.classList.add('SimpleSel__title--placeholder');
package/src/style.css CHANGED
@@ -11,6 +11,8 @@
11
11
  --simpS_color_dis: #8b8b8b;
12
12
  --simpS_status_bar: rgba(46, 122, 1, 0.67);
13
13
  --simpS_dropdownBg: var(--simpS_bg);
14
+ --simpS_labelBg: var(--simpS_bg);
15
+ --simpS_label_pad_hor: 4px;
14
16
  --simpS_borderColor: var(--simpS_color);
15
17
  --simpS_DropDownBorderColor: var(--simpS_borderColor);
16
18
 
@@ -469,3 +471,26 @@
469
471
  width: 100%;
470
472
  transition-duration: var(--duration, 1ms);
471
473
  }
474
+
475
+ /** **/
476
+ .SimpleSel--label_mode.SimpleSel--fill_without_value {
477
+ .SimpleSel__title {
478
+ opacity: 0;
479
+ visibility: hidden;
480
+ pointer-events: none;
481
+ }
482
+ }
483
+ .SimpleSel__label {
484
+ position: absolute;
485
+ top: 50%;
486
+ left: var(--simpS_pad_hor);
487
+ transform: translateY(-50%);
488
+ transition: all 0.2s ease;
489
+ pointer-events: none;
490
+ }
491
+ .SimpleSel--fill_with_value .SimpleSel__label {
492
+ top: 0;
493
+ transform: translateY(-50%);
494
+ background-color: var(--simpS_labelBg);
495
+ padding: 0 var(--simpS_label_pad_hor);
496
+ }
@@ -50,6 +50,8 @@ export interface ISimpleSelectOptions {
50
50
  isAlwaysOpen: boolean;
51
51
  isAlwaysOpenShowDisabledTabindex: boolean;
52
52
 
53
+ isLabelMode: boolean;
54
+
53
55
  detectNative?: () => boolean;
54
56
 
55
57
  isScrollToCheckedFirst: boolean;