Skip to content

Commit

Permalink
Updates Media Date Range to utilise “mobile first” approach to layout
Browse files Browse the repository at this point in the history
On screens smaller than 480px:

* removes selected date text on button (leaving just an icon)
* displays only 1 month of calendar at a time (instead of two)

Adds tests to cover this.
  • Loading branch information
jakejones1984 committed Jul 1, 2018
1 parent 520c446 commit bf27848
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 11 deletions.
1 change: 1 addition & 0 deletions assets/stylesheets/sections/media.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@import '../shared/mixins/clear-text';
@import '../shared/mixins/heading';
@import '../shared/mixins/long-content-fade';
@import '../shared/mixins/hide-content-accessibly';

@import '../shared/colors';
@import '../shared/extends';
Expand Down
6 changes: 3 additions & 3 deletions client/my-sites/media-library/media-date-range.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export class MediaDateRange extends Component {
from: this.momentDateToNative( this.state.startDate ),
to: this.momentDateToNative( this.state.endDate ),
} }
numberOfMonths={ 2 }
numberOfMonths={ window.matchMedia( '(min-width: 480px)' ).matches ? 2 : 1 }
calendarViewDate={ this.momentDateToNative( this.state.startDate ) }
disabledDays={ [
{
Expand Down Expand Up @@ -264,8 +264,8 @@ export class MediaDateRange extends Component {
onClick={ this.togglePopover }
compact
>
<Gridicon className="media-library__date-range-icon" icon="calendar" />
<span>
<Gridicon className="media-library__date-range-btn-icon" icon="calendar" />
<span className="media-library__date-range-btn-text">
{ this.dateToHumanReadable( this.state.startDate ) }
-
{ this.dateToHumanReadable( this.state.endDate ) }
Expand Down
34 changes: 28 additions & 6 deletions client/my-sites/media-library/media-date-range.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,29 @@
}
}

.media-library__date-range-icon {
.media-library__date-range-btn-icon {
margin-right: 5px;
}

.media-library__date-range-btn-text {
@include hide-content-accessibly;

@include breakpoint( '>480px' ) {
clip: default;
height: auto;
overflow: visible;
position: static;
width: auto;
}
}

.media-library__date-range-popover-inner {
padding: 15px;
width: 400px;
max-width: 100%;
max-width: 90%;

@include breakpoint( '>480px' ) {
width: 400px;
}
}

.media-library__date-range-popover-header {
Expand All @@ -56,14 +71,21 @@

.DayPicker-wrapper {
display: flex;
flex-direction: column;

@include breakpoint( '>480px' ) {
flex-direction: row;
}
}

.DayPicker-Month {
margin-right: 1em;

&:last-child {
margin-left: 1em;
margin-right: 0;
@include breakpoint( '>480px' ) {
&:last-child {
margin-left: 1em;
margin-right: 0;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ exports[`MediaDateRange should render 1`] = `
type="button"
>
<t
className="media-library__date-range-icon"
className="media-library__date-range-btn-icon"
icon="calendar"
size={24}
/>
<span>
<span
className="media-library__date-range-btn-text"
>
01/05/2018
-
01/06/2018
Expand Down
19 changes: 19 additions & 0 deletions client/my-sites/media-library/test/media-data-range.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ describe( 'MediaDateRange', () => {
let fixedEndDate;

beforeEach( () => {
Object.defineProperty( window, 'matchMedia', {
value: jest.fn( () => {
return { matches: true };
} ),
} );

// Note: forces locale to UK date format to make
// test easier to assert again
moment.locale( [ 'en-GB' ] );
Expand Down Expand Up @@ -174,6 +180,19 @@ describe( 'MediaDateRange', () => {
);
} );

test( 'should show 1 month calendar view on screens <480px', () => {
Object.defineProperty( window, 'matchMedia', {
value: jest.fn( () => {
return { matches: false };
} ),
} );

const wrapper = shallow( <MediaDateRange moment={ moment } /> );
const datePicker = wrapper.find( DatePicker );

expect( datePicker.props().numberOfMonths ).toEqual( 1 );
} );

describe( 'text inputs', () => {
let startDate;
let endDate;
Expand Down

0 comments on commit bf27848

Please sign in to comment.