Skip to content

Commit

Permalink
Navigation: Transfer demos to TS (#2825)
Browse files Browse the repository at this point in the history
* Typestat config created + files renamed

* Enhance types with typestat

* Improve typings + add missing @types/react-dom package

* Typings improvments

* fix cannot use jsx components in vscode

* Types improv + tsconf changes to remove component is not tsx problem

* Check tsc version on CI

* Revert printing tsc version on CI

* Revert TSConfig changes

* Generate JS from ts

* Revert bad js generation result for DateBox and DateRangeBox

* Fix sysemJs index.js import to tsx in index.html

* Final TS enhansments

* generate js

* Exclude Vue from ts config because it's polluting react JSX with wrong typings

* Revert excluding vue from ts

* Update ts for tabs demos (merge)

* Fix minor errors

* Missed extension in tabpanel

* Drawer: navigationList fix file extension

* Fix generate-js

* Fix missing merge changes

* Fix styles generation

* generate js
  • Loading branch information
ivanblinov2k17 authored Nov 13, 2023
1 parent ce93399 commit cf0c05f
Show file tree
Hide file tree
Showing 242 changed files with 9,332 additions and 438 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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 Accordion, { AccordionTypes } from 'devextreme-react/accordion';
import CheckBox, { CheckBoxTypes } from 'devextreme-react/check-box';
import TagBox, { TagBoxTypes } from 'devextreme-react/tag-box';
import Slider, { Tooltip, Label, SliderTypes } from 'devextreme-react/slider';

import service from './data.js';
import CustomTitle from './CustomTitle.js';
import CustomItem from './CustomItem.js';
import service from './data.ts';
import CustomTitle from './CustomTitle.tsx';
import CustomItem from './CustomItem.tsx';

const companyLabel = { 'aria-label': 'Company' };
const companies = service.getCompanies();
Expand All @@ -17,7 +17,7 @@ const App = () => {
const [collapsible, setCollapsible] = React.useState(false);
const [animationDuration, setAnimationDuration] = React.useState(300);

const selectionChanged = React.useCallback((e) => {
const selectionChanged = React.useCallback((e: AccordionTypes.SelectionChangedEvent) => {
let newItems = [...selectedItems];
e.removedItems.forEach((item) => {
const index = newItems.indexOf(item);
Expand All @@ -31,19 +31,19 @@ const App = () => {
setSelectedItems(newItems);
}, [selectedItems, setSelectedItems]);

const selectedItemsChanged = React.useCallback((e) => {
const selectedItemsChanged = React.useCallback((e: TagBoxTypes.ValueChangedEvent) => {
setSelectedItems(e.value);
}, [setSelectedItems]);

const multipleChanged = React.useCallback((e) => {
const multipleChanged = React.useCallback((e: CheckBoxTypes.ValueChangedEvent) => {
setMultiple(e.value);
}, [setMultiple]);

const collapsibleChanged = React.useCallback((e) => {
const collapsibleChanged = React.useCallback((e: CheckBoxTypes.ValueChangedEvent) => {
setCollapsible(e.value);
}, [setCollapsible]);

const animationDurationChanged = React.useCallback((e) => {
const animationDurationChanged = React.useCallback((e: SliderTypes.ValueChangedEvent) => {
setAnimationDuration(e.value);
}, [setAnimationDuration]);

Expand Down
2 changes: 1 addition & 1 deletion JSDemos/Demos/Accordion/Overview/React/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<script src="../../../../../node_modules/systemjs/dist/system.js"></script>
<script type="text/javascript" src="config.js"></script>
<script type="text/javascript">
System.import("./index.js");
System.import("./index.tsx");
</script>
</head>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom';

import App from './App.js';
import App from './App.tsx';

ReactDOM.render(
<App />,
Expand Down
116 changes: 116 additions & 0 deletions JSDemos/Demos/Accordion/Overview/ReactJs/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
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';

const companyLabel = { 'aria-label': 'Company' };
const companies = service.getCompanies();
const App = () => {
const [selectedItems, setSelectedItems] = React.useState([companies[0]]);
const [multiple, setMultiple] = React.useState(false);
const [collapsible, setCollapsible] = React.useState(false);
const [animationDuration, setAnimationDuration] = React.useState(300);
const selectionChanged = React.useCallback(
(e) => {
let newItems = [...selectedItems];
e.removedItems.forEach((item) => {
const index = newItems.indexOf(item);
if (index >= 0) {
newItems.splice(index, 1);
}
});
if (e.addedItems.length) {
newItems = [...newItems, ...e.addedItems];
}
setSelectedItems(newItems);
},
[selectedItems, setSelectedItems],
);
const selectedItemsChanged = React.useCallback(
(e) => {
setSelectedItems(e.value);
},
[setSelectedItems],
);
const multipleChanged = React.useCallback(
(e) => {
setMultiple(e.value);
},
[setMultiple],
);
const collapsibleChanged = React.useCallback(
(e) => {
setCollapsible(e.value);
},
[setCollapsible],
);
const animationDurationChanged = React.useCallback(
(e) => {
setAnimationDuration(e.value);
},
[setAnimationDuration],
);
return (
<div id="accordion">
<Accordion
dataSource={companies}
collapsible={collapsible}
multiple={multiple}
animationDuration={animationDuration}
selectedItems={selectedItems}
onSelectionChanged={selectionChanged}
itemTitleRender={CustomTitle}
itemRender={CustomItem}
id="accordion-container"
/>
<div className="options">
<div className="caption">Options</div>
<div className="option">
<CheckBox
text="Multiple enabled"
value={multiple}
onValueChanged={multipleChanged}
/>
</div>
<div className="option">
<CheckBox
text="Collapsible enabled"
value={collapsible}
onValueChanged={collapsibleChanged}
/>
</div>
<div className="option">
<span>Animation duration</span>
<Slider
min={0}
max={1000}
value={animationDuration}
onValueChanged={animationDurationChanged}
>
<Tooltip
enabled={true}
position="bottom"
/>
<Label visible={true} />
</Slider>
</div>
<div className="option">
<span className="caption">Selected Items</span>
<TagBox
dataSource={companies}
displayExpr="CompanyName"
value={selectedItems}
inputAttr={companyLabel}
onValueChanged={selectedItemsChanged}
disabled={!multiple}
/>
</div>
</div>
</div>
);
};
export default App;
34 changes: 34 additions & 0 deletions JSDemos/Demos/Accordion/Overview/ReactJs/CustomItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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>
);
}
5 changes: 5 additions & 0 deletions JSDemos/Demos/Accordion/Overview/ReactJs/CustomTitle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';

export default function CustomTitle(data) {
return <div className="header">{data.CompanyName}</div>;
}
51 changes: 51 additions & 0 deletions JSDemos/Demos/Accordion/Overview/ReactJs/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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;
},
};
44 changes: 44 additions & 0 deletions JSDemos/Demos/Accordion/Overview/ReactJs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!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="../../../../../node_modules/devextreme-dist/css/dx.light.css"
/>
<link
rel="stylesheet"
type="text/css"
href="styles.css"
/>

<script src="../../../../../node_modules/core-js/client/shim.min.js"></script>
<script src="../../../../../node_modules/systemjs/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>
5 changes: 5 additions & 0 deletions JSDemos/Demos/Accordion/Overview/ReactJs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.js';

ReactDOM.render(<App />, document.getElementById('app'));
52 changes: 52 additions & 0 deletions JSDemos/Demos/Accordion/Overview/ReactJs/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#accordion {
height: 700px;
}

#accordion .header {
font-size: 20px;
}

#accordion .header,
#accordion p {
margin: 0;
}

#accordion-container {
margin-right: 400px;
}

.dx-theme-material #accordion .dx-accordion-item-title {
display: flex;
}

.dx-theme-material #accordion .header {
align-self: center;
}

.options {
padding: 20px;
position: absolute;
bottom: 0;
right: 0;
width: 340px;
top: 0;
background-color: rgba(191, 191, 191, 0.15);
}

.options > .caption {
font-weight: 500;
font-size: 18px;
}

.option {
margin-top: 10px;
}

.option > .caption {
margin-top: 10px;
display: inline-block;
}

.option > .dx-tagbox {
margin-top: 2px;
}
Loading

0 comments on commit cf0c05f

Please sign in to comment.