1.0.2 • Published 11 months ago

@calumk/vue-progress-status v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

@calumk/vue-progress-status

npm version GitHub license

A customizable status notification system for Vue 3 with a progress bar and hover functionality.

View Demo

Features

  • Clean, minimal status notifications
  • Progress bar for auto-dismissing messages
  • Hover to pause/resume the timer
  • Expandable messages for longer content
  • Multiple message types (info, success, warning, error)
  • Comprehensive history tracking of all notifications and updates
  • Fully customizable via CSS variables

Installation

# npm
npm install @calumk/vue-progress-status

# yarn
yarn add @calumk/vue-progress-status

# pnpm
pnpm add @calumk/vue-progress-status

# bun
bun install @calumk/vue-progress-status

Usage

Basic Usage

// Show a notification
const id = progressStatus.push({
  title: 'Processing',
  message: 'Starting the operation...', // Preferred over 'text'
  severity: 'info',
  timeout: 5000
})

// Update the notification
progressStatus.update(id, {
  title: 'Processing',
  message: 'Operation in progress...',
  severity: 'success'
})

// Cancel the notification
progressStatus.cancel(id)

Available Options

OptionTypeDefaultDescription
titlestring''The title of the notification
messagestring''The message content (preferred)
textstring''The message content (deprecated, use message instead)
severity'info' | 'success' | 'warning' | 'error''info'The severity level of the notification
timeoutnumber10000Duration in milliseconds before auto-dismiss (0 for no auto-dismiss)
cancellablebooleantrueWhether the notification can be manually dismissed

Methods

MethodParametersReturnDescription
pushoptions: MessageOptionsnumberShows a new notification and returns its ID
updateid: number, options: MessageOptionsvoidUpdates an existing notification
cancelid: numbervoidCancels a specific notification
cancelAll-voidCancels all active notifications
getMessages-Message[]Returns all active notifications
getMessageHistory-MessageHistoryEntry[]Returns the history of all notifications
clearHistory-voidClears the notification history

MessageOptions Interface

interface MessageOptions {
  title?: string;
  /** @deprecated Use message instead */
  text?: string;
  message?: string;
  severity?: 'info' | 'success' | 'warning' | 'error';
  timeout?: number;
  cancellable?: boolean;
}

Using the Service

You can use the service to trigger notifications from anywhere in your application. There are two ways to use it:

Method 1: Using Service Methods Directly

<script setup>
import { progressStatusService } from '@calumk/vue-progress-status'

function showServiceNotification() {
  const messageId = progressStatusService.push({
    title: 'Service Notification',
    text: 'This notification was triggered using the service',
    severity: 'info',
    timeout: 5000,
    cancellable: true
  })

  // Update the message
  progressStatusService.update(messageId, {
    text: 'Updated message text'
  })

  // Cancel the message
  progressStatusService.cancel(messageId)
}
</script>

Method 2: Using Message Object Methods

<script setup>
import { progressStatusService } from '@calumk/vue-progress-status'

function showServiceNotification() {
  const message = progressStatusService.push({
    title: 'Service Notification',
    text: 'This notification was triggered using the service',
    severity: 'info',
    timeout: 5000,
    cancellable: true
  })

  // Update the message
  message.update({
    text: 'Updated message text'
  })

  // Cancel the message
  message.cancel()
}
</script>

Don't forget to add the component somewhere in your app:

<template>
  <ProgressStatus />
</template>

<script setup>
import ProgressStatus from '@calumk/vue-progress-status'
</script>

API

Component Props

PropTypeDefaultDescription
debugBooleanfalseEnables debug logging to console

Message Options

OptionTypeDefaultDescription
titleString''Title of the notification
textString''Message content
severityString'info'Type of notification ('info', 'success', 'warning', 'error')
timeoutNumber10000Time in ms before auto-dismiss (0 for no timeout)
cancellableBooleantrueWhether user can dismiss the notification

Methods

MethodParametersReturnDescription
pushoptionsmessageIdAdd a new notification
update(id, options)voidUpdate an existing notification
cancelidvoidDismiss a notification

Development

# Install dependencies
npm install

# Start development server
npm run dev

# Build the library
npm run build

# Build the GitHub Pages demo
npm run build:demo

# Preview the demo locally
npm run preview:demo

# Deploy to GitHub Pages
npm run deploy:demo

License

MIT License


Calum Knott

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

0.3.6

11 months ago

0.3.1

11 months ago

0.3.0

11 months ago

0.2.0

11 months ago

0.1.0

11 months ago