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

Rich text updates #1625

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 14 additions & 0 deletions assets/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,16 @@ h5,
word-break: break-word;
}

.hxl {
font-size: calc(var(--font-heading-scale) * 5rem);
}

@media only screen and (min-width: 750px) {
.hxl {
font-size: calc(var(--font-heading-scale) * 6.2rem);
}
}

.h0 {
font-size: calc(var(--font-heading-scale) * 4rem);
}
Expand Down Expand Up @@ -553,6 +563,10 @@ table:not([class]) th {
}
}

.left {
text-align: left;
}

Comment on lines +566 to +569
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although this isn't required (text-align: left;) being the default value, it might be used for other elements and for instances where we'd need to override an existing text-align value.

.center {
text-align: center;
}
Expand Down
43 changes: 20 additions & 23 deletions assets/section-rich-text.css
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
.rich-text {
margin-left: auto;
margin-right: auto;
text-align: center;
z-index: 1;
}

.rich-text.rich-text--full-width {
max-width: initial;
width: 100%;
}

.rich-text__blocks {
margin: auto;
/* 2.5rem margin on left & right */
.rich-text__wrapper {
display: flex;
justify-content: center;
width: calc(100% - 5rem / var(--font-body-scale));
}

.rich-text__blocks * {
overflow-wrap: break-word;
}

.rich-text--full-width .rich-text__blocks {
/* 4rem (1.5rem + 2.5rem) margin on left & right */
.rich-text:not(.rich-text--full-width) .rich-text__wrapper {
margin: auto;
width: calc(100% - 8rem / var(--font-body-scale));
}

@media screen and (min-width: 750px) {
.rich-text__blocks {
max-width: 50rem;
.rich-text__wrapper {
width: 100%;
}

.rich-text--full-width .rich-text__blocks {
/* 7.5rem (5rem + 2.5rem) margin on left & right */
width: calc(100% - 15rem);
.rich-text__wrapper--left {
justify-content: flex-start;
}

.rich-text__wrapper--right {
justify-content: flex-end;
}

.rich-text__blocks {
max-width: 60rem;
}
}

Expand All @@ -42,7 +37,9 @@
}
}

/* Blocks */
.rich-text__blocks * {
overflow-wrap: break-word;
}

.rich-text__blocks > * {
margin-top: 0;
Expand Down
58 changes: 57 additions & 1 deletion locales/en.default.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@
},
"options__3": {
"label": "Large"
},
"options__4": {
"label": "Extra large"
}
}
},
Expand Down Expand Up @@ -2206,6 +2209,30 @@
"rich-text": {
"name": "Rich text",
"settings": {
"desktop_content_position": {
"options__1": {
"label": "Left"
},
"options__2": {
"label": "Center"
},
"options__3": {
"label": "Right"
},
"label": "Desktop content position"
},
"content_alignment": {
"options__1": {
"label": "Left"
},
"options__2": {
"label": "Center"
},
"options__3": {
"label": "Right"
},
"label": "Content alignment"
},
"full_width": {
"label": "Make section full width"
}
Expand All @@ -2219,6 +2246,35 @@
}
}
},
"caption": {
"name": "Caption",
"settings": {
"text": {
"label": "Text"
},
"text_style": {
"label": "Text style",
"options__1": {
"label": "Subtitle"
},
"options__2": {
"label": "Uppercase"
}
},
"caption_size": {
"label": "Text size",
"options__1": {
"label": "Small"
},
"options__2": {
"label": "Medium"
},
"options__3": {
"label": "Large"
}
}
}
},
"text": {
"name": "Text",
"settings": {
Expand Down Expand Up @@ -2653,4 +2709,4 @@
}
}
}
}
}
133 changes: 115 additions & 18 deletions sections/rich-text.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,27 @@

<div class="isolate{% unless section.settings.full_width %} page-width{% endunless %}">
<div class="rich-text content-container color-{{ section.settings.color_scheme }} gradient{% if section.settings.full_width %} rich-text--full-width content-container--full-width{% endif %} section-{{ section.id }}-padding">
<div class="rich-text__blocks">
{%- for block in section.blocks -%}
{%- case block.type -%}
{%- when 'heading' -%}
<h2 class="{{ block.settings.heading_size }}" {{ block.shopify_attributes }}>{{ block.settings.heading | escape }}</h2>
{%- when 'text' -%}
<div class="rich-text__text rte" {{ block.shopify_attributes }}>{{ block.settings.text }}</div>
{%- when 'button' -%}
<a{% if block.settings.button_link == blank %} role="link" aria-disabled="true"{% else %} href="{{ block.settings.button_link }}"{% endif %} class="button{% if block.settings.button_style_secondary %} button--secondary{% else %} button--primary{% endif %}" {{ block.shopify_attributes }}>
{{ block.settings.button_label | escape }}
</a>
{%- endcase -%}
{%- endfor -%}
<div class="rich-text__wrapper rich-text__wrapper--{{ section.settings.desktop_content_position }}{% if section.settings.full_width %} page-width{% endif %}">
<div class="rich-text__blocks {{ section.settings.content_alignment }}">
{%- for block in section.blocks -%}
{%- case block.type -%}
{%- when 'heading' -%}
<h2 class="rich-text__heading rte {{ block.settings.heading_size }}" {{ block.shopify_attributes }}>{{ block.settings.heading }}</h2>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll need to update the h2 so that it doesn't include <p> tags for the richtext, to prevent this:

Screenshot

image

Either of the following works but I'll need to confirm if its the solution we want to go with for rich text headings:

<h2 class="rich-text__heading rte {{ block.settings.heading_size }}" {{ block.shopify_attributes }}>{{ block.settings.heading | replace: '<p>', '<span>' | replace: '</p>', '</span>' }}</h2>

