diff --git a/README.md b/README.md index fd265a5c4..edf3fba83 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,7 @@ Property | type | Default Value | Desctiptio -------------------------------------|-----------|------------------|----------------------------------------------------------------- locale | Object | enUS from locale | you can view full list from [here](https://github.com/Adphorus/react-date-range/tree/next/src/locale/index.js). Locales directly exported from [`date-fns/locales`](https://date-fns.org/v2.0.0-alpha.7/docs/I18n#supported-languages). className | String | | wrapper classname +narrow | Boolean | | Adjust layout for mobile 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 @@ -119,7 +120,7 @@ onChange(Calendar) | Func | | callback f onChange(DateRange) | Func | | callback function for range changes. fn(changes). changes contains changed ranges with new `startDate`/`endDate` properties. color(Calendar) | String | `#3d91ff` | defines color for selected date in Calendar date(Calendar) | Date | | date value for Calendar -showDateDisplay(DateRange) | Boolean | true | show/hide selection display row. Uses `dateDisplayFormat` for formatter +showDateDisplay(DateRange) | Boolean | false | show/hide selection display row. Uses `dateDisplayFormat` for formatter onShownDateChange(DateRange,Calendar)| Function | | Callback function that is called when the shown date changes initialFocusedRange(DateRange) | Object | | Initial value for focused range. See `focusedRange` for usage. focusedRange(DateRange) | Object | | It defines which range and step are focused. Common initial value is `[0, 0]`; first value is index of ranges, second one is which step on date range(startDate or endDate). diff --git a/demo/src/components/Main.js b/demo/src/components/Main.js index feb0a65be..342cb14bb 100644 --- a/demo/src/components/Main.js +++ b/demo/src/components/Main.js @@ -5,9 +5,7 @@ import { format, addDays } from 'date-fns'; import Section from './Section'; function renderStaticRangeLabel(staticRange) { - return ( - - ); + return ; } class CustomStaticRangeLabelContent extends React.Component { @@ -18,14 +16,11 @@ class CustomStaticRangeLabelContent extends React.Component { currentDateString: Date(), }; - this.intervalId = setInterval( - () => { - this.setState({ - currentDateString: Date(), - }); - }, - 1000 - ); + this.intervalId = setInterval(() => { + this.setState({ + currentDateString: Date(), + }); + }, 1000); } componentWillUnmount() { @@ -222,6 +217,33 @@ export default class Main extends Component { +
+
+ + +
+
+ +
+
+
-
+
-
+
({ - startDate: new Date(), - endDate: new Date(), - }), - isSelected() { - return ( - true - ); + staticRanges={[ + { + label: 'Hoy', + hasCustomRendering: true, + range: () => ({ + startDate: new Date(), + endDate: new Date(), + }), + isSelected() { + return true; + }, }, - }]} + ]} onChange={this.handleRangeChange.bind(this, 'definedRange')} className={'centered'} - > - + />
@@ -413,18 +434,18 @@ export default class Main extends Component { ({ - startDate: new Date(), - endDate: new Date(), - }), - isSelected() { - return ( - true - ); + staticRanges={[ + { + hasCustomRendering: true, + range: () => ({ + startDate: new Date(), + endDate: new Date(), + }), + isSelected() { + return true; + }, }, - }]} + ]} onChange={this.handleRangeChange.bind(this, 'definedRange')} className={'centered'} /> diff --git a/src/components/Calendar.js b/src/components/Calendar.js index 6e2ca898d..55e013d90 100644 --- a/src/components/Calendar.js +++ b/src/components/Calendar.js @@ -30,8 +30,9 @@ import { DateDisplay, CalendarWrapper, Months, - InfiniteMonthsWrapper, + InfiniteMonthsList, DateDisplayItem, + InfiniteMonthsWrapper, } from './styles/Calendar.styled.js'; import { WeekDays, WeekDay } from './styles/Month.styled.js'; import MonthAndYearPicker from './MonthAndYearPicker.js'; @@ -319,9 +320,9 @@ class Calendar extends PureComponent { {showDateDisplay && this.renderDateDisplay()} {navigatorRenderer(focusedDate, this.changeShownDate, this.props)} {scroll.enabled ? ( -
+ {isVertical && this.renderWeekdays(this.dateOptions)} - onPreviewChange && onPreviewChange()} @@ -370,8 +371,8 @@ class Calendar extends PureComponent { ); }} /> - -
+ + ) : ( {months.map((monthStep, i) => ( @@ -410,7 +411,7 @@ Calendar.defaultProps = { focusedRange: [0, 0], dateDisplayFormat: 'MMM D, YYYY', monthDisplayFormat: 'MMM YYYY', - showDateDisplay: true, + showDateDisplay: false, showPreview: true, displayMode: 'date', months: 1, diff --git a/src/components/DateRange.js b/src/components/DateRange.js index 8e49a5aaa..39bfa026a 100644 --- a/src/components/DateRange.js +++ b/src/components/DateRange.js @@ -115,6 +115,14 @@ class DateRange extends Component { } render() { + const { narrow, ...props } = this.props; + let { direction, months, scroll } = props; + if (narrow) { + direction = 'vertical'; + months = 1; + scroll = { enabled: true }; + } + return ( { this.updatePreview(value ? this.calcNewSelection(value) : null); }} - {...this.props} + {...props} + months={months} + scroll={scroll} + direction={direction} displayMode="dateRange" className={this.props.className} onChange={this.setSelection} @@ -146,6 +157,7 @@ DateRange.defaultProps = { DateRange.propTypes = { ...Calendar.propTypes, + narrow: PropTypes.bool, onChange: PropTypes.func, onRangeFocusChange: PropTypes.func, className: PropTypes.string, diff --git a/src/components/DateRangePicker.js b/src/components/DateRangePicker.js index 669da4622..fbf9f39ac 100644 --- a/src/components/DateRangePicker.js +++ b/src/components/DateRangePicker.js @@ -16,12 +16,14 @@ class DateRangePicker extends Component { const { focusedRange } = this.state; return ( - this.dateRange.updatePreview(value)} - {...this.props} - range={this.props.ranges[focusedRange[0]]} - /> + {!this.props.narrow && ( + this.dateRange.updatePreview(value)} + {...this.props} + range={this.props.ranges[focusedRange[0]]} + /> + )} this.setState({ focusedRange })} focusedRange={focusedRange} diff --git a/src/components/styles/Calendar.styled.js b/src/components/styles/Calendar.styled.js index 108c3116c..e56a0bbba 100644 --- a/src/components/styles/Calendar.styled.js +++ b/src/components/styles/Calendar.styled.js @@ -1,4 +1,5 @@ import styled, { css } from 'styled-components'; +import { WeekDays } from './Month.styled'; const marginHorizontal = css` margin: 0 5px; @@ -82,8 +83,54 @@ export const Months = styled.div` `; export const InfiniteMonthsWrapper = styled.div` + position: relative; + + &:before, + &:after { + content: ''; + position: absolute; + width: 100%; + height: 10px; + left: 0; + z-index: 10; + } + + &:before { + background: linear-gradient(rgba(0, 0, 0, 0.08), transparent); + top: 2.667em; /* WeekDays height */ + } + + &:after { + background: linear-gradient(transparent, rgba(0, 0, 0, 0.08)); + bottom: 0; + } +`; + +export const InfiniteMonthsList = styled.div` + position: relative; overflow: auto; ${props => (props.direction === 'vertical' ? monthsVertical : monthsHorizontal)}; + + > div { + &:before, + &:after { + content: ''; + height: 10px; + width: 100%; + left: 0; + position: absolute; + background: #fff; + z-index: 11; + } + + &:before { + top: 0; + } + + &:after { + bottom: 0; + } + } `; //