UNPKG

@primer/react

Version:

An implementation of GitHub's Primer Design System using React

260 lines (257 loc) • 6.28 kB
import { c } from 'react-compiler-runtime'; import React, { forwardRef } from 'react'; import { clsx } from 'clsx'; import classes from './ProgressBar.module.css.js'; import { BoxWithFallback } from '../internal/components/BoxWithFallback.js'; import { jsx } from 'react/jsx-runtime'; const Item = /*#__PURE__*/forwardRef((t0, forwardRef) => { const $ = c(32); let ariaLabel; let ariaValueNow; let ariaValueText; let className; let progress; let rest; let style; if ($[0] !== t0) { ({ progress, "aria-label": ariaLabel, "aria-valuenow": ariaValueNow, "aria-valuetext": ariaValueText, className, style, ...rest } = t0); $[0] = t0; $[1] = ariaLabel; $[2] = ariaValueNow; $[3] = ariaValueText; $[4] = className; $[5] = progress; $[6] = rest; $[7] = style; } else { ariaLabel = $[1]; ariaValueNow = $[2]; ariaValueText = $[3]; className = $[4]; progress = $[5]; rest = $[6]; style = $[7]; } const progressAsNumber = typeof progress === "string" ? parseInt(progress, 10) : progress; let t1; if ($[8] !== ariaValueNow || $[9] !== progressAsNumber) { var _ariaValueNow; t1 = (_ariaValueNow = ariaValueNow) !== null && _ariaValueNow !== void 0 ? _ariaValueNow : progressAsNumber !== undefined && progressAsNumber >= 0 ? Math.round(progressAsNumber) : 0; $[8] = ariaValueNow; $[9] = progressAsNumber; $[10] = t1; } else { t1 = $[10]; } let t2; if ($[11] !== ariaValueText || $[12] !== t1) { t2 = { "aria-valuenow": t1, "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuetext": ariaValueText }; $[11] = ariaValueText; $[12] = t1; $[13] = t2; } else { t2 = $[13]; } const ariaAttributes = t2; let styles; if ($[14] !== progress || $[15] !== rest.bg) { styles = {}; let t3; if ($[17] !== rest.bg) { t3 = rest.bg && rest.bg.split("."); $[17] = rest.bg; $[18] = t3; } else { t3 = $[18]; } const bgType = t3; styles["--progress-width"] = progress ? `${progress}%` : "0%"; styles["--progress-bg"] = bgType && `var(--bgColor-${bgType[0]}-${bgType[1]})` || "var(--bgColor-success-emphasis)"; $[14] = progress; $[15] = rest.bg; $[16] = styles; } else { styles = $[16]; } let t3; if ($[19] !== className) { t3 = clsx(className, classes.ProgressBarItem); $[19] = className; $[20] = t3; } else { t3 = $[20]; } let t4; if ($[21] !== style || $[22] !== styles) { t4 = { ...styles, ...style }; $[21] = style; $[22] = styles; $[23] = t4; } else { t4 = $[23]; } let t5; if ($[24] !== ariaAttributes || $[25] !== ariaLabel || $[26] !== forwardRef || $[27] !== progress || $[28] !== rest || $[29] !== t3 || $[30] !== t4) { t5 = /*#__PURE__*/jsx(BoxWithFallback, { as: "span", className: t3, ...rest, role: "progressbar", "aria-label": ariaLabel, ref: forwardRef, progress: progress, style: t4, ...ariaAttributes }); $[24] = ariaAttributes; $[25] = ariaLabel; $[26] = forwardRef; $[27] = progress; $[28] = rest; $[29] = t3; $[30] = t4; $[31] = t5; } else { t5 = $[31]; } return t5; }); Item.displayName = 'ProgressBar.Item'; const ProgressBar = /*#__PURE__*/forwardRef((t0, forwardRef) => { const $ = c(32); let animated; let ariaLabel; let ariaValueNow; let ariaValueText; let children; let className; let inline; let progress; let rest; let t1; let t2; if ($[0] !== t0) { ({ animated, progress, bg: t1, barSize: t2, children, "aria-label": ariaLabel, "aria-valuenow": ariaValueNow, "aria-valuetext": ariaValueText, className, inline, ...rest } = t0); $[0] = t0; $[1] = animated; $[2] = ariaLabel; $[3] = ariaValueNow; $[4] = ariaValueText; $[5] = children; $[6] = className; $[7] = inline; $[8] = progress; $[9] = rest; $[10] = t1; $[11] = t2; } else { animated = $[1]; ariaLabel = $[2]; ariaValueNow = $[3]; ariaValueText = $[4]; children = $[5]; className = $[6]; inline = $[7]; progress = $[8]; rest = $[9]; t1 = $[10]; t2 = $[11]; } const bg = t1 === undefined ? "success.emphasis" : t1; const barSize = t2 === undefined ? "default" : t2; if (children && progress) { throw new Error("You should pass `progress` or children, not both."); } let t3; if ($[12] !== children) { t3 = React.Children.toArray(children); $[12] = children; $[13] = t3; } else { t3 = $[13]; } const validChildren = t3.length; let t4; if ($[14] !== className) { t4 = clsx(className, classes.ProgressBarContainer); $[14] = className; $[15] = t4; } else { t4 = $[15]; } const t5 = inline ? "inline" : "block"; let t6; if ($[16] !== animated || $[17] !== ariaLabel || $[18] !== ariaValueNow || $[19] !== ariaValueText || $[20] !== bg || $[21] !== children || $[22] !== progress || $[23] !== validChildren) { t6 = validChildren ? children : /*#__PURE__*/jsx(Item, { "data-animated": animated, progress: progress, "aria-label": ariaLabel, "aria-valuenow": ariaValueNow, "aria-valuetext": ariaValueText, bg: bg }); $[16] = animated; $[17] = ariaLabel; $[18] = ariaValueNow; $[19] = ariaValueText; $[20] = bg; $[21] = children; $[22] = progress; $[23] = validChildren; $[24] = t6; } else { t6 = $[24]; } let t7; if ($[25] !== barSize || $[26] !== forwardRef || $[27] !== rest || $[28] !== t4 || $[29] !== t5 || $[30] !== t6) { t7 = /*#__PURE__*/jsx(BoxWithFallback, { as: "span", ref: forwardRef, className: t4, "data-progress-display": t5, "data-progress-bar-size": barSize, ...rest, children: t6 }); $[25] = barSize; $[26] = forwardRef; $[27] = rest; $[28] = t4; $[29] = t5; $[30] = t6; $[31] = t7; } else { t7 = $[31]; } return t7; }); ProgressBar.displayName = 'ProgressBar'; export { Item, ProgressBar };