{"version":3,"file":"ProgressBar.mjs","sources":["../../../src/components/ProgressBar/ProgressBar.tsx"],"sourcesContent":["import clsx from 'clsx';\nimport React from 'react';\n\nimport { assertEdsUsage } from '../../util/logging';\nimport type { EitherInclusive } from '../../util/utility-types';\nimport Counter from '../Counter';\nimport FieldLabel from '../FieldLabel';\nimport Text from '../Text';\n\nimport styles from './ProgressBar.module.css';\n\n// React.HTMLAttributes<HTMLProgressElement>\nexport type ProgressBarProps = {\n  // Component API\n  /**\n   * CSS class names that can be appended to the component.\n   */\n  className?: string;\n  /**\n   * CSS properties defined for the progress bar track. Includes the component's CSS Custom Properties:\n   *\n   * - `--progress-bar__bg`\n   * - `--progress-bar__fg`\n   */\n  style?: ProgressBarCSSProperties;\n  // Design API\n  /**\n   * Determines the usage context of the progress bar.\n   * * Labels and value strings are only valid for `context`=`standalone`.\n   * * Never use `context`=`embedded` unless as a child of a container.\n   *\n   * **Default is `\"standalone\"`**.\n   */\n  context?: 'embedded' | 'standalone';\n  /**\n   * Determine whether the labels sit above or to the left of the progress bar\n   *\n   * **Default is `\"vertical\"`**.\n   */\n  labelLayout?: 'horizontal' | 'vertical';\n  /**\n   * The maximum numeric value allowed for the progress bar.\n   *\n   * ** Default is `1`**.\n   */\n  max?: number;\n  /**\n   * The “filled” portion of the progressBar is determined by the relationship between the minValue, maxValue, and Value. The var fills to a percentage = (value)/(maxValue–minValue).\n   *\n   * Value used by component is a number between 0 and 1.\n   */\n  value: number;\n  /**\n   * Human-readable representation of the progress shown in the bar.\n   */\n  valueLabel?: string;\n} & EitherInclusive<\n  {\n    /**\n     * Visible text label for the component.\n     */\n    descriptionLabel: string;\n  },\n  {\n    /**\n     * Aria-label to provide an accesible name for the text input if no visible label is provided.\n     */\n    'aria-label': string;\n  }\n>;\n\nexport interface ProgressBarCSSProperties extends React.CSSProperties {\n  /**\n   * Custom property to customize the background color of this component (e.g., background color)\n   */\n  '--progress-bar__bg'?: string;\n\n  /**\n   * Custom property to customize the foreground color of this component (e.g., text, icon, etc.)\n   */\n  '--progress-bar__fg'?: string;\n}\n\n/**\n * The properties actually applied to the track, which is `ProgressBarCSSProperties` plus the one\n * the component sets for itself. Deliberately not exported and not part of the public interface,\n * so a caller cannot set the fill directly.\n */\ninterface ProgressBarTrackCSSProperties extends ProgressBarCSSProperties {\n  /**\n   * The filled share of the track, derived from `value` and `max`.\n   */\n  '--progress-bar__progress'?: number;\n}\n\nconst PROGRESS_BAR_MINIMUM = 0;\n\n/**\n * BETA: This component is still a work in progress and is subject to change.\n *\n * ## Usage\n *\n * Show the level of completeness for a given task or process. Indicate the percentage of\n * completion for a discrete number of steps. Not to be confused with the `LoadingIndicator`, which\n * covers waiting rather than measured progress.\n *\n * | Type/Use | Description | Example |\n * |----------|-------------|---------|\n * | Standalone | The default. Shows the bar with its labels above or beside it, set by `labelLayout`. | Page-level progress after a user action. |\n * | Embedded | `context=\"embedded\"` drops the labels and lets the bar sit flush with its container's edges. | A bar along the edge of a `Modal` or `Card`. |\n *\n * `ProgressBar` can be the child of a container like `Modal` or `Card`. When used in such a\n * container, `context`=`embedded` should be used to ensure the left and right edges of the\n * progressBar sit flush within the edges of the container.\n *\n * `value` is read against `max` (default `1`) and clamped to that range, so the bar cannot report\n * below zero or above 100%. Supply `valueLabel` to replace the computed percentage with your own\n * text, or pass an empty string to suppress it.\n *\n * ## Content & Accessibility\n *\n * ### Do's\n *\n * * Use `ProgressBar` when content can be progressively completed and is triggered by user action (e.g., a click of a button) at the page level.\n * * Use `ProgressBar` to show a measure within a form or other display, where the bar is static and reflects useful details.\n * * Give every bar a name. The type requires either a visible `descriptionLabel` or an `aria-label`, which matters most for `context=\"embedded\"`, where no visible label renders.\n *\n * ### Don'ts\n *\n * * Avoid using `ProgressBar` when you have a wizard-like, paginated experience. Use `VisualPageIndicator` instead.\n * * Avoid `ProgressBar` without labels for user feedback.\n */\nexport const ProgressBar = ({\n  className,\n  context = 'standalone',\n  descriptionLabel,\n  labelLayout = 'vertical',\n  max = 1,\n  style,\n  value,\n  valueLabel,\n  ...other\n}: ProgressBarProps) => {\n  const componentClassName = clsx(\n    styles['progress-bar'],\n    labelLayout && styles[`progress-bar--labelLayout-${labelLayout}`],\n    className,\n  );\n\n  const progressBarId = React.useId();\n\n  // compute display values by checking ranges and normalizing outputs\n  const computedValue = Math.max(Math.min(value, max), PROGRESS_BAR_MINIMUM);\n\n  // A caller-supplied `valueLabel` replaces the computed percentage outright, including an empty\n  // string used to suppress the value entirely\n  const shouldRenderPercentage =\n    valueLabel === undefined || valueLabel === null;\n\n  const shouldRenderLabels = !!(\n    descriptionLabel ||\n    shouldRenderPercentage ||\n    valueLabel\n  );\n\n  const trackClassName = clsx(\n    styles['progress-bar__track'],\n    context && styles[`progress-bar__track--context-${context}`],\n  );\n\n  const trackStyle: ProgressBarTrackCSSProperties = {\n    ...style,\n    // Set after the caller's styles: the fill is derived from `value`, so it is not a\n    // caller-facing custom property.\n    '--progress-bar__progress': computedValue / max,\n  };\n\n  // Both checks cover label props, which an embedded bar never renders. Advisory rather than\n  // broken usage, so it warns at the same level as the range check below.\n  assertEdsUsage(\n    [\n      context === 'embedded' && !!descriptionLabel,\n      context === 'embedded' && !!valueLabel,\n    ],\n    'Labels are not allowed when context is embedded',\n  );\n\n  assertEdsUsage(\n    [value > max, value < PROGRESS_BAR_MINIMUM],\n    `Value ${value} outside allowed range between ${PROGRESS_BAR_MINIMUM} and ${max}`,\n  );\n\n  // TODO: use <progress> component instead, and override appearance?\n  return (\n    <div className={componentClassName}>\n      {context === 'standalone' && shouldRenderLabels && (\n        <div className={styles['progress-bar__labels']}>\n          {descriptionLabel && (\n            <FieldLabel id={progressBarId} size=\"md\">\n              {descriptionLabel}\n            </FieldLabel>\n          )}\n          {/*\n            Always the percentage variant here: progress is a share of the whole, never a count\n            of discrete items. `computedValue` is already clamped to `max`, so the counter's\n            over-total treatment cannot trigger.\n          */}\n          {shouldRenderPercentage && (\n            <Counter\n              className={styles['progress-bar__valueLabel']}\n              count={computedValue}\n              total={max}\n              variant=\"percentage\"\n            />\n          )}\n          {valueLabel && (\n            <Text\n              as=\"span\"\n              className={styles['progress-bar__valueLabel']}\n              preset=\"body-sm\"\n            >\n              {valueLabel}\n            </Text>\n          )}\n        </div>\n      )}\n      <div\n        aria-labelledby={\n          descriptionLabel && context === 'standalone'\n            ? progressBarId\n            : undefined\n        }\n        className={trackClassName}\n        role=\"progressbar\"\n        style={trackStyle}\n        {...other}\n      >\n        <div className={styles['progress-bar__content']} />\n      </div>\n    </div>\n  );\n};\n\nProgressBar.displayName = 'ProgressBar';\n"],"names":["React"],"mappings":";;;;;;;;AA+FA,MAAM,oBAAoB,GAAG,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCG;AACI,MAAM,WAAW,GAAG,CAAC,EAC1B,SAAS,EACT,OAAO,GAAG,YAAY,EACtB,gBAAgB,EAChB,WAAW,GAAG,UAAU,EACxB,GAAG,GAAG,CAAC,EACP,KAAK,EACL,KAAK,EACL,UAAU,EACV,GAAG,KAAK,EACS,KAAI;IACrB,MAAM,kBAAkB,GAAG,IAAI,CAC7B,MAAM,CAAC,cAAc,CAAC,EACtB,WAAW,IAAI,MAAM,CAAC,6BAA6B,WAAW,CAAA,CAAE,CAAC,EACjE,SAAS,CACV;AAED,IAAA,MAAM,aAAa,GAAGA,cAAK,CAAC,KAAK,EAAE;;AAGnC,IAAA,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,oBAAoB,CAAC;;;IAI1E,MAAM,sBAAsB,GAC1B,UAAU,KAAK,SAAS,IAAI,UAAU,KAAK,IAAI;AAEjD,IAAA,MAAM,kBAAkB,GAAG,CAAC,EAC1B,gBAAgB;QAChB,sBAAsB;AACtB,QAAA,UAAU,CACX;AAED,IAAA,MAAM,cAAc,GAAG,IAAI,CACzB,MAAM,CAAC,qBAAqB,CAAC,EAC7B,OAAO,IAAI,MAAM,C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