Skip to content

Add CTA functionality to button #381

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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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
92 changes: 84 additions & 8 deletions src/modules/button.module/fields.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,70 @@
[
{
"label": "Button type",
"name": "button_type",
"type": "choice",
"display": "radio",
"inline_help_text": "",
"help_text": "",
"required": false,
"locked": false,
"choices": [
[
"button",
"Button"
],
[
"cta",
"CTA"
]
],
"placeholder": "",
"default": "button"
},
{
"label": "CTA",
"name": "cta_guid",
"type": "cta",
"sortable": false,
"required": false,
"locked": false,
"default": null,
"visibility": {
"controlling_field": "button_type",
"controlling_value_regex": "cta",
"operator": "EQUAL"
}
},
{
"label": "Button link",
"name": "link",
"type": "link",
"supported_types": ["EXTERNAL", "CONTENT", "FILE", "EMAIL_ADDRESS"],
"supported_types": ["EXTERNAL", "CONTENT", "FILE", "EMAIL_ADDRESS", "BLOG"],
"default": {
"url": {
"href": "",
"type": "EXTERNAL"
},
"no_follow": false,
"open_in_new_tab": false
},
"visibility": {
"controlling_field": "button_type",
"controlling_value_regex": "button",
"operator": "EQUAL"
}
},
{
"label": "Button text",
"name": "button_text",
"type": "text",
"required": true,
"default": "Add a button link here"
"default": "Add button text here",
"visibility": {
"controlling_field": "button_type",
"controlling_value_regex": "button",
"operator": "EQUAL"
}
},
{
"label": "Styles",
Expand All @@ -36,7 +82,12 @@
"name": "font",
"type": "font"
}
]
],
"visibility": {
"controlling_field": "button_type",
"controlling_value_regex": "button",
"operator": "EQUAL"
}
},
{
"label": "Background",
Expand All @@ -48,7 +99,12 @@
"name": "color",
"type": "color"
}
]
],
"visibility": {
"controlling_field": "button_type",
"controlling_value_regex": "button",
"operator": "EQUAL"
}
},
{
"label": "Border",
Expand All @@ -60,7 +116,12 @@
"name" : "border",
"type" : "border"
}
]
],
"visibility": {
"controlling_field": "button_type",
"controlling_value_regex": "button",
"operator": "EQUAL"
}
},
{
"label": "Corner",
Expand All @@ -76,7 +137,12 @@
"step": 1,
"suffix": "px"
}
]
],
"visibility": {
"controlling_field": "button_type",
"controlling_value_regex": "button",
"operator": "EQUAL"
}
},
{
"label": "Spacing",
Expand All @@ -88,7 +154,12 @@
"name": "spacing",
"type": "spacing"
}
]
],
"visibility": {
"controlling_field": "button_type",
"controlling_value_regex": "button",
"operator": "EQUAL"
}
},
{
"label": "Alignment",
Expand All @@ -101,7 +172,12 @@
"type": "alignment",
"alignment_direction": "HORIZONTAL"
}
]
],
"visibility": {
"controlling_field": "button_type",
"controlling_value_regex": "button",
"operator": "EQUAL"
}
}
]
}
Expand Down
136 changes: 82 additions & 54 deletions src/modules/button.module/module.html
Original file line number Diff line number Diff line change
@@ -1,67 +1,95 @@
{# Module styles #}
{# Checking if CTA or Button type #}
{% if module.button_type == "cta" %}

<style>
{% scope_css %}
{% cta guid='{{ module.cta_guid }}' %}

{% else %}

{# Button wrapper #}
{# Button styles #}

{% if module.styles.alignment.alignment %}
.button-wrapper {
text-align: {{ module.styles.alignment.alignment.horizontal_align }};
}
{% endif %}
<style>
{% scope_css %}

{# Button #}
{# Button wrapper #}

.button {
{% if module.styles.background.color.color %}
background-color: rgba({{ module.styles.background.color.color|convert_rgb }}, {{ module.styles.background.color.opacity / 100 }});
{% endif %}
{{ module.styles.border.border.css }}
{% if module.styles.corner.radius %}
border-radius: {{ module.styles.corner.radius ~ 'px' }};
{% if module.styles.alignment.alignment %}
.button-wrapper {
text-align: {{ module.styles.alignment.alignment.horizontal_align }};
}
{% endif %}
{{ module.styles.text.font.css }}
{{ module.styles.spacing.spacing.css }}
}

.button:hover,
.button:focus {
{% if module.styles.background.color.color %}
background-color: rgba({{ color_variant(module.styles.background.color.color, -80)|convert_rgb }}, {{ module.styles.background.color.opacity / 100 }});
{% endif %}
}

.button:active {
{% if module.styles.background.color.color %}
background-color: rgba({{ color_variant(module.styles.background.color.color, 80)|convert_rgb }}, {{ module.styles.background.color.opacity / 100 }});
{# Button #}

.button {
{% if module.styles.background.color.color %}
background-color: rgba({{ module.styles.background.color.color|convert_rgb }}, {{ module.styles.background.color.opacity / 100 }});
{% endif %}
{{ module.styles.border.border.css }}
{% if module.styles.corner.radius %}
border-radius: {{ module.styles.corner.radius ~ 'px' }};
{% endif %}
{{ module.styles.text.font.css }}
{{ module.styles.spacing.spacing.css }}
}

.button:hover,
.button:focus {
{% if module.styles.background.color.color %}
background-color: rgba({{ color_variant(module.styles.background.color.color, -80)|convert_rgb }}, {{ module.styles.background.color.opacity / 100 }});
{% endif %}
}

.button:active {
{% if module.styles.background.color.color %}
background-color: rgba({{ color_variant(module.styles.background.color.color, 80)|convert_rgb }}, {{ module.styles.background.color.opacity / 100 }});
{% endif %}
}

{% end_scope_css %}
</style>

{# Sets attributes used for the link field #}

{% macro href() %}
{% if module.link.url.href != "" %}
{# If the URL type is set to email, append `mailto:` in front of the inputted value #}
{% if module.link.url.type is equalto "EMAIL_ADDRESS" %}
{{ { 'href': 'mailto:' ~ module.link.url.href }|xmlattr }}
{% else %}
{# Rule check:
Unless the URL entered has http:// or https:// at the front,
is a telephone number (sniffed out by the value containing `tel:),
or the URL field doesn't have a value (because one of the other link types was chosen),
set the href variable to be `//` and append the entered URL string.
Otherwise, set the href to the exact value (unless its false or undefined then set it to be empty)
#}
{% unless (module.link.url.href is string_containing "//")
or (!module.link is string_startingwith "tel:")
or !module.link.url.href
%}
{{ { 'href': '//' ~ module.link.url.href }|xmlattr }}
{% else %}
{{ { 'href': module.link.url.href || "" }|xmlattr }}
{% endunless %}
{% endif %}
}
{% endif %}
{% endmacro %}

{% end_scope_css %}
</style>
{# Setting the link's target attribute to blank if the 'open in new tab' field is toggled #}
{% if module.link.open_in_new_tab %}
{% set target = 'target="_blank"'%}
{% endif %}

{# Sets attributes used for the link field #}
{# Checking to see if either field is toggled 'true' #}
{% if module.link.open_in_new_tab || module.link.no_follow %}
{# Setting the link's rel attribute to noopener if the 'open in new tab' field is toggled. Also setting it to nofollow if the 'tell search engines not to follow this link' field is toggled #}
{% set rel = 'rel="' ~ (module.link.open_in_new_tab ? "noopener " : null) ~ (module.link.no_follow ? "nofollow" : null) ~ '"' %}
{% endif %}

{% set href = module.link.url.href %}
{% if module.link.url.type is equalto 'EMAIL_ADDRESS' %}
{% set href = 'mailto:' + href %}
{% endif %}
{% set rel = [] %}
{% if module.link.no_follow %}
{% do rel.append('nofollow') %}
{% endif %}
{% if module.link.open_in_new_tab %}
{% do rel.append('noopener') %}
{% endif %}
{# Button #}

{# Button #}
<div class="button-wrapper">
<a class="button" {{ href() }} {{ target }} {{ rel }}>{{ module.button_text }}</a>
</div>

<div class="button-wrapper">
<a class="button" href="{{ href }}"
{% if module.link.open_in_new_tab %}target="_blank"{% endif %}
{% if rel %}rel="{{ rel|join(' ') }}"{% endif %}
>
{{ module.button_text }}
</a>
</div>
{% endif %}