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

[Image with Text] Add ambient movement to image #2385

Merged
merged 9 commits into from
Mar 20, 2023
12 changes: 12 additions & 0 deletions locales/en.default.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,18 @@
},
"label": "Content layout"
},
"animations": {
"content": "Animations"
},
"image_behavior": {
"options__1": {
"label": "None"
},
"options__2": {
"label": "Ambient movement"
},
"label": "Image behavior"
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted in #2383 (comment), it might make sense to have these strings be global since they're re-used across a few Sections.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noting that after conferring with @kmeleta, I've updated this to use new strings declared in sections.all.animation (Commits 5fb7ea5 and fd8b916). We'll be using these for Image Banner, Image with Text, and Slideshow, so this cuts down on duplicate code.

The only new consideration here is just that we should focus on merging this before #2383, since that PR will also need to use these global strings.

"mobile_content_alignment": {
"options__1": {
"label": "Left"
Expand Down
41 changes: 35 additions & 6 deletions sections/image-with-text.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,29 @@
<div class="image-with-text__grid grid grid--gapless grid--1-col grid--{% if section.settings.desktop_image_width == 'medium' %}2-col-tablet{% else %}3-col-tablet{% endif %}{% if section.settings.layout == 'text_first' %} image-with-text__grid--reverse{% endif %}">
<div class="image-with-text__media-item image-with-text__media-item--{{ section.settings.desktop_image_width }} image-with-text__media-item--{{ section.settings.desktop_content_position }} grid__item">
<div
class="image-with-text__media image-with-text__media--{{ section.settings.height }} gradient color-{{ section.settings.color_scheme }} global-media-settings {% if section.settings.image != blank %}media{% else %}image-with-text__media--placeholder placeholder{% endif %}"
class="image-with-text__media image-with-text__media--{{ section.settings.height }} gradient color-{{ section.settings.color_scheme }} global-media-settings {% if section.settings.image != blank %}media{% else %}image-with-text__media--placeholder placeholder{% endif %}{% if section.settings.image_behavior != 'none' %} animate--{{ section.settings.image_behavior }}{% endif %}"
{% if section.settings.height == 'adapt' and section.settings.image != blank %}
style="padding-bottom: {{ 1 | divided_by: section.settings.image.aspect_ratio | times: 100 }}%;"
{% endif %}
>
{%- if section.settings.image != blank -%}
{%- capture sizes -%}
(min-width: {{ settings.page_width }}px) {{ settings.page_width | minus: 100 | divided_by: 2 }}px,
(min-width: 750px) calc((100vw - 130px) / 2), calc((100vw - 50px) / 2)
{%- endcapture -%}
{%- if section.settings.image_behavior == 'ambient' -%}
{%- assign widths = '198, 432, 642, 900, 1284, 1800' -%}
{%- capture sizes -%}
(min-width: {{ settings.page_width }}px) {{ settings.page_width | minus: 100 | divided_by: 1.6667 }}px,
(min-width: 750px) calc((100vw - 130px) / 1.667), calc((100vw - 50px) / 1.667)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 1.6667 number here is admittedly a little weird. I could alternatively do calc(((100vw - 50px) / 2) * 1.2) and get the same result if we think that's easier to read.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is easier to read 😅 I'm switching it in my PR for collage's ambient movement

{%- endcapture -%}
{%- else -%}
{%- assign widths = '165, 360, 535, 750, 1070, 1500' -%}
{%- capture sizes -%}
(min-width: {{ settings.page_width }}px) {{ settings.page_width | minus: 100 | divided_by: 2 }}px,
(min-width: 750px) calc((100vw - 130px) / 2), calc((100vw - 50px) / 2)
{%- endcapture -%}
{%- endif -%}
{{
section.settings.image
| image_url: width: 1500
| image_tag: loading: 'lazy', sizes: sizes, widths: '165, 360, 535, 750, 1070, 1500'
| image_tag: loading: 'lazy', sizes: sizes, widths: widths
}}
{%- else -%}
{{ 'image' | placeholder_svg_tag: 'placeholder-svg' }}
Expand Down Expand Up @@ -243,6 +252,26 @@
"default": "background-1",
"label": "t:sections.all.colors.label"
},
{
"type": "header",
"content": "t:sections.image-with-text.settings.animations.content"
},
{
"type": "select",
"id": "image_behavior",
"options": [
{
"value": "none",
"label": "t:sections.image-with-text.settings.image_behavior.options__1.label"
},
{
"value": "ambient",
"label": "t:sections.image-with-text.settings.image_behavior.options__2.label"
}
],
"default": "none",
"label": "t:sections.image-with-text.settings.image_behavior.label"
},
{
"type": "header",
"content": "Mobile layout"
Expand Down