import React from 'react';
import Accordion from 'devextreme-react/accordion';
import CheckBox from 'devextreme-react/check-box';
import TagBox from 'devextreme-react/tag-box';
import Slider, { Tooltip, Label } from 'devextreme-react/slider';
import service from './data.js';
import CustomTitle from './CustomTitle.js';
import CustomItem from './CustomItem.js';
class App extends React.Component {
constructor(props) {
super(props);
this.companies = service.getCompanies();
this.state = {
selectedItems: [this.companies[0]],
multiple: false,
collapsible: false,
animationDuration: 300
};
this.selectionChanged = this.selectionChanged.bind(this);
this.selectedItemsChanged = this.selectedItemsChanged.bind(this);
this.multipleChanged = this.multipleChanged.bind(this);
this.collapsibleChanged = this.collapsibleChanged.bind(this);
this.animationDurationChanged = this.animationDurationChanged.bind(this);
}
render() {
const { selectedItems, multiple, collapsible, animationDuration } = this.state;
return (
<div id="accordion">
<Accordion
dataSource={this.companies}
collapsible={collapsible}
multiple={multiple}
animationDuration={animationDuration}
selectedItems={selectedItems}
onSelectionChanged={this.selectionChanged}
itemTitleRender={CustomTitle}
itemRender={CustomItem}
/>
<div className="selected-data">
<span className="caption">Selected Items</span>
<TagBox dataSource={this.companies}
displayExpr="CompanyName"
value={selectedItems}
onValueChanged={this.selectedItemsChanged}
disabled={!multiple}
/>
</div>
<div className="options">
<div className="caption">Options</div>
<div className="option">
<CheckBox text="Multiple enabled"
value={multiple}
onValueChanged={this.multipleChanged}
/>
</div>
<div className="option">
<CheckBox
text="Collapsible enabled"
value={collapsible}
onValueChanged={this.collapsibleChanged}
/>
</div>
<div className="option">
<span>Animation duration</span>
<Slider
min={0}
max={1000}
value={animationDuration}
onValueChanged={this.animationDurationChanged}
>
<Tooltip enabled={true} position="bottom" />
<Label visible={true} />
</Slider>
</div>
</div>
</div>
);
}
selectionChanged(e) {
let newItems = [...this.state.selectedItems];
e.removedItems.forEach(item => {
let index = newItems.indexOf(item);
if (index >= 0) {
newItems.splice(index, 1);
}
});
if (e.addedItems.length) {
newItems = [...newItems, ...e.addedItems];
}
this.setState({
selectedItems: newItems
});
}
selectedItemsChanged(e) {
this.setState({
selectedItems: e.value
});
}
multipleChanged(e) {
this.setState({
multiple: e.value
});
}
collapsibleChanged(e) {
this.setState({
collapsible: e.value
});
}
animationDurationChanged(e) {
this.setState({
animationDuration: e.value
});
}
}
export default App;
import React from 'react';
export default function CustomItem(data) {
return (
<div>
<div>
<p>
<b>{data.City} </b>
(<span>{data.State}</span>)
</p>
<p>
<span>{data.Zipcode} </span>
<span>{data.Address}</span>
</p>
</div>
<div>
<p>
Phone: <b>{data.Phone}</b>
</p>
<p>
Fax: <b>{data.Fax}</b>
</p>
<p>
Website: <a href={data.Website} target="_blank">
{data.Website}
</a>
</p>
</div>
</div>
);
}
import React from 'react';
export default function CustomTitle(data) {
return (
<h1>{data.CompanyName}</h1>
);
}
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.js';
ReactDOM.render(
<App />,
document.getElementById('app')
);
<!DOCTYPE html>
<html>
<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=1.0" />
<link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/20.2.5/css/dx.common.css" />
<link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/20.2.5/css/dx.light.css" />
<link rel="stylesheet" type="text/css" href="styles.css" />
<script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script>
<script src="https://unpkg.com/systemjs@0.21.3/dist/system.js"></script>
<script type="text/javascript" src="config.js"></script>
<script type="text/javascript">
System.import('./index.js');
</script>
</head>
<body class="dx-viewport">
<div class="demo-container">
<div id="app"></div>
</div>
</body>
</html>
#accordion h1 {
font-size: 20px;
}
#accordion h1,
#accordion p {
margin: 0;
}
.dx-theme-material #accordion .dx-accordion-item-opened .dx-accordion-item-title {
display: flex;
}
.dx-theme-material #accordion .dx-accordion-item-opened h1 {
align-self: center;
}
.options,
.selected-data {
padding: 20px;
background-color: rgba(191, 191, 191, 0.15);
margin-top: 20px;
}
.selected-data {
position: relative;
height: 36px;
}
.selected-data > .caption {
position: relative;
top: 5px;
margin-right: 10px;
font-weight: bold;
font-size: 115%;
}
.selected-data > .dx-widget {
position: absolute;
left: 140px;
right: 20px;
top: 20px;
}
.options > .caption {
font-weight: 500;
font-size: 18px;
}
.option {
margin-top: 10px;
}
const companies = [{
'ID': 1,
'CompanyName': 'Super Mart of the West',
'Address': '702 SW 8th Street',
'City': 'Bentonville',
'State': 'Arkansas',
'Zipcode': 72716,
'Phone': '(800) 555-2797',
'Fax': '(800) 555-2171',
'Website': 'http://www.nowebsitesupermart.com'
}, {
'ID': 2,
'CompanyName': 'Electronics Depot',
'Address': '2455 Paces Ferry Road NW',
'City': 'Atlanta',
'State': 'Georgia',
'Zipcode': 30339,
'Phone': '(800) 595-3232',
'Fax': '(800) 595-3231',
'Website': 'http://www.nowebsitedepot.com'
}, {
'ID': 3,
'CompanyName': 'K&S Music',
'Address': '1000 Nicllet Mall',
'City': 'Minneapolis',
'State': 'Minnesota',
'Zipcode': 55403,
'Phone': '(612) 304-6073',
'Fax': '(612) 304-6074',
'Website': 'http://www.nowebsitemusic.com'
}, {
'ID': 4,
'CompanyName': "Tom's Club",
'Address': '999 Lake Drive',
'City': 'Issaquah',
'State': 'Washington',
'Zipcode': 98027,
'Phone': '(800) 955-2292',
'Fax': '(800) 955-2293',
'Website': 'http://www.nowebsitetomsclub.com'
}];
export default {
getCompanies() {
return companies;
}
};
System.config({
transpiler: 'plugin-babel',
meta: {
'devextreme/localization.js': {
"esModule": true
},
},
paths: {
'npm:': 'https://unpkg.com/'
},
defaultExtension: 'js',
map: {
'react': 'npm:react@16.14.0/umd/react.development.js',
'react-dom': 'npm:react-dom@16.14.0/umd/react-dom.development.js',
'prop-types': 'npm:prop-types@15.7.2/prop-types.js',
'rrule': 'npm:rrule@2.6.6/dist/es5/rrule.js',
'luxon': 'npm:luxon@1.25.0/build/global/luxon.min.js',
'es6-object-assign': 'npm:es6-object-assign@1.1.0',
'devextreme': 'npm:devextreme@20.2.5',
'devextreme-react': 'npm:devextreme-react@20.2.5',
'jszip': 'npm:jszip@3.5.0/dist/jszip.min.js',
'devextreme-quill': 'npm:devextreme-quill@0.9.8/dist/dx-quill.min.js',
'devexpress-diagram': 'npm:devexpress-diagram@2.0.11/dist/dx-diagram.js',
'devexpress-gantt': 'npm:devexpress-gantt@2.0.18/dist/dx-gantt.js',
'preact': 'npm:preact@10.5.11/dist/preact.js',
'preact/hooks': 'npm:preact@10.5.11/hooks/dist/hooks.js',
// SystemJS plugins
'plugin-babel': 'npm:systemjs-plugin-babel@0.0.25/plugin-babel.js',
'systemjs-babel-build': 'npm:systemjs-plugin-babel@0.0.25/systemjs-babel-browser.js'
},
packages: {
'devextreme': {
defaultExtension: 'js'
},
'devextreme-react': {
main: 'index.js'
},
'devextreme/events/utils': {
main: 'index'
},
'devextreme/events': {
main: 'index'
},
'es6-object-assign': {
main: './index.js',
defaultExtension: 'js'
}
},
babelOptions: {
sourceMaps: false,
stage0: true,
react: true
}
});