UNPKG

@yamada-ui/calendar

Version:

Yamada UI calendar component

1 lines 6.98 kB
{"version":3,"sources":["../src/month-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 } from \"react\"\nimport type { DatePickerFieldProps, DatePickerIconProps } from \"./date-picker\"\nimport type { UseMonthPickerProps } from \"./use-month-picker\"\nimport {\n forwardRef,\n omitThemeProps,\n ui,\n useComponentMultiStyle,\n} from \"@yamada-ui/core\"\nimport { Popover, PopoverContent } from \"@yamada-ui/popover\"\nimport { Portal } from \"@yamada-ui/portal\"\nimport { cx, runIfFunc } from \"@yamada-ui/utils\"\nimport { Calendar } from \"./calendar\"\nimport {\n DatePickerClearIcon,\n DatePickerField,\n DatePickerIcon,\n} from \"./date-picker\"\nimport { DatePickerProvider } from \"./use-date-picker\"\nimport { useMonthPicker } from \"./use-month-picker\"\n\ninterface MonthPickerOptions {\n children?: FC<{ value: Date | undefined; 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 month picker clear icon.\n *\n * @default true\n *\n * @deprecated Use `clearable` instead.\n */\n isClearable?: boolean\n /**\n * Props for month picker clear icon element.\n */\n clearIconProps?: DatePickerIconProps\n /**\n * Props for month picker container element.\n */\n containerProps?: Omit<HTMLUIProps, \"children\">\n /**\n * Props for month picker container element.\n */\n contentProps?: Omit<MotionProps, \"children\">\n /**\n * Props for month picker field element.\n */\n fieldProps?: Omit<DatePickerFieldProps, \"children\" | \"inputProps\">\n /**\n * Props for month picker icon element.\n */\n iconProps?: DatePickerIconProps\n /**\n * Props for month picker input element.\n */\n inputProps?: DatePickerFieldProps[\"inputProps\"]\n /**\n * Props to be forwarded to the portal component.\n *\n * @default '{ disabled: true }'\n *\n */\n portalProps?: Omit<PortalProps, \"children\">\n}\n\nexport interface MonthPickerProps\n extends ThemeProps<\"DatePicker\">,\n MonthPickerOptions,\n UseMonthPickerProps {}\n\n/**\n * `MonthPicker` is a component used for users to select a month.\n *\n * @see Docs https://yamada-ui.com/components/forms/month-picker\n */\nexport const MonthPicker = forwardRef<MonthPickerProps, \"div\">((props, ref) => {\n const [styles, mergedProps] = useComponentMultiStyle(\"MonthPicker\", props)\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 clearIconProps,\n containerProps,\n contentProps,\n fieldProps,\n iconProps,\n inputProps,\n portalProps = { disabled: true },\n ...computedProps\n } = omitThemeProps(mergedProps)\n const {\n value,\n getCalendarProps,\n getContainerProps,\n getFieldProps,\n getIconProps,\n getInputProps,\n getPopoverProps,\n onClose,\n } = useMonthPicker(computedProps)\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-month-picker\", className)}\n __css={css}\n {...getContainerProps(containerProps)}\n >\n <ui.div\n className=\"ui-month-picker__inner\"\n __css={{ position: \"relative\", ...styles.inner }}\n >\n <DatePickerField\n className=\"ui-month-picker__field\"\n {...getFieldProps({ height, minHeight, ...fieldProps }, ref)}\n inputProps={getInputProps(inputProps)}\n />\n\n {clearable && value ? (\n <DatePickerClearIcon\n className=\"ui-month-picker__icon--clear\"\n {...getIconProps({ clear: true, ...clearIconProps })}\n />\n ) : (\n <DatePickerIcon\n className=\"ui-month-picker__icon\"\n {...getIconProps({ clear: false, ...iconProps })}\n />\n )}\n </ui.div>\n\n <Portal {...portalProps}>\n <PopoverContent\n as=\"div\"\n className=\"ui-month-picker__content\"\n __css={{ ...styles.content }}\n {...contentProps}\n >\n <Calendar\n className=\"ui-month-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\nMonthPicker.displayName = \"MonthPicker\"\nMonthPicker.__ui__ = \"MOnthPicker\"\n"],"mappings":";;;;;;;;;;;;;;;;;AAMA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,SAAS,sBAAsB;AACxC,SAAS,cAAc;AACvB,SAAS,IAAI,iBAAiB;AA2HpB,SAIE,KAJF;AA9CH,IAAM,cAAc,WAAoC,CAAC,OAAO,QAAQ;AAC7E,QAAM,CAAC,QAAQ,WAAW,IAAI,uBAAuB,eAAe,KAAK;AACzE,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,cAAc;AAAA,IACd,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA,SAAS;AAAA,IACT;AAAA,IACA,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,cAAc,EAAE,UAAU,KAAK;AAAA,IAC/B,GAAG;AAAA,EACL,IAAI,eAAe,WAAW;AAC9B,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,eAAe,aAAa;AAChC,QAAM,MAAmB;AAAA,IACvB;AAAA,IACA,GAAG;AAAA,IACH,GAAG;AAAA,IACH,GAAG,OAAO;AAAA,EACZ;AAEA,SACE,oBAAC,sBAAmB,OAAO,QACzB,8BAAC,WAAS,GAAG,gBAAgB,GAC3B;AAAA,IAAC,GAAG;AAAA,IAAH;AAAA,MACC,WAAW,GAAG,mBAAmB,SAAS;AAAA,MAC1C,OAAO;AAAA,MACN,GAAG,kBAAkB,cAAc;AAAA,MAEpC;AAAA;AAAA,UAAC,GAAG;AAAA,UAAH;AAAA,YACC,W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