devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
106 lines (105 loc) • 3.54 kB
JavaScript
/**
* DevExtreme (esm/__internal/scheduler/header/m_view_switcher.js)
* Version: 25.2.5
* Build date: Fri Feb 20 2026
*
* Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
import {
current,
isFluent
} from "../../../ui/themes";
import {
formatViews,
getViewName
} 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: views,
currentView: currentView
} = header.option();
const formattedViews = formatViews(views);
const selectedView = getViewName(currentView);
const isSelectedViewInViews = formattedViews.some((view => view.name === selectedView));
return {
selectedView: isSelectedViewInViews ? selectedView : void 0,
views: formattedViews
}
};
const isViewSwitcherVisible = views => views.length > 1;
export const getTabViewSwitcher = (header, item) => {
const {
selectedView: selectedView,
views: views
} = getViewsAndSelectedView(header);
const isVisible = isViewSwitcherVisible(views);
const stylingMode = isFluent(current()) ? "outlined" : "contained";
return Object.assign({
widget: "dxButtonGroup",
locateInMenu: "auto",
location: "after",
name: "viewSwitcher",
cssClass: ClASS.container,
visible: isVisible,
options: {
items: views,
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 isVisible = isViewSwitcherVisible(views);
return Object.assign({
widget: "dxDropDownButton",
locateInMenu: "never",
location: "after",
name: "viewSwitcher",
cssClass: ClASS.container,
visible: isVisible,
options: {
items: views,
useSelectMode: true,
keyExpr: "name",
selectedItemKey: selectedView,
displayExpr: "text",
showArrowIcon: true,
elementAttr: {
class: ClASS.dropDownButton
},
onItemClick: e => {
header._updateCurrentView(e.itemData)
},
onContentReady: e => {
const viewSwitcher = e.component;
header._addEvent("currentView", (view => {
viewSwitcher.option("selectedItemKey", getViewName(view))
}))
},
dropDownOptions: {
width: "max-content",
_wrapperClassExternal: ClASS.dropDownButtonContent
}
}
}, item)
};