@amonratcha/web-minimal-spinner
v0.0.2
Published
Tiny spinner for browser (Angular-ready ESM bundle)
Readme
# minimal-spinner
Tiny spinner for Node (CLI) and browser (DOM). This package provides a browser-ready ESM bundle so frontend frameworks (Angular, Vite, webpack) can import it directly.
## Install
npm:
```bash
npm install minimal-spinnerBuild (for maintainers)
npm install
npm run buildnpm run buildrunstscto emit types and Node build, andesbuildto createdist/browser.js(ES module).
Usage — Angular (example)
In your Angular component import the browser bundle entry (the package exports points import to dist/browser.js, so typically you can write import Spinner from 'minimal-spinner'):
// src/app/spinner-demo/spinner-demo.component.ts
import { Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
import Spinner from 'minimal-spinner'; // bundlers will resolve to dist/browser.js
@Component({
selector: 'app-spinner-demo',
template: `
<div #host></div>
<button (click)="start()">Start</button>
<button (click)="succeed()">Succeed</button>
<button (click)="fail()">Fail</button>
`
})
export class SpinnerDemoComponent implements OnInit, OnDestroy {
@ViewChild('host', { static: true }) host!: ElementRef<HTMLDivElement>;
private spinner: any;
ngOnInit(): void {
// ensure this runs only in browser (if using SSR, guard with isPlatformBrowser)
this.spinner = new Spinner({ container: this.host.nativeElement, text: 'Loading...', interval: 100 });
}
start() { this.spinner.start(); }
succeed() { this.spinner.succeed('Done'); }
fail() { this.spinner.fail('Failed'); }
ngOnDestroy() { this.spinner?.stop(true); }
}Notes:
- If your Angular app uses SSR (Angular Universal), do not construct or start spinner on server — guard with
isPlatformBrowser. - To test locally without publishing, use
npm packin the spinner project andnpm install ../path/to/minimal-spinner-0.0.1.tgzin your Angular project, or usenpm link.
