UNPKG

@yamada-ui/calendar

Version:

Yamada UI calendar component

1 lines 6.82 kB
{"version":3,"sources":["../src/calendar.tsx"],"sourcesContent":["import type {\n ComponentArgs,\n CSSUIObject,\n HTMLUIProps,\n ThemeProps,\n} from \"@yamada-ui/core\"\nimport type { ForwardedRef, ReactElement, RefAttributes } from \"react\"\nimport type { CalendarHeaderProps } from \"./calendar-header\"\nimport type { MonthProps } from \"./month\"\nimport type { MonthListProps } from \"./month-list\"\nimport type {\n CalendarContext,\n MaybeValue,\n UseCalendarProps,\n} from \"./use-calendar\"\nimport type { YearListProps } from \"./year-list\"\nimport { omitThemeProps, ui, useComponentMultiStyle } from \"@yamada-ui/core\"\nimport { cx } from \"@yamada-ui/utils\"\nimport { forwardRef } from \"react\"\nimport { Month } from \"./month\"\nimport { MonthList } from \"./month-list\"\nimport { CalendarProvider, useCalendar } from \"./use-calendar\"\nimport { YearList } from \"./year-list\"\n\ninterface CalendarOptions {\n /**\n * Props for calendar header element.\n */\n headerProps?: HTMLUIProps\n}\n\nexport interface CalendarBaseProps\n extends Omit<HTMLUIProps, \"defaultValue\" | \"onChange\" | \"value\">,\n ThemeProps<\"Calendar\">,\n CalendarOptions,\n Omit<CalendarHeaderProps, \"index\" | \"label\">,\n Pick<YearListProps, \"yearGridProps\" | \"yearProps\">,\n Pick<MonthListProps, \"monthGridProps\" | \"monthProps\">,\n Pick<MonthProps, \"dayProps\" | \"tableProps\" | \"weekdayProps\"> {}\n\nexport interface CalendarProps<Y extends MaybeValue = Date>\n extends CalendarBaseProps,\n UseCalendarProps<Y> {}\n\n/**\n * `Calendar` is a component for displaying or selecting dates in a calendar.\n *\n * @see Docs https://yamada-ui.com/components/data-display/calendar\n */\nexport const Calendar = forwardRef(\n <T extends MaybeValue = Date>(\n props: CalendarProps<T>,\n ref: ForwardedRef<HTMLDivElement>,\n ) => {\n const [styles, mergedProps] = useComponentMultiStyle(\"Calendar\", props)\n const {\n className,\n defaultValue,\n value,\n controlProps,\n dayProps,\n headerProps,\n labelProps,\n monthGridProps,\n monthProps,\n nextProps,\n prevProps,\n tableProps,\n weekdayProps,\n yearGridProps,\n yearProps,\n onChange,\n ...computedProps\n } = omitThemeProps(mergedProps)\n\n const { type, getContainerProps, ...rest } = useCalendar<T>({\n defaultValue,\n value,\n onChange,\n ...computedProps,\n })\n\n const css: CSSUIObject = {\n alignItems: \"flex-start\",\n display: \"flex\",\n flexWrap: \"wrap\",\n ...styles.container,\n }\n\n const w = computedProps.w ?? computedProps.width\n const minW = computedProps.minW ?? computedProps.minWidth\n const maxW = computedProps.maxW ?? computedProps.maxWidth\n const h = computedProps.h ?? computedProps.height\n const minH = computedProps.minH ?? computedProps.minHeight\n const maxH = computedProps.maxH ?? computedProps.maxHeight\n\n return (\n <CalendarProvider\n value={{ type, styles, ...rest } as unknown as CalendarContext}\n >\n <ui.div\n className={cx(\"ui-calendar\", className)}\n __css={css}\n {...getContainerProps({}, ref)}\n >\n {type === \"year\" ? (\n <YearList\n {...{\n h,\n maxH,\n maxW,\n minH,\n minW,\n w,\n controlProps,\n headerProps,\n labelProps,\n nextProps,\n prevProps,\n yearGridProps,\n yearProps,\n }}\n />\n ) : null}\n {type === \"month\" ? (\n <MonthList\n {...{\n h,\n maxH,\n maxW,\n minH,\n minW,\n w,\n controlProps,\n headerProps,\n labelProps,\n monthGridProps,\n monthProps,\n nextProps,\n prevProps,\n }}\n />\n ) : null}\n {type === \"date\" ? (\n <Month\n {...{\n h,\n maxH,\n maxW,\n minH,\n minW,\n w,\n controlProps,\n dayProps,\n headerProps,\n labelProps,\n nextProps,\n prevProps,\n tableProps,\n weekdayProps,\n }}\n />\n ) : null}\n </ui.div>\n </CalendarProvider>\n )\n },\n) as (<Y extends MaybeValue = Date>(\n props: CalendarProps<Y> & RefAttributes<HTMLDivElement>,\n) => ReactElement) &\n ComponentArgs\n\nCalendar.displayName = \"Calendar\"\nCalendar.__ui__ = \"Calendar\"\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,SAAS,gBA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