diff --git a/apps/demos/Demos/PivotGrid/DrillDown/React/App.tsx b/apps/demos/Demos/PivotGrid/DrillDown/React/App.tsx index 055fcdbd6c4c..46e68c5c707f 100644 --- a/apps/demos/Demos/PivotGrid/DrillDown/React/App.tsx +++ b/apps/demos/Demos/PivotGrid/DrillDown/React/App.tsx @@ -19,6 +19,9 @@ const App = () => { const [popupVisible, setPopupVisible] = useState(false); const dataGridRef = useRef(null); + const onPopupHiding = useCallback(() => setPopupVisible(false), []); + const onPopupShown = useCallback(() => dataGridRef.current?.instance().updateDimensions(), []); + const onCellClick = useCallback((e: PivotGridTypes.CellClickEvent) => { if (e.area === 'data' && e.cell) { const pivotGridDataSource = e.component.getDataSource(); @@ -50,8 +53,8 @@ const App = () => { width={600} height={400} title={popupTitle} - onHiding={() => setPopupVisible(false)} - onShown={() => dataGridRef.current?.instance().updateDimensions()} + onHiding={onPopupHiding} + onShown={onPopupShown} showCloseButton={true} > { const [drillDownDataSource, setDrillDownDataSource] = useState(undefined); const [popupVisible, setPopupVisible] = useState(false); const dataGridRef = useRef(null); + const onPopupHiding = useCallback(() => setPopupVisible(false), []); + const onPopupShown = useCallback(() => dataGridRef.current?.instance().updateDimensions(), []); const onCellClick = useCallback((e) => { if (e.area === 'data' && e.cell) { const pivotGridDataSource = e.component.getDataSource(); @@ -39,8 +41,8 @@ const App = () => { width={600} height={400} title={popupTitle} - onHiding={() => setPopupVisible(false)} - onShown={() => dataGridRef.current?.instance().updateDimensions()} + onHiding={onPopupHiding} + onShown={onPopupShown} showCloseButton={true} > { const [layout, setLayout] = useState(0); const fieldChooserRef = useRef(null); + const onApplyChanges = useCallback(() => fieldChooserRef.current?.instance().applyChanges(), []); + const onCancelChanges = useCallback(() => fieldChooserRef.current?.instance().cancelChanges(), []); + return ( <> { } diff --git a/apps/demos/Demos/PivotGrid/StandaloneFieldChooser/ReactJs/App.js b/apps/demos/Demos/PivotGrid/StandaloneFieldChooser/ReactJs/App.js index 63f5a1640a62..d99b56b47702 100644 --- a/apps/demos/Demos/PivotGrid/StandaloneFieldChooser/ReactJs/App.js +++ b/apps/demos/Demos/PivotGrid/StandaloneFieldChooser/ReactJs/App.js @@ -1,4 +1,4 @@ -import React, { useRef, useState } from 'react'; +import React, { useCallback, useRef, useState } from 'react'; import { Button } from 'devextreme-react/button'; import { PivotGrid, FieldChooser } from 'devextreme-react/pivot-grid'; import { PivotGridFieldChooser, Texts } from 'devextreme-react/pivot-grid-field-chooser'; @@ -14,6 +14,11 @@ const App = () => { const [applyChangesMode, setApplyChangesMode] = useState('instantly'); const [layout, setLayout] = useState(0); const fieldChooserRef = useRef(null); + const onApplyChanges = useCallback(() => fieldChooserRef.current?.instance().applyChanges(), []); + const onCancelChanges = useCallback( + () => fieldChooserRef.current?.instance().cancelChanges(), + [], + ); return ( <> { )} diff --git a/apps/demos/Demos/Scheduler/ContextMenu/React/itemTemplate.tsx b/apps/demos/Demos/Scheduler/ContextMenu/React/itemTemplate.tsx index ce704b4a2f01..ae59a57e295b 100644 --- a/apps/demos/Demos/Scheduler/ContextMenu/React/itemTemplate.tsx +++ b/apps/demos/Demos/Scheduler/ContextMenu/React/itemTemplate.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useMemo } from 'react'; type ItemTemplateProps = { data: { @@ -7,11 +7,15 @@ type ItemTemplateProps = { } }; -const ItemTemplate = (props: ItemTemplateProps) => ( -
- {props.data.color &&
} - {props.data.text} -
-); +const ItemTemplate = (props: ItemTemplateProps) => { + const badgeStyle = useMemo(() => ({ backgroundColor: props.data.color }), [props.data.color]); + + return ( +
+ {props.data.color &&
} + {props.data.text} +
+ ); +}; export default ItemTemplate; diff --git a/apps/demos/Demos/Scheduler/ContextMenu/ReactJs/itemTemplate.js b/apps/demos/Demos/Scheduler/ContextMenu/ReactJs/itemTemplate.js index 31eaeb9417d8..eaeb52c1a484 100644 --- a/apps/demos/Demos/Scheduler/ContextMenu/ReactJs/itemTemplate.js +++ b/apps/demos/Demos/Scheduler/ContextMenu/ReactJs/itemTemplate.js @@ -1,14 +1,17 @@ -import React from 'react'; +import React, { useMemo } from 'react'; -const ItemTemplate = (props) => ( -
- {props.data.color && ( -
- )} - {props.data.text} -
-); +const ItemTemplate = (props) => { + const badgeStyle = useMemo(() => ({ backgroundColor: props.data.color }), [props.data.color]); + return ( +
+ {props.data.color && ( +
+ )} + {props.data.text} +
+ ); +}; export default ItemTemplate; diff --git a/apps/demos/Demos/Scheduler/HiddenDays/React/App.tsx b/apps/demos/Demos/Scheduler/HiddenDays/React/App.tsx index 5ecbbeba4e84..2099e1462dac 100644 --- a/apps/demos/Demos/Scheduler/HiddenDays/React/App.tsx +++ b/apps/demos/Demos/Scheduler/HiddenDays/React/App.tsx @@ -16,6 +16,20 @@ const defaultVisible: SchedulerTypes.DayOfWeek[] = [0, 1, 2, 4, 6]; const views: SchedulerTypes.Properties['views'] = ['week', 'workWeek', 'month', 'timelineWeek', 'agenda']; const currentDate = new Date(2021, 3, 26); const VALIDATION_MESSAGE = 'The hiddenWeekDays option cannot hide all days of the week. At least one day must remain visible.'; +const DayCheckBox = ({ + dayIndex, label, value, onDayToggle, +}: { + dayIndex: SchedulerTypes.DayOfWeek; + label: string; + value: boolean; + onDayToggle: (dayIndex: SchedulerTypes.DayOfWeek, e: CheckBoxTypes.ValueChangedEvent) => void; +}) => { + const onValueChanged = useCallback((e: CheckBoxTypes.ValueChangedEvent) => { + onDayToggle(dayIndex, e); + }, [dayIndex, onDayToggle]); + + return ; +}; const App = () => { const [visibleDays, setVisibleDays] = useState(defaultVisible); @@ -51,10 +65,11 @@ const App = () => {
Visible Week Days
{dayLabels.map((label, idx) => (
- onDayToggle(idx as SchedulerTypes.DayOfWeek, e)} + onDayToggle={onDayToggle} />
))} diff --git a/apps/demos/Demos/Scheduler/HiddenDays/ReactJs/App.js b/apps/demos/Demos/Scheduler/HiddenDays/ReactJs/App.js index f6447c013062..08772f987b12 100644 --- a/apps/demos/Demos/Scheduler/HiddenDays/ReactJs/App.js +++ b/apps/demos/Demos/Scheduler/HiddenDays/ReactJs/App.js @@ -15,6 +15,23 @@ const views = ['week', 'workWeek', 'month', 'timelineWeek', 'agenda']; const currentDate = new Date(2021, 3, 26); const VALIDATION_MESSAGE = 'The hiddenWeekDays option cannot hide all days of the week. At least one day must remain visible.'; +const DayCheckBox = ({ + dayIndex, label, value, onDayToggle, +}) => { + const onValueChanged = useCallback( + (e) => { + onDayToggle(dayIndex, e); + }, + [dayIndex, onDayToggle], + ); + return ( + + ); +}; const App = () => { const [visibleDays, setVisibleDays] = useState(defaultVisible); const isInvalid = visibleDays.length === 0; @@ -46,10 +63,11 @@ const App = () => { className="option" key={label} > - onDayToggle(idx, e)} + onDayToggle={onDayToggle} />
))} diff --git a/apps/demos/Demos/Scheduler/IndividualViewsCustomization/React/App.tsx b/apps/demos/Demos/Scheduler/IndividualViewsCustomization/React/App.tsx index 3f98a1fcbcf4..49e51404d699 100644 --- a/apps/demos/Demos/Scheduler/IndividualViewsCustomization/React/App.tsx +++ b/apps/demos/Demos/Scheduler/IndividualViewsCustomization/React/App.tsx @@ -13,6 +13,7 @@ const currentDate = new Date(2021, 3, 27); const dayOfWeekNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; const typeGroups = ['typeId']; const priorityGroups = ['priorityId']; +const colCountByScreen = { xs: 3 }; type DateCellProps = { data: any; @@ -67,7 +68,7 @@ const App = () => ( - + diff --git a/apps/demos/Demos/Scheduler/IndividualViewsCustomization/ReactJs/App.js b/apps/demos/Demos/Scheduler/IndividualViewsCustomization/ReactJs/App.js index 4ad2cb8bd73a..2b011432326e 100644 --- a/apps/demos/Demos/Scheduler/IndividualViewsCustomization/ReactJs/App.js +++ b/apps/demos/Demos/Scheduler/IndividualViewsCustomization/ReactJs/App.js @@ -12,6 +12,7 @@ const currentDate = new Date(2021, 3, 27); const dayOfWeekNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; const typeGroups = ['typeId']; const priorityGroups = ['priorityId']; +const colCountByScreen = { xs: 3 }; const DateCell = ({ data: cellData }) => ( <>
{dayOfWeekNames[cellData.date.getDay()]}
@@ -67,7 +68,7 @@ const App = () => ( diff --git a/apps/demos/Demos/Scheduler/Overview/React/ResourceCell.tsx b/apps/demos/Demos/Scheduler/Overview/React/ResourceCell.tsx index 23f948f62ecf..342286469e66 100644 --- a/apps/demos/Demos/Scheduler/Overview/React/ResourceCell.tsx +++ b/apps/demos/Demos/Scheduler/Overview/React/ResourceCell.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useMemo } from 'react'; type ResourceCellProps = { data: { color: string; text: string; data: { avatar: string; age: number; discipline: string; }; }; @@ -6,10 +6,12 @@ type ResourceCellProps = { const ResourceCell = (props: ResourceCellProps) => { const { data: { color, text, data: { avatar, age, discipline } } } = props; + const backgroundStyle = useMemo(() => ({ background: color }), [color]); + const textStyle = useMemo(() => ({ color }), [color]); return (
-
+

{text}

@@ -18,7 +20,7 @@ const ResourceCell = (props: ResourceCellProps) => { alt={`${text} photo`} />
-
+
Age: {age}
{discipline} diff --git a/apps/demos/Demos/Scheduler/Overview/ReactJs/ResourceCell.js b/apps/demos/Demos/Scheduler/Overview/ReactJs/ResourceCell.js index 6f080eb30b8a..7f745581c3f3 100644 --- a/apps/demos/Demos/Scheduler/Overview/ReactJs/ResourceCell.js +++ b/apps/demos/Demos/Scheduler/Overview/ReactJs/ResourceCell.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useMemo } from 'react'; const ResourceCell = (props) => { const { @@ -8,11 +8,13 @@ const ResourceCell = (props) => { data: { avatar, age, discipline }, }, } = props; + const backgroundStyle = useMemo(() => ({ background: color }), [color]); + const textStyle = useMemo(() => ({ color }), [color]); return (

{text}

@@ -27,7 +29,7 @@ const ResourceCell = (props) => {
Age: {age}
diff --git a/apps/demos/Demos/Scheduler/ResolveTimeConflicts/React/App.tsx b/apps/demos/Demos/Scheduler/ResolveTimeConflicts/React/App.tsx index 42a44a6958aa..c00bd50ff2af 100644 --- a/apps/demos/Demos/Scheduler/ResolveTimeConflicts/React/App.tsx +++ b/apps/demos/Demos/Scheduler/ResolveTimeConflicts/React/App.tsx @@ -25,6 +25,7 @@ const overlappingRuleItems = [ { value: 'sameResource', text: 'Different Resources' }, { value: 'allResources', text: 'Never' }, ]; +const formElementAttr = { class: 'hide-informer', id: 'form' }; function getNextDay(date: Date): Date { const next = new Date(date); @@ -90,12 +91,21 @@ const assigneeIdEditorOptions = { tagTemplate: 'tagTemplate', }; -const tagTemplate = (itemData: Assignee) => ( -
- {itemData.text} -
-
-); +const TagTemplate = ({ itemData }: { itemData: Assignee }) => { + const tagStyle = useMemo(() => ({ + backgroundColor: itemData.color, + borderColor: itemData.color, + }), [itemData.color]); + + return ( +
+ {itemData.text} +
+
+ ); +}; + +const tagTemplate = (itemData: Assignee) => ; const conflictInformerRender = () => (
This time slot conflicts with another appointment.
@@ -107,6 +117,10 @@ const App = () => { const showConflictErrorRef = useRef(false); const overlappingRuleRef = useRef('sameResource'); + const onOverlappingRuleChanged = useCallback((e: SelectBoxTypes.ValueChangedEvent) => { + overlappingRuleRef.current = e.value; + }, []); + const setConflictError = useCallback((show: boolean) => { showConflictErrorRef.current = show; formRef.current?.option('elementAttr.class', show ? '' : 'hide-informer'); @@ -226,7 +240,7 @@ const App = () => { labelMode="hidden" onInitialized={onFormInitialized} customizeItem={customizeItem} - elementAttr={{ class: 'hide-informer', id: 'form' }} + elementAttr={formElementAttr} > { valueExpr="value" displayExpr="text" defaultValue="sameResource" - onValueChanged={(e: SelectBoxTypes.ValueChangedEvent) => { overlappingRuleRef.current = e.value; }} + onValueChanged={onOverlappingRuleChanged} />
diff --git a/apps/demos/Demos/Scheduler/ResolveTimeConflicts/ReactJs/App.js b/apps/demos/Demos/Scheduler/ResolveTimeConflicts/ReactJs/App.js index e13487f0fae2..ec740a9b79a2 100644 --- a/apps/demos/Demos/Scheduler/ResolveTimeConflicts/ReactJs/App.js +++ b/apps/demos/Demos/Scheduler/ResolveTimeConflicts/ReactJs/App.js @@ -13,6 +13,7 @@ const overlappingRuleItems = [ { value: 'sameResource', text: 'Different Resources' }, { value: 'allResources', text: 'Never' }, ]; +const formElementAttr = { class: 'hide-informer', id: 'form' }; function getNextDay(date) { const next = new Date(date); next.setDate(next.getDate() + 1); @@ -59,15 +60,25 @@ const assigneeIdEditorOptions = { }, tagTemplate: 'tagTemplate', }; -const tagTemplate = (itemData) => ( -
- {itemData.text} -
-
-); +const TagTemplate = ({ itemData }) => { + const tagStyle = useMemo( + () => ({ + backgroundColor: itemData.color, + borderColor: itemData.color, + }), + [itemData.color], + ); + return ( +
+ {itemData.text} +
+
+ ); +}; +const tagTemplate = (itemData) => ; const conflictInformerRender = () => (
This time slot conflicts with another appointment.
); @@ -76,6 +87,9 @@ const App = () => { const formRef = useRef(null); const showConflictErrorRef = useRef(false); const overlappingRuleRef = useRef('sameResource'); + const onOverlappingRuleChanged = useCallback((e) => { + overlappingRuleRef.current = e.value; + }, []); const setConflictError = useCallback((show) => { showConflictErrorRef.current = show; formRef.current?.option('elementAttr.class', show ? '' : 'hide-informer'); @@ -201,7 +215,7 @@ const App = () => { labelMode="hidden" onInitialized={onFormInitialized} customizeItem={customizeItem} - elementAttr={{ class: 'hide-informer', id: 'form' }} + elementAttr={formElementAttr} > { valueExpr="value" displayExpr="text" defaultValue="sameResource" - onValueChanged={(e) => { - overlappingRuleRef.current = e.value; - }} + onValueChanged={onOverlappingRuleChanged} />
diff --git a/apps/demos/Demos/Scheduler/Resources/React/App.tsx b/apps/demos/Demos/Scheduler/Resources/React/App.tsx index 0125755f0dc7..88b768e6b60a 100644 --- a/apps/demos/Demos/Scheduler/Resources/React/App.tsx +++ b/apps/demos/Demos/Scheduler/Resources/React/App.tsx @@ -17,6 +17,7 @@ import { const currentDate = new Date(2021, 3, 27); const views: SchedulerTypes.ViewType[] = ['workWeek']; +const colCountByScreen = { xs: 3 }; const App = () => { const [currentResource, setCurrentResource] = useState(resourcesList[0]); @@ -67,7 +68,7 @@ const App = () => { - + diff --git a/apps/demos/Demos/Scheduler/Resources/ReactJs/App.js b/apps/demos/Demos/Scheduler/Resources/ReactJs/App.js index 984c1afb0811..b276ddef9cd6 100644 --- a/apps/demos/Demos/Scheduler/Resources/ReactJs/App.js +++ b/apps/demos/Demos/Scheduler/Resources/ReactJs/App.js @@ -12,6 +12,7 @@ import { const currentDate = new Date(2021, 3, 27); const views = ['workWeek']; +const colCountByScreen = { xs: 3 }; const App = () => { const [currentResource, setCurrentResource] = useState(resourcesList[0]); const onRadioGroupValueChanged = useCallback((e) => { @@ -62,7 +63,7 @@ const App = () => {