Skip to content

Commit 51fa248

Browse files
committed
Refactor modal: close icon, sr-only heading, transitions instead of animations. Clean code
1 parent 3ddb444 commit 51fa248

File tree

9 files changed

+73
-127
lines changed

9 files changed

+73
-127
lines changed

tbx/project_styleguide/templates/patterns/atoms/icon_buttons/icon_button--close.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

tbx/project_styleguide/templates/patterns/atoms/icon_buttons/icon_button.html

Lines changed: 0 additions & 14 deletions
This file was deleted.

tbx/project_styleguide/templates/patterns/atoms/sprites/sprites.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
<path d="M3.367 10.547a10 10 0 016.772-6.771l2.927-.861a10 10 0 015.644 0l2.927.86a10 10 0 016.772 6.772l.86 2.928a10 10 0 010 5.643l-.86 2.927a10 10 0 01-6.772 6.772l-2.927.861a10 10 0 01-5.644 0l-2.927-.86a10 10 0 01-6.772-6.773l-.86-2.927a10 10 0 010-5.643l.86-2.928z" fill="none" stroke="currentColor" stroke-width="4"/>
5656
</symbol>
5757

58+
<symbol id="close" viewBox="0 0 32 24" fill="none">
59+
<path d="M4 10H28" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" transform="rotate(45 16 10)"/><path d="M4 10H28" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" transform="rotate(-45 16 10)"/>
60+
</symbol>
61+
5862
{# Logo: Torchbox #}
5963
<symbol id="logo-torchbox" viewBox="0 0 830 220" fill="none">
6064
<path d="M119.519 103.815C120.273 102.498 122.253 102.874 122.442 104.38C122.913 108.709 123.479 115.39 122.536 122.636C120.462 139.104 106.789 165.924 77.6512 173.452C76.331 173.828 75.2938 172.323 76.0481 171.099C78.6884 166.959 80.2915 161.124 80.2915 153.502C80.2915 136.093 61.4323 109.65 61.4323 109.65C61.4323 109.65 42.5731 136.093 42.5731 153.502C42.5731 161.03 44.1761 166.865 46.8164 171.005C47.665 172.229 46.6278 173.734 45.2133 173.358C15.2272 165.359 -2.21751 135.34 0.234189 105.98C1.27144 93.8401 8.06076 82.7358 12.0212 77.2778C12.8699 76.1485 14.7558 76.7132 14.8501 78.2188C15.133 84.5238 16.5474 96.0045 22.8652 105.603L23.0538 105.791C26.1655 99.204 29.466 94.4047 29.466 94.4047C32.2005 90.2641 35.4066 86.1236 38.3297 82.924C53.7 65.5148 57.0947 47.6351 47.9479 28.7202C47.2879 27.3086 48.8909 25.897 50.2111 26.744C64.1669 35.4015 103.771 65.0443 104.526 119.719V120.566C108.863 118.495 115.087 111.72 119.519 103.815Z" fill="currentColor"/><path d="M173.985 67.8179V171.335H198.352V67.8179H238.194V46.2963H134.143V67.8179H173.985Z" fill="currentColor"/><path d="M520.864 122.067V171.336H544.164V116.909C544.164 110.388 542.741 104.637 539.895 99.6566C537.05 94.6763 533.078 90.7633 527.979 87.9175C522.999 85.0717 517.248 83.6487 510.726 83.6487C504.204 83.6487 498.394 85.0717 493.295 87.9175C490.691 89.4055 488.379 91.2014 486.359 93.3054V46.2998H463.058V171.336H486.359V122.067C486.359 118.629 487.07 115.605 488.493 112.996C490.035 110.388 492.11 108.372 494.718 106.949C497.327 105.526 500.291 104.815 503.612 104.815C508.71 104.815 512.86 106.415 516.062 109.617C519.264 112.819 520.864 116.969 520.864 122.067Z" fill="currentColor"/>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<div class="modal" id="iframe-embed-modal" aria-hidden="true">
2+
<div class="modal__overlay" data-micromodal-close></div>
3+
<div class="modal__container"
4+
role="dialog"
5+
aria-modal="true"
6+
aria-labelledby="modal-title">
7+
<header class="modal__header">
8+
<h2 class="sr-only" id="modal-title">Service Enquiry</h2>
9+
<button type="button"
10+
class="modal__close-button"
11+
data-micromodal-close
12+
aria-label="Close modal">{% include "patterns/atoms/icons/icon.html" with name="close" %}</button>
13+
</header>
14+
<div class="modal__content" id="filters-content">
15+
<iframe src="{{ iframe_src }}"
16+
width="100%"
17+
height="650px"
18+
frameborder="0"
19+
title="Service enquiry form">
20+
</iframe>
21+
</div>
22+
</div>
23+
</div>
Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{% load wagtailcore_tags %}
22
{# call_to_action is a required field (streamblock) in the block definition #}
33

4-
54
<div class="call-to-action__sticky" data-sticky-cta>
65
<div class="call-to-action__inner">
76
{% if value.get_button_link_block.block_type == "modal_iframe" %}
@@ -26,25 +25,5 @@
2625
</div>
2726

2827
{% if value.get_button_link_block.block_type == "modal_iframe" %}
29-
<!-- Modal content -->
30-
<div class="modal" id="iframe-embed-modal" aria-hidden="true">
31-
<div class="modal__overlay" data-micromodal-close></div>
32-
<div class="modal__container" role="dialog" aria-modal="true" aria-labelledby="modal-title" >
33-
<header class="modal__header">
34-
<h2 class="modal__heading heading heading--two" id="modal-title">Service Enquiry</h2>
35-
<div class="modal__close">
36-
{% include "patterns/atoms/icon_buttons/icon_button.html" with modifier="close" data="data-micromodal-close" aria='aria-label="Close modal"' %}
37-
</div>
38-
</header>
39-
<main class="modal__content" id="filters-content">
40-
<iframe
41-
src="{{ value.get_button_link }}"
42-
width="100%"
43-
height="650px"
44-
frameborder="0"
45-
title="Modal Webform">
46-
</iframe>
47-
</main>
48-
</div>
49-
</div>
28+
{% include "patterns/molecules/iframe_modal/iframe_modal.html" with iframe_src=value.get_button_link %}
5029
{% endif %}

tbx/project_styleguide/templates/patterns/molecules/streamfield/blocks/sticky_call_to_action.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ context:
33
sticky_text: Get in touch
44
sticky_subtext: learn about our journey
55
button_link:
6-
- modal_iframe:
7-
url: 'https://example.com'
6+
- modal_iframe: 'https://example.com'

tbx/static_src/javascript/components/modal.js

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import MicroModal from 'micromodal'; // es6 module
22

3-
// Assumes a strcuture as follows
4-
// <div class="modal" id="filters" aria-hidden="true">
5-
// <div class="modal__overlay" tabindex="-1" data-micromodal-close></div>
6-
// <div class="modal__container" role="dialog" aria-modal="true" aria-labelledby="modal-title" >
7-
// <header class="modal__header">
8-
// <h2 class="modal__heading heading heading--two" id="modal-title">Title<h2>
9-
// <div class="modal__close">
10-
// {% include "atoms/icon_buttons/icon_button.html" with modifier="close" data="data-micromodal-close" aria='aria-label="Close modal"' %}
11-
// </div>
12-
// </header>
13-
// <main class="modal__content" id="filters-content">
14-
// Content
15-
// </main>
16-
// <footer class="modal__footer">
17-
// <button class="modal__btn" data-micromodal-close>Close</button>
18-
// </footer>
19-
// </div>
3+
// Markup required
4+
// Trigger:
5+
// <button type="button" data-micromodal-trigger="iframe-embed-modal">Open</button>
6+
//
7+
// Modal:
8+
// <div class="modal" id="iframe-embed-modal" aria-hidden="true">
9+
// <div class="modal__overlay" data-micromodal-close></div>
10+
// <div class="modal__container"
11+
// role="dialog"
12+
// aria-modal="true"
13+
// aria-labelledby="modal-title">
14+
// <header class="modal__header">
15+
// <h2 id="modal-title">Service enquiry</h2>
16+
// <button type="button" data-micromodal-close aria-label="Close dialog"></button>
17+
// </header>
18+
// <div class="modal__content">...</div>
19+
// </div>
2020
// </div>
2121

2222
class Modal {
@@ -58,14 +58,11 @@ class Modal {
5858
}
5959

6060
// Close modal when clicking on close buttons
61-
const closeButton = event.target.closest(
62-
'[data-micromodal-close], [data-listing-submit]',
63-
);
61+
const closeButton = event.target.closest('[data-micromodal-close]');
6462
if (closeButton) {
6563
const modal = closeButton.closest('.modal');
6664
if (modal) {
6765
MicroModal.close(modal.id); // Close the modal
68-
document.body.style.overflow = ''; // Remove overflow hidden from body
6966
}
7067
}
7168
}

tbx/static_src/sass/components/_modal.scss

Lines changed: 26 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -32,121 +32,87 @@
3232
left: 0;
3333
right: 0;
3434
bottom: 0;
35-
// background-color: var(--color--background--overlay);
3635
background: rgba(55, 55, 55, 0.6);
3736
backdrop-filter: blur(10px);
37+
will-change: opacity;
38+
opacity: 0;
39+
transition: opacity $transition;
3840
}
3941

4042
&__container {
4143
@include z-index(modal-controls);
42-
// @include hcm-border();
43-
// position: relative;
4444
background-color: var(--color--background);
4545
padding: $grid;
4646
width: 100%;
4747
max-height: 100dvh;
4848
overflow-y: auto;
49-
// margin: $grid-l;
5049
border: 1px solid var(--color--border--highlight);
50+
will-change: opacity;
51+
opacity: 0;
52+
transition: opacity $transition;
5153

5254
@include media-query(medium) {
5355
width: 50vw;
5456
min-width: 459px;
55-
padding: $grid-m;
57+
padding: $spacer-small;
5658
}
5759

5860
@include media-query(large) {
5961
max-width: 758px;
60-
padding: $grid-l;
62+
padding: $spacer-small-plus;
6163
}
6264
}
6365

6466
&__header {
6567
display: flex;
66-
justify-content: space-between;
68+
justify-content: flex-end;
6769
align-items: center;
68-
margin-bottom: $grid-l;
70+
margin-bottom: $spacer-small-plus;
6971
}
7072

7173
&__title {
7274
margin-top: 0;
7375
margin-bottom: 0;
7476
}
7577

76-
&__close {
78+
&__close-button {
7779
@include z-index(modal-controls);
78-
position: relative;
79-
background: transparent;
80-
border: 0;
80+
width: 24px;
81+
height: 24px;
8182

82-
button:focus {
83+
&:focus {
8384
@include focus-style();
8485
}
85-
}
8686

87-
&__container,
88-
&__overlay {
89-
will-change: transform;
87+
.icon {
88+
width: 100%;
89+
height: 100%;
90+
}
9091
}
9192

9293
&[aria-hidden='false'] {
9394
#{$root}__overlay {
94-
animation: mmfadeIn 0.3s cubic-bezier(0, 0, 0.2, 1);
95+
opacity: 1;
9596
}
9697

9798
#{$root}__container {
98-
animation: mmslideIn 0.3s cubic-bezier(0, 0, 0.2, 1),
99-
mmfadeIn 0.3s cubic-bezier(0, 0, 0.2, 1);
99+
opacity: 1;
100100
}
101101
}
102102

103103
&[aria-hidden='true'] {
104104
#{$root}__overlay {
105-
animation: mmfadeOut 0.3s cubic-bezier(0, 0, 0.2, 1);
105+
opacity: 0;
106106
}
107107

108108
#{$root}__container {
109-
animation: mmfadeOut 0.3s cubic-bezier(0, 0, 0.2, 1);
109+
opacity: 0;
110110
}
111111
}
112-
}
113-
114-
@keyframes mmfadeIn {
115-
from {
116-
opacity: 0;
117-
}
118112

119-
to {
120-
opacity: 1;
121-
}
122-
}
123-
124-
@keyframes mmfadeOut {
125-
from {
126-
opacity: 1;
127-
}
128-
129-
to {
130-
opacity: 0;
131-
}
132-
}
133-
134-
@keyframes mmslideIn {
135-
from {
136-
transform: translateY(15%);
137-
}
138-
139-
to {
140-
transform: translateY(0);
141-
}
142-
}
143-
144-
@keyframes mmslideOut {
145-
from {
146-
transform: translateY(0);
147-
}
148-
149-
to {
150-
transform: translateY(-10%);
113+
&__content {
114+
@include high-contrast-mode() {
115+
border: 1px solid var(--color--text);
116+
}
151117
}
152118
}

tbx/static_src/sass/config/_variables.scss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -371,13 +371,6 @@ $grid: 30px;
371371
$grid-gutters: $grid;
372372
$grid-gutters-large: 80px;
373373
$grid-gutters-x-large: 120px;
374-
$grid-xs: calc($grid / 4); // 5px
375-
$grid-s: calc($grid / 2); // 10px
376-
$grid-s-m: calc($grid * 0.75); // 15px
377-
$grid-m: calc($grid * 1.5); // 30px
378-
$grid-l: calc($grid * 2); // 40px
379-
$grid-xl: calc($grid * 3); // 60px
380-
$grid-xxl: calc($grid * 4); // 80px
381374

382375
// Vertical spacing
383376
// Any changes here will also need to be made in tailwind.config.js

0 commit comments

Comments
 (0)