Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UX: improves change-timestamp modal datepicker #7771

Merged
merged 1 commit into from
Jun 24, 2019
Merged
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
26 changes: 12 additions & 14 deletions app/assets/javascripts/discourse/components/date-picker.js.es6
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
on
} from "ember-addons/ember-computed-decorators";

const DATE_FORMAT = "YYYY-MM-DD";

export default Ember.Component.extend({
classNames: ["date-picker-wrapper"],
_picker: null,
Expand All @@ -17,23 +19,22 @@ export default Ember.Component.extend({

@on("didInsertElement")
_loadDatePicker() {
const container = this.element.querySelector(`#${this.containerId}`);

if (this.site.mobileView) {
this._loadNativePicker(container);
this._loadNativePicker();
} else {
const container = document.getElementById(this.containerId);
this._loadPikadayPicker(container);
}
},

_loadPikadayPicker(container) {
loadScript("/javascripts/pikaday.js").then(() => {
Ember.run.next(() => {
const default_opts = {
const options = {
field: this.element.querySelector(".date-picker"),
container: container || this.element,
container: container || null,
bound: container === null,
format: "YYYY-MM-DD",
format: DATE_FORMAT,
firstDay: 1,
i18n: {
previousMonth: I18n.t("dates.previous_month"),
Expand All @@ -45,14 +46,13 @@ export default Ember.Component.extend({
onSelect: date => this._handleSelection(date)
};

this._picker = new Pikaday(Object.assign(default_opts, this._opts()));
this._picker = new Pikaday(Object.assign(options, this._opts()));
});
});
},

_loadNativePicker(container) {
const wrapper = container || this.element;
const picker = wrapper.querySelector("input.date-picker");
_loadNativePicker() {
const picker = this.element.querySelector("input.date-picker");
picker.onchange = () => this._handleSelection(picker.value);
picker.hide = () => {
/* do nothing for native */
Expand All @@ -64,12 +64,10 @@ export default Ember.Component.extend({
},

_handleSelection(value) {
const formattedDate = moment(value).format("YYYY-MM-DD");
const formattedDate = moment(value).format(DATE_FORMAT);

if (!this.element || this.isDestroying || this.isDestroyed) return;

this._picker && this._picker.hide();

if (this.onSelect) {
this.onSelect(formattedDate);
}
Expand All @@ -79,8 +77,8 @@ export default Ember.Component.extend({
_destroy() {
if (this._picker) {
this._picker.destroy();
this._picker = null;
}
this._picker = null;
},

@computed()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@
</p>

<form>
{{date-picker-past value=date containerId="date-container"}}
{{date-picker-past
value=(unbound date)
containerId="date-container"
onSelect=(action (mut date))}}

{{input type="time" value=time}}
</form>

<div id="date-container" />
<div id="date-container"></div>
{{/d-modal-body}}

<div class="modal-footer change-timestamp-footer">
<button class="btn btn-primary" disabled={{buttonDisabled}} {{action "changeTimestamp"}}>{{buttonTitle}}</button>
{{d-button
class="btn-primary"
disabled=buttonDisabled
action=(action "changeTimestamp")
translatedLabel=buttonTitle}}
</div>
28 changes: 23 additions & 5 deletions app/assets/stylesheets/common/base/modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -426,13 +426,35 @@
}

.modal .modal-body.change-timestamp {
overflow-y: scroll;
#date-container {
.pika-single {
width: 100%;
box-sizing: border-box;
display: flex;
justify-content: center;
}
}

form {
display: flex;

.date-picker-wrapper,
input[type="time"] {
width: 50%;
}

.date-picker-wrapper {
display: flex;
flex: 1;

.date-picker {
flex: 1;
}
}

input.date-picker,
input[type="time"] {
text-align: left;
margin: 0;
}
}
Expand All @@ -453,10 +475,6 @@
.date-picker-wrapper {
min-width: 130px;
margin-right: 0.5em;

.date-picker {
height: 100%;
}
}

input[type="time"] {
Expand Down
5 changes: 0 additions & 5 deletions app/assets/stylesheets/mobile/modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,3 @@
.modal-inner-container {
margin-bottom: 20px;
}

.change-timestamp-footer .btn-primary {
float: right;
margin-right: 5px;
}