Progress

A bar showing how far along a task is, or that it is running when the amount is unknown.

Install

If this is the first component in the project, set up once. This writes ermine.json and copies the theme stylesheet. The installation guide covers Vue, Nuxt and Astro.

npx ermineui init
pnpm dlx ermineui init
yarn dlx ermineui init
bunx ermineui init

Then add the component:

npx ermineui add progress
pnpm dlx ermineui add progress
yarn dlx ermineui add progress
bunx ermineui add progress

That copies 2 files into src/components/ui/progress/. Files you already have are kept.

Use

import { Progress } from '@/components/ui/progress'
<Alert variant="destructive">
  <svg>…</svg>  <!-- optional: an svg placed first becomes the icon -->
  <AlertTitle>Build failed</AlertTitle>
  <AlertDescription>Type error in cart/total.ts on line 42.</AlertDescription>
</Alert>

<Avatar src="/people/ines.jpg" alt="Ines Kovač">IK</Avatar>

<Progress :value="35" aria-label="Upload" />  <!-- leave value out when the amount is unknown -->
<Spinner />
<Button :loading="saving" @click="save">Save</Button>  <!-- a spinner, and no second press, while saving is true -->

In Nuxt, with the auto-import setting, the tags work in templates without the import. In Astro, use it inside a Vue island.

What gets copied

FileWhere it goes
Progress.vuesrc/components/ui/progress/Progress.vue
index.tssrc/components/ui/progress/index.ts

The folders are the suggested ones. ermine.json says where yours are.

Source

This is exactly what the command copies. To install by hand, create each file below and the helpers listed above.

Progress.vue 85 lines
<script setup lang="ts">
import { computed } from 'vue'

const props = withDefaults(
  defineProps<{
    /** How much is done, from 0 to max. Leave out (or pass null) when the amount is not known. */
    value?: number | null
    max?: number
  }>(),
  { max: 100 },
)

const known = computed(() => typeof props.value === 'number' && Number.isFinite(props.value))
const percent = computed(() => (known.value ? Math.max(0, Math.min((props.value! / props.max) * 100, 100)) : 0))
</script>

<template>
  <div
    role="progressbar"
    class="er-progress"
    aria-valuemin="0"
    :aria-valuemax="max"
    :aria-valuenow="known ? Math.max(0, Math.min(value!, max)) : undefined"
    :data-state="known ? (percent === 100 ? 'complete' : 'loading') : 'indeterminate'"
    :style="{ '--er-progress': `${percent}%` }"
  >
    <div class="er-progress-bar" />
  </div>
</template>

<style>
@layer components {
  .er-progress {
    width: 100%;
    height: 0.5rem;
    border-radius: 999px;
    background: color-mix(in oklab, var(--er-primary) 15%, transparent);
    overflow: hidden;
  }

  .er-progress-bar {
    width: 100%;
    height: 100%;
    border-radius: inherit;
    background: var(--er-primary);
    transform: translateX(calc(var(--er-progress, 0%) - 100%));
    transition: transform 300ms var(--er-ease);
  }

  .er-progress[data-state='indeterminate'] .er-progress-bar {
    width: 40%;
    transform: none;
    transition: none;
    animation: er-progress-slide 1.4s ease-in-out infinite;
  }

  @keyframes er-progress-slide {
    from {
      transform: translateX(-100%);
    }
    to {
      transform: translateX(250%);
    }
  }

  /* Without motion, a bar that fades in place still reads as "working". */
  @media (prefers-reduced-motion: reduce) {
    .er-progress-bar {
      transition: none;
    }

    .er-progress[data-state='indeterminate'] .er-progress-bar {
      width: 100%;
      animation: er-progress-fade 2s ease-in-out infinite;
    }
  }

  @keyframes er-progress-fade {
    50% {
      opacity: 0.35;
    }
  }
}
</style>
index.ts 3 lines
/** Progress — a bar showing how far along a task is, or that it is running when the amount is unknown. */
export { default as Progress } from './Progress.vue'