UNPKG

@react-spectrum/s2

Version:
247 lines (233 loc) 14.2 kB
import "./DateRangePicker.css"; import {CalendarButton as $1196aa313ab37be1$export$adb29da0ac001538, CalendarPopover as $1196aa313ab37be1$export$f3ce207574a3cffe, timeField as $1196aa313ab37be1$export$5320dd0e349ed44d} from "./DatePicker.mjs"; import {DateInput as $0e78e2b1ea2e947e$export$7edc06cf1783b30f, DateInputContainer as $0e78e2b1ea2e947e$export$3f08d3c48fa697, InvalidIndicator as $0e78e2b1ea2e947e$export$19696856283ab185} from "./DateField.mjs"; import {FieldGroup as $9afd80978c252040$export$f0fe469072bc6950, FieldLabel as $9afd80978c252040$export$1acdcf5a973a8414, HelpText as $9afd80978c252040$export$a67c0bc59081311a} from "./Field.mjs"; import $dMar9$intlStringsmjs from "./intlStrings.mjs"; import {RangeCalendar as $ecdee84c2f0ddfb5$export$a4f5c8b89d277a8d} from "./RangeCalendar.mjs"; import {TimeField as $a4c1b812c7e17006$export$5eaee2322dd727eb} from "./TimeField.mjs"; import {useSpectrumContextProps as $5ce63c423902f47d$export$764f6146fadd77f7} from "../icons/useSpectrumContextProps.mjs"; import {jsx as $dMar9$jsx, jsxs as $dMar9$jsxs, Fragment as $dMar9$Fragment} from "react/jsx-runtime"; import {FormContext as $dMar9$FormContext, DateRangePicker as $dMar9$DateRangePicker} from "react-aria-components"; import {createContext as $dMar9$createContext, forwardRef as $dMar9$forwardRef, useContext as $dMar9$useContext, useState as $dMar9$useState} from "react"; import {useLocalizedStringFormatter as $dMar9$useLocalizedStringFormatter} from "@react-aria/i18n"; function $parcel$interopDefault(a) { return a && a.__esModule ? a.default : a; } /* * Copyright 2024 Adobe. All rights reserved. * This file is licensed to you under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. You may obtain a copy * of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS * OF ANY KIND, either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ const $c9bb0cbce1dac403$export$8282edba42ee28a = /*#__PURE__*/ (0, $dMar9$createContext)(null); const $c9bb0cbce1dac403$export$17334619f3ac2224 = /*#__PURE__*/ (0, $dMar9$forwardRef)(function DateRangePicker(props, ref) { [props, ref] = (0, $5ce63c423902f47d$export$764f6146fadd77f7)(props, ref, $c9bb0cbce1dac403$export$8282edba42ee28a); let stringFormatter = (0, $dMar9$useLocalizedStringFormatter)((0, ($parcel$interopDefault($dMar9$intlStringsmjs))), '@react-spectrum/s2'); let { label: label, contextualHelp: contextualHelp, description: descriptionMessage, errorMessage: errorMessage, isRequired: isRequired, size: size = 'M', labelPosition: labelPosition = 'top', necessityIndicator: necessityIndicator, labelAlign: labelAlign = 'start', UNSAFE_style: UNSAFE_style, UNSAFE_className: UNSAFE_className, styles: styles, placeholderValue: placeholderValue, maxVisibleMonths: maxVisibleMonths = 1, createCalendar: createCalendar, ...dateFieldProps } = props; let formContext = (0, $dMar9$useContext)((0, $dMar9$FormContext)); let [buttonHasFocus, setButtonHasFocus] = (0, $dMar9$useState)(false); return /*#__PURE__*/ (0, $dMar9$jsx)((0, $dMar9$DateRangePicker), { ref: ref, isRequired: isRequired, ...dateFieldProps, style: UNSAFE_style, className: (UNSAFE_className || '') + function anonymous(props, overrides) { let rules = " "; let gridColumnStart = false; let gridColumnEnd = false; let matches = (overrides || '').matchAll(/(?:^|\s)(J|G|I|H|_u|_v|_s|__A|_d|_J|z|y|B|A|_P|_9|W|_l|_A|_z|_6|Z|N|L)[^\s]+/g); for (let p of matches){ if (p[1] === "z") gridColumnStart = true; if (p[1] === "y") gridColumnEnd = true; rules += p[0]; } rules += ' se1'; if (props.isInForm) { if (!gridColumnStart) rules += ' z2mU1'; } if (props.isInForm) { if (props.labelPosition === "side") { if (!gridColumnEnd) rules += ' yvoofG1'; } } if (props.isInForm) rules += ' DLwlgod1'; else { if (props.labelPosition === "side") rules += ' DPlN5qb1'; else if (props.labelPosition === "top") rules += ' DM8Mfn1'; } if (props.labelPosition === "side") rules += ' EPlN5qb1'; else if (props.labelPosition === "top") rules += ' E4w1sLc1'; if (props.labelPosition === "side") rules += ' CbRM95c1'; else if (props.labelPosition === "top") rules += ' Cxaocre1'; if (props.size === "XL") { rules += ' -_6BNtrc-e1'; rules += ' vx1'; } else if (props.size === "L") { rules += ' -_6BNtrc-d1'; rules += ' vx1'; } else if (props.size === "S") { rules += ' -_6BNtrc-b1'; rules += ' vx1'; } else if (props.size === "XS") { rules += ' -_6BNtrc-a1'; rules += ' vx1'; } else { rules += ' -_6BNtrc-c1'; rules += ' vx1'; } rules += ' ea1'; rules += ' _Fd1'; rules += ' _FnuYUweb1'; if (props.size === "XL") rules += ' -BhX7R-Fz1'; else if (props.size === "L") rules += ' -BhX7R-Fv1'; else if (props.size === "S") rules += ' -BhX7R-Fp1'; else if (props.size === "XS") rules += ' -BhX7R-Fn1'; else rules += ' -BhX7R-Fx1'; rules += ' -AJjOLd-UVkF0Db1'; rules += ' qg1'; rules += ' __ca1'; return rules; }({ isInForm: !!formContext, labelPosition: labelPosition, size: size }, styles), children: ({ isDisabled: isDisabled, isInvalid: isInvalid, isOpen: isOpen, state: state })=>{ let placeholder = placeholderValue || undefined; let timePlaceholder = placeholder && 'hour' in placeholder ? placeholder : undefined; let timeMinValue = props.minValue && 'hour' in props.minValue ? props.minValue : undefined; let timeMaxValue = props.maxValue && 'hour' in props.maxValue ? props.maxValue : undefined; let timeGranularity = state.granularity === 'hour' || state.granularity === 'minute' || state.granularity === 'second' ? state.granularity : undefined; let showTimeField = !!timeGranularity; return /*#__PURE__*/ (0, $dMar9$jsxs)((0, $dMar9$Fragment), { children: [ /*#__PURE__*/ (0, $dMar9$jsx)((0, $9afd80978c252040$export$1acdcf5a973a8414), { isDisabled: isDisabled, isRequired: isRequired, size: size, labelPosition: labelPosition, labelAlign: labelAlign, necessityIndicator: necessityIndicator, contextualHelp: contextualHelp, children: label }), /*#__PURE__*/ (0, $dMar9$jsxs)((0, $9afd80978c252040$export$f0fe469072bc6950), { role: "presentation", shouldTurnOffFocusRing: buttonHasFocus, isDisabled: isDisabled, isInvalid: isInvalid, size: size, styles: function anonymous(props) { let rules = " "; rules += ' zXcEWr1'; rules += ' yXcEWr1'; rules += ' BXcEWr1'; rules += ' AXcEWr1'; if (props.size === "XL") rules += ' Nl1'; else if (props.size === "L") rules += ' Nj1'; else if (props.size === "S") rules += ' Nf1'; else if (props.size === "XS") rules += ' Ne1'; else rules += ' Nk1'; if (props.isQuiet) rules += ' _qd1'; else rules += ' _qtb1'; if (props.size === "XL") rules += ' -Anxdcc-Zt1'; else if (props.size === "L") rules += ' -Anxdcc-ZStdtne1'; else if (props.size === "S") rules += ' -Anxdcc-Zr1'; else rules += ' -Anxdcc-Z3fn9H1'; rules += ' __v6TNLWb1'; rules += ' __Wb1'; rules += ' SMBFGYc1'; rules += ' RfBFGYc1'; rules += ' -S_-Sv1'; rules += ' -R_-Rp1'; return rules; }({ size: size }), children: [ /*#__PURE__*/ (0, $dMar9$jsxs)((0, $0e78e2b1ea2e947e$export$3f08d3c48fa697), { children: [ /*#__PURE__*/ (0, $dMar9$jsx)((0, $0e78e2b1ea2e947e$export$7edc06cf1783b30f), { slot: "start" }), /*#__PURE__*/ (0, $dMar9$jsx)("span", { "aria-hidden": "true", className: " _va1 _ua1 Sj1 Rj1", children: "\u2013" }), /*#__PURE__*/ (0, $dMar9$jsx)((0, $0e78e2b1ea2e947e$export$7edc06cf1783b30f), { slot: "end" }) ] }), /*#__PURE__*/ (0, $dMar9$jsx)((0, $0e78e2b1ea2e947e$export$19696856283ab185), { isInvalid: isInvalid, isDisabled: isDisabled }), /*#__PURE__*/ (0, $dMar9$jsx)("div", { className: " _va1 _ub1 sd1 _Cb1", children: /*#__PURE__*/ (0, $dMar9$jsx)((0, $1196aa313ab37be1$export$adb29da0ac001538), { isOpen: isOpen, size: size, setButtonHasFocus: setButtonHasFocus }) }) ] }), /*#__PURE__*/ (0, $dMar9$jsxs)((0, $1196aa313ab37be1$export$f3ce207574a3cffe), { shouldFlip: props.shouldFlip, children: [ /*#__PURE__*/ (0, $dMar9$jsx)((0, $ecdee84c2f0ddfb5$export$a4f5c8b89d277a8d), { visibleMonths: maxVisibleMonths, createCalendar: createCalendar }), showTimeField && /*#__PURE__*/ (0, $dMar9$jsxs)("div", { className: " sd1 Ul1 ql1 _qb1 JA1", children: [ /*#__PURE__*/ (0, $dMar9$jsx)((0, $a4c1b812c7e17006$export$5eaee2322dd727eb), { styles: (0, $1196aa313ab37be1$export$5320dd0e349ed44d), label: stringFormatter.format('datepicker.startTime'), value: state.timeRange?.start || null, onChange: (v)=>state.setTime('start', v), placeholderValue: timePlaceholder, granularity: timeGranularity, minValue: timeMinValue, maxValue: timeMaxValue, hourCycle: props.hourCycle, hideTimeZone: props.hideTimeZone }), /*#__PURE__*/ (0, $dMar9$jsx)((0, $a4c1b812c7e17006$export$5eaee2322dd727eb), { styles: (0, $1196aa313ab37be1$export$5320dd0e349ed44d), label: stringFormatter.format('datepicker.endTime'), value: state.timeRange?.end || null, onChange: (v)=>state.setTime('end', v), placeholderValue: timePlaceholder, granularity: timeGranularity, minValue: timeMinValue, maxValue: timeMaxValue, hourCycle: props.hourCycle, hideTimeZone: props.hideTimeZone }) ] }) ] }), /*#__PURE__*/ (0, $dMar9$jsx)((0, $9afd80978c252040$export$a67c0bc59081311a), { size: size, isDisabled: isDisabled, isInvalid: isInvalid, description: descriptionMessage, children: errorMessage }) ] }); } }); }); export {$c9bb0cbce1dac403$export$8282edba42ee28a as DateRangePickerContext, $c9bb0cbce1dac403$export$17334619f3ac2224 as DateRangePicker}; //# sourceMappingURL=DateRangePicker.mjs.map