nice-elements 1.15.1 → 1.16.1

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/CLAUDE.md +1 -0
  3. package/README.md +1 -1
  4. package/bower.json +1 -1
  5. package/dist/nice.js +620 -509
  6. package/dist/nice.min.js +1 -1
  7. package/dist/style.css +145 -126
  8. package/dist/style.css.map +1 -1
  9. package/dist/style.min.css +2 -2
  10. package/package.json +5 -6
  11. package/src/components/nice-calendar/nice-calendar.html +3 -4
  12. package/src/components/nice-calendar/nice-calendar.scss +0 -9
  13. package/src/components/nice-date/nice-date-picker.html +60 -0
  14. package/src/components/nice-date/nice-date.html +29 -86
  15. package/src/components/nice-date/nice-date.js +7 -35
  16. package/src/components/nice-date/nice-date.scss +6 -15
  17. package/src/components/nice-datetime-picker/nice-datetime-picker.html +1 -4
  18. package/src/components/nice-datetime-picker/nice-datetime-picker.scss +9 -12
  19. package/src/components/nice-datetimerange-picker/nice-datetimerange-picker.html +1 -3
  20. package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.html +32 -30
  21. package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.js +1 -33
  22. package/src/components/nice-datetimerange-picker-2/nice-datetimerange-picker-2.scss +7 -12
  23. package/src/components/nice-dropdown/nice-dropdown.html +42 -40
  24. package/src/components/nice-dropdown/nice-dropdown.js +52 -54
  25. package/src/components/nice-dropdown/nice-dropdown.scss +25 -4
  26. package/src/components/nice-dropdown-old/nice-dropdown-old.html +1 -1
  27. package/src/components/nice-dropdown-old/nice-dropdown-old.scss +8 -2
  28. package/src/components/nice-dtp/nice-dtp.html +7 -7
  29. package/src/components/nice-notification/nice-notification.html +6 -6
  30. package/src/components/nice-notification/nice-notification.scss +7 -6
  31. package/src/components/nice-options/nice-options.scss +4 -0
  32. package/src/components/nice-popup/nice-popup.html +4 -4
  33. package/src/components/nice-popup/nice-popup.js +61 -75
  34. package/src/components/nice-popup/nice-popup.scss +10 -31
  35. package/src/components/nice-search/nice-search.html +21 -26
  36. package/src/components/nice-search/nice-search.js +9 -12
  37. package/src/components/nice-search/nice-search.scss +9 -10
  38. package/src/components/nice-search2/nice-search2.html +22 -18
  39. package/src/components/nice-search2/nice-search2.js +12 -56
  40. package/src/components/nice-search2/nice-search2.scss +3 -2
  41. package/src/components/nice-svgs/nice-svgs.html +8 -0
  42. package/src/components/nice-time-picker/nice-time-picker.html +1 -3
  43. package/src/components/nice-time-picker/nice-time-picker.scss +0 -8
  44. package/src/directives/nice-tooltip/_nice-tooltip.scss +7 -28
  45. package/src/directives/nice-tooltip/nice-tooltip.js +16 -29
  46. package/src/services/nice-service.js +236 -1
  47. package/src/styles/_nice-anchored.scss +75 -0
  48. package/src/styles/_nice.scss +1 -0
@@ -5,6 +5,12 @@
5
5
  * @name niceElements.directive:nicePopup
6
6
  * @description
7
7
  * # nicePopup
8
+ * Shows content next to a target. Positioned with NiceService.anchor()
9
+ * (native popover + CSS anchor positioning, Popper fallback).
10
+ *
11
+ * trigger="click" (default): clicking the target toggles it, clicking outside closes it.
12
+ * trigger="manual": the parent opens and closes it through is-open.
13
+ * Escape always closes it (also in "manual", is-open is set to false).
8
14
  */
9
15
  angular.module('niceElements')
