Skip to content

Commit

Permalink
[#2757] Add home view styling for when notifications exist
Browse files Browse the repository at this point in the history
  • Loading branch information
jiromaykin committed Nov 14, 2024
1 parent 282365d commit 904afd4
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/open_inwoner/js/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import './siteimprove/tracking'
import './twofactor-sms'
import { FileInput } from './form/FileInput'
import { ToggleHide } from './card/ToggleHide'
import './views'

const htmx = (window.htmx = require('htmx.org'))

Expand Down
2 changes: 2 additions & 0 deletions src/open_inwoner/js/components/notifications/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ export class Notification {
*/
close() {
this.node.parentElement.removeChild(this.node)
// Dispatch a custom event to notify other components that a notification has been closed
document.dispatchEvent(new CustomEvent('notificationClosed'))
}

/**
Expand Down
44 changes: 44 additions & 0 deletions src/open_inwoner/js/components/views/home-view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
export class NotificationHandler {
static selector = '.view---pages-root'

constructor(root) {
this.root = root
this.notificationsSection = document.querySelector('.notification')

this.checkNotifications()

// Listen for the dispatch event from notifications
document.addEventListener(
'notificationClosed',
this.updateStyling.bind(this)
)
}

checkNotifications() {
if (
this.notificationsSection &&
this.notificationsSection.children.length > 0
) {
this.root.classList.add('has-notifications')
}
}

/**
* Updates styling based on presence of the dispatch event
*/
updateStyling() {
const notificationExists =
this.notificationsSection.querySelector('.notification')
if (!notificationExists) {
this.root.classList.remove('has-notifications')
}
}
}

/**
* Controls deviant styling of notifications in Homepage
*/
const rootElement = document.querySelector(NotificationHandler.selector)
if (rootElement) {
new NotificationHandler(rootElement)
}
2 changes: 2 additions & 0 deletions src/open_inwoner/js/components/views/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Handling exceptions in certain views
import './home-view'
3 changes: 1 addition & 2 deletions src/open_inwoner/scss/components/Grid/Grid.scss
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,14 @@
}

&__welcome.plugin {
margin-top: -80px;
margin-top: -130px;
background-color: var(--color-white);
border-radius: var(--border-radius);
padding: var(--spacing-large);
box-sizing: border-box;
width: 100%;

@media (min-width: 768px) {
margin-top: -130px;
width: 50%;
}
}
Expand Down
26 changes: 26 additions & 0 deletions src/open_inwoner/scss/views/_view.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
.view {
&---pages-root {
&.has-notifications {
.notifications {
margin-top: -41px;
@media (min-width: 768px) {
margin-top: -32px;
}
}
.grid__welcome.plugin {
margin-top: -40px;
padding: 0;

@media (min-width: 768px) {
margin-top: -30px;
}
}
}
.container .button--icon-after {
padding-left: 0;

@media (min-width: 768px) {
padding-left: var(--spacing-large);
}
}
}

&--accounts-contact_list {
.form--horizontal {
padding-top: var(--row-height);
Expand Down

0 comments on commit 904afd4

Please sign in to comment.