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

chore: style status messages for 10.3 #489

Merged
merged 3 commits into from
Aug 8, 2024
Merged
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
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
67 changes: 67 additions & 0 deletions js/messages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* @file
* Message template overrides.
*/

((Drupal) => {
'use strict';

/**
* 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}) => {
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 iconType = 'about';
var role = 'status';
switch (type) {
case 'error':
iconType = 'error';
role = 'alert';
break;
case 'warning':
iconType = 'alert';
break;
case 'status':
iconType = '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--${iconType}" aria-hidden="true" focusable="false" width="24" height="24">
<use xlink:href="#cd-icon--${iconType}"></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);
Loading