import React from 'react';
import createClass from 'create-react-class';
import CalendarMonth from './CalendarMonth';
import ReactDayPicker from 'react-day-picker';
import _ from 'lodash';
import Button from '../Button/Button';
export default {
title: 'Private/CalendarMonth',
component: CalendarMonth,
parameters: {
docs: {
description: {
component: (CalendarMonth as any).peek.description,
},
},
},
};
/* Selected Day */
export const SelectedDay = () => {
const Component = createClass({
render() {
return (
);
},
});
return ;
};
SelectedDay.storyName = 'SelectedDay';
/* Disabled Days */
export const DisabledDays = () => {
const Component = createClass({
render() {
return (
);
},
});
return ;
};
DisabledDays.storyName = 'DisabledDays';
/* Custom Daypicker Modifiers */
export const CustomDaypickerModifiers = () => {
const Component = createClass({
render() {
return (
day.getDay() === 2,
}}
/>
);
},
});
return ;
};
CustomDaypickerModifiers.storyName = 'CustomDaypickerModifiers';
/* Select Dates */
export const SelectDates = () => {
const Component = createClass({
getInitialState() {
return {
offset: 0,
selectedDays: [],
cursor: null,
};
},
handlePrev() {
this.setState({
offset: this.state.offset - 1,
});
},
handleNext() {
this.setState({
offset: this.state.offset + 1,
});
},
handleDayClick(date: any, { disabled }: any) {
if (disabled) {
return;
}
const { selectedDays } = this.state;
this.setState({
selectedDays: _.xorWith(
selectedDays,
[date],
ReactDayPicker.DateUtils.isSameDay
),
cursor: date,
});
},
handleDayMouseEnter(day: any, { disabled }: any) {
if (disabled) {
this.setState({
cursor: null,
});
} else {
this.setState({
cursor: day,
});
}
},
handleDayMouseLeave() {
this.setState({
cursor: null,
});
},
render() {
const { selectedDays, cursor, offset } = this.state;
return (
selectedDays:{' '}
{_.map(selectedDays, (selected) =>
selected.toLocaleDateString('en-US')
).join(', ')}
);
},
});
return ;
};
SelectDates.storyName = 'SelectDates';
/* Select Range */
export const SelectRange = () => {
const Component = createClass({
getInitialState() {
return {
offset: 0,
selectMode: 'from',
from: null,
to: null,
cursor: null,
};
},
handlePrev() {
this.setState({
offset: this.state.offset - 1,
});
},
handleNext() {
this.setState({
offset: this.state.offset + 1,
});
},
handleDayClick(date: any, { disabled }: any) {
if (disabled) {
return;
}
const { selectMode } = this.state;
if (selectMode === 'to') {
this.setState({
to: date,
cursor: date,
});
} else {
this.setState({
from: date,
selectMode: 'to',
cursor: date,
});
}
},
handleDayMouseEnter(day: any, { disabled }: any) {
if (disabled) {
this.setState({
cursor: null,
});
} else {
this.setState({
cursor: day,
});
}
},
handleDayMouseLeave() {
this.setState({
cursor: null,
});
},
render() {
const { selectMode, from, to, cursor, offset } = this.state;
return (
from: {from && from.toLocaleDateString('en-US')}, to:{' '}
{to && to.toLocaleDateString('en-US')}
);
},
});
return ;
};
SelectRange.storyName = 'SelectRange';
/* Show Cursor */
export const ShowCursor = () => {
const Component = createClass({
UNSAFE_componentWillMount() {
this.fromDate = new Date();
this.fromDate.setDate(1);
},
render() {
return (
Cursor for day selectMode:
Cursor for range selectMode:
);
},
});
return ;
};
ShowCursor.storyName = 'ShowCursor';