JSFiddle - React, Tailwind, and code Playground

by sfoster

HTML

<div class="downloadProgress indeterminate">
  <div class="progress-bar">

  </div>
</div>

<div class="bg">
</div>
<hr>

<p>
<progress value="25"></progress>
</p>

<p>
<my-progress value="25"></my-progress>
</p>

CSS

body {
  background-color: #999;
  --bar-color: rgb(0,97,224);
  --bar-highlight-color: rgb(144,89,255);
  --bar-highlight2-color: #ff4aa2;
  --highlight-background: var(--bar-color) linear-gradient(90deg, transparent 0,
                                                      rgba(205,0,255,0.75) 25%,
                                                      rgba(205,0,255,0.75) 75%,
                                                      transparent 100%)
}

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/*** Common-styled progressmeter ***/

/*
 * Styling "html:progress" is limited by the fact that a number of properties
 * are intentionally locked at the UA stylesheet level. We have to use a border
 * instead of an outline because the latter would be drawn over the progress
 * bar and we cannot change its z-index. This means we have to use a negative
 * margin, except when the value is zero, and adjust the width calculation for
 * the indeterminate state.
 */

.downloadProgress {
  appearance: none;
  display: -moz-box;
  width: 300px;
  margin: 4px 0 0;
  margin-inline-end: 12px;
  border: none;
  border-radius: 3px;
  height: 6px;
  background-color: ButtonFace;
}

.downloadProgress > .progress-bar {
  appearance: none;
  background: var(--highlight-background);
  border-radius: 3px;
}

.downloadProgress[paused] > .progress-bar {
  background: none GrayText;
}

.downloadProgress:not([value="0"]) > .progress-bar {
  margin: -1px;
  height: 8px;
  border-radius: 4px;
}

.downloadProgress[value="100"] > .progress-bar,
.downloadProgress[value="99"] > .progress-bar
{
  background: none var(--bar-color);
}

.downloadProgress.indeterminate > .progress-bar {
  width: calc(100% + 2px);
  /* Make a reflecting animation with our highlight color.
     Create a gradient with 2 identical pattern, and enlarge the size to...

JavaScript

class MyProgress extends HTMLProgressElement {
  connectedCallback() {
  	this.value = 50;
  }
}
customElements.define("my-progress", MyProgress, { extends: "progress" });