@limetech/lime-elements 37.0.0-dev.1 → 37.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  import { MDCSlider } from '@material/slider';
2
2
  import { h, Host, } from '@stencil/core';
3
3
  import { getPercentageClass } from './getPercentageClass';
4
+ import { createRandomString } from '../../util/random-string';
4
5
  /**
5
6
  * @exampleComponent limel-example-slider
6
7
  * @exampleComponent limel-example-slider-multiplier
@@ -30,6 +31,8 @@ export class Slider {
30
31
  this.percentageClass = undefined;
31
32
  this.inputHandler = this.inputHandler.bind(this);
32
33
  this.getContainerClassList = this.getContainerClassList.bind(this);
34
+ this.labelId = createRandomString();
35
+ this.helperTextId = createRandomString();
33
36
  }
34
37
  connectedCallback() {
35
38
  this.initialize();
@@ -100,17 +103,17 @@ export class Slider {
100
103
  if (this.disabled || this.readonly) {
101
104
  inputProps.disabled = true;
102
105
  }
103
- return (h(Host, { class: this.getContainerClassList() }, h("label", { class: "slider__label mdc-floating-label mdc-floating-label--float-above" }, this.label), h("div", { class: "slider__content-range-container" }, h("span", { class: "slider__content-min-label" }, this.multiplyByFactor(this.valuemin), this.unit), h("span", { class: "slider__content-max-label" }, this.multiplyByFactor(this.valuemax), this.unit)), h("div", { class: {
106
+ return (h(Host, { class: this.getContainerClassList() }, h("label", { class: "slider__label mdc-floating-label mdc-floating-label--float-above", id: this.labelId }, this.label), h("div", { class: "slider__content-range-container" }, h("span", { class: "slider__content-min-label" }, this.multiplyByFactor(this.valuemin), this.unit), h("span", { class: "slider__content-max-label" }, this.multiplyByFactor(this.valuemax), this.unit)), h("div", { class: {
104
107
  'mdc-slider': true,
105
108
  'mdc-slider--discrete': true,
106
109
  'mdc-slider--disabled': this.disabled || this.readonly,
107
- } }, h("input", Object.assign({ class: "mdc-slider__input", type: "range", min: this.multiplyByFactor(this.valuemin), max: this.multiplyByFactor(this.valuemax), value: this.multiplyByFactor(this.value), name: "volume", "aria-label": "Discrete slider demo" }, inputProps)), h("div", { class: "mdc-slider__track" }, h("div", { class: "mdc-slider__track--inactive" }), h("div", { class: "mdc-slider__track--active" }, h("div", { class: "mdc-slider__track--active_fill" }))), h("div", { class: "mdc-slider__thumb" }, h("div", { class: "mdc-slider__value-indicator-container", "aria-hidden": "true" }, h("div", { class: "mdc-slider__value-indicator" }, h("span", { class: "mdc-slider__value-indicator-text" }, this.multiplyByFactor(this.value)))), h("div", { class: "mdc-slider__thumb-knob" }))), this.renderHelperLine()));
110
+ } }, h("input", Object.assign({ class: "mdc-slider__input", type: "range", min: this.multiplyByFactor(this.valuemin), max: this.multiplyByFactor(this.valuemax), value: this.multiplyByFactor(this.value), name: "volume", "aria-labelledby": this.labelId, "aria-controls": this.helperTextId }, inputProps)), h("div", { class: "mdc-slider__track" }, h("div", { class: "mdc-slider__track--inactive" }), h("div", { class: "mdc-slider__track--active" }, h("div", { class: "mdc-slider__track--active_fill" }))), h("div", { class: "mdc-slider__thumb" }, h("div", { class: "mdc-slider__value-indicator-container", "aria-hidden": "true" }, h("div", { class: "mdc-slider__value-indicator" }, h("span", { class: "mdc-slider__value-indicator-text" }, this.multiplyByFactor(this.value)))), h("div", { class: "mdc-slider__thumb-knob" }))), this.renderHelperLine()));
108
111
  }
109
112
  renderHelperLine() {
110
113
  if (!this.helperText) {
111
114
  return;
112
115
  }
113
- return h("limel-helper-line", { helperText: this.helperText });
116
+ return (h("limel-helper-line", { helperText: this.helperText, helperTextId: this.helperTextId }));
114
117
  }
115
118
  watchDisabled() {
116
119
  this.updateDisabledState();
@@ -1 +1 @@
1
- {"version":3,"file":"slider.js","sourceRoot":"","sources":["../../../src/components/slider/slider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EACH,SAAS,EACT,OAAO,EACP,KAAK,EAEL,CAAC,EACD,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,KAAK,GACR,MA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACJ","sourcesContent":["import { MDCSlider } from '@material/slider';\nimport {\n Component,\n Element,\n Event,\n EventEmitter,\n h,\n Host,\n Prop,\n State,\n Watch,\n} from '@stencil/core';\nimport { getPercentageClass } from './getPercentageClass';\n/**\n * @exampleComponent limel-example-slider\n * @exampleComponent limel-example-slider-multiplier\n * @exampleComponent limel-example-slider-multiplier-percentage-colors\n * @exampleComponent limel-example-slider-composite\n */\n@Component({\n tag: 'limel-slider',\n shadow: true,\n styleUrl: 'slider.scss',\n})\nexport class Slider {\n /**\n * Disables the slider when `true`,\n * and visually shows that the field is editable but disabled.\n * This tells the users that if certain requirements are met,\n * the slider may become interactable.\n */\n @Prop({ reflect: true })\n public disabled = false;\n\n /**\n * Disables the slider when `true`. This visualizes the slider slightly differently.\n * But shows no visual sign indicating that the slider field\n * is disabled or can ever become interactable.\n */\n @Prop({ reflect: true })\n public readonly = false;\n\n /**\n * Default value: 1.\n * The factor that the properties `value`, `valuemax`, `valuemin`, and\n * `step` are multiplied by. On `change` divides the value by the factor,\n * so the original format stays the same.\n */\n @Prop({ reflect: true })\n public factor: number = 1;\n\n /**\n * Label to display next to the input\n */\n @Prop({ reflect: true })\n public label: string;\n\n /**\n * Optional helper text to display below the slider\n */\n @Prop({ reflect: true })\n public helperText: string;\n\n /**\n * Unit to display next to the value\n */\n @Prop({ reflect: true })\n public unit: string = '';\n\n /**\n * The value of the input\n */\n @Prop({ reflect: true })\n public value: number;\n\n /**\n * The maximum value allowed\n */\n @Prop({ reflect: true })\n public valuemax: number = 100; // eslint-disable-line no-magic-numbers\n\n /**\n * The minimum value allowed\n */\n @Prop({ reflect: true })\n public valuemin: number = 0;\n\n /**\n * The stepping interval to use when adjusting the value\n */\n @Prop({ reflect: true })\n public step: number;\n\n /**\n * Emitted when the value has been changed\n */\n @Event()\n private change: EventEmitter<number>;\n\n @Element()\n private rootElement: HTMLLimelSliderElement;\n\n private mdcSlider: MDCSlider;\n\n @State()\n private percentageClass: string;\n\n public constructor() {\n this.inputHandler = this.inputHandler.bind(this);\n this.getContainerClassList = this.getContainerClassList.bind(this);\n }\n\n public connectedCallback() {\n this.initialize();\n }\n\n public componentDidLoad() {\n this.initialize();\n }\n\n private initialize() {\n const inputElement = this.getInputElement();\n if (!inputElement) {\n return;\n }\n\n const value = this.getValue();\n\n /*\n For some reason the input element's `value` attribute is removed\n (probably by Stencil) when the element is first rendered. But if the\n attribute is missing when MDCSlider is initialized (MDC v11.0.0),\n MDCSlider crashes.\n So we add the attribute right before initializing MDCSlider. /Ads\n */\n inputElement.setAttribute('value', `${this.multiplyByFactor(value)}`);\n\n /*\n When creating the `mdcSlider` component, its important that the value set in\n the input field obeys the range and the step size.\n\n The MDCSlider will throw an exception unless the value in the input element\n is dividible by the step value and is in the provided range.\n If an exception occurs, this component will crash and it will be impossible to change\n its value.\n The logic below ensures that the component will render even though the\n provided value is wrong.\n This could be considered wrong, but it at least fixes so that it's possible\n to change the value from the UI.\n */\n const greaterThanOrEqualMin = value >= this.valuemin;\n const lessThanOrEqualMax = value <= this.valuemax;\n\n if (!greaterThanOrEqualMin) {\n const newMin = this.multiplyByFactor(value);\n inputElement.setAttribute('min', `${newMin}`);\n }\n\n if (!lessThanOrEqualMax) {\n const newMax = this.multiplyByFactor(value);\n inputElement.setAttribute('max', `${newMax}`);\n }\n\n if (!this.isMultipleOfStep(value, this.step)) {\n inputElement.removeAttribute('step');\n }\n\n this.createMDCSlider();\n }\n\n public componentWillLoad() {\n this.setPercentageClass(this.value);\n }\n\n public disconnectedCallback() {\n this.destroyMDCSlider();\n }\n\n private getContainerClassList() {\n return {\n [this.percentageClass]: true,\n disabled: this.disabled || this.readonly,\n readonly: this.readonly,\n };\n }\n\n public render() {\n const inputProps: any = {};\n if (this.step) {\n inputProps.step = this.multiplyByFactor(this.step);\n }\n\n if (this.disabled || this.readonly) {\n inputProps.disabled = true;\n }\n\n return (\n <Host class={this.getContainerClassList()}>\n <label class=\"slider__label mdc-floating-label mdc-floating-label--float-above\">\n {this.label}\n </label>\n <div class=\"slider__content-range-container\">\n <span class=\"slider__content-min-label\">\n {this.multiplyByFactor(this.valuemin)}\n {this.unit}\n </span>\n <span class=\"slider__content-max-label\">\n {this.multiplyByFactor(this.valuemax)}\n {this.unit}\n </span>\n </div>\n <div\n class={{\n 'mdc-slider': true,\n 'mdc-slider--discrete': true,\n 'mdc-slider--disabled': this.disabled || this.readonly,\n }}\n >\n <input\n class=\"mdc-slider__input\"\n type=\"range\"\n min={this.multiplyByFactor(this.valuemin)}\n max={this.multiplyByFactor(this.valuemax)}\n value={this.multiplyByFactor(this.value)}\n name=\"volume\"\n aria-label=\"Discrete slider demo\"\n {...inputProps}\n />\n <div class=\"mdc-slider__track\">\n <div class=\"mdc-slider__track--inactive\"></div>\n <div class=\"mdc-slider__track--active\">\n <div class=\"mdc-slider__track--active_fill\"></div>\n </div>\n </div>\n <div class=\"mdc-slider__thumb\">\n <div\n class=\"mdc-slider__value-indicator-container\"\n aria-hidden=\"true\"\n >\n <div class=\"mdc-slider__value-indicator\">\n <span class=\"mdc-slider__value-indicator-text\">\n {this.multiplyByFactor(this.value)}\n </span>\n </div>\n </div>\n <div class=\"mdc-slider__thumb-knob\"></div>\n </div>\n </div>\n {this.renderHelperLine()}\n </Host>\n );\n }\n\n private renderHelperLine() {\n if (!this.helperText) {\n return;\n }\n\n return <limel-helper-line helperText={this.helperText} />;\n }\n\n @Watch('disabled')\n protected watchDisabled() {\n this.updateDisabledState();\n }\n\n @Watch('readonly')\n protected watchReadonly() {\n this.updateDisabledState();\n }\n\n @Watch('value')\n protected watchValue() {\n if (!this.mdcSlider) {\n return;\n }\n\n const value = this.multiplyByFactor(this.getValue());\n this.mdcSlider.setValue(value);\n\n if (this.isStepConfigured()) {\n return;\n }\n\n const step = this.multiplyByFactor(this.step);\n if (!this.isMultipleOfStep(value, step)) {\n return;\n }\n\n this.reCreateSliderWithStep();\n }\n\n private updateDisabledState() {\n if (!this.mdcSlider) {\n return;\n }\n\n this.mdcSlider.setDisabled(this.disabled || this.readonly);\n }\n\n private changeHandler = (event) => {\n let value = event.detail.value;\n const step = this.multiplyByFactor(this.step);\n\n if (!this.isMultipleOfStep(value, step)) {\n value = this.roundToStep(value, step);\n }\n\n this.change.emit(value / this.factor);\n };\n\n private multiplyByFactor(value) {\n return Math.round(value * this.factor);\n }\n\n private getValue() {\n let value = this.value;\n if (!isFinite(value)) {\n value = this.valuemin;\n }\n\n return value;\n }\n\n private inputHandler(event) {\n this.setPercentageClass(event.detail.value / this.factor);\n }\n\n private setPercentageClass(value) {\n this.percentageClass = getPercentageClass(\n (value - this.valuemin) / (this.valuemax - this.valuemin)\n );\n }\n\n private isMultipleOfStep(value: number, step: number): boolean {\n if (!step) {\n return true;\n }\n\n return value % step === 0;\n }\n\n private roundToStep(value: number, step: number): number {\n return Math.round(value / step) * step;\n }\n\n private getRootElement(): HTMLElement | undefined {\n return this.rootElement.shadowRoot.querySelector('.mdc-slider');\n }\n\n private getInputElement(): HTMLInputElement | undefined {\n const element = this.getRootElement();\n if (!element) {\n return;\n }\n\n return element.querySelector('input');\n }\n\n private isStepConfigured(): boolean {\n if (!this.step) {\n return true;\n }\n\n const input = this.getInputElement();\n if (!input) {\n return true;\n }\n\n return input.hasAttribute('step');\n }\n\n private reCreateSliderWithStep() {\n const inputElement = this.getInputElement();\n const step = `${this.multiplyByFactor(this.step)}`;\n\n inputElement.setAttribute('step', step);\n\n this.destroyMDCSlider();\n this.createMDCSlider();\n }\n\n private createMDCSlider() {\n const element = this.getRootElement();\n\n this.mdcSlider = new MDCSlider(element);\n this.mdcSlider.listen('MDCSlider:change', this.changeHandler);\n this.mdcSlider.listen('MDCSlider:input', this.inputHandler);\n }\n\n private destroyMDCSlider() {\n this.mdcSlider.unlisten('MDCSlider:change', this.changeHandler);\n this.mdcSlider.unlisten('MDCSlider:input', this.inputHandler);\n this.mdcSlider.destroy();\n this.mdcSlider = undefined;\n }\n}\n"]}
1
+ {"version":3,"file":"slider.js","sourceRoot":"","sources":["../../../src/components/slider/slider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EACH,SAAS,EACT,OAAO,EACP,KAAK,EAEL,CAAC,EACD,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,KAAK,GACR,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D;;;;;GAKG;AAMH,MAAM,OAAO,MAAM;EAqFf;IA4MQ,kBAAa,GAAG,CAAC,KAAK,EAAE,EAAE;MAC9B,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC;MAC/B,MAAM,IAAI,GAAG,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;MAE9C,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE;QACrC,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;OACzC;MAED,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1C,CAAC,CAAC;oBAlSgB,KAAK;oBAQL,KAAK;kBASC,CAAC;;;gBAkBH,EAAE;;oBAYE,GAAG;oBAMH,CAAC;;;IAyBvB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjD,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,I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,CAAC;IAEtC,IAAI,CAAC,SAAS,GAAG,IAAI,SAAS,CAAC,OAAO,CAAC,CAAC;IACxC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,kBAAkB,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAC9D,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,iBAAiB,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;EAChE,CAAC;EAEO,gBAAgB;IACpB,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,kBAAkB,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAChE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAC9D,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;IACzB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;EAC/B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACJ","sourcesContent":["import { MDCSlider } from '@material/slider';\nimport {\n Component,\n Element,\n Event,\n EventEmitter,\n h,\n Host,\n Prop,\n State,\n Watch,\n} from '@stencil/core';\nimport { getPercentageClass } from './getPercentageClass';\nimport { createRandomString } from '../../util/random-string';\n\n/**\n * @exampleComponent limel-example-slider\n * @exampleComponent limel-example-slider-multiplier\n * @exampleComponent limel-example-slider-multiplier-percentage-colors\n * @exampleComponent limel-example-slider-composite\n */\n@Component({\n tag: 'limel-slider',\n shadow: true,\n styleUrl: 'slider.scss',\n})\nexport class Slider {\n /**\n * Disables the slider when `true`,\n * and visually shows that the field is editable but disabled.\n * This tells the users that if certain requirements are met,\n * the slider may become interactable.\n */\n @Prop({ reflect: true })\n public disabled = false;\n\n /**\n * Disables the slider when `true`. This visualizes the slider slightly differently.\n * But shows no visual sign indicating that the slider field\n * is disabled or can ever become interactable.\n */\n @Prop({ reflect: true })\n public readonly = false;\n\n /**\n * Default value: 1.\n * The factor that the properties `value`, `valuemax`, `valuemin`, and\n * `step` are multiplied by. On `change` divides the value by the factor,\n * so the original format stays the same.\n */\n @Prop({ reflect: true })\n public factor: number = 1;\n\n /**\n * Label to display next to the input\n */\n @Prop({ reflect: true })\n public label: string;\n\n /**\n * Optional helper text to display below the slider\n */\n @Prop({ reflect: true })\n public helperText: string;\n\n /**\n * Unit to display next to the value\n */\n @Prop({ reflect: true })\n public unit: string = '';\n\n /**\n * The value of the input\n */\n @Prop({ reflect: true })\n public value: number;\n\n /**\n * The maximum value allowed\n */\n @Prop({ reflect: true })\n public valuemax: number = 100; // eslint-disable-line no-magic-numbers\n\n /**\n * The minimum value allowed\n */\n @Prop({ reflect: true })\n public valuemin: number = 0;\n\n /**\n * The stepping interval to use when adjusting the value\n */\n @Prop({ reflect: true })\n public step: number;\n\n /**\n * Emitted when the value has been changed\n */\n @Event()\n private change: EventEmitter<number>;\n\n @Element()\n private rootElement: HTMLLimelSliderElement;\n\n private mdcSlider: MDCSlider;\n private labelId: string;\n private helperTextId: string;\n\n @State()\n private percentageClass: string;\n\n public constructor() {\n this.inputHandler = this.inputHandler.bind(this);\n this.getContainerClassList = this.getContainerClassList.bind(this);\n this.labelId = createRandomString();\n this.helperTextId = createRandomString();\n }\n\n public connectedCallback() {\n this.initialize();\n }\n\n public componentDidLoad() {\n this.initialize();\n }\n\n private initialize() {\n const inputElement = this.getInputElement();\n if (!inputElement) {\n return;\n }\n\n const value = this.getValue();\n\n /*\n For some reason the input element's `value` attribute is removed\n (probably by Stencil) when the element is first rendered. But if the\n attribute is missing when MDCSlider is initialized (MDC v11.0.0),\n MDCSlider crashes.\n So we add the attribute right before initializing MDCSlider. /Ads\n */\n inputElement.setAttribute('value', `${this.multiplyByFactor(value)}`);\n\n /*\n When creating the `mdcSlider` component, its important that the value set in\n the input field obeys the range and the step size.\n\n The MDCSlider will throw an exception unless the value in the input element\n is dividible by the step value and is in the provided range.\n If an exception occurs, this component will crash and it will be impossible to change\n its value.\n The logic below ensures that the component will render even though the\n provided value is wrong.\n This could be considered wrong, but it at least fixes so that it's possible\n to change the value from the UI.\n */\n const greaterThanOrEqualMin = value >= this.valuemin;\n const lessThanOrEqualMax = value <= this.valuemax;\n\n if (!greaterThanOrEqualMin) {\n const newMin = this.multiplyByFactor(value);\n inputElement.setAttribute('min', `${newMin}`);\n }\n\n if (!lessThanOrEqualMax) {\n const newMax = this.multiplyByFactor(value);\n inputElement.setAttribute('max', `${newMax}`);\n }\n\n if (!this.isMultipleOfStep(value, this.step)) {\n inputElement.removeAttribute('step');\n }\n\n this.createMDCSlider();\n }\n\n public componentWillLoad() {\n this.setPercentageClass(this.value);\n }\n\n public disconnectedCallback() {\n this.destroyMDCSlider();\n }\n\n private getContainerClassList() {\n return {\n [this.percentageClass]: true,\n disabled: this.disabled || this.readonly,\n readonly: this.readonly,\n };\n }\n\n public render() {\n const inputProps: any = {};\n if (this.step) {\n inputProps.step = this.multiplyByFactor(this.step);\n }\n\n if (this.disabled || this.readonly) {\n inputProps.disabled = true;\n }\n\n return (\n <Host class={this.getContainerClassList()}>\n <label\n class=\"slider__label mdc-floating-label mdc-floating-label--float-above\"\n id={this.labelId}\n >\n {this.label}\n </label>\n <div class=\"slider__content-range-container\">\n <span class=\"slider__content-min-label\">\n {this.multiplyByFactor(this.valuemin)}\n {this.unit}\n </span>\n <span class=\"slider__content-max-label\">\n {this.multiplyByFactor(this.valuemax)}\n {this.unit}\n </span>\n </div>\n <div\n class={{\n 'mdc-slider': true,\n 'mdc-slider--discrete': true,\n 'mdc-slider--disabled': this.disabled || this.readonly,\n }}\n >\n <input\n class=\"mdc-slider__input\"\n type=\"range\"\n min={this.multiplyByFactor(this.valuemin)}\n max={this.multiplyByFactor(this.valuemax)}\n value={this.multiplyByFactor(this.value)}\n name=\"volume\"\n aria-labelledby={this.labelId}\n aria-controls={this.helperTextId}\n {...inputProps}\n />\n <div class=\"mdc-slider__track\">\n <div class=\"mdc-slider__track--inactive\"></div>\n <div class=\"mdc-slider__track--active\">\n <div class=\"mdc-slider__track--active_fill\"></div>\n </div>\n </div>\n <div class=\"mdc-slider__thumb\">\n <div\n class=\"mdc-slider__value-indicator-container\"\n aria-hidden=\"true\"\n >\n <div class=\"mdc-slider__value-indicator\">\n <span class=\"mdc-slider__value-indicator-text\">\n {this.multiplyByFactor(this.value)}\n </span>\n </div>\n </div>\n <div class=\"mdc-slider__thumb-knob\"></div>\n </div>\n </div>\n {this.renderHelperLine()}\n </Host>\n );\n }\n\n private renderHelperLine() {\n if (!this.helperText) {\n return;\n }\n\n return (\n <limel-helper-line\n helperText={this.helperText}\n helperTextId={this.helperTextId}\n />\n );\n }\n\n @Watch('disabled')\n protected watchDisabled() {\n this.updateDisabledState();\n }\n\n @Watch('readonly')\n protected watchReadonly() {\n this.updateDisabledState();\n }\n\n @Watch('value')\n protected watchValue() {\n if (!this.mdcSlider) {\n return;\n }\n\n const value = this.multiplyByFactor(this.getValue());\n this.mdcSlider.setValue(value);\n\n if (this.isStepConfigured()) {\n return;\n }\n\n const step = this.multiplyByFactor(this.step);\n if (!this.isMultipleOfStep(value, step)) {\n return;\n }\n\n this.reCreateSliderWithStep();\n }\n\n private updateDisabledState() {\n if (!this.mdcSlider) {\n return;\n }\n\n this.mdcSlider.setDisabled(this.disabled || this.readonly);\n }\n\n private changeHandler = (event) => {\n let value = event.detail.value;\n const step = this.multiplyByFactor(this.step);\n\n if (!this.isMultipleOfStep(value, step)) {\n value = this.roundToStep(value, step);\n }\n\n this.change.emit(value / this.factor);\n };\n\n private multiplyByFactor(value) {\n return Math.round(value * this.factor);\n }\n\n private getValue() {\n let value = this.value;\n if (!isFinite(value)) {\n value = this.valuemin;\n }\n\n return value;\n }\n\n private inputHandler(event) {\n this.setPercentageClass(event.detail.value / this.factor);\n }\n\n private setPercentageClass(value) {\n this.percentageClass = getPercentageClass(\n (value - this.valuemin) / (this.valuemax - this.valuemin)\n );\n }\n\n private isMultipleOfStep(value: number, step: number): boolean {\n if (!step) {\n return true;\n }\n\n return value % step === 0;\n }\n\n private roundToStep(value: number, step: number): number {\n return Math.round(value / step) * step;\n }\n\n private getRootElement(): HTMLElement | undefined {\n return this.rootElement.shadowRoot.querySelector('.mdc-slider');\n }\n\n private getInputElement(): HTMLInputElement | undefined {\n const element = this.getRootElement();\n if (!element) {\n return;\n }\n\n return element.querySelector('input');\n }\n\n private isStepConfigured(): boolean {\n if (!this.step) {\n return true;\n }\n\n const input = this.getInputElement();\n if (!input) {\n return true;\n }\n\n return input.hasAttribute('step');\n }\n\n private reCreateSliderWithStep() {\n const inputElement = this.getInputElement();\n const step = `${this.multiplyByFactor(this.step)}`;\n\n inputElement.setAttribute('step', step);\n\n this.destroyMDCSlider();\n this.createMDCSlider();\n }\n\n private createMDCSlider() {\n const element = this.getRootElement();\n\n this.mdcSlider = new MDCSlider(element);\n this.mdcSlider.listen('MDCSlider:change', this.changeHandler);\n this.mdcSlider.listen('MDCSlider:input', this.inputHandler);\n }\n\n private destroyMDCSlider() {\n this.mdcSlider.unlisten('MDCSlider:change', this.changeHandler);\n this.mdcSlider.unlisten('MDCSlider:input', this.inputHandler);\n this.mdcSlider.destroy();\n this.mdcSlider = undefined;\n }\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-9bd6d7c6.js';
2
+ import { c as createRandomString } from './random-string-2246b81e.js';
2
3
  import { M as MDCFoundation, a as MDCComponent } from './component-410aad5a.js';
3
4
  import { M as MDCRipple, a as applyPassive, b as MDCRippleFoundation } from './component-5b4ac85a.js';
4
5
  import { m as matches } from './ponyfill-30263d5e.js';
@@ -1442,6 +1443,8 @@ const Slider = class {
1442
1443
  this.percentageClass = undefined;
1443
1444
  this.inputHandler = this.inputHandler.bind(this);
1444
1445
  this.getContainerClassList = this.getContainerClassList.bind(this);
1446
+ this.labelId = createRandomString();
1447
+ this.helperTextId = createRandomString();
1445
1448
  }
1446
1449
  connectedCallback() {
1447
1450
  this.initialize();
@@ -1512,17 +1515,17 @@ const Slider = class {
1512
1515
  if (this.disabled || this.readonly) {
1513
1516
  inputProps.disabled = true;
1514
1517
  }
1515
- return (h(Host, { class: this.getContainerClassList() }, h("label", { class: "slider__label mdc-floating-label mdc-floating-label--float-above" }, this.label), h("div", { class: "slider__content-range-container" }, h("span", { class: "slider__content-min-label" }, this.multiplyByFactor(this.valuemin), this.unit), h("span", { class: "slider__content-max-label" }, this.multiplyByFactor(this.valuemax), this.unit)), h("div", { class: {
1518
+ return (h(Host, { class: this.getContainerClassList() }, h("label", { class: "slider__label mdc-floating-label mdc-floating-label--float-above", id: this.labelId }, this.label), h("div", { class: "slider__content-range-container" }, h("span", { class: "slider__content-min-label" }, this.multiplyByFactor(this.valuemin), this.unit), h("span", { class: "slider__content-max-label" }, this.multiplyByFactor(this.valuemax), this.unit)), h("div", { class: {
1516
1519
  'mdc-slider': true,
1517
1520
  'mdc-slider--discrete': true,
1518
1521
  'mdc-slider--disabled': this.disabled || this.readonly,
1519
- } }, h("input", Object.assign({ class: "mdc-slider__input", type: "range", min: this.multiplyByFactor(this.valuemin), max: this.multiplyByFactor(this.valuemax), value: this.multiplyByFactor(this.value), name: "volume", "aria-label": "Discrete slider demo" }, inputProps)), h("div", { class: "mdc-slider__track" }, h("div", { class: "mdc-slider__track--inactive" }), h("div", { class: "mdc-slider__track--active" }, h("div", { class: "mdc-slider__track--active_fill" }))), h("div", { class: "mdc-slider__thumb" }, h("div", { class: "mdc-slider__value-indicator-container", "aria-hidden": "true" }, h("div", { class: "mdc-slider__value-indicator" }, h("span", { class: "mdc-slider__value-indicator-text" }, this.multiplyByFactor(this.value)))), h("div", { class: "mdc-slider__thumb-knob" }))), this.renderHelperLine()));
1522
+ } }, h("input", Object.assign({ class: "mdc-slider__input", type: "range", min: this.multiplyByFactor(this.valuemin), max: this.multiplyByFactor(this.valuemax), value: this.multiplyByFactor(this.value), name: "volume", "aria-labelledby": this.labelId, "aria-controls": this.helperTextId }, inputProps)), h("div", { class: "mdc-slider__track" }, h("div", { class: "mdc-slider__track--inactive" }), h("div", { class: "mdc-slider__track--active" }, h("div", { class: "mdc-slider__track--active_fill" }))), h("div", { class: "mdc-slider__thumb" }, h("div", { class: "mdc-slider__value-indicator-container", "aria-hidden": "true" }, h("div", { class: "mdc-slider__value-indicator" }, h("span", { class: "mdc-slider__value-indicator-text" }, this.multiplyByFactor(this.value)))), h("div", { class: "mdc-slider__thumb-knob" }))), this.renderHelperLine()));
1520
1523
  }
1521
1524
  renderHelperLine() {
1522
1525
  if (!this.helperText) {
1523
1526
  return;
1524
1527
  }
1525
- return h("limel-helper-line", { helperText: this.helperText });
1528
+ return (h("limel-helper-line", { helperText: this.helperText, helperTextId: this.helperTextId }));
1526
1529
  }
1527
1530
  watchDisabled() {
1528
1531
  this.updateDisabledState();