{"version":3,"file":"MonthsList.cjs","names":["useDatesContext","getMonthsData","getMonthInTabOrder","toDateString","PickerControl","isMonthDisabled","Box","classes"],"sources":["../../../src/components/MonthsList/MonthsList.tsx"],"sourcesContent":["import dayjs from 'dayjs';\nimport {\n  Box,\n  BoxProps,\n  DataAttributes,\n  ElementProps,\n  factory,\n  Factory,\n  MantineSize,\n  StylesApiProps,\n  useProps,\n  useStyles,\n} from '@mantine/core';\nimport { ControlsGroupSettings, DateStringValue } from '../../types';\nimport { toDateString } from '../../utils';\nimport { useDatesContext } from '../DatesProvider';\nimport { PickerControl, PickerControlProps } from '../PickerControl';\nimport { getMonthInTabOrder } from './get-month-in-tab-order/get-month-in-tab-order';\nimport { getMonthsData } from './get-months-data/get-months-data';\nimport { isMonthDisabled } from './is-month-disabled/is-month-disabled';\nimport classes from './MonthsList.module.css';\n\nexport type MonthsListStylesNames =\n  | 'monthsList'\n  | 'monthsListCell'\n  | 'monthsListRow'\n  | 'monthsListControl';\n\nexport interface MonthsListSettings extends ControlsGroupSettings {\n  /** `dayjs` format for months list */\n  monthsListFormat?: string;\n\n  /** Passes props down month picker control */\n  getMonthControlProps?: (date: DateStringValue) => Partial<PickerControlProps> & DataAttributes;\n\n  /** Determines whether controls should be separated @default true */\n  withCellSpacing?: boolean;\n\n  /** Determines whether the list should take the full width of its container @default false */\n  fullWidth?: boolean;\n}\n\nexport interface MonthsListProps\n  extends BoxProps, MonthsListSettings, StylesApiProps<MonthsListFactory>, ElementProps<'table'> {\n  __staticSelector?: string;\n\n  /** Prevents focus shift when buttons are clicked */\n  __preventFocus?: boolean;\n\n  /** Determines whether propagation for Escape key should be stopped */\n  __stopPropagation?: boolean;\n\n  /** Year for which months list should be displayed */\n  year: DateStringValue;\n\n  /** Component size */\n  size?: MantineSize;\n}\n\nexport type MonthsListFactory = Factory<{\n  props: MonthsListProps;\n  ref: HTMLTableElement;\n  stylesNames: MonthsListStylesNames;\n}>;\n\nconst defaultProps = {\n  monthsListFormat: 'MMM',\n  withCellSpacing: true,\n} satisfies Partial<MonthsListProps>;\n\nexport const MonthsList = factory<MonthsListFactory>((_props) => {\n  const props = useProps('MonthsList', defaultProps, _props);\n  const {\n    classNames,\n    className,\n    style,\n    styles,\n    unstyled,\n    vars,\n    __staticSelector,\n    year,\n    monthsListFormat,\n    locale,\n    minDate,\n    maxDate,\n    getMonthControlProps,\n    __getControlRef,\n    __onControlKeyDown,\n    __onControlClick,\n    __onControlMouseEnter,\n    __preventFocus,\n    __stopPropagation,\n    withCellSpacing,\n    fullWidth,\n    size,\n    attributes,\n    ...others\n  } = props;\n\n  const getStyles = useStyles<MonthsListFactory>({\n    name: __staticSelector || 'MonthsList',\n    classes,\n    props,\n    className,\n    style,\n    classNames,\n    styles,\n    unstyled,\n    attributes,\n    vars,\n    rootSelector: 'monthsList',\n  });\n\n  const ctx = useDatesContext();\n\n  const months = getMonthsData(year);\n\n  const monthInTabOrder = getMonthInTabOrder({\n    months,\n    minDate: toDateString(minDate)!,\n    maxDate: toDateString(maxDate)!,\n    getMonthControlProps,\n  });\n\n  const rows = months.map((monthsRow, rowIndex) => {\n    const cells = monthsRow.map((month, cellIndex) => {\n      const controlProps = getMonthControlProps?.(month);\n      const isMonthInTabOrder = dayjs(month).isSame(monthInTabOrder, 'month');\n\n      return (\n        <td\n          key={cellIndex}\n          {...getStyles('monthsListCell')}\n          data-with-spacing={withCellSpacing || undefined}\n        >\n          <PickerControl\n            {...getStyles('monthsListControl')}\n            size={size}\n            unstyled={unstyled}\n            fullWidth={fullWidth}\n            __staticSelector={__staticSelector || 'MonthsList'}\n            data-mantine-stop-propagation={__stopPropagation || undefined}\n            disabled={isMonthDisabled({\n              month,\n              minDate: toDateString(minDate)!,\n              maxDate: toDateString(maxDate)!,\n            })}\n            ref={(node) => {\n              if (node) {\n                __getControlRef?.(rowIndex, cellIndex, node);\n              }\n            }}\n            {...controlProps}\n            onKeyDown={(event) => {\n              controlProps?.onKeyDown?.(event);\n              __onControlKeyDown?.(event, { rowIndex, cellIndex, date: month });\n            }}\n            onClick={(event) => {\n              controlProps?.onClick?.(event);\n              __onControlClick?.(event, month);\n            }}\n            onMouseEnter={(event) => {\n              controlProps?.onMouseEnter?.(event);\n              __onControlMouseEnter?.(event, month);\n            }}\n            onMouseDown={(event) => {\n              controlProps?.onMouseDown?.(event);\n              __preventFocus && event.preventDefault();\n            }}\n            tabIndex={__preventFocus || !isMonthInTabOrder ? -1 : 0}\n          >\n            {controlProps?.children ??\n              dayjs(month).locale(ctx.getLocale(locale)).format(monthsListFormat)}\n          </PickerControl>\n        </td>\n      );\n    });\n\n    return (\n      <tr key={rowIndex} {...getStyles('monthsListRow')}>\n        {cells}\n      </tr>\n    );\n  });\n\n  return (\n    <Box\n      component=\"table\"\n      size={size}\n      {...getStyles('monthsList')}\n      data-full-width={fullWidth || undefined}\n      {...others}\n    >\n      <tbody>{rows}</tbody>\n    </Box>\n  );\n});\n\nMonthsList.classes = classes;\nMonthsList.displayName = '@mantine/dates/MonthsList';\n"],"mappings":";;;;;;;;;;;;;;AAiEA,MAAM,eAAe;CACnB,kBAAkB;CAClB,iBAAiB;AACnB;AAEA,MAAa,cAAA,GAAA,cAAA,QAAA,EAAyC,WAAW;CAC/D,MAAM,SAAA,GAAA,cAAA,SAAA,CAAiB,cAAc,cAAc,MAAM;CACzD,MAAM,EACJ,YACA,WACA,OACA,QACA,UACA,MACA,kBACA,MACA,kBACA,QACA,SACA,SACA,sBACA,iBACA,oBACA,kBACA,uBACA,gBACA,mBACA,iBACA,WACA,MACA,YACA,GAAG,WACD;CAEJ,MAAM,aAAA,GAAA,cAAA,UAAA,CAAyC;EAC7C,MAAM,oBAAoB;EAC1B,SAAA,0BAAA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,cAAc;CAChB,CAAC;CAED,MAAM,MAAMA,0BAAAA,gBAAgB;CAE5B,MAAM,SAASC,wBAAAA,cAAc,IAAI;CAEjC,MAAM,kBAAkBC,+BAAAA,mBAAmB;EACzC;EAC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