1.0.1 • Published 9 days ago

@startinblox/component-notifications v1.0.1

Weekly downloads
108
License
MIT
Repository
-
Last release
9 days ago

Solid Notifications

solid-notifications is a component that displays all elements of an inbox, i.e. a notification container.

When the user clicks one of the notifications, a 'navigate' event is triggered with the object of the notification given as the resource parameter.

The component listens to 'read' events. These events details contain a resource. When such an event is triggered, it sets all notifications with that resource as read, and saves these notifications back to the container. To send an event, you can dispatch it like this:

window.dispatchEvent(new CustomEvent('read', {detail: {resource: resource}}))

Usage

In your template, insert the following line where you want to display the component.

<solid-notifications bind-user nested-field="inbox"></solid-notifications>

If you want to use the bind-user attribute, do not forget to use sib-oidc for authentication.

Parameters

NameDefaultDescription
data-srcundefinedURL of the inbox to display.
nested-field""String added at the end of the data source URL. Useful if you are using bind-user to get the current user URL.
extra-context{}Context to add to let the router know where to navigate after a click on a notification.
date-format"DD/MM/YYYY - kk:mm"Format of the date displayed in the notifications box. For more informations about available formats, look at the moment.js doc.

Routing

To redirect to specific pages when you click on a notification, you should:

  1. Choose a route to be the default view for a resource type. To do this, add the attribute rdf-type to a solid-route (ex: <solid-route name="project" rdf-type="doap:project"></solid-route>)
  2. Add an extra-context to the sib-conversation component, so it can understands the rdf_type you used before.

For more informations, please see the example at index.html

Template

You can customize the template of a notification based on its object type. To do this, use the solid-notifications-template component, and set the data-rdf-type attribute:

<solid-notifications-template
  data-rdf-type="hd:circle"
>
  <template>
    <!-- your template -->
  </template>
</solid-notifications-template>

For each notification with an object of type hd:circle, this template will be used.

The following variables are available in your template:

  • summary: summary of the notification
  • date: formatted date of the notification
  • object: Proxy of the object of the notification (needs await keyword to access its properties)
  • author: Proxy of the author of the notification (needs await keyword to access its properties)
  • unread: boolean which indicates if the notification is unread/read

For example, your template can look like this:

<solid-notifications-template
  data-rdf-type="hd:circle"
>
  <template>
    <div class="solid-notification__avatar">
      <img src="${await author['account.picture']}">
    </div>
    <div class="solid-notification__content">
      <div class="solid-notification__title">${await author.name} in the circle #${await object.name}</div>
      <p class="solid-notification__summary">${summary}</p>
      <div class="solid-notification__date">${date}</div>
    </div>
  </template>
</solid-notifications-template>

The default notification template is:

<div class="solid-notification__avatar">
  <img src="[author.account.picture]">
</div>
<div class="solid-notification__content">
  <solid-display class="solid-notification__title">[notification.object.name]</solid-display>
  <p class="solid-notification__summary">[notification.summary]</p>
  <div class="solid-notification__date">[notification.date]</div>
</div>

Design

To customize your component, you can set the css variable --solid-notifications-theme anywhere in your stylesheet to the color you want. For example:

:root{
  --solid-notifications-theme: #ffd759;
}

Solid Badge

solid-badge is a component that displays the number of unread notifications in the inbox of the logged in user related to a resource or a container.

As it uses the bind-user, you have to make sure to include a valid sib-auth configuration.

Usage

In your template, insert the following line where you want to display the component.

<solid-badge data-src="http://server/resourceId"></solid-badge>

Parameters

NameDefaultDescription
data-srcundefinedURL of the resource or container of which you want to get the unread count.
data-type''Type of the notifications of which you want to get the unread count.
data-rdf-type''RDF type of the notification object of which you want to get the unread count.
nested-field""String added at the end of the data source URL. Useful if you are using bind-resource to get the current displayed resource.

You can combine the data-src, data-type and data-rdf-type attributes to filter a specific kind of notification. For example, this will count the unread notification of the circle-1, for user additions:

<solid-badge data-src="http://server/circle/1" data-type="New User"></solid-badge>

Design

To customize your component, you can set the css variable --solid-badge-theme anywhere in your stylesheet to the color you want. For example:

:root{
  --solid-badge-theme: #ffd759;
}
1.0.1

9 days ago

1.0.1-beta.2

9 days ago

1.0.1-beta.1

9 days ago

1.0.0

4 months ago

1.0.0-alpha.1

4 months ago

1.0.0-beta.1

4 months ago

0.9.2-alpha.1

4 months ago

0.14.3-alpha.2

4 months ago

0.14.3-alpha.1

4 months ago

0.14.2

3 years ago

0.14.0

3 years ago

0.14.1

3 years ago

0.13.0

3 years ago

0.12.1

3 years ago

0.12.0

3 years ago

0.11.3

3 years ago

0.11.2

3 years ago

0.11.1

3 years ago

0.11.0

3 years ago

0.10.4

3 years ago

0.10.3

3 years ago

0.10.2

3 years ago

0.10.1

3 years ago

0.9.0

3 years ago

0.9.1

3 years ago

0.8.4

4 years ago

0.8.3

4 years ago

0.8.2

4 years ago

0.8.1

4 years ago

0.8.0

4 years ago

0.7.3

4 years ago

0.7.2

4 years ago

0.7.1

4 years ago

0.7.0-beta.2

4 years ago

0.7.0

4 years ago

0.7.0-beta.1

4 years ago

0.6.3

4 years ago

0.6.2

4 years ago

0.6.1

4 years ago

0.6.0-beta.2

4 years ago

0.6.0

4 years ago

0.6.0-beta.1

4 years ago

0.5.0

4 years ago

0.5.0-beta.4

4 years ago

0.5.0-beta.3

4 years ago

0.5.0-beta.1

4 years ago

0.5.0-beta.2

4 years ago

0.4.0

4 years ago

0.4.0-beta.2

4 years ago

0.4.0-beta.1

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.26

5 years ago

0.1.25

5 years ago

0.1.24

5 years ago

0.1.23

5 years ago

0.1.22

5 years ago

0.1.21

5 years ago

0.1.20

5 years ago

0.1.19

5 years ago

0.1.18

5 years ago

0.1.17

5 years ago

0.1.16

5 years ago

0.1.15

5 years ago

0.1.14

5 years ago

0.1.13

5 years ago

0.1.12

5 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago