@financial-times/n-myft-ui 31.0.0 → 31.0.2
Sign up to get free protection for your applications and to get access to all the features.
@@ -61,14 +61,18 @@ const instantAlertsIconOff = ({ event, followPlusInstantAlerts }) => {
|
|
61
61
|
});
|
62
62
|
};
|
63
63
|
|
64
|
-
|
65
64
|
const sendModalToggleEvent = ({ followPlusInstantAlerts }) => {
|
66
65
|
const preferenceModalToggleEvent = new CustomEvent('myft.preference-modal.show-hide.toggle', { bubbles: true });
|
67
66
|
followPlusInstantAlerts.dispatchEvent(preferenceModalToggleEvent);
|
68
67
|
followPlusInstantAlerts.classList.toggle('n-myft-follow-button--instant-alerts--open');
|
69
|
-
|
70
68
|
};
|
71
69
|
|
70
|
+
const sendModalHideEvent = ({ event, followPlusInstantAlerts }) => {
|
71
|
+
if (event.target !== followPlusInstantAlerts) {
|
72
|
+
const preferenceModalHideEvent = new CustomEvent('myft.preference-modal.hide', { detail: {targetElement: event.target}, bubbles: true });
|
73
|
+
followPlusInstantAlerts.dispatchEvent(preferenceModalHideEvent);
|
74
|
+
}
|
75
|
+
};
|
72
76
|
|
73
77
|
export default () => {
|
74
78
|
/**
|
@@ -88,5 +92,8 @@ export default () => {
|
|
88
92
|
document.body.addEventListener('myft.user.followed.concept.load', (event) => instantAlertsIconLoad({event, followPlusInstantAlerts}));
|
89
93
|
|
90
94
|
document.body.addEventListener('myft.user.followed.concept.update', (event) => instantAlertsIconUpdate({event, followPlusInstantAlerts}));
|
95
|
+
|
91
96
|
document.body.addEventListener('myft.user.followed.concept.remove', (event) => instantAlertsIconOff({ event, followPlusInstantAlerts }));
|
97
|
+
|
98
|
+
document.addEventListener('click', (event) => sendModalHideEvent({event, followPlusInstantAlerts}));
|
92
99
|
};
|
@@ -9,6 +9,13 @@ const renderError = ({ message, preferencesModal }) => {
|
|
9
9
|
errorElement.innerHTML = message;
|
10
10
|
};
|
11
11
|
|
12
|
+
const removeError = ({ preferencesModal }) => {
|
13
|
+
renderError({
|
14
|
+
message: "",
|
15
|
+
preferencesModal,
|
16
|
+
});
|
17
|
+
}
|
18
|
+
|
12
19
|
/**
|
13
20
|
* This preference modal is part of a test
|
14
21
|
* Therefore we have built the positioning function to work within the known parameters of that test
|
@@ -75,6 +82,13 @@ const tracking = (conceptId) => {
|
|
75
82
|
document.body.dispatchEvent(trackingEvent);
|
76
83
|
};
|
77
84
|
|
85
|
+
const preferenceModalHide = ({ event, preferencesModal }) => {
|
86
|
+
if (!preferencesModal.contains(event.detail.targetElement)) {
|
87
|
+
preferencesModal.classList.remove('n-myft-ui__preferences-modal--show');
|
88
|
+
removeError({ preferencesModal });
|
89
|
+
}
|
90
|
+
};
|
91
|
+
|
78
92
|
const preferenceModalShowAndHide = ({ event, preferencesModal, conceptId }) => {
|
79
93
|
preferencesModal.classList.toggle('n-myft-ui__preferences-modal--show');
|
80
94
|
|
@@ -85,23 +99,25 @@ const preferenceModalShowAndHide = ({ event, preferencesModal, conceptId }) => {
|
|
85
99
|
|
86
100
|
} else {
|
87
101
|
// Remove existing errors when hiding the modal
|
88
|
-
|
89
|
-
message: '',
|
90
|
-
preferencesModal,
|
91
|
-
});
|
102
|
+
removeError({ preferencesModal });
|
92
103
|
}
|
93
104
|
};
|
94
105
|
|
95
106
|
const removeTopic = async ({ event, conceptId, preferencesModal }) => {
|
96
107
|
event.target.setAttribute('disabled', true);
|
97
108
|
|
109
|
+
// remove error message before attempt to remove topic
|
110
|
+
removeError({ preferencesModal });
|
111
|
+
|
98
112
|
try {
|
99
113
|
await myFtClient.remove('user', null, 'followed', 'concept', conceptId, { token: csrfToken });
|
100
114
|
preferenceModalShowAndHide({ preferencesModal });
|
101
115
|
} catch (error) {
|
102
|
-
renderError({
|
116
|
+
renderError({
|
117
|
+
message: 'Sorry, we are unable to remove this topic. Please try again later or try from <a href="/myft">myFT</a>',
|
118
|
+
preferencesModal,
|
119
|
+
});
|
103
120
|
}
|
104
|
-
|
105
121
|
event.target.removeAttribute('disabled');
|
106
122
|
};
|
107
123
|
|
@@ -169,6 +185,9 @@ const toggleInstantAlertsPreference = async ({ event, conceptId, preferencesModa
|
|
169
185
|
|
170
186
|
instantAlertsCheckbox.setAttribute('disabled', true);
|
171
187
|
|
188
|
+
// remove error message before attempt to toggle instant alert
|
189
|
+
removeError({ preferencesModal });
|
190
|
+
|
172
191
|
const data = {
|
173
192
|
token: csrfToken
|
174
193
|
};
|
@@ -188,7 +207,7 @@ const toggleInstantAlertsPreference = async ({ event, conceptId, preferencesModa
|
|
188
207
|
} catch (error) {
|
189
208
|
renderError({
|
190
209
|
message: 'Sorry, we are unable to change your instant alert preference. Please try again later or try from <a href="/myft">myFT</a>',
|
191
|
-
preferencesModal
|
210
|
+
preferencesModal,
|
192
211
|
});
|
193
212
|
|
194
213
|
instantAlertsCheckbox.checked = instantAlertsCheckbox.checked
|
@@ -245,6 +264,8 @@ export default () => {
|
|
245
264
|
|
246
265
|
document.addEventListener('myft.preference-modal.show-hide.toggle', event => preferenceModalShowAndHide({ event, preferencesModal, conceptId }));
|
247
266
|
|
267
|
+
document.addEventListener('myft.preference-modal.hide', event => preferenceModalHide({ event, preferencesModal }));
|
268
|
+
|
248
269
|
document.addEventListener('myft.user.preferred.preference.load', (event) => getAlertsPreferences({ event, preferencesModal }));
|
249
270
|
|
250
271
|
document.body.addEventListener('myft.user.followed.concept.load', (event) => setCheckboxForAlertConcept({ event, preferencesModal }));
|
@@ -47,14 +47,39 @@
|
|
47
47
|
color: oColorsByName('claret-60');
|
48
48
|
}
|
49
49
|
|
50
|
+
.n-myft-ui__preferences-modal__remove-button:disabled {
|
51
|
+
opacity: 0.5;
|
52
|
+
}
|
53
|
+
|
50
54
|
.n-myft-ui__preferences-modal--show {
|
51
55
|
display: block;
|
52
56
|
visibility: visible;
|
53
57
|
}
|
54
58
|
|
59
|
+
// reference to the color/BG color of the error message
|
60
|
+
// components/o-message/src/scss/_brand.scss#L21 in origami
|
55
61
|
.n-myft-ui__preferences-modal-error {
|
56
62
|
display: block;
|
57
63
|
@include oTypographySans($scale: -1, $weight: 'regular', $style: 'normal');
|
58
|
-
color:
|
59
|
-
|
64
|
+
color: oColorsMix('black', 'crimson', $percentage: 12.5);
|
65
|
+
background-color: oColorsMix('crimson', $percentage: 10);
|
66
|
+
text-align: left;
|
67
|
+
padding: 8px 12px;
|
68
|
+
margin-top: 16px;
|
69
|
+
|
70
|
+
// use opacity to enforce CSS transition
|
71
|
+
opacity: 1;
|
72
|
+
transition: opacity 0.5s;
|
73
|
+
|
74
|
+
a {
|
75
|
+
@include oTypographySans($scale: -1, $weight: 'semibold', $style: 'normal');
|
76
|
+
color: oColorsMix('black', 'crimson', $percentage: 12.5);
|
77
|
+
text-decoration-color: oColorsMix('black', 'crimson', $percentage: 12.5);
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
.n-myft-ui__preferences-modal-error:empty {
|
82
|
+
opacity: 0;
|
83
|
+
padding: 0;
|
84
|
+
margin-top: 0;
|
60
85
|
}
|