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,gCAAC,CAAA,GAAA,sCAAU;4BACT,WAAW,CAAA,GAAA,wCAAa;4BACxB,OAAO;4BACP,MAAM,MAAM,OAAO;4BACnB,cAAY,gBAAgB,MAAM,CAAC;4BACnC,KAAK;4BACL,OAAO,CAAC,cAAgB,CAAA,GAAA,oCAAS,EAAE,eAAe;oCAChD,WAAW;gCACb,GAAG;oCAAC,GAAG,WAAW;oCAAE,WAAW,YAAY,UAAU;gCAAA;sCACpD,CAAC,4BACA,gCAAC;oCAAI,WAAW,CAAA,GAAA,sCAAW,EAAE;8CAAC;oCAAI;8CAChC,cAAA,gCAAC;wCACC,WAAW,CAAA,GAAA,+BAAI,EAAE;4CACf,GAAG,WAAW;kDACd;wDACA;wCACF;;;;;;;;AASpB","sources":["packages/@react-spectrum/s2/src/RangeSlider.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 ContextValue,\n SliderThumb,\n SliderTrack\n} from 'react-aria-components';\nimport {createContext, forwardRef, useContext, useRef} from 'react';\nimport {filledTrack, SliderBase, SliderBaseProps, thumb, thumbContainer, thumbHitArea, track, upperTrack} from './Slider';\nimport {FocusableRef, FocusableRefValue, RangeValue} from '@react-types/shared';\nimport {FormContext, useFormProps} from './Form';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {pressScale} from './pressScale';\nimport {useFocusableRef} from '@react-spectrum/utils';\nimport {useLocale, useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useSpectrumContextProps} from './useSpectrumContextProps';\n\nexport interface RangeSliderProps extends Omit<SliderBaseProps<RangeValue<number>>, 'children'> {\n /**\n * The name of the start input element, used when submitting an HTML form. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefname).\n */\n startName?: string,\n /**\n * The name of the end input element, used when submitting an HTML form. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#htmlattrdefname).\n */\n endName?: string\n}\n\nexport const RangeSliderContext = createContext<ContextValue<Partial<RangeSliderProps>, FocusableRefValue<HTMLDivElement>>>(null);\n\nexport const RangeSlider = /*#__PURE__*/ forwardRef(function RangeSlider(props: RangeSliderProps, ref: FocusableRef<HTMLDivElement>) {\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/s2');\n [props, ref] = useSpectrumContextProps(props, ref, RangeSliderContext);\n let formContext = useContext(FormContext);\n props = useFormProps(props);\n let {\n labelPosition = 'top',\n size = 'M',\n isEmphasized,\n trackStyle = 'thin',\n thumbStyle = 'default'\n } = props;\n let lowerThumbRef = useRef(null);\n let upperThumbRef = useRef(null);\n let inputRef = useRef(null); // TODO: need to pass inputRef to SliderThumb when we release the next version of RAC 1.3.0\n let domRef = useFocusableRef(ref, inputRef);\n\n let {direction} = useLocale();\n let cssDirection = direction === 'rtl' ? 'right' : 'left';\n\n return (\n <SliderBase\n {...props}\n value={props.value ? [props.value.start, props.value.end] : undefined}\n defaultValue={props.defaultValue ? [props.defaultValue.start, props.defaultValue.end] : [props.minValue ?? 0, props.maxValue ?? 100]}\n onChange={v => props.onChange?.({start: v[0], end: v[1]})}\n onChangeEnd={v => props.onChangeEnd?.({start: v[0], end: v[1]})}\n sliderRef={domRef}>\n <SliderTrack\n className={track({size, labelPosition, isInForm: !!formContext})}>\n {({state, isDisabled}) => (\n <>\n <div className={upperTrack({isDisabled, trackStyle})} />\n <div\n style={{\n width: `${Math.abs(state.getThumbPercent(0) - state.getThumbPercent(1)) * 100}%`,\n [cssDirection]: `${state.getThumbPercent(0) * 100}%`\n }}\n className={filledTrack({isDisabled, isEmphasized, trackStyle})} />\n <SliderThumb\n className={thumbContainer}\n index={0}\n name={props.startName}\n aria-label={stringFormatter.format('slider.minimum')}\n ref={lowerThumbRef}\n style={(renderProps) => pressScale(lowerThumbRef, {\n transform: 'translate(-50%, -50%)',\n zIndex: state.getThumbPercent(0) === 1 ? 1 : undefined\n })({...renderProps, isPressed: renderProps.isDragging})}>\n {(renderProps) => (\n <div className={thumbHitArea({size})}>\n <div\n className={thumb({\n ...renderProps,\n size,\n thumbStyle\n })} />\n </div>\n )}\n </SliderThumb>\n <SliderThumb\n className={thumbContainer}\n index={1}\n name={props.endName}\n aria-label={stringFormatter.format('slider.maximum')}\n ref={upperThumbRef}\n style={(renderProps) => pressScale(upperThumbRef, {\n transform: 'translate(-50%, -50%)'\n })({...renderProps, isPressed: renderProps.isDragging})}>\n {(renderProps) => (\n <div className={thumbHitArea({size})}>\n <div\n className={thumb({\n ...renderProps,\n size,\n thumbStyle\n })} />\n </div>\n )}\n </SliderThumb>\n </>\n )}\n </SliderTrack>\n </SliderBase>\n );\n});\n"],"names":[],"version":3,"file":"RangeSlider.cjs.map"}