Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.

adding a prop to allow disabling the month and year selectors #206

Merged
Merged
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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ locale | Object | enUS from locale | you can vi
className | String | | wrapper classname
months | Number | 1 | rendered month count
showSelectionPreview | Boolean | true | show preview on focused/hovered dates
showMonthAndYearPickers | Boolean | true | show select tags for month and year on calendar top, if false it will just display the month and year
rangeColors | String[] | | defines color for selection preview.
shownDate | Date | | initial focus date
minDate | Date | | defines minimum date. Disabled earlier dates
maxDate | Date | | defines maximum date. Disabled later dates
direction | String | 'vertical' | direction of calendar months. can be `vertical` or `horizontal`
scroll | Object | { enabled: false }| infinite scroll behaviour configuration. Check out [Infinite Scroll](#infinite-scrolled-mode) section
scroll | Object | { enabled: false }| infinite scroll behaviour configuration. Check out [Infinite Scroll](#infinite-scrolled-mode) section
showMonthArrow | Boolean | true | show/hide month arrow button
navigatorRenderer | Func | | renderer for focused date navigation area. fn(currentFocusedDate: Date, changeShownDate: func, props: object)
ranges | *Object[] | [] | Defines ranges. array of range object
Expand Down Expand Up @@ -151,7 +152,7 @@ If you prefer, you can overwrite calendar sizes with `calendarWidth`/`calendarHe
```js
// shape of scroll prop
scroll: {
enabled: PropTypes.bool,
enabled: PropTypes.bool,
monthHeight: PropTypes.number,
longMonthHeight: PropTypes.number, // some months has 1 more row than others
monthWidth: PropTypes.number, // just used when direction="horizontal"
Expand Down
64 changes: 37 additions & 27 deletions src/components/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class Calendar extends PureComponent {
}
}
renderMonthAndYear(focusedDate, changeShownDate, props) {
const { showMonthArrow, locale, minDate, maxDate } = props;
const { showMonthArrow, locale, minDate, maxDate, showMonthAndYearPickers } = props;
const upperYearLimit = maxDate.getFullYear();
const lowerYearLimit = minDate.getFullYear();
const styles = this.styles;
Expand All @@ -175,34 +175,42 @@ class Calendar extends PureComponent {
<i />
</button>
) : null}
<span className={styles.monthAndYearPickers}>
<span className={styles.monthPicker}>
<select
value={focusedDate.getMonth()}
onChange={e => changeShownDate(e.target.value, 'setMonth')}>
{locale.localize.months().map((month, i) => (
<option key={i} value={i}>
{month}
</option>
))}
</select>
</span>
<span className={styles.monthAndYearDivider} />
<span className={styles.yearPicker}>
<select
value={focusedDate.getFullYear()}
onChange={e => changeShownDate(e.target.value, 'setYear')}>
{new Array(upperYearLimit - lowerYearLimit + 1).fill(upperYearLimit).map((val, i) => {
const year = val - i;
return (
<option key={year} value={year}>
{year}
{showMonthAndYearPickers ? (
<span className={styles.monthAndYearPickers}>
<span className={styles.monthPicker}>
<select
value={focusedDate.getMonth()}
onChange={e => changeShownDate(e.target.value, 'setMonth')}>
{locale.localize.months().map((month, i) => (
<option key={i} value={i}>
{month}
</option>
);
})}
</select>
))}
</select>
</span>
<span className={styles.monthAndYearDivider} />
<span className={styles.yearPicker}>
<select
value={focusedDate.getFullYear()}
onChange={e => changeShownDate(e.target.value, 'setYear')}>
{new Array(upperYearLimit - lowerYearLimit + 1)
.fill(upperYearLimit)
.map((val, i) => {
const year = val - i;
return (
<option key={year} value={year}>
{year}
</option>
);
})}
</select>
</span>
</span>
) : (
<span className={styles.monthAndYearPickers}>
{locale.localize.months()[focusedDate.getMonth()]} {focusedDate.getFullYear()}
</span>
</span>
)}
{showMonthArrow ? (
<button
type="button"
Expand Down Expand Up @@ -447,6 +455,7 @@ class Calendar extends PureComponent {

Calendar.defaultProps = {
showMonthArrow: true,
showMonthAndYearPickers: true,
classNames: {},
locale: defaultLocale,
ranges: [],
Expand All @@ -469,6 +478,7 @@ Calendar.defaultProps = {

Calendar.propTypes = {
showMonthArrow: PropTypes.bool,
showMonthAndYearPickers: PropTypes.bool,
minDate: PropTypes.object,
maxDate: PropTypes.object,
date: PropTypes.object,
Expand Down