slider.js 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322
  1. /*!
  2. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  4. * v1.0.0-beta.82
  5. */
  6. import { Component, Element, Event, h, Host, Listen, Method, Prop, State, Watch } from "@stencil/core";
  7. import { guid } from "../../utils/guid";
  8. import { intersects } from "../../utils/dom";
  9. import { clamp, decimalPlaces } from "../../utils/math";
  10. import { connectLabel, disconnectLabel } from "../../utils/label";
  11. import { afterConnectDefaultValueSet, connectForm, disconnectForm, HiddenFormInputSlot } from "../../utils/form";
  12. import { updateHostInteraction } from "../../utils/interactive";
  13. function isRange(value) {
  14. return Array.isArray(value);
  15. }
  16. export class Slider {
  17. constructor() {
  18. //--------------------------------------------------------------------------
  19. //
  20. // Properties
  21. //
  22. //--------------------------------------------------------------------------
  23. /** Disable and gray out the slider */
  24. this.disabled = false;
  25. /** Indicates if a histogram is present */
  26. this.hasHistogram = false;
  27. /** Label handles with their numeric value */
  28. this.labelHandles = false;
  29. /** Label tick marks with their numeric value. */
  30. this.labelTicks = false;
  31. /** Maximum selectable value */
  32. this.max = 100;
  33. /** Minimum selectable value */
  34. this.min = 0;
  35. /**
  36. * When true, the slider will display values from high to low.
  37. *
  38. * Note that this value will be ignored if the slider has an associated histogram.
  39. */
  40. this.mirrored = false;
  41. /** Use finer point for handles */
  42. this.precise = false;
  43. /**
  44. * When true, makes the component required for form-submission.
  45. */
  46. this.required = false;
  47. /** When true, enables snap selection along the step interval */
  48. this.snap = false;
  49. /** Interval to move on up/down keys */
  50. this.step = 1;
  51. /** Currently selected number (if single select) */
  52. this.value = 0;
  53. /**
  54. * Specify the scale of the slider, defaults to m
  55. */
  56. this.scale = "m";
  57. this.guid = `calcite-slider-${guid()}`;
  58. this.activeProp = "value";
  59. this.minMaxValueRange = null;
  60. this.minValueDragRange = null;
  61. this.maxValueDragRange = null;
  62. this.tickValues = [];
  63. this.dragUpdate = (event) => {
  64. event.preventDefault();
  65. if (this.dragProp) {
  66. const value = this.translate(event.clientX || event.pageX);
  67. if (isRange(this.value) && this.dragProp === "minMaxValue") {
  68. if (this.minValueDragRange && this.maxValueDragRange && this.minMaxValueRange) {
  69. const newMinValue = value - this.minValueDragRange;
  70. const newMaxValue = value + this.maxValueDragRange;
  71. if (newMaxValue <= this.max &&
  72. newMinValue >= this.min &&
  73. newMaxValue - newMinValue === this.minMaxValueRange) {
  74. this.minValue = this.clamp(newMinValue, "minValue");
  75. this.maxValue = this.clamp(newMaxValue, "maxValue");
  76. }
  77. }
  78. else {
  79. this.minValueDragRange = value - this.minValue;
  80. this.maxValueDragRange = this.maxValue - value;
  81. this.minMaxValueRange = this.maxValue - this.minValue;
  82. }
  83. }
  84. else {
  85. this.setValue(this.dragProp, this.clamp(value, this.dragProp));
  86. }
  87. }
  88. };
  89. this.dragEnd = (event) => {
  90. this.removeDragListeners();
  91. this.focusActiveHandle(event.clientX);
  92. if (this.lastDragPropValue != this[this.dragProp]) {
  93. this.emitChange();
  94. }
  95. this.dragProp = null;
  96. this.lastDragPropValue = null;
  97. this.minValueDragRange = null;
  98. this.maxValueDragRange = null;
  99. this.minMaxValueRange = null;
  100. };
  101. /**
  102. * Set the reference of the track Element
  103. * @internal
  104. * @param node
  105. */
  106. this.storeTrackRef = (node) => {
  107. this.trackEl = node;
  108. };
  109. }
  110. histogramWatcher(newHistogram) {
  111. this.hasHistogram = !!newHistogram;
  112. }
  113. valueHandler() {
  114. this.setMinMaxFromValue();
  115. }
  116. minMaxValueHandler() {
  117. this.setValueFromMinMax();
  118. }
  119. //--------------------------------------------------------------------------
  120. //
  121. // Lifecycle
  122. //
  123. //--------------------------------------------------------------------------
  124. connectedCallback() {
  125. this.setMinMaxFromValue();
  126. this.setValueFromMinMax();
  127. connectLabel(this);
  128. connectForm(this);
  129. }
  130. disconnectedCallback() {
  131. disconnectLabel(this);
  132. disconnectForm(this);
  133. this.removeDragListeners();
  134. }
  135. componentWillLoad() {
  136. this.tickValues = this.generateTickValues();
  137. if (!isRange(this.value)) {
  138. this.value = this.clamp(this.value);
  139. }
  140. afterConnectDefaultValueSet(this, this.value);
  141. if (this.snap && !isRange(this.value)) {
  142. this.value = this.getClosestStep(this.value);
  143. }
  144. if (this.histogram) {
  145. this.hasHistogram = true;
  146. }
  147. }
  148. componentDidRender() {
  149. if (this.labelHandles) {
  150. this.adjustHostObscuredHandleLabel("value");
  151. if (isRange(this.value)) {
  152. this.adjustHostObscuredHandleLabel("minValue");
  153. if (!(this.precise && !this.hasHistogram)) {
  154. this.hyphenateCollidingRangeHandleLabels();
  155. }
  156. }
  157. }
  158. this.hideObscuredBoundingTickLabels();
  159. updateHostInteraction(this);
  160. }
  161. render() {
  162. const id = this.el.id || this.guid;
  163. const maxProp = isRange(this.value) ? "maxValue" : "value";
  164. const value = isRange(this.value) ? this.maxValue : this.value;
  165. const min = this.minValue || this.min;
  166. const useMinValue = this.shouldUseMinValue();
  167. const minInterval = this.getUnitInterval(useMinValue ? this.minValue : min) * 100;
  168. const maxInterval = this.getUnitInterval(value) * 100;
  169. const mirror = this.shouldMirror();
  170. const leftThumbOffset = `${mirror ? 100 - minInterval : minInterval}%`;
  171. const rightThumbOffset = `${mirror ? maxInterval : 100 - maxInterval}%`;
  172. const valueIsRange = isRange(this.value);
  173. const handle = (h("div", { "aria-disabled": this.disabled, "aria-label": valueIsRange ? this.maxLabel : this.minLabel, "aria-orientation": "horizontal", "aria-valuemax": this.max, "aria-valuemin": this.min, "aria-valuenow": value, class: {
  174. thumb: true,
  175. "thumb--value": true,
  176. "thumb--active": this.lastDragProp !== "minMaxValue" && this.dragProp === maxProp
  177. }, onBlur: () => (this.activeProp = null), onFocus: () => (this.activeProp = maxProp), onPointerDown: () => this.dragStart(maxProp), ref: (el) => (this.maxHandle = el), role: "slider", style: { right: rightThumbOffset }, tabIndex: 0 },
  178. h("div", { class: "handle" })));
  179. const labeledHandle = (h("div", { "aria-disabled": this.disabled, "aria-label": valueIsRange ? this.maxLabel : this.minLabel, "aria-orientation": "horizontal", "aria-valuemax": this.max, "aria-valuemin": this.min, "aria-valuenow": value, class: {
  180. thumb: true,
  181. "thumb--value": true,
  182. "thumb--active": this.lastDragProp !== "minMaxValue" && this.dragProp === maxProp
  183. }, onBlur: () => (this.activeProp = null), onFocus: () => (this.activeProp = maxProp), onPointerDown: () => this.dragStart(maxProp), ref: (el) => (this.maxHandle = el), role: "slider", style: { right: rightThumbOffset }, tabIndex: 0 },
  184. h("span", { "aria-hidden": "true", class: "handle__label handle__label--value" }, value ? value.toLocaleString() : value),
  185. h("span", { "aria-hidden": "true", class: "handle__label handle__label--value static" }, value ? value.toLocaleString() : value),
  186. h("span", { "aria-hidden": "true", class: "handle__label handle__label--value transformed" }, value ? value.toLocaleString() : value),
  187. h("div", { class: "handle" })));
  188. const histogramLabeledHandle = (h("div", { "aria-disabled": this.disabled, "aria-label": valueIsRange ? this.maxLabel : this.minLabel, "aria-orientation": "horizontal", "aria-valuemax": this.max, "aria-valuemin": this.min, "aria-valuenow": value, class: {
  189. thumb: true,
  190. "thumb--value": true,
  191. "thumb--active": this.lastDragProp !== "minMaxValue" && this.dragProp === maxProp
  192. }, onBlur: () => (this.activeProp = null), onFocus: () => (this.activeProp = maxProp), onPointerDown: () => this.dragStart(maxProp), ref: (el) => (this.maxHandle = el), role: "slider", style: { right: rightThumbOffset }, tabIndex: 0 },
  193. h("div", { class: "handle" }),
  194. h("span", { "aria-hidden": "true", class: "handle__label handle__label--value" }, value ? value.toLocaleString() : value),
  195. h("span", { "aria-hidden": "true", class: "handle__label handle__label--value static" }, value ? value.toLocaleString() : value),
  196. h("span", { "aria-hidden": "true", class: "handle__label handle__label--value transformed" }, value ? value.toLocaleString() : value)));
  197. const preciseHandle = (h("div", { "aria-disabled": this.disabled, "aria-label": valueIsRange ? this.maxLabel : this.minLabel, "aria-orientation": "horizontal", "aria-valuemax": this.max, "aria-valuemin": this.min, "aria-valuenow": value, class: {
  198. thumb: true,
  199. "thumb--value": true,
  200. "thumb--active": this.lastDragProp !== "minMaxValue" && this.dragProp === maxProp,
  201. "thumb--precise": true
  202. }, onBlur: () => (this.activeProp = null), onFocus: () => (this.activeProp = maxProp), onPointerDown: () => this.dragStart(maxProp), ref: (el) => (this.maxHandle = el), role: "slider", style: { right: rightThumbOffset }, tabIndex: 0 },
  203. h("div", { class: "handle" }),
  204. h("div", { class: "handle-extension" })));
  205. const histogramPreciseHandle = (h("div", { "aria-disabled": this.disabled, "aria-label": valueIsRange ? this.maxLabel : this.minLabel, "aria-orientation": "horizontal", "aria-valuemax": this.max, "aria-valuemin": this.min, "aria-valuenow": value, class: {
  206. thumb: true,
  207. "thumb--value": true,
  208. "thumb--active": this.lastDragProp !== "minMaxValue" && this.dragProp === maxProp,
  209. "thumb--precise": true
  210. }, onBlur: () => (this.activeProp = null), onFocus: () => (this.activeProp = maxProp), onPointerDown: () => this.dragStart(maxProp), ref: (el) => (this.maxHandle = el), role: "slider", style: { right: rightThumbOffset }, tabIndex: 0 },
  211. h("div", { class: "handle-extension" }),
  212. h("div", { class: "handle" })));
  213. const labeledPreciseHandle = (h("div", { "aria-disabled": this.disabled, "aria-label": valueIsRange ? this.maxLabel : this.minLabel, "aria-orientation": "horizontal", "aria-valuemax": this.max, "aria-valuemin": this.min, "aria-valuenow": value, class: {
  214. thumb: true,
  215. "thumb--value": true,
  216. "thumb--active": this.lastDragProp !== "minMaxValue" && this.dragProp === maxProp,
  217. "thumb--precise": true
  218. }, onBlur: () => (this.activeProp = null), onFocus: () => (this.activeProp = maxProp), onPointerDown: () => this.dragStart(maxProp), ref: (el) => (this.maxHandle = el), role: "slider", style: { right: rightThumbOffset }, tabIndex: 0 },
  219. h("span", { "aria-hidden": "true", class: "handle__label handle__label--value" }, value ? value.toLocaleString() : value),
  220. h("span", { "aria-hidden": "true", class: "handle__label handle__label--value static" }, value ? value.toLocaleString() : value),
  221. h("span", { "aria-hidden": "true", class: "handle__label handle__label--value transformed" }, value ? value.toLocaleString() : value),
  222. h("div", { class: "handle" }),
  223. h("div", { class: "handle-extension" })));
  224. const histogramLabeledPreciseHandle = (h("div", { "aria-disabled": this.disabled, "aria-label": valueIsRange ? this.maxLabel : this.minLabel, "aria-orientation": "horizontal", "aria-valuemax": this.max, "aria-valuemin": this.min, "aria-valuenow": value, class: {
  225. thumb: true,
  226. "thumb--value": true,
  227. "thumb--active": this.lastDragProp !== "minMaxValue" && this.dragProp === maxProp,
  228. "thumb--precise": true
  229. }, onBlur: () => (this.activeProp = null), onFocus: () => (this.activeProp = maxProp), onPointerDown: () => this.dragStart(maxProp), ref: (el) => (this.maxHandle = el), role: "slider", style: { right: rightThumbOffset }, tabIndex: 0 },
  230. h("div", { class: "handle-extension" }),
  231. h("div", { class: "handle" }),
  232. h("span", { "aria-hidden": "true", class: "handle__label handle__label--value" }, value ? value.toLocaleString() : value),
  233. h("span", { "aria-hidden": "true", class: "handle__label handle__label--value static" }, value ? value.toLocaleString() : value),
  234. h("span", { "aria-hidden": "true", class: "handle__label handle__label--value transformed" }, value ? value.toLocaleString() : value)));
  235. const minHandle = (h("div", { "aria-disabled": this.disabled, "aria-label": this.minLabel, "aria-orientation": "horizontal", "aria-valuemax": this.max, "aria-valuemin": this.min, "aria-valuenow": this.minValue, class: {
  236. thumb: true,
  237. "thumb--minValue": true,
  238. "thumb--active": this.dragProp === "minValue"
  239. }, onBlur: () => (this.activeProp = null), onFocus: () => (this.activeProp = "minValue"), onPointerDown: () => this.dragStart("minValue"), ref: (el) => (this.minHandle = el), role: "slider", style: { left: leftThumbOffset }, tabIndex: 0 },
  240. h("div", { class: "handle" })));
  241. const minLabeledHandle = (h("div", { "aria-disabled": this.disabled, "aria-label": this.minLabel, "aria-orientation": "horizontal", "aria-valuemax": this.max, "aria-valuemin": this.min, "aria-valuenow": this.minValue, class: {
  242. thumb: true,
  243. "thumb--minValue": true,
  244. "thumb--active": this.dragProp === "minValue"
  245. }, onBlur: () => (this.activeProp = null), onFocus: () => (this.activeProp = "minValue"), onPointerDown: () => this.dragStart("minValue"), ref: (el) => (this.minHandle = el), role: "slider", style: { left: leftThumbOffset }, tabIndex: 0 },
  246. h("span", { "aria-hidden": "true", class: "handle__label handle__label--minValue" }, this.minValue && this.minValue.toLocaleString()),
  247. h("span", { "aria-hidden": "true", class: "handle__label handle__label--minValue static" }, this.minValue && this.minValue.toLocaleString()),
  248. h("span", { "aria-hidden": "true", class: "handle__label handle__label--minValue transformed" }, this.minValue && this.minValue.toLocaleString()),
  249. h("div", { class: "handle" })));
  250. const minHistogramLabeledHandle = (h("div", { "aria-disabled": this.disabled, "aria-label": this.minLabel, "aria-orientation": "horizontal", "aria-valuemax": this.max, "aria-valuemin": this.min, "aria-valuenow": this.minValue, class: {
  251. thumb: true,
  252. "thumb--minValue": true,
  253. "thumb--active": this.dragProp === "minValue"
  254. }, onBlur: () => (this.activeProp = null), onFocus: () => (this.activeProp = "minValue"), onPointerDown: () => this.dragStart("minValue"), ref: (el) => (this.minHandle = el), role: "slider", style: { left: leftThumbOffset }, tabIndex: 0 },
  255. h("div", { class: "handle" }),
  256. h("span", { "aria-hidden": "true", class: "handle__label handle__label--minValue" }, this.minValue && this.minValue.toLocaleString()),
  257. h("span", { "aria-hidden": "true", class: "handle__label handle__label--minValue static" }, this.minValue && this.minValue.toLocaleString()),
  258. h("span", { "aria-hidden": "true", class: "handle__label handle__label--minValue transformed" }, this.minValue && this.minValue.toLocaleString())));
  259. const minPreciseHandle = (h("div", { "aria-disabled": this.disabled, "aria-label": this.minLabel, "aria-orientation": "horizontal", "aria-valuemax": this.max, "aria-valuemin": this.min, "aria-valuenow": this.minValue, class: {
  260. thumb: true,
  261. "thumb--minValue": true,
  262. "thumb--active": this.dragProp === "minValue",
  263. "thumb--precise": true
  264. }, onBlur: () => (this.activeProp = null), onFocus: () => (this.activeProp = "minValue"), onPointerDown: () => this.dragStart("minValue"), ref: (el) => (this.minHandle = el), role: "slider", style: { left: leftThumbOffset }, tabIndex: 0 },
  265. h("div", { class: "handle-extension" }),
  266. h("div", { class: "handle" })));
  267. const minLabeledPreciseHandle = (h("div", { "aria-disabled": this.disabled, "aria-label": this.minLabel, "aria-orientation": "horizontal", "aria-valuemax": this.max, "aria-valuemin": this.min, "aria-valuenow": this.minValue, class: {
  268. thumb: true,
  269. "thumb--minValue": true,
  270. "thumb--active": this.dragProp === "minValue",
  271. "thumb--precise": true
  272. }, onBlur: () => (this.activeProp = null), onFocus: () => (this.activeProp = "minValue"), onPointerDown: () => this.dragStart("minValue"), ref: (el) => (this.minHandle = el), role: "slider", style: { left: leftThumbOffset }, tabIndex: 0 },
  273. h("div", { class: "handle-extension" }),
  274. h("div", { class: "handle" }),
  275. h("span", { "aria-hidden": "true", class: "handle__label handle__label--minValue" }, this.minValue && this.minValue.toLocaleString()),
  276. h("span", { "aria-hidden": "true", class: "handle__label handle__label--minValue static" }, this.minValue && this.minValue.toLocaleString()),
  277. h("span", { "aria-hidden": "true", class: "handle__label handle__label--minValue transformed" }, this.minValue && this.minValue.toLocaleString())));
  278. return (h(Host, { id: id, onTouchStart: this.handleTouchStart },
  279. h("div", { class: {
  280. ["container"]: true,
  281. ["container--range"]: valueIsRange,
  282. [`scale--${this.scale}`]: true
  283. } },
  284. this.renderGraph(),
  285. h("div", { class: "track", ref: this.storeTrackRef },
  286. h("div", { class: "track__range", onPointerDown: () => this.dragStart("minMaxValue"), style: {
  287. left: `${mirror ? 100 - maxInterval : minInterval}%`,
  288. right: `${mirror ? minInterval : 100 - maxInterval}%`
  289. } }),
  290. h("div", { class: "ticks" }, this.tickValues.map((tick) => {
  291. const tickOffset = `${this.getUnitInterval(tick) * 100}%`;
  292. let activeTicks = tick >= min && tick <= value;
  293. if (useMinValue) {
  294. activeTicks = tick >= this.minValue && tick <= this.maxValue;
  295. }
  296. return (h("span", { class: {
  297. tick: true,
  298. "tick--active": activeTicks
  299. }, style: {
  300. left: mirror ? "" : tickOffset,
  301. right: mirror ? tickOffset : ""
  302. } }, this.renderTickLabel(tick)));
  303. }))),
  304. h("div", { class: "thumb-container" },
  305. !this.precise && !this.labelHandles && valueIsRange && minHandle,
  306. !this.hasHistogram &&
  307. !this.precise &&
  308. this.labelHandles &&
  309. valueIsRange &&
  310. minLabeledHandle,
  311. this.precise && !this.labelHandles && valueIsRange && minPreciseHandle,
  312. this.precise && this.labelHandles && valueIsRange && minLabeledPreciseHandle,
  313. this.hasHistogram &&
  314. !this.precise &&
  315. this.labelHandles &&
  316. valueIsRange &&
  317. minHistogramLabeledHandle,
  318. !this.precise && !this.labelHandles && handle,
  319. !this.hasHistogram && !this.precise && this.labelHandles && labeledHandle,
  320. !this.hasHistogram && this.precise && !this.labelHandles && preciseHandle,
  321. this.hasHistogram && this.precise && !this.labelHandles && histogramPreciseHandle,
  322. !this.hasHistogram && this.precise && this.labelHandles && labeledPreciseHandle,
  323. this.hasHistogram && !this.precise && this.labelHandles && histogramLabeledHandle,
  324. this.hasHistogram &&
  325. this.precise &&
  326. this.labelHandles &&
  327. histogramLabeledPreciseHandle,
  328. h(HiddenFormInputSlot, { component: this })))));
  329. }
  330. renderGraph() {
  331. return this.histogram ? (h("calcite-graph", { class: "graph", colorStops: this.histogramStops, data: this.histogram, highlightMax: isRange(this.value) ? this.maxValue : this.value, highlightMin: isRange(this.value) ? this.minValue : this.min, max: this.max, min: this.min })) : null;
  332. }
  333. renderTickLabel(tick) {
  334. const valueIsRange = isRange(this.value);
  335. const isMinTickLabel = tick === this.min;
  336. const isMaxTickLabel = tick === this.max;
  337. const tickLabel = (h("span", { class: {
  338. tick__label: true,
  339. "tick__label--min": isMinTickLabel,
  340. "tick__label--max": isMaxTickLabel
  341. } }, tick.toLocaleString()));
  342. if (this.labelTicks && !this.hasHistogram && !valueIsRange) {
  343. return tickLabel;
  344. }
  345. if (this.labelTicks &&
  346. !this.hasHistogram &&
  347. valueIsRange &&
  348. !this.precise &&
  349. !this.labelHandles) {
  350. return tickLabel;
  351. }
  352. if (this.labelTicks &&
  353. !this.hasHistogram &&
  354. valueIsRange &&
  355. !this.precise &&
  356. this.labelHandles) {
  357. return tickLabel;
  358. }
  359. if (this.labelTicks &&
  360. !this.hasHistogram &&
  361. valueIsRange &&
  362. this.precise &&
  363. (isMinTickLabel || isMaxTickLabel)) {
  364. return tickLabel;
  365. }
  366. if (this.labelTicks && this.hasHistogram && !this.precise && !this.labelHandles) {
  367. return tickLabel;
  368. }
  369. if (this.labelTicks &&
  370. this.hasHistogram &&
  371. this.precise &&
  372. !this.labelHandles &&
  373. (isMinTickLabel || isMaxTickLabel)) {
  374. return tickLabel;
  375. }
  376. if (this.labelTicks &&
  377. this.hasHistogram &&
  378. !this.precise &&
  379. this.labelHandles &&
  380. (isMinTickLabel || isMaxTickLabel)) {
  381. return tickLabel;
  382. }
  383. if (this.labelTicks &&
  384. this.hasHistogram &&
  385. this.precise &&
  386. this.labelHandles &&
  387. (isMinTickLabel || isMaxTickLabel)) {
  388. return tickLabel;
  389. }
  390. return null;
  391. }
  392. //--------------------------------------------------------------------------
  393. //
  394. // Event Listeners
  395. //
  396. //--------------------------------------------------------------------------
  397. keyDownHandler(event) {
  398. const mirror = this.shouldMirror();
  399. const { activeProp, max, min, pageStep, step } = this;
  400. const value = this[activeProp];
  401. const key = event.key;
  402. if (key === "Enter" || key === " ") {
  403. event.preventDefault();
  404. return;
  405. }
  406. let adjustment;
  407. if (key === "ArrowUp" || key === "ArrowRight") {
  408. const directionFactor = mirror && key === "ArrowRight" ? -1 : 1;
  409. adjustment = value + step * directionFactor;
  410. }
  411. else if (key === "ArrowDown" || key === "ArrowLeft") {
  412. const directionFactor = mirror && key === "ArrowLeft" ? -1 : 1;
  413. adjustment = value - step * directionFactor;
  414. }
  415. else if (key === "PageUp") {
  416. if (pageStep) {
  417. adjustment = value + pageStep;
  418. }
  419. }
  420. else if (key === "PageDown") {
  421. if (pageStep) {
  422. adjustment = value - pageStep;
  423. }
  424. }
  425. else if (key === "Home") {
  426. adjustment = min;
  427. }
  428. else if (key === "End") {
  429. adjustment = max;
  430. }
  431. if (isNaN(adjustment)) {
  432. return;
  433. }
  434. event.preventDefault();
  435. const fixedDecimalAdjustment = Number(adjustment.toFixed(decimalPlaces(step)));
  436. this.setValue(activeProp, this.clamp(fixedDecimalAdjustment, activeProp));
  437. }
  438. clickHandler(event) {
  439. this.focusActiveHandle(event.clientX);
  440. }
  441. pointerDownHandler(event) {
  442. const x = event.clientX || event.pageX;
  443. const position = this.translate(x);
  444. let prop = "value";
  445. if (isRange(this.value)) {
  446. const inRange = position >= this.minValue && position <= this.maxValue;
  447. if (inRange && this.lastDragProp === "minMaxValue") {
  448. prop = "minMaxValue";
  449. }
  450. else {
  451. const closerToMax = Math.abs(this.maxValue - position) < Math.abs(this.minValue - position);
  452. prop = closerToMax || position > this.maxValue ? "maxValue" : "minValue";
  453. }
  454. }
  455. this.lastDragPropValue = this[prop];
  456. this.dragStart(prop);
  457. const isThumbActive = this.el.shadowRoot.querySelector(".thumb:active");
  458. if (!isThumbActive) {
  459. this.setValue(prop, this.clamp(position, prop));
  460. }
  461. }
  462. handleTouchStart(event) {
  463. // needed to prevent extra click at the end of a handle drag
  464. event.preventDefault();
  465. }
  466. //--------------------------------------------------------------------------
  467. //
  468. // Public Methods
  469. //
  470. //--------------------------------------------------------------------------
  471. /** Sets focus on the component. */
  472. async setFocus() {
  473. const handle = this.minHandle ? this.minHandle : this.maxHandle;
  474. handle.focus();
  475. }
  476. //--------------------------------------------------------------------------
  477. //
  478. // Private Methods
  479. //
  480. //--------------------------------------------------------------------------
  481. setValueFromMinMax() {
  482. const { minValue, maxValue } = this;
  483. if (typeof minValue === "number" && typeof maxValue === "number") {
  484. this.value = [minValue, maxValue];
  485. }
  486. }
  487. setMinMaxFromValue() {
  488. const { value } = this;
  489. if (isRange(value)) {
  490. this.minValue = value[0];
  491. this.maxValue = value[1];
  492. }
  493. }
  494. onLabelClick() {
  495. this.setFocus();
  496. }
  497. shouldMirror() {
  498. return this.mirrored && !this.hasHistogram;
  499. }
  500. shouldUseMinValue() {
  501. if (!isRange(this.value)) {
  502. return false;
  503. }
  504. return ((this.hasHistogram && this.maxValue === 0) || (!this.hasHistogram && this.minValue === 0));
  505. }
  506. generateTickValues() {
  507. const ticks = [];
  508. let current = this.min;
  509. while (this.ticks && current < this.max + this.ticks) {
  510. ticks.push(Math.min(current, this.max));
  511. current = current + this.ticks;
  512. }
  513. return ticks;
  514. }
  515. dragStart(prop) {
  516. this.dragProp = prop;
  517. this.lastDragProp = this.dragProp;
  518. this.activeProp = prop;
  519. document.addEventListener("pointermove", this.dragUpdate);
  520. document.addEventListener("pointerup", this.dragEnd);
  521. document.addEventListener("pointercancel", this.dragEnd);
  522. }
  523. focusActiveHandle(valueX) {
  524. switch (this.dragProp) {
  525. case "minValue":
  526. this.minHandle.focus();
  527. break;
  528. case "maxValue":
  529. this.maxHandle.focus();
  530. break;
  531. case "minMaxValue":
  532. this.getClosestHandle(valueX).focus();
  533. break;
  534. default:
  535. break;
  536. }
  537. }
  538. emitInput() {
  539. this.calciteSliderInput.emit();
  540. this.calciteSliderUpdate.emit();
  541. }
  542. emitChange() {
  543. this.calciteSliderChange.emit();
  544. }
  545. removeDragListeners() {
  546. document.removeEventListener("pointermove", this.dragUpdate);
  547. document.removeEventListener("pointerup", this.dragEnd);
  548. document.removeEventListener("pointercancel", this.dragEnd);
  549. }
  550. /**
  551. * Set the prop value if changed at the component level
  552. * @param valueProp
  553. * @param value
  554. */
  555. setValue(valueProp, value) {
  556. const oldValue = this[valueProp];
  557. const valueChanged = oldValue !== value;
  558. if (!valueChanged) {
  559. return;
  560. }
  561. this[valueProp] = value;
  562. const dragging = this.dragProp;
  563. if (!dragging) {
  564. this.emitChange();
  565. }
  566. this.emitInput();
  567. }
  568. /**
  569. * If number is outside range, constrain to min or max
  570. * @internal
  571. */
  572. clamp(value, prop) {
  573. value = clamp(value, this.min, this.max);
  574. // ensure that maxValue and minValue don't swap positions
  575. if (prop === "maxValue") {
  576. value = Math.max(value, this.minValue);
  577. }
  578. if (prop === "minValue") {
  579. value = Math.min(value, this.maxValue);
  580. }
  581. return value;
  582. }
  583. /**
  584. * Translate a pixel position to value along the range
  585. * @internal
  586. */
  587. translate(x) {
  588. const range = this.max - this.min;
  589. const { left, width } = this.trackEl.getBoundingClientRect();
  590. const percent = (x - left) / width;
  591. const mirror = this.shouldMirror();
  592. const clampedValue = this.clamp(this.min + range * (mirror ? 1 - percent : percent));
  593. let value = Number(clampedValue.toFixed(decimalPlaces(this.step)));
  594. if (this.snap && this.step) {
  595. value = this.getClosestStep(value);
  596. }
  597. return value;
  598. }
  599. /**
  600. * Get closest allowed value along stepped values
  601. * @internal
  602. */
  603. getClosestStep(num) {
  604. num = Number(this.clamp(num).toFixed(decimalPlaces(this.step)));
  605. if (this.step) {
  606. const step = Math.round(num / this.step) * this.step;
  607. num = Number(this.clamp(step).toFixed(decimalPlaces(this.step)));
  608. }
  609. return num;
  610. }
  611. getClosestHandle(valueX) {
  612. return this.getDistanceX(this.maxHandle, valueX) > this.getDistanceX(this.minHandle, valueX)
  613. ? this.minHandle
  614. : this.maxHandle;
  615. }
  616. getDistanceX(el, valueX) {
  617. return Math.abs(el.getBoundingClientRect().left - valueX);
  618. }
  619. getFontSizeForElement(element) {
  620. return Number(window.getComputedStyle(element).getPropertyValue("font-size").match(/\d+/)[0]);
  621. }
  622. /**
  623. * Get position of value along range as fractional value
  624. * @return {number} number in the unit interval [0,1]
  625. * @internal
  626. */
  627. getUnitInterval(num) {
  628. num = this.clamp(num);
  629. const range = this.max - this.min;
  630. return (num - this.min) / range;
  631. }
  632. adjustHostObscuredHandleLabel(name) {
  633. const label = this.el.shadowRoot.querySelector(`.handle__label--${name}`);
  634. const labelStatic = this.el.shadowRoot.querySelector(`.handle__label--${name}.static`);
  635. const labelTransformed = this.el.shadowRoot.querySelector(`.handle__label--${name}.transformed`);
  636. const labelStaticBounds = labelStatic.getBoundingClientRect();
  637. const labelStaticOffset = this.getHostOffset(labelStaticBounds.left, labelStaticBounds.right);
  638. label.style.transform = `translateX(${labelStaticOffset}px)`;
  639. labelTransformed.style.transform = `translateX(${labelStaticOffset}px)`;
  640. }
  641. hyphenateCollidingRangeHandleLabels() {
  642. const { shadowRoot } = this.el;
  643. const mirror = this.shouldMirror();
  644. const leftModifier = mirror ? "value" : "minValue";
  645. const rightModifier = mirror ? "minValue" : "value";
  646. const leftValueLabel = shadowRoot.querySelector(`.handle__label--${leftModifier}`);
  647. const leftValueLabelStatic = shadowRoot.querySelector(`.handle__label--${leftModifier}.static`);
  648. const leftValueLabelTransformed = shadowRoot.querySelector(`.handle__label--${leftModifier}.transformed`);
  649. const leftValueLabelStaticHostOffset = this.getHostOffset(leftValueLabelStatic.getBoundingClientRect().left, leftValueLabelStatic.getBoundingClientRect().right);
  650. const rightValueLabel = shadowRoot.querySelector(`.handle__label--${rightModifier}`);
  651. const rightValueLabelStatic = shadowRoot.querySelector(`.handle__label--${rightModifier}.static`);
  652. const rightValueLabelTransformed = shadowRoot.querySelector(`.handle__label--${rightModifier}.transformed`);
  653. const rightValueLabelStaticHostOffset = this.getHostOffset(rightValueLabelStatic.getBoundingClientRect().left, rightValueLabelStatic.getBoundingClientRect().right);
  654. const labelFontSize = this.getFontSizeForElement(leftValueLabel);
  655. const labelTransformedOverlap = this.getRangeLabelOverlap(leftValueLabelTransformed, rightValueLabelTransformed);
  656. const hyphenLabel = leftValueLabel;
  657. const labelOffset = labelFontSize / 2;
  658. if (labelTransformedOverlap > 0) {
  659. hyphenLabel.classList.add("hyphen", "hyphen--wrap");
  660. if (rightValueLabelStaticHostOffset === 0 && leftValueLabelStaticHostOffset === 0) {
  661. // Neither handle overlaps the host boundary
  662. let leftValueLabelTranslate = labelTransformedOverlap / 2 - labelOffset;
  663. leftValueLabelTranslate =
  664. Math.sign(leftValueLabelTranslate) === -1
  665. ? Math.abs(leftValueLabelTranslate)
  666. : -leftValueLabelTranslate;
  667. const leftValueLabelTransformedHostOffset = this.getHostOffset(leftValueLabelTransformed.getBoundingClientRect().left +
  668. leftValueLabelTranslate -
  669. labelOffset, leftValueLabelTransformed.getBoundingClientRect().right +
  670. leftValueLabelTranslate -
  671. labelOffset);
  672. let rightValueLabelTranslate = labelTransformedOverlap / 2;
  673. const rightValueLabelTransformedHostOffset = this.getHostOffset(rightValueLabelTransformed.getBoundingClientRect().left + rightValueLabelTranslate, rightValueLabelTransformed.getBoundingClientRect().right + rightValueLabelTranslate);
  674. if (leftValueLabelTransformedHostOffset !== 0) {
  675. leftValueLabelTranslate += leftValueLabelTransformedHostOffset;
  676. rightValueLabelTranslate += leftValueLabelTransformedHostOffset;
  677. }
  678. if (rightValueLabelTransformedHostOffset !== 0) {
  679. leftValueLabelTranslate += rightValueLabelTransformedHostOffset;
  680. rightValueLabelTranslate += rightValueLabelTransformedHostOffset;
  681. }
  682. leftValueLabel.style.transform = `translateX(${leftValueLabelTranslate}px)`;
  683. leftValueLabelTransformed.style.transform = `translateX(${leftValueLabelTranslate - labelOffset}px)`;
  684. rightValueLabel.style.transform = `translateX(${rightValueLabelTranslate}px)`;
  685. rightValueLabelTransformed.style.transform = `translateX(${rightValueLabelTranslate}px)`;
  686. }
  687. else if (leftValueLabelStaticHostOffset > 0 || rightValueLabelStaticHostOffset > 0) {
  688. // labels overlap host boundary on the left side
  689. leftValueLabel.style.transform = `translateX(${leftValueLabelStaticHostOffset + labelOffset}px)`;
  690. rightValueLabel.style.transform = `translateX(${labelTransformedOverlap + rightValueLabelStaticHostOffset}px)`;
  691. rightValueLabelTransformed.style.transform = `translateX(${labelTransformedOverlap + rightValueLabelStaticHostOffset}px)`;
  692. }
  693. else if (leftValueLabelStaticHostOffset < 0 || rightValueLabelStaticHostOffset < 0) {
  694. // labels overlap host boundary on the right side
  695. let leftValueLabelTranslate = Math.abs(leftValueLabelStaticHostOffset) + labelTransformedOverlap - labelOffset;
  696. leftValueLabelTranslate =
  697. Math.sign(leftValueLabelTranslate) === -1
  698. ? Math.abs(leftValueLabelTranslate)
  699. : -leftValueLabelTranslate;
  700. leftValueLabel.style.transform = `translateX(${leftValueLabelTranslate}px)`;
  701. leftValueLabelTransformed.style.transform = `translateX(${leftValueLabelTranslate - labelOffset}px)`;
  702. }
  703. }
  704. else {
  705. hyphenLabel.classList.remove("hyphen", "hyphen--wrap");
  706. leftValueLabel.style.transform = `translateX(${leftValueLabelStaticHostOffset}px)`;
  707. leftValueLabelTransformed.style.transform = `translateX(${leftValueLabelStaticHostOffset}px)`;
  708. rightValueLabel.style.transform = `translateX(${rightValueLabelStaticHostOffset}px)`;
  709. rightValueLabelTransformed.style.transform = `translateX(${rightValueLabelStaticHostOffset}px)`;
  710. }
  711. }
  712. /**
  713. * Hides bounding tick labels that are obscured by either handle.
  714. */
  715. hideObscuredBoundingTickLabels() {
  716. const valueIsRange = isRange(this.value);
  717. if (!this.hasHistogram && !valueIsRange && !this.labelHandles && !this.precise) {
  718. return;
  719. }
  720. if (!this.hasHistogram && !valueIsRange && this.labelHandles && !this.precise) {
  721. return;
  722. }
  723. if (!this.hasHistogram && !valueIsRange && !this.labelHandles && this.precise) {
  724. return;
  725. }
  726. if (!this.hasHistogram && !valueIsRange && this.labelHandles && this.precise) {
  727. return;
  728. }
  729. if (!this.hasHistogram && valueIsRange && !this.precise) {
  730. return;
  731. }
  732. if (this.hasHistogram && !this.precise && !this.labelHandles) {
  733. return;
  734. }
  735. const minHandle = this.el.shadowRoot.querySelector(".thumb--minValue");
  736. const maxHandle = this.el.shadowRoot.querySelector(".thumb--value");
  737. const minTickLabel = this.el.shadowRoot.querySelector(".tick__label--min");
  738. const maxTickLabel = this.el.shadowRoot.querySelector(".tick__label--max");
  739. if (!minHandle && maxHandle && minTickLabel && maxTickLabel) {
  740. minTickLabel.style.opacity = this.isMinTickLabelObscured(minTickLabel, maxHandle) ? "0" : "1";
  741. maxTickLabel.style.opacity = this.isMaxTickLabelObscured(maxTickLabel, maxHandle) ? "0" : "1";
  742. }
  743. if (minHandle && maxHandle && minTickLabel && maxTickLabel) {
  744. minTickLabel.style.opacity =
  745. this.isMinTickLabelObscured(minTickLabel, minHandle) ||
  746. this.isMinTickLabelObscured(minTickLabel, maxHandle)
  747. ? "0"
  748. : "1";
  749. maxTickLabel.style.opacity =
  750. this.isMaxTickLabelObscured(maxTickLabel, minHandle) ||
  751. (this.isMaxTickLabelObscured(maxTickLabel, maxHandle) && this.hasHistogram)
  752. ? "0"
  753. : "1";
  754. }
  755. }
  756. /**
  757. * Returns an integer representing the number of pixels to offset on the left or right side based on desired position behavior.
  758. * @internal
  759. */
  760. getHostOffset(leftBounds, rightBounds) {
  761. const hostBounds = this.el.getBoundingClientRect();
  762. const buffer = 7;
  763. if (leftBounds + buffer < hostBounds.left) {
  764. return hostBounds.left - leftBounds - buffer;
  765. }
  766. if (rightBounds - buffer > hostBounds.right) {
  767. return -(rightBounds - hostBounds.right) + buffer;
  768. }
  769. return 0;
  770. }
  771. /**
  772. * Returns an integer representing the number of pixels that the two given span elements are overlapping, taking into account
  773. * a space in between the two spans equal to the font-size set on them to account for the space needed to render a hyphen.
  774. * @param leftLabel
  775. * @param rightLabel
  776. */
  777. getRangeLabelOverlap(leftLabel, rightLabel) {
  778. const leftLabelBounds = leftLabel.getBoundingClientRect();
  779. const rightLabelBounds = rightLabel.getBoundingClientRect();
  780. const leftLabelFontSize = this.getFontSizeForElement(leftLabel);
  781. const rangeLabelOverlap = leftLabelBounds.right + leftLabelFontSize - rightLabelBounds.left;
  782. return Math.max(rangeLabelOverlap, 0);
  783. }
  784. /**
  785. * Returns a boolean value representing if the minLabel span element is obscured (being overlapped) by the given handle div element.
  786. * @param minLabel
  787. * @param handle
  788. */
  789. isMinTickLabelObscured(minLabel, handle) {
  790. const minLabelBounds = minLabel.getBoundingClientRect();
  791. const handleBounds = handle.getBoundingClientRect();
  792. return intersects(minLabelBounds, handleBounds);
  793. }
  794. /**
  795. * Returns a boolean value representing if the maxLabel span element is obscured (being overlapped) by the given handle div element.
  796. * @param maxLabel
  797. * @param handle
  798. */
  799. isMaxTickLabelObscured(maxLabel, handle) {
  800. const maxLabelBounds = maxLabel.getBoundingClientRect();
  801. const handleBounds = handle.getBoundingClientRect();
  802. return intersects(maxLabelBounds, handleBounds);
  803. }
  804. static get is() { return "calcite-slider"; }
  805. static get encapsulation() { return "shadow"; }
  806. static get originalStyleUrls() { return {
  807. "$": ["slider.scss"]
  808. }; }
  809. static get styleUrls() { return {
  810. "$": ["slider.css"]
  811. }; }
  812. static get properties() { return {
  813. "disabled": {
  814. "type": "boolean",
  815. "mutable": false,
  816. "complexType": {
  817. "original": "boolean",
  818. "resolved": "boolean",
  819. "references": {}
  820. },
  821. "required": false,
  822. "optional": false,
  823. "docs": {
  824. "tags": [],
  825. "text": "Disable and gray out the slider"
  826. },
  827. "attribute": "disabled",
  828. "reflect": true,
  829. "defaultValue": "false"
  830. },
  831. "hasHistogram": {
  832. "type": "boolean",
  833. "mutable": true,
  834. "complexType": {
  835. "original": "boolean",
  836. "resolved": "boolean",
  837. "references": {}
  838. },
  839. "required": false,
  840. "optional": false,
  841. "docs": {
  842. "tags": [],
  843. "text": "Indicates if a histogram is present"
  844. },
  845. "attribute": "has-histogram",
  846. "reflect": true,
  847. "defaultValue": "false"
  848. },
  849. "histogram": {
  850. "type": "unknown",
  851. "mutable": false,
  852. "complexType": {
  853. "original": "DataSeries",
  854. "resolved": "Point[]",
  855. "references": {
  856. "DataSeries": {
  857. "location": "import",
  858. "path": "../graph/interfaces"
  859. }
  860. }
  861. },
  862. "required": false,
  863. "optional": true,
  864. "docs": {
  865. "tags": [{
  866. "name": "see",
  867. "text": "[DataSeries](https://github.com/Esri/calcite-components/blob/master/src/components/graph/interfaces.ts#L5)"
  868. }],
  869. "text": "List of x,y coordinates within the slider's min and max, displays above the slider track."
  870. }
  871. },
  872. "histogramStops": {
  873. "type": "unknown",
  874. "mutable": false,
  875. "complexType": {
  876. "original": "ColorStop[]",
  877. "resolved": "ColorStop[]",
  878. "references": {
  879. "ColorStop": {
  880. "location": "import",
  881. "path": "../graph/interfaces"
  882. }
  883. }
  884. },
  885. "required": false,
  886. "optional": false,
  887. "docs": {
  888. "tags": [],
  889. "text": "Array of values describing a single color stop, sorted by offset ascending."
  890. }
  891. },
  892. "labelHandles": {
  893. "type": "boolean",
  894. "mutable": false,
  895. "complexType": {
  896. "original": "boolean",
  897. "resolved": "boolean",
  898. "references": {}
  899. },
  900. "required": false,
  901. "optional": false,
  902. "docs": {
  903. "tags": [],
  904. "text": "Label handles with their numeric value"
  905. },
  906. "attribute": "label-handles",
  907. "reflect": true,
  908. "defaultValue": "false"
  909. },
  910. "labelTicks": {
  911. "type": "boolean",
  912. "mutable": false,
  913. "complexType": {
  914. "original": "boolean",
  915. "resolved": "boolean",
  916. "references": {}
  917. },
  918. "required": false,
  919. "optional": false,
  920. "docs": {
  921. "tags": [],
  922. "text": "Label tick marks with their numeric value."
  923. },
  924. "attribute": "label-ticks",
  925. "reflect": true,
  926. "defaultValue": "false"
  927. },
  928. "max": {
  929. "type": "number",
  930. "mutable": false,
  931. "complexType": {
  932. "original": "number",
  933. "resolved": "number",
  934. "references": {}
  935. },
  936. "required": false,
  937. "optional": false,
  938. "docs": {
  939. "tags": [],
  940. "text": "Maximum selectable value"
  941. },
  942. "attribute": "max",
  943. "reflect": true,
  944. "defaultValue": "100"
  945. },
  946. "maxLabel": {
  947. "type": "string",
  948. "mutable": false,
  949. "complexType": {
  950. "original": "string",
  951. "resolved": "string",
  952. "references": {}
  953. },
  954. "required": false,
  955. "optional": true,
  956. "docs": {
  957. "tags": [],
  958. "text": "Used as an accessible label (aria-label) for second handle if needed (ex. \"Temperature, upper bound\")"
  959. },
  960. "attribute": "max-label",
  961. "reflect": false
  962. },
  963. "maxValue": {
  964. "type": "number",
  965. "mutable": true,
  966. "complexType": {
  967. "original": "number",
  968. "resolved": "number",
  969. "references": {}
  970. },
  971. "required": false,
  972. "optional": true,
  973. "docs": {
  974. "tags": [],
  975. "text": "Currently selected upper number (if multi-select)"
  976. },
  977. "attribute": "max-value",
  978. "reflect": false
  979. },
  980. "min": {
  981. "type": "number",
  982. "mutable": false,
  983. "complexType": {
  984. "original": "number",
  985. "resolved": "number",
  986. "references": {}
  987. },
  988. "required": false,
  989. "optional": false,
  990. "docs": {
  991. "tags": [],
  992. "text": "Minimum selectable value"
  993. },
  994. "attribute": "min",
  995. "reflect": true,
  996. "defaultValue": "0"
  997. },
  998. "minLabel": {
  999. "type": "string",
  1000. "mutable": false,
  1001. "complexType": {
  1002. "original": "string",
  1003. "resolved": "string",
  1004. "references": {}
  1005. },
  1006. "required": false,
  1007. "optional": false,
  1008. "docs": {
  1009. "tags": [],
  1010. "text": "Used as an accessible label (aria-label) for first (or only) handle (ex. \"Temperature, lower bound\")"
  1011. },
  1012. "attribute": "min-label",
  1013. "reflect": false
  1014. },
  1015. "minValue": {
  1016. "type": "number",
  1017. "mutable": true,
  1018. "complexType": {
  1019. "original": "number",
  1020. "resolved": "number",
  1021. "references": {}
  1022. },
  1023. "required": false,
  1024. "optional": true,
  1025. "docs": {
  1026. "tags": [],
  1027. "text": "Currently selected lower number (if multi-select)"
  1028. },
  1029. "attribute": "min-value",
  1030. "reflect": false
  1031. },
  1032. "mirrored": {
  1033. "type": "boolean",
  1034. "mutable": false,
  1035. "complexType": {
  1036. "original": "boolean",
  1037. "resolved": "boolean",
  1038. "references": {}
  1039. },
  1040. "required": false,
  1041. "optional": false,
  1042. "docs": {
  1043. "tags": [],
  1044. "text": "When true, the slider will display values from high to low.\n\nNote that this value will be ignored if the slider has an associated histogram."
  1045. },
  1046. "attribute": "mirrored",
  1047. "reflect": true,
  1048. "defaultValue": "false"
  1049. },
  1050. "name": {
  1051. "type": "string",
  1052. "mutable": false,
  1053. "complexType": {
  1054. "original": "string",
  1055. "resolved": "string",
  1056. "references": {}
  1057. },
  1058. "required": false,
  1059. "optional": false,
  1060. "docs": {
  1061. "tags": [],
  1062. "text": "The name of the slider"
  1063. },
  1064. "attribute": "name",
  1065. "reflect": true
  1066. },
  1067. "pageStep": {
  1068. "type": "number",
  1069. "mutable": false,
  1070. "complexType": {
  1071. "original": "number",
  1072. "resolved": "number",
  1073. "references": {}
  1074. },
  1075. "required": false,
  1076. "optional": true,
  1077. "docs": {
  1078. "tags": [],
  1079. "text": "Interval to move on page up/page down keys"
  1080. },
  1081. "attribute": "page-step",
  1082. "reflect": false
  1083. },
  1084. "precise": {
  1085. "type": "boolean",
  1086. "mutable": false,
  1087. "complexType": {
  1088. "original": "boolean",
  1089. "resolved": "boolean",
  1090. "references": {}
  1091. },
  1092. "required": false,
  1093. "optional": false,
  1094. "docs": {
  1095. "tags": [],
  1096. "text": "Use finer point for handles"
  1097. },
  1098. "attribute": "precise",
  1099. "reflect": false,
  1100. "defaultValue": "false"
  1101. },
  1102. "required": {
  1103. "type": "boolean",
  1104. "mutable": false,
  1105. "complexType": {
  1106. "original": "boolean",
  1107. "resolved": "boolean",
  1108. "references": {}
  1109. },
  1110. "required": false,
  1111. "optional": false,
  1112. "docs": {
  1113. "tags": [],
  1114. "text": "When true, makes the component required for form-submission."
  1115. },
  1116. "attribute": "required",
  1117. "reflect": true,
  1118. "defaultValue": "false"
  1119. },
  1120. "snap": {
  1121. "type": "boolean",
  1122. "mutable": false,
  1123. "complexType": {
  1124. "original": "boolean",
  1125. "resolved": "boolean",
  1126. "references": {}
  1127. },
  1128. "required": false,
  1129. "optional": false,
  1130. "docs": {
  1131. "tags": [],
  1132. "text": "When true, enables snap selection along the step interval"
  1133. },
  1134. "attribute": "snap",
  1135. "reflect": false,
  1136. "defaultValue": "false"
  1137. },
  1138. "step": {
  1139. "type": "number",
  1140. "mutable": false,
  1141. "complexType": {
  1142. "original": "number",
  1143. "resolved": "number",
  1144. "references": {}
  1145. },
  1146. "required": false,
  1147. "optional": true,
  1148. "docs": {
  1149. "tags": [],
  1150. "text": "Interval to move on up/down keys"
  1151. },
  1152. "attribute": "step",
  1153. "reflect": false,
  1154. "defaultValue": "1"
  1155. },
  1156. "ticks": {
  1157. "type": "number",
  1158. "mutable": false,
  1159. "complexType": {
  1160. "original": "number",
  1161. "resolved": "number",
  1162. "references": {}
  1163. },
  1164. "required": false,
  1165. "optional": true,
  1166. "docs": {
  1167. "tags": [],
  1168. "text": "Show tick marks on the number line at provided interval"
  1169. },
  1170. "attribute": "ticks",
  1171. "reflect": false
  1172. },
  1173. "value": {
  1174. "type": "number",
  1175. "mutable": true,
  1176. "complexType": {
  1177. "original": "null | number | number[]",
  1178. "resolved": "number | number[]",
  1179. "references": {}
  1180. },
  1181. "required": false,
  1182. "optional": false,
  1183. "docs": {
  1184. "tags": [],
  1185. "text": "Currently selected number (if single select)"
  1186. },
  1187. "attribute": "value",
  1188. "reflect": true,
  1189. "defaultValue": "0"
  1190. },
  1191. "scale": {
  1192. "type": "string",
  1193. "mutable": false,
  1194. "complexType": {
  1195. "original": "Scale",
  1196. "resolved": "\"l\" | \"m\" | \"s\"",
  1197. "references": {
  1198. "Scale": {
  1199. "location": "import",
  1200. "path": "../interfaces"
  1201. }
  1202. }
  1203. },
  1204. "required": false,
  1205. "optional": false,
  1206. "docs": {
  1207. "tags": [],
  1208. "text": "Specify the scale of the slider, defaults to m"
  1209. },
  1210. "attribute": "scale",
  1211. "reflect": false,
  1212. "defaultValue": "\"m\""
  1213. }
  1214. }; }
  1215. static get states() { return {
  1216. "activeProp": {},
  1217. "minMaxValueRange": {},
  1218. "minValueDragRange": {},
  1219. "maxValueDragRange": {},
  1220. "tickValues": {}
  1221. }; }
  1222. static get events() { return [{
  1223. "method": "calciteSliderInput",
  1224. "name": "calciteSliderInput",
  1225. "bubbles": true,
  1226. "cancelable": true,
  1227. "composed": true,
  1228. "docs": {
  1229. "tags": [],
  1230. "text": "Fires on all updates to the slider.\n:warning: Will be fired frequently during drag. If you are performing any\nexpensive operations consider using a debounce or throttle to avoid\nlocking up the main thread."
  1231. },
  1232. "complexType": {
  1233. "original": "any",
  1234. "resolved": "any",
  1235. "references": {}
  1236. }
  1237. }, {
  1238. "method": "calciteSliderChange",
  1239. "name": "calciteSliderChange",
  1240. "bubbles": true,
  1241. "cancelable": true,
  1242. "composed": true,
  1243. "docs": {
  1244. "tags": [],
  1245. "text": "Fires on when the thumb is released on slider\nIf you need to constantly listen to the drag event,\nplease use calciteSliderInput instead"
  1246. },
  1247. "complexType": {
  1248. "original": "any",
  1249. "resolved": "any",
  1250. "references": {}
  1251. }
  1252. }, {
  1253. "method": "calciteSliderUpdate",
  1254. "name": "calciteSliderUpdate",
  1255. "bubbles": true,
  1256. "cancelable": true,
  1257. "composed": true,
  1258. "docs": {
  1259. "tags": [{
  1260. "name": "deprecated",
  1261. "text": "use calciteSliderInput instead"
  1262. }],
  1263. "text": "Fires on all updates to the slider.\n:warning: Will be fired frequently during drag. If you are performing any\nexpensive operations consider using a debounce or throttle to avoid\nlocking up the main thread."
  1264. },
  1265. "complexType": {
  1266. "original": "any",
  1267. "resolved": "any",
  1268. "references": {}
  1269. }
  1270. }]; }
  1271. static get methods() { return {
  1272. "setFocus": {
  1273. "complexType": {
  1274. "signature": "() => Promise<void>",
  1275. "parameters": [],
  1276. "references": {
  1277. "Promise": {
  1278. "location": "global"
  1279. }
  1280. },
  1281. "return": "Promise<void>"
  1282. },
  1283. "docs": {
  1284. "text": "Sets focus on the component.",
  1285. "tags": []
  1286. }
  1287. }
  1288. }; }
  1289. static get elementRef() { return "el"; }
  1290. static get watchers() { return [{
  1291. "propName": "histogram",
  1292. "methodName": "histogramWatcher"
  1293. }, {
  1294. "propName": "value",
  1295. "methodName": "valueHandler"
  1296. }, {
  1297. "propName": "minValue",
  1298. "methodName": "minMaxValueHandler"
  1299. }, {
  1300. "propName": "maxValue",
  1301. "methodName": "minMaxValueHandler"
  1302. }]; }
  1303. static get listeners() { return [{
  1304. "name": "keydown",
  1305. "method": "keyDownHandler",
  1306. "target": undefined,
  1307. "capture": false,
  1308. "passive": false
  1309. }, {
  1310. "name": "click",
  1311. "method": "clickHandler",
  1312. "target": undefined,
  1313. "capture": false,
  1314. "passive": false
  1315. }, {
  1316. "name": "pointerdown",
  1317. "method": "pointerDownHandler",
  1318. "target": undefined,
  1319. "capture": false,
  1320. "passive": true
  1321. }]; }
  1322. }