import React, { useState } from 'react';
import type { ButtonGroupTypes } from 'devextreme-react/button-group';
import type { CheckBoxTypes } from 'devextreme-react/check-box';
import type { Orientation } from 'devextreme-react/common';
import { navigationModes, orientations } from './data.ts';
import Steppers from './Steppers.tsx';
import Options from './Options.tsx';
export default function App() {
const [orientation, setOrientation] = useState<Orientation>(orientations[0].value);
const [navigationMode, setNavigationMode] = useState<boolean>(navigationModes[0].value);
const [selectOnFocus, setSelectOnFocus] = useState<boolean>(true);
const [rtlMode, setRtlMode] = useState<boolean>(false);
const onOrientationClick = (e: ButtonGroupTypes.ItemClickEvent): void => {
setOrientation(e.itemData.value);
};
const onNavigationModeClick = (e: ButtonGroupTypes.ItemClickEvent): void => {
setNavigationMode(e.itemData.value);
};
const onSelectOnFocusChanged = (e: CheckBoxTypes.ValueChangedEvent): void => {
setSelectOnFocus(e.value);
};
const onRtlModeChanged = (e: CheckBoxTypes.ValueChangedEvent): void => {
setRtlMode(e.value);
};
const widgetWrapperOrientationClass: string = `widget-wrapper-${orientation}`;
return (
<div className="stepper-demo">
<div className="widget-container">
<div className={`widget-wrapper ${widgetWrapperOrientationClass}`}>
<Steppers
orientation={orientation}
navigationMode={navigationMode}
selectOnFocus={selectOnFocus}
rtlMode={rtlMode}
/>
</div>
</div>
<div className="options">
<Options
orientation={orientation}
navigationMode={navigationMode}
selectOnFocus={selectOnFocus}
rtlMode={rtlMode}
onOrientationClick={onOrientationClick}
onNavigationModeClick={onNavigationModeClick}
onSelectOnFocusChanged={onSelectOnFocusChanged}
onRtlModeChanged={onRtlModeChanged}
/>
</div>
</div>
);
}
import React, { useState } from 'react';
import { navigationModes, orientations } from './data.js';
import Steppers from './Steppers.js';
import Options from './Options.js';
export default function App() {
const [orientation, setOrientation] = useState(orientations[0].value);
const [navigationMode, setNavigationMode] = useState(navigationModes[0].value);
const [selectOnFocus, setSelectOnFocus] = useState(true);
const [rtlMode, setRtlMode] = useState(false);
const onOrientationClick = (e) => {
setOrientation(e.itemData.value);
};
const onNavigationModeClick = (e) => {
setNavigationMode(e.itemData.value);
};
const onSelectOnFocusChanged = (e) => {
setSelectOnFocus(e.value);
};
const onRtlModeChanged = (e) => {
setRtlMode(e.value);
};
const widgetWrapperOrientationClass = `widget-wrapper-${orientation}`;
return (
<div className="stepper-demo">
<div className="widget-container">
<div className={`widget-wrapper ${widgetWrapperOrientationClass}`}>
<Steppers
orientation={orientation}
navigationMode={navigationMode}
selectOnFocus={selectOnFocus}
rtlMode={rtlMode}
/>
</div>
</div>
<div className="options">
<Options
orientation={orientation}
navigationMode={navigationMode}
selectOnFocus={selectOnFocus}
rtlMode={rtlMode}
onOrientationClick={onOrientationClick}
onNavigationModeClick={onNavigationModeClick}
onSelectOnFocusChanged={onSelectOnFocusChanged}
onRtlModeChanged={onRtlModeChanged}
/>
</div>
</div>
);
}
import React from 'react';
import { ButtonGroup, type ButtonGroupTypes } from 'devextreme-react/button-group';
import { CheckBox, type CheckBoxTypes } from 'devextreme-react/check-box';
import { type Orientation } from 'devextreme-react/common';
import { navigationModes, orientations } from './data.ts';
interface OptionsProps {
orientation: Orientation,
navigationMode: boolean,
selectOnFocus: boolean,
rtlMode: boolean,
onOrientationClick: (e: ButtonGroupTypes.ItemClickEvent) => void;
onNavigationModeClick: (e: ButtonGroupTypes.ItemClickEvent) => void;
onSelectOnFocusChanged: (e: CheckBoxTypes.ValueChangedEvent) => void;
onRtlModeChanged: (e: CheckBoxTypes.ValueChangedEvent) => void;
}
export default function Options({
orientation,
navigationMode,
selectOnFocus,
rtlMode,
onOrientationClick,
onNavigationModeClick,
onSelectOnFocusChanged,
onRtlModeChanged,
}: OptionsProps) {
return (
<>
<div className="caption">Options</div>
<div className="option">
<div>Orientation</div>
<ButtonGroup
id="orientation"
keyExpr="value"
items={orientations}
selectedItemKeys={[orientation]}
onItemClick={onOrientationClick}
/>
</div>
<div className="option">
<div>Navigation Mode</div>
<ButtonGroup
id="navigationMode"
keyExpr="value"
items={navigationModes}
selectedItemKeys={[navigationMode]}
onItemClick={onNavigationModeClick}
/>
</div>
<div className="option-separator"></div>
<div className="option">
<CheckBox
id="selectOnFocus"
text="Select step on focus"
value={selectOnFocus}
onValueChanged={onSelectOnFocusChanged}
/>
</div>
<div className="option">
<CheckBox
id="rtlMode"
text="Right-to-left mode"
value={rtlMode}
onValueChanged={onRtlModeChanged}
/>
</div>
</>
);
}
import React from 'react';
import { Stepper, Item } from 'devextreme-react/stepper';
import type { StepperTypes } from 'devextreme-react/stepper';
import type { Orientation } from 'devextreme-react/common';
import { steps } from './data.ts';
import type { StepperConfig } from './types.ts';
const stepperConfigs: StepperConfig[] = [
{
id: 'icons',
labelId: 'iconsLabel',
title: 'Icons and Labels',
fields: ['label', 'icon', 'optional'] as const,
},
{
id: 'numbers',
labelId: 'numbersLabel',
title: 'Numbers and Labels',
fields: ['label', 'optional'] as const,
},
{
id: 'customText',
labelId: 'customTextLabel',
title: 'Custom Text',
fields: ['text'] as const,
},
];
interface SteppersProps {
orientation: Orientation;
navigationMode: boolean;
selectOnFocus: boolean;
rtlMode: boolean;
}
export default function Steppers({
orientation,
navigationMode,
selectOnFocus,
rtlMode,
}: SteppersProps) {
return (
<>
{stepperConfigs.map(({ id, labelId, title, fields }: StepperConfig) => (
<div key={id} className="stepper-wrapper">
<div id={labelId} className="stepper-label">{title}</div>
<Stepper
id={id}
elementAttr={{ 'aria-labelledby': labelId }}
defaultSelectedIndex={2}
orientation={orientation}
linear={navigationMode}
selectOnFocus={selectOnFocus}
rtlEnabled={rtlMode}
>
{steps.map((step: StepperTypes.Item, index: number) => {
const itemProps = fields.reduce((acc: Record<string, unknown>, field: keyof StepperTypes.Item): Record<string, unknown> => {
acc[field] = step[field];
return acc;
}, {});
return <Item key={index} {...itemProps} />;
})}
</Stepper>
</div>
))}
</>
);
}
import React from 'react';
import ReactDOM from 'react-dom';
import themes from 'devextreme/ui/themes';
import App from './App.tsx';
themes.initialized(() => {
ReactDOM.render(
<App />,
document.getElementById('app'),
);
});
import type { StepperTypes } from 'devextreme-react/stepper';
import type { StepperOrientation, StepperNavigationMode } from './types.ts';
export const steps: StepperTypes.Item[] = [
{
text: 'A',
label: 'Cart',
icon: 'cart',
},
{
text: 'B',
label: 'Shipping Info',
icon: 'clipboardtasklist',
},
{
text: 'C',
label: 'Promo Code',
icon: 'gift',
optional: true,
},
{
text: 'D',
label: 'Checkout',
icon: 'packagebox',
},
{
text: 'E',
label: 'Ordered',
icon: 'checkmarkcircle',
},
];
export const orientations: StepperOrientation[] = [
{ text: 'Horizontal', value: 'horizontal' },
{ text: 'Vertical', value: 'vertical' },
];
export const navigationModes: StepperNavigationMode[] = [
{ text: 'Non-linear', value: false },
{ text: 'Linear', value: true },
];
import type { Orientation } from 'devextreme-react/common';
import type { StepperTypes } from 'devextreme-react/stepper';
export type StepperOrientation = {
text: string;
value: Orientation;
};
export type StepperNavigationMode = {
text: string;
value: boolean;
};
export type StepperConfig = {
id: string;
labelId: string;
title: string;
fields: (keyof StepperTypes.Item)[];
};
import React from 'react';
import { ButtonGroup } from 'devextreme-react/button-group';
import { CheckBox } from 'devextreme-react/check-box';
import { navigationModes, orientations } from './data.js';
export default function Options({
orientation,
navigationMode,
selectOnFocus,
rtlMode,
onOrientationClick,
onNavigationModeClick,
onSelectOnFocusChanged,
onRtlModeChanged,
}) {
return (
<>
<div className="caption">Options</div>
<div className="option">
<div>Orientation</div>
<ButtonGroup
id="orientation"
keyExpr="value"
items={orientations}
selectedItemKeys={[orientation]}
onItemClick={onOrientationClick}
/>
</div>
<div className="option">
<div>Navigation Mode</div>
<ButtonGroup
id="navigationMode"
keyExpr="value"
items={navigationModes}
selectedItemKeys={[navigationMode]}
onItemClick={onNavigationModeClick}
/>
</div>
<div className="option-separator"></div>
<div className="option">
<CheckBox
id="selectOnFocus"
text="Select step on focus"
value={selectOnFocus}
onValueChanged={onSelectOnFocusChanged}
/>
</div>
<div className="option">
<CheckBox
id="rtlMode"
text="Right-to-left mode"
value={rtlMode}
onValueChanged={onRtlModeChanged}
/>
</div>
</>
);
}
import React from 'react';
import { Stepper, Item } from 'devextreme-react/stepper';
import { steps } from './data.js';
const stepperConfigs = [
{
id: 'icons',
labelId: 'iconsLabel',
title: 'Icons and Labels',
fields: ['label', 'icon', 'optional'],
},
{
id: 'numbers',
labelId: 'numbersLabel',
title: 'Numbers and Labels',
fields: ['label', 'optional'],
},
{
id: 'customText',
labelId: 'customTextLabel',
title: 'Custom Text',
fields: ['text'],
},
];
export default function Steppers({
orientation, navigationMode, selectOnFocus, rtlMode,
}) {
return (
<>
{stepperConfigs.map(({
id, labelId, title, fields,
}) => (
<div
key={id}
className="stepper-wrapper"
>
<div
id={labelId}
className="stepper-label"
>
{title}
</div>
<Stepper
id={id}
elementAttr={{ 'aria-labelledby': labelId }}
defaultSelectedIndex={2}
orientation={orientation}
linear={navigationMode}
selectOnFocus={selectOnFocus}
rtlEnabled={rtlMode}
>
{steps.map((step, index) => {
const itemProps = fields.reduce((acc, field) => {
acc[field] = step[field];
return acc;
}, {});
return (
<Item
key={index}
{...itemProps}
/>
);
})}
</Stepper>
</div>
))}
</>
);
}
import React from 'react';
import ReactDOM from 'react-dom';
import themes from 'devextreme/ui/themes';
import App from './App.js';
themes.initialized(() => {
ReactDOM.render(<App />, document.getElementById('app'));
});
export const steps = [
{
text: 'A',
label: 'Cart',
icon: 'cart',
},
{
text: 'B',
label: 'Shipping Info',
icon: 'clipboardtasklist',
},
{
text: 'C',
label: 'Promo Code',
icon: 'gift',
optional: true,
},
{
text: 'D',
label: 'Checkout',
icon: 'packagebox',
},
{
text: 'E',
label: 'Ordered',
icon: 'checkmarkcircle',
},
];
export const orientations = [
{ text: 'Horizontal', value: 'horizontal' },
{ text: 'Vertical', value: 'vertical' },
];
export const navigationModes = [
{ text: 'Non-linear', value: false },
{ text: 'Linear', value: true },
];
<!DOCTYPE html>
<html 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" />
<link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/26.1.5/css/dx.light.css" />
<link rel="stylesheet" type="text/css" href="./bundle.css" />
</head>
<body class="dx-viewport">
<div class="demo-container">
<div id="app"></div>
</div>
<script src="bundles/vendor/react.vendor.js"></script>
<script src="./bundle.js"></script>
</body>
</html>
#app {
display: flex;
flex-direction: column;
}
.stepper-demo {
display: flex;
height: 580px;
gap: 20px;
}
.widget-container {
display: flex;
align-items: center;
justify-content: center;
width: calc(100% - 280px);
min-width: 320px;
overflow: clip;
gap: 20px;
}
.widget-wrapper {
display: inline-flex;
flex-direction: column;
align-items: center;
justify-content: center;
row-gap: 80px;
width: 100%;
height: 100%;
}
.widget-wrapper-vertical {
display: flex;
flex-direction: row;
justify-content: space-around;
}
.widget-wrapper-vertical .stepper-wrapper {
width: auto;
max-width: 33%;
}
.widget-wrapper-vertical .stepper-label {
text-align: center;
white-space: nowrap;
}
.widget-wrapper-vertical #customText {
width: auto;
}
.dx-stepper-vertical {
height: 400px;
width: 100%;
}
.stepper-wrapper {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
gap: 16px;
}
.stepper-label {
font-weight: 600;
}
.options {
display: flex;
flex-direction: column;
flex-shrink: 0;
width: 300px;
box-sizing: border-box;
padding: 20px;
background-color: rgba(191, 191, 191, 0.15);
gap: 16px;
height: 100%;
}
.caption {
font-weight: 500;
font-size: 18px;
}
.option {
display: flex;
flex-direction: column;
row-gap: 4px;
}
.option-separator {
border-bottom: 1px solid var(--dx-color-border);
}
.dx-buttongroup .dx-button {
width: 50%;
}