/*! * All material copyright ESRI, All Rights Reserved, unless otherwise specified. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details. * v1.0.0-beta.97 */ import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client/index.js'; import { T as TEXT$1, b as getSlotted, i as isPrimaryPointerButton, s as setRequestedIcon, g as getElementProp, c as getElementDir, C as CSS_UTILITY } from './dom.js'; import { c as connectLabel, d as disconnectLabel, g as getLabelText } from './label2.js'; import { s as submitForm, c as connectForm, d as disconnectForm, H as HiddenFormInputSlot } from './form.js'; import { n as numberStringFormatter, i as isValidNumber, p as parseNumberString, s as sanitizeNumberString, a as defaultNumberingSystem, u as updateEffectiveLocale, c as connectLocalized, d as disconnectLocalized } from './locale.js'; import { n as numberKeys } from './key.js'; import { d as decimalPlaces } from './math.js'; import { c as createObserver } from './observers.js'; import { u as updateHostInteraction } from './interactive.js'; import { d as defineCustomElement$3 } from './icon.js'; import { d as defineCustomElement$2 } from './progress.js'; const CSS = { loader: "loader", clearButton: "clear-button", editingEnabled: "editing-enabled", inlineChild: "inline-child", inputIcon: "icon", prefix: "prefix", suffix: "suffix", numberButtonWrapper: "number-button-wrapper", buttonItemHorizontal: "number-button-item--horizontal", wrapper: "element-wrapper", inputWrapper: "wrapper", actionWrapper: "action-wrapper", resizeIconWrapper: "resize-icon-wrapper", numberButtonItem: "number-button-item" }; const SLOTS = { action: "action" }; const TEXT = { clear: "Clear value" }; const inputNumberCss = "@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host{display:block}:host([scale=s]) input,:host([scale=s]) .prefix,:host([scale=s]) .suffix{block-size:1.5rem;padding-inline:0.5rem;font-size:var(--calcite-font-size--2);line-height:1rem}:host([scale=s]) .number-button-wrapper,:host([scale=s]) .action-wrapper calcite-button,:host([scale=s]) .action-wrapper calcite-button button{block-size:1.5rem}:host([scale=s]) .clear-button{min-block-size:1.5rem;min-inline-size:1.5rem}:host([scale=m]) input,:host([scale=m]) .prefix,:host([scale=m]) .suffix{block-size:2rem;padding-inline:0.75rem;font-size:var(--calcite-font-size--1);line-height:1rem}:host([scale=m]) .number-button-wrapper,:host([scale=m]) .action-wrapper calcite-button,:host([scale=m]) .action-wrapper calcite-button button{block-size:2rem}:host([scale=m]) .clear-button{min-block-size:2rem;min-inline-size:2rem}:host([scale=l]) input,:host([scale=l]) .prefix,:host([scale=l]) .suffix{block-size:2.75rem;padding-inline:1rem;font-size:var(--calcite-font-size-0);line-height:1.25rem}:host([scale=l]) .number-button-wrapper,:host([scale=l]) .action-wrapper calcite-button,:host([scale=l]) .action-wrapper calcite-button button{block-size:2.75rem}:host([scale=l]) .clear-button{min-block-size:2.75rem;min-inline-size:2.75rem}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}:host input{transition:var(--calcite-animation-timing), block-size 0, outline-offset 0s;-webkit-appearance:none;position:relative;margin:0px;box-sizing:border-box;display:flex;max-block-size:100%;inline-size:100%;max-inline-size:100%;flex:1 1 0%;border-radius:0px;background-color:var(--calcite-ui-foreground-1);font-family:inherit;font-weight:var(--calcite-font-weight-normal);border-width:1px;border-style:solid;border-color:var(--calcite-ui-border-input);color:var(--calcite-ui-text-1)}:host input::placeholder,:host input:-ms-input-placeholder,:host input::-ms-input-placeholder{font-weight:var(--calcite-font-weight-normal);color:var(--calcite-ui-text-3)}:host input:focus{border-color:var(--calcite-ui-brand);color:var(--calcite-ui-text-1)}:host input[readonly]{background-color:var(--calcite-ui-background);font-weight:var(--calcite-font-weight-medium)}:host input[readonly]:focus{color:var(--calcite-ui-text-1)}:host calcite-icon{color:var(--calcite-ui-text-3)}:host input{outline-color:transparent}:host input:focus{outline:2px solid var(--calcite-ui-brand);outline-offset:-2px}:host([status=invalid]) input{border-color:var(--calcite-ui-danger)}:host([status=invalid]) input:focus{outline:2px solid var(--calcite-ui-danger);outline-offset:-2px}:host([scale=s]) .icon{inset-inline-start:0.5rem}:host([scale=m]) .icon{inset-inline-start:0.75rem}:host([scale=l]) .icon{inset-inline-start:1rem}:host([icon][scale=s]) input{padding-inline-start:2rem}:host([icon][scale=m]) input{padding-inline-start:2.5rem}:host([icon][scale=l]) input{padding-inline-start:3rem}.element-wrapper{position:relative;order:3;display:inline-flex;flex:1 1 0%;align-items:center}.icon{pointer-events:none;position:absolute;z-index:1;display:block;transition:all var(--calcite-animation-timing) ease-in-out 0s, outline 0s, outline-offset 0s}.clear-button{pointer-events:initial;order:4;margin:0px;box-sizing:border-box;display:flex;min-block-size:100%;cursor:pointer;align-items:center;justify-content:center;align-self:stretch;border-width:1px;border-style:solid;border-color:var(--calcite-ui-border-input);background-color:var(--calcite-ui-foreground-1);outline-color:transparent;border-inline-start-width:0px}.clear-button:hover{background-color:var(--calcite-ui-foreground-2);transition:all var(--calcite-animation-timing) ease-in-out 0s, outline 0s, outline-offset 0s}.clear-button:hover calcite-icon{color:var(--calcite-ui-text-1);transition:all var(--calcite-animation-timing) ease-in-out 0s, outline 0s, outline-offset 0s}.clear-button:active{background-color:var(--calcite-ui-foreground-3)}.clear-button:active calcite-icon{color:var(--calcite-ui-text-1)}.clear-button:focus{outline:2px solid var(--calcite-ui-brand);outline-offset:-2px}.clear-button:disabled{opacity:var(--calcite-ui-opacity-disabled)}.loader{inset-block-start:1px;inset-inline:1px;pointer-events:none;position:absolute;display:block}.action-wrapper{order:7;display:flex}.prefix,.suffix{box-sizing:border-box;display:flex;block-size:auto;min-block-size:100%;-webkit-user-select:none;user-select:none;align-content:center;align-items:center;overflow-wrap:break-word;border-width:1px;border-style:solid;border-color:var(--calcite-ui-border-input);background-color:var(--calcite-ui-background);font-weight:var(--calcite-font-weight-medium);line-height:1;color:var(--calcite-ui-text-2)}.prefix{order:2;border-inline-end-width:0px}.suffix{order:5;border-inline-start-width:0px}:host([alignment=start]) input{text-align:start}:host([alignment=end]) input{text-align:end}.number-button-wrapper{pointer-events:none;order:6;box-sizing:border-box;display:flex;flex-direction:column;transition:all var(--calcite-animation-timing) ease-in-out 0s, outline 0s, outline-offset 0s}:host([number-button-type=vertical]) .wrapper{flex-direction:row;display:flex}:host([number-button-type=vertical]) input{order:2}:host([number-button-type=horizontal]) .calcite--rtl .number-button-item[data-adjustment=down] calcite-icon{transform:rotate(-90deg)}:host([number-button-type=horizontal]) .calcite--rtl .number-button-item[data-adjustment=up] calcite-icon{transform:rotate(-90deg)}.number-button-item.number-button-item--horizontal[data-adjustment=down],.number-button-item.number-button-item--horizontal[data-adjustment=up]{order:1;max-block-size:100%;min-block-size:100%;align-self:stretch}.number-button-item.number-button-item--horizontal[data-adjustment=down] calcite-icon,.number-button-item.number-button-item--horizontal[data-adjustment=up] calcite-icon{transform:rotate(90deg)}.number-button-item.number-button-item--horizontal[data-adjustment=down]{border-width:1px;border-style:solid;border-color:var(--calcite-ui-border-input);border-inline-end-width:0px}.number-button-item.number-button-item--horizontal[data-adjustment=down]:hover{background-color:var(--calcite-ui-foreground-2)}.number-button-item.number-button-item--horizontal[data-adjustment=down]:hover calcite-icon{color:var(--calcite-ui-text-1)}.number-button-item.number-button-item--horizontal[data-adjustment=up]{order:5}.number-button-item.number-button-item--horizontal[data-adjustment=up]:hover{background-color:var(--calcite-ui-foreground-2)}.number-button-item.number-button-item--horizontal[data-adjustment=up]:hover calcite-icon{color:var(--calcite-ui-text-1)}:host([number-button-type=vertical]) .number-button-item[data-adjustment=down]:hover{background-color:var(--calcite-ui-foreground-2)}:host([number-button-type=vertical]) .number-button-item[data-adjustment=down]:hover calcite-icon{color:var(--calcite-ui-text-1)}:host([number-button-type=vertical]) .number-button-item[data-adjustment=up]:hover{background-color:var(--calcite-ui-foreground-2)}:host([number-button-type=vertical]) .number-button-item[data-adjustment=up]:hover calcite-icon{color:var(--calcite-ui-text-1)}:host([number-button-type=vertical]) .number-button-item[data-adjustment=down]{border-block-start-width:0px}.number-button-item{max-block-size:50%;min-block-size:50%;pointer-events:initial;margin:0px;box-sizing:border-box;display:flex;cursor:pointer;align-items:center;align-self:center;border-width:1px;border-style:solid;border-color:var(--calcite-ui-border-input);background-color:var(--calcite-ui-foreground-1);padding-block:0px;padding-inline:0.5rem;transition:all var(--calcite-animation-timing) ease-in-out 0s, outline 0s, outline-offset 0s;border-inline-start-width:0px}.number-button-item calcite-icon{pointer-events:none;transition:all var(--calcite-animation-timing) ease-in-out 0s, outline 0s, outline-offset 0s}.number-button-item:focus{background-color:var(--calcite-ui-foreground-2)}.number-button-item:focus calcite-icon{color:var(--calcite-ui-text-1)}.number-button-item:active{background-color:var(--calcite-ui-foreground-3)}.number-button-item:disabled{pointer-events:none}.wrapper{position:relative;display:flex;flex-direction:row;align-items:center}:host(.no-bottom-border) input{border-block-end-width:0px}:host(.border-top-color-one) input{border-block-start-color:var(--calcite-ui-border-1)}:host .inline-child{background-color:transparent;transition:all var(--calcite-animation-timing) ease-in-out 0s, outline 0s, outline-offset 0s}:host .inline-child .editing-enabled{background-color:inherit}:host .inline-child:not(.editing-enabled){display:flex;cursor:pointer;border-color:transparent;padding-inline-start:0}::slotted(input[slot=hidden-form-input]){margin:0 !important;opacity:0 !important;outline:none !important;padding:0 !important;position:absolute !important;inset:0 !important;transform:none !important;-webkit-appearance:none !important;z-index:-1 !important}"; const InputNumber = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement { constructor() { super(); this.__registerHost(); this.__attachShadow(); this.calciteInternalInputNumberFocus = createEvent(this, "calciteInternalInputNumberFocus", 6); this.calciteInternalInputNumberBlur = createEvent(this, "calciteInternalInputNumberBlur", 6); this.calciteInputNumberInput = createEvent(this, "calciteInputNumberInput", 7); this.calciteInputNumberChange = createEvent(this, "calciteInputNumberChange", 6); //-------------------------------------------------------------------------- // // Properties // //-------------------------------------------------------------------------- /** Specifies the text alignment of the component's value. */ this.alignment = "start"; /** * When `true`, the component is focused on page load. * * @mdn [autofocus](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus) */ this.autofocus = false; /** * When `true`, a clear button is displayed when the component has a value. */ this.clearable = false; /** * When `true`, interaction is prevented and the component is displayed with lower opacity. * * @mdn [disabled](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled) */ this.disabled = false; /** * When `true`, number values are displayed with a group separator corresponding to the language and country format. */ this.groupSeparator = false; /** * When `true`, the component will not be visible. * * @mdn [hidden](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/hidden) */ this.hidden = false; /** * Accessible name that will appear while loading. * * @default "Loading" */ this.intlLoading = TEXT$1.loading; /** When `true`, the icon will be flipped when the element direction is right-to-left (`"rtl"`). */ this.iconFlipRtl = false; /** When `true`, the component is in the loading state and `calcite-progress` is displayed. */ this.loading = false; /** * Toggles locale formatting for numbers. * * @internal */ this.localeFormat = false; /** Specifies the placement of the buttons. */ this.numberButtonType = "vertical"; /** * When `true`, the component's value can be read, but cannot be modified. * * @mdn [readOnly](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/readonly) */ this.readOnly = false; /** When `true`, the component must have a value in order for the form to submit. */ this.required = false; /** Specifies the size of the component. */ this.scale = "m"; /** Specifies the status of the input field, which determines message and icons. */ this.status = "idle"; /** * @internal */ this.editingEnabled = false; /** The component's value. */ this.value = ""; this.previousValueOrigin = "initial"; this.mutationObserver = createObserver("mutation", () => this.setDisabledAction()); this.userChangedValue = false; //-------------------------------------------------------------------------- // // State // //-------------------------------------------------------------------------- this.effectiveLocale = ""; //-------------------------------------------------------------------------- // // Private Methods // //-------------------------------------------------------------------------- this.keyDownHandler = (event) => { if (this.readOnly || this.disabled) { return; } if (this.isClearable && event.key === "Escape") { this.clearInputValue(event); event.preventDefault(); } if (event.key === "Enter" && !event.defaultPrevented) { if (submitForm(this)) { event.preventDefault(); } } }; this.clearInputValue = (nativeEvent) => { this.setNumberValue({ committing: true, nativeEvent, origin: "user", value: "" }); }; this.emitChangeIfUserModified = () => { if (this.previousValueOrigin === "user" && this.value !== this.previousEmittedValue) { this.calciteInputNumberChange.emit(); } this.previousEmittedValue = this.value; }; this.inputNumberBlurHandler = () => { this.calciteInternalInputNumberBlur.emit(); this.emitChangeIfUserModified(); }; this.inputNumberFocusHandler = (event) => { const slottedActionEl = getSlotted(this.el, "action"); if (event.target !== slottedActionEl) { this.setFocus(); } this.calciteInternalInputNumberFocus.emit(); }; this.inputNumberInputHandler = (nativeEvent) => { if (this.disabled || this.readOnly) { return; } const value = nativeEvent.target.value; numberStringFormatter.numberFormatOptions = { locale: this.effectiveLocale, numberingSystem: this.numberingSystem, useGrouping: this.groupSeparator }; const delocalizedValue = numberStringFormatter.delocalize(value); if (nativeEvent.inputType === "insertFromPaste") { if (!isValidNumber(delocalizedValue)) { nativeEvent.preventDefault(); } this.setNumberValue({ nativeEvent, origin: "user", value: parseNumberString(delocalizedValue) }); this.childNumberEl.value = this.localizedValue; } else { this.setNumberValue({ nativeEvent, origin: "user", value: delocalizedValue }); } }; this.inputNumberKeyDownHandler = (event) => { if (this.disabled || this.readOnly) { return; } if (event.key === "ArrowUp") { /* prevent default behavior of moving cursor to the beginning of the input when holding down ArrowUp */ event.preventDefault(); this.nudgeNumberValue("up", event); return; } if (event.key === "ArrowDown") { this.nudgeNumberValue("down", event); return; } const supportedKeys = [ ...numberKeys, "ArrowLeft", "ArrowRight", "Backspace", "Delete", "Enter", "Escape", "Tab" ]; if (event.altKey || event.ctrlKey || event.metaKey) { return; } const isShiftTabEvent = event.shiftKey && event.key === "Tab"; if (supportedKeys.includes(event.key) && (!event.shiftKey || isShiftTabEvent)) { if (event.key === "Enter") { this.emitChangeIfUserModified(); } return; } numberStringFormatter.numberFormatOptions = { locale: this.effectiveLocale, numberingSystem: this.numberingSystem, useGrouping: this.groupSeparator }; if (event.key === numberStringFormatter.decimal) { if (!this.value && !this.childNumberEl.value) { return; } if (this.value && this.childNumberEl.value.indexOf(numberStringFormatter.decimal) === -1) { return; } } if (/[eE]/.test(event.key)) { if (!this.value && !this.childNumberEl.value) { return; } if (this.value && !/[eE]/.test(this.childNumberEl.value)) { return; } } if (event.key === "-") { if (!this.value && !this.childNumberEl.value) { return; } if (this.value && this.childNumberEl.value.split("-").length <= 2) { return; } } event.preventDefault(); }; this.nudgeNumberValue = (direction, nativeEvent) => { if (nativeEvent instanceof KeyboardEvent && nativeEvent.repeat) { return; } const inputMax = this.maxString ? parseFloat(this.maxString) : null; const inputMin = this.minString ? parseFloat(this.minString) : null; const valueNudgeDelayInMs = 100; this.incrementOrDecrementNumberValue(direction, inputMax, inputMin, nativeEvent); if (this.nudgeNumberValueIntervalId) { window.clearInterval(this.nudgeNumberValueIntervalId); } let firstValueNudge = true; this.nudgeNumberValueIntervalId = window.setInterval(() => { if (firstValueNudge) { firstValueNudge = false; return; } this.incrementOrDecrementNumberValue(direction, inputMax, inputMin, nativeEvent); }, valueNudgeDelayInMs); }; this.nudgeButtonPointerUpAndOutHandler = (event) => { if (!isPrimaryPointerButton(event)) { return; } window.clearInterval(this.nudgeNumberValueIntervalId); }; this.nudgeButtonPointerDownHandler = (event) => { if (!isPrimaryPointerButton(event)) { return; } event.preventDefault(); const direction = event.target.dataset.adjustment; if (!this.disabled) { this.nudgeNumberValue(direction, event); } }; this.hiddenInputChangeHandler = (event) => { if (event.target.name === this.name) { this.setNumberValue({ value: event.target.value, origin: "direct" }); } event.stopPropagation(); }; this.setChildNumberElRef = (el) => { this.childNumberEl = el; }; this.setInputNumberValue = (newInputValue) => { if (!this.childNumberEl) { return; } this.childNumberEl.value = newInputValue; }; this.setPreviousEmittedNumberValue = (newPreviousEmittedValue) => { this.previousEmittedValue = isValidNumber(newPreviousEmittedValue) ? newPreviousEmittedValue : ""; }; this.setPreviousNumberValue = (newPreviousValue) => { this.previousValue = isValidNumber(newPreviousValue) ? newPreviousValue : ""; }; this.setNumberValue = ({ committing = false, nativeEvent, origin, previousValue, value }) => { numberStringFormatter.numberFormatOptions = { locale: this.effectiveLocale, numberingSystem: this.numberingSystem, useGrouping: this.groupSeparator }; const sanitizedValue = sanitizeNumberString((this.numberingSystem && this.numberingSystem !== "latn") || defaultNumberingSystem !== "latn" ? numberStringFormatter.delocalize(value) : value); const newValue = value && !sanitizedValue ? isValidNumber(this.previousValue) ? this.previousValue : "" : sanitizedValue; const newLocalizedValue = numberStringFormatter.localize(newValue); this.setPreviousNumberValue(previousValue || this.value); this.previousValueOrigin = origin; this.userChangedValue = origin === "user" && this.value !== newValue; this.value = newValue; this.localizedValue = newLocalizedValue; if (origin === "direct") { this.setInputNumberValue(newLocalizedValue); } if (nativeEvent) { const calciteInputNumberInputEvent = this.calciteInputNumberInput.emit({ element: this.childNumberEl, nativeEvent, value: this.value }); if (calciteInputNumberInputEvent.defaultPrevented) { const previousLocalizedValue = numberStringFormatter.localize(this.previousValue); this.value = this.previousValue; this.localizedValue = previousLocalizedValue; } else if (committing) { this.emitChangeIfUserModified(); } } }; this.inputNumberKeyUpHandler = () => { window.clearInterval(this.nudgeNumberValueIntervalId); }; } disabledWatcher() { this.setDisabledAction(); } localeChanged() { updateEffectiveLocale(this); } /** watcher to update number-to-string for max */ maxWatcher() { var _a; this.maxString = ((_a = this.max) === null || _a === void 0 ? void 0 : _a.toString()) || null; } /** watcher to update number-to-string for min */ minWatcher() { var _a; this.minString = ((_a = this.min) === null || _a === void 0 ? void 0 : _a.toString()) || null; } valueWatcher(newValue, previousValue) { if (!this.userChangedValue) { this.setNumberValue({ origin: "direct", previousValue, value: newValue == null || newValue == "" ? "" : isValidNumber(newValue) ? newValue : this.previousValue || "" }); this.warnAboutInvalidNumberValue(newValue); } this.userChangedValue = false; } updateRequestedIcon() { this.requestedIcon = setRequestedIcon({}, this.icon, "number"); } get isClearable() { return this.clearable && this.value.length > 0; } //-------------------------------------------------------------------------- // // Lifecycle // //-------------------------------------------------------------------------- connectedCallback() { var _a; connectLocalized(this); this.scale = getElementProp(this.el, "scale", this.scale); this.status = getElementProp(this.el, "status", this.status); this.inlineEditableEl = this.el.closest("calcite-inline-editable"); if (this.inlineEditableEl) { this.editingEnabled = this.inlineEditableEl.editingEnabled || false; } connectLabel(this); connectForm(this); this.setPreviousEmittedNumberValue(this.value); this.setPreviousNumberValue(this.value); this.warnAboutInvalidNumberValue(this.value); this.setNumberValue({ origin: "connected", value: isValidNumber(this.value) ? this.value : "" }); (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(this.el, { childList: true }); this.setDisabledAction(); this.el.addEventListener("calciteInternalHiddenInputChange", this.hiddenInputChangeHandler); } disconnectedCallback() { var _a; disconnectLabel(this); disconnectForm(this); disconnectLocalized(this); (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect(); this.el.removeEventListener("calciteInternalHiddenInputChange", this.hiddenInputChangeHandler); } componentWillLoad() { var _a, _b; this.maxString = (_a = this.max) === null || _a === void 0 ? void 0 : _a.toString(); this.minString = (_b = this.min) === null || _b === void 0 ? void 0 : _b.toString(); this.requestedIcon = setRequestedIcon({}, this.icon, "number"); } componentShouldUpdate(newValue, oldValue, property) { if (property === "value" && newValue && !isValidNumber(newValue)) { this.setNumberValue({ origin: "reset", value: oldValue }); return false; } return true; } componentDidRender() { updateHostInteraction(this); } //-------------------------------------------------------------------------- // // Public Methods // //-------------------------------------------------------------------------- /** Sets focus on the component. */ async setFocus() { var _a; (_a = this.childNumberEl) === null || _a === void 0 ? void 0 : _a.focus(); } /** Selects all text of the component's `value`. */ async selectText() { var _a; (_a = this.childNumberEl) === null || _a === void 0 ? void 0 : _a.select(); } onLabelClick() { this.setFocus(); } incrementOrDecrementNumberValue(direction, inputMax, inputMin, nativeEvent) { const { value } = this; const inputStep = this.step === "any" ? 1 : Math.abs(this.step || 1); const inputVal = value && value !== "" ? parseFloat(value) : 0; const adjustment = direction === "up" ? 1 : -1; const nudgedValue = inputVal + inputStep * adjustment; const finalValue = (typeof inputMin === "number" && !isNaN(inputMin) && nudgedValue < inputMin) || (typeof inputMax === "number" && !isNaN(inputMax) && nudgedValue > inputMax) ? inputVal : nudgedValue; const inputValPlaces = decimalPlaces(inputVal); const inputStepPlaces = decimalPlaces(inputStep); this.setNumberValue({ committing: true, nativeEvent, origin: "user", value: finalValue.toFixed(Math.max(inputValPlaces, inputStepPlaces)) }); } onFormReset() { this.setNumberValue({ origin: "reset", value: this.defaultValue }); } syncHiddenFormInput(input) { var _a, _b, _c, _d; input.type = "number"; input.min = (_b = (_a = this.min) === null || _a === void 0 ? void 0 : _a.toString(10)) !== null && _b !== void 0 ? _b : ""; input.max = (_d = (_c = this.max) === null || _c === void 0 ? void 0 : _c.toString(10)) !== null && _d !== void 0 ? _d : ""; } setDisabledAction() { const slottedActionEl = getSlotted(this.el, "action"); if (!slottedActionEl) { return; } this.disabled ? slottedActionEl.setAttribute("disabled", "") : slottedActionEl.removeAttribute("disabled"); } warnAboutInvalidNumberValue(value) { if (value && !isValidNumber(value)) { console.warn(`The specified value "${value}" cannot be parsed, or is out of range.`); } } // -------------------------------------------------------------------------- // // Render Methods // // -------------------------------------------------------------------------- render() { const dir = getElementDir(this.el); const loader = (h("div", { class: CSS.loader }, h("calcite-progress", { label: this.intlLoading, type: "indeterminate" }))); const inputClearButton = (h("button", { "aria-label": this.intlClear || TEXT.clear, class: CSS.clearButton, disabled: this.disabled || this.readOnly, onClick: this.clearInputValue, tabIndex: -1, type: "button" }, h("calcite-icon", { icon: "x", scale: "s" }))); const iconEl = (h("calcite-icon", { class: CSS.inputIcon, flipRtl: this.iconFlipRtl, icon: this.requestedIcon, scale: "s" })); const isHorizontalNumberButton = this.numberButtonType === "horizontal"; const numberButtonsHorizontalUp = (h("button", { "aria-hidden": "true", class: { [CSS.numberButtonItem]: true, [CSS.buttonItemHorizontal]: isHorizontalNumberButton }, "data-adjustment": "up", disabled: this.disabled || this.readOnly, onPointerDown: this.nudgeButtonPointerDownHandler, onPointerOut: this.nudgeButtonPointerUpAndOutHandler, onPointerUp: this.nudgeButtonPointerUpAndOutHandler, tabIndex: -1, type: "button" }, h("calcite-icon", { icon: "chevron-up", scale: "s" }))); const numberButtonsHorizontalDown = (h("button", { "aria-hidden": "true", class: { [CSS.numberButtonItem]: true, [CSS.buttonItemHorizontal]: isHorizontalNumberButton }, "data-adjustment": "down", disabled: this.disabled || this.readOnly, onPointerDown: this.nudgeButtonPointerDownHandler, onPointerOut: this.nudgeButtonPointerUpAndOutHandler, onPointerUp: this.nudgeButtonPointerUpAndOutHandler, tabIndex: -1, type: "button" }, h("calcite-icon", { icon: "chevron-down", scale: "s" }))); const numberButtonsVertical = (h("div", { class: CSS.numberButtonWrapper }, numberButtonsHorizontalUp, numberButtonsHorizontalDown)); const prefixText = h("div", { class: CSS.prefix }, this.prefixText); const suffixText = h("div", { class: CSS.suffix }, this.suffixText); const childEl = (h("input", { "aria-label": getLabelText(this), autofocus: this.autofocus ? true : null, defaultValue: this.defaultValue, disabled: this.disabled ? true : null, enterKeyHint: this.el.enterKeyHint, inputMode: this.el.inputMode, key: "localized-input", maxLength: this.maxLength, minLength: this.minLength, name: undefined, onBlur: this.inputNumberBlurHandler, onFocus: this.inputNumberFocusHandler, onInput: this.inputNumberInputHandler, onKeyDown: this.inputNumberKeyDownHandler, onKeyUp: this.inputNumberKeyUpHandler, placeholder: this.placeholder || "", readOnly: this.readOnly, ref: this.setChildNumberElRef, type: "text", value: this.localizedValue })); return (h(Host, { onClick: this.inputNumberFocusHandler, onKeyDown: this.keyDownHandler }, h("div", { class: { [CSS.inputWrapper]: true, [CSS_UTILITY.rtl]: dir === "rtl" } }, this.numberButtonType === "horizontal" && !this.readOnly ? numberButtonsHorizontalDown : null, this.prefixText ? prefixText : null, h("div", { class: CSS.wrapper }, childEl, this.isClearable ? inputClearButton : null, this.requestedIcon ? iconEl : null, this.loading ? loader : null), h("div", { class: CSS.actionWrapper }, h("slot", { name: SLOTS.action })), this.numberButtonType === "vertical" && !this.readOnly ? numberButtonsVertical : null, this.suffixText ? suffixText : null, this.numberButtonType === "horizontal" && !this.readOnly ? numberButtonsHorizontalUp : null, h(HiddenFormInputSlot, { component: this })))); } get el() { return this; } static get watchers() { return { "disabled": ["disabledWatcher"], "locale": ["localeChanged"], "max": ["maxWatcher"], "min": ["minWatcher"], "value": ["valueWatcher"], "icon": ["updateRequestedIcon"] }; } static get style() { return inputNumberCss; } }, [1, "calcite-input-number", { "alignment": [513], "autofocus": [516], "clearable": [516], "disabled": [516], "groupSeparator": [516, "group-separator"], "hidden": [516], "icon": [520], "intlClear": [1, "intl-clear"], "intlLoading": [1, "intl-loading"], "iconFlipRtl": [516, "icon-flip-rtl"], "label": [1], "loading": [516], "locale": [1], "numberingSystem": [513, "numbering-system"], "localeFormat": [4, "locale-format"], "max": [514], "min": [514], "maxLength": [514, "max-length"], "minLength": [514, "min-length"], "name": [513], "numberButtonType": [513, "number-button-type"], "placeholder": [1], "prefixText": [1, "prefix-text"], "readOnly": [516, "read-only"], "required": [516], "scale": [1537], "status": [1537], "step": [520], "suffixText": [1, "suffix-text"], "editingEnabled": [1540, "editing-enabled"], "value": [1025], "effectiveLocale": [32], "localizedValue": [32], "setFocus": [64], "selectText": [64] }]); function defineCustomElement$1() { if (typeof customElements === "undefined") { return; } const components = ["calcite-input-number", "calcite-icon", "calcite-progress"]; components.forEach(tagName => { switch (tagName) { case "calcite-input-number": if (!customElements.get(tagName)) { customElements.define(tagName, InputNumber); } break; case "calcite-icon": if (!customElements.get(tagName)) { defineCustomElement$3(); } break; case "calcite-progress": if (!customElements.get(tagName)) { defineCustomElement$2(); } break; } }); } defineCustomElement$1(); const CalciteInputNumber = InputNumber; const defineCustomElement = defineCustomElement$1; export { CalciteInputNumber, defineCustomElement };