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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Add the ability to set half width sections to pop to full width on small screens.
Matthew Kennedy39a773301877
diff --git a/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_promo.html.erb b/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_promo.html.erbindex eb9aea83b9..83978533bc 100644--- a/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_promo.html.erb+++ b/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_promo.html.erb@@ -17,6 +17,16 @@<%= f.select(:boundary, @cms_section.boundaries, {include_blank: false}, class: 'select2') %><%= f.error_message_on :boundary %><% end %>++ <div class="row">+ <%= f.field_container :full_width_on_small, class: ['form-group col-6'] do %>+ <div class="custom-control custom-checkbox">+ <%= f.check_box :full_width_on_small, class: 'custom-control-input' %>+ <%= f.label :full_width_on_small, Spree.t(:full_width_on_small), class: 'custom-control-label' %>+ <%= f.error_message_on :full_width_on_small %>+ </div>+ <% end %>+ </div></div><div class="col-12 col-md-6"><% @cms_section.build_icon unless @cms_section.icon %>diff --git a/core/app/models/spree/cms/pages/homepage.rb b/core/app/models/spree/cms/pages/homepage.rbindex e3fd0a4ea4..647e945920 100644--- a/core/app/models/spree/cms/pages/homepage.rb+++ b/core/app/models/spree/cms/pages/homepage.rb@@ -1,6 +1,8 @@module Spree::Cms::Pagesclass Homepage < Spree::CmsPage- before_save :empty_slug+ before_create :empty_slug+ after_save :empty_slug+validates :type, uniqueness: { scope: [:store, :locale] }def sections?diff --git a/core/app/models/spree/cms/sections/promo.rb b/core/app/models/spree/cms/sections/promo.rbindex a6e2a54d73..396d731127 100644--- a/core/app/models/spree/cms/sections/promo.rb+++ b/core/app/models/spree/cms/sections/promo.rb@@ -10,7 +10,6 @@ module Spree::Cms::Sectionsend# Overide this per section type-def widths['Half']enddiff --git a/core/app/models/spree/cms_page.rb b/core/app/models/spree/cms_page.rbindex 24127c7c5e..4a23db1a9c 100644--- a/core/app/models/spree/cms_page.rb+++ b/core/app/models/spree/cms_page.rb@@ -47,6 +47,8 @@ module Spreeprivatedef handle_slug+ return if homepage?+self.slug = if slug.blank?title.to_urlelsediff --git a/core/db/migrate/20210512191732_create_spree_cms_pages.rb b/core/db/migrate/20210512191732_create_spree_cms_pages.rbindex c363612f0c..59925acbc9 100644--- a/core/db/migrate/20210512191732_create_spree_cms_pages.rb+++ b/core/db/migrate/20210512191732_create_spree_cms_pages.rb@@ -14,5 +14,6 @@ class CreateSpreeCmsPages < ActiveRecord::Migration[5.2]t.timestampsend+ add_index :spree_cms_pages, :slugendenddiff --git a/core/db/migrate/20210514204251_create_spree_cms_sections.rb b/core/db/migrate/20210514204251_create_spree_cms_sections.rbindex db500b9451..21d23b2267 100644--- a/core/db/migrate/20210514204251_create_spree_cms_sections.rb+++ b/core/db/migrate/20210514204251_create_spree_cms_sections.rb@@ -7,7 +7,7 @@ class CreateSpreeCmsSections < ActiveRecord::Migration[5.2]t.column :button_text, :stringt.column :content, :textt.column :width, :string- t.column :width_small, :string+ t.column :full_width_on_small, :boolean, default: falset.column :boundary, :stringt.column :type, :stringt.column :destination, :string@@ -19,5 +19,6 @@ class CreateSpreeCmsSections < ActiveRecord::Migration[5.2]t.timestampsend+ add_index :spree_cms_sections, :positionendenddiff --git a/frontend/app/assets/stylesheets/spree/frontend/views/spree/home/index.scss b/frontend/app/assets/stylesheets/spree/frontend/views/spree/home/index.scssindex e7f7d1bf00..b2081e12d4 100644--- a/frontend/app/assets/stylesheets/spree/frontend/views/spree/home/index.scss+++ b/frontend/app/assets/stylesheets/spree/frontend/views/spree/home/index.scss@@ -283,6 +283,7 @@}}+.full-width {width: 100vw;position: relative;@@ -292,8 +293,8 @@margin-right: -50vw;}-aside {- .full-width {+aside.cms_half_section {+ .full-width {width: calc(50vw - #{$grid-gutter-width / 2});position: relative;left: 100%;@@ -313,3 +314,49 @@ aside {}}}++aside.half_section_on_md_up {+ .full-width { /* stylelint-disable-line no-descending-specificity */+ width: 100vw;+ position: relative;+ left: 50%;+ right: 50%;+ margin-left: -50vw;+ margin-right: -50vw;+ }++ &:nth-of-type(even) {+ .full-width {+ width: 100vw;+ position: relative;+ left: 50%;+ right: 50%;+ margin-left: -50vw;+ margin-right: -50vw;+ }+ }+}++@include media-breakpoint-up(md) {+ aside.half_section_on_md_up {+ .full-width {+ width: calc(50vw - #{$grid-gutter-width / 2});+ position: relative;+ left: 100%;+ right: 100%;+ margin-left: calc(-50vw + #{$grid-gutter-width / 2});+ margin-right: 0;+ }++ &:nth-of-type(even) {+ .full-width {+ width: calc(50vw - #{$grid-gutter-width / 2});+ position: relative;+ left: 0;+ right: 100%;+ margin-left: 0vw;+ margin-right: calc(-50vw + #{$grid-gutter-width / 2});+ }+ }+ }+}diff --git a/frontend/app/helpers/spree/cms_pages_helper.rb b/frontend/app/helpers/spree/cms_pages_helper.rbindex 16077b7b05..e39152823b 100644--- a/frontend/app/helpers/spree/cms_pages_helper.rb+++ b/frontend/app/helpers/spree/cms_pages_helper.rb@@ -7,24 +7,45 @@ module Spreedef build_section(section)preview_type = section.type.parameterize(separator: '_')- case section.width- when 'Half'- element = 'aside'- css_width = 'col-6 cms_half_section'- when 'Full'- element = 'div'- css_width = 'col-12 cms_full_section'+ if section.full_width_on_small+ case section.width+ when 'Half'+ element = 'aside'+ css_width = 'col-12 col-md-6 cms_half_section half_section_on_md_up'+ when 'Full'+ element = 'div'+ css_width = 'col-12 cms_full_section'+ else+ element = 'div'+ css_width = ''+ end++ boundary = case section.boundary+ when 'Screen'+ 'full-width '+ else+ ''+ endelse- element = 'div'- css_width = ''- end+ case section.width+ when 'Half'+ element = 'aside'+ css_width = 'col-6 cms_half_section'+ when 'Full'+ element = 'div'+ css_width = 'col-12 cms_full_section'+ else+ element = 'div'+ css_width = ''+ end- boundary = case section.boundary- when 'Screen'- 'full-width'- else- ''- end+ boundary = case section.boundary+ when 'Screen'+ 'full-width'+ else+ ''+ end+ endrender "spree/shared/cms/sections/#{preview_type}", section: section,width: css_width,