UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

124 lines (123 loc) • 4.75 kB
/** * DevExtreme (esm/__internal/ui/number_box/number_box.spins.js) * Version: 26.1.6 * Build date: Fri Oct 16 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ import eventsEngine from "../../../common/core/events/core/events_engine"; import pointer from "../../../common/core/events/pointer"; import { addNamespace } from "../../../common/core/events/utils/index"; import $ from "../../../core/renderer"; import TextEditorButton from "../../ui/text_box/texteditor_button_collection/button"; import SpinButton from "./number_box.spin"; const SPIN_CLASS = "dx-numberbox-spin"; const SPIN_CONTAINER_CLASS = "dx-numberbox-spin-container"; const SPIN_TOUCH_FRIENDLY_CLASS = "dx-numberbox-spin-touch-friendly"; export default class SpinButtons extends TextEditorButton { _attachEvents(instance, $spinContainer) { const { editor: editor } = this; if (!editor) { return } const eventName = addNamespace(pointer.down, editor.NAME ?? ""); const $spinContainerChildren = $spinContainer.children(); const pointerDownAction = editor._createAction(() => { var _this$editor; null === (_this$editor = this.editor) || void 0 === _this$editor || _this$editor._spinButtonsPointerDownHandler() }); eventsEngine.off($spinContainer, eventName); eventsEngine.on($spinContainer, eventName, e => pointerDownAction({ event: e })); SpinButton.getInstance($spinContainerChildren.eq(0)).option("onChange", e => { var _this$editor2; null === (_this$editor2 = this.editor) || void 0 === _this$editor2 || _this$editor2._spinUpChangeHandler(e) }); SpinButton.getInstance($spinContainerChildren.eq(1)).option("onChange", e => { var _this$editor3; null === (_this$editor3 = this.editor) || void 0 === _this$editor3 || _this$editor3._spinDownChangeHandler(e) }) } _create() { const { editor: editor } = this; if (!editor) { return } const $spinContainer = $("<div>").addClass(SPIN_CONTAINER_CLASS); const $spinUp = $("<div>").appendTo($spinContainer); const $spinDown = $("<div>").appendTo($spinContainer); const options = this._getOptions(); this._addToContainer($spinContainer); editor._createComponent($spinUp, SpinButton, Object.assign({ direction: "up" }, options)); editor._createComponent($spinDown, SpinButton, Object.assign({ direction: "down" }, options)); this._legacyRender(editor.$element(), this._isTouchFriendly(), options.visible); return { instance: $spinContainer, $element: $spinContainer } } _getOptions() { const { editor: editor } = this; const { disabled: disabled } = (null === editor || void 0 === editor ? void 0 : editor.option()) ?? {}; return { visible: this._isVisible(), disabled: !!disabled } } _isVisible() { const { editor: editor } = this; const { showSpinButtons: showSpinButtons } = (null === editor || void 0 === editor ? void 0 : editor.option()) ?? {}; return super._isVisible() && !!showSpinButtons } _isTouchFriendly() { const { editor: editor } = this; const { showSpinButtons: showSpinButtons, useLargeSpinButtons: useLargeSpinButtons } = (null === editor || void 0 === editor ? void 0 : editor.option()) ?? {}; return !!showSpinButtons && !!useLargeSpinButtons } _legacyRender($editor, isTouchFriendly, isVisible) { $editor.toggleClass(SPIN_TOUCH_FRIENDLY_CLASS, isTouchFriendly); $editor.toggleClass(SPIN_CLASS, isVisible) } update() { const shouldUpdate = super.update(); const { editor: editor, instance: instance } = this; if (shouldUpdate && instance && editor) { const $spinButtons = instance.children(); const spinUp = SpinButton.getInstance($spinButtons.eq(0)); const spinDown = SpinButton.getInstance($spinButtons.eq(1)); const options = this._getOptions(); spinUp.option(options); spinDown.option(options); this._legacyRender(editor.$element(), this._isTouchFriendly(), options.visible) } return shouldUpdate } }