chunk.TUY6S2OO.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. import {
  2. getLabelledBy,
  3. renderFormControl
  4. } from "./chunk.LLZCD55S.js";
  5. import {
  6. hasSlot
  7. } from "./chunk.FMCX45AD.js";
  8. import {
  9. l
  10. } from "./chunk.5MED2A3H.js";
  11. import {
  12. event,
  13. watch
  14. } from "./chunk.XX234VRK.js";
  15. import {
  16. e as e2
  17. } from "./chunk.YXKHB4AC.js";
  18. import {
  19. T,
  20. e,
  21. h,
  22. n,
  23. o,
  24. r,
  25. r2
  26. } from "./chunk.5PIDMFOE.js";
  27. import {
  28. __decorateClass
  29. } from "./chunk.IHGPZX35.js";
  30. // _uyihdawu1:/Users/claviska/Projects/shoelace/src/components/range/range.scss
  31. var range_default = ':host {\n position: relative;\n box-sizing: border-box;\n}\n:host *, :host *:before, :host *:after {\n box-sizing: inherit;\n}\n\n[hidden] {\n display: none !important;\n}\n\n.form-control .form-control__label {\n display: none;\n}\n.form-control .form-control__help-text {\n display: none;\n}\n\n.form-control--has-label .form-control__label {\n display: inline-block;\n color: var(--sl-input-label-color);\n margin-bottom: var(--sl-spacing-xxx-small);\n}\n.form-control--has-label.form-control--small .form-control__label {\n font-size: var(--sl-input-label-font-size-small);\n}\n.form-control--has-label.form-control--medium .form-control__label {\n font-size: var(--sl-input-label-font-size-medium);\n}\n.form-control--has-label.form-control--large .form-control_label {\n font-size: var(--sl-input-label-font-size-large);\n}\n\n.form-control--has-help-text .form-control__help-text {\n display: block;\n color: var(--sl-input-help-text-color);\n}\n.form-control--has-help-text .form-control__help-text ::slotted(*) {\n margin-top: var(--sl-spacing-xxx-small);\n}\n.form-control--has-help-text.form-control--small .form-control__help-text {\n font-size: var(--sl-input-help-text-font-size-small);\n}\n.form-control--has-help-text.form-control--medium .form-control__help-text {\n font-size: var(--sl-input-help-text-font-size-medium);\n}\n.form-control--has-help-text.form-control--large .form-control__help-text {\n font-size: var(--sl-input-help-text-font-size-large);\n}\n\n:host {\n --thumb-size: 20px;\n --tooltip-offset-y: 10px;\n --track-color: var(--sl-color-gray-200);\n --track-height: 6px;\n display: block;\n}\n\n.range {\n position: relative;\n}\n.range .range__control {\n -webkit-appearance: none;\n width: 100%;\n height: var(--sl-input-height-medium);\n background: transparent;\n line-height: var(--sl-input-height-medium);\n vertical-align: middle;\n}\n.range .range__control::-webkit-slider-runnable-track {\n width: 100%;\n height: var(--track-height);\n background-color: var(--track-color);\n border-radius: 3px;\n border: none;\n}\n.range .range__control::-webkit-slider-thumb {\n border: none;\n width: var(--thumb-size);\n height: var(--thumb-size);\n border-radius: 50%;\n background-color: var(--sl-color-primary-500);\n border: solid var(--sl-input-border-width) var(--sl-color-primary-500);\n -webkit-appearance: none;\n margin-top: calc(var(--thumb-size) / -2 + var(--track-height) / 2);\n transition: var(--sl-transition-fast) border-color, var(--sl-transition-fast) background-color, var(--sl-transition-fast) color, var(--sl-transition-fast) box-shadow, var(--sl-transition-fast) transform;\n cursor: pointer;\n}\n.range .range__control:not(:disabled)::-webkit-slider-thumb:hover {\n background-color: var(--sl-color-primary-400);\n border-color: var(--sl-color-primary-400);\n}\n.range .range__control:not(:disabled):focus::-webkit-slider-thumb {\n background-color: var(--sl-color-primary-400);\n border-color: var(--sl-color-primary-400);\n box-shadow: 0 0 0 var(--sl-focus-ring-width) var(--sl-focus-ring-color-primary);\n}\n.range .range__control:not(:disabled)::-webkit-slider-thumb:active {\n background-color: var(--sl-color-primary-500);\n border-color: var(--sl-color-primary-500);\n cursor: grabbing;\n}\n.range .range__control::-moz-focus-outer {\n border: 0;\n}\n.range .range__control::-moz-range-track {\n width: 100%;\n height: var(--track-height);\n background-color: var(--track-color);\n border-radius: 3px;\n border: none;\n}\n.range .range__control::-moz-range-thumb {\n border: none;\n height: var(--thumb-size);\n width: var(--thumb-size);\n border-radius: 50%;\n background-color: var(--sl-color-primary-500);\n border-color: var(--sl-color-primary-500);\n transition: var(--sl-transition-fast) border-color, var(--sl-transition-fast) background-color, var(--sl-transition-fast) color, var(--sl-transition-fast) box-shadow, var(--sl-transition-fast) transform;\n cursor: pointer;\n}\n.range .range__control:not(:disabled)::-moz-range-thumb:hover {\n background-color: var(--sl-color-primary-400);\n border-color: var(--sl-color-primary-400);\n}\n.range .range__control:not(:disabled):focus::-moz-range-thumb {\n background-color: var(--sl-color-primary-400);\n border-color: var(--sl-color-primary-400);\n box-shadow: 0 0 0 var(--sl-focus-ring-width) var(--sl-focus-ring-color-primary);\n}\n.range .range__control:not(:disabled)::-moz-range-thumb:active {\n background-color: var(--sl-color-primary-600);\n border-color: var(--sl-color-primary-600);\n cursor: grabbing;\n}\n.range .range__control:focus {\n outline: none;\n}\n.range .range__control:disabled {\n opacity: 0.5;\n}\n.range .range__control:disabled::-webkit-slider-thumb {\n cursor: not-allowed;\n}\n.range .range__control:disabled::-moz-range-thumb {\n cursor: not-allowed;\n}\n\n.range__tooltip {\n position: absolute;\n z-index: var(--sl-z-index-tooltip);\n left: 1px;\n border-radius: var(--sl-tooltip-border-radius);\n background-color: var(--sl-tooltip-background-color);\n font-family: var(--sl-tooltip-font-family);\n font-size: var(--sl-tooltip-font-size);\n font-weight: var(--sl-tooltip-font-weight);\n line-height: var(--sl-tooltip-line-height);\n color: var(--sl-tooltip-color);\n opacity: 0;\n padding: var(--sl-tooltip-padding);\n transition: var(--sl-transition-fast) opacity;\n pointer-events: none;\n}\n.range__tooltip:after {\n content: "";\n position: absolute;\n width: 0;\n height: 0;\n left: 50%;\n margin-left: calc(-1 * var(--sl-tooltip-arrow-size));\n}\n\n.range--tooltip-visible .range__tooltip {\n opacity: 1;\n}\n\n.range--tooltip-top .range__tooltip {\n top: calc(-1 * var(--thumb-size) - var(--tooltip-offset-y));\n}\n.range--tooltip-top .range__tooltip:after {\n border-top: var(--sl-tooltip-arrow-size) solid var(--sl-tooltip-background-color);\n border-left: var(--sl-tooltip-arrow-size) solid transparent;\n border-right: var(--sl-tooltip-arrow-size) solid transparent;\n top: 100%;\n}\n\n.range--tooltip-bottom .range__tooltip {\n bottom: calc(-1 * var(--thumb-size) - var(--tooltip-offset-y));\n}\n.range--tooltip-bottom .range__tooltip:after {\n border-bottom: var(--sl-tooltip-arrow-size) solid var(--sl-tooltip-background-color);\n border-left: var(--sl-tooltip-arrow-size) solid transparent;\n border-right: var(--sl-tooltip-arrow-size) solid transparent;\n bottom: 100%;\n}';
  32. // src/components/range/range.ts
  33. var id = 0;
  34. var SlRange = class extends h {
  35. constructor() {
  36. super(...arguments);
  37. this.inputId = `input-${++id}`;
  38. this.helpTextId = `input-help-text-${id}`;
  39. this.labelId = `input-label-${id}`;
  40. this.hasFocus = false;
  41. this.hasHelpTextSlot = false;
  42. this.hasLabelSlot = false;
  43. this.hasTooltip = false;
  44. this.name = "";
  45. this.value = 0;
  46. this.label = "";
  47. this.helpText = "";
  48. this.disabled = false;
  49. this.invalid = false;
  50. this.min = 0;
  51. this.max = 100;
  52. this.step = 1;
  53. this.tooltip = "top";
  54. this.tooltipFormatter = (value) => value.toString();
  55. }
  56. connectedCallback() {
  57. super.connectedCallback();
  58. this.handleSlotChange = this.handleSlotChange.bind(this);
  59. this.resizeObserver = new ResizeObserver(() => this.syncTooltip());
  60. this.shadowRoot.addEventListener("slotchange", this.handleSlotChange);
  61. if (this.value === void 0 || this.value === null)
  62. this.value = this.min;
  63. if (this.value < this.min)
  64. this.value = this.min;
  65. if (this.value > this.max)
  66. this.value = this.max;
  67. this.handleSlotChange();
  68. this.updateComplete.then(() => {
  69. this.syncTooltip();
  70. this.resizeObserver.observe(this.input);
  71. });
  72. }
  73. disconnectedCallback() {
  74. super.disconnectedCallback();
  75. this.resizeObserver.unobserve(this.input);
  76. this.shadowRoot.removeEventListener("slotchange", this.handleSlotChange);
  77. }
  78. focus(options) {
  79. this.input.focus(options);
  80. }
  81. blur() {
  82. this.input.blur();
  83. }
  84. setCustomValidity(message) {
  85. this.input.setCustomValidity(message);
  86. this.invalid = !this.input.checkValidity();
  87. }
  88. handleInput() {
  89. this.value = Number(this.input.value);
  90. this.slChange.emit();
  91. requestAnimationFrame(() => this.syncTooltip());
  92. }
  93. handleBlur() {
  94. this.hasFocus = false;
  95. this.hasTooltip = false;
  96. this.slBlur.emit();
  97. }
  98. handleFocus() {
  99. this.hasFocus = true;
  100. this.hasTooltip = true;
  101. this.slFocus.emit();
  102. }
  103. handleSlotChange() {
  104. this.hasHelpTextSlot = hasSlot(this, "help-text");
  105. this.hasLabelSlot = hasSlot(this, "label");
  106. }
  107. handleTouchStart() {
  108. this.focus();
  109. }
  110. syncTooltip() {
  111. if (this.tooltip !== "none") {
  112. const percent = Math.max(0, (this.value - this.min) / (this.max - this.min));
  113. const inputWidth = this.input.offsetWidth;
  114. const tooltipWidth = this.output.offsetWidth;
  115. const thumbSize = getComputedStyle(this.input).getPropertyValue("--thumb-size");
  116. const x = `calc(${inputWidth * percent}px - calc(calc(${percent} * ${thumbSize}) - calc(${thumbSize} / 2)))`;
  117. this.output.style.transform = `translateX(${x})`;
  118. this.output.style.marginLeft = `-${tooltipWidth / 2}px`;
  119. }
  120. }
  121. render() {
  122. return renderFormControl({
  123. inputId: this.inputId,
  124. label: this.label,
  125. labelId: this.labelId,
  126. hasLabelSlot: this.hasLabelSlot,
  127. helpTextId: this.helpTextId,
  128. helpText: this.helpText,
  129. hasHelpTextSlot: this.hasHelpTextSlot,
  130. size: "medium"
  131. }, T`
  132. <div
  133. part="base"
  134. class=${e2({
  135. range: true,
  136. "range--disabled": this.disabled,
  137. "range--focused": this.hasFocus,
  138. "range--tooltip-visible": this.hasTooltip,
  139. "range--tooltip-top": this.tooltip === "top",
  140. "range--tooltip-bottom": this.tooltip === "bottom"
  141. })}
  142. @touchstart=${this.handleTouchStart.bind(this)}
  143. >
  144. <input
  145. part="input"
  146. type="range"
  147. class="range__control"
  148. name=${l(this.name)}
  149. ?disabled=${this.disabled}
  150. min=${l(this.min)}
  151. max=${l(this.max)}
  152. step=${l(this.step)}
  153. .value=${String(this.value)}
  154. aria-labelledby=${l(getLabelledBy({
  155. label: this.label,
  156. labelId: this.labelId,
  157. hasLabelSlot: this.hasLabelSlot,
  158. helpText: this.helpText,
  159. helpTextId: this.helpTextId,
  160. hasHelpTextSlot: this.hasHelpTextSlot
  161. }))}
  162. @input=${this.handleInput.bind(this)}
  163. @focus=${this.handleFocus.bind(this)}
  164. @blur=${this.handleBlur.bind(this)}
  165. />
  166. ${this.tooltip !== "none" ? T` <output part="tooltip" class="range__tooltip"> ${this.tooltipFormatter(this.value)} </output> ` : ""}
  167. </div>
  168. `);
  169. }
  170. };
  171. SlRange.styles = r(range_default);
  172. __decorateClass([
  173. o(".range__control")
  174. ], SlRange.prototype, "input", 2);
  175. __decorateClass([
  176. o(".range__tooltip")
  177. ], SlRange.prototype, "output", 2);
  178. __decorateClass([
  179. r2()
  180. ], SlRange.prototype, "hasFocus", 2);
  181. __decorateClass([
  182. r2()
  183. ], SlRange.prototype, "hasHelpTextSlot", 2);
  184. __decorateClass([
  185. r2()
  186. ], SlRange.prototype, "hasLabelSlot", 2);
  187. __decorateClass([
  188. r2()
  189. ], SlRange.prototype, "hasTooltip", 2);
  190. __decorateClass([
  191. e()
  192. ], SlRange.prototype, "name", 2);
  193. __decorateClass([
  194. e({ type: Number })
  195. ], SlRange.prototype, "value", 2);
  196. __decorateClass([
  197. e()
  198. ], SlRange.prototype, "label", 2);
  199. __decorateClass([
  200. e({ attribute: "help-text" })
  201. ], SlRange.prototype, "helpText", 2);
  202. __decorateClass([
  203. e({ type: Boolean, reflect: true })
  204. ], SlRange.prototype, "disabled", 2);
  205. __decorateClass([
  206. e({ type: Boolean, reflect: true })
  207. ], SlRange.prototype, "invalid", 2);
  208. __decorateClass([
  209. e({ type: Number })
  210. ], SlRange.prototype, "min", 2);
  211. __decorateClass([
  212. e({ type: Number })
  213. ], SlRange.prototype, "max", 2);
  214. __decorateClass([
  215. e({ type: Number })
  216. ], SlRange.prototype, "step", 2);
  217. __decorateClass([
  218. e()
  219. ], SlRange.prototype, "tooltip", 2);
  220. __decorateClass([
  221. e()
  222. ], SlRange.prototype, "tooltipFormatter", 2);
  223. __decorateClass([
  224. event("sl-change")
  225. ], SlRange.prototype, "slChange", 2);
  226. __decorateClass([
  227. event("sl-blur")
  228. ], SlRange.prototype, "slBlur", 2);
  229. __decorateClass([
  230. event("sl-focus")
  231. ], SlRange.prototype, "slFocus", 2);
  232. __decorateClass([
  233. watch("label"),
  234. watch("helpText")
  235. ], SlRange.prototype, "handleSlotChange", 1);
  236. SlRange = __decorateClass([
  237. n("sl-range")
  238. ], SlRange);
  239. var range_default2 = SlRange;
  240. export {
  241. range_default2 as range_default
  242. };