# @uptimelink/webwidget
the webwidget for public use of uptimelink
## Install
To install the `@uptimelink/webwidget` package, you need to have Node.js and npm (or yarn) installed. Once you have these prerequisites, you can install the package via npm by running the following command in your terminal:
```bash
npm install @uptimelink/webwidget
```
Alternatively, if you use yarn, you can run:
```bash
yarn add @uptimelink/webwidget
```
## Usage
### Introduction
The `@uptimelink/webwidget` package provides a web component that can be embedded into web pages to display uptime information for a given project on the UptimeLink platform. The component is implemented using TypeScript and leverages modern web standards including Web Components and LitElement.
### Basic Setup
First, you will need to import the `UptimelinkWebwidget` class and define it in your project. To do this, create an HTML file and include a script to register the web component.
```typescript
// index.ts
import { UptimelinkWebwidget } from '@uptimelink/webwidget';
// Append the webwidget component to the document body
document.body.appendChild(UptimelinkWebwidget.demo());
```
### Setting Up in HTML
To use the widget in an HTML document, you will need to include the built JavaScript file. Here is an example:
```html
${this.showExpanded ? html`
/* Expanded view content */
` : null}
`;
}
private async setupEventing() {
const domtools = await this.domtoolsPromise;
await this.updateComplete;
const mainbox = this.shadowRoot.querySelector('.mainbox') as HTMLDivElement;
mainbox.onmouseenter = async () => {
if (!this.isOnTop) {
const rect = mainbox.getBoundingClientRect();
const uptimelinkWidget = new UptimelinkWebwidget();
uptimelinkWidget.isOnTop = true;
uptimelinkWidget.style.position = 'fixed';
uptimelinkWidget.style.top = `${rect.top}px`;
uptimelinkWidget.style.left = `${rect.left}px`;
document.body.append(uptimelinkWidget);
return;
}
this.isElevated = true;
this.isFocused = true;
this.windowLayer = await DeesWindowLayer.createAndShow({ blur: true });
await domtools.convenience.smartdelay.delayFor(200);
if (!this.isFocused) return;
this.showExpanded = true;
await this.performUpdate();
await domtools.convenience.smartdelay.delayFor(50);
const expandedDiv = this.shadowRoot.querySelector('.expanded') as HTMLElement;
expandedDiv.style.opacity = '1';
};
mainbox.onmouseleave = async () => {
if (!this.isOnTop) return;
this.windowLayer.destroy();
domtools.convenience.smartdelay.delayFor(200).then(() => {
if (!this.isFocused) {
this.isElevated = false;
this.remove();
}
});
if (!this.showExpanded) {
this.isFocused = false;
return;
}
this.showExpanded = false;
await domtools.convenience.smartdelay.delayFor(50);
this.isFocused = false;
}
}
}
```
### Utilizing Multiple Widgets
You can also utilize multiple instances of the web widget on a single page. Below is an example of how you could do this:
```typescript
// multipleWidgets.ts
import { UptimelinkWebwidget } from '@uptimelink/webwidget';
const widget1 = document.createElement('uptimelink-webwidget');
const widget2 = document.createElement('uptimelink-webwidget');
widget1.projectSlug = 'project1';
widget2.projectSlug = 'project2';
document.body.appendChild(widget1);
document.body.appendChild(widget2);
```
### Building and Serving
To build the project, use the following npm scripts:
```bash
npm run build
```
To watch for changes and rebuild automatically:
```bash
npm run watch
```
### Testing
Currently, the `test` script is identical to the `build` script. Running tests requires building the project:
```bash
npm run test
```
### Contributing
Contributions to the `@uptimelink/webwidget` project are welcome! Please follow the guidelines provided in the repository. Reach out on the project issues page for discussions, questions, or follow the established process for submitting pull requests.
### Conclusion
This guide covered the steps needed to install, set up, and use the `@uptimelink/webwidget` package in your TypeScript projects. We also explored various ways to customize and extend the widget, ensuring seamless integration into your existing web applications. For more detailed information, refer to the [documentation](https://uptimelink.gitlab.io/webwidget/).
Feel free to check the links provided in the initial sections for more context and updates about the project's status and availability.
undefined