devextreme
Version:
HTML5 JavaScript Component Suite for Responsive Web Development
177 lines (172 loc) • 6.81 kB
JavaScript
/**
* DevExtreme (cjs/ui/calendar/ui.calendar.navigator.js)
* Version: 23.2.6
* Build date: Wed May 01 2024
*
* Copyright (c) 2012 - 2024 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
;
exports.default = void 0;
var _renderer = _interopRequireDefault(require("../../core/renderer"));
var _extend = require("../../core/utils/extend");
var _ui = _interopRequireDefault(require("../widget/ui.widget"));
var _button = _interopRequireDefault(require("../button"));
var _themes = require("../themes");
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
}
}
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
_setPrototypeOf(subClass, superClass)
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(o, p) {
o.__proto__ = p;
return o
};
return _setPrototypeOf(o, p)
}
const CALENDAR_NAVIGATOR_CLASS = "dx-calendar-navigator";
const CALENDAR_NAVIGATOR_PREVIOUS_MONTH_CLASS = "dx-calendar-navigator-previous-month";
const CALENDAR_NAVIGATOR_NEXT_MONTH_CLASS = "dx-calendar-navigator-next-month";
const CALENDAR_NAVIGATOR_PREVIOUS_VIEW_CLASS = "dx-calendar-navigator-previous-view";
const CALENDAR_NAVIGATOR_NEXT_VIEW_CLASS = "dx-calendar-navigator-next-view";
const CALENDAR_NAVIGATOR_DISABLED_LINK_CLASS = "dx-calendar-disabled-navigator-link";
const CALENDAR_NAVIGATOR_CAPTION_BUTTON_CLASS = "dx-calendar-caption-button";
const BUTTON_TEXT_CLASS = "dx-button-text";
let Navigator = function(_Widget) {
_inheritsLoose(Navigator, _Widget);
function Navigator() {
return _Widget.apply(this, arguments) || this
}
var _proto = Navigator.prototype;
_proto._getDefaultOptions = function() {
return (0, _extend.extend)(_Widget.prototype._getDefaultOptions.call(this), {
onClick: null,
onCaptionClick: null,
type: "normal",
stylingMode: "outlined",
text: ""
})
};
_proto._defaultOptionsRules = function() {
return _Widget.prototype._defaultOptionsRules.call(this).concat([{
device: function() {
return (0, _themes.isMaterial)()
},
options: {
type: "default",
stylingMode: "text"
}
}, {
device: function() {
return (0, _themes.isFluent)()
},
options: {
type: "normal",
stylingMode: "text"
}
}])
};
_proto._init = function() {
_Widget.prototype._init.call(this);
this._initActions()
};
_proto._initActions = function() {
this._clickAction = this._createActionByOption("onClick");
this._captionClickAction = this._createActionByOption("onCaptionClick")
};
_proto._initMarkup = function() {
_Widget.prototype._initMarkup.call(this);
this.$element().addClass("dx-calendar-navigator");
this._renderButtons();
this._renderCaption()
};
_proto._renderButtons = function() {
const {
rtlEnabled: rtlEnabled,
type: type,
stylingMode: stylingMode,
focusStateEnabled: focusStateEnabled
} = this.option();
this._prevButton = this._createComponent((0, _renderer.default)("<div>"), _button.default, {
focusStateEnabled: focusStateEnabled,
icon: rtlEnabled ? "chevronright" : "chevronleft",
onClick: e => {
this._clickAction({
direction: -1,
event: e
})
},
type: type,
stylingMode: stylingMode,
integrationOptions: {}
});
const $prevButton = this._prevButton.$element().addClass("dx-calendar-navigator-previous-view").addClass("dx-calendar-navigator-previous-month");
this._nextButton = this._createComponent((0, _renderer.default)("<div>"), _button.default, {
focusStateEnabled: focusStateEnabled,
icon: rtlEnabled ? "chevronleft" : "chevronright",
onClick: e => {
this._clickAction({
direction: 1,
event: e
})
},
type: type,
stylingMode: stylingMode,
integrationOptions: {}
});
const $nextButton = this._nextButton.$element().addClass("dx-calendar-navigator-next-view").addClass("dx-calendar-navigator-next-month");
this._caption = this._createComponent((0, _renderer.default)("<div>").addClass("dx-calendar-caption-button"), _button.default, {
focusStateEnabled: focusStateEnabled,
onClick: e => {
this._captionClickAction({
event: e
})
},
type: type,
stylingMode: stylingMode,
template: (_, content) => {
const {
text: text
} = this.option();
const viewCaptionTexts = text.split(" - ");
viewCaptionTexts.forEach(captionText => {
(0, _renderer.default)(content).append((0, _renderer.default)("<span>").addClass("dx-button-text").text(captionText))
})
},
integrationOptions: {}
});
const $caption = this._caption.$element();
this.$element().append($prevButton, $caption, $nextButton)
};
_proto._renderCaption = function() {
this._caption.option("text", this.option("text"))
};
_proto.toggleButton = function(buttonPrefix, value) {
const buttonName = "_" + buttonPrefix + "Button";
const button = this[buttonName];
if (button) {
button.option("disabled", value);
button.$element().toggleClass("dx-calendar-disabled-navigator-link", value)
}
};
_proto._optionChanged = function(args) {
switch (args.name) {
case "text":
this._renderCaption();
break;
default:
_Widget.prototype._optionChanged.call(this, args)
}
};
return Navigator
}(_ui.default);
var _default = Navigator;
exports.default = _default;
module.exports = exports.default;
module.exports.default = exports.default;