Skip to content

Commit

Permalink
Breaking: Update container component
Browse files Browse the repository at this point in the history
- simplify component class
- move @z-index@ handling to CSS custom property

Replaces mansona#272
  • Loading branch information
pichfl committed Jun 8, 2022
1 parent 1c16c50 commit 652b973
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 30 deletions.
13 changes: 0 additions & 13 deletions addon/components/notification-container.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* eslint-disable ember/no-classic-components, ember/no-computed-properties-in-native-classes */
import Component from '@ember/component';
import { computed } from '@ember/object';
import { htmlSafe } from '@ember/template';
import { inject as service } from '@ember/service';

import layout from '../templates/components/notification-container';
Expand All @@ -12,15 +10,4 @@ export default class NotificationContainerComponent extends Component {
tagName = '';
layout = layout;
position = 'top';
zindex = '1060';

@computed('position')
get positionClass() {
return `ember-cli-notifications-notification__container--${this.position}`;
}

@computed('zindex')
get inlineStyle() {
return htmlSafe(`z-index: ${this.zindex};`);
}
}
26 changes: 15 additions & 11 deletions addon/styles/components/notification-container.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
:root {
--ecn-container-position: 10px;
/* Spacing */
--ecn-spacing-1: 0.5rem;
--ecn-spacing-2: 1rem;

/* Container */
--ecn-container-z-index: 9999;
--ecn-container-position: var(--ecn-spacing-1);
--ecn-container-width: 80%;
--ecn-container-max-with: 400px;

Expand All @@ -17,51 +23,49 @@
--ecn-orange: #ff7f48;
--ecn-red: #e74c3c;

/* Spacing */
--ecn-spacing-1: .5rem;
--ecn-spacing-2: 1rem;
}

/* Base */
.ember-cli-notifications-notification__container {
.ecn_container {
position: fixed;
margin: 0 auto;
width: var(--ecn-container-width);
max-width: var(--ecn-container-max-with);
z-index: var(--ecn-container-z-index, 9999);
}

/* Position */
.ember-cli-notifications-notification__container--top {
.ecn_container-top {
top: var(--ecn-container-position);
right: 0;
left: 0;
}

.ember-cli-notifications-notification__container--top-left {
.ecn_container-top-left {
top: var(--ecn-container-position);
right: auto;
left: var(--ecn-container-position);
}

.ember-cli-notifications-notification__container--top-right {
.ecn_container-top-right {
top: var(--ecn-container-position);
right: var(--ecn-container-position);
left: auto;
}

.ember-cli-notifications-notification__container--bottom {
.ecn_container-bottom {
right: 0;
bottom: var(--ecn-container-position);
left: 0;
}

.ember-cli-notifications-notification__container--bottom-left {
.ecn_container-bottom-left {
right: auto;
bottom: var(--ecn-container-position);
left: var(--ecn-container-position);
}

.ember-cli-notifications-notification__container--bottom-right {
.ecn_container-bottom-right {
right: var(--ecn-container-position);
bottom: var(--ecn-container-position);
left: auto;
Expand Down
3 changes: 1 addition & 2 deletions addon/templates/components/notification-container.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<div
class="ember-cli-notifications-notification__container {{this.positionClass}}"
style={{this.inlineStyle}}
class="ecn_container ecn_container-{{this.position}}"
data-test-notification-container={{this.position}}
>
{{#each this.notifications.content as |notification|}}
Expand Down
8 changes: 4 additions & 4 deletions tests/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{! template-lint-disable link-rel-noopener no-action no-unbalanced-curlies require-button-type require-input-label }}
<NotificationContainer @position={{this.position}} @zindex={{this.zindex}} />
<NotificationContainer @position={{this.position}} />
<div class="bg-blue white py4">
<div class="max-width-4 mx-auto px2">
<div class="mb3">
Expand All @@ -26,9 +26,9 @@
<h2>Basic usage</h2>
<hr>
<p>Include the container component in your template.</p>
<p>Optionally, change the position or z-index value of the notifications container.</p>
<p class="h5"><i>Default value is top</i></p>
<CodeBlock @language="handlebars">&#123;&#123;notification-container position="top-right" zindex="9999"&#125;&#125;</CodeBlock>
<p>Optionally, change the position of the notifications container. The default value is <code>top</code>.</p>
<CodeBlock @language="handlebars">&#123;&#123;notification-container position="top-right"&#125;&#125;</CodeBlock>
<p>To change the <code>z-index</code> of the container, override the CSS custom property <code>--ecn-container-zindex</code>. The default value is <code>9999</code>.</p>

<p>Inject the notifications service where required.</p>
<CodeBlock @language="js">import Controller from '@ember/controller';
Expand Down

0 comments on commit 652b973

Please sign in to comment.