Or

<h2 class="rich-text__heading rte {{ block.settings.heading_size }}" {{ block.shopify_attributes }}>{{ block.settings.heading | replace: 'p>', 'span>' }}</h2>
Screenshot

image

Confirmed with: https://validator.w3.org/nu/#textarea

{%- when 'caption' -%}
<p class="rich-text__caption {{ block.settings.text_style }} {{ block.settings.text_style }}--{{ block.settings.text_size }} {{ block.settings.text_style }}" {{ block.shopify_attributes }}>{{ block.settings.caption }}</p>
{%- when 'text' -%}
<div class="rich-text__text rte" {{ block.shopify_attributes }}>{{ block.settings.text }}</div>
{%- when 'button' -%}
{%- if block.settings.button_label != blank -%}
<div class="rich-text__button">
<a{% if block.settings.button_link == blank %} role="link" aria-disabled="true"{% else %} href="{{ block.settings.button_link }}"{% endif %} class="button{% if block.settings.button_style_secondary %} button--secondary{% else %} button--primary{% endif %}" {{ block.shopify_attributes }}>
{{ block.settings.button_label | escape }}
</a>
</div>
{%- endif -%}
Comment on lines +34 to +40
Copy link
Contributor Author

@andrewetchen andrewetchen Apr 18, 2022

Choose a reason for hiding this comment

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

The {%- if block.settings.button_label != blank -%} conditional was added to prevent this: #1615.

Additionally, I added a <div> to make sure button blocks are placed on new lines instead of inline.

{%- endcase -%}
{%- endfor -%}
</div>
</div>
</div>
</div>
Expand All @@ -43,6 +51,46 @@
"tag": "section",
"class": "section",
"settings": [
{
"type": "select",
"id": "desktop_content_position",
"options": [
{
"value": "left",
"label": "t:sections.rich-text.settings.desktop_content_position.options__1.label"
},
{
"value": "center",
"label": "t:sections.rich-text.settings.desktop_content_position.options__2.label"
},
{
"value": "right",
"label": "t:sections.rich-text.settings.desktop_content_position.options__3.label"
}
],
"default": "center",
"label": "t:sections.rich-text.settings.desktop_content_position.label"
},
{
"type": "select",
"id": "content_alignment",
"options": [
{
"value": "left",
"label": "t:sections.rich-text.settings.content_alignment.options__1.label"
},
{
"value": "center",
"label": "t:sections.rich-text.settings.content_alignment.options__2.label"
},
{
"value": "right",
"label": "t:sections.rich-text.settings.content_alignment.options__3.label"
}
],
"default": "center",
"label": "t:sections.rich-text.settings.content_alignment.label"
},
{
"type": "select",
"id": "color_scheme",
Expand Down Expand Up @@ -106,12 +154,11 @@
{
"type": "heading",
"name": "t:sections.rich-text.blocks.heading.name",
"limit": 1,
"settings": [
{
"type": "text",
"type": "richtext",
"id": "heading",
"default": "Talk about your brand",
"default": "<p>Talk about your brand</p>",
"label": "t:sections.rich-text.blocks.heading.settings.heading.label"
},
{
Expand All @@ -129,17 +176,68 @@
{
"value": "h0",
"label": "t:sections.all.heading_size.options__3.label"
},
{
"value": "hxl",
"label": "t:sections.all.heading_size.options__4.label"
}
],
"default": "h1",
"label": "t:sections.all.heading_size.label"
}
]
},
{
"type": "caption",
"name": "t:sections.rich-text.blocks.caption.name",
"settings": [
{
"type": "text",
"id": "caption",
"default": "Add a tagline",
"label": "t:sections.rich-text.blocks.caption.settings.text.label"
},
{
"type": "select",
"id": "text_style",
"options": [
{
"value": "subtitle",
"label": "t:sections.rich-text.blocks.caption.settings.text_style.options__1.label"
},
{
"value": "caption-with-letter-spacing",
"label": "t:sections.rich-text.blocks.caption.settings.text_style.options__2.label"
}
],
"default": "caption-with-letter-spacing",
"label": "t:sections.rich-text.blocks.caption.settings.text_style.label"
},
{
"type": "select",
"id": "text_size",
"options": [
{
"value": "small",
"label": "t:sections.rich-text.blocks.caption.settings.caption_size.options__1.label"
},
{
"value": "medium",
"label": "t:sections.rich-text.blocks.caption.settings.caption_size.options__2.label"
},
{
"value": "large",
"label": "t:sections.rich-text.blocks.caption.settings.caption_size.options__3.label"
}
],
"default": "medium",
"label": "t:sections.rich-text.blocks.caption.settings.caption_size.label"
}
]
},
{
"type": "text",
"name": "t:sections.rich-text.blocks.text.name",
"limit": 1,
"settings": [
{
"type": "richtext",
Expand All @@ -152,7 +250,6 @@
{
"type": "button",
"name": "t:sections.rich-text.blocks.button.name",
"limit": 1,
"settings": [
{
"type": "text",
Expand Down
2 changes: 1 addition & 1 deletion templates/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"heading": {
"type": "heading",
"settings": {
"heading": "Talk about your brand",
"heading": "<p>Talk about your brand</p>",
Copy link
Contributor Author

@andrewetchen andrewetchen Apr 18, 2022

Choose a reason for hiding this comment

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

Related: https://github.com/Shopify/dawn/pull/1625/files#r852183418

richtext input setting

p tags must be used to wrap the default richtext. It will result in an error if it's not:

shopify-cli

11:12:21 ERROR  » update templates/index.json:
  Setting 'heading' is invalid. All top level nodes must be '<p>' tags

Code editor

image

"heading_size": "h1"
}
},
Expand Down