{"version":3,"file":"ComboboxTarget.cjs","sources":["../../../../src/components/Combobox/ComboboxTarget/ComboboxTarget.tsx"],"sourcesContent":["import { cloneElement } from 'react';\nimport { useMergedRef } from '@raikou/hooks';\nimport { factory, Factory, isElement, useProps } from '../../../core';\nimport { Popover } from '../../Popover';\nimport { useComboboxContext } from '../Combobox.context';\nimport { useComboboxTargetProps } from '../use-combobox-target-props/use-combobox-target-props';\n\nexport interface ComboboxTargetProps {\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<ComboboxTargetProps> = {\n  refProp: 'ref',\n  targetType: 'input',\n  withKeyboardNavigation: true,\n  withAriaAttributes: true,\n  withExpandedAttribute: false,\n  autoComplete: 'off',\n};\n\nexport type ComboboxTargetFactory = Factory<{\n  props: ComboboxTargetProps;\n  ref: HTMLElement;\n  compound: true;\n}>;\n\nexport const ComboboxTarget = factory<ComboboxTargetFactory>((props, ref) => {\n  const {\n    children,\n    refProp,\n    withKeyboardNavigation,\n    withAriaAttributes,\n    withExpandedAttribute,\n    targetType,\n    autoComplete,\n    ...others\n  } = useProps('ComboboxTarget', defaultProps, props);\n\n  if (!isElement(children)) {\n    throw new Error(\n      'Combobox.Target 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\n  const targetProps = useComboboxTargetProps({\n    targetType,\n    withAriaAttributes,\n    withKeyboardNavigation,\n    withExpandedAttribute,\n    onKeyDown: children.props.onKeyDown,\n    autoComplete,\n  });\n\n  const clonedElement = cloneElement(children, {\n    ...targetProps,\n    ...others,\n  });\n\n  return (\n    <Popover.Target ref={useMergedRef(ref, ctx.store.targetRef)}>{clonedElement}</Popover.Target>\n  );\n});\n\nComboboxTarget.displayName = '@raikou/core/ComboboxTarget';\n"],"names":["factory","useProps","isElement","useComboboxContext","useComboboxTargetProps","cloneElement","jsx","Popover","useMergedRef"],"mappings":";;;;;;;;;;;;;;;;;;AAiCA,MAAM,YAA6C,GAAA;AAAA,EACjD,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,cAAiB,GAAAA,eAAA,CAA+B,CAAC,KAAA,EAAO,GAAQ,KAAA;AAC3E,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,gBAAkB,EAAA,YAAA,EAAc,KAAK,CAAA;AAElD,EAAI,IAAA,CAACC,mBAAU,CAAA,QAAQ,CAAG,EAAA;AACxB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA;AAGF,EAAA,MAAM,MAAMC,mCAAmB,EAAA;AAE/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,EAAM,MAAA,aAAA,GAAgBC,m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