@refinitiv-ui/elements 6.0.0-next.0 → 6.0.0-next.3

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 (280) hide show
  1. package/lib/accordion/index.d.ts +5 -0
  2. package/lib/accordion/themes/halo/dark/index.js +1 -1
  3. package/lib/accordion/themes/halo/light/index.js +1 -1
  4. package/lib/accordion/themes/solar/charcoal/index.js +1 -1
  5. package/lib/accordion/themes/solar/pearl/index.js +1 -1
  6. package/lib/appstate-bar/index.d.ts +5 -0
  7. package/lib/appstate-bar/themes/halo/dark/index.js +1 -1
  8. package/lib/appstate-bar/themes/halo/light/index.js +1 -1
  9. package/lib/appstate-bar/themes/solar/charcoal/index.js +1 -1
  10. package/lib/appstate-bar/themes/solar/pearl/index.js +1 -1
  11. package/lib/autosuggest/index.d.ts +5 -0
  12. package/lib/autosuggest/index.js +13 -2
  13. package/lib/autosuggest/themes/halo/dark/index.js +4 -4
  14. package/lib/autosuggest/themes/halo/light/index.js +4 -4
  15. package/lib/autosuggest/themes/solar/charcoal/index.js +3 -3
  16. package/lib/autosuggest/themes/solar/pearl/index.js +3 -3
  17. package/lib/button/index.d.ts +5 -0
  18. package/lib/button/index.js +1 -1
  19. package/lib/button/themes/halo/dark/index.js +2 -2
  20. package/lib/button/themes/halo/light/index.js +2 -2
  21. package/lib/button/themes/solar/charcoal/index.js +1 -1
  22. package/lib/button/themes/solar/pearl/index.js +1 -1
  23. package/lib/button-bar/index.d.ts +5 -0
  24. package/lib/button-bar/themes/halo/dark/index.js +1 -1
  25. package/lib/button-bar/themes/halo/light/index.js +1 -1
  26. package/lib/button-bar/themes/solar/charcoal/index.js +1 -1
  27. package/lib/button-bar/themes/solar/pearl/index.js +1 -1
  28. package/lib/calendar/index.d.ts +5 -0
  29. package/lib/calendar/themes/halo/dark/index.js +2 -2
  30. package/lib/calendar/themes/halo/light/index.js +2 -2
  31. package/lib/calendar/themes/solar/charcoal/index.js +1 -1
  32. package/lib/calendar/themes/solar/pearl/index.js +1 -1
  33. package/lib/canvas/index.d.ts +5 -0
  34. package/lib/card/index.d.ts +21 -0
  35. package/lib/card/index.js +31 -8
  36. package/lib/card/themes/halo/dark/index.js +4 -4
  37. package/lib/card/themes/halo/light/index.js +4 -4
  38. package/lib/card/themes/solar/charcoal/index.js +3 -3
  39. package/lib/card/themes/solar/pearl/index.js +3 -3
  40. package/lib/chart/index.d.ts +5 -0
  41. package/lib/chart/themes/halo/dark/index.js +2 -2
  42. package/lib/chart/themes/halo/light/index.js +2 -2
  43. package/lib/chart/themes/solar/charcoal/index.js +2 -2
  44. package/lib/chart/themes/solar/pearl/index.js +2 -2
  45. package/lib/checkbox/index.d.ts +5 -0
  46. package/lib/checkbox/themes/halo/dark/index.js +2 -2
  47. package/lib/checkbox/themes/halo/light/index.js +2 -2
  48. package/lib/checkbox/themes/solar/charcoal/index.js +2 -2
  49. package/lib/checkbox/themes/solar/pearl/index.js +2 -2
  50. package/lib/clock/index.d.ts +5 -0
  51. package/lib/collapse/index.d.ts +5 -0
  52. package/lib/collapse/themes/halo/dark/index.js +4 -4
  53. package/lib/collapse/themes/halo/light/index.js +4 -4
  54. package/lib/collapse/themes/solar/charcoal/index.js +3 -3
  55. package/lib/collapse/themes/solar/pearl/index.js +3 -3
  56. package/lib/color-dialog/elements/color-palettes.d.ts +5 -0
  57. package/lib/color-dialog/elements/grayscale-palettes.d.ts +5 -0
  58. package/lib/color-dialog/index.d.ts +5 -0
  59. package/lib/color-dialog/index.js +11 -6
  60. package/lib/color-dialog/themes/halo/dark/index.js +5 -5
  61. package/lib/color-dialog/themes/halo/light/index.js +5 -5
  62. package/lib/color-dialog/themes/solar/charcoal/index.js +5 -5
  63. package/lib/color-dialog/themes/solar/pearl/index.js +5 -5
  64. package/lib/combo-box/custom-elements.json +0 -22
  65. package/lib/combo-box/custom-elements.md +0 -7
  66. package/lib/combo-box/index.d.ts +5 -0
  67. package/lib/combo-box/themes/halo/dark/index.js +6 -6
  68. package/lib/combo-box/themes/halo/light/index.js +6 -6
  69. package/lib/combo-box/themes/solar/charcoal/index.js +5 -5
  70. package/lib/combo-box/themes/solar/pearl/index.js +5 -5
  71. package/lib/counter/index.d.ts +5 -0
  72. package/lib/counter/themes/halo/dark/index.js +2 -2
  73. package/lib/counter/themes/halo/light/index.js +2 -2
  74. package/lib/counter/themes/solar/charcoal/index.js +1 -1
  75. package/lib/counter/themes/solar/pearl/index.js +1 -1
  76. package/lib/datetime-field/custom-elements.json +0 -75
  77. package/lib/datetime-field/custom-elements.md +27 -36
  78. package/lib/datetime-field/index.d.ts +5 -0
  79. package/lib/datetime-field/themes/halo/dark/index.js +1 -1
  80. package/lib/datetime-field/themes/halo/light/index.js +1 -1
  81. package/lib/datetime-field/themes/solar/charcoal/index.js +1 -1
  82. package/lib/datetime-field/themes/solar/pearl/index.js +1 -1
  83. package/lib/datetime-picker/index.d.ts +5 -0
  84. package/lib/datetime-picker/themes/halo/dark/index.js +5 -5
  85. package/lib/datetime-picker/themes/halo/light/index.js +5 -5
  86. package/lib/datetime-picker/themes/solar/charcoal/index.js +5 -5
  87. package/lib/datetime-picker/themes/solar/pearl/index.js +5 -5
  88. package/lib/dialog/index.d.ts +5 -0
  89. package/lib/dialog/themes/halo/dark/index.js +6 -6
  90. package/lib/dialog/themes/halo/light/index.js +6 -6
  91. package/lib/dialog/themes/solar/charcoal/index.js +5 -5
  92. package/lib/dialog/themes/solar/pearl/index.js +5 -5
  93. package/lib/email-field/index.d.ts +5 -0
  94. package/lib/email-field/themes/halo/dark/index.js +1 -1
  95. package/lib/email-field/themes/halo/light/index.js +1 -1
  96. package/lib/email-field/themes/solar/charcoal/index.js +1 -1
  97. package/lib/email-field/themes/solar/pearl/index.js +1 -1
  98. package/lib/flag/index.d.ts +5 -0
  99. package/lib/header/index.d.ts +5 -0
  100. package/lib/heatmap/helpers/text.d.ts +1 -7
  101. package/lib/heatmap/helpers/text.js +1 -18
  102. package/lib/heatmap/index.d.ts +5 -0
  103. package/lib/heatmap/index.js +3 -2
  104. package/lib/heatmap/themes/halo/dark/index.js +2 -2
  105. package/lib/heatmap/themes/halo/light/index.js +2 -2
  106. package/lib/heatmap/themes/solar/charcoal/index.js +2 -2
  107. package/lib/heatmap/themes/solar/pearl/index.js +2 -2
  108. package/lib/icon/index.d.ts +5 -0
  109. package/lib/interactive-chart/index.d.ts +5 -12
  110. package/lib/interactive-chart/index.js +10 -22
  111. package/lib/interactive-chart/themes/halo/dark/index.js +2 -2
  112. package/lib/interactive-chart/themes/halo/light/index.js +2 -2
  113. package/lib/interactive-chart/themes/solar/charcoal/index.js +1 -1
  114. package/lib/interactive-chart/themes/solar/pearl/index.js +1 -1
  115. package/lib/item/index.d.ts +5 -0
  116. package/lib/item/themes/halo/dark/index.js +3 -3
  117. package/lib/item/themes/halo/light/index.js +3 -3
  118. package/lib/item/themes/solar/charcoal/index.js +2 -2
  119. package/lib/item/themes/solar/pearl/index.js +2 -2
  120. package/lib/label/index.d.ts +5 -0
  121. package/lib/label/themes/halo/dark/index.js +1 -1
  122. package/lib/label/themes/halo/light/index.js +1 -1
  123. package/lib/label/themes/solar/charcoal/index.js +1 -1
  124. package/lib/label/themes/solar/pearl/index.js +1 -1
  125. package/lib/layout/index.d.ts +5 -0
  126. package/lib/led-gauge/index.d.ts +5 -0
  127. package/lib/led-gauge/themes/halo/dark/index.js +1 -1
  128. package/lib/led-gauge/themes/halo/light/index.js +1 -1
  129. package/lib/led-gauge/themes/solar/charcoal/index.js +1 -1
  130. package/lib/led-gauge/themes/solar/pearl/index.js +1 -1
  131. package/lib/list/index.d.ts +5 -0
  132. package/lib/list/themes/halo/dark/index.js +2 -2
  133. package/lib/list/themes/halo/light/index.js +2 -2
  134. package/lib/list/themes/solar/charcoal/index.js +1 -1
  135. package/lib/list/themes/solar/pearl/index.js +1 -1
  136. package/lib/loader/index.d.ts +6 -0
  137. package/lib/loader/index.js +4 -0
  138. package/lib/multi-input/index.d.ts +5 -0
  139. package/lib/multi-input/themes/halo/dark/index.js +3 -3
  140. package/lib/multi-input/themes/halo/light/index.js +3 -3
  141. package/lib/multi-input/themes/solar/charcoal/index.js +2 -2
  142. package/lib/multi-input/themes/solar/pearl/index.js +2 -2
  143. package/lib/notification/elements/notification-tray.d.ts +5 -0
  144. package/lib/notification/elements/notification.d.ts +5 -0
  145. package/lib/notification/themes/halo/dark/index.js +1 -1
  146. package/lib/notification/themes/halo/light/index.js +1 -1
  147. package/lib/notification/themes/solar/charcoal/index.js +1 -1
  148. package/lib/notification/themes/solar/pearl/index.js +1 -1
  149. package/lib/number-field/custom-elements.json +0 -48
  150. package/lib/number-field/custom-elements.md +20 -26
  151. package/lib/number-field/index.d.ts +5 -0
  152. package/lib/number-field/themes/halo/dark/index.js +2 -2
  153. package/lib/number-field/themes/halo/light/index.js +2 -2
  154. package/lib/number-field/themes/solar/charcoal/index.js +1 -1
  155. package/lib/number-field/themes/solar/pearl/index.js +1 -1
  156. package/lib/overlay/elements/overlay-backdrop.d.ts +5 -0
  157. package/lib/overlay/elements/overlay-viewport.d.ts +5 -0
  158. package/lib/overlay/elements/overlay.d.ts +5 -0
  159. package/lib/overlay/managers/focus-manager.js +9 -3
  160. package/lib/overlay/themes/halo/dark/index.js +1 -1
  161. package/lib/overlay/themes/halo/light/index.js +1 -1
  162. package/lib/overlay-menu/helpers/types.d.ts +6 -0
  163. package/lib/overlay-menu/helpers/types.js +7 -1
  164. package/lib/overlay-menu/index.d.ts +14 -4
  165. package/lib/overlay-menu/index.js +45 -14
  166. package/lib/overlay-menu/managers/menu-manager.js +1 -0
  167. package/lib/overlay-menu/themes/halo/dark/index.js +4 -4
  168. package/lib/overlay-menu/themes/halo/light/index.js +4 -4
  169. package/lib/overlay-menu/themes/solar/charcoal/index.js +3 -3
  170. package/lib/overlay-menu/themes/solar/pearl/index.js +3 -3
  171. package/lib/pagination/index.d.ts +5 -0
  172. package/lib/pagination/themes/halo/dark/index.js +3 -3
  173. package/lib/pagination/themes/halo/light/index.js +3 -3
  174. package/lib/pagination/themes/solar/charcoal/index.js +3 -3
  175. package/lib/pagination/themes/solar/pearl/index.js +3 -3
  176. package/lib/panel/index.d.ts +5 -0
  177. package/lib/password-field/custom-elements.json +0 -7
  178. package/lib/password-field/custom-elements.md +0 -6
  179. package/lib/password-field/index.d.ts +5 -0
  180. package/lib/password-field/themes/halo/dark/index.js +1 -1
  181. package/lib/password-field/themes/halo/light/index.js +1 -1
  182. package/lib/password-field/themes/solar/charcoal/index.js +1 -1
  183. package/lib/password-field/themes/solar/pearl/index.js +1 -1
  184. package/lib/pill/index.d.ts +5 -0
  185. package/lib/pill/themes/halo/dark/index.js +2 -2
  186. package/lib/pill/themes/halo/light/index.js +2 -2
  187. package/lib/pill/themes/solar/charcoal/index.js +1 -1
  188. package/lib/pill/themes/solar/pearl/index.js +1 -1
  189. package/lib/progress-bar/index.d.ts +5 -0
  190. package/lib/radio-button/index.d.ts +5 -0
  191. package/lib/radio-button/themes/halo/dark/index.js +1 -1
  192. package/lib/radio-button/themes/halo/light/index.js +1 -1
  193. package/lib/radio-button/themes/solar/charcoal/index.js +1 -1
  194. package/lib/radio-button/themes/solar/pearl/index.js +1 -1
  195. package/lib/rating/index.d.ts +5 -0
  196. package/lib/search-field/custom-elements.json +0 -7
  197. package/lib/search-field/custom-elements.md +0 -6
  198. package/lib/search-field/index.d.ts +5 -0
  199. package/lib/search-field/themes/halo/dark/index.js +1 -1
  200. package/lib/search-field/themes/halo/light/index.js +1 -1
  201. package/lib/search-field/themes/solar/charcoal/index.js +1 -1
  202. package/lib/search-field/themes/solar/pearl/index.js +1 -1
  203. package/lib/select/index.d.ts +5 -0
  204. package/lib/select/themes/halo/dark/index.js +4 -4
  205. package/lib/select/themes/halo/light/index.js +4 -4
  206. package/lib/select/themes/solar/charcoal/index.js +3 -3
  207. package/lib/select/themes/solar/pearl/index.js +3 -3
  208. package/lib/sidebar-layout/index.d.ts +5 -0
  209. package/lib/sidebar-layout/themes/halo/dark/index.js +2 -2
  210. package/lib/sidebar-layout/themes/halo/light/index.js +2 -2
  211. package/lib/sidebar-layout/themes/solar/charcoal/index.js +1 -1
  212. package/lib/sidebar-layout/themes/solar/pearl/index.js +1 -1
  213. package/lib/slider/constants.d.ts +15 -0
  214. package/lib/slider/constants.js +18 -0
  215. package/lib/slider/index.d.ts +55 -80
  216. package/lib/slider/index.js +361 -454
  217. package/lib/slider/themes/halo/dark/index.js +2 -2
  218. package/lib/slider/themes/halo/light/index.js +2 -2
  219. package/lib/slider/themes/solar/charcoal/index.js +1 -1
  220. package/lib/slider/themes/solar/pearl/index.js +1 -1
  221. package/lib/slider/utils.d.ts +35 -0
  222. package/lib/slider/utils.js +54 -0
  223. package/lib/sparkline/index.d.ts +5 -0
  224. package/lib/swing-gauge/index.d.ts +5 -0
  225. package/lib/swing-gauge/themes/halo/dark/index.js +1 -1
  226. package/lib/swing-gauge/themes/halo/light/index.js +1 -1
  227. package/lib/swing-gauge/themes/solar/charcoal/index.js +1 -1
  228. package/lib/swing-gauge/themes/solar/pearl/index.js +1 -1
  229. package/lib/tab/index.d.ts +5 -0
  230. package/lib/tab/themes/halo/dark/index.js +3 -3
  231. package/lib/tab/themes/halo/light/index.js +3 -3
  232. package/lib/tab/themes/solar/charcoal/index.js +2 -2
  233. package/lib/tab/themes/solar/pearl/index.js +2 -2
  234. package/lib/tab-bar/index.d.ts +5 -0
  235. package/lib/tab-bar/themes/halo/dark/index.js +3 -3
  236. package/lib/tab-bar/themes/halo/light/index.js +3 -3
  237. package/lib/tab-bar/themes/solar/charcoal/index.js +2 -2
  238. package/lib/tab-bar/themes/solar/pearl/index.js +2 -2
  239. package/lib/text-field/custom-elements.json +0 -22
  240. package/lib/text-field/custom-elements.md +0 -7
  241. package/lib/text-field/index.d.ts +5 -0
  242. package/lib/text-field/themes/halo/dark/index.js +1 -1
  243. package/lib/text-field/themes/halo/light/index.js +1 -1
  244. package/lib/text-field/themes/solar/charcoal/index.js +1 -1
  245. package/lib/text-field/themes/solar/pearl/index.js +1 -1
  246. package/lib/time-picker/index.d.ts +5 -0
  247. package/lib/time-picker/themes/halo/dark/index.js +2 -2
  248. package/lib/time-picker/themes/halo/light/index.js +2 -2
  249. package/lib/time-picker/themes/solar/charcoal/index.js +2 -2
  250. package/lib/time-picker/themes/solar/pearl/index.js +2 -2
  251. package/lib/toggle/index.d.ts +5 -0
  252. package/lib/toggle/themes/halo/dark/index.js +1 -1
  253. package/lib/toggle/themes/halo/light/index.js +1 -1
  254. package/lib/tooltip/elements/tooltip-element.d.ts +1 -2
  255. package/lib/tooltip/index.d.ts +6 -0
  256. package/lib/tooltip/index.js +1 -0
  257. package/lib/tooltip/themes/halo/dark/index.js +1 -1
  258. package/lib/tooltip/themes/halo/light/index.js +1 -1
  259. package/lib/tooltip/themes/solar/charcoal/index.js +1 -1
  260. package/lib/tooltip/themes/solar/pearl/index.js +1 -1
  261. package/lib/tornado-chart/elements/tornado-chart.d.ts +5 -0
  262. package/lib/tornado-chart/elements/tornado-item.d.ts +5 -0
  263. package/lib/tornado-chart/themes/halo/dark/index.js +2 -2
  264. package/lib/tornado-chart/themes/halo/light/index.js +2 -2
  265. package/lib/tornado-chart/themes/solar/charcoal/index.js +2 -2
  266. package/lib/tornado-chart/themes/solar/pearl/index.js +2 -2
  267. package/lib/tree/elements/tree-item.d.ts +5 -0
  268. package/lib/tree/elements/tree.d.ts +5 -0
  269. package/lib/tree/helpers/renderer.js +14 -15
  270. package/lib/tree/themes/halo/dark/index.js +5 -5
  271. package/lib/tree/themes/halo/light/index.js +5 -5
  272. package/lib/tree/themes/solar/charcoal/index.js +3 -3
  273. package/lib/tree/themes/solar/pearl/index.js +3 -3
  274. package/lib/tree-select/index.d.ts +5 -0
  275. package/lib/tree-select/themes/halo/dark/index.js +10 -10
  276. package/lib/tree-select/themes/halo/light/index.js +10 -10
  277. package/lib/tree-select/themes/solar/charcoal/index.js +9 -9
  278. package/lib/tree-select/themes/solar/pearl/index.js +9 -9
  279. package/lib/version.js +1 -1
  280. package/package.json +14 -14
