Skip to content

Commit

Permalink
chore: style status messages for 10.3
Browse files Browse the repository at this point in the history
  • Loading branch information
lazysoundsystem committed Aug 7, 2024
1 parent e5a6fd0 commit 4285d8a
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
2 changes: 2 additions & 0 deletions common_design.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ regions:
libraries-extend:
core/drupal.dropbutton:
- common_design/cd-dropbutton
core/drupal.message:
- common_design/messages

libraries-override:
core/modernizr:
Expand Down
9 changes: 9 additions & 0 deletions common_design.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ global-styling:
dependencies:
- common_design/cd-core

# Style status messages when they come via bigpipe.
# @see https://www.drupal.org/project/drupal/issues/3456176
messages:
css:
component:
components/cd-alert/cd-alert.css: {}
js:
js/messages.js: {}

# Roboto Condensed and Slab.
# @see https://brand.unocha.org/d/xEPytAUjC3sH/visual-identity#/basics/fonts/advanced-users
fonts-advanced:
Expand Down
66 changes: 66 additions & 0 deletions js/messages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* @file
* Message template overrides.
*/

((Drupal) => {

Check failure on line 6 in js/messages.js

View workflow job for this annotation

GitHub Actions / checks

Use the function form of 'use strict'
/**

Check failure on line 7 in js/messages.js

View workflow job for this annotation

GitHub Actions / checks

Expected line before comment
* 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

View workflow job for this annotation

GitHub Actions / checks

There should be no space after '{'

Check failure on line 24 in js/messages.js

View workflow job for this annotation

GitHub Actions / checks

There should be no space before '}'

Check failure on line 24 in js/messages.js

View workflow job for this annotation

GitHub Actions / checks

There should be no space after '{'

Check failure on line 24 in js/messages.js

View workflow job for this annotation

GitHub Actions / checks

There should be no space before '}'
const messagesTypes = Drupal.Message.getMessageTypeLabels();
const messageWrapper = document.createElement('div');

messageWrapper.setAttribute('class', `messages messages--${type} cd-alert cd-alert--${type}`);
messageWrapper.setAttribute(

Check failure on line 29 in js/messages.js

View workflow job for this annotation

GitHub Actions / checks

Unexpected newline after '('
'role',
type === 'error' || type === 'warning' ? 'alert' : 'status',
);

Check failure on line 32 in js/messages.js

View workflow job for this annotation

GitHub Actions / checks

Unexpected newline before ')'
var icon_type = 'about', role='status';

Check failure on line 33 in js/messages.js

View workflow job for this annotation

GitHub Actions / checks

Split 'var' declarations into multiple statements

Check failure on line 33 in js/messages.js

View workflow job for this annotation

GitHub Actions / checks

Identifier 'icon_type' is not in camel case
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);

0 comments on commit 4285d8a

Please sign in to comment.