Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-scheduler): support scheduler localization capability (#1985)
- Loading branch information
1 parent
568ba8a
commit 286003e
Showing
64 changed files
with
836 additions
and
217 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
...scheduler-demos/src/demo-sources/scheduler-localization/material-ui/custom-formatting.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import * as React from 'react'; | ||
import Paper from '@material-ui/core/Paper'; | ||
import moment from 'moment'; | ||
import { ViewState } from '@devexpress/dx-react-scheduler'; | ||
import { | ||
Scheduler, | ||
WeekView, | ||
Toolbar, | ||
Appointments, | ||
} from '@devexpress/dx-react-scheduler-material-ui'; | ||
import { appointments } from '../../../demo-data/appointments'; | ||
|
||
const formatDayScaleDate = (date, options) => { | ||
const momentDate = moment(date); | ||
const { weekday } = options; | ||
return momentDate.format(weekday ? 'dddd' : 'D'); | ||
}; | ||
const formatTimeScaleDate = date => moment(date).format('hh:mm:ss'); | ||
|
||
const DayScaleCell = ( | ||
{ formatDate, ...restProps }, | ||
) => <WeekView.DayScaleCell {...restProps} formatDate={formatDayScaleDate} />; | ||
const TimeScaleCell = ( | ||
{ formatDate, ...restProps }, | ||
) => <WeekView.TimeScaleCell {...restProps} formatDate={formatTimeScaleDate} />; | ||
|
||
export default class Demo extends React.PureComponent { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
data: appointments, | ||
currentDate: '2018-06-27', | ||
}; | ||
} | ||
|
||
render() { | ||
const { data, currentDate, locale } = this.state; | ||
|
||
return ( | ||
<Paper> | ||
<Scheduler | ||
data={data} | ||
locale={locale} | ||
> | ||
<ViewState | ||
defaultCurrentDate={currentDate} | ||
/> | ||
<WeekView | ||
startDayHour={9} | ||
endDayHour={19} | ||
dayScaleCellComponent={DayScaleCell} | ||
timeScaleCellComponent={TimeScaleCell} | ||
/> | ||
<Toolbar /> | ||
<Appointments /> | ||
</Scheduler> | ||
</Paper> | ||
); | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
...s/dx-react-scheduler-demos/src/demo-sources/scheduler-localization/material-ui/locale.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import * as React from 'react'; | ||
import Paper from '@material-ui/core/Paper'; | ||
import TextField from '@material-ui/core/TextField'; | ||
import MenuItem from '@material-ui/core/MenuItem'; | ||
import { ViewState } from '@devexpress/dx-react-scheduler'; | ||
import { withStyles } from '@material-ui/core/styles'; | ||
import { | ||
Scheduler, | ||
WeekView, | ||
Toolbar, | ||
DateNavigator, | ||
Appointments, | ||
AllDayPanel, | ||
} from '@devexpress/dx-react-scheduler-material-ui'; | ||
|
||
import { appointments } from '../../../demo-data/appointments'; | ||
|
||
const allDayLocalizationMessages = { | ||
'fr-FR': { | ||
allDay: "Autour de l'horloge", | ||
}, | ||
'de-GR': { | ||
allDay: 'Rund um die Uhr', | ||
}, | ||
'en-US': { | ||
allDay: 'All Day', | ||
}, | ||
}; | ||
|
||
const getAllDayMessages = locale => allDayLocalizationMessages[locale]; | ||
|
||
const styles = theme => ({ | ||
container: { | ||
display: 'flex', | ||
marginBottom: theme.spacing.unit * 2, | ||
justifyContent: 'flex-end', | ||
}, | ||
text: { | ||
...theme.typography.h6, | ||
marginRight: theme.spacing.unit * 2, | ||
}, | ||
}); | ||
|
||
const LocaleSwitcher = withStyles(styles, { name: 'LocaleSwitcher' })( | ||
({ onLocaleChange, currentLocale, classes }) => ( | ||
<div className={classes.container}> | ||
<div className={classes.text}> | ||
Locale: | ||
</div> | ||
<TextField | ||
select | ||
value={currentLocale} | ||
onChange={onLocaleChange} | ||
> | ||
<MenuItem value="fr-FR">Le français (French)</MenuItem> | ||
<MenuItem value="de-GR">Deutsch (German)</MenuItem> | ||
<MenuItem value="en-US">English (United States)</MenuItem> | ||
</TextField> | ||
</div> | ||
), | ||
); | ||
|
||
export default class Demo extends React.PureComponent { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
data: appointments, | ||
currentDate: '2018-06-27', | ||
locale: 'fr-FR', | ||
}; | ||
|
||
this.changeLocale = event => this.setState({ locale: event.target.value }); | ||
} | ||
|
||
render() { | ||
const { data, currentDate, locale } = this.state; | ||
|
||
return ( | ||
<div> | ||
<LocaleSwitcher | ||
currentLocale={locale} | ||
onLocaleChange={this.changeLocale} | ||
/> | ||
<Paper> | ||
<Scheduler | ||
data={data} | ||
locale={locale} | ||
> | ||
<ViewState | ||
defaultCurrentDate={currentDate} | ||
/> | ||
<WeekView | ||
startDayHour={9} | ||
endDayHour={19} | ||
/> | ||
<Toolbar /> | ||
<DateNavigator /> | ||
<Appointments /> | ||
<AllDayPanel | ||
messages={getAllDayMessages(locale)} | ||
/> | ||
</Scheduler> | ||
</Paper> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.