Skip to content
Open
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ yarn add react-native-month-selector
| seperatorColor | string | "#b6c3cb" | color of the separators |
| nextIcon | JSX.Element | null | custom react component for the next button |
| prevIcon | JSX.Element | null | custom react component for the prev button |
| emptyPrevNextIcon | JSX.Element | null | custom react component for an empty prev/next button Example: emptyPrevNextIcon={ <View style={{width: 22, margin: 22}} />}
|
| nextText | string | "Next" | custom text for the next button |
| prevText | string | "Prev" | custom text for the prev button |
| containerStyle | ViewStyle | null | custom style for the container |
| yearTextStyle | TextStyle | null | custom style for the year text |
| monthTextStyle | TextStyle | null | custom style of the text for the months |
| monthWidth | number | 40 | custom width and height for months. BorderRadius will be adjusted
| currentMonthTextStyle | TextStyle | null | custom style for the current month text |
| initialView | moment.Moment | moment() | which month should be selected initially |
| onMonthTapped | (month: moment.Moment) => any | (month) => {} | function called when month is pressed |
Expand Down
45 changes: 35 additions & 10 deletions src/MonthSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ interface MonthSelectorProps {
seperatorHeight: number
nextIcon: JSX.Element
prevIcon: JSX.Element
emptyPrevNextIcon: JSX.Element
prevNextIcon: JSX.Element
nextText: string
prevText: string
containerStyle: ViewStyle
yearTextStyle: TextStyle
monthTextStyle: TextStyle
currentMonthTextStyle: TextStyle
monthWidth: number
monthFormat: string
initialView: moment.Moment
onMonthTapped: (month: moment.Moment) => any
Expand Down Expand Up @@ -75,13 +78,15 @@ class MonthSelector extends React.Component<
seperatorHeight: PropTypes.number,
nextIcon: PropTypes.any,
prevIcon: PropTypes.any,
emptyPrevNextIcon: PropTypes.any,
nextText: PropTypes.string,
prevText: PropTypes.string,
containerStyle: PropTypes.any,
yearTextStyle: PropTypes.any,
monthTextStyle: PropTypes.any,
currentMonthTextStyle: PropTypes.any,
monthFormat: PropTypes.string,
monthWidth: PropTypes.number,
initialView: PropTypes.any,
onMonthTapped: PropTypes.func,
onYearChanged: PropTypes.func,
Expand All @@ -105,6 +110,7 @@ class MonthSelector extends React.Component<
seperatorColor: "#b6c3cb",
nextIcon: null,
prevIcon: null,
emptyPrevNextIcon: null,
nextText: "Next",
prevText: "Prev",
containerStyle: null,
Expand All @@ -114,6 +120,7 @@ class MonthSelector extends React.Component<
color: "#22ee11",
},
monthTextStyle: { color: "#000" },
monthWidth: 40,
initialView: moment(),
onMonthTapped: month => {},
onYearChanged: year => {},
Expand Down Expand Up @@ -162,12 +169,26 @@ class MonthSelector extends React.Component<
return {}
}

getSelectedMonthWidth() {
if (this.props.monthWidth) {
return {
height: this.props.monthWidth,
width: this.props.monthWidth,
borderRadius: this.props.monthWidth /2,
}
}
else {
return {};
}
}

getMonthActualComponent(month: moment.Moment, isDisabled: boolean = false) {
return (
<View
style={[
isDisabled === true && { flex: 1, alignItems: "center" },
styles.monthStyle,
this.getSelectedMonthWidth(),
this.getSelectedBackgroundColor(month),
]}
>
Expand Down Expand Up @@ -260,23 +281,27 @@ class MonthSelector extends React.Component<
]}
>
<TouchableOpacity onPress={() => this.handNextPrevTaps(false)}>
{this.props.prevIcon ? (
this.props.prevIcon
) : (
<Text>{this.props.prevText}</Text>
)}
{this.props.emptyPrevNextIcon && !this.isYearEnabled(false) ? (
this.props.emptyPrevNextIcon
) : this.props.prevIcon ? (
this.props.prevIcon
) : (
<Text>{this.props.prevText}</Text>
)}
</TouchableOpacity>
<View style={styles.yearViewStyle}>
<Text style={this.props.yearTextStyle}>
{this.state.initialView.format("YYYY")}
</Text>
</View>
<TouchableOpacity onPress={() => this.handNextPrevTaps(true)}>
{this.props.nextIcon ? (
this.props.nextIcon
) : (
<Text>{this.props.nextText}</Text>
)}
{this.props.emptyPrevNextIcon && !this.isYearEnabled(true) ? (
this.props.emptyPrevNextIcon
) :this.props.nextIcon ? (
this.props.nextIcon
) : (
<Text>{this.props.nextText}</Text>
)}
</TouchableOpacity>
</View>
)
Expand Down