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AS,CAAC,iCAAmB,gBAAC;wBAAK,WAAW,kCAAY;kCAAC;4BAAM,YAAY;2CAAO;wBAAa;kCAAK;;kCACvG,gBAAC;wBAAI,WAAW,kCAAY;2CAAC;kCAAe;wBAAI;kCAC9C,cAAA,gBAAC;4BACC,WAAW,CAAA,GAAA,yCAAU,EAAE,2BAAK;gCAAC,GAAG,KAAK;+CAAE;4BAAa,IAAK,kBAAkB,6CAAuB;2CAAC;4BAAS,KAAK;4BACjH,OAAO;gCAAC,OAAO,kBAAkB,YAAY,aAAa;4BAAG;;;;;;AAM3E","sources":["packages/@react-spectrum/s2/src/ProgressBar.tsx"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {\n ProgressBar as AriaProgressBar,\n ProgressBarProps as AriaProgressBarProps,\n ContextValue\n} from 'react-aria-components';\nimport {bar, track} from './bar-utils' with {type: 'macro'};\nimport {createContext, forwardRef, ReactNode} from 'react';\nimport {DOMRef, DOMRefValue, LabelPosition} from '@react-types/shared';\nimport {FieldLabel} from './Field';\nimport {fieldLabel, getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};\nimport {keyframes} from '../style/style-macro' with {type: 'macro'};\nimport {mergeStyles} from '../style/runtime';\nimport {style} from '../style' with {type: 'macro'};\nimport {useDOMRef} from '@react-spectrum/utils';\nimport {useLocale} from '@react-aria/i18n';\nimport {useSpectrumContextProps} from './useSpectrumContextProps';\n\ninterface ProgressBarStyleProps {\n /**\n * The size of the ProgressBar.\n *\n * @default 'M'\n */\n size?: 'S' | 'M' | 'L' | 'XL',\n /**\n * Whether presentation is indeterminate when progress isn't known.\n */\n isIndeterminate?: boolean,\n /**\n * The static color style to apply. Useful when the button appears over a color background.\n */\n staticColor?: 'white' | 'black' | 'auto',\n /**\n * The label's overall position relative to the element it is labeling.\n * @default 'top'\n */\n labelPosition?: LabelPosition\n\n}\n\nexport interface ProgressBarProps extends Omit<AriaProgressBarProps, 'children' | 'className' | 'style'>, ProgressBarStyleProps, StyleProps {\n /** The content to display as the label. */\n label?: ReactNode\n}\n\nexport const ProgressBarContext = createContext<ContextValue<Partial<ProgressBarProps>, DOMRefValue<HTMLDivElement>>>(null);\n\nconst indeterminateLTR = keyframes(`\n 0% {\n transform: translateX(-70%) scaleX(0.7);\n }\n 100% {\n transform: translateX(100%) scaleX(0.7);\n }\n`);\n\nconst indeterminateRTL = keyframes(`\n 0% {\n transform: translateX(100%) scaleX(0.7);\n }\n 100% {\n transform: translateX(-70%) scaleX(0.7);\n }\n`);\n\nconst wrapper = style({\n ...bar(),\n gridTemplateColumns: {\n default: {\n labelPosition: {\n top: ['1fr', 'auto'],\n side: ['auto', '1fr']\n }\n },\n isIndeterminate: {\n labelPosition: {\n top: ['1fr'],\n side: ['auto', '1fr']\n }\n }\n },\n gridTemplateAreas: {\n default: {\n labelPosition: {\n top: [\n 'label value',\n 'bar bar'\n ],\n side: [\n 'label bar value'\n ]\n }\n },\n isIndeterminate: {\n labelPosition: {\n top: [\n 'label',\n 'bar'\n ],\n side: [\n 'label bar'\n ]\n }\n }\n }\n}, getAllowedOverrides());\n\nconst valueStyles = style({\n ...fieldLabel(),\n gridArea: 'value'\n});\n\nconst trackStyles = style({\n ...track(),\n height: {\n default: 6,\n size: {\n S: 4, // progress-bar-thickness-small\n M: 6, // progress-bar-thickness-medium\n L: 8, // progress-bar-thickness-large\n XL: 10 // progress-bar-thickness-extra-large\n }\n }\n});\n\nconst fill = style<ProgressBarStyleProps & {isStaticColor: boolean}>({\n height: 'full',\n borderStyle: 'none',\n borderRadius: 'full',\n backgroundColor: {\n default: 'accent',\n isStaticColor: 'transparent-overlay-900',\n forcedColors: 'ButtonText'\n },\n width: {\n isIndeterminate: 'full'\n },\n transformOrigin: {\n isIndeterminate: 'left'\n }\n});\n\nconst indeterminateAnimation = style({\n animation: {\n direction: {\n ltr: indeterminateLTR,\n rtl: indeterminateRTL\n }\n },\n animationDuration: 1000,\n animationIterationCount: 'infinite',\n animationTimingFunction: 'in-out',\n willChange: 'transform',\n position: 'relative'\n});\n\n/**\n * ProgressBars show the progression of a system operation: downloading, uploading, processing, etc., in a visual way.\n * They can represent either determinate or indeterminate progress.\n */\nexport const ProgressBar = /*#__PURE__*/ forwardRef(function ProgressBar(props: ProgressBarProps, ref: DOMRef<HTMLDivElement>) {\n [props, ref] = useSpectrumContextProps(props, ref, ProgressBarContext);\n let {\n label, size = 'M',\n staticColor,\n isIndeterminate,\n labelPosition = 'top',\n UNSAFE_style,\n UNSAFE_className = ''\n } = props;\n let domRef = useDOMRef(ref);\n let {direction} = useLocale();\n let isStaticColor = !!staticColor;\n\n return (\n <AriaProgressBar\n {...props}\n ref={domRef}\n style={UNSAFE_style}\n className={UNSAFE_className + wrapper({...props, size, labelPosition, staticColor}, props.styles)}>\n {({percentage, valueText}) => (\n <>\n {label && <FieldLabel size={size} labelAlign=\"start\" labelPosition={labelPosition} staticColor={staticColor}>{label}</FieldLabel>}\n {label && !isIndeterminate && <span className={valueStyles({size, labelAlign: 'end', isStaticColor})}>{valueText}</span>}\n <div className={trackStyles({isStaticColor, size})}>\n <div\n className={mergeStyles(fill({...props, isStaticColor}), (isIndeterminate ? indeterminateAnimation({direction}) : null))}\n style={{width: isIndeterminate ? undefined : percentage + '%'}} />\n </div>\n </>\n )}\n </AriaProgressBar>\n );\n});\n\n"],"names":[],"version":3,"file":"ProgressBar.mjs.map"}