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

Refactor: Handle notification htmlContent in backing class #342

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
13 changes: 12 additions & 1 deletion addon/components/notification-message.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable ember/no-classic-components, ember/no-computed-properties-in-native-classes */
import Component from '@ember/component';
import { htmlSafe } from '@ember/template';
import { htmlSafe, isHTMLSafe } from '@ember/template';
import { action, computed, set } from '@ember/object';
import { inject as service } from '@ember/service';

Expand All @@ -15,6 +15,17 @@ export default class NotificationMessage extends Component {

paused = false;

@computed('notification.{htmlContent,message}')
get message() {
const { htmlContent, message } = this.notification;

if (isHTMLSafe(message) || !htmlContent) {
return message;
}

return htmlSafe(message);
}

@computed('notification.dismiss')
get dismissClass() {
return !this.notification.dismiss ? 'c-notification--in' : '';
Expand Down
6 changes: 1 addition & 5 deletions addon/templates/components/notification-message.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@
{{/if}}
</div>
<div class="c-notification__content" {{on "click" this.handleOnClick}}>
{{#if @notification.htmlContent}}
{{{@notification.message}}}
{{else}}
{{@notification.message}}
{{/if}}
{{this.message}}
<div
class="c-notification__close"
{{on "click" this.removeNotification}}
Expand Down