{"version":3,"file":"ComboboxEventsTarget.cjs","sources":["../../../../src/components/Combobox/ComboboxEventsTarget/ComboboxEventsTarget.tsx"],"sourcesContent":["import { cloneElement } from 'react';\nimport { useMergedRef } from '@raikou/hooks';\nimport { factory, Factory, getRefProp, isElement, useProps } from '../../../core';\nimport { useComboboxContext } from '../Combobox.context';\nimport { useComboboxTargetProps } from '../use-combobox-target-props/use-combobox-target-props';\n\nexport interface ComboboxEventsTargetProps {\n  /** Target element */\n  children: React.ReactNode;\n\n  /** Key of the prop that should be used to access element ref */\n  refProp?: string;\n\n  /** Determines whether component should respond to keyboard events, `true` by default */\n  withKeyboardNavigation?: boolean;\n\n  /** Determines whether the target should have `aria-` attributes, `true` by default */\n  withAriaAttributes?: boolean;\n\n  /** Determines whether the target should have `aria-expanded` attribute, `false` by default */\n  withExpandedAttribute?: boolean;\n\n  /** Determines which events should be handled by the target element.\n   * `button` target type handles `Space` and `Enter` keys to toggle dropdown opened state.\n   * `input` by default.\n   * */\n  targetType?: 'button' | 'input';\n\n  /** Input autocomplete attribute */\n  autoComplete?: string;\n}\n\nconst defaultProps: Partial<ComboboxEventsTargetProps> = {\n  refProp: 'ref',\n  targetType: 'input',\n  withKeyboardNavigation: true,\n  withAriaAttributes: true,\n  withExpandedAttribute: false,\n  autoComplete: 'off',\n};\n\nexport type ComboboxEventsTargetFactory = Factory<{\n  props: ComboboxEventsTargetProps;\n  ref: HTMLElement;\n  compound: true;\n}>;\n\nexport const ComboboxEventsTarget = factory<ComboboxEventsTargetFactory>((props, ref) => {\n  const {\n    children,\n    refProp,\n    withKeyboardNavigation,\n    withAriaAttributes,\n    withExpandedAttribute,\n    targetType,\n    autoComplete,\n    ...others\n  } = useProps('ComboboxEventsTarget', defaultProps, props);\n\n  if (!isElement(children)) {\n    throw new Error(\n      'Combobox.EventsTarget component children should be an element or a component that accepts ref. Fragments, strings, numbers and other primitive values are not supported'\n    );\n  }\n\n  const ctx = useComboboxContext();\n  const targetProps = useComboboxTargetProps({\n    targetType,\n    withAriaAttributes,\n    withKeyboardNavigation,\n    withExpandedAttribute,\n    onKeyDown: children.props.onKeyDown,\n    autoComplete,\n  });\n\n  return cloneElement(children, {\n    ...targetProps,\n    ...others,\n    [refProp!]: useMergedRef(ref, ctx.store.targetRef, getRefProp(children)),\n  });\n});\n\nComboboxEventsTarget.displayName = '@raikou/core/ComboboxEventsTarget';\n"],"names":["factory","useProps","isElement","useComboboxContext","useComboboxTargetProps","cloneElement","useMergedRef","getRefProp"],"mappings":";;;;;;;;;;;;;;;;AAgCA,MAAM,YAAmD,GAAA;AAAA,EACvD,OAAS,EAAA,KAAA;AAAA,EACT,UAAY,EAAA,OAAA;AAAA,EACZ,sBAAwB,EAAA,IAAA;AAAA,EACxB,kBAAoB,EAAA,IAAA;AAAA,EACpB,qBAAuB,EAAA,KAAA;AAAA,EACvB,YAAc,EAAA;AAChB,CAAA;AAQO,MAAM,oBAAuB,GAAAA,eAAA,CAAqC,CAAC,KAAA,EAAO,GAAQ,KAAA;AACvF,EAAM,MAAA;AAAA,IACJ,QAAA;AAAA,IACA,OAAA;AAAA,IACA,sBAAA;AAAA,IACA,kBAAA;AAAA,IACA,qBAAA;AAAA,IACA,UAAA;AAAA,IACA,YAAA;AAAA,IACA,GAAG;AAAA,GACD,GAAAC,iBAAA,CAAS,sBAAwB,EAAA,YAAA,EAAc,KAAK,CAAA;AAExD,EAAI,IAAA,CAACC,mBAAU,CAAA,QAAQ,CAAG,EAAA;AACxB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA;AAGF,EAAA,MAAM,MAAMC,mCAAmB,EAAA;AAC/B,EAAA,MAAM,cAAcC,6CAAuB,CAAA;AAAA,IACzC,UAAA;AAAA,IACA,kBAAA;AAAA,IACA,sBAAA;AAAA,IACA,qBAAA;AAAA,IACA,SAAA,EAAW,SAAS,KAAM,CAAA,SAAA;AAAA,IAC1B;AAAA,GACD,CAAA;AAED,EAAA,OAAOC,mBAAa,QAAU,EAAA;AAAA,IAC5B,GAAG,WAAA;AAAA,IACH,GAAG,MAAA;AAAA,IACH,CAAC,OAAQ,GAAGC,kBAAa,CAAA,GAAA,EAAK,IAAI,KAAM,CAAA,SAAA,EAAWC,qBAAW,CAAA,QAAQ,CAAC;AAAA,GACxE,CAAA;AACH,CAAC;AAED,oBAAA,CAAqB,WAAc,GAAA,mCAAA;;;;"}