{"version":3,"file":"MoreEvents.mjs","names":["classes"],"sources":["../../../src/components/MoreEvents/MoreEvents.tsx"],"sourcesContent":["import {\n  BoxProps,\n  ElementProps,\n  factory,\n  Factory,\n  MantineRadius,\n  Modal,\n  ModalProps,\n  Popover,\n  PopoverProps,\n  StylesApiProps,\n  UnstyledButton,\n  useProps,\n  useStyles,\n} from '@mantine/core';\nimport { useDisclosure } from '@mantine/hooks';\nimport { getLabel, ScheduleLabelsOverride } from '../../labels';\nimport { ScheduleEventData, ScheduleMode } from '../../types';\nimport { RenderEvent, RenderEventBody, ScheduleEvent } from '../ScheduleEvent/ScheduleEvent';\nimport classes from './MoreEvents.module.css';\n\nexport type MoreEventsDropdownType = 'popover' | 'modal';\n\nexport type MoreEventsStylesNames = 'moreEventsButton' | 'moreEventsList' | 'moreEventsDropdown';\n\nexport interface MoreEventsProps\n  extends BoxProps, StylesApiProps<MoreEventsFactory>, ElementProps<'button'> {\n  /** List of events to display */\n  events: ScheduleEventData[];\n\n  /** Events count to use for `+X more` label */\n  moreEventsCount: number;\n\n  /** Key of `theme.radius` or any valid CSS value to set border-radius @default theme.defaultRadius */\n  radius?: MantineRadius;\n\n  /** Title for the Modal component, ignored if `dropdownType` is not 'modal' */\n  modalTitle?: string;\n\n  /** Type of dropdown to use for displaying more events @default 'popover' */\n  dropdownType?: MoreEventsDropdownType;\n\n  /** Props passed down to `Popover` component */\n  popoverProps?: Partial<Omit<PopoverProps, 'children'>>;\n\n  /** Props passed down to `Modal` component */\n  modalProps?: Partial<Omit<ModalProps, 'children'>>;\n\n  /** Called when the dropdown is closed */\n  onDropdownClose?: () => void;\n\n  /** Function to customize event body, `event` object is passed as first argument */\n  renderEventBody?: RenderEventBody;\n\n  /** Function to fully customize event rendering, receives all props that would be passed to the root element including children */\n  renderEvent?: RenderEvent;\n\n  /** Labels override */\n  labels?: ScheduleLabelsOverride;\n\n  /** Interaction mode: 'default' allows all interactions, 'static' disables event interactions @default default */\n  mode?: ScheduleMode;\n\n  /** Called when an event inside the dropdown is clicked */\n  onEventClick?: (event: ScheduleEventData, e: React.MouseEvent<HTMLButtonElement>) => void;\n}\n\nexport type MoreEventsFactory = Factory<{\n  props: MoreEventsProps;\n  ref: HTMLButtonElement;\n  stylesNames: MoreEventsStylesNames;\n}>;\n\nconst defaultProps = {\n  dropdownType: 'popover',\n} satisfies Partial<MoreEventsProps>;\n\nexport const MoreEvents = factory<MoreEventsFactory>((_props) => {\n  const props = useProps('MoreEvents', defaultProps, _props);\n  const {\n    classNames,\n    className,\n    style,\n    styles,\n    unstyled,\n    vars,\n    attributes,\n    radius,\n    dropdownType,\n    events,\n    moreEventsCount,\n    popoverProps,\n    modalProps,\n    onDropdownClose,\n    children,\n    modalTitle,\n    renderEventBody,\n    renderEvent,\n    id,\n    labels,\n    mode,\n    onEventClick,\n    ...others\n  } = props;\n  const [dropdownOpened, dropdownHandlers] = useDisclosure();\n\n  const getStyles = useStyles<MoreEventsFactory>({\n    name: 'MoreEvents',\n    classes,\n    props,\n    className,\n    style,\n    classNames,\n    styles,\n    unstyled,\n    attributes,\n    vars,\n    rootSelector: 'moreEventsButton',\n  });\n\n  const handleClose = () => {\n    dropdownHandlers.close();\n    onDropdownClose?.();\n  };\n\n  const eventsList = (\n    <div {...getStyles('moreEventsList')}>\n      {events.map((event) => (\n        <ScheduleEvent\n          key={event.id}\n          radius={radius}\n          event={event}\n          size=\"md\"\n          renderEventBody={renderEventBody}\n          renderEvent={renderEvent}\n          mode={mode}\n          onClick={onEventClick ? (e) => onEventClick(event, e) : undefined}\n        >\n          {event.title}\n        </ScheduleEvent>\n      ))}\n    </div>\n  );\n\n  return (\n    <>\n      {dropdownType === 'modal' && (\n        <Modal\n          opened={dropdownOpened}\n          onClose={handleClose}\n          unstyled={unstyled}\n          radius={radius}\n          title={modalTitle}\n          {...modalProps}\n        >\n          {eventsList}\n        </Modal>\n      )}\n\n      <Popover\n        position=\"bottom-start\"\n        width={260}\n        opened={dropdownOpened}\n        trapFocus\n        returnFocus={false}\n        unstyled={unstyled}\n        disabled={popoverProps?.disabled || dropdownType === 'modal'}\n        radius={radius}\n        transitionProps={{ transition: 'pop', duration: 120 }}\n        offset={-46}\n        id={id}\n        {...popoverProps}\n        onChange={(_opened) => {\n          if (!_opened) {\n            popoverProps?.onChange?.(_opened);\n            handleClose();\n          }\n        }}\n      >\n        <Popover.Target>\n          <UnstyledButton\n            {...getStyles('moreEventsButton')}\n            mod={{ static: mode === 'static' }}\n            onClick={() => dropdownHandlers.toggle()}\n            {...others}\n          >\n            {getLabel('moreLabel', labels)(moreEventsCount)}\n          </UnstyledButton>\n        </Popover.Target>\n\n        <Popover.Dropdown {...getStyles('moreEventsDropdown')}>{eventsList}</Popover.Dropdown>\n      </Popover>\n    </>\n  );\n});\n\nMoreEvents.displayName = '@mantine/schedule/MoreEvents';\nMoreEvents.classes = classes;\n"],"mappings":";;;;;;;;AAyEA,MAAM,eAAe,EACnB,cAAc,UAChB;AAEA,MAAa,aAAa,SAA4B,WAAW;CAC/D,MAAM,QAAQ,SAAS,cAAc,cAAc,MAAM;CACzD,MAAM,EACJ,YACA,WACA,OACA,QACA,UACA,MACA,YACA,QACA,cACA,QACA,iBACA,cACA,YACA,iBACA,UACA,YACA,iBACA,aACA,IACA,QACA,MACA,cACA,GAAG,WACD;CACJ,MAAM,CAAC,gBAAgB,oBAAoB,cAAc;CAEzD,MAAM,YAAY,UAA6B;EAC7C,MAAM;EACN,SAAA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,cAAc;CAChB,CAAC;CAED,MAAM,oBAAoB;EACxB,iBAAiB,MAAM;EACvB,kBAAkB;CACpB;CAEA,MAAM,aACJ,oBAAC,OAAD;EAAK,GAAI,UAAU,gBAAgB;YAChC,OAAO,KAAK,UACX,oBAAC,eAAD;GAEU;GACD;GACP,MAAK;GACY;GACJ;GACP;GACN,SAAS,gBAAgB,MAAM,aAAa,OAAO,CAAC,IAAI,KAAA;aAEvD,MAAM;EACM,GAVR,MAAM,EA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