{"version":3,"file":"MiniCalendar.cjs","names":["createVarsResolver","getSize","factory","useProps","useStyles","useDatesContext","useUncontrolled","toDateString","UnstyledButton","Box","AccordionChevron","classes"],"sources":["../../../src/components/MiniCalendar/MiniCalendar.tsx"],"sourcesContent":["import dayjs from 'dayjs';\nimport {\n  AccordionChevron,\n  Box,\n  BoxProps,\n  createVarsResolver,\n  DataAttributes,\n  ElementProps,\n  factory,\n  Factory,\n  getSize,\n  MantineSize,\n  StylesApiProps,\n  UnstyledButton,\n  useProps,\n  useStyles,\n} from '@mantine/core';\nimport { useUncontrolled } from '@mantine/hooks';\nimport { DateLabelFormat } from '../../types';\nimport { toDateString } from '../../utils';\nimport { useDatesContext } from '../DatesProvider';\nimport classes from './MiniCalendar.module.css';\n\nexport type MiniCalendarStylesNames =\n  | 'root'\n  | 'control'\n  | 'days'\n  | 'day'\n  | 'dayMonth'\n  | 'dayNumber';\n\nexport type MiniCalendarCssVariables = {\n  root: '--mini-calendar-font-size';\n};\n\nexport interface MiniCalendarProps\n  extends BoxProps, StylesApiProps<MiniCalendarFactory>, ElementProps<'div', 'onChange'> {\n  /** Controlled component date value, start date of the interval */\n  date?: Date | string;\n\n  /** Uncontrolled component default value, start date of the interval */\n  defaultDate?: Date | string;\n\n  /** Called with date in `YYYY-MM-DD` format when date internal changes */\n  onDateChange?: (date: string) => void;\n\n  /** Selected date, controlled value */\n  value?: Date | string | null;\n\n  /** Called with date in `YYYY-MM-DD` format when date changes */\n  onChange?: (date: string) => void;\n\n  /** Maximum date that can be selected, date object or date string in `YYYY-MM-DD` format */\n  maxDate?: Date | string;\n\n  /** Minimum date that can be selected, date object or date string in `YYYY-MM-DD` format */\n  minDate?: Date | string;\n\n  /** Number of days to display in the calendar @default 7 */\n  numberOfDays?: number;\n\n  /** `dayjs` format for month label or a function that returns month label based on the date value @default \"MMM\" */\n  monthLabelFormat?: DateLabelFormat;\n\n  /** Called when the next button is clicked */\n  onNext?: () => void;\n\n  /** Called when the previous button is clicked */\n  onPrevious?: () => void;\n\n  /** Props passed down to the day component */\n  getDayProps?: (date: string) => Record<string, any>;\n\n  /** Component size @default 'sm' */\n  size?: MantineSize;\n\n  /** Props passed to previous control button */\n  previousControlProps?: React.ComponentProps<'button'> & DataAttributes;\n\n  /** Props passed to next control button */\n  nextControlProps?: React.ComponentProps<'button'> & DataAttributes;\n\n  /** dayjs locale used for formatting */\n  locale?: string;\n}\n\nexport type MiniCalendarFactory = Factory<{\n  props: MiniCalendarProps;\n  ref: HTMLDivElement;\n  stylesNames: MiniCalendarStylesNames;\n  vars: MiniCalendarCssVariables;\n}>;\n\nconst defaultProps = {\n  size: 'sm',\n  numberOfDays: 7,\n  monthLabelFormat: 'MMM',\n} satisfies Partial<MiniCalendarProps>;\n\nconst varsResolver = createVarsResolver<MiniCalendarFactory>((_theme, { size }) => ({\n  root: {\n    '--mini-calendar-font-size': getSize(size, 'mantine-font-size'),\n  },\n}));\n\nexport const MiniCalendar = factory<MiniCalendarFactory>((_props) => {\n  const props = useProps('MiniCalendar', defaultProps, _props);\n  const {\n    classNames,\n    className,\n    style,\n    styles,\n    unstyled,\n    vars,\n    attributes,\n    date,\n    defaultDate,\n    onDateChange,\n    value,\n    onChange,\n    onNext,\n    onPrevious,\n    getDayProps,\n    numberOfDays,\n    size,\n    minDate,\n    maxDate,\n    monthLabelFormat,\n    nextControlProps,\n    previousControlProps,\n    locale,\n    ...others\n  } = props;\n\n  const getStyles = useStyles<MiniCalendarFactory>({\n    name: 'MiniCalendar',\n    classes,\n    props,\n    className,\n    style,\n    classNames,\n    styles,\n    unstyled,\n    vars,\n    varsResolver,\n    attributes,\n  });\n\n  const ctx = useDatesContext();\n  const _locale = ctx.getLocale(locale);\n\n  const [_date, setDate] = useUncontrolled({\n    value: toDateString(date),\n    defaultValue: toDateString(defaultDate),\n    finalValue: toDateString(value) || dayjs().format('YYYY-MM-DD'),\n    onChange: onDateChange,\n  });\n\n  const handleNext = () => {\n    onNext?.();\n    const nextDate = dayjs(_date).add(numberOfDays, 'days');\n    setDate(toDateString(nextDate));\n  };\n\n  const handlePrevious = () => {\n    onPrevious?.();\n    const previousDate = dayjs(_date).subtract(numberOfDays, 'days');\n    setDate(toDateString(previousDate));\n  };\n\n  const previousDisabled = minDate\n    ? dayjs(_date).subtract(1, 'days').isBefore(dayjs(minDate))\n    : false;\n\n  const nextDisabled = maxDate\n    ? dayjs(_date).add(numberOfDays, 'days').isAfter(dayjs(maxDate))\n    : false;\n\n  const range = Array(numberOfDays)\n    .fill(0)\n    .map((_, index) => dayjs(_date).add(index, 'days'))\n    .map((date) => {\n      const disabled =\n        (minDate && date.isBefore(dayjs(minDate), 'day')) ||\n        (maxDate && date.isAfter(dayjs(maxDate), 'day')) ||\n        false;\n\n      const dayProps = getDayProps?.(toDateString(date));\n\n      return (\n        <UnstyledButton\n          key={date.toString()}\n          disabled={disabled}\n          aria-label={date.format('YYYY-MM-DD')}\n          data-disabled={disabled || undefined}\n          data-selected={value && dayjs(date).isSame(value, 'day') ? true : undefined}\n          {...dayProps}\n          onClick={(event) => {\n            dayProps?.onClick?.(event);\n            onChange?.(toDateString(date));\n          }}\n          {...getStyles('day', {\n            active: !disabled,\n            className: dayProps?.className,\n            style: dayProps?.style,\n          })}\n        >\n          <span {...getStyles('dayMonth')}>\n            {typeof monthLabelFormat === 'function'\n              ? monthLabelFormat(toDateString(date))\n              : date.locale(_locale).format(monthLabelFormat)}\n          </span>\n          <span {...getStyles('dayNumber')}>{date.date()}</span>\n        </UnstyledButton>\n      );\n    });\n\n  return (\n    <Box size={size} {...getStyles('root')} {...others}>\n      <UnstyledButton\n        size={size}\n        onClick={handlePrevious}\n        disabled={previousDisabled}\n        data-disabled={previousDisabled || undefined}\n        data-direction=\"previous\"\n        {...previousControlProps}\n        {...getStyles('control', {\n          active: !previousDisabled,\n          className: previousControlProps?.className,\n          style: previousControlProps?.style,\n        })}\n      >\n        {previousControlProps?.children || <AccordionChevron data-chevron size={size} />}\n      </UnstyledButton>\n\n      <div {...getStyles('days')}>{range}</div>\n\n      <UnstyledButton\n        size={size}\n        onClick={handleNext}\n        disabled={nextDisabled}\n        data-disabled={nextDisabled || undefined}\n        data-direction=\"next\"\n        {...nextControlProps}\n        {...getStyles('control', {\n          active: !nextDisabled,\n          className: nextControlProps?.className,\n          style: nextControlProps?.style,\n        })}\n      >\n        {nextControlProps?.children || <AccordionChevron data-chevron size={size} />}\n      </UnstyledButton>\n    </Box>\n  );\n});\n\nMiniCalendar.displayName = '@mantine/dates/MiniCalendar';\nMiniCalendar.classes = classes;\nMiniCalendar.varsResolver = varsResolver;\n\nexport namespace MiniCalendar {\n  export type Props = MiniCalendarProps;\n  export type StylesNames = MiniCalendarStylesNames;\n  export type Factory = MiniCalendarFactory;\n  export type CssVariables = MiniCalendarCssVariables;\n}\n"],"mappings":";;;;;;;;;;;AA6FA,MAAM,eAAe;CACnB,MAAM;CACN,cAAc;CACd,kBAAkB;AACpB;AAEA,MAAM,gBAAA,GAAeA,cAAAA,mBAAAA,EAAyC,QAAQ,EAAE,YAAY,EAClF,MAAM,EACJ,8BAAA,GAA6BC,cAAAA,QAAAA,CAAQ,MAAM,mBAAmB,EAChE,EACF,EAAE;AAEF,MAAa,gBAAA,GAAeC,cAAAA,QAAAA,EAA8B,WAAW;CACnE,MAAM,SAAA,GAAQC,cAAAA,SAAAA,CAAS,gBAAgB,cAAc,MAAM;CAC3D,MAAM,EACJ,YACA,WACA,OACA,QACA,UACA,MACA,YACA,MACA,aACA,cACA,OACA,UACA,QACA,YACA,aACA,cACA,MACA,SACA,SACA,kBACA,kBACA,sBACA,QACA,GAAG,WACD;CAEJ,MAAM,aAAA,GAAYC,cAAAA,UAAAA,CAA+B;EAC/C,MAAM;EACN,SAAA,4BAAA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAGD,MAAM,UADMC,0BAAAA,gBACM,CAAC,CAAC,UAAU,MAAM;CAEpC,MAAM,CAAC,OAAO,YAAA,GAAWC,eAAAA,gBAAA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