devextreme
Version:
HTML5 JavaScript Component Suite for Responsive Web Development
108 lines (107 loc) • 3.72 kB
JavaScript
/**
* DevExtreme (esm/__internal/scheduler/header/m_view_switcher.js)
* Version: 25.1.4
* Build date: Tue Aug 05 2025
*
* Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
import _extends from "@babel/runtime/helpers/esm/extends";
import {
isFluent
} from "../../../ui/themes";
import {
getViewName,
isOneView
} from "./m_utils";
const ClASS = {
container: "dx-scheduler-view-switcher",
dropDownButton: "dx-scheduler-view-switcher-dropdown-button",
dropDownButtonContent: "dx-scheduler-view-switcher-dropdown-button-content"
};
const getViewsAndSelectedView = header => {
const views = header.option("views");
const selectedView = header.option("currentView").name;
const isSelectedViewInViews = views.some((view => view.name === selectedView));
return {
selectedView: isSelectedViewInViews ? selectedView : void 0,
views: views
}
};
export const getTabViewSwitcher = (header, item) => {
const {
selectedView: selectedView,
views: views
} = getViewsAndSelectedView(header);
const stylingMode = isFluent() ? "outlined" : "contained";
const items = views.map((view => _extends({}, view, {
text: view.name
})));
return _extends({
widget: "dxButtonGroup",
locateInMenu: "auto",
location: "after",
name: "viewSwitcher",
cssClass: ClASS.container,
options: {
items: items,
keyExpr: "name",
selectedItemKeys: [selectedView],
stylingMode: stylingMode,
onItemClick: e => {
header._updateCurrentView(e.itemData)
},
onContentReady: e => {
const viewSwitcher = e.component;
header._addEvent("currentView", (view => {
viewSwitcher.option("selectedItemKeys", [getViewName(view)])
}))
}
}
}, item)
};
export const getDropDownViewSwitcher = (header, item) => {
const {
selectedView: selectedView,
views: views
} = getViewsAndSelectedView(header);
const isOnlyOneView = isOneView(views, selectedView);
return _extends({
widget: "dxDropDownButton",
locateInMenu: "never",
location: "after",
name: "viewSwitcher",
cssClass: ClASS.container,
options: {
items: views,
useSelectMode: true,
keyExpr: "name",
selectedItemKey: selectedView,
displayExpr: "name",
showArrowIcon: !isOnlyOneView,
elementAttr: {
class: ClASS.dropDownButton
},
onItemClick: e => {
header._updateCurrentView(e.itemData)
},
onContentReady: e => {
const viewSwitcher = e.component;
header._addEvent("currentView", (view => {
const currentViews = header.option("views");
viewSwitcher.option("showArrowIcon", !isOneView(currentViews, view.name));
viewSwitcher.option("selectedItemKey", getViewName(view))
}))
},
dropDownOptions: {
onShowing: e => {
if (isOnlyOneView) {
e.cancel = true
}
},
width: "max-content",
_wrapperClassExternal: ClASS.dropDownButtonContent
}
}
}, item)
};