Skip to content

Commit 9246842

Browse files
committed
Adding 'dayFormatter' and 'markToday' props; editing reservations commets
1 parent 93fd2c3 commit 9246842

File tree

4 files changed

+52
-30
lines changed

4 files changed

+52
-30
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,3 +672,11 @@
672672
### Change
673673

674674
- Day components refactor.
675+
676+
## [1.505.0] - 2020-12-17
677+
678+
### Added
679+
680+
- AgendaList - adding 'dayFormatter' prop to custom format section header's title.
681+
- adding 'markToday' prop to control the "TODAY, ..." string appearance.
682+
- passing 'title' as a param for 'renderSectionHeader' callback.

src/agenda/reservation-list/index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,28 @@ class ReservationList extends Component {
1919
reservations: PropTypes.object,
2020
selectedDay: PropTypes.instanceOf(XDate),
2121
topDay: PropTypes.instanceOf(XDate),
22-
/** Show items only for the selected day. Default = false. */
22+
/** Show items only for the selected day. Default = false */
2323
showOnlySelectedDayItems: PropTypes.bool,
24-
/** callback that gets called when day changes while scrolling agenda list. */
24+
/** callback that gets called when day changes while scrolling agenda list */
2525
onDayChange: PropTypes.func,
26-
/** specify what should be rendered instead of ActivityIndicator. */
26+
/** specify what should be rendered instead of ActivityIndicator */
2727
renderEmptyData: PropTypes.func,
2828

2929
/** onScroll ListView event */
3030
onScroll: PropTypes.func,
31-
/** Called when the user begins dragging the agenda list. **/
31+
/** Called when the user begins dragging the agenda list **/
3232
onScrollBeginDrag: PropTypes.func,
33-
/** Called when the user stops dragging the agenda list. **/
33+
/** Called when the user stops dragging the agenda list **/
3434
onScrollEndDrag: PropTypes.func,
35-
/** Called when the momentum scroll starts for the agenda list. **/
35+
/** Called when the momentum scroll starts for the agenda list **/
3636
onMomentumScrollBegin: PropTypes.func,
37-
/** Called when the momentum scroll stops for the agenda list. **/
37+
/** Called when the momentum scroll stops for the agenda list **/
3838
onMomentumScrollEnd: PropTypes.func,
39-
/** A RefreshControl component, used to provide pull-to-refresh functionality for the ScrollView. */
39+
/** A RefreshControl component, used to provide pull-to-refresh functionality for the ScrollView */
4040
refreshControl: PropTypes.element,
41-
/** Set this true while waiting for new data from a refresh. */
41+
/** Set this true while waiting for new data from a refresh */
4242
refreshing: PropTypes.bool,
43-
/** If provided, a standard RefreshControl will be added for "Pull to Refresh" functionality. Make sure to also set the refreshing prop correctly. */
43+
/** If provided, a standard RefreshControl will be added for "Pull to Refresh" functionality. Make sure to also set the refreshing prop correctly */
4444
onRefresh: PropTypes.func
4545
};
4646

src/agenda/reservation-list/reservation.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ class Reservation extends Component {
1313

1414
static propTypes = {
1515
item: PropTypes.any,
16-
/** Specify theme properties to override specific styles for reservation parts. Default = {}. */
16+
/** Specify theme properties to override specific styles for reservation parts. Default = {} */
1717
theme: PropTypes.object,
18-
/** specify your item comparison function for increased performance. */
18+
/** specify your item comparison function for increased performance */
1919
rowHasChanged: PropTypes.func,
20-
/** specify how each date should be rendered. day can be undefined if the item is not first in that day. */
20+
/** specify how each date should be rendered. day can be undefined if the item is not first in that day */
2121
renderDay: PropTypes.func,
22-
/** specify how each item should be rendered in agenda. */
22+
/** specify how each item should be rendered in agenda */
2323
renderItem: PropTypes.func,
24-
/** specify how empty date content with no items should be rendered. */
24+
/** specify how empty date content with no items should be rendered */
2525
renderEmptyDate: PropTypes.func
2626
};
2727

src/expandableCalendar/agendaList.js

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,21 @@ class AgendaList extends Component {
2424
...SectionList.propTypes,
2525
/** day format in section title. Formatting values: http://arshaw.com/xdate/#Formatting */
2626
dayFormat: PropTypes.string,
27+
/** a function to custom format the section header's title */
28+
dayFormatter: PropTypes.func,
2729
/** whether to use moment.js for date string formatting
2830
* (remember to pass 'dayFormat' with appropriate format, like 'dddd, MMM D') */
2931
useMoment: PropTypes.bool,
32+
/** whether to mark today's title with the "Today, ..." string. Default = true */
33+
markToday: PropTypes.bool,
3034
/** style passed to the section view */
3135
sectionStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array])
3236
}
3337

3438
static defaultProps = {
3539
dayFormat: 'dddd, MMM d',
36-
stickySectionHeadersEnabled: true
40+
stickySectionHeadersEnabled: true,
41+
markToday: true
3742
}
3843

3944
constructor(props) {
@@ -134,35 +139,44 @@ class AgendaList extends Component {
134139
}
135140

136141
renderSectionHeader = ({section: {title}}) => {
137-
if (this.props.renderSectionHeader) {
138-
return this.props.renderSectionHeader();
142+
const {renderSectionHeader, dayFormatter, dayFormat, useMoment, markToday, sectionStyle} = this.props;
143+
144+
if (renderSectionHeader) {
145+
return renderSectionHeader(title);
139146
}
140147

141148
let sectionTitle = title;
142149

143-
if (this.props.dayFormat) {
144-
let date;
145-
let today;
146-
147-
if (this.props.useMoment) {
148-
date = moment(title).format(this.props.dayFormat);
149-
today = moment().format(this.props.dayFormat);
150+
if (dayFormatter) {
151+
sectionTitle = dayFormatter(title);
152+
} else if (dayFormat) {
153+
if (useMoment) {
154+
sectionTitle = moment(title).format(dayFormat);
150155
} else {
151-
date = XDate(title).toString(this.props.dayFormat);
152-
today = XDate().toString(this.props.dayFormat);
156+
sectionTitle = XDate(title).toString(dayFormat);
153157
}
158+
}
154159

160+
if (markToday) {
155161
const todayString = XDate.locales[XDate.defaultLocale].today || commons.todayString;
156-
sectionTitle = date === today ? `${todayString}, ${date}` : date;
162+
const today = XDate().toString("yyyy-MM-d");
163+
sectionTitle = title === today ? `${todayString}, ${sectionTitle}` : sectionTitle;
157164
}
158165

159166
return (
160-
<Text allowFontScaling={false} style={[this.style.sectionText, this.props.sectionStyle]} onLayout={this.onHeaderLayout}>{sectionTitle}</Text>
167+
<Text
168+
allowFontScaling={false}
169+
style={[this.style.sectionText, sectionStyle]}
170+
onLayout={this.onHeaderLayout}
171+
>
172+
{sectionTitle}
173+
</Text>
161174
);
162175
}
163176

164177
keyExtractor = (item, index) => {
165-
return _.isFunction(this.props.keyExtractor) ? this.props.keyExtractor(item, index) : String(index);
178+
const {keyExtractor} = this.props;
179+
return _.isFunction(keyExtractor) ? keyExtractor(item, index) : String(index);
166180
}
167181

168182
render() {

0 commit comments

Comments
 (0)