Skip to content

Commit 425c5f9

Browse files
authored
feat(notification-banner): support long polling and css custom variables (#158)
* feat: enhanced banner to support custom styling * Added long polling feature * fixes lint errors * Added validation for new props, updated vss var name, fixed documentation
1 parent 0deac78 commit 425c5f9

File tree

3 files changed

+152
-10
lines changed

3 files changed

+152
-10
lines changed

@uportal/notification-banner/README.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,83 @@ npm run build
2727
```
2828
npm run lint
2929
```
30+
31+
## Attributes
32+
33+
`<notification-banner>` takes the following attributes:
34+
35+
### `notification-api-url`
36+
37+
Url to connect notification-endpoint. Defaults to `/NotificationPortlet/api/v2/notifications`.
38+
39+
```html
40+
<notification-banner
41+
notification-api-url="/NotificationPortlet/api/v2/notifications"
42+
></notification-banner>
43+
```
44+
45+
### `user-info-api-url`
46+
47+
Url to connect to oidc. The default for this value is `/uPortal/api/v5-1/userinfo`.
48+
49+
```html
50+
<notification-banner user-info-api-url="/uPortal/api/v5-1/userinfo"></notification-banner>
51+
```
52+
53+
### `notificationVariant`
54+
55+
Bootstrap variant of 'alert' component to style notification items. Default is 'info'. Can be set to 'custom' to add 'alert-custom' class which will allow styling according to theming section below.
56+
57+
```html
58+
<notification-banner notificationVariant="info"></notification-banner>
59+
```
60+
61+
### `notificationIcon`
62+
63+
Icon displayed next to heading. Supports "info" and "exclamation-triangle" from Font Awesome.
64+
65+
```html
66+
<notification-banner notificationIcon="info"></notification-banner>
67+
```
68+
69+
### `notificationIconSize`
70+
71+
Icon size for Font Awesome icon displayed next to heading.
72+
73+
```html
74+
<notification-banner notificationIconSize="2x"></notification-banner>
75+
```
76+
77+
### `filter`
78+
79+
Query string parameter to append to api call to retrieve notifications.
80+
81+
```html
82+
<notification-banner notificationIconSize="2x"></notification-banner>
83+
```
84+
85+
### `debug`
86+
87+
Skips oidc call for api token.
88+
89+
```html
90+
<notification-banner debug></notification-banner>
91+
```
92+
93+
### Theming
94+
95+
Currently this component supports [CSS Variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables) for overriding button colors. Defining the following variables will change the colors for the component accordingly. They will fall back to the colors described below.
96+
97+
You should define this in your custom stylesheet.
98+
99+
```css
100+
:root {
101+
--notif-banner-heading-text-color: white; /* text color of notification item heading */
102+
--notif-banner-body-text-color: white; /* text color of notification item body */
103+
--notif-banner-bg-color: darkred; /* background color of notification items */
104+
--notif-banner-border-color: darkred; /* border color of notification items */
105+
--notif-banner-border-radius: 0; /* border radius of notification items */
106+
--notif-banner-item-margin: 0 0 1px 0; /* margin between notification items */
107+
--notif-banner-container-margin: 0; /* margin around notification item list */
108+
}
109+
```

@uportal/notification-banner/src/App.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<template>
22
<div id="app">
33
<img alt="Vue logo" src="./assets/logo.png" />
4-
<NotificationBanner debug="true" notificationApiUrl="sample-notifications.json" />
4+
<NotificationBanner debug="true"
5+
notificationVariant="success"
6+
notificationApiUrl="sample-notifications.json"
7+
filter="user=foobar"
8+
notificationIcon="info" />
59
</div>
610
</template>
711

@@ -25,4 +29,5 @@ export default {
2529
color: #2c3e50;
2630
margin-top: 60px;
2731
}
32+
2833
</style>

@uportal/notification-banner/src/components/NotificationBanner.vue

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<template>
22
<div class="notification-banner">
3-
<b-alert v-for="(notification, index) in notifications" :key="index" varient="info" show>
3+
<b-alert v-for="(notification, index) in notifications" :key="index" :varient="notificationVariant" :class="{'alert-custom': customVariant}" show>
44
<h4>
5-
<font-awesome-icon icon="info" />
5+
<font-awesome-icon :icon="notificationIcon" :size="notificationIconSize" />
66
{{ notification.title }}
77
</h4>
88
<span v-html="notification.body" />
@@ -12,21 +12,27 @@
1212

1313
<script>
1414
import { library } from '@fortawesome/fontawesome-svg-core';
15-
import { faInfo } from '@fortawesome/free-solid-svg-icons/faInfo';
15+
import { faInfo, faExclamationTriangle } from '@fortawesome/free-solid-svg-icons';
1616
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
1717
import bAlert from 'bootstrap-vue/es/components/alert/alert';
1818
import oidc from '@uportal/open-id-connect';
1919
import { get } from 'axios';
2020
21-
library.add(faInfo);
21+
library.add(faInfo, faExclamationTriangle);
22+
23+
const variants = ['info', 'primary', 'success', 'danger', 'warning', 'secondary', 'light', 'dark'];
24+
const icons = ['info', 'exclamation-triangle'];
25+
const sizes = ['xs', 'sm', 'lg', ...[...Array(10).keys()].map(k => `${k + 1}x`)];
26+
27+
const validator = (list) => (value) => list.indexOf(value) !== -1
2228
2329
export default {
2430
name: 'NotificationBanner',
2531
2632
props: {
2733
debug: {
28-
type: Boolean,
29-
default: false
34+
type: String,
35+
default: 'false'
3036
},
3137
userInfoApiUrl: {
3238
type: String,
@@ -36,9 +42,28 @@ export default {
3642
type: String,
3743
default: '/NotificationPortlet/api/v2/notifications'
3844
},
45+
notificationVariant: {
46+
type: String,
47+
default: 'info',
48+
validator: validator(variants)
49+
},
50+
notificationIcon: {
51+
type: String,
52+
default: 'info',
53+
validator: validator(icons)
54+
},
55+
notificationIconSize: {
56+
type: String,
57+
default: '1x',
58+
validator: validator(sizes)
59+
},
3960
filter: {
4061
type: String,
41-
default: ''
62+
default: '',
63+
},
64+
refresh: {
65+
type: String,
66+
default: '0'
4267
}
4368
},
4469
@@ -54,14 +79,24 @@ export default {
5479
};
5580
},
5681
82+
computed: {
83+
isDebug: function () {
84+
return this.debug === 'true' ? true : false;
85+
},
86+
customVariant: function () {
87+
const { notificationVariant } = this;
88+
return variants.indexOf(notificationVariant) === -1;
89+
}
90+
},
91+
5792
methods: {
5893
async fetchNotifications() {
5994
// read props
60-
const { debug, notificationApiUrl, filter, userInfoApiUrl } = this;
95+
const { notificationApiUrl, filter, userInfoApiUrl } = this;
6196
6297
try {
6398
// Obtain an OIDC Id Token, except in debug mode
64-
const { encoded: token } = debug
99+
const { encoded: token } = this.isDebug
65100
? { encoded: null }
66101
: await oidc({ userInfoApiUrl });
67102
@@ -81,6 +116,14 @@ export default {
81116
// eslint-disable-next-line no-console
82117
console.error(err);
83118
}
119+
120+
if (this.refresh !== '0') {
121+
const { refresh } = this;
122+
const time = parseInt(refresh);
123+
124+
setTimeout(() => this.fetchNotifications(), time);
125+
}
126+
84127
}
85128
},
86129
@@ -103,7 +146,21 @@ export default {
103146
104147
// custom styles
105148
margin: 1rem;
149+
margin: var(--notif-banner-container-margin, 1rem);
106150
text-align: left;
151+
152+
.alert.alert-custom {
153+
background: var(--notif-banner-bg-color, grey);
154+
color: var(--notif-banner-body-text-color, white);
155+
border-color: var(--notif-banner-border-color, var(--notif-banner-bg-color, grey));
156+
border-radius: var(--notif-banner-border-radius, 0.25rem);
157+
margin: var(--notif-banner-item-margin, 1rem);
158+
159+
> h4 {
160+
color: var(--notif-banner-heading-text-color, white);
161+
margin-top: 0;
162+
}
163+
}
107164
}
108165
109166
.notification-banner svg {

0 commit comments

Comments
 (0)