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AAM,OAAO,CAAC,SAAS;wCACtC,kBAAkB;wCAClB,aAAa;wCACb,UAAU;wCACV,UAAU;wCACV,WAAW,MAAM,SAAS;wCAC1B,cAAc,MAAM,YAAY;;kDAClC,gBAAC,CAAA,GAAA,yCAAQ;wCACP,QAAQ,CAAA,GAAA,yCAAQ;wCAChB,OAAO,gBAAgB,MAAM,CAAC;wCAC9B,OAAO,MAAM,SAAS,EAAE,OAAO;wCAC/B,UAAU,CAAA,IAAK,MAAM,OAAO,CAAC,OAAO;wCACpC,kBAAkB;wCAClB,aAAa;wCACb,UAAU;wCACV,UAAU;wCACV,WAAW,MAAM,SAAS;wCAC1B,cAAc,MAAM,YAAY;;;;;;kCAIxC,gBAAC,CAAA,GAAA,yCAAO;wBACN,MAAM;wBACN,YAAY;wBACZ,WAAW;wBACX,aAAa;kCACZ;;;;QAIT;;AAGN","sources":["packages/@react-spectrum/s2/src/DateRangePicker.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 DateRangePicker as AriaDateRangePicker,\n DateRangePickerProps as AriaDateRangePickerProps,\n ContextValue,\n DateValue,\n FormContext,\n PopoverProps\n} from 'react-aria-components';\nimport {CalendarButton, CalendarPopover, timeField} from './DatePicker';\nimport {createContext, forwardRef, ReactElement, Ref, useContext, useState} from 'react';\nimport {DateInput, DateInputContainer, InvalidIndicator} from './DateField';\nimport {field, fieldInput, getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};\nimport {FieldGroup, FieldLabel, HelpText} from './Field';\nimport {forwardRefType, GlobalDOMAttributes, HelpTextProps, SpectrumLabelableProps} from '@react-types/shared';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {RangeCalendar, RangeCalendarProps, TimeField} from '../';\nimport {style} from '../style' with {type: 'macro'};\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\nimport {useSpectrumContextProps} from './useSpectrumContextProps';\n\n\nexport interface DateRangePickerProps<T extends DateValue> extends\n Omit<AriaDateRangePickerProps<T>, 'children' | 'className' | 'style' | keyof GlobalDOMAttributes>,\n Pick<RangeCalendarProps<T>, 'createCalendar' | 'pageBehavior' | 'firstDayOfWeek' | 'isDateUnavailable'>,\n Pick<PopoverProps, 'shouldFlip'>,\n StyleProps,\n SpectrumLabelableProps,\n HelpTextProps {\n /**\n * The size of the DateField.\n *\n * @default 'M'\n */\n size?: 'S' | 'M' | 'L' | 'XL',\n /**\n * The maximum number of months to display at once in the calendar popover, if screen space permits.\n * @default 1\n */\n maxVisibleMonths?: number\n}\n\nexport const DateRangePickerContext = createContext<ContextValue<Partial<DateRangePickerProps<any>>, HTMLDivElement>>(null);\n\n/**\n * DateRangePickers combine two DateFields and a RangeCalendar popover to allow users\n * to enter or select a date and time range.\n */\nexport const DateRangePicker = /*#__PURE__*/ (forwardRef as forwardRefType)(function DateRangePicker<T extends DateValue>(\n props: DateRangePickerProps<T>, ref: Ref<HTMLDivElement>\n): ReactElement {\n [props, ref] = useSpectrumContextProps(props, ref, DateRangePickerContext);\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-spectrum/s2');\n let {\n label,\n contextualHelp,\n description: descriptionMessage,\n errorMessage,\n isRequired,\n size = 'M',\n labelPosition = 'top',\n necessityIndicator,\n labelAlign = 'start',\n UNSAFE_style,\n UNSAFE_className,\n styles,\n placeholderValue,\n maxVisibleMonths = 1,\n createCalendar,\n ...dateFieldProps\n } = props;\n let formContext = useContext(FormContext);\n let [buttonHasFocus, setButtonHasFocus] = useState(false);\n\n return (\n <AriaDateRangePicker\n ref={ref}\n isRequired={isRequired}\n {...dateFieldProps}\n style={UNSAFE_style}\n className={(UNSAFE_className || '') + style(field(), getAllowedOverrides())({\n isInForm: !!formContext,\n labelPosition,\n size\n }, styles)}>\n {({isDisabled, isInvalid, isOpen, state}) => {\n let placeholder: DateValue | undefined = placeholderValue || undefined;\n let timePlaceholder = placeholder && 'hour' in placeholder ? placeholder : undefined;\n let timeMinValue = props.minValue && 'hour' in props.minValue ? props.minValue : undefined;\n let timeMaxValue = props.maxValue && 'hour' in props.maxValue ? props.maxValue : undefined;\n let timeGranularity = state.granularity === 'hour'\n || state.granularity === 'minute'\n || state.granularity === 'second'\n ? state.granularity : undefined;\n let showTimeField = !!timeGranularity;\n return (\n <>\n <FieldLabel\n isDisabled={isDisabled}\n isRequired={isRequired}\n size={size}\n labelPosition={labelPosition}\n labelAlign={labelAlign}\n necessityIndicator={necessityIndicator}\n contextualHelp={contextualHelp}>\n {label}\n </FieldLabel>\n <FieldGroup\n role=\"presentation\"\n shouldTurnOffFocusRing={buttonHasFocus}\n isDisabled={isDisabled}\n isInvalid={isInvalid}\n size={size}\n styles={style({\n ...fieldInput(),\n textWrap: 'nowrap',\n paddingStart: 'edge-to-text',\n paddingEnd: 4\n })({size})}>\n <DateInputContainer>\n <DateInput slot=\"start\" />\n <span aria-hidden=\"true\" className={style({flexShrink: 0, flexGrow: 0, paddingX: 2})}>–</span>\n <DateInput slot=\"end\" />\n </DateInputContainer>\n <InvalidIndicator isInvalid={isInvalid} isDisabled={isDisabled} />\n <div\n className={style({\n flexShrink: 0,\n flexGrow: 1,\n display: 'flex',\n justifyContent: 'end'\n })}>\n <CalendarButton isOpen={isOpen} size={size} setButtonHasFocus={setButtonHasFocus} />\n </div>\n </FieldGroup>\n <CalendarPopover shouldFlip={props.shouldFlip}>\n <RangeCalendar\n visibleMonths={maxVisibleMonths}\n createCalendar={createCalendar} />\n {showTimeField && (\n <div className={style({display: 'flex', gap: 16, contain: 'inline-size', marginTop: 24})}>\n <TimeField\n styles={timeField}\n label={stringFormatter.format('datepicker.startTime')}\n value={state.timeRange?.start || null}\n onChange={v => state.setTime('start', v)}\n placeholderValue={timePlaceholder}\n granularity={timeGranularity}\n minValue={timeMinValue}\n maxValue={timeMaxValue}\n hourCycle={props.hourCycle}\n hideTimeZone={props.hideTimeZone} />\n <TimeField\n styles={timeField}\n label={stringFormatter.format('datepicker.endTime')}\n value={state.timeRange?.end || null}\n onChange={v => state.setTime('end', v)}\n placeholderValue={timePlaceholder}\n granularity={timeGranularity}\n minValue={timeMinValue}\n maxValue={timeMaxValue}\n hourCycle={props.hourCycle}\n hideTimeZone={props.hideTimeZone} />\n </div>\n )}\n </CalendarPopover>\n <HelpText\n size={size}\n isDisabled={isDisabled}\n isInvalid={isInvalid}\n description={descriptionMessage}>\n {errorMessage}\n </HelpText>\n </>\n );\n }}\n </AriaDateRangePicker>\n );\n});\n"],"names":[],"version":3,"file":"DateRangePicker.mjs.map"}