slider.js 54 KB

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