100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
or-attribute-input added send button, helper text and additional attribute value type support (see #149)
Rich Turnerac6af82eff96
diff --git a/deployment/manager/shared/locales/en/or.json b/deployment/manager/shared/locales/en/or.jsonindex a30170e39..7f6940854 100644--- a/deployment/manager/shared/locales/en/or.json+++ b/deployment/manager/shared/locales/en/or.json@@ -84,6 +84,7 @@"cancel": "Cancel","createdOn": "Created on","createdOnWithDate": "Created on: {{-date, LLLL}}",+ "updatedWithDate": "Updated on: {{-date, LLLL}}","accessPublicRead": "Public read","type": "Type","path": "Path",@@ -216,6 +217,7 @@"port": "Port","host": "Hostname","errorOccurred": "An error has occurred",+ "sendFailed": "Send failed","managerError": {"MANAGER_FAILED_TO_LOAD": "Manager failed to load (see console logs)","AUTH_FAILED": "Auth failed to load (see console logs)",@@ -225,6 +227,8 @@"TRANSLATION_ERROR": "Translations error (see console logs)"},"couldNotRetrieveAttribute": "Could not retrieve attribute information",+ "pressEnterToSend": "Press Enter to send",+ "sending": "Sending","submit": "Submit","password": "Password","units": {diff --git a/ui/component/or-asset-viewer/src/index.ts b/ui/component/or-asset-viewer/src/index.tsindex f798dfad8..0af75d19c 100644--- a/ui/component/or-asset-viewer/src/index.ts+++ b/ui/component/or-asset-viewer/src/index.ts@@ -448,7 +448,7 @@ export function getAttributeTemplate(asset: Asset, attribute: AssetAttribute, ho}}return html`- <or-attribute-input dense .assetType="${asset!.type}" .attribute="${attribute}"}"></or-attribute-input>+ <or-attribute-input dense .assetType="${asset!.type}" .attribute="${attribute}" hasHelperText></or-attribute-input>`;}diff --git a/ui/component/or-attribute-input/src/index.ts b/ui/component/or-attribute-input/src/index.tsindex 927efd6f6..570774e71 100644--- a/ui/component/or-attribute-input/src/index.ts+++ b/ui/component/or-attribute-input/src/index.ts@@ -1,4 +1,4 @@-import {css, customElement, html, LitElement, property, PropertyValues, query, TemplateResult} from "lit-element";+import {css, customElement, unsafeCSS, html, LitElement, property, PropertyValues, query, TemplateResult} from "lit-element";import {i18next, translate} from "@openremote/or-translate";import {AssetAttribute,@@ -11,7 +11,7 @@ import {ValueType,SharedEvent} from "@openremote/model";-import manager, {AssetModelUtil, subscribe, Util} from "@openremote/core";+import manager, {AssetModelUtil, subscribe, Util, DefaultColor4} from "@openremote/core";import "@openremote/or-input";import {InputType, OrInput, OrInputChangedEvent} from "@openremote/or-input";import "@openremote/or-map";@@ -89,7 +89,7 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitEdisplay: inline-block;}- or-input {+ #wrapper > or-input {width: 100%;}@@ -98,13 +98,168 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitEposition: relative;}+ #wrapper.right-padding {+ padding-right: 48px;+ }++ #wrapper-helper {+ display: flex;+ flex: 1;+ }++ #wrapper-helper > or-input {+ flex: 1;+ margin-top: -15px;+ }++ #wrapper-helper-inner {+ margin-right: 20px;+ }++ /* Copy of mdc text field helper text styles */+ #helper-text {+ margin-top: 3px;+ color: rgba(0, 0, 0, 0.6);+ font-family: Roboto, sans-serif;+ -webkit-font-smoothing: antialiased;+ font-size: 0.75rem;+ font-weight: 400;+ letter-spacing: 0.0333333em;+ }+#scrim {position: absolute;left: 0;top: 0;right: 0;bottom: 0;- opacity: 0.5;+ background: transparent;+ display: flex;+ align-items: center;+ justify-content: center;+ }++ #send-btn {+ flex: 0;+ }++ /* https://codepen.io/finnhvman/pen/bmNdNr */+ .pure-material-progress-circular {+ -webkit-appearance: none;+ -moz-appearance: none;+ appearance: none;+ box-sizing: border-box;+ border: none;+ border-radius: 50%;+ padding: 0.25em;+ width: 3em;+ height: 3em;+ color: var(--or-app-color4, ${unsafeCSS(DefaultColor4)});+ background-color: transparent;+ font-size: 16px;+ overflow: hidden;+ }++ .pure-material-progress-circular::-webkit-progress-bar {+ background-color: transparent;+ }++ /* Indeterminate */+ .pure-material-progress-circular:indeterminate {+ -webkit-mask-image: linear-gradient(transparent 50%, black 50%), linear-gradient(to right, transparent 50%, black 50%);+ mask-image: linear-gradient(transparent 50%, black 50%), linear-gradient(to right, transparent 50%, black 50%);+ animation: pure-material-progress-circular 6s infinite cubic-bezier(0.3, 0.6, 1, 1);+ }++ :-ms-lang(x), .pure-material-progress-circular:indeterminate {+ animation: none;+ }++ .pure-material-progress-circular:indeterminate::before,+ .pure-material-progress-circular:indeterminate::-webkit-progress-value {+ content: "";+ display: block;+ box-sizing: border-box;+ margin-bottom: 0.25em;+ border: solid 0.25em transparent;+ border-top-color: currentColor;+ border-radius: 50%;+ width: 100% !important;+ height: 100%;+ background-color: transparent;+ animation: pure-material-progress-circular-pseudo 0.75s infinite linear alternate;+ }++ .pure-material-progress-circular:indeterminate::-moz-progress-bar {+ box-sizing: border-box;+ border: solid 0.25em transparent;+ border-top-color: currentColor;+ border-radius: 50%;+ width: 100%;+ height: 100%;+ background-color: transparent;+ animation: pure-material-progress-circular-pseudo 0.75s infinite linear alternate;+ }++ .pure-material-progress-circular:indeterminate::-ms-fill {+ animation-name: -ms-ring;+ }++ @keyframes pure-material-progress-circular {+ 0% {+ transform: rotate(0deg);+ }+ 12.5% {+ transform: rotate(180deg);+ animation-timing-function: linear;+ }+ 25% {+ transform: rotate(630deg);+ }+ 37.5% {+ transform: rotate(810deg);+ animation-timing-function: linear;+ }+ 50% {+ transform: rotate(1260deg);+ }+ 62.5% {+ transform: rotate(1440deg);+ animation-timing-function: linear;+ }+ 75% {+ transform: rotate(1890deg);+ }+ 87.5% {+ transform: rotate(2070deg);+ animation-timing-function: linear;+ }+ 100% {+ transform: rotate(2520deg);+ }+ }++ @keyframes pure-material-progress-circular-pseudo {+ 0% {+ transform: rotate(-30deg);+ }+ 29.4% {+ border-left-color: transparent;+ }+ 29.41% {+ border-left-color: currentColor;+ }+ 64.7% {+ border-bottom-color: transparent;+ }+ 64.71% {+ border-bottom-color: currentColor;+ }+ 100% {+ border-left-color: currentColor;+ border-bottom-color: currentColor;+ transform: rotate(225deg);+ }}`;}@@ -139,11 +294,19 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitE@property()public inputType?: InputType;+ @property({type: Boolean})+ public hasHelperText?: boolean;++ @property({type: Boolean})+ public disableButton?: boolean;+@property({type: Boolean})public disableSubscribe: boolean = false;- @query("#loading")- protected _orInput!: OrInput;+ @query("#input")+ protected _attrInput!: OrInput;+ @query("#send-btn")+ protected _sendButton!: OrInput;@property()protected _attributeEvent?: AttributeEvent;@@ -163,7 +326,11 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitEprotected _options?: any;protected _readonly?: boolean;protected _disabled?: boolean;- protected _valueFormatter?: (value: any) => any;+ protected _showButton?: boolean;+ protected _valueFormat?: string;+ protected _sendError = false;++ @property({attribute: false})protected _writeTimeoutHandler?: number;public disconnectedCallback() {@@ -271,12 +438,12 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitEthis._attributeDescriptor = AssetModelUtil.getAttributeDescriptorFromAsset(attrName, this.assetType);}- if (this.attributeValueDescriptor) {+ if (this.attribute) {+ this._attributeValueDescriptor = AssetModelUtil.getAttributeValueDescriptorFromAsset(this.attribute ? this.attribute.type as string : undefined, this.assetType, this._attributeDescriptor ? this._attributeDescriptor!.attributeName : undefined);+ } else if (this.attributeValueDescriptor) {this._attributeValueDescriptor = this.attributeValueDescriptor;} else if (this._attributeDescriptor) {this._attributeValueDescriptor = this._attributeDescriptor.valueDescriptor;- } else if (this.attribute) {- this._attributeValueDescriptor = AssetModelUtil.getAttributeValueDescriptorFromAsset(this.attribute ? this.attribute.type as string : undefined, this.assetType, this._attributeDescriptor ? this._attributeDescriptor!.attributeName : undefined);}this._updateTemplate();@@ -293,8 +460,9 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitEthis._options = undefined;this._disabled = undefined;this._readonly = undefined;+ this._showButton = undefined;this._inputType = undefined;- this._valueFormatter = undefined;+ this._valueFormat = undefined;if (this.customProvider) {this._template = this.customProvider(this.assetType, this.attribute, this._attributeDescriptor, this._attributeValueDescriptor, (v) => this._updateValue(v), this.readonly, this.disabled, this.label);@@ -311,23 +479,8 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitEcase AttributeValueType.GEO_JSON_POINT.name:this._template = GeoJsonPointInputTemplateProvider(this.assetType, this.attribute, this._attributeDescriptor, this._attributeValueDescriptor, (v) => this._updateValue(v), this.readonly, this.disabled, this.label);return;- case AttributeValueType.BOOLEAN.name:- case AttributeValueType.SWITCH_TOGGLE.name:- this._inputType = InputType.SWITCH;- break;- case AttributeValueType.NUMBER.name:- this._inputType = InputType.NUMBER;- break;- case AttributeValueType.STRING.name:- this._inputType = InputType.TEXT;- break;- case AttributeValueType.OBJECT.name:- case AttributeValueType.ARRAY.name:- this._inputType = InputType.JSON;- break;- case AttributeValueType.BRIGHTNESS.name:- this._inputType = InputType.NUMBER;- this._step = 1;+ case AttributeValueType.SWITCH_MOMENTARY.name:+ this._inputType = InputType.BUTTON_MOMENTARY;break;default:// Use value type@@ -368,7 +521,8 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitEif (this._inputType) {this._min = Util.getMetaValue(MetaItemType.RANGE_MIN, this.attribute, this._attributeDescriptor, this._attributeValueDescriptor) as number;this._max = Util.getMetaValue(MetaItemType.RANGE_MAX, this.attribute, this._attributeDescriptor, this._attributeValueDescriptor) as number;- this._unit = Util.getMetaValue(MetaItemType.UNIT_TYPE, this.attribute, this._attributeDescriptor, this._attributeValueDescriptor);+ this._unit = Util.getMetaValue(MetaItemType.UNIT_TYPE, this.attribute, this._attributeDescriptor, this._attributeValueDescriptor) as string;+ this._step = Util.getMetaValue(MetaItemType.STEP, this.attribute, this._attributeDescriptor, this._attributeValueDescriptor) as number;this._label = this.label !== undefined ? this.label : Util.getAttributeLabel(this.attribute, this._attributeDescriptor) + (this._unit ? " (" + i18next.t(this._unit) + ")" : "");this._readonly = this.readonly !== undefined ? this.readonly : Util.getMetaValue(MetaItemType.READ_ONLY, this.attribute, this._attributeDescriptor);this._disabled = this.disabled;@@ -378,48 +532,86 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitEthis._inputType = InputType.SELECT;}- switch (this._inputType) {- case InputType.NUMBER:- case InputType.TEXT:- case InputType.COLOUR:- case InputType.TELEPHONE:- this._valueFormatter = Util.getAttributeValueFormatter(this.attribute, this._attributeDescriptor, this._attributeValueDescriptor);+ if (!this.inputType && this._inputType === InputType.TEXT && Util.getMetaValue(MetaItemType.MULTILINE, this.attribute, this._attributeDescriptor, this._attributeValueDescriptor)) {+ this._inputType = InputType.TEXTAREA;}++ if (!this.inputType && this._inputType === InputType.NUMBER && this._min !== undefined && this._max) {+ this._inputType = InputType.RANGE;+ }++ this._valueFormat = Util.getAttributeValueFormat(this.attribute, this._attributeDescriptor, this._attributeValueDescriptor);+ this._showButton = !this.disableButton && this.inputTypeSupportsButton() && !!this._getAttributeRef();}}public render() {// Check if attribute hasn't been loaded yet or pending write- const loading = this.attributeRefs && !this._attributeEvent;+ const loading = (this.attributeRefs && !this._attributeEvent) || this._writeTimeoutHandler;let content: TemplateResult | string | undefined = "";- if (!loading) {- let value = this.getValue();+ const value = this.getValue();- if (this._template) {- content = this._template(value);- } else {+ if (this._template) {+ content = this._template(value);+ } else {- if (!this._inputType) {- content = html`<div>INVALID</div>`;- }+ if (!this._inputType) {+ content = html`<div><or-translate .value="attributeUnsupported"></or-translate></div>`;+ }- if (this._valueFormatter) {- value = this._valueFormatter(value);- }+ const helperText = this.getHelperText();+ const buttonIcon = this._writeTimeoutHandler ? "send-clock" : "send";+ let label = this._label;++ if (helperText && !this.inputTypeSupportsHelperText()) {+ label = undefined;+ }- content = html`<or-input id="input" .type="${this._inputType}" .label="${this._label}" .value="${value}" .allowedValues="${this._options}" .min="${this._min}" .max="${this._max}" .options="${this._options}" .readonly="${this._readonly}" .disabled="${this._disabled}" @or-input-changed="${(e: OrInputChangedEvent) => {- this._updateValue(e.detail.value);- e.stopPropagation()+ content = html`<or-input id="input" .type="${this._inputType}" .label="${label}" .value="${value}"+ .allowedValues="${this._options}" .min="${this._min}" .max="${this._max}" .format="${this._valueFormat}"+ .options="${this._options}" .readonly="${this._readonly}" .disabled="${this._disabled || loading}"+ .helperText="${helperText}" .helperPersistent="${true}"+ @keyup="${(e: KeyboardEvent) => {+ if (e.code === "Enter" && this._inputType !== InputType.JSON && this._inputType !== InputType.TEXTAREA) {+ this._updateValue(this._attrInput.value)+ }+ }}" @or-input-changed="${(e: OrInputChangedEvent) => {+ e.stopPropagation();+ if (!this._showButton) {+ this._updateValue(e.detail.value);+ }}}"></or-input>`;++ if (helperText && !this.inputTypeSupportsHelperText()) {+ // Manually provide helper text outside of or-input+ content = html`+ <div id="wrapper-helper">+ <div id="wrapper-helper-inner">+ <div>${this._label}</div>+ <div id="helper-text">${helperText}</div>+ </div>+ ${content}+ </div>+ `;+ }++ if (this._showButton) {+ content = html`+ ${content}+ <or-input id="send-btn" icon="${buttonIcon}" type="button" .disabled="${this._disabled || loading}" @or-input-changed="${(e: OrInputChangedEvent) => {+ e.stopPropagation();+ this._updateValue(this._attrInput.value);+ }}"></or-input>+ `;}}return html`- <div id="wrapper">+ <div id="wrapper" class="${this._showButton ? "" : "right-padding"}">${content}- ${loading || this._writeTimeoutHandler+ ${loading? html`<div id="scrim"><progress class="pure-material-progress-circular"></progress></div>`: ``}</div>@@ -430,6 +622,53 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitEreturn this._attributeEvent ? this._attributeEvent.attributeState!.value : this.attribute ? this.attribute.value : this.value;}+ protected getTimestamp(): number | undefined {+ return this._attributeEvent ? this._attributeEvent.timestamp : this.attribute ? this.attribute.valueTimestamp : undefined;+ }++ protected getHelperText(): string | undefined {+ if (!this.hasHelperText) {+ return;+ }++ if (this._writeTimeoutHandler) {+ return i18next.t("sending");+ }++ if (this._sendError) {+ return i18next.t("sendFailed");+ }++ const timestamp = this.getTimestamp();++ if (!timestamp) {+ return;+ }++ return i18next.t("updatedWithDate", { date: new Date(timestamp) });+ }++ protected inputTypeSupportsButton() {+ return this._inputType === InputType.NUMBER+ || this._inputType === InputType.TELEPHONE+ || this._inputType === InputType.TEXT+ || this._inputType === InputType.PASSWORD+ || this._inputType === InputType.DATE+ || this._inputType === InputType.DATETIME+ || this._inputType === InputType.EMAIL+ || this._inputType === InputType.JSON+ || this._inputType === InputType.MONTH+ || this._inputType === InputType.TEXTAREA+ || this._inputType === InputType.TIME+ || this._inputType === InputType.URL+ || this._inputType === InputType.WEEK;+ }++ protected inputTypeSupportsHelperText() {+ return this.inputTypeSupportsButton()+ || this._inputType === InputType.SELECT;+ }+/*** This is called by asset-mixin*/@@ -440,7 +679,6 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitEconst oldValue = this.getValue();this._attributeEvent = event as AttributeEvent;-this._onAttributeValueChanged(oldValue, this._attributeEvent.attributeState!.value, event.timestamp);}@@ -452,6 +690,7 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitEthis._clearWriteTimeout();this.value = newValue;+ this._sendError = false;this.dispatchEvent(new OrAttributeInputChangedEvent(newValue, oldValue));}@@ -491,6 +730,14 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitE}protected _onWriteTimeout() {- this._writeTimeoutHandler = undefined;+ this._sendError = true;+ if (!this.inputTypeSupportsButton()) {+ // Put the old value back+ this._attrInput.value = this.getValue();+ }+ if (this.hasHelperText) {+ this.requestUpdate();+ }+ this._clearWriteTimeout();}}diff --git a/ui/component/or-input/src/index.ts b/ui/component/or-input/src/index.tsindex dd763decb..e85c006d4 100644--- a/ui/component/or-input/src/index.ts+++ b/ui/component/or-input/src/index.ts@@ -6,13 +6,13 @@ import {MDCComponent} from "@material/base";import {MDCRipple} from "@material/ripple";import {MDCCheckbox} from "@material/checkbox";import {MDCSwitch} from "@material/switch";+import {MDCSlider} from "@material/slider";import {MDCSelect, MDCSelectEvent } from "@material/select";import {MDCList, MDCListActionEvent} from "@material/list";import {MDCFormField, MDCFormFieldInput} from "@material/form-field";import {MDCIconButtonToggle, MDCIconButtonToggleEventDetail} from "@material/icon-button";-import moment from "moment";-import {DefaultColor4, DefaultColor8} from "@openremote/core";+import {DefaultColor4, DefaultColor8, Util} from "@openremote/core";import i18next from "i18next";// TODO: Add webpack/rollup to build so consumers aren't forced to use the same tooling@@ -30,6 +30,7 @@ const selectStyle = require("!!raw-loader!@material/select/dist/mdc.select.css")const listStyle = require("!!raw-loader!@material/list/dist/mdc.list.css");const menuSurfaceStyle = require("!!raw-loader!@material/menu-surface/dist/mdc.menu-surface.css");const menuStyle = require("!!raw-loader!@material/menu/dist/mdc.menu.css");+const sliderStyle = require("!!raw-loader!@material/slider/dist/mdc.slider.css");export class OrInputChangedEvent extends CustomEvent<OrInputChangedEventDetail> {@@ -106,13 +107,14 @@ const style = css`height: 56px;}- #wrapper {+ #switch-wrapper {display: flex;align-items: center;- }+ height: 100%;+ }- #wrapper > label {- margin-left: 10px;+ #switch-wrapper > label {+ margin-right: 20px;}#component {@@ -190,6 +192,7 @@ const style = css`.mdc-icon-button {padding: 0;+ color: var(--internal-or-input-color);}#field {@@ -216,6 +219,7 @@ export class OrInput extends LitElement {css`${unsafeCSS(listStyle)}`,css`${unsafeCSS(menuStyle)}`,css`${unsafeCSS(menuSurfaceStyle)}`,+ css`${unsafeCSS(sliderStyle)}`,style];}@@ -308,6 +312,9 @@ export class OrInput extends LitElement {@property({type: Boolean})public rounded: boolean = false;+ @property({type: String})+ public format?: string;+/* BUTTON STYLES END *//* TEXT INPUT STYLES START */@@ -356,6 +363,10 @@ export class OrInput extends LitElement {const outlined = !this.fullWidth && this.outlined;const hasHelper = !!this.helperText;const showValidationMessage = this.validationMessage;+ const helperClasses = {+ "mdc-text-field-helper-text--persistent": this.helperPersistent,+ "mdc-text-field-helper-text--validation-msg": showValidationMessage,+ };const hasValue = this.value || this.value === false;const labelTemplate = showLabel ? html`<label class="mdc-floating-label ${hasValue ? "mdc-floating-label--float-above" : ""}" for="elem">${this.label}</label>` : ``;@@ -364,7 +375,8 @@ export class OrInput extends LitElement {return html`<span>RADIO</span>`;case InputType.SWITCH:return html`- <span id="wrapper">+ <span id="switch-wrapper">+ ${this.label ? html`<label for="elem" class="${this.disabled ? "mdc-switch--disabled" : ""}">${this.label}</label>` : ``}<div id="component" class="mdc-switch ${this.disabled || this.readonly ? "mdc-switch--disabled" : ""} ${this.value ? "mdc-switch--checked" : ""}"><div class="mdc-switch__track"></div><div class="mdc-switch__thumb-underlay">@@ -378,10 +390,9 @@ export class OrInput extends LitElement {</div></div></div>- <label for="elem">${this.label}</label></span>`;- case InputType.LIST:+ case InputType.LIST:const classesList = {"mdc-select--outlined": outlined,"mdc-select--disabled": this.disabled,@@ -390,11 +401,7 @@ export class OrInput extends LitElement {"mdc-select--no-label": !this.label,"mdc-select--with-leading-icon": !!this.icon};- const helperClassesList = {- "mdc-select-helper-text--persistent": this.helperPersistent,- "mdc-select-helper-text--validation-msg": showValidationMessage,- };-+let optsList: [string, string][] | undefined;if (this.options && this.options.length > 0) {if (Array.isArray(this.options[0])) {@@ -427,10 +434,6 @@ export class OrInput extends LitElement {"mdc-select--no-label": !this.label,"mdc-select--with-leading-icon": !!this.icon};- const helperClasses = {- "mdc-select-helper-text--persistent": this.helperPersistent,- "mdc-select-helper-text--validation-msg": showValidationMessage,- };let opts: [string, string][] | undefined;if (this.options && this.options.length > 0) {@@ -441,7 +444,7 @@ export class OrInput extends LitElement {}}const value = opts && opts.find(([optValue, optDisplay], index) => this.value === optValue);- const valueLabel = value ? value[1] : this.value;+ const valueLabel = value ? value[1] : typeof this.value === "string" ? this.value : "";this._selectedIndex = -1;return html`@@ -450,7 +453,7 @@ export class OrInput extends LitElement {@MDCSelect:change="${(e: MDCSelectEvent) => this.onValueChange(undefined, e.detail.index === -1 ? undefined : Array.isArray(this.options![e.detail.index]) ? this.options![e.detail.index][0] : this.options![e.detail.index])}"><div id="menu-anchor" class="mdc-select__anchor select-class"><or-icon class="mdc-select__dropdown-icon" icon="menu-down"></or-icon>- <input id="elem" readonly class="mdc-select__selected-text" role="button" value="${i18next.t(valueLabel)}" aria-haspopup="listbox" aria-controls="component-helper-text" aria-describedby="component-helper-text" aria-labelledby="component-label component"/>+ <input id="elem" readonly class="mdc-select__selected-text" role="button" value="${valueLabel ? i18next.t(valueLabel) : ""}" aria-haspopup="listbox" aria-controls="component-helper-text" aria-describedby="component-helper-text" aria-labelledby="component-label component"/>${outlined ? this.renderOutlined(labelTemplate) : labelTemplate}${!outlined ? html`<div class="mdc-line-ripple"></div>` : ``}</div>@@ -504,7 +507,7 @@ export class OrInput extends LitElement {<button id="component" class="${classMap(classes)}"?readonly="${this.readonly}"?disabled="${this.disabled}"- @onmousedown="${() => {if (isMomentary) this.onValueChange(undefined, true)}}" @onmouseup="${() => isMomentary ? this.onValueChange(undefined, false) : this.onValueChange(undefined, true)}">+ @mousedown="${() => {if (isMomentary) this.dispatchEvent(new OrInputChangedEvent(true, null))}}" @mouseup="${() => isMomentary ? this.dispatchEvent(new OrInputChangedEvent(false, true)) : this.dispatchEvent(new OrInputChangedEvent(true, null))}">${!isIconButton ? html`<div class="mdc-button__ripple"></div>` : ``}${this.icon ? html`<or-icon class="${isIconButton ? "" : this.action ? "mdc-fab__icon" : "mdc-button__icon"}" aria-hidden="true" icon="${this.icon}"></or-icon>` : ``}${this.label ? html`<span class="${this.action ? "mdc-fab__label" : "mdc-button__label"}">${this.label}</span>` : ``}@@ -547,50 +550,84 @@ export class OrInput extends LitElement {case InputType.TEXT:case InputType.TEXTAREA:case InputType.JSON: {- const valMinMax: [any, any, any] = [this.value, this.min, this.max];-- if (valMinMax.find((v) => v !== undefined && v !== null && typeof(v) !== "string") !== undefined) {-- let format: string | undefined;-- switch (this.type) {- case InputType.TIME:- format = "HH:mm";- break;- case InputType.DATE:- format = "YYYY-MM-DD";- break;- case InputType.WEEK:- format = "YYYY-[W]WW";- break;- case InputType.MONTH:- format = "YYYY-MM";- break;- case InputType.DATETIME:- format = "YYYY-MM-DDTHH:mm";- break;- case InputType.JSON:- valMinMax[0] = valMinMax[0] !== undefined && valMinMax[0] !== null ? (typeof valMinMax[0] === "string" ? valMinMax[0] : JSON.stringify(valMinMax[0], null, 2)) : "";- break;- default:- valMinMax[0] = valMinMax[0] !== undefined && valMinMax[0] !== null ? valMinMax[0] : "";- break;- }+ // The following HTML input types require the values as specially formatted strings+ const valMinMax: [any, any, any] = [this.value || "", this.min, this.max];++ if (valMinMax.some((v) => v !== undefined && v !== null && typeof (v) !== "string")) {++ if (this.type === InputType.JSON) {+ valMinMax[0] = valMinMax[0] !== undefined && valMinMax[0] !== null ? (typeof valMinMax[0] === "string" ? valMinMax[0] : JSON.stringify(valMinMax[0], null, 2)) : "";+ } else {+ let format: string | undefined;+ let requiresDate = false;++ switch (this.type) {+ case InputType.TIME:+ requiresDate = true;+ format = "HH:mm";+ break;+ case InputType.DATE:+ requiresDate = true;+ format = "YYYY-MM-DD";+ break;+ case InputType.WEEK:+ requiresDate = true;+ format = "YYYY-[W]WW";+ break;+ case InputType.MONTH:+ requiresDate = true;+ format = "YYYY-MM";+ break;+ case InputType.DATETIME:+ requiresDate = true;+ format = "YYYY-MM-DDTHH:mm";+ break;+ default:+ // Allow custom formats to be used for other input types+ format = this.format;+ }- if (format) {- valMinMax.forEach((val, i) => {- if (typeof(val) === "number") {- const offset = (new Date()).getTimezoneOffset() * 60000;- val = new Date(val - offset);- }- if (val instanceof Date) {- val = moment(val).format(format);- }- valMinMax[i] = val;- });+ if (format) {+ const formatter = Util.getAttributeValueFormatter();++ valMinMax.forEach((val, i) => {+ if (requiresDate) {+ if (typeof (val) === "number") {+ // Assume UNIX timestamp in ms+ const offset = (new Date()).getTimezoneOffset() * 60000;+ val = new Date(val - offset);+ }+ if (val) {+ val = formatter(val, format);+ }+ }+ valMinMax[i] = val;+ });+ }}}+ if (this.type === InputType.RANGE) {+ return html`+ <div id="component" class="mdc-slider mdc-slider--discrete" tabindex="0" role="slider"+ aria-valuemin="${ifDefined(valMinMax[1])}" aria-valuemax="${ifDefined(valMinMax[2])}"+ aria-valuenow="${ifDefined(valMinMax[0])}" aria-label="${ifDefined(this.label)}">+ <div class="mdc-slider__track-container">+ <div class="mdc-slider__track"></div>+ </div>+ <div class="mdc-slider__thumb-container">+ <div class="mdc-slider__pin">+ <span class="mdc-slider__pin-value-marker"></span>+ </div>+ <svg class="mdc-slider__thumb" width="21" height="21">+ <circle cx="10.5" cy="10.5" r="7.875"></circle>+ </svg>+ <div class="mdc-slider__focus-ring"></div>+ </div>+ </div>+ `;+ }+const classes = {"mdc-text-field--outlined": outlined,"mdc-text-field--textarea": this.type === InputType.TEXTAREA || this.type === InputType.JSON,@@ -601,15 +638,11 @@ export class OrInput extends LitElement {"mdc-text-field--with-leading-icon": !!this.icon,"mdc-text-field--with-trailing-icon": !!this.iconTrailing};- const helperClasses = {- "mdc-text-field-helper-text--persistent": this.helperPersistent,- "mdc-text-field-helper-text--validation-msg": showValidationMessage,- };return html`<div id="component" class="mdc-text-field ${classMap(classes)}">${this.icon ? html`<or-icon class="mdc-text-field__icon" aria-hidden="true" icon="${this.icon}"></or-icon>` : ``}- ${this.type === InputType.TEXTAREA || this.type === InputType.JSON ? html`+ ${this.type === InputType.TEXTAREA || this.type === InputType.JSON ? html`<textarea id="elem" class="mdc-text-field__input"?required="${this.required}"?readonly="${this.readonly}"@@ -622,7 +655,7 @@ export class OrInput extends LitElement {aria-label="${ifDefined(this.label)}">${valMinMax[0] ? valMinMax[0] : ""}</textarea>${this.renderOutlined(labelTemplate)}` :- html`<input type="${this.type}" id="elem" class="mdc-text-field__input"+ html`<input type="${this.type}" id="elem" class="mdc-text-field__input"?required="${this.required}"?readonly="${this.readonly}"?disabled="${this.disabled}"@@ -645,7 +678,7 @@ export class OrInput extends LitElement {<div class="mdc-text-field-helper-text ${classMap(helperClasses)}">${showValidationMessage ? this.validationMessage : this.helperText}</div>${this.charCounter && !this.readonly ? html`<div class="mdc-text-field-character-counter"></div>` : ``}</div>- ` : ``}+ ` : ``}`;}}@@ -706,6 +739,9 @@ export class OrInput extends LitElement {case InputType.SWITCH:this._mdcComponent = new MDCSwitch(component);break;+ case InputType.RANGE:+ this._mdcComponent = new MDCSlider(component);+ break;default:const textField = new MDCTextField(component);textField.useNativeValidation = false;