@yamada-ui/calendar
Version:
Yamada UI calendar component
1 lines • 12.9 kB
Source Map (JSON)
{"version":3,"sources":["../src/range-date-picker.tsx"],"sourcesContent":["import type { CSSUIObject, FC, HTMLUIProps, ThemeProps } from \"@yamada-ui/core\"\nimport type { MotionProps } from \"@yamada-ui/motion\"\nimport type { PortalProps } from \"@yamada-ui/portal\"\nimport type { ReactNode, RefAttributes } from \"react\"\nimport type { DatePickerIconProps } from \"./date-picker\"\nimport type { UseRangeDatePickerProps } from \"./use-range-date-picker\"\nimport {\n forwardRef,\n layoutStyleProperties,\n omitThemeProps,\n ui,\n useComponentMultiStyle,\n} from \"@yamada-ui/core\"\nimport { Popover, PopoverContent, PopoverTrigger } from \"@yamada-ui/popover\"\nimport { Portal } from \"@yamada-ui/portal\"\nimport {\n cx,\n dataAttr,\n mergeRefs,\n runIfFunc,\n splitObject,\n} from \"@yamada-ui/utils\"\nimport { Calendar } from \"./calendar\"\nimport { DatePickerClearIcon, DatePickerIcon } from \"./date-picker\"\nimport { DatePickerProvider, useDatePickerContext } from \"./use-date-picker\"\nimport { useRangeDatePicker } from \"./use-range-date-picker\"\n\ninterface RangeDatePickerOptions {\n children?: FC<{ value: [Date?, Date?]; onClose: () => void }> | ReactNode\n /**\n * If `true`, display the month picker clear icon.\n *\n * @default true\n */\n clearable?: boolean\n /**\n * The border color when the input is invalid.\n */\n errorBorderColor?: string\n /**\n * The border color when the input is focused.\n */\n focusBorderColor?: string\n /**\n * If `true`, display the date picker clear icon.\n *\n * @default true\n *\n * @deprecated Use `clearable` instead.\n */\n isClearable?: boolean\n /**\n * The visual separator between each value.\n *\n * @default '-'\n */\n separator?: string\n /**\n * Props for date picker clear icon element.\n */\n clearIconProps?: DatePickerIconProps\n /**\n * Props for date picker container element.\n */\n containerProps?: Omit<HTMLUIProps, \"children\">\n /**\n * Props for date picker container element.\n */\n contentProps?: Omit<MotionProps, \"children\">\n /**\n * Props for date picker end input element.\n */\n endInputProps?: HTMLUIProps<\"input\">\n /**\n * Props for date picker field element.\n */\n fieldProps?: Omit<HTMLUIProps, \"children\">\n /**\n * Props for date picker icon element.\n */\n iconProps?: DatePickerIconProps\n /**\n * Props to be forwarded to the portal component.\n *\n * @default '{ disabled: true }'\n *\n */\n portalProps?: Omit<PortalProps, \"children\">\n /**\n * Props for date picker start input element.\n */\n startInputProps?: HTMLUIProps<\"input\">\n}\n\nexport interface RangeDatePickerProps\n extends ThemeProps<\"DatePicker\">,\n RangeDatePickerOptions,\n UseRangeDatePickerProps {}\n\n/**\n * `RangeDatePicker` is a component used for users to select a range of dates.\n *\n * @see Docs https://yamada-ui.com/components/forms/range-date-picker\n */\nexport const RangeDatePicker = forwardRef<RangeDatePickerProps, \"input\">(\n (props, ref) => {\n const [styles, mergedProps] = useComponentMultiStyle(\n \"RangeDatePicker\",\n props,\n )\n const {\n className,\n children,\n isClearable = true,\n clearable = isClearable,\n color,\n h,\n height = h,\n minH,\n minHeight = minH,\n separator,\n clearIconProps,\n containerProps,\n contentProps,\n endInputProps,\n fieldProps,\n iconProps,\n portalProps = { disabled: true },\n startInputProps,\n ...computedProps\n } = omitThemeProps(mergedProps)\n const {\n value,\n getCalendarProps,\n getContainerProps,\n getEndInputProps,\n getFieldProps,\n getIconProps,\n getPopoverProps,\n getStartInputProps,\n onClose,\n } = useRangeDatePicker(computedProps)\n const [startValue, endValue] = value\n const css: CSSUIObject = {\n color,\n h: \"fit-content\",\n w: \"100%\",\n ...styles.container,\n }\n\n return (\n <DatePickerProvider value={styles}>\n <Popover {...getPopoverProps()}>\n <ui.div\n className={cx(\"ui-range-date-picker\", className)}\n __css={css}\n {...getContainerProps(containerProps)}\n >\n <ui.div\n className=\"ui-range-date-picker__inner\"\n __css={{ position: \"relative\", ...styles.inner }}\n >\n <RangeDatePickerField\n separator={separator}\n value={value}\n {...getFieldProps({ height, minHeight, ...fieldProps })}\n endInputProps={getEndInputProps(endInputProps)}\n startInputProps={getStartInputProps(startInputProps, ref)}\n />\n\n {clearable && (!!startValue || !!endValue) ? (\n <DatePickerClearIcon\n {...getIconProps({ clear: true, ...clearIconProps })}\n />\n ) : (\n <DatePickerIcon\n {...getIconProps({ clear: false, ...iconProps })}\n />\n )}\n </ui.div>\n\n <Portal {...portalProps}>\n <PopoverContent\n as=\"div\"\n className=\"ui-range-date-picker__content\"\n __css={{ ...styles.content }}\n {...contentProps}\n >\n <Calendar\n className=\"ui-range-date-picker__calendar\"\n {...getCalendarProps()}\n />\n\n {runIfFunc(children, { value, onClose })}\n </PopoverContent>\n </Portal>\n </ui.div>\n </Popover>\n </DatePickerProvider>\n )\n },\n)\n\nRangeDatePicker.displayName = \"RangeDatePicker\"\nRangeDatePicker.__ui__ = \"RangeDatePicker\"\n\ninterface RangeDatePickerFieldOptions {\n value: [Date?, Date?] | undefined\n}\n\nexport interface RangeDatePickerFieldProps\n extends HTMLUIProps,\n Pick<\n RangeDatePickerProps,\n \"endInputProps\" | \"separator\" | \"startInputProps\"\n >,\n RangeDatePickerFieldOptions {}\n\nexport const RangeDatePickerField = forwardRef<\n RangeDatePickerFieldProps,\n \"input\"\n>(\n (\n {\n className,\n separator = \"-\",\n value = [],\n endInputProps,\n startInputProps,\n ...rest\n },\n ref,\n ) => {\n const styles = useDatePickerContext()\n\n const [startValue, endValue] = value\n const {\n ref: startInputRef,\n placeholder: startPlaceholder,\n ...computedStartInputProps\n } = (startInputProps ?? {}) as HTMLUIProps<\"input\"> &\n RefAttributes<HTMLInputElement>\n const { placeholder: endPlaceholder, ...computedEndInputProps } =\n endInputProps ?? {}\n const hasPlaceholder = !!startPlaceholder || !!endPlaceholder\n const hasValue = !!startValue || !!endValue\n const hasSeparator = hasPlaceholder || hasValue\n\n const css: CSSUIObject = {\n alignItems: \"center\",\n display: \"flex\",\n pe: \"2rem\",\n ...styles.field,\n }\n\n return (\n <PopoverTrigger>\n <ui.div\n className={cx(\"ui-range-date-picker__field\", className)}\n __css={css}\n {...rest}\n >\n <AutosizingInput\n ref={mergeRefs(ref, startInputRef)}\n className=\"ui-range-date-picker__field__start-input\"\n aria-label=\"Start date\"\n placeholder={startPlaceholder}\n {...computedStartInputProps}\n />\n\n {hasSeparator && !!separator ? (\n <ui.span\n data-placeholder={dataAttr(!startValue)}\n marginInline=\"0.25rem\"\n >\n {separator}\n </ui.span>\n ) : null}\n\n <AutosizingInput\n className=\"ui-range-date-picker__field__end-input\"\n aria-label=\"End date\"\n placeholder={endPlaceholder}\n {...computedEndInputProps}\n />\n </ui.div>\n </PopoverTrigger>\n )\n },\n)\n\nRangeDatePickerField.displayName = \"RangeDatePickerField\"\nRangeDatePickerField.__ui__ = \"RangeDatePickerField\"\n\ninterface AutosizingInputProps extends HTMLUIProps<\"input\"> {}\n\nconst AutosizingInput = forwardRef<AutosizingInputProps, \"input\">(\n ({ className, placeholder, value, ...rest }, ref) => {\n const [containerProps, inputProps] = splitObject(\n rest,\n layoutStyleProperties,\n )\n\n const css: CSSUIObject = {\n alignItems: \"center\",\n display: \"inline-flex\",\n position: \"relative\",\n }\n\n return (\n <ui.div className={className} __css={css} {...containerProps}>\n <ui.span data-placeholder={dataAttr(!value)} opacity={value ? 0 : 1}>\n {value || placeholder}\n </ui.span>\n\n <ui.input\n ref={ref}\n left=\"0\"\n position=\"absolute\"\n value={value}\n w=\"100%\"\n {...inputProps}\n />\n </ui.div>\n )\n },\n)\n\nAutosizingInput.displayName = \"AutosizingInput\"\nAutosizingInput.__ui__ = \"AutosizingInput\"\n"],"mappings":";;;;;;;;;;;;;;;;;AAMA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,SAAS,gBAAgB,sBAAsB;AACxD,SAAS,cAAc;AACvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAyIK,SAIE,KAJF;AAtDL,IAAM,kBAAkB;AAAA,EAC7B,CAAC,OAAO,QAAQ;AACd,UAAM,CAAC,QAAQ,WAAW,IAAI;AAAA,MAC5B;AAA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