$(() => {
const tab1 = $('#withText').dxTabs({
width: 'auto',
rtlEnabled: false,
selectedIndex: 0,
showNavButtons: false,
dataSource: tabsText,
orientation: orientations[0],
stylingMode: stylingModes[1],
iconPosition: iconPositions[0],
}).dxTabs('instance');
const tab2 = $('#withIconAndText').dxTabs({
width: 'auto',
rtlEnabled: false,
selectedIndex: 0,
showNavButtons: false,
dataSource: tabsIconAndText,
orientation: orientations[0],
stylingMode: stylingModes[1],
iconPosition: iconPositions[0],
}).dxTabs('instance');
const tab3 = $('#withIcon').dxTabs({
width: 'auto',
rtlEnabled: false,
selectedIndex: 0,
showNavButtons: false,
dataSource: tabsIcon,
orientation: orientations[0],
stylingMode: stylingModes[1],
iconPosition: iconPositions[0],
}).dxTabs('instance');
$('#orientation').dxSelectBox({
items: orientations,
value: orientations[0],
inputAttr: { 'aria-label': 'Orientation' },
onValueChanged(data) {
const $widgetWrapper = $('.widget-wrapper');
const isVertical = data.value === 'vertical';
$widgetWrapper.toggleClass('widget-wrapper-vertical', isVertical);
$widgetWrapper.toggleClass('widget-wrapper-horizontal', !isVertical);
setTabsOption('orientation', data.value);
},
});
$('#styling-mode').dxSelectBox({
items: stylingModes,
value: stylingModes[1],
inputAttr: { 'aria-label': 'Styling Mode' },
onValueChanged(data) {
setTabsOption('stylingMode', data.value);
},
});
$('#icon-position').dxSelectBox({
items: iconPositions,
inputAttr: { 'aria-label': 'Icon Position' },
value: iconPositions[0],
onValueChanged(data) {
setTabsOption('iconPosition', data.value);
},
});
const showNavButtonsCheckBox = $('#show-navigation-buttons').dxCheckBox({
text: 'Show navigation buttons',
value: false,
onValueChanged(data) {
const shouldRestrictWidth = data.value || scrollContentCheckBox.option('value');
toggleStrictWidthClass(shouldRestrictWidth);
setTabsOption('showNavButtons', data.value);
},
}).dxCheckBox('instance');
const scrollContentCheckBox = $('#scroll-content').dxCheckBox({
text: 'Scroll content',
value: false,
onValueChanged(data) {
const shouldRestrictWidth = data.value || showNavButtonsCheckBox.option('value');
toggleStrictWidthClass(shouldRestrictWidth);
setTabsOption('scrollByContent', data.value);
},
}).dxCheckBox('instance');
$('#full-width').dxCheckBox({
text: 'Full width',
value: false,
onValueChanged(data) {
setTabsOption('width', data.value ? '100%' : 'auto');
},
});
$('#rtl').dxCheckBox({
text: 'Right-to-left mode',
value: false,
onValueChanged(data) {
setTabsOption('rtlEnabled', data.value);
},
});
function setTabsOption(option, value) {
tab1.option(option, value);
tab2.option(option, value);
tab3.option(option, value);
}
function toggleStrictWidthClass(shouldRestrictWidth) {
const $widgetWrapper = $('.widget-wrapper');
$widgetWrapper.toggleClass('strict-width', shouldRestrictWidth);
}
});
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>DevExtreme Demo</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>window.jQuery || document.write(decodeURIComponent('%3Cscript src="js/jquery.min.js"%3E%3C/script%3E'))</script>
<link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/24.1.5/css/dx.light.css" />
<script src="js/dx.all.js"></script>
<script src="data.js"></script>
<link rel="stylesheet" type="text/css" href="styles.css" />
<script src="index.js"></script>
</head>
<body class="dx-viewport">
<div class="demo-container">
<div class="tabs-demo">
<div class="widget-container">
<div class="widget-wrapper widget-wrapper-horizontal">
<div id="withText"></div>
<div id="withIconAndText"></div>
<div id="withIcon"></div>
</div>
</div>
<div class="options">
<div class="caption">Options</div>
<div class="option">
<span>Orientation</span>
<div id="orientation"></div>
</div>
<div class="option">
<span>Styling mode</span>
<div id="styling-mode"></div>
</div>
<div class="option">
<span>Icon position</span>
<div id="icon-position"></div>
</div>
<div class="option">
<div id="show-navigation-buttons"></div>
</div>
<div class="option">
<div id="scroll-content"></div>
</div>
<div class="option">
<div id="full-width"></div>
</div>
<div class="option">
<div id="rtl"></div>
</div>
</div>
</div>
</div>
</body>
</html>
.tabs-demo {
display: flex;
}
.strict-width {
max-width: 340px;
}
.dx-theme-generic .strict-width {
max-width: 250px;
}
.widget-container {
display: flex;
align-items: center;
justify-content: center;
flex-grow: 1;
width: 100%;
min-width: 200px;
padding: 16px 32px;
overflow: clip;
}
.widget-wrapper {
display: inline-flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 80px;
width: 100%;
}
.widget-wrapper-vertical {
width: 100%;
flex-direction: row;
align-items: center;
}
.options {
display: flex;
flex-direction: column;
flex-shrink: 0;
padding: 20px;
background-color: rgba(191, 191, 191, 0.15);
}
.caption {
font-weight: 500;
font-size: 18px;
}
#show-navigation-buttons {
margin-top: 22px;
}
.option {
margin-top: 20px;
}
.dx-tabs {
max-width: 100%;
}
.dx-tabs-vertical {
height: 216px;
}
.dx-viewport:not(.dx-theme-generic) .dx-tabs-horizontal {
border-block-end: 1px solid rgb(225, 225, 225, 0.4);
}
.dx-viewport:not(.dx-theme-generic) .dx-tabs-vertical {
height: 232px;
border-inline-end: 1px solid rgb(225, 225, 225, 0.4);
}
const tabsText = [
{
id: 0,
text: 'User',
},
{
id: 1,
text: 'Analytics',
},
{
id: 2,
text: 'Clients',
},
{
id: 3,
text: 'Orders',
},
{
id: 4,
text: 'Favorites',
},
{
id: 5,
text: 'Search',
},
];
const tabsIconAndText = [
{
id: 0,
text: 'User',
icon: 'user',
},
{
id: 1,
text: 'Analytics',
icon: 'chart',
},
{
id: 2,
text: 'Clients',
icon: 'accountbox',
},
{
id: 3,
text: 'Orders',
icon: 'ordersbox',
},
{
id: 4,
text: 'Favorites',
icon: 'bookmark',
},
{
id: 5,
text: 'Search',
icon: 'search',
},
];
const tabsIcon = [
{
id: 0,
icon: 'user',
},
{
id: 1,
icon: 'chart',
},
{
id: 2,
icon: 'accountbox',
},
{
id: 3,
icon: 'ordersbox',
},
{
id: 4,
icon: 'bookmark',
},
{
id: 5,
icon: 'search',
},
];
const orientations = ['horizontal', 'vertical'];
const stylingModes = [
'primary',
'secondary',
];
const iconPositions = [
'top',
'start',
'end',
'bottom',
];