|
1 | | -import React from 'react'; |
| 1 | +import React, { useCallback, useState } from 'react'; |
2 | 2 |
|
3 | 3 | import Scheduler, { |
4 | 4 | Resource, |
5 | 5 | type SchedulerTypes, |
6 | 6 | } from 'devextreme-react/scheduler'; |
| 7 | +import SelectBox from 'devextreme-react/select-box'; |
| 8 | +import type { SelectBoxTypes } from 'devextreme-react/select-box'; |
7 | 9 |
|
8 | 10 | import { data, resourcesData, priorityData } from './data.ts'; |
9 | 11 |
|
10 | 12 | const currentDate = new Date(2021, 1, 2); |
11 | 13 | const views: SchedulerTypes.ViewType[] = ['timelineDay', 'timelineWeek', 'timelineWorkWeek', 'timelineMonth']; |
12 | 14 | const groups = ['priority']; |
13 | 15 |
|
14 | | -const App = () => ( |
15 | | - <Scheduler |
16 | | - timeZone="America/Los_Angeles" |
17 | | - dataSource={data} |
18 | | - views={views} |
19 | | - defaultCurrentView="timelineMonth" |
20 | | - defaultCurrentDate={currentDate} |
21 | | - height={580} |
22 | | - groups={groups} |
23 | | - cellDuration={60} |
24 | | - firstDayOfWeek={0} |
25 | | - startDayHour={8} |
26 | | - endDayHour={20} |
27 | | - > |
28 | | - <Resource |
29 | | - fieldExpr="ownerId" |
30 | | - allowMultiple={true} |
31 | | - dataSource={resourcesData} |
32 | | - label="Owner" |
33 | | - useColorAsDefault={true} |
34 | | - icon="user" |
35 | | - /> |
36 | | - <Resource |
37 | | - fieldExpr="priority" |
38 | | - allowMultiple={false} |
39 | | - dataSource={priorityData} |
40 | | - label="Priority" |
41 | | - icon="tags" |
42 | | - /> |
43 | | - </Scheduler> |
44 | | -); |
| 16 | +const snapToCellsModeItems: { value: SchedulerTypes.SnapToCellsMode; text: string }[] = [ |
| 17 | + { value: 'auto', text: 'Auto' }, |
| 18 | + { value: 'always', text: 'Always' }, |
| 19 | + { value: 'never', text: 'Never' }, |
| 20 | +]; |
| 21 | + |
| 22 | +const App = () => { |
| 23 | + const [snapToCellsMode, setSnapToCellsMode] = useState<SchedulerTypes.SnapToCellsMode>('always'); |
| 24 | + |
| 25 | + const onSnapToCellsModeChanged = useCallback((e: SelectBoxTypes.ValueChangedEvent) => { |
| 26 | + setSnapToCellsMode(e.value); |
| 27 | + }, []); |
| 28 | + |
| 29 | + return ( |
| 30 | + <> |
| 31 | + <Scheduler |
| 32 | + timeZone="America/Los_Angeles" |
| 33 | + dataSource={data} |
| 34 | + views={views} |
| 35 | + defaultCurrentView="timelineMonth" |
| 36 | + defaultCurrentDate={currentDate} |
| 37 | + height={580} |
| 38 | + groups={groups} |
| 39 | + cellDuration={60} |
| 40 | + firstDayOfWeek={0} |
| 41 | + startDayHour={8} |
| 42 | + endDayHour={20} |
| 43 | + snapToCellsMode={snapToCellsMode} |
| 44 | + > |
| 45 | + <Resource |
| 46 | + fieldExpr="ownerId" |
| 47 | + allowMultiple={true} |
| 48 | + dataSource={resourcesData} |
| 49 | + label="Owner" |
| 50 | + useColorAsDefault={true} |
| 51 | + icon="user" |
| 52 | + /> |
| 53 | + <Resource |
| 54 | + fieldExpr="priority" |
| 55 | + allowMultiple={false} |
| 56 | + dataSource={priorityData} |
| 57 | + label="Priority" |
| 58 | + icon="tags" |
| 59 | + /> |
| 60 | + </Scheduler> |
| 61 | + <div className="options"> |
| 62 | + <div className="option"> |
| 63 | + <span>Snap to Cells Mode:</span> |
| 64 | + <SelectBox |
| 65 | + items={snapToCellsModeItems} |
| 66 | + valueExpr="value" |
| 67 | + displayExpr="text" |
| 68 | + value={snapToCellsMode} |
| 69 | + onValueChanged={onSnapToCellsModeChanged} |
| 70 | + /> |
| 71 | + </div> |
| 72 | + </div> |
| 73 | + </> |
| 74 | + ); |
| 75 | +}; |
45 | 76 |
|
46 | 77 | export default App; |
0 commit comments