-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: style status messages for 10.3
- Loading branch information
1 parent
e5a6fd0
commit 4285d8a
Showing
3 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* @file | ||
* Message template overrides. | ||
*/ | ||
|
||
((Drupal) => { | ||
/** | ||
* Overrides message theme function. | ||
* | ||
* @param {object} message | ||
* The message object. | ||
* @param {string} message.text | ||
* The message text. | ||
* @param {object} options | ||
* The message context. | ||
* @param {string} options.type | ||
* The message type. | ||
* @param {string} options.id | ||
* ID of the message, for reference. | ||
* | ||
* @return {HTMLElement} | ||
* A DOM Node. | ||
*/ | ||
Drupal.theme.message = ({ text }, { type, id }) => { | ||
Check failure on line 24 in js/messages.js GitHub Actions / checks
Check failure on line 24 in js/messages.js GitHub Actions / checks
Check failure on line 24 in js/messages.js GitHub Actions / checks
|
||
const messagesTypes = Drupal.Message.getMessageTypeLabels(); | ||
const messageWrapper = document.createElement('div'); | ||
|
||
messageWrapper.setAttribute('class', `messages messages--${type} cd-alert cd-alert--${type}`); | ||
messageWrapper.setAttribute( | ||
'role', | ||
type === 'error' || type === 'warning' ? 'alert' : 'status', | ||
); | ||
var icon_type = 'about', role='status'; | ||
Check failure on line 33 in js/messages.js GitHub Actions / checks
|
||
switch (type) { | ||
case 'error': | ||
icon_type = 'error'; | ||
role = 'alert'; | ||
break; | ||
case 'warning': | ||
icon_type = 'alert'; | ||
break; | ||
case 'status': | ||
icon_type = 'selected'; | ||
} | ||
messageWrapper.setAttribute('data-drupal-message-id', id); | ||
messageWrapper.setAttribute('data-drupal-message-type', type); | ||
|
||
messageWrapper.innerHTML = ` | ||
<div role="${role}" aria-label="${type}"> | ||
<svg class="cd-icon cd-icon--${icon_type}" aria-hidden="true" focusable="false" width="24" height="24"> | ||
<use xlink:href="#cd-icon--${icon_type}"></use> | ||
</svg> | ||
<div class="cd-alert__container cd-max-width"> | ||
<div class="cd-alert__title"> | ||
<h2 class="visually-hidden">${messagesTypes[type]}</h2> | ||
</div> | ||
<div class="cd-alert__message [ cd-flow ]"> | ||
${text} | ||
</div> | ||
</div> | ||
</div> | ||
`; | ||
|
||
return messageWrapper; | ||
}; | ||
})(Drupal); |