Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Set Common Flatpickr Defaults. (#10766)

Matthew Kennedy3c6b9f491a30
diff --git a/backend/app/assets/javascripts/spree/backend/admin.js b/backend/app/assets/javascripts/spree/backend/admin.js
index a0c5226e83..389eea5eec 100644
--- a/backend/app/assets/javascripts/spree/backend/admin.js
+++ b/backend/app/assets/javascripts/spree/backend/admin.js
@@ -120,7 +120,7 @@ jQuery(function ($) {
$('.js-filterable').each(function () {
var $this = $(this)
- if ($this.val() !== null && $this.val() !== '' && $this.val().length !== 0 && $this.prop('readonly') !== true) {
+ if ($this.val() !== null && $this.val() !== '' && $this.val().length !== 0 && !$this.hasClass('flatpickr-alt-input')) {
var ransackValue, filter
var ransackFieldId = $this.attr('id')
var label = $('label[for="' + ransackFieldId + '"]')
@@ -223,29 +223,26 @@ $.fn.radioControlsVisibilityOfElement = function (dependentElementSelector) {
}
document.addEventListener('DOMContentLoaded', function() {
- var dateFrom = flatpickr('.datePickerFrom', {
+ flatpickr.setDefaults({
altInput: true,
time_24hr: true,
- locale: Spree.translations.flatpickr_locale,
+ altInputClass: 'flatpickr-alt-input',
+ locale: Spree.translations.flatpickr_locale
+ })
+
+ var dateFrom = flatpickr('.datePickerFrom', {
onChange: function(selectedDates) {
dateTo.set('minDate', selectedDates[0])
}
})
var dateTo = flatpickr('.datePickerTo', {
- locale: Spree.translations.flatpickr_locale,
- time_24hr: true,
- altInput: true,
onChange: function(selectedDates) {
dateFrom.set('maxDate', selectedDates[0])
}
})
- flatpickr('.datepicker', {
- locale: Spree.translations.flatpickr_locale,
- time_24hr: true,
- altInput: true
- })
+ flatpickr('.datepicker', { })
})
$(document).ready(function() {
diff --git a/backend/app/assets/stylesheets/spree/backend/global/_mixins.scss b/backend/app/assets/stylesheets/spree/backend/global/_mixins.scss
new file mode 100644
index 0000000000..3426b86448
--- /dev/null
+++ b/backend/app/assets/stylesheets/spree/backend/global/_mixins.scss
@@ -0,0 +1,19 @@
+// Mixin to prefix several properties at once
+
+// EXAMPLE
+// @include prefix((
+// appearance: none,
+// touch-callout: none,
+// user-select: none
+// ), webkit moz ms khtml);
+
+@mixin prefix($declarations, $prefixes: ()) {
+ @each $property, $value in $declarations {
+ @each $prefix in $prefixes {
+ #{'-' + $prefix + '-' + $property}: $value;
+ }
+
+ // Output standard non-prefixed declaration
+ #{$property}: $value;
+ }
+}
diff --git a/backend/app/assets/stylesheets/spree/backend/plugins/_flatpickr.scss b/backend/app/assets/stylesheets/spree/backend/plugins/_flatpickr.scss
index 812ddf22dc..2383a1c124 100644
--- a/backend/app/assets/stylesheets/spree/backend/plugins/_flatpickr.scss
+++ b/backend/app/assets/stylesheets/spree/backend/plugins/_flatpickr.scss
@@ -1,108 +1,113 @@
-// Adaptive icon from calendar to close.
-@mixin swith-appended-icon {
- &:placeholder-shown:not(:focus) + * {
- @content;
- }
-}
-
-input.input {
- -webkit-appearance: none;
- -moz-appearance: none;
- appearance: none;
- background-color: white !important;
-}
+.flatpickr-calendar {
+ // Custom Flatpickr styling for Spree + BS4.
+ .flatpickr-current-month {
+ span.cur-month:hover {
+ background: transparent;
+ }
+ .numInputWrapper {
+ margin-left: 3px;
+ border-radius: $border-radius;
+ overflow: hidden;
+ }
-.flatpickr-current-month .numInputWrapper {
- margin-left: 3px;
- border-radius: $border-radius;
- overflow: hidden;
-}
-.flatpickr-current-month span.cur-month:hover {
- background: transparent;
-}
-.numInputWrapper span.arrowUp {
- border-color: transparent;
- border-radius: 0;
-}
-.numInputWrapper span.arrowDown {
- border-color: transparent;
- border-radius: 0;
-}
+ .flatpickr-monthDropdown-months {
+ @include prefix((
+ appearance: none
+ ), webkit moz ms khtml);
-.input-group {
- input.input{
- @include swith-appended-icon {
- opacity: 0;
+ padding: 0.2em;
+ border-radius: $border-radius;
}
}
-}
-.append_under {
- position: absolute;
- right: 0;
- top: 0;
- z-index: 0;
- height: 100%;
-}
+ .numInputWrapper span.arrowUp {
+ border-color: transparent;
+ border-radius: 0;
+ }
-.flatpickr-day {
- margin: 2px 0;
- border-radius: $border-radius ;
-}
+ .numInputWrapper span.arrowDown {
+ border-color: transparent;
+ border-radius: 0;
+ }
-// Fix Flatpickr bug where things jusy highlight for no reason.
-input.input[readonly] {
- -webkit-touch-callout: none; /* iOS Safari */
- -webkit-user-select: none; /* Safari */
- -khtml-user-select: none; /* Konqueror HTML */
- -moz-user-select: none; /* Old versions of Firefox */
- -ms-user-select: none; /* Internet Explorer/Edge */
- user-select: none; /* Non-prefixed version, currently
- supported by Chrome, Edge, Opera and Firefox */
-}
+ .flatpickr-day {
+ margin: 2px 0;
+ border-radius: $border-radius ;
+ }
+ .flatpickr-months .flatpickr-prev-month:hover svg,
+ .flatpickr-months .flatpickr-next-month:hover svg {
+ fill: $primary;
+ }
-.flatpickr-months .flatpickr-prev-month:hover svg,
-.flatpickr-months .flatpickr-next-month:hover svg {
- fill: $primary;
-}
+ .flatpickr-time {
+ border-radius: 0 0 5px 5px;
+ &:after {
+ display: none;
+ }
+ .numInputWrapper {
+ span {
+ border-color: transparent;
+ border-radius: 0;
+ }
+ }
+ }
-// Force rounded corner for the toggle cal and close icons.
-.input-group >
-.input-group-append:not(:last-child) >
-.force-round {
- z-index: 5;
- border-top-right-radius: $border-radius !important;
- border-bottom-right-radius: $border-radius !important;
+ // Required to stop an opened cal showing above the nav bar.
+ &.open {
+ z-index: $zindex-dropdown;
+ }
}
-.input-group >
-.form-control:not(:first-child), .input-group > .input:not(:first-child) {
- border-top-left-radius: $border-radius !important;
- border-bottom-left-radius: $border-radius !important;
+// Mixin for calendar toggle icon show/hide.
+@mixin swith-appended-icon {
+ &:placeholder-shown:not(:focus) + * {
+ @content;
+ }
}
-div.flatpickr-calendar.open {
- z-index: $zindex-dropdown;
-}
+.input-group.datePickerFrom,
+.input-group.datePickerTo,
+.input-group.datepicker {
+ input.flatpickr-alt-input[readonly] {
+ // Flatpickr alternate input is read-only,
+ // style it as an active input field.
+ background-color: white !important;
-.flatpickr-time {
- border-radius: 0 0 5px 5px;
- &:after {
- display: none;
- }
- .numInputWrapper {
- span {
- border-color: transparent;
- border-radius: 0;
+ // Fix a bug where occasionally the whole screen will highlight
+ // if you clicked the Flatpcikr input box while moving the cursor.
+ @include prefix((
+ appearance: none,
+ touch-callout: none,
+ user-select: none
+ ), webkit moz ms khtml);
+
+ @include swith-appended-icon {
+ opacity: 0;
}
}
-}
-.flatpickr-current-month .flatpickr-monthDropdown-months {
- -webkit-appearance: none;
- -moz-appearance: none;
- appearance: none;
- padding: 0.2em;
- border-radius: $border-radius;
+ // Required for calendar toggle icon show/hide.
+ .append_under {
+ position: absolute;
+ right: 0;
+ top: 0;
+ z-index: 0;
+ height: 100%;
+ }
+
+ // Styling for calendar toggle icon toggle
+ .input-group-append:not(:last-child) >
+ .force-round {
+ z-index: 5;
+ border-top-right-radius: $border-radius !important;
+ border-bottom-right-radius: $border-radius !important;
+ }
+
+ // Styling for calendar toggle icon toggle
+ .form-control:not(:first-child),
+ .input-group >.flatpickr-alt-input:not(:first-child) {
+ border-top-left-radius: $border-radius !important;
+ border-bottom-left-radius: $border-radius !important;
+ }
}
diff --git a/backend/app/assets/stylesheets/spree/backend/spree_admin.css.scss b/backend/app/assets/stylesheets/spree/backend/spree_admin.css.scss
index f3597dabba..e714b95b97 100644
--- a/backend/app/assets/stylesheets/spree/backend/spree_admin.css.scss
+++ b/backend/app/assets/stylesheets/spree/backend/spree_admin.css.scss
@@ -1,4 +1,5 @@
@import 'global/variables';
+@import 'global/mixins';
@import 'bootstrap';
@import 'glyphicons';
diff --git a/core/lib/spree/testing_support/flatpickr_capybara.rb b/core/lib/spree/testing_support/flatpickr_capybara.rb
index f255566ff0..ae0d0a8b35 100644
--- a/core/lib/spree/testing_support/flatpickr_capybara.rb
+++ b/core/lib/spree/testing_support/flatpickr_capybara.rb
@@ -49,7 +49,7 @@ module Spree
def with_open_flatpickr(label_text)
field_label = find_field(id: label_text, type: :hidden)
- date_field = field_label.sibling('.input')
+ date_field = field_label.sibling('.flatpickr-alt-input')
date_field.click # Open the widget
yield(date_field)