Skip to content

Commit

Permalink
Better code, embrace padding.
Browse files Browse the repository at this point in the history
The DateTime component as it exists, references a 3rd party library that uses lots of inline styles and hard-coded widths and dimensions.

Having explored various other approaches now, there are only two ways to fix this.

1. Actually add the padding to the component itself. This is the only way to make it work inside popovers when used outside of WordPress.
2. Do a major refactor to include a different datetime library.

In order to move forward, I'm therefore embracing the padding.
  • Loading branch information
jasmussen committed Nov 15, 2019
1 parent 2ead619 commit 36a0ee7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
38 changes: 26 additions & 12 deletions packages/components/src/date-time/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
/*rtl:end:ignore*/

.components-datetime {
padding: $grid-size;
padding: $grid-size-large;

.components-datetime__calendar-help {
padding: $grid-size;
padding: $grid-size-large;

h4 {
margin: 0;
Expand All @@ -18,8 +18,6 @@
.components-datetime__date-help-button {
display: block;
margin-left: auto;
margin-right: $grid-size;
margin-top: 0.5em;
}

fieldset {
Expand All @@ -30,21 +28,33 @@

select,
input {
box-sizing: border-box;
height: 28px;
vertical-align: middle;
padding: 0;
@include input-style__neutral();
}

// Override inherited conflicting styles to be consistent.
select,
input[type="number"],
.components-button {
height: 30px;
margin-top: 0;
margin-bottom: 0;
}
}

.components-datetime__date {
min-height: 236px;
border-top: 1px solid $light-gray-500;
margin-left: -$grid-size;
margin-right: -$grid-size;

// Override external DatePicker styles.
.CalendarMonthGrid {
// The included component contains an arbitrary 13px padding that misaligns things.
margin-left: -13px;
}

.DayPickerNavigation_leftButton__horizontalDefault {
left: 0;
}

.CalendarMonth_caption {
font-size: $default-font-size;
}
Expand Down Expand Up @@ -84,11 +94,15 @@
}

.components-datetime__time {
margin-bottom: 1em;
padding-bottom: $grid-size-large;

fieldset {
margin-top: 0.5em;
position: relative;
margin-bottom: 0.5em;
}

fieldset + fieldset {
margin-bottom: 0;
}

.components-datetime__time-field-am-pm fieldset {
Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/components/post-publish-panel/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
display: none;
}

// The DateTime component has an intrinsic padding in order for the horizontal scrolling to function inside a popover.
// We unset that here when used inline.
.components-datetime {
padding: 0;
}
Expand Down

0 comments on commit 36a0ee7

Please sign in to comment.