import React, { useCallback, useState } from 'react';
import CheckBox from 'devextreme-react/check-box';
import type { CheckBoxTypes } from 'devextreme-react/check-box';
import SelectBox from 'devextreme-react/select-box';
import type { SelectBoxTypes } from 'devextreme-react/select-box';
import TextArea from 'devextreme-react/text-area';
import type { TextAreaTypes } from 'devextreme-react/text-area';
import { valueChangeEvents, content } from './data.ts';
const notesLabel = { 'aria-label': 'Notes' };
const eventLabel = { 'aria-label': 'Event' };
function App() {
const [value, setValue] = useState<string>(content);
const [valueForEditableTestArea, setValueForEditableTestArea] = useState<string>(content);
const [maxLength, setMaxLength] = useState<number | undefined>(undefined);
const [eventValue, setEventValue] = useState<string>(valueChangeEvents[0].name);
const [autoResizeEnabled, setAutoResizeEnabled] = useState<boolean>(false);
const [height, setHeight] = useState<number | undefined>(90);
const onCheckboxValueChanged = useCallback((e: CheckBoxTypes.ValueChangedEvent): void => {
const str = content;
setValue(e.value ? str.substring(0, 100) : str);
setMaxLength(e.value ? 100 : undefined);
}, []);
const onAutoResizeChanged = useCallback((e: CheckBoxTypes.ValueChangedEvent): void => {
setAutoResizeEnabled(e.value);
setHeight(e.value ? undefined : 90);
}, []);
const onSelectBoxValueChanged = useCallback((e: SelectBoxTypes.ValueChangedEvent): void => {
setEventValue(e.value);
}, []);
const onTextAreaValueChanged = useCallback((e: TextAreaTypes.ValueChangedEvent): void => {
setValueForEditableTestArea(e.value);
}, []);
return (
<>
<div className="dx-fieldset">
<div className="dx-fieldset-header">Default Mode</div>
<div className="dx-field">
<CheckBox
defaultValue={false}
onValueChanged={onCheckboxValueChanged}
text="Limit text length"
></CheckBox>
</div>
<div className="dx-field">
<CheckBox
value={autoResizeEnabled}
onValueChanged={onAutoResizeChanged}
text="Enable auto resize"
></CheckBox>
</div>
</div>
<div className="textarea-wrapper">
<TextArea
height={height}
maxLength={maxLength}
defaultValue={value}
inputAttr={notesLabel}
autoResizeEnabled={autoResizeEnabled}
/>
</div>
<div className="full-width-content">
<div className="dx-fieldset">
<div className="dx-fieldset-header">Event Handling and API</div>
<div className="dx-field">
<div className="dx-field-label">Synchronize text areas </div>
<div className="dx-field-value">
<SelectBox
items={valueChangeEvents}
valueExpr="name"
displayExpr="title"
inputAttr={eventLabel}
value={eventValue}
onValueChanged={onSelectBoxValueChanged}
/>
</div>
</div>
</div>
<div className="textarea-wrapper">
<TextArea
height={90}
value={valueForEditableTestArea}
valueChangeEvent={eventValue}
inputAttr={notesLabel}
onValueChanged={onTextAreaValueChanged}
/>
<TextArea
height={90}
value={valueForEditableTestArea}
readOnly={true}
inputAttr={notesLabel}
valueChangeEvent={eventValue}
/>
</div>
</div>
</>
);
}
export default App;
import React, { useCallback, useState } from 'react';
import CheckBox from 'devextreme-react/check-box';
import SelectBox from 'devextreme-react/select-box';
import TextArea from 'devextreme-react/text-area';
import { valueChangeEvents, content } from './data.js';
const notesLabel = { 'aria-label': 'Notes' };
const eventLabel = { 'aria-label': 'Event' };
function App() {
const [value, setValue] = useState(content);
const [valueForEditableTestArea, setValueForEditableTestArea] = useState(content);
const [maxLength, setMaxLength] = useState(undefined);
const [eventValue, setEventValue] = useState(valueChangeEvents[0].name);
const [autoResizeEnabled, setAutoResizeEnabled] = useState(false);
const [height, setHeight] = useState(90);
const onCheckboxValueChanged = useCallback((e) => {
const str = content;
setValue(e.value ? str.substring(0, 100) : str);
setMaxLength(e.value ? 100 : undefined);
}, []);
const onAutoResizeChanged = useCallback((e) => {
setAutoResizeEnabled(e.value);
setHeight(e.value ? undefined : 90);
}, []);
const onSelectBoxValueChanged = useCallback((e) => {
setEventValue(e.value);
}, []);
const onTextAreaValueChanged = useCallback((e) => {
setValueForEditableTestArea(e.value);
}, []);
return (
<>
<div className="dx-fieldset">
<div className="dx-fieldset-header">Default Mode</div>
<div className="dx-field">
<CheckBox
defaultValue={false}
onValueChanged={onCheckboxValueChanged}
text="Limit text length"
></CheckBox>
</div>
<div className="dx-field">
<CheckBox
value={autoResizeEnabled}
onValueChanged={onAutoResizeChanged}
text="Enable auto resize"
></CheckBox>
</div>
</div>
<div className="textarea-wrapper">
<TextArea
height={height}
maxLength={maxLength}
defaultValue={value}
inputAttr={notesLabel}
autoResizeEnabled={autoResizeEnabled}
/>
</div>
<div className="full-width-content">
<div className="dx-fieldset">
<div className="dx-fieldset-header">Event Handling and API</div>
<div className="dx-field">
<div className="dx-field-label">Synchronize text areas </div>
<div className="dx-field-value">
<SelectBox
items={valueChangeEvents}
valueExpr="name"
displayExpr="title"
inputAttr={eventLabel}
value={eventValue}
onValueChanged={onSelectBoxValueChanged}
/>
</div>
</div>
</div>
<div className="textarea-wrapper">
<TextArea
height={90}
value={valueForEditableTestArea}
valueChangeEvent={eventValue}
inputAttr={notesLabel}
onValueChanged={onTextAreaValueChanged}
/>
<TextArea
height={90}
value={valueForEditableTestArea}
readOnly={true}
inputAttr={notesLabel}
valueChangeEvent={eventValue}
/>
</div>
</div>
</>
);
}
export default App;
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.tsx';
ReactDOM.render(<App />, document.getElementById('app'));
import type { ValueChangeEvent } from './types.ts';
export const valueChangeEvents: ValueChangeEvent[] = [{
title: 'On Change',
name: 'change',
}, {
title: 'On Key Up',
name: 'keyup',
}];
export const content = 'Prepare 2013 Marketing Plan: We need to double revenues in 2013 and our marketing strategy is going to be key here. R&D is improving existing products and creating new products so we can deliver great AV equipment to our customers.Robert, please make certain to create a PowerPoint presentation for the members of the executive team.';
export type ValueChangeEvent = {
title: string;
name: string;
};
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.js';
ReactDOM.render(<App />, document.getElementById('app'));
export const valueChangeEvents = [
{
title: 'On Change',
name: 'change',
},
{
title: 'On Key Up',
name: 'keyup',
},
];
export const content =
'Prepare 2013 Marketing Plan: We need to double revenues in 2013 and our marketing strategy is going to be key here. R&D is improving existing products and creating new products so we can deliver great AV equipment to our customers.Robert, please make certain to create a PowerPoint presentation for the members of the executive team.';
<!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>
.full-width-content {
width: 100%;
margin-top: 30px;
}
.full-width-content .textarea-wrapper > .dx-widget {
margin-bottom: 20px;
}
.full-width-content .dx-field {
max-width: 385px;
}
.textarea-wrapper {
padding: 0 20px;
}