10
16
  .directive('nicePopup', function () {
@@ -16,92 +22,69 @@ angular.module('niceElements')
16
22
  'content': '?nicePopupContent'
17
23
  },
18
24
  scope: {
19
- offsetDistance: '@', // distance, displaces the popper away from, or toward, the reference element in the direction of its placement
20
- offsetSkidding: '@', // skidding, displaces the popper along the reference element.
21
- placement: '@', // Describes the preferred placement of the popper
22
- strategy: '@',
25
+ isOpen: '=?', // two-way open state
26
+ trigger: '@', // "click" (default) or "manual"
27
+ offsetDistance: '@', // gap in px between the target and the content
28
+ offsetSkidding: '@', // shift in px along the target
29
+ placement: '@', // preferred placement, e.g. "bottom-start"
30
+ strategy: '@', // Popper strategy (fallback only)
23
31
  showArrow: '@',
32
+ sameWidth: '@', // content as wide as the target
24
33
  onChange: '&?',
25
34
  },
26
- controller: function ($scope, $element, $timeout) {
27
- $scope.isOpen = false;
28
- if (!$scope.showArrow) { $scope.showArrow = false; }
29
- if (!$scope.offsetDistance && $scope.showArrow) { $scope.offsetDistance = 8; }
30
- if (!$scope.offsetDistance) { $scope.offsetDistance = 5; }
31
- if (!$scope.offsetSkidding) { $scope.offsetSkidding = 0; }
35
+ controller: function ($scope, $element, $attrs, $timeout, NiceService) {
36
+ NiceService.bindFlag($scope, $attrs, 'showArrow');
37
+ NiceService.bindFlag($scope, $attrs, 'sameWidth');
38
+ if (!$scope.isOpen) { $scope.isOpen = false; }
39
+ if (!$scope.trigger) { $scope.trigger = "click"; }
32
40
  if (!$scope.placement) { $scope.placement = "auto"; }
33
- if (!$scope.strategy) { $scope.strategy = "fixed"; }
41
+ if (!$scope.offsetDistance) { $scope.offsetDistance = $scope.showArrow ? 8 : 5; }
42
+ if (!$scope.offsetSkidding) { $scope.offsetSkidding = 0; }
34
43
 
35
- // Placements
36
- // [
37
- // 'auto',
38
- // 'auto-start',
39
- // 'auto-end',
40
- // 'top',
41
- // 'top-start',
42
- // 'top-end',
43
- // 'bottom',
44
- // 'bottom-start',
45
- // 'bottom-end',
46
- // 'right',
47
- // 'right-start',
48
- // 'right-end',
49
- // 'left',
50
- // 'left-start',
51
- // 'left-end'
52
- // ]
44
+ // Placements: auto, auto-start, auto-end, top, top-start, top-end, bottom, bottom-start,
45
+ // bottom-end, right, right-start, right-end, left, left-start, left-end
53
46
 
54
- // Setup popper
55
- // https://popper.js.org/docs/v2/constructors/
56
- $scope.setupPopper = function () {
47
+ let anchored = null;
48
+
49
+ // Template is in the DOM after the first digest
50
+ const setupTimer = $timeout(function () {
57
51
  const target = $element[0].getElementsByClassName('nice-popup-target')[0];
58
52
  const content = $element[0].getElementsByClassName('nice-popup-content')[0];
59
- $scope.popper = Popper.createPopper(target, content, {
53
+ const arrow = $element[0].getElementsByClassName('nice-popup-arrow')[0];
54
+ anchored = NiceService.anchor(target, content, {
60
55
  placement: $scope.placement,
56
+ offset: parseInt($scope.offsetDistance),
57
+ skidding: parseInt($scope.offsetSkidding),
58
+ sameWidth: $scope.sameWidth,
61
59
  strategy: $scope.strategy,
62
- modifiers: [
63
- {
64
- name: 'offset',
65
- options: {
66
- offset: [$scope.offsetSkidding, $scope.offsetDistance],
67
- },
68
- },
69
- {
70
- name: 'arrow',
71
- options: {
72
- padding: 5, // 5px from the edges of the popper
73
- },
74
- },
75
- // {
76
- // name: "sameWidth",
77
- // enabled: true,
78
- // phase: "beforeWrite",
79
- // requires: ["computeStyles"],
80
- // fn: function (e) {
81
- // var state = e.state;
82
- // state.styles.popper.width = state.rects.reference.width + "px";
83
- // },
84
- // effect: function (e) {
85
- // var state = e.state;
86
- // state.elements.popper.style.width = state.elements.reference.offsetWidth + "px";
87
- // }
88
- // }
89
- ],
60
+ arrow: arrow,
61
+ onEscape: function () {
62
+ $timeout(function () { $scope.close(); });
63
+ }
90
64
  });
91
- };
65
+ if ($scope.isOpen) anchored.open();
66
+ });
92
67
 
93
- const setupTimer = $timeout(function () {
94
- $scope.setupPopper();
68
+ // Show or hide the content when the state changes
69
+ $scope.$watch('isOpen', function (isOpen, wasOpen) {
70
+ if (!anchored) return;
71
+ if (isOpen) {
72
+ anchored.open();
73
+ // Content is rendered with ng-if, update once it's there
74
+ $timeout(function () { if (anchored) anchored.update(); });
75
+ } else {
76
+ anchored.close();
77
+ }
78
+ if (isOpen !== wasOpen && $scope.onChange) $scope.onChange({ isOpen: isOpen });
95
79
  });
96
80
 
97
- // Popper adds scroll/resize listeners to window; remove them with the component
98
81
  $scope.$on('$destroy', function () {
99
82
  $timeout.cancel(setupTimer);
100
- if ($scope.popper) $scope.popper.destroy();
101
- $scope.popper = null;
83
+ if (anchored) anchored.destroy();
84
+ anchored = null;
102
85
  });
103
86
 
104
- // -----------------------------------Open -----------------------------------
87
+ // ----------------------------------- Open -----------------------------------
105
88
  $scope.toggle = function () {
106
89
  if ($scope.isOpen) {
107
90
  $scope.close();
@@ -112,17 +95,20 @@ angular.module('niceElements')
112
95
 
113
96
  $scope.close = function () {
114
97
  $scope.isOpen = false;
115
- if ($scope.onChange) $scope.onChange({ isOpen: $scope.isOpen });
116
98
  };
117
99
 
118
100
  $scope.open = function () {
119
- if ($scope.popper) $scope.popper.update();
120
101
  $scope.isOpen = true;
121
- if ($scope.onChange) $scope.onChange({ isOpen: $scope.isOpen });
122
- $timeout(function () {
123
- if ($scope.popper) $scope.popper.update();
124
- });
102
+ };
103
+
104
+ // Click on target / outside only does something in "click" mode
105
+ $scope.targetClicked = function () {
106
+ if ($scope.trigger != 'manual') $scope.toggle();
107
+ };
108
+
109
+ $scope.clickedOutside = function () {
110
+ if ($scope.trigger != 'manual') $scope.close();
125
111
  };
126
112
  }
127
113
  };
128
- });
114
+ });
@@ -1,44 +1,23 @@
1
+ // Positioning and arrow placement come from _nice-anchored.scss
2
+
3
+ // Single class on purpose: components can make the target a block (".nice-x .nice-popup-target")
4
+ .nice-popup-target {
5
+ display: inline-block;
6
+ }
7
+
1
8
  .nice-popup {
2
- .nice-popup-target {
3
- display: inline-block;
4
- }
5
9
 
6
- .nice-popup-arrow[data-hide] {
7
- visibility: hidden;
10
+ .nice-popup-arrow {
11
+ z-index: -1;
8
12
  }
9
13
 
10
- .nice-popup-arrow,
11
14
  .nice-popup-arrow::before {
12
15
  position: absolute;
13
16
  width: 8px;
14
17
  height: 8px;
15
- z-index: -1;
16
- }
17
-
18
- .nice-popup-arrow::before {
19
18
  content: '';
20
19
  transform: rotate(45deg);
21
20
  background: #ffffff;
22
21
  border: 1px solid $nice-border-color;
23
22
  }
24
-
25
- .nice-popup-content {
26
- z-index: 1;
27
- }
28
-
29
- .nice-popup-content[data-popper-placement^='top']>.nice-popup-arrow {
30
- bottom: -4px;
31
- }
32
-
33
- .nice-popup-content[data-popper-placement^='bottom']>.nice-popup-arrow {
34
- top: -4px;
35
- }
36
-
37
- .nice-popup-content[data-popper-placement^='left']>.nice-popup-arrow {
38
- right: -4px;
39
- }
40
-
41
- .nice-popup-content[data-popper-placement^='right']>.nice-popup-arrow {
42
- left: -4px;
43
- }
44
- }
23
+ }
@@ -5,36 +5,31 @@
5
5
 
6
6
  <!------------------------- Field ------------------------->
7
7
  <div class="nice-field col-xs-12" ng-class="[fieldWidth ? fieldWidth : 'col-sm-8', { 'nice-disabled': isDisabled }]">
8
- <div class="input-group" ng-class="{ 'disabled': isDisabled }">
9
- <input class="form-control" type="text" id="{{ id }}" ng-model="modelString" ng-keypress="keypress($event)" placeholder="{{ placeholder }}" ng-disabled="isDisabled" ng-change="updateSearch()" ng-required="required" tabindex="{{ tabIndex }}">
8
+ <div class="nice-search-field" click-outside="closeDropdown()" is-open="{{ results.length > 0 || noResults }}">
9
+ <div class="input-group" ng-class="{ 'disabled': isDisabled }">
10
+ <input class="form-control" type="text" id="{{ id }}" ng-model="modelString" ng-keypress="keypress($event)" placeholder="{{ placeholder }}" ng-disabled="isDisabled" ng-change="updateSearch()" ng-required="required" tabindex="{{ tabIndex }}">
10
11
 
11
- <button type="button" class="btn input-group-addon" ng-click="search()" ng-if="!model" ng-disabled="isDisabled">
12
- <!-- <i ng-show="!loading" class="fa fa-search"></i>
13
- <i ng-show="loading" class="fa fa-refresh fa-spin"></i> -->
14
- <!-- <nice-icon ng-show="loading" icon="icon-loader" class="d-block nice-animation-spin"></nice-icon> -->
15
- <nice-icon ng-show="!loading" icon="icon-search"></nice-icon>
16
- <nice-loader ng-if="loading"></nice-loader>
17
- </button>
12
+ <button type="button" class="btn input-group-addon" ng-click="search()" ng-if="!model" ng-disabled="isDisabled">
13
+ <!-- <nice-icon ng-show="loading" icon="icon-loader" class="d-block nice-animation-spin"></nice-icon> -->
14
+ <nice-icon ng-show="!loading" icon="icon-search"></nice-icon>
15
+ <nice-loader ng-if="loading"></nice-loader>
16
+ </button>
18
17
 
19
- <button type="button" class="btn input-group-addon" ng-click="remove()" ng-if="model" ng-disabled="isDisabled">
20
- <!-- <i ng-show="!loading" class="fa fa-remove"></i> -->
21
- <nice-icon ng-show="!loading" icon="icon-x"></nice-icon>
22
- </button>
23
- </div>
24
- </div>
25
- </div>
18
+ <button type="button" class="btn input-group-addon" ng-click="remove()" ng-if="model" ng-disabled="isDisabled">
19
+ <nice-icon ng-show="!loading" icon="icon-x"></nice-icon>
20
+ </button>
21
+ </div>
26
22
 
27
- <div class="row" ng-if="noResults || results.length">
28
- <div ng-class="labelWidth ? labelWidth : 'col-sm-4'" ng-if="title"></div>
29
- <div class="nice-field col-xs-12" ng-class="fieldWidth ? fieldWidth : 'col-sm-8'">
30
- <div class="nice-dropdown-empty" ng-if="noResults">
31
- <div class="nice-search-row" translate translate-context="Nice">No results found.</div>
32
- </div>
23
+ <!------------------------- Dropdown ------------------------->
24
+ <div class="nice-dropdown-empty" ng-if="noResults">
25
+ <div class="nice-search-row" translate translate-context="Nice">No results found.</div>
26
+ </div>
33
27
 
34
- <div class="nice-dropdown" ng-if="results.length">
35
- <div ng-repeat="result in results" class="nice-search-row" ng-class="{'active': selectedIndex == $index}" ng-click="selectRow(result)">
36
- <span class="text-bold" ng-if="!hasRowTemplate">{{ result[keyForInputLabel] }}</span>
37
- <div ng-if="hasRowTemplate" nice-search-row-transclude></div>
28
+ <div class="nice-dropdown" ng-if="results.length">
29
+ <div ng-repeat="result in results" class="nice-search-row" ng-class="{'active': selectedIndex == $index}" ng-click="selectRow(result)">
30
+ <span class="text-bold" ng-if="!hasRowTemplate">{{ result[keyForInputLabel] }}</span>
31
+ <div ng-if="hasRowTemplate" nice-search-row-transclude></div>
32
+ </div>
38
33
  </div>
39
34
  </div>
40
35
  </div>
@@ -119,19 +119,12 @@ angular.module('niceElements')
119
119
  //scope.$apply();
120
120
  };
121
121
 
122
- // Close the dropdown if clicked outside
123
- const onClick = function (event) {
124
- const isClickedElementChildOfPopup = element.find(event.target).length > 0;
125
-
126
- if (isClickedElementChildOfPopup) return;
127
-
122
+ // Close the dropdown (called by click-outside in the template)
123
+ scope.closeDropdown = function () {
128
124
  scope.results = [];
129
125
  scope.noResults = false;
130
- scope.$apply();
131
126
  };
132
127
 
133
- angular.element(element).on('click', onClick);
134
-
135
128
  // Keyboard up/down on search results
136
129
  const onKeyDown = function (event) {
137
130
  if ((event.keyCode == 38 || event.keyCode == 40 || event.keyCode == 13 || event.keyCode == 27) && scope.results && scope.results.length > 0) {
@@ -163,7 +156,6 @@ angular.module('niceElements')
163
156
  angular.element(element).on('keydown', onKeyDown);
164
157
 
165
158
  scope.$on('$destroy', function () {
166
- angular.element(element).off('click', onClick);
167
159
  angular.element(element).off('keydown', onKeyDown);
168
160
  });
169
161
 
@@ -216,10 +208,15 @@ angular.module('niceElements')
216
208
  }
217
209
  $scope.requests = $scope.requests + 1;
218
210
  const requestNumber = angular.copy($scope.requests);
211
+ // $timeout so the view updates also when refreshFunction returns a native Promise
219
212
  $scope.refreshFunction($scope.modelString).then(function (response) {
220
- updateList(response, requestNumber);
213
+ $timeout(function () {
214
+ updateList(response, requestNumber);
215
+ });
221
216
  }, function (error) {
222
- $scope.loading = false;
217
+ $timeout(function () {
218
+ $scope.loading = false;
219
+ });
223
220
  });
224
221
  // Why was this here?
225
222
  // $scope.model = $scope.modelString;
@@ -24,13 +24,19 @@
24
24
  }
25
25
  }
26
26
 
27
+ // Positioning parent of the dropdown (wraps the input)
28
+ .nice-search-field {
29
+ position: relative;
30
+ }
31
+
32
+ // Dropdown sits right under the input, same width
27
33
  .nice-dropdown {
28
34
  position: absolute;
29
35
  z-index: 999;
30
- //top: 35px;
36
+ top: 100%;
31
37
  left: 0;
32
- // right: 0;
33
- //min-width: 340px;
38
+ right: 0;
39
+ margin-top: 4px;
34
40
  max-height: 300px;
35
41
  background-color: white;
36
42
  border-radius: $nice-border-radius;
@@ -40,10 +46,6 @@
40
46
  -webkit-box-shadow: 0 0 1px rgba(0, 0, 0, 0.175);
41
47
  box-shadow: 0 0 1px rgba(0, 0, 0, 0.175);
42
48
 
43
- top: -13px;
44
- margin: 15px;
45
- right: 0;
46
-
47
49
  .nice-search-row {
48
50
  padding: 10px 15px;
49
51
  z-index: 1000;
@@ -79,9 +81,6 @@
79
81
 
80
82
  .nice-dropdown-empty {
81
83
  @extend .nice-dropdown;
82
- top: -13px;
83
- margin: 15px;
84
- right: 0;
85
84
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
86
85
 
87
86
  .nice-search-row {
@@ -5,29 +5,33 @@
5
5
 
6
6
  <!------------------------- Field ------------------------->
7
7
  <div class="nice-field col-xs-12" ng-class="[fieldWidth ? fieldWidth : 'col-sm-8', { 'nice-disabled': isDisabled }]" click-outside="close()">
8
- <div class="nice-search-button input-group" ng-class="{ 'disabled': isDisabled }">
9
- <input class="form-control" type="text" id="{{ id }}" ng-model="model" placeholder="{{ placeholder }}" ng-disabled="isDisabled" ng-change="updateSearch()" ng-focus="onFocus()" ng-required="required" tabindex="{{ tabIndex }}">
8
+ <nice-popup trigger="manual" is-open="isOpen" placement="{{ placement }}" same-width="true">
9
+ <nice-popup-target>
10
+ <div class="nice-search-button input-group" ng-class="{ 'disabled': isDisabled }">
11
+ <input class="form-control" type="text" id="{{ id }}" ng-model="modelAccessor" ng-model-options="{ getterSetter: true }" placeholder="{{ placeholder }}" ng-disabled="isDisabled" ng-change="updateSearch()" ng-focus="onFocus()" ng-required="required" tabindex="{{ tabIndex }}">
10
12
 
11
- <button type="button" class="btn input-group-addon" ng-disabled="isDisabled" ng-click="buttonClicked()">
12
- <nice-icon ng-show="!loading && model != ''" icon="icon-x"></nice-icon>
13
- <nice-icon ng-show="!loading && model == ''" icon="icon-search"></nice-icon>
14
- <nice-loader ng-if="loading"></nice-loader>
15
- </button>
16
- </div>
17
-
18
- <div class="nice-search-dropdown-wrapper">
19
- <div class="nice-search-dropdown" ng-if="showDropdown && isOpen">
20
- <div class="nice-search-row nice-search-row-loading" ng-if="loading && results.length == 0">
21
- <nice-loader ng-if="loading"></nice-loader>
13
+ <button type="button" class="btn input-group-addon" ng-disabled="isDisabled" ng-click="buttonClicked()">
14
+ <nice-icon ng-show="!loading && model != ''" icon="icon-x"></nice-icon>
15
+ <nice-icon ng-show="!loading && model == ''" icon="icon-search"></nice-icon>
16
+ <nice-loader ng-if="loading"></nice-loader>
17
+ </button>
22
18
  </div>
19
+ </nice-popup-target>
20
+
21
+ <nice-popup-content>
22
+ <div class="nice-search-dropdown" ng-if="showDropdown && isOpen">
23
+ <div class="nice-search-row nice-search-row-loading" ng-if="loading && results.length == 0">
24
+ <nice-loader ng-if="loading"></nice-loader>
25
+ </div>
23
26
 
24
- <div class="nice-search-row nice-search-row-empty" ng-if="!loading && results.length == 0" translate translate-context="Nice">No results found.</div>
27
+ <div class="nice-search-row nice-search-row-empty" ng-if="!loading && results.length == 0" translate translate-context="Nice">No results found.</div>
25
28
 
26
- <div ng-repeat="result in results" class="nice-search-row" ng-class="{'active': selectedIndex == $index}" ng-click="selectItem(result)">
27
- <ng-transclude>{{ result[keyForInputLabel] }}</ng-transclude>
29
+ <div ng-repeat="result in results" class="nice-search-row" ng-class="{'active': selectedIndex == $index}" ng-click="selectItem(result)">
30
+ <ng-transclude>{{ result[keyForInputLabel] }}</ng-transclude>
31
+ </div>
28
32
  </div>
29
- </div>
30
- </div>
33
+ </nice-popup-content>
34
+ </nice-popup>
31
35
  </div>
32
36
  </div>
33
37
  </ng-form>
@@ -24,7 +24,7 @@ angular.module('niceElements')
24
24
  labelWidth: '@',
25
25
  refreshFunction: '=',
26
26
  refreshSelectedCallback: '=',
27
- onSelect: '=',
27
+ onSelect: '&?',
28
28
  onChange: '&?',
29
29
  noMargin: '@',
30
30
  tabIndex: '@',
@@ -33,7 +33,7 @@ angular.module('niceElements')
33
33
  isInline: '=',
34
34
  help: '@',
35
35
  required: '=',
36
- placement: '@', // Describes the preferred placement of the popper
36
+ placement: '@', // Preferred placement of the dropdown (nice-popup)
37
37
  },
38
38
  controller: function ($scope, $timeout, $element) {
39
39
  $scope.loading = false;
@@ -48,51 +48,14 @@ angular.module('niceElements')
48
48
  if (!$scope.model) $scope.model = "";
49
49
  if (!$scope.placement) { $scope.placement = "bottom-start"; }
50
50
 
51
- // Setup popper
52
- // https://popper.js.org/docs/v2/constructors/
53
- $scope.setupPopper = function () {
54
- const button = $element[0].getElementsByClassName('nice-search-button')[0];
55
- const tooltip = $element[0].getElementsByClassName('nice-search-dropdown-wrapper')[0];
56
- $scope.popper = Popper.createPopper(button, tooltip, {
57
- strategy: 'fixed',
58
- placement: $scope.placement,
59
- modifiers: [
60
- {
61
- name: 'offset',
62
- options: {
63
- offset: [0, 5],
64
- },
65
- },
66
- {
67
- name: "sameWidth",
68
- enabled: true,
69
- phase: "beforeWrite",
70
- requires: ["computeStyles"],
71
- fn: function (e) {
72
- const state = e.state;
73
- state.styles.popper.width = state.rects.reference.width + "px";
74
- },
75
- effect: function (e) {
76
- const state = e.state;
77
- state.elements.popper.style.width = state.elements.reference.offsetWidth + "px";
78
- }
79
- }
80
- ],
81
- });
51
+ // ------------------- Model accessor -------------------
52
+ // Input lives inside nice-popup's transcluded (child) scope, so a plain ng-model="model"
53
+ // would write to the child scope only. Bind through a getter/setter instead.
54
+ $scope.modelAccessor = function (value) {
55
+ if (arguments.length) $scope.model = value;
56
+ return $scope.model;
82
57
  };
83
58
 
84
- const setupTimer = $timeout(function () {
85
- $scope.setupPopper();
86
- });
87
-
88
- // Popper adds scroll/resize listeners to window; remove them with the component
89
- $scope.$on('$destroy', function () {
90
- $timeout.cancel(setupTimer);
91
- if ($scope.popper) $scope.popper.destroy();
92
- $scope.popper = null;
93
- });
94
-
95
-
96
59
  // ------------------- On focus -------------------
97
60
  $scope.onFocus = function () {
98
61
  if ($scope.showDropdown && $scope.results.length == 0) {
@@ -115,22 +78,12 @@ angular.module('niceElements')
115
78
  // ------------------- On focus -------------------
116
79
  $scope.open = function () {
117
80
  $scope.isOpen = true;
118
- $timeout(function () {
119
- if ($scope.popper) $scope.popper.update();
120
- });
121
81
  };
122
82
 
123
83
 
124
84
  // ------------------- On blur -------------------
125
85
  $scope.close = function () {
126
86
  $scope.isOpen = false;
127
-
128
- // const input = $element[0].getElementsByTagName('input')[0];
129
- // if (input) input.blur();
130
-
131
- $timeout(function () {
132
- if ($scope.popper) $scope.popper.update();
133
- });
134
87
  };
135
88
 
136
89
 
@@ -206,7 +159,10 @@ angular.module('niceElements')
206
159
  // ------------------------ Select item ------------------------
207
160
  $scope.selectItem = function (item) {
208
161
  if ($scope.onSelect) {
209
- $scope.onSelect(item);
162
+ // Supports on-select="fn(model)" (expression) and on-select="fn" (function reference):
163
+ // the expression form is evaluated directly, the reference form returns the function to call.
164
+ const result = $scope.onSelect({ model: item });
165
+ if (angular.isFunction(result)) result(item);
210
166
  $scope.clear();
211
167
  $scope.close();
212
168
  }
@@ -14,8 +14,9 @@
14
14
  }
15
15
  }
16
16
 
17
- .nice-search-dropdown-wrapper {
18
- z-index: 999;
17
+ // Dropdown is a nice-popup as wide as the input
18
+ .nice-popup-target {
19
+ display: block;
19
20
  }
20
21
 
21
22
  .nice-search-dropdown {
@@ -245,6 +245,10 @@
245
245
  <path d="M23 12c0-3.037-1.232-5.789-3.222-7.778s-4.741-3.222-7.778-3.222-5.789 1.232-7.778 3.222-3.222 4.741-3.222 7.778 1.232 5.789 3.222 7.778 4.741 3.222 7.778 3.222 5.789-1.232 7.778-3.222 3.222-4.741 3.222-7.778zM21 12c0 2.486-1.006 4.734-2.636 6.364s-3.878 2.636-6.364 2.636-4.734-1.006-6.364-2.636-2.636-3.878-2.636-6.364 1.006-4.734 2.636-6.364 3.878-2.636 6.364-2.636 4.734 1.006 6.364 2.636 2.636 3.878 2.636 6.364z"></path>
246
246
  </symbol>
247
247
 
248
+ <symbol id="icon-dot" viewBox="0 0 24 24">
249
+ <path d="M12 6a6 6 0 1 1 0 12a6 6 0 1 1 0-12z"></path>
250
+ </symbol>
251
+
248
252
  <symbol id="icon-clipboard" viewBox="0 0 24 24">
249
253
  <path d="M7 5c0 0.552 0.225 1.053 0.586 1.414s0.862 0.586 1.414 0.586h6c0.552 0 1.053-0.225 1.414-0.586s0.586-0.862 0.586-1.414h1c0.276 0 0.525 0.111 0.707 0.293s0.293 0.431 0.293 0.707v14c0 0.276-0.111 0.525-0.293 0.707s-0.431 0.293-0.707 0.293h-12c-0.276 0-0.525-0.111-0.707-0.293s-0.293-0.431-0.293-0.707v-14c0-0.276 0.111-0.525 0.293-0.707s0.431-0.293 0.707-0.293zM9 1c-0.552 0-1.053 0.225-1.414 0.586s-0.586 0.862-0.586 1.414h-1c-0.828 0-1.58 0.337-2.121 0.879s-0.879 1.293-0.879 2.121v14c0 0.828 0.337 1.58 0.879 2.121s1.293 0.879 2.121 0.879h12c0.828 0 1.58-0.337 2.121-0.879s0.879-1.293 0.879-2.121v-14c0-0.828-0.337-1.58-0.879-2.121s-1.293-0.879-2.121-0.879h-1c0-0.552-0.225-1.053-0.586-1.414s-0.862-0.586-1.414-0.586zM9 3h6v2h-6z"></path>
250
254
  </symbol>
@@ -778,6 +782,10 @@
778
782
  </symbol>
779
783
 
780
784
  <symbol id="icon-plus" viewBox="0 0 24 24">
785
+ <path d="M10.5 5.5a1.5 1.5 0 0 1 3 0v5h5a1.5 1.5 0 0 1 0 3h-5v5a1.5 1.5 0 0 1-3 0v-5h-5a1.5 1.5 0 0 1 0-3h5z"></path>
786
+ </symbol>
787
+
788
+ <symbol id="icon-plus-2" viewBox="0 0 24 24">
781
789
  <path d="M5 13h6v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6h6c0.552 0 1-0.448 1-1s-0.448-1-1-1h-6v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1v6h-6c-0.552 0-1 0.448-1 1s0.448 1 1 1z"></path>
782
790
  </symbol>
783
791
 
@@ -4,7 +4,7 @@
4
4
  <nice-title text="title || niceTitle" help="help" required="required" description="description" label-width="labelWidth"></nice-title>
5
5
 
6
6
  <!------------------------- Field ------------------------->
7
- <div class="nice-field col-xs-12" ng-class="fieldWidth ? fieldWidth : 'col-sm-8'">
7
+ <div class="nice-field col-xs-12" ng-class="fieldWidth ? fieldWidth : 'col-sm-8'" click-outside="close()" is-open="{{ open }}">
8
8
  <div class="input-group" ng-class="{
9
9
  'has-warning': !isDisabled && forma.$invalid && forma.$dirty,
10
10
  'disabled': isDisabled
@@ -39,6 +39,4 @@
39
39
  </div>
40
40
  </div>
41
41
  </div>
42
-
43
- <div class="nice-background" ng-click="close()" ng-if="open"></div>
44
42
  </div>
@@ -27,12 +27,4 @@
27
27
  }
28
28
  }
29
29
 
30
- .nice-background {
31
- position: fixed;
32
- top: 0;
33
- left: 0;
34
- width: 100%;
35
- z-index: 800;
36
- height: 100%;
37
- }
38
30
  }