forked from Princeton-CDH/cdh-web
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Site alert #105
Merged
Merged
Site alert #105
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8973ac0
Site alert
liamjohnston 9bf37fd
PR feedback
liamjohnston e8f7683
site alert bed work
sarahframe 7f072a9
removing migration files not necessary
sarahframe 4ff9c25
Fix aria-labelledby
liamjohnston 7a54b5f
fix class name
liamjohnston bd4dbfc
remove log
liamjohnston File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...eb/pages/migrations/0050_sitealert_alter_contentpage_body_alter_homepage_body_and_more.py
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
cdhweb/static_src/components/AlertBanner/AlertBanner.mount.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { InitComponent } from '../ComponentsInit'; | ||
|
||
const initComponent: InitComponent = (component) => { | ||
const alertId = component.getAttribute('data-alert-id'); | ||
if (!alertId) { | ||
throw Error('No banner alert ID supplied'); | ||
} | ||
const alertHasBeenDismissed = !!localStorage.getItem(alertId); | ||
|
||
if (alertHasBeenDismissed) | ||
return () => { | ||
// Alert has previously been dismissed. No need to show it. Abort. | ||
}; | ||
|
||
component.classList.remove('u-hidden'); | ||
const dismissBtn = component.querySelector('button'); | ||
|
||
dismissBtn?.addEventListener('click', () => { | ||
localStorage.setItem(alertId, alertId); | ||
component.classList.add('u-hidden'); | ||
}); | ||
|
||
return () => { | ||
// Return a cleanup function | ||
// nothing to do in this case; | ||
}; | ||
}; | ||
|
||
export default initComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
.alert-banner { | ||
--alert-accent-color: var(--color-brand-100); | ||
--alert-bg-color: var(--color-brand-5); | ||
|
||
// This linear gradient has a hard stop in the middle and goes full width. | ||
// This is so we get the left-side full bleed for the decoration area. | ||
// The content area has a white background which hides this trickery. | ||
background-image: linear-gradient( | ||
to right, | ||
var(--alert-accent-color) 50%, | ||
var(--alert-bg-color) 50% | ||
); | ||
|
||
line-height: 1.5; | ||
border-block-end: 1px solid var(--color-brand-110); | ||
} | ||
|
||
.alert-banner--informational, | ||
.alert-banner--warning { | ||
--alert-accent-color: var(--color-brand-100); | ||
} | ||
.alert-banner--emergency { | ||
--alert-accent-color: var(--color-red-100); | ||
} | ||
|
||
// has `grid-standard` | ||
.alert-banner__grid { | ||
// background-color: var(--color-white); | ||
|
||
// d = decoration (left color block and icon) | ||
// c = content (including dismiss button) | ||
grid-template-areas: 'd c c c c c c c c c c c'; | ||
|
||
@include lg { | ||
grid-template-areas: 'd d c c c c c c c c c c'; | ||
} | ||
} | ||
|
||
.alert-banner__decoration { | ||
--icon-accent-color: var(--icon-accent-color-dark); | ||
|
||
grid-area: d; | ||
background-color: var(--alert-accent-color); | ||
|
||
// icon placement | ||
display: grid; | ||
justify-content: end; | ||
padding: 6px 4px; | ||
|
||
@include lg { | ||
padding: 20px 8px; | ||
} | ||
|
||
:where(svg) { | ||
width: 20px; | ||
aspect-ratio: 1; | ||
} | ||
} | ||
|
||
.alert-banner__content { | ||
grid-area: c; | ||
background-color: var(--alert-bg-color); | ||
position: relative; // for pseudo element placement | ||
|
||
font-size: px2rem(16); | ||
padding-block: 8px; | ||
|
||
@include lg { | ||
padding-block: 16px; | ||
} | ||
|
||
// Visually add left padding to the alert content | ||
&::before { | ||
content: ''; | ||
position: absolute; | ||
top: 0; | ||
left: calc(-1 * var(--standard-gap)); | ||
width: var(--standard-gap); | ||
height: 100%; | ||
background-color: var(--alert-bg-color); | ||
} | ||
} | ||
|
||
.alert-banner__heading { | ||
font-size: px2rem(20); | ||
} | ||
|
||
// Wrapper for a) text and b) dismiss button | ||
.alert-banner__content--dismissable { | ||
display: grid; | ||
grid-template-columns: 1fr auto; | ||
align-items: start; | ||
gap: 12px; | ||
} | ||
|
||
.alert-banner__text { | ||
max-inline-size: px2rem(1080); | ||
} | ||
|
||
.alert-banner__dismiss-btn { | ||
background: none; | ||
border: none; | ||
font: inherit; | ||
cursor: pointer; | ||
|
||
padding: 4px; | ||
|
||
:where(svg) { | ||
width: px2rem(18); | ||
aspect-ratio: 1; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{% load wagtailcore_tags %} | ||
|
||
{% for alert in site_alerts %} | ||
|
||
<div role="note" | ||
class="u-hidden alert-banner alert-banner--{{ alert.alert_type }}" | ||
data-component="alert-banner" | ||
data-alert-id="alert_{{ alert.alert_id }}" | ||
aria-labelledby="alert-heading-{{ alert.alert_id|slugify }}" | ||
> | ||
<div class="alert-banner__grid content-width grid-standard"> | ||
<div class="alert-banner__decoration"> | ||
{% if alert.alert_type == 'warning' or alert.alert_type == 'emergency' %} | ||
{% include 'includes/svg.html' with sprite="two-tone" svg="warning" %} | ||
{% else %} | ||
{% include 'includes/svg.html' with sprite="two-tone" svg="info" %} | ||
{% endif %} | ||
</div> | ||
<div class="alert-banner__content | ||
{% if alert.dismissable %} | ||
alert-banner__content--dismissable | ||
{% endif %} | ||
"> | ||
<div class="alert-banner__text"> | ||
<h2 id="alert-heading-{{ alert.alert_id|slugify }}" class="alert-banner__heading"> | ||
{{ alert.get_alert_type_display }}: | ||
{# alert.title field is optional, but title prefix (above) appears regardless #} | ||
{{ alert.title }} | ||
</h2> | ||
{{ alert.message|richtext}} | ||
</div> | ||
{% if alert.dismissable %} | ||
<button role="button" class="alert-banner__dismiss-btn" aria-label="Dismiss alert"> | ||
{% include 'includes/svg.html' with sprite="two-tone" svg="x" %} | ||
</button> | ||
{% endif %} | ||
</div> | ||
</div> | ||
</div> | ||
{% endfor %} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debugging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed