Skip to content

Commit

Permalink
Added prop and tests for custom arrow icon
Browse files Browse the repository at this point in the history
  • Loading branch information
JemarJones committed Jan 31, 2017
1 parent 0bd7072 commit da5968e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/components/DateRangePicker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const defaultProps = {
showClearDates: false,
showDefaultInputIcon: false,
customInputIcon: null,
customArrowIcon: null,
disabled: false,
required: false,
reopenPickerOnClearDates: false,
Expand Down Expand Up @@ -256,6 +257,7 @@ export default class DateRangePicker extends React.Component {
showClearDates,
showDefaultInputIcon,
customInputIcon,
customArrowIcon,
disabled,
required,
phrases,
Expand Down Expand Up @@ -288,6 +290,7 @@ export default class DateRangePicker extends React.Component {
showCaret={!withPortal && !withFullScreenPortal}
showDefaultInputIcon={showDefaultInputIcon}
customInputIcon={customInputIcon}
customArrowIcon={customArrowIcon}
disabled={disabled}
required={required}
reopenPickerOnClearDates={reopenPickerOnClearDates}
Expand Down
6 changes: 5 additions & 1 deletion src/components/DateRangePickerInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const propTypes = {
showCaret: PropTypes.bool,
showDefaultInputIcon: PropTypes.bool,
customInputIcon: PropTypes.node,
customArrowIcon: PropTypes.node,

// i18n
phrases: PropTypes.shape({
Expand Down Expand Up @@ -69,6 +70,7 @@ const defaultProps = {
showCaret: false,
showDefaultInputIcon: false,
customInputIcon: null,
customArrowIcon: null,

// i18n
phrases: {
Expand Down Expand Up @@ -125,10 +127,12 @@ export default class DateRangePickerInput extends React.Component {
showCaret,
showDefaultInputIcon,
customInputIcon,
customArrowIcon,
phrases,
} = this.props;

const inputIcon = customInputIcon || (<CalendarIcon />);
const arrowIcon = customArrowIcon || (<RightArrow />);

return (
<div
Expand Down Expand Up @@ -160,7 +164,7 @@ export default class DateRangePickerInput extends React.Component {
/>

<div className="DateRangePickerInput__arrow">
<RightArrow />
{arrowIcon}
</div>

<DateInput
Expand Down
4 changes: 4 additions & 0 deletions src/components/DateRangePickerInputController.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const propTypes = {
onDatesChange: PropTypes.func,

customInputIcon: PropTypes.node,
customArrowIcon: PropTypes.node,

// i18n
phrases: PropTypes.shape({
Expand Down Expand Up @@ -75,6 +76,7 @@ const defaultProps = {
onDatesChange() {},

customInputIcon: null,
customArrowIcon: null,

// i18n
phrases: {
Expand Down Expand Up @@ -197,6 +199,7 @@ export default class DateRangePickerInputWithHandlers extends React.Component {
showCaret,
showDefaultInputIcon,
customInputIcon,
customArrowIcon,
disabled,
required,
phrases,
Expand Down Expand Up @@ -224,6 +227,7 @@ export default class DateRangePickerInputWithHandlers extends React.Component {
showCaret={showCaret}
showDefaultInputIcon={showDefaultInputIcon}
customInputIcon={customInputIcon}
customArrowIcon={customArrowIcon}
phrases={phrases}
onStartDateChange={this.onStartDateChange}
onStartDateFocus={this.onStartDateFocus}
Expand Down
18 changes: 18 additions & 0 deletions stories/DateRangePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ const TestCustomInputIcon = () => (
</span>
);

const TestCustomArrowIcon = () => (
<span
style={{
border: '1px solid #dce0e0',
backgroundColor: '#fff',
color: '#484848',
padding: '3px',
}}
>
->
</span>
);

class TestWrapper extends React.Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -258,4 +271,9 @@ storiesOf('DateRangePicker', module)
<DateRangePickerWrapper
customInputIcon={<TestCustomInputIcon />}
/>
))
.addWithInfo('with custom arrow icon', () => (
<DateRangePickerWrapper
customArrowIcon={<TestCustomArrowIcon />}
/>
));
10 changes: 10 additions & 0 deletions test/components/DateRangePickerInput_spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ describe('DateRangePickerInput', () => {
});
});

describe('props.customArrowIcon is a React Element', () => {
it('has custom icon', () => {
const wrapper = shallow(
<DateRangePickerInput
customArrowIcon={<span className="custom-arrow-icon" />}
/>);
expect(wrapper.find('.DateRangePickerInput__calendar-icon .custom-arrow-icon'));
});
});

describe('#onClearDatesMouseEnter', () => {
it('sets state.isClearDatesHovered to true', () => {
const wrapper = shallow(<DateRangePickerInput />);
Expand Down

0 comments on commit da5968e

Please sign in to comment.