@@ -3,48 +3,11 @@ import { html, css, ControlElement, WarningNotice } from '@refinitiv-ui/core';
3
3
  import { customElement } from '@refinitiv-ui/core/decorators/custom-element.js';
4
4
  import { property } from '@refinitiv-ui/core/decorators/property.js';
5
5
  import { query } from '@refinitiv-ui/core/decorators/query.js';
6
+ import { createRef, ref } from '@refinitiv-ui/core/directives/ref.js';
6
7
  import { styleMap } from '@refinitiv-ui/core/directives/style-map.js';
7
8
  import { VERSION } from '../version.js';
8
9
  import '../number-field/index.js';
9
- var SliderNameType;
10
- (function (SliderNameType) {
11
- SliderNameType["value"] = "value";
12
- SliderNameType["from"] = "from";
13
- SliderNameType["to"] = "to";
14
- })(SliderNameType || (SliderNameType = {}));
15
- var PreviousSliderNameType;
16
- (function (PreviousSliderNameType) {
17
- PreviousSliderNameType["value"] = "valuePrevious";
18
- PreviousSliderNameType["from"] = "fromPrevious";
19
- PreviousSliderNameType["to"] = "toPrevious";
20
- })(PreviousSliderNameType || (PreviousSliderNameType = {}));
21
- var NumberFieldNameType;
22
- (function (NumberFieldNameType) {
23
- NumberFieldNameType["fromInput"] = "fromInput";
24
- NumberFieldNameType["toInput"] = "toInput";
25
- })(NumberFieldNameType || (NumberFieldNameType = {}));
26
- /**
27
- * Set prevent default action and stop bubbles event
28
- * @private
29
- * @param event event mouse or touch
30
- * @returns {void}
31
- */
32
- const preventDefault = function (event) {
33
- event.preventDefault();
34
- event.stopPropagation();
35
- return event;
36
- };
37
- /**
38
- * Return value that never exceed the maximum boundary
39
- * @private
40
- * @param value value for check clamp
41
- * @param min max value
42
- * @param max min value
43
- * @returns number between two numbers
44
- */
45
- const clamp = function (value, min, max) {
46
- return Math.max(min, Math.min(value, max)).toString();
47
- };
10
+ import { clamp, preventDefault, validateNumber, isDecimalNumber, countDecimalPlace } from './utils.js';
48
11
  /**
49
12
  * Allows users to make selections from a range of values
50
13
  *
@@ -63,12 +26,15 @@ const clamp = function (value, min, max) {
63
26
  */
