@react-spectrum/s2
Version:
Spectrum 2 UI components in React
1 lines • 8.72 kB
Source Map (JSON)
{"mappings":"AC4F4C;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;;;EAAA;;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAiCtB;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAQ8B;;;;EAAA;;;;EAAA;;;;EAKzB;;;;EAAA;;;;EAAA;;;;EAcK;;;;EAAA;;;;EAAA;;;;EAAA;;;;EAAA;;;;;AA5DY;EAAA;;;;;AAiCtB;EAAA;IAAA","sources":["d7a279a73f170432","packages/@react-spectrum/s2/src/DateRangePicker.tsx"],"sourcesContent":["@import \"270ce443556f6832\";\n@import \"e665ec5e30b00bf9\";\n@import \"187f6499c2fa9b0d\";\n@import \"1dda7790205ac36a\";\n@import \"b7a8eac09818aeb5\";\n","/*\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.css.map"}