Newer
Older
vmk-ui-kit / src / js / components / progress.js
@Eugene Sukhodolskiy Eugene Sukhodolskiy 2 days ago 586 bytes Add Tabs, Avatar, Chip, and Progress components
/**
 * VMK UI Kit browser progress helper.
 *
 * Simple utility to update .progress-bar widths.
 */

function setValue(element, value, max = 100) {
  const progress = typeof element === "string" ? document.querySelector(element) : element;
  if (!progress) return;

  const bar = progress.querySelector(".progress-bar");
  if (!bar) return;

  const percentage = Math.max(0, Math.min(100, (value / max) * 100));
  bar.style.width = `${percentage}%`;
  bar.setAttribute("aria-valuenow", String(value));
  bar.setAttribute("aria-valuemax", String(max));
}

export default {
  setValue
};