Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/show extra info in a day cell #242

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions demo/src/components/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ export default class Main extends Component {
}

render() {
const cellInfo = [
{ date: addDays(new Date(), 1), value: '$ 20' },
{ date: addDays(new Date(), 2), value: '$ 120' },
];
return (
<main className={'Main'}>
<h1 className={'Title'}>React-date-range</h1>
Expand Down Expand Up @@ -347,6 +351,8 @@ export default class Main extends Component {
className={'PreviewArea'}
disabledDates={[new Date(), addDays(new Date(), 3)]}
minDate={addDays(new Date(), -3)}
cellInfo={cellInfo}
cellInfoClassName="abc"
Comment on lines +354 to +355
Copy link
Contributor

@kamyar kamyar May 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about instead of passing a list of date & value, passing a function that when it is called with a date, returns the extra info to be shown for it?

/>
</Section>
</main>
Expand Down
17 changes: 16 additions & 1 deletion src/components/DayCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,13 @@ class DayCell extends Component {
));
}
render() {
const { styles } = this.props;
const { styles, cellInfoClassName, cellInfo } = this.props;
let dayInfo = [];
if (this.props && this.props !== 'undefined' && cellInfo) {
dayInfo = this.props.cellInfo.filter(data => {
return isSameDay(new Date(data.date), new Date(this.props.day));
});
}
return (
<button
type="button"
Expand All @@ -182,6 +188,13 @@ class DayCell extends Component {
<span className={styles.dayNumber}>
<span>{format(this.props.day, 'D')}</span>
</span>
{dayInfo.length > 0 && (
<span
className={cellInfoClassName}
style={{ display: 'inline-block', marginTop: '15px' }}>
{dayInfo[0].value}
</span>
)}
</button>
);
}
Expand Down Expand Up @@ -223,6 +236,8 @@ DayCell.propTypes = {
onMouseDown: PropTypes.func,
onMouseUp: PropTypes.func,
onMouseEnter: PropTypes.func,
cellInfo: PropTypes.array,
cellInfoClassName: PropTypes.string,
};

export default DayCell;