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

Add CTA functionality to button #381

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
138 changes: 131 additions & 7 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,6 +154,59 @@
"name": "spacing",
"type": "spacing"
}
],
"visibility": {
"controlling_field": "button_type",
"controlling_value_regex": "button",
"operator": "EQUAL"
}
},
{
"label": "Hover",
"name": "hover",
"type": "group",
"children": [
{
"label": "Text",
"name": "text",
"type": "group",
"children": [
{
"label": "Font",
"name": "font",
"type": "font",
"visibility": {
"hidden_subfields": {
"size": true
}
}
}
]
},
{
"label": "Background",
"name": "background",
"type": "group",
"children": [
{
"label": "Color",
"name": "color",
"type": "color"
}
]
},
{
"label": "Border",
"name": "border",
"type": "group",
"children": [
{
"label" : "Border",
"name" : "border",
"type" : "border"
}
]
}
]
},
{
Expand All @@ -101,7 +220,12 @@
"type": "alignment",
"alignment_direction": "HORIZONTAL"
}
]
],
"visibility": {
"controlling_field": "button_type",
"controlling_value_regex": "button",
"operator": "EQUAL"
}
}
]
}
Expand Down
141 changes: 87 additions & 54 deletions src/modules/button.module/module.html
Original file line number Diff line number Diff line change
@@ -1,67 +1,100 @@
{# 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 }});
{% if module.styles.alignment.alignment %}
.button-wrapper {
text-align: {{ module.styles.alignment.alignment.horizontal_align }};
}
{% 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 #}

.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 %}
}
.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 }}
}

{% end_scope_css %}
</style>
.button:hover,
.button:focus {
{% if module.styles.hover.background.color.color %}
background-color: rgba({{ module.styles.hover.background.color.color|convert_rgb }}, {{ module.styles.hover.background.color.opacity / 100 }});
{% endif %}
{{ module.styles.hover.border.border.css }}
{% if module.styles.hover.text.font.color %}
color: {{ module.styles.hover.text.font.color }};
{% endif %}
{% if module.styles.hover.text.font.size %}
font-size: {{ module.styles.hover.text.font.size ~ module.styles.hover.text.font.size_unit }};
{% endif %}
{% if module.styles.hover.text.font.style %}
{{ module.styles.hover.text.font.style }};
{% endif %}
}

{# Sets attributes used for the link field #}
.button:active {
{% if module.styles.hover.background.color.color %}
background-color: rgba({{ color_variant(module.styles.hover.background.color.color, 80)|convert_rgb }}, {{ module.styles.hover.background.color.opacity / 100 }});
{% endif %}
{{ module.styles.hover.border.border.css }}
{% if module.styles.hover.border.border %}
border-color: {{ color_variant(module.styles.hover.border.border.top.color, 80) }};
{% endif %}
{% if module.styles.hover.text.font.color %}
color: {{ module.styles.hover.text.font.color }};
{% endif %}
{% if module.styles.hover.text.font.size %}
font-size: {{ module.styles.hover.text.font.size ~ module.styles.hover.text.font.size_unit }};
{% endif %}
{% if module.styles.hover.text.font.style %}
{{ module.styles.hover.text.font.style }};
{% 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 %}
{% end_scope_css %}
</style>

{# Button #}
{# Sets attributes used for the link field #}
{% macro setLinkAttributes()%}

{# Setting href - If the URL type is set to email, append `mailto:` in front of the inputted value #}
{% set href = (module.button_link.url.type is equalto 'EMAIL_ADDRESS') ? 'mailto:' ~ module.button_link.url.href : module.button_link.url.href %}
{% if href %}
{{ {'href': '{{ href }}'}|xmlattr }}
{% endif %}

{# Setting the link's target and rel attributes based on the 'open in new tab' and 'tell search engines not to follow this link' fields being toggled #}
{% if module.button_link.open_in_new_tab and module.button_link.no_follow %}
{{ {'rel': 'noopener nofollow', 'target': '_blank'}|xmlattr }}
{% elif module.button_link.open_in_new_tab %}
{{ {'rel': 'noopener', 'target': '_blank'}|xmlattr }}
{% elif module.button_link.no_follow %}
{{ {'rel': 'nofollow'}|xmlattr }}
{% endif %}

{% endmacro %}

<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>
{# Button #}

<div class="button-wrapper">
<a class="button" {{ setLinkAttributes() }}>{{ module.button_text }}</a>
</div>

{% endif %}