{"version":3,"file":"ActionBar.mjs","names":["classes"],"sources":["../../../src/components/ActionBar/ActionBar.tsx"],"sourcesContent":["import { useEffect, useEffectEvent } from 'react';\nimport { RemoveScroll } from 'react-remove-scroll';\nimport {\n  BoxProps,\n  ElementProps,\n  factory,\n  Factory,\n  getDefaultZIndex,\n  MantineRadius,\n  MantineShadow,\n  StylesApiProps,\n  useProps,\n  useStyles,\n} from '../../core';\nimport { Affix, AffixBaseProps } from '../Affix';\nimport { Paper, PaperBaseProps } from '../Paper';\nimport { Transition, TransitionOverride } from '../Transition';\nimport { ActionBarProvider } from './ActionBar.context';\nimport {\n  ActionBarCloseButton,\n  ActionBarCloseButtonStylesNames,\n} from './ActionBarCloseButton/ActionBarCloseButton';\nimport { ActionBarDivider, ActionBarDividerStylesNames } from './ActionBarDivider/ActionBarDivider';\nimport classes from './ActionBar.module.css';\n\nexport type ActionBarStylesNames =\n  | 'root'\n  | ActionBarDividerStylesNames\n  | ActionBarCloseButtonStylesNames;\n\nexport interface ActionBarProps\n  extends\n    BoxProps,\n    AffixBaseProps,\n    PaperBaseProps,\n    StylesApiProps<ActionBarFactory>,\n    ElementProps<'div'> {\n  /** Controls visibility */\n  opened: boolean;\n\n  /** Called when close button is clicked or Escape is pressed */\n  onClose?: () => void;\n\n  /** Props passed down to the `Transition` component, `{ transition: 'pop', duration: 200 }` by default */\n  transitionProps?: TransitionOverride;\n\n  /** Key of `theme.shadows` or any valid CSS `box-shadow` value */\n  shadow?: MantineShadow;\n\n  /** Key of `theme.radius` or any valid CSS value to set `border-radius` */\n  radius?: MantineRadius;\n\n  /** Determines whether the action bar should be closed when `Escape` key is pressed, `false` by default */\n  closeOnEscape?: boolean;\n\n  /** `aria-label` of the actions group, `'Actions'` by default */\n  'aria-label'?: string;\n\n  /** If set, the component uses `display: none` to hide the root element instead of removing the DOM node, `false` by default */\n  keepMounted?: boolean;\n\n  children: React.ReactNode;\n}\n\nexport type ActionBarFactory = Factory<{\n  props: ActionBarProps;\n  ref: HTMLDivElement;\n  stylesNames: ActionBarStylesNames;\n  staticComponents: {\n    Divider: typeof ActionBarDivider;\n    CloseButton: typeof ActionBarCloseButton;\n  };\n}>;\n\nconst defaultProps = {\n  withBorder: true,\n  py: 'xs',\n  px: 'sm',\n  position: { bottom: 30, left: 0, right: 0 },\n  transitionProps: { transition: 'pop', duration: 200 },\n  closeOnEscape: false,\n  withinPortal: true,\n  'aria-label': 'Actions',\n  zIndex: getDefaultZIndex('modal'),\n} satisfies Partial<ActionBarProps>;\n\nexport const ActionBar = factory<ActionBarFactory>((_props) => {\n  const props = useProps('ActionBar', defaultProps, _props);\n  const {\n    classNames,\n    className,\n    style,\n    styles,\n    unstyled,\n    vars,\n    zIndex,\n    position,\n    keepMounted,\n    opened,\n    transitionProps,\n    withinPortal,\n    children,\n    onClose,\n    portalProps,\n    closeOnEscape,\n    attributes,\n    ...others\n  } = props;\n\n  const getStyles = useStyles<ActionBarFactory>({\n    name: 'ActionBar',\n    classes,\n    props,\n    className,\n    style,\n    classNames,\n    styles,\n    unstyled,\n    attributes,\n    vars,\n  });\n\n  const handleEscape = useEffectEvent((event: KeyboardEvent) => {\n    if (event.key === 'Escape' && !event.isComposing) {\n      onClose?.();\n    }\n  });\n\n  useEffect(() => {\n    if (!closeOnEscape || !opened) {\n      return undefined;\n    }\n\n    window.addEventListener('keydown', handleEscape, { passive: true });\n    return () => window.removeEventListener('keydown', handleEscape);\n  }, [closeOnEscape, opened]);\n\n  return (\n    <Affix\n      zIndex={zIndex}\n      position={position}\n      withinPortal={withinPortal}\n      portalProps={portalProps}\n      unstyled={unstyled}\n      // The default position is anchored to both edges, so the bar is a full width fixed\n      // element. Without this it shifts by the scrollbar width whenever a Modal or Drawer\n      // locks scrolling – which is exactly the flow ActionBar exists for (select rows, run a\n      // bulk action, confirm it in a modal).\n      className={RemoveScroll.classNames.fullWidth}\n    >\n      {/* `keepMountedMode` is pinned to `display-none`: the documented contract is that the\n          bar stays in the DOM and is merely hidden, and `Transition`'s default `activity`\n          mode tears down the effects of everything inside it instead. */}\n      <Transition\n        keepMounted={keepMounted}\n        keepMountedMode=\"display-none\"\n        mounted={opened}\n        {...transitionProps}\n      >\n        {(transitionStyles) => (\n          <ActionBarProvider value={{ onClose, getStyles, unstyled }}>\n            <Paper\n              unstyled={unstyled}\n              {...getStyles('root', { style: transitionStyles })}\n              role=\"group\"\n              {...others}\n            >\n              {children}\n            </Paper>\n          </ActionBarProvider>\n        )}\n      </Transition>\n    </Affix>\n  );\n});\n\nActionBar.classes = classes;\nActionBar.displayName = '@mantine/core/ActionBar';\nActionBar.Divider = ActionBarDivider;\nActionBar.CloseButton = ActionBarCloseButton;\n"],"mappings":";;;;;;;;;;;;;;;;AA0EA,MAAM,eAAe;CACnB,YAAY;CACZ,IAAI;CACJ,IAAI;CACJ,UAAU;EAAE,QAAQ;EAAI,MAAM;EAAG,OAAO;CAAE;CAC1C,iBAAiB;EAAE,YAAY;EAAO,UAAU;CAAI;CACpD,eAAe;CACf,cAAc;CACd,cAAc;CACd,QAAQ,iBAAiB,OAAO;AAClC;AAEA,MAAa,YAAY,SAA2B,WAAW;CAC7D,MAAM,QAAQ,SAAS,aAAa,cAAc,MAAM;CACxD,MAAM,EACJ,YACA,WACA,OACA,QACA,UACA,MACA,QACA,UACA,aACA,QACA,iBACA,cACA,UACA,SACA,aACA,eACA,YACA,GAAG,WACD;CAEJ,MAAM,YAAY,UAA4B;EAC5C,MAAM;EACN,SAAA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,MAAM,eAAe,gBAAgB,UAAyB;EAC5D,IAAI,MAAM,QAAQ,YAAY,CAAC,MAAM,aACnC,UAAU;CAEd,CAAC;CAED,gBAAgB;EACd,IAAI,CAAC,iBAAiB,CAAC,QACrB;EAGF,OAAO,iBAAiB,WAAW,cAAc,EAAE,SAAS,KAAK,CAAC;EAClE,aAAa,OAAO,oBAAoB,WAAW,YAAY;CACjE,GAAG,CAAC,eAAe,MAAM,CAAC;C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