64
27
  let Slider = class Slider extends ControlElement {
65
28
  constructor() {
66
- super(...arguments);
29
+ super();
30
+ /**
31
+ * An array of slider thumbs
32
+ */
33
+ this.thumbs = [];
34
+ /**
35
+ * Whether if the thumb is being drag
36
+ */
67
37
  this.dragging = false;
68
- this.stepUse = 1;
69
- this.decimalPlaces = 0;
70
- this.dragElements = [];
71
- this.isEventReady = false;
72
38
  this.valuePrevious = '';
73
39
  this.fromPrevious = '';
74
40
  this.toPrevious = '';
@@ -115,134 +81,25 @@ let Slider = class Slider extends ControlElement {
115
81
  */
116
82
  this.minRange = '0';
117
83
  /**
118
- * Input number event blur and notify property
119
- * @param event event blur input number field
120
- * @returns {void}
84
+ * Slider element reference
121
85
  */
122
- this.onBlur = (event) => {
123
- if (this.readonly) {
124
- return;
125
- }
126
- const { value, name } = event.target;
127
- const currentData = name;
128
- const perviousData = `${name}Previous`;
129
- if (value && this[currentData] !== value) {
130
- this.updateNotifyProperty(currentData, value);
131
- this[perviousData] = value;
132
- }
133
- event.preventDefault();
134
- };
86
+ this.sliderRef = createRef();
135
87
  /**
136
- * Input number event keydown y
137
- * @param event event keydown
138
- * @returns {void}
88
+ * Slider's track reference
139
89
  */
140
- this.onKeydown = (event) => {
141
- if (this.readonly || this.disabled) {
142
- return;
143
- }
144
- this.handleEnterKey(event);
145
- };
90
+ this.trackRef = createRef();
146
91
  /**
147
- * Start dragging event on slider
148
- * @param event event dragstart
149
- * @returns {void}
150
- */
151
- this.onDragStart = (event) => {
152
- this.dragging = true;
153
- this.classList.add('grabbable');
154
- if (this.range) {
155
- const pct = this.getMousePosition(event);
156
- const mousePos = ((this.maxNumber - this.minNumber) * pct) + this.minNumber;
157
- const distFrom = Math.abs(mousePos - this.fromNumber);
158
- const distTo = Math.abs(mousePos - this.toNumber);
159
- if (distFrom < distTo) {
160
- this.activeThumb = this.dragElements[0];
161
- }
162
- else if (distFrom > distTo) {
163
- this.activeThumb = this.dragElements[1];
164
- }
165
- this.dragElements.forEach((el) => {
166
- el.style.zIndex = '5';
167
- });
168
- this.activeThumb.style.zIndex = '10';
169
- // Set focus to input when drag.
170
- if (this.isShowInputField) {
171
- this.toggleFocusField(this.activeThumb.getAttribute('name') || '', true);
172
- }
173
- }
174
- else {
175
- this.activeThumb = this.dragElements[0];
176
- }
177
- this.onDrag(event);
178
- if (event.changedTouches) {
179
- this.addEventListener('touchmove', this.onDrag);
180
- this.addEventListener('touchend', this.onDragEnd);
181
- }
182
- else {
183
- window.addEventListener('mousemove', this.onDrag);
184
- window.addEventListener('mouseup', this.onDragEnd);
185
- }
186
- };
92
+ * @ignore
93
+ */
94
+ this.onDrag = this.onDrag.bind(this);
187
95
  /**
188
- * Dragging after on dragging start event
189
- * @param event event mousemove and touchmove
190
- * @returns {void}
191
- */
192
- this.onDrag = (event) => {
193
- if (this.minNumber !== this.maxNumber) {
194
- const thumbPos = this.getMousePosition(event);
195
- const closestStep = this.calculateStep(thumbPos);
196
- // Can be dragged slider when the value is valid
197
- if (closestStep <= 1) {
198
- const thumbLeft = this.stepUse !== 0 ? closestStep : thumbPos;
199
- const calStepValue = this.calculateValue(thumbLeft);
200
- const prettyVal = Number(this.displayValue(calStepValue));
201
- if (this.range) {
202
- if (this.activeThumb === this.dragElements[1]) {
203
- this.to = this.validateTo(prettyVal).toString();
204
- }
205
- else {
206
- this.from = this.validateFrom(prettyVal).toString();
207
- }
208
- }
209
- else {
210
- this.value = prettyVal.toString();
211
- }
212
- }
213
- }
214
- };
96
+ * @ignore
97
+ */
98
+ this.onDragStart = this.onDragStart.bind(this);
215
99
  /**
216
- * End dragging event and remove dragging event
217
- * @param e event mouseup and touchmove
218
- * @returns {void}
219
- */
220
- this.onDragEnd = (e) => {
221
- if (this.dragging) {
222
- this.dragging = false;
223
- const event = e;
224
- if (event.changedTouches) {
225
- this.removeEventListener('touchmove', this.onDrag);
226
- this.removeEventListener('touchend', this.onDragEnd);
227
- }
228
- else {
229
- window.removeEventListener('mousemove', this.onDrag);
230
- window.removeEventListener('mouseup', this.onDragEnd);
231
- }
232
- this.classList.remove('grabbable');
233
- if (this.classList.length === 0) {
234
- this.removeAttribute('class');
235
- }
236
- if (!event.changedTouches) {
237
- event.preventDefault();
238
- }
239
- this.dispatchDataChangedEvent();
240
- // Reset tab index of input that's drag.
241
- if (this.isShowInputField) {
242
- this.toggleFocusField(this.activeThumb.getAttribute('name') || '', false);
243
- }
244
- }
245
- };
100
+ * @ignore
101
+ */
102
+ this.onDragEnd = this.onDragEnd.bind(this);
246
103
  }
247
104
  /**
248
105
  * Element version number
@@ -251,6 +108,79 @@ let Slider = class Slider extends ControlElement {
251
108
  static get version() {
252
109
  return VERSION;
253
110
  }
111
+ /**
112
+ * Define styles in a tagged template literal, using the css tag function.
113
+ * @returns CSS template
114
+ */
115
+ static get styles() {
116
+ return css `
117
+ :host {
118
+ display: flex;
119
+ }
120
+ [part=slider-wrapper] {
121
+ position: relative;
122
+ width: 100%;
123
+ }
124
+ [part=slider] {
125
+ width: 100%;
126
+ height: 100%;
127
+ display: inline-block;
128
+ }
129
+ :host(:not([disabled]):focus){
130
+ outline:none;
131
+ }
132
+ :host([show-steps]) [part=track-wrapper]::after {
133
+ display:block;
134
+ position: absolute;
135
+ content: "";
136
+ right: 0;
137
+ }
138
+ [part=track-wrapper]{
139
+ content: "";
140
+ position: absolute;
141
+ width: 100%;
142
+ top: 50%;
143
+ left: 0;
144
+ pointer-events: none;
145
+ }
146
+ [part=thumb-container]{
147
+ position: absolute;
148
+ top: 0;
149
+ width: 100%;
150
+ z-index: 5;
151
+ }
152
+ [part=thumb]{
153
+ position: absolute;
154
+ margin: 0 auto;
155
+ }
156
+ [part=pin]{
157
+ display: flex;
158
+ position: absolute;
159
+ align-items: center;
160
+ justify-content: center;
161
+ z-index: 1;
162
+ }
163
+ :host([show-steps]) [part=step-container]{
164
+ position: absolute;
165
+ left: 0;
166
+ width: 100%;
167
+ }
168
+ :host([show-steps]) [part=step]{
169
+ width: 100%;
170
+ position: absolute;
171
+ left: 0;
172
+ }
173
+ [part=track-fill]{
174
+ z-index: 2;
175
+ content: "";
176
+ position: absolute;
177
+ left: 0;
178
+ }
179
+ :host([show-steps][step="0"]) [part=track-wrapper]::after{
180
+ width: 0;
181
+ }
182
+ `;
183
+ }
254
184
  /**
255
185
  * Converts value from string to number for calculations
256
186
  * @returns value of input as a number
@@ -295,6 +225,18 @@ let Slider = class Slider extends ControlElement {
295
225
  }
296
226
  return step;
297
227
  }
228
+ /**
229
+ * Compute and normalise step value for calculations
230
+ * @returns step value that should be inside the min / max boundary
231
+ */
232
+ get stepRange() {
233
+ const step = Math.abs(this.stepNumber);
234
+ if (step > this.maxNumber - this.minNumber && !isDecimalNumber(step)) {
235
+ // new step shouldn't be larger than slider
236
+ return Math.abs(this.maxNumber - this.minNumber);
237
+ }
238
+ return step;
239
+ }
298
240
  /**
299
241
  * Converts from value from string to number for calculations
300
242
  * @returns from value of slider as a number
@@ -328,6 +270,18 @@ let Slider = class Slider extends ControlElement {
328
270
  }
329
271
  return minRange;
330
272
  }
273
+ /**
274
+ * Number of decimal places used for displaying value
275
+ * Based on step or min decimal places
276
+ */
277
+ get decimalPlace() {
278
+ if (isDecimalNumber(this.stepRange) || isDecimalNumber(this.minNumber)) {
279
+ const stepDecimal = countDecimalPlace(this.stepRange);
280
+ const minDecimal = countDecimalPlace(this.minNumber);
281
+ return stepDecimal > minDecimal ? stepDecimal : minDecimal;
282
+ }
283
+ return 0;
284
+ }
331
285
  /**
332
286
  * Return hide/show input field state
333
287
  * @returns {boolean} true if showInputField value is exist
@@ -342,62 +296,61 @@ let Slider = class Slider extends ControlElement {
342
296
  */
343
297
  firstUpdated(changedProperties) {
344
298
  super.firstUpdated(changedProperties);
345
- // initialize slider
346
- void this.updateComplete.then(() => {
347
- this.initializeProperty();
348
- this.initSlider();
349
- this.updateEventListeners();
350
- });
299
+ this.prepareValues();
300
+ this.prepareThumbs();
301
+ this.prepareSliderTrack();
351
302
  }
352
303
  /**
353
- * On Update lifecycle
304
+ * On willUpdate lifecycle
354
305
  * @param changedProperties changed properties
355
306
  * @returns {void}
356
307
  */
357
- update(changedProperties) {
358
- super.update(changedProperties);
359
- if (changedProperties.has('disabled') || changedProperties.has('readonly')) {
360
- this.updateEventListeners();
361
- }
362
- changedProperties.forEach((oldValue, propName) => {
363
- if (['value', 'min', 'max', 'from', 'to', 'step', 'minRange'].includes(propName)) {
364
- this.showWarningInvalidProperty(propName);
308
+ willUpdate(changedProperties) {
309
+ super.willUpdate(changedProperties);
310
+ if ((changedProperties.has('disabled') && changedProperties.get('disabled') !== undefined)
311
+ || (changedProperties.has('readonly') && changedProperties.get('readonly') !== undefined)) {
312
+ this.prepareSliderTrack();
313
+ }
314
+ changedProperties.forEach((_, changedProperty) => {
315
+ if (['value', 'min', 'max', 'from', 'to', 'step', 'minRange'].includes(changedProperty)) {
316
+ this.showWarningInvalidProperty(changedProperty);
365
317
  }
366
318
  });
367
319
  }
368
320
  /**
321
+ * On updated lifecycle
369
322
  * @param changedProperties changed properties
370
323
  * @returns {void}
371
324
  */
372
325
  updated(changedProperties) {
373
326
  super.updated(changedProperties);
374
- changedProperties.forEach((oldValue, propName) => {
375
- if (propName === 'value') {
376
- this.onValueChange();
377
- }
378
- else if (propName === 'min') {
379
- this.onMinChange(oldValue);
380
- }
381
- else if (propName === 'max') {
382
- this.onMaxChange(oldValue);
383
- }
384
- else if (propName === 'from' && this.range) {
385
- this.onValueChangeFrom();
386
- }
387
- else if (propName === 'to' && this.range) {
388
- this.onValueChangeTo();
389
- }
390
- else if (propName === 'step') {
391
- this.onStepChange();
392
- }
393
- else if (propName === 'minRange') {
394
- this.onMinRangeChange();
327
+ if (changedProperties.has('value')) {
328
+ this.onValueChange();
329
+ }
330
+ if (changedProperties.has('min')) {
331
+ this.onMinChange(changedProperties.get('min'));
332
+ }
333
+ if (changedProperties.has('max')) {
334
+ this.onMaxChange(changedProperties.get('max'));
335
+ }
336
+ if (this.range) {
337
+ if (changedProperties.has('from')) {
338
+ this.onFromValueChange();
395
339
  }
396
- else if (propName === 'range') {
397
- this.initializeProperty();
398
- this.initSlider();
340
+ if (changedProperties.has('to')) {
341
+ this.onToValueChange();
399
342
  }
400
- });
343
+ }
344
+ if (changedProperties.has('step')) {
345
+ this.onStepChange();
346
+ }
347
+ if (changedProperties.has('minRange')) {
348
+ this.onMinRangeChange();
349
+ }
350
+ if (changedProperties.has('range')) {
351
+ this.prepareValues();
352
+ this.prepareThumbs();
353
+ }
401
354
  }
402
355
  /**
403
356
  * Show Warning a warning message invalid property
@@ -442,16 +395,13 @@ let Slider = class Slider extends ControlElement {
442
395
  }
443
396
  }
444
397
  /**
445
- * Initialise class properties
398
+ * Initialises slider value properties
446
399
  * @returns {void}
447
400
  */
448
- initializeProperty() {
449
- this.stepUse = this.calculateStepRange(this.stepNumber);
401
+ prepareValues() {
450
402
  if (this.minNumber !== this.maxNumber) {
451
- // init decimal places
452
- this.updateDecimalPlaces();
453
403
  if (this.range) {
454
- this.activeThumb = this.dragElements[1];
404
+ this.activeThumb = this.thumbs[1];
455
405
  if (this.minRangeNumber) {
456
406
  const distanceFromTo = Math.abs(this.toNumber - this.fromNumber);
457
407
  const clampValueFrom = this.toNumber - this.minRangeNumber;
@@ -480,120 +430,83 @@ let Slider = class Slider extends ControlElement {
480
430
  else {
481
431
  this.value = this.min;
482
432
  }
483
- // initial old value
484
433
  this.valuePrevious = this.value;
485
434
  this.toPrevious = this.to;
486
435
  this.fromPrevious = this.from;
487
436
  }
488
437
  /**
489
- * Initialise slider properties
438
+ * Query and assigned thumbs depending on slider mode and add event listeners to it
490
439
  * @returns {void}
491
440
  */
492
- initSlider() {
493
- this.dragElements = [];
494
- if (this.range) {
495
- this.shadowRoot?.querySelectorAll('#thumbContainer').forEach((item) => {
496
- this.dragElements.push(item);
497
- });
498
- }
499
- else {
500
- this.dragElements = [
501
- this.thumbContainer
502
- ];
503
- }
504
- this.activeThumb = this.dragElements[0];
505
- this.dragElements.concat(this).forEach((el) => {
506
- el.addEventListener('drag', preventDefault);
507
- el.addEventListener('dragstart', preventDefault);
508
- el.addEventListener('dragend', preventDefault);
441
+ prepareThumbs() {
442
+ this.thumbs = [];
443
+ const thumbs = this.shadowRoot?.querySelectorAll('[part~=thumb-container]') || [];
444
+ this.thumbs = this.range ? Array.from(thumbs) : [thumbs[0]];
445
+ this.activeThumb = this.thumbs[0];
446
+ this.thumbs.forEach((thumb) => {
447
+ thumb.addEventListener('drag', preventDefault);
448
+ thumb.addEventListener('dragstart', preventDefault);
449
+ thumb.addEventListener('dragend', preventDefault);
509
450
  });
510
- this.isEventReady = true;
511
451
  }
512
452
  /**
513
- * Calculate step in range
514
- * @param step value step for calculate
515
- * @returns step value that should be inside the min / max boundary
516
- */
517
- calculateStepRange(step) {
518
- const newStep = Math.abs(step);
519
- if (newStep > this.maxNumber - this.minNumber && !this.isDecimalNumber(newStep)) {
520
- // new step shouldn't be larger than slider
521
- return Math.abs(this.maxNumber - this.minNumber);
522
- }
523
- return newStep;
524
- }
525
- /**
526
- * Check if step or min number is decimal
527
- * If yes, set number of decimal places
453
+ * Add or remove event listener on slider track depending on slider disabled and readonly state
528
454
  * @returns {void}
529
455
  */
530
- updateDecimalPlaces() {
531
- // Set decimal places when step or min have decimal
532
- if (this.isDecimalNumber(this.stepUse) || this.isDecimalNumber(this.minNumber)) {
533
- const stepUseDecimal = this.countDecimals(this.stepUse);
534
- const minDecimal = this.countDecimals(this.minNumber);
535
- this.decimalPlaces = stepUseDecimal > minDecimal ? stepUseDecimal : minDecimal;
456
+ prepareSliderTrack() {
457
+ if (this.disabled || this.readonly) {
458
+ this.sliderRef.value?.removeEventListener('mousedown', this.onDragStart);
459
+ this.sliderRef.value?.removeEventListener('touchstart', this.onDragStart);
536
460
  }
537
461
  else {
538
- this.decimalPlaces = 0;
462
+ this.sliderRef.value?.addEventListener('mousedown', this.onDragStart, { passive: true });
463
+ this.sliderRef.value?.addEventListener('touchstart', this.onDragStart, { passive: true });
539
464
  }
540
465
  }
541
466
  /**
542
- * Count decimal number
543
- * @param value value for checking
544
- * @returns number of decimal points
545
- */
546
- countDecimals(value) {
547
- return Number(value).toString().split('.')[1]?.length | 0;
548
- }
549
- /**
550
- * Check if decimal number e.g. 10.5, etc
551
- * @param value value for checking
552
- * @returns true if value is decimal
553
- */
554
- isDecimalNumber(value) {
555
- return value % 1 !== 0;
556
- }
557
- /**
558
- * Calculate percentage by value
467
+ * Calculate percentage from value, min and max
559
468
  * @param value value to be calculated
560
469
  * @returns percentage
561
470
  */
562
471
  calculatePercentage(value) {
563
- const valuePercent = Math.abs((((value || 0) - this.minNumber) / (this.maxNumber - this.minNumber)) * 100);
564
- if (valuePercent > 100) {
472
+ const percentage = Math.abs((((value || 0) - this.minNumber) / (this.maxNumber - this.minNumber)) * 100);
473
+ if (percentage > 100) {
565
474
  return 100;
566
475
  }
567
- else if (valuePercent < 0) {
476
+ else if (percentage < 0) {
568
477
  return 0;
569
478
  }
570
479
  else {
571
- return valuePercent;
480
+ return percentage;
572
481
  }
573
482
  }
574
483
  /**
575
- * Add and remove event listener when have disable and readonly properties
484
+ * Input number event blur and notify property
485
+ * @param event event blur input number field
576
486
  * @returns {void}
577
487
  */
578
- updateEventListeners() {
579
- if (this.isEventReady) {
580
- if (this.disabled || this.readonly) {
581
- this.slider.removeEventListener('mousedown', this.onDragStart);
582
- this.slider.removeEventListener('touchstart', this.onDragStart);
583
- }
584
- else {
585
- this.slider.addEventListener('mousedown', this.onDragStart, { passive: true });
586
- this.slider.addEventListener('touchstart', this.onDragStart, { passive: true });
587
- }
488
+ onBlur(event) {
489
+ if (this.readonly) {
490
+ return;
588
491
  }
492
+ const { value, name } = event.target;
493
+ const currentData = name;
494
+ const previousData = `${name}Previous`;
495
+ if (value && this[currentData] !== value) {
496
+ this.updateNotifyProperty(currentData, value);
497
+ this[previousData] = value;
498
+ }
499
+ event.preventDefault();
589
500
  }
590
501
  /**
591
- * Handles key press keyboard events
592
- *
593
- * @param event Event Object
502
+ * Input number event keydown y
503
+ * @param event event keydown
594
504
  * @returns {void}
595
505
  */
596
- handleEnterKey(event) {
506
+ onKeydown(event) {
507
+ if (this.readonly || this.disabled) {
508
+ return;
509
+ }
597
510
  if (event.key === ' ' || event.key === 'Spacebar' || event.key === 'Enter') {
598
511
  event.target.blur();
599
512
  }
@@ -605,21 +518,21 @@ let Slider = class Slider extends ControlElement {
605
518
  * @returns {void}
606
519
  */
607
520
  updateNotifyProperty(name, value) {
608
- let isUpdateValue = false;
609
- const valueSanitize = Number(this.sanitizeNumber(Number(value), 0));
521
+ let shouldUpdate = false;
522
+ const validatedValue = Number(validateNumber(Number(value), 0));
610
523
  if (name === 'to') {
611
- isUpdateValue = this.isValueInBoundary(valueSanitize, 'to');
524
+ shouldUpdate = this.isValueInBoundary(validatedValue, 'to');
612
525
  }
613
526
  else {
614
- isUpdateValue = this.isValueInBoundary(valueSanitize, '');
527
+ shouldUpdate = this.isValueInBoundary(validatedValue, '');
615
528
  }
616
- if (isUpdateValue) {
529
+ if (shouldUpdate) {
617
530
  (this[name]) = value;
618
531
  this.notifyPropertyChange(name, value);
619
532
  }
620
533
  else {
621
- const nameInput = `${name}Input`;
622
- this[nameInput].value = this[name];
534
+ const inputName = `${name}Input`;
535
+ this[inputName].value = this[name];
623
536
  }
624
537
  }
625
538
  /**
@@ -638,8 +551,8 @@ let Slider = class Slider extends ControlElement {
638
551
  }
639
552
  /**
640
553
  * Set focus to input from state
641
- * @param {String} name number field's name
642
- * @param {Boolean} focusState state of focus
554
+ * @param name number field's name
555
+ * @param focusState state of focus
643
556
  * @returns {void}
644
557
  */
645
558
  toggleFocusField(name, focusState) {
@@ -647,12 +560,56 @@ let Slider = class Slider extends ControlElement {
647
560
  this[`${name}Input`].setAttribute('tabindex', `${focusState ? 1 : 0}`);
648
561
  }
649
562
  }
563
+ /**
564
+ * Start dragging event on slider
565
+ * @param event event dragstart
566
+ * @returns {void}
567
+ */
568
+ onDragStart(event) {
569
+ this.dragging = true;
570
+ this.classList.add('grabbable');
571
+ if (this.range) {
572
+ const percentage = this.getMousePosition(event);
573
+ const mousePosition = ((this.maxNumber - this.minNumber) * percentage) + this.minNumber;
574
+ const distanceFrom = Math.abs(mousePosition - this.fromNumber);
575
+ const distanceTo = Math.abs(mousePosition - this.toNumber);
576
+ if (distanceFrom < distanceTo) {
577
+ this.activeThumb = this.thumbs[0];
578
+ }
579
+ else if (distanceFrom > distanceTo) {
580
+ this.activeThumb = this.thumbs[1];
581
+ }
582
+ this.thumbs.forEach((el) => {
583
+ el.style.zIndex = '5';
584
+ });
585
+ this.activeThumb.style.zIndex = '10';
586
+ // Set focus to input when drag.
587
+ if (this.isShowInputField) {
588
+ this.toggleFocusField(this.activeThumb.getAttribute('name') || '', true);
589
+ }
590
+ }
591
+ else {
592
+ this.activeThumb = this.thumbs[0];
593
+ }
594
+ this.onDrag(event);
595
+ if (event.changedTouches) {
596
+ this.addEventListener('touchmove', this.onDrag);
597
+ this.addEventListener('touchend', this.onDragEnd);
598
+ }
599
+ else {
600
+ window.addEventListener('mousemove', this.onDrag);
601
+ window.addEventListener('mouseup', this.onDragEnd);
602
+ }
603
+ }
650
604
  /**
651
605
  * @param event event mousemove and touchmove
652
606
  * @returns mouse position by percentage
653
607
  */
654
608
  getMousePosition(event) {
655
- const sliderRect = this.trackWrapper.getBoundingClientRect();
609
+ const sliderRect = this.trackRef.value?.getBoundingClientRect();
610
+ if (!sliderRect) {
611
+ return 1;
612
+ }
656
613
  // check drag desktop or mobile
657
614
  const pageX = event.changedTouches ? event.changedTouches[0].pageX : event.pageX;
658
615
  const positionSize = pageX - sliderRect.left;
@@ -663,6 +620,35 @@ let Slider = class Slider extends ControlElement {
663
620
  return 1;
664
621
  }
665
622
  }
623
+ /**
624
+ * Dragging after on dragging start event
625
+ * @param event event mousemove and touchmove
626
+ * @returns {void}
627
+ */
628
+ onDrag(event) {
629
+ if (this.minNumber === this.maxNumber) {
630
+ return;
631
+ }
632
+ const thumbPosition = this.getMousePosition(event);
633
+ const nearestStep = this.calculateStep(thumbPosition);
634
+ if (nearestStep > 1) {
635
+ return;
636
+ }
637
+ const thumbLeft = this.stepRange !== 0 ? nearestStep : thumbPosition;
638
+ const computedStepValue = this.calculateValue(thumbLeft);
639
+ const displayedValue = Number(this.displayValue(computedStepValue));
640
+ if (this.range) {
641
+ if (this.activeThumb === this.thumbs[1]) {
642
+ this.to = this.validateTo(displayedValue).toString();
643
+ }
644
+ else {
645
+ this.from = this.validateFrom(displayedValue).toString();
646
+ }
647
+ }
648
+ else {
649
+ this.value = displayedValue.toString();
650
+ }
651
+ }
666
652
  /**
667
653
  * Handle 'from' value on drag out of boundary.
668
654
  * @param value value from change
@@ -692,12 +678,12 @@ let Slider = class Slider extends ControlElement {
692
678
  }
693
679
  }
694
680
  /**
695
- * Calculate the nearest interval
681
+ * Calculate the nearest step interval
696
682
  * @param thumbPosition thumb position dragging on slider
697
683
  * @returns position step on slider
698
684
  */
699
685
  calculateStep(thumbPosition) {
700
- const stepSize = this.calculatePercentage(this.minNumber + this.stepUse) / 100;
686
+ const stepSize = this.calculatePercentage(this.minNumber + this.stepRange) / 100;
701
687
  // calculate step to current point to next point
702
688
  const posToFixStep = Math.round(thumbPosition / stepSize) * stepSize;
703
689
  if (thumbPosition <= posToFixStep + (stepSize / 2)) {
@@ -736,11 +722,11 @@ let Slider = class Slider extends ControlElement {
736
722
  * @returns formatted value
737
723
  */
738
724
  displayValue(value) {
739
- if (this.isDecimalNumber(value)) {
740
- const valueDecimalCount = this.countDecimals(value);
725
+ if (isDecimalNumber(value)) {
726
+ const valueDecimalCount = countDecimalPlace(value);
741
727
  // return value decimal by a boundary of max decimal
742
- if (valueDecimalCount > this.decimalPlaces) {
743
- return value.toFixed(this.decimalPlaces);
728
+ if (valueDecimalCount > this.decimalPlace) {
729
+ return value.toFixed(this.decimalPlace);
744
730
  }
745
731
  else {
746
732
  return value.toString();
@@ -750,6 +736,37 @@ let Slider = class Slider extends ControlElement {
750
736
  return value.toString();
751
737
  }
752
738
  }
739
+ /**
740
+ * End dragging event and remove dragging event
741
+ * @param event event mouseup and touchmove
742
+ * @returns {void}
743
+ */
744
+ onDragEnd(event) {
745
+ if (this.dragging) {
746
+ this.dragging = false;
747
+ const touchEvent = event;
748
+ if (touchEvent.changedTouches) {
749
+ this.removeEventListener('touchmove', this.onDrag);
750
+ this.removeEventListener('touchend', this.onDragEnd);
751
+ }
752
+ else {
753
+ window.removeEventListener('mousemove', this.onDrag);
754
+ window.removeEventListener('mouseup', this.onDragEnd);
755
+ }
756
+ this.classList.remove('grabbable');
757
+ if (this.classList.length === 0) {
758
+ this.removeAttribute('class');
759
+ }
760
+ if (!touchEvent.changedTouches) {
761
+ event.preventDefault();
762
+ }
763
+ this.dispatchDataChangedEvent();
764
+ // Reset tabIndex of input that's being drag.
765
+ if (this.isShowInputField) {
766
+ this.toggleFocusField(this.activeThumb.getAttribute('name') || '', false);
767
+ }
768
+ }
769
+ }
753
770
  /**
754
771
  * Value observer
755
772
  * @returns {void}
@@ -758,12 +775,12 @@ let Slider = class Slider extends ControlElement {
758
775
  if (this.readonly) {
759
776
  const valuePercent = this.calculatePercentage(Number(this.value)) / 100;
760
777
  const closestStep = this.calculateStep(valuePercent);
761
- const thumbLeft = this.stepUse !== 0 ? closestStep : valuePercent;
778
+ const thumbLeft = this.stepRange !== 0 ? closestStep : valuePercent;
762
779
  const calStepValue = this.calculateValue(thumbLeft);
763
780
  this.value = this.displayValue(calStepValue);
764
781
  }
765
782
  else {
766
- const valueSanitize = Number(this.sanitizeNumber(Number(this.value), 0));
783
+ const valueSanitize = Number(validateNumber(Number(this.value), 0));
767
784
  if (this.isValueInBoundary(valueSanitize, '')) {
768
785
  this.value = this.displayValue(valueSanitize);
769
786
  }
@@ -786,8 +803,8 @@ let Slider = class Slider extends ControlElement {
786
803
  * From value observer
787
804
  * @returns {void}
788
805
  */
789
- onValueChangeFrom() {
790
- const valueFrom = Number(this.sanitizeNumber(this.fromNumber, 0));
806
+ onFromValueChange() {
807
+ const valueFrom = Number(validateNumber(this.fromNumber, 0));
791
808
  if (this.isValueInBoundary(valueFrom, 'from')) {
792
809
  this.from = this.displayValue(this.fromNumber);
793
810
  }
@@ -811,30 +828,6 @@ let Slider = class Slider extends ControlElement {
811
828
  this.fromPrevious = this.from;
812
829
  }
813
830
  }
814
- /**
815
- * Return fallback number of the value is invalid
816
- * @param value value for checking
817
- * @param fallbackValue fallback value when value is not number;
818
- * @returns sanitized number
819
- */
820
- sanitizeNumber(value, fallbackValue) {
821
- let val;
822
- if (this.isNumberValue(value) && typeof value === 'number') {
823
- val = value.toString();
824
- }
825
- else {
826
- val = fallbackValue;
827
- }
828
- return val.toString();
829
- }
830
- /**
831
- * Check if value is number
832
- * @param value value for checking
833
- * @returns true if value is numeric
834
- */
835
- isNumberValue(value) {
836
- return !isNaN(value) && !isNaN(Number(value));
837
- }
838
831
  /**
839
832
  * Check if value is inside min / max boundary
840
833
  * @param value value is checking
@@ -858,7 +851,7 @@ let Slider = class Slider extends ControlElement {
858
851
  return false;
859
852
  }
860
853
  // check step min and max in range
861
- if (this.stepUse < this.minNumber || this.stepUse > this.maxNumber) {
854
+ if (this.stepRange < this.minNumber || this.stepRange > this.maxNumber) {
862
855
  return true;
863
856
  }
864
857
  }
@@ -868,8 +861,8 @@ let Slider = class Slider extends ControlElement {
868
861
  * To value observer
869
862
  * @returns {void}
870
863
  */
871
- onValueChangeTo() {
872
- const valueTo = Number(this.sanitizeNumber(this.toNumber, 0));
864
+ onToValueChange() {
865
+ const valueTo = Number(validateNumber(this.toNumber, 0));
873
866
  if (this.isValueInBoundary(valueTo, 'to')) {
874
867
  this.to = this.displayValue(valueTo);
875
868
  }
@@ -898,17 +891,14 @@ let Slider = class Slider extends ControlElement {
898
891
  * @returns {void}
899
892
  */
900
893
  onStepChange() {
901
- this.step = this.sanitizeNumber(this.stepNumber, 1);
902
- this.stepUse = this.calculateStepRange(this.stepNumber);
903
- // Set decimal places value when step is decimal
904
- this.updateDecimalPlaces();
894
+ this.step = validateNumber(this.stepNumber, 1);
905
895
  }
906
896
  /**
907
897
  * Min range observer
908
898
  * @returns {void}
909
899
  */
910
900
  onMinRangeChange() {
911
- const valueMinRange = Math.abs(Number(this.sanitizeNumber(this.minRangeNumber, 0)));
901
+ const valueMinRange = Math.abs(Number(validateNumber(this.minRangeNumber, 0)));
912
902
  const maximumRangeMinMax = Math.abs(this.maxNumber - this.minNumber);
913
903
  const maximumRangeFromTo = Math.abs(this.toNumber - this.fromNumber);
914
904
  if (valueMinRange && valueMinRange >= this.stepNumber) {
@@ -932,9 +922,7 @@ let Slider = class Slider extends ControlElement {
932
922
  * @returns {void}
933
923
  */
934
924
  onMinChange(oldValue) {
935
- this.min = this.sanitizeNumber(this.minNumber, 0);
936
- // Set decimal places value when min is decimal
937
- this.updateDecimalPlaces();
925
+ this.min = validateNumber(this.minNumber, 0);
938
926
  if (this.minNumber > this.maxNumber) {
939
927
  this.min = this.max;
940
928
  }
@@ -956,7 +944,7 @@ let Slider = class Slider extends ControlElement {
956
944
  * @returns {void}
957
945
  */
958
946
  onMaxChange(oldValue) {
959
- this.max = this.sanitizeNumber(this.maxNumber, 100);
947
+ this.max = validateNumber(this.maxNumber, 100);
960
948
  if (this.maxNumber < this.minNumber) {
961
949
  this.max = this.min;
962
950
  }
@@ -977,7 +965,7 @@ let Slider = class Slider extends ControlElement {
977
965
  * @param range show range slider
978
966
  * @returns Track template
979
967
  */
980
- renderTrackWrapper(range) {
968
+ renderTrack(range) {
981
969
  const stepContainerSize = this.calculatePercentage(this.minNumber + this.stepNumber);
982
970
  const translateX = (stepContainerSize / 2);
983
971
  const stepsStyle = { transform: `translateX(${translateX}%)`, backgroundSize: `${stepContainerSize}% 100%` };
@@ -986,12 +974,12 @@ let Slider = class Slider extends ControlElement {
986
974
  ? { width: `${this.calculatePercentage(this.toNumber) - this.calculatePercentage(this.fromNumber)}%`, left: `${this.calculatePercentage(this.fromNumber)}%` }
987
975
  : { width: `${this.calculatePercentage(Number(this.value))}%` };
988
976
  return html `
989
- <div part="track-wrapper" id="trackWrapper">
990
- <div part="track-fill" id="trackFill" style=${styleMap(trackFillStyle)}></div>
991
- <div part="step-container" id="stepContainer" style=${styleMap(stepContainerStyle)}>
992
- <div part="step" id="steps" style=${styleMap(stepsStyle)}></div>
977
+ <div part="track-wrapper" ${ref(this.trackRef)}>
978
+ <div part="track-fill" style=${styleMap(trackFillStyle)}></div>
979
+ <div part="step-container" style=${styleMap(stepContainerStyle)}>
980
+ <div part="step" style=${styleMap(stepsStyle)}></div>
981
+ </div>
993
982
  </div>
994
- </div>
995
983
  `;
996
984
  }
997
985
  /**
@@ -1004,11 +992,12 @@ let Slider = class Slider extends ControlElement {
1004
992
  renderThumb(value, percentageValue, name) {
1005
993
  const thumbStyle = { left: `${percentageValue}%` };
1006
994
  return html `
1007
- <div part="thumb-container" name=${name} id="thumbContainer" style=${styleMap(thumbStyle)}>
1008
- <div part="pin">
1009
- <span id="pinMarker" part="pin-value-marker">${value}</span></div>
1010
- <div part="thumb" draggable="true" id="thumb"></div>
1011
- </div>
995
+ <div part="thumb-container" name=${name} style=${styleMap(thumbStyle)}>
996
+ <div part="pin">
997
+ <span part="pin-value-marker">${value}</span>
998
+ </div>
999
+ <div part="thumb" draggable="true"></div>
1000
+ </div>
1012
1001
  `;
1013
1002
  }
1014
1003
  /**
@@ -1033,92 +1022,19 @@ let Slider = class Slider extends ControlElement {
1033
1022
  */
1034
1023
  renderNumberField(value, name) {
1035
1024
  return html `
1036
- <ef-number-field
1037
- @blur=${this.onBlur}
1038
- @keydown=${this.onKeydown}
1039
- part="input"
1040
- name="${name}"
1041
- no-spinner
1042
- .value="${value}"
1043
- min="${this.min}"
1044
- max="${this.max}"
1045
- step="${this.step}"
1046
- ?disabled="${this.disabled}"
1047
- ?readonly="${this.readonly || this.showInputField === 'readonly'}"
1048
- ></ef-number-field>
1049
- `;
1050
- }
1051
- /**
1052
- * Define styles in a tagged template literal, using the css tag function.
1053
- * @returns CSS template
1054
- */
1055
- static get styles() {
1056
- return css `
1057
- :host {
1058
- display: flex;
1059
- }
1060
- [part=slider-wrapper] {
1061
- position: relative;
1062
- width: 100%;
1063
- }
1064
- [part=slider] {
1065
- width: 100%;
1066
- height: 100%;
1067
- display: inline-block;
1068
- }
1069
- :host(:not([disabled]):focus){
1070
- outline:none;
1071
- }
1072
- :host([show-steps]) [part=track-wrapper]::after {
1073
- display:block;
1074
- position: absolute;
1075
- content: "";
1076
- right: 0;
1077
- }
1078
- [part=track-wrapper]{
1079
- content: "";
1080
- position: absolute;
1081
- width: 100%;
1082
- top: 50%;
1083
- left: 0;
1084
- pointer-events: none;
1085
- }
1086
- [part=thumb-container]{
1087
- position: absolute;
1088
- top: 0;
1089
- width: 100%;
1090
- z-index: 5;
1091
- }
1092
- [part=thumb]{
1093
- position: absolute;
1094
- margin: 0 auto;
1095
- }
1096
- [part=pin]{
1097
- display: flex;
1098
- position: absolute;
1099
- align-items: center;
1100
- justify-content: center;
1101
- z-index: 1;
1102
- }
1103
- :host([show-steps]) [part=step-container]{
1104
- position: absolute;
1105
- left: 0;
1106
- width: 100%;
1107
- }
1108
- :host([show-steps]) [part=step]{
1109
- width: 100%;
1110
- position: absolute;
1111
- left: 0;
1112
- }
1113
- [part=track-fill]{
1114
- z-index: 2;
1115
- content: "";
1116
- position: absolute;
1117
- left: 0;
1118
- }
1119
- :host([show-steps][step="0"]) [part=track-wrapper]::after{
1120
- width: 0;
1121
- }
1025
+ <ef-number-field
1026
+ @blur=${this.onBlur}
1027
+ @keydown=${this.onKeydown}
1028
+ part="input"
1029
+ name="${name}"
1030
+ no-spinner
1031
+ .value="${value}"
1032
+ min="${this.min}"
1033
+ max="${this.max}"
1034
+ step="${this.step}"
1035
+ ?disabled="${this.disabled}"
1036
+ ?readonly="${this.readonly || this.showInputField === 'readonly'}"
1037
+ ></ef-number-field>
1122
1038
  `;
1123
1039
  }
1124
1040
  /**
@@ -1129,8 +1045,8 @@ let Slider = class Slider extends ControlElement {
1129
1045
  return html `
1130
1046
  ${this.range && this.isShowInputField ? this.renderNumberField(this.from, 'from') : null}
1131
1047
  <div part="slider-wrapper">
1132
- <div part="slider">
1133
- ${this.renderTrackWrapper(this.range)}
1048
+ <div part="slider" ${ref(this.sliderRef)}>
1049
+ ${this.renderTrack(this.range)}
1134
1050
  ${this.range ? this.renderThumbRange(this.fromNumber, this.toNumber) : this.renderThumb(this.valueNumber, this.calculatePercentage(Number(this.value)), 'value')}
1135
1051
  </div>
1136
1052
  </div>
@@ -1169,15 +1085,6 @@ __decorate([
1169
1085
  __decorate([
1170
1086
  property({ type: String, attribute: 'min-range' })
1171
1087
  ], Slider.prototype, "minRange", void 0);
1172
- __decorate([
1173
- query('[part="slider"]')
1174
- ], Slider.prototype, "slider", void 0);
1175
- __decorate([
1176
- query('#trackWrapper')
1177
- ], Slider.prototype, "trackWrapper", void 0);
1178
- __decorate([
1179
- query('#thumbContainer')
1180
- ], Slider.prototype, "thumbContainer", void 0);
1181
1088
  __decorate([
1182
1089
  query('ef-number-field[name=value]')
1183
1090
  ], Slider.prototype, "valueInput", void 0);