CodeCoupler Application Basics Service Worker Loader Vue 🔒
What is this?
This Vue component uses @codecoupler-pro/app-service-worker to display an icon indicating the status of the service worker. Four different icons are displayed depending on the status: Loading, OK, Error, and Update Available.
If an update is available, a pop-up will appear below the button to alert the user to install it.
Clicking the icon displays a dropdown menu that offers the user the following options depending on the status: Check for updates, Install update, Reload page (in case of an error).
In addition, the current version number of the service worker is displayed, as well as an error message if an error occurs.
The component uses bootstrap in combination with @popperjs/core to display the dropdown and the
popup.
Setup
Install Bundle:
Define Aliases, Externals and Assets:
Basic Usage
Use it with JavaScript:
Use it as a CodeCoupler Costa Component:
Use it as Vue component:
Icons
All standard icons are defined as SVG. They have no background, width and height are set to
1em and all shapes use the current text color (fill or stroke attributes are set to
"currentColor"). For custom SVG icons, it is recommended that you follow this principle as well.
You can override the default icons using the property iconsComponent. Create a Vue file with
multiple svg icons and tag them with v-if like shown below. Place them all in one span element.
Define then one prop icon:
| icons-component-custom.vue | |
|---|---|
Import this file and use this as prop:
The following icon identifiers can be used:
- error
- loading
- ok
- update
- reload
- lookup
- update-now
Styling
CSS Classes
The internal HTML structure can be accessed as follows:
You can select a specific icon by adding the identifier: "& span.icon.identifier {}". Possible identifiers can be found in the above section.
Dropdown Menu and Items
The dropdown menu will be rendered into the body of the document. For this reason, in addition to
the dropdown-menu class, you can assign an additional class to the dropdown using the
dropdownClasses prop to target it more precisely.
Use this class in conjunction with the dropdown-menu class to access the inner HTML elements.
Otherwise, Bootstrap's predefined styles may override yours if the Bootstrap stylesheet is loaded
after your own:
Each entry in the dropdown menu has the class dropdown-item. In addition, an extra class specifies
the type of content, which contains specific inner elements.
Dropdown item with an icon and text:
You can select a specific dropdown menu item with an icon and text by adding the
identifier: & a.dropdown-item.identifier {}. Possible identifiers:
- loading
- lookup
- update-now
- reload
Dropdown item with error message:
Dropdown item with version information:
Popover
The popovers will be rendered into the body of the document. For this reason, in addition to the
popover class, you can assign an additional class to the popovers using the popoverClasses prop
to target it more precisely.
Use this class in conjunction with the popover class to access the inner HTML elements. Otherwise,
Bootstrap's predefined styles may override yours if the Bootstrap stylesheet is loaded after your
own:
Popovers contains specific inner elements.
Header:
Body:
Customizing using Bootstrap variables (example):
Colorizing arrow depending on placement using plain CSS:
Reference
The following props can be passed:
swLoader: Object-
ServiceWorkerLoader instance.
dropdownClasses: String-
Additional class names for dropdown menu element. The specified classes will be set via the
setClassfunction from the@codecoupler/dom-bundlepackage. You can provide one or more class names as a string of space-separated values or as an array of strings. See above. popoverClasses: String-
Additional class names for dropdown menu element. The popup will be rendered into the
bodyof the document. For this reason, in addition to thepopupclass, you can assign an additional class to the popup using thepopoverClassesprop to target it more precisely. iconsComponent: Vue-
Overrides the default icons. See above.
texts: Object-
Redefine all texts here:
showIcons: Object-
To show the icons regardless of the current status you can pass the identifier as properties and the value
trueto this object. Example:{ identifier1: true }. swUpdateLocation: StringandswUpdateLocationForced: String-
History replacement in case of an service loader update or a forced service loader update. The default values are
/#sw-updateand/#sw-update-forced. swDebugUpdateAvailable: Boolean-
If
truean available update is simulated. The update can be started, and the browser is forced to reload the ServiceWorker.