2020-05-21 03:32:02 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2024-10-21 03:29:17 +00:00
|
|
|
import dayjs from 'dayjs';
|
2024-10-21 06:24:02 +00:00
|
|
|
import localeData from 'dayjs/plugin/localeData';
|
|
|
|
import utc from 'dayjs/plugin/utc';
|
|
|
|
import weekOfYear from 'dayjs/plugin/weekOfYear';
|
2020-05-21 03:32:02 +00:00
|
|
|
import Calendar from '@seafile/seafile-calendar';
|
|
|
|
import DatePicker from '@seafile/seafile-calendar/lib/Picker';
|
|
|
|
import { translateCalendar } from '../utils/date-format-utils';
|
|
|
|
|
|
|
|
import '@seafile/seafile-calendar/assets/index.css';
|
|
|
|
import '../css/date-and-time-picker.css';
|
|
|
|
|
2024-10-21 06:24:02 +00:00
|
|
|
dayjs.extend(utc);
|
|
|
|
dayjs.extend(localeData);
|
|
|
|
dayjs.extend(weekOfYear);
|
|
|
|
|
|
|
|
|
2020-05-21 03:32:02 +00:00
|
|
|
class Picker extends React.Component {
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.calendarContainerRef = React.createRef();
|
2020-07-05 02:20:23 +00:00
|
|
|
this.inputRef = React.createRef();
|
2024-10-21 06:24:02 +00:00
|
|
|
let now = dayjs();
|
2020-05-21 03:32:02 +00:00
|
|
|
let lang = window.app.config.lang;
|
2024-10-21 06:24:02 +00:00
|
|
|
const isZhcn = lang === 'zh-cn';
|
|
|
|
if (isZhcn) {
|
|
|
|
now = now.locale('zh-cn');
|
|
|
|
} else {
|
|
|
|
now = now.locale('en-gb');
|
|
|
|
}
|
|
|
|
this.defaultCalendarValue = now.clone();
|
2020-05-21 03:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getCalendarContainer = () => {
|
|
|
|
return this.calendarContainerRef.current;
|
2023-09-13 00:40:50 +00:00
|
|
|
};
|
2020-05-21 03:32:02 +00:00
|
|
|
|
|
|
|
render() {
|
2020-07-21 03:17:09 +00:00
|
|
|
let showHourAndMinute = true; // default: true
|
2023-09-13 00:40:50 +00:00
|
|
|
if (this.props.showHourAndMinute != undefined) {
|
|
|
|
showHourAndMinute = this.props.showHourAndMinute;
|
2020-07-21 03:17:09 +00:00
|
|
|
}
|
|
|
|
|
2024-10-21 06:24:02 +00:00
|
|
|
const format = showHourAndMinute ? 'YYYY-MM-DD HH:mm' : 'YYYY-MM-DD';
|
2020-07-21 03:17:09 +00:00
|
|
|
|
2020-05-21 03:32:02 +00:00
|
|
|
return (
|
|
|
|
<DatePicker
|
2023-09-13 00:40:50 +00:00
|
|
|
disabled={this.props.disabled}
|
2020-05-21 03:32:02 +00:00
|
|
|
getCalendarContainer={this.getCalendarContainer}
|
2024-10-21 06:24:02 +00:00
|
|
|
calendar={
|
|
|
|
<Calendar
|
|
|
|
defaultValue={this.defaultCalendarValue}
|
|
|
|
disabledDate={this.props.disabledDate}
|
|
|
|
format={format}
|
|
|
|
locale={translateCalendar()}
|
|
|
|
showHourAndMinute={showHourAndMinute}
|
|
|
|
/>
|
|
|
|
}
|
2023-09-13 00:40:50 +00:00
|
|
|
value={this.props.value}
|
|
|
|
onChange={this.props.onChange}
|
2020-05-21 03:32:02 +00:00
|
|
|
>
|
|
|
|
{
|
2024-07-18 03:58:42 +00:00
|
|
|
({ value }) => {
|
2020-05-21 03:32:02 +00:00
|
|
|
return (
|
|
|
|
<div>
|
2020-11-02 05:56:35 +00:00
|
|
|
<input
|
2024-10-21 06:24:02 +00:00
|
|
|
placeholder={format}
|
2023-09-13 00:40:50 +00:00
|
|
|
style={{ width: this.props.inputWidth || 250 }}
|
2020-05-21 03:32:02 +00:00
|
|
|
tabIndex="-1"
|
2023-09-13 00:40:50 +00:00
|
|
|
disabled={this.props.disabled}
|
2020-07-05 02:20:23 +00:00
|
|
|
readOnly={true}
|
2024-10-21 06:24:02 +00:00
|
|
|
value={value && value.format(format) || ''}
|
2020-05-21 03:32:02 +00:00
|
|
|
className="form-control"
|
2020-07-05 02:20:23 +00:00
|
|
|
ref={this.inputRef}
|
2020-05-21 03:32:02 +00:00
|
|
|
/>
|
|
|
|
<div ref={this.calendarContainerRef} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</DatePicker>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-13 00:40:50 +00:00
|
|
|
Picker.propTypes = {
|
|
|
|
showHourAndMinute: PropTypes.bool.isRequired,
|
|
|
|
disabledDate: PropTypes.func.isRequired,
|
|
|
|
value: PropTypes.object,
|
|
|
|
disabled: PropTypes.func.isRequired,
|
|
|
|
inputWidth: PropTypes.number.isRequired,
|
|
|
|
onChange: PropTypes.func.isRequired
|
|
|
|
};
|
2020-05-21 03:32:02 +00:00
|
|
|
|
|
|
|
export default Picker;
|