{"version":3,"file":"index.cjs","sources":["../../../../src/components/NumberField/NumberField.tsx"],"sourcesContent":["import {\n  ChangeEvent,\n  InputHTMLAttributes,\n  ReactNode,\n  forwardRef,\n  useId,\n  useRef,\n} from 'react';\nimport { Icon } from '@/components/Icon';\nimport {\n  InputEndContent,\n  InputStartContent,\n  InputWrapper,\n  NumberInputElement,\n  WrapperProps,\n} from '@/components/InputWrapper';\nimport { mergeRefs } from '@/utils/mergeRefs';\nexport interface NumberFieldProps\n  extends\n    Omit<WrapperProps, 'id' | 'children'>,\n    Omit<InputHTMLAttributes<HTMLInputElement>, 'type' | 'onChange' | 'dir'> {\n  /** The input type - always number for NumberField */\n  type?: 'number';\n  /** Whether to show a loading spinner */\n  loading?: boolean;\n  /** Callback when the input value changes */\n  onChange: (inputValue: string, e?: ChangeEvent<HTMLInputElement>) => void;\n  /** The orientation of the label relative to the input */\n  orientation?: 'vertical' | 'horizontal';\n  /** The direction/position of the label - start places label before, end places label after */\n  dir?: 'start' | 'end';\n  /** Whether to hide the increment/decrement controls */\n  hideControls?: boolean;\n  /** Additional content to the left of the control */\n  startContent?: ReactNode;\n  /** Additional content to the right of the control */\n  endContent?: ReactNode;\n}\n\nexport const NumberField = forwardRef<HTMLInputElement, NumberFieldProps>(\n  (\n    {\n      disabled,\n      label,\n      error,\n      id,\n      loading,\n      onChange: onChangeProp,\n      orientation,\n      dir,\n      hideControls,\n      startContent,\n      endContent,\n      ...props\n    },\n    ref\n  ) => {\n    const inputRef = useRef<HTMLInputElement>(null);\n    const defaultId = useId();\n    const onChange = (e: ChangeEvent<HTMLInputElement>) => {\n      onChangeProp(e.target.value, e);\n    };\n\n    const handleStartContentClick: React.MouseEventHandler<HTMLDivElement> = () => {\n      inputRef.current?.focus();\n    };\n\n    const hasStartContent = Boolean(startContent);\n    const hasEndContent = Boolean(loading || endContent);\n\n    return (\n      <InputWrapper\n        disabled={disabled}\n        id={id ?? defaultId}\n        label={label}\n        error={error}\n        orientation={orientation}\n        dir={dir}\n      >\n        {startContent && (\n          <InputStartContent onClick={handleStartContentClick}>\n            {startContent}\n          </InputStartContent>\n        )}\n        <NumberInputElement\n          ref={mergeRefs([inputRef, ref])}\n          type=\"number\"\n          id={id ?? defaultId}\n          disabled={disabled}\n          onChange={onChange}\n          $hideControls={hideControls}\n          $hasStartContent={hasStartContent}\n          $hasEndContent={hasEndContent}\n          {...props}\n        />\n        {hasEndContent && (\n          <InputEndContent>\n            {endContent ? endContent : null}\n            {loading && (\n              <Icon\n                name=\"loading-animated\"\n                size=\"sm\"\n              />\n            )}\n          </InputEndContent>\n        )}\n      </InputWrapper>\n    );\n  }\n);\n"],"names":["forwardRef","useRef","useId","jsxs","InputWrapper","jsx","InputStartContent","NumberInputElement","mergeRefs","InputEndContent","Icon"],"mappings":";;;;;;;;;;AAuCO,MAAM,WAAA,GAAcA,gBAAA;AAAA,EACzB,CACE;AAAA,IACE,QAAA;AAAA,IACA,KAAA;AAAA,IACA,KAAA;AAAA,IACA,EAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA,EAAU,YAAA;AAAA,IACV,WAAA;AAAA,IACA,GAAA;AAAA,IACA,YAAA;AAAA,IACA,YAAA;AAAA,IACA,UAAA;AAAA,IACA,GAAG;AAAA,KAEL,GAAA,KACG;AACH,IAAA,MAAM,QAAA,GAAWC,aAAyB,IAAI,CAAA;AAC9C,IAAA,MAAM,YAAYC,WAAA,EAAM;AACxB,IAAA,MAAM,QAAA,GAAW,CAAC,CAAA,KAAqC;AACrD,MAAA,YAAA,CAAa,CAAA,CAAE,MAAA,CAAO,KAAA,EAAO,CAAC,CAAA;AAAA,IAChC,CAAA;AAEA,IAAA,MAAM,0BAAmE,MAAM;AAC7E,MAAA,QAAA,CAAS,SAAS,KAAA,EAAM;AAAA,IAC1B,CAAA;AAEA,IAAA,MAAM,eAAA,GAAkB,QAAQ,YAAY,CAAA;AAC5C,IAAA,MAAM,aAAA,GAAgB,OAAA,CAAQ,OAAA,IAAW,UAAU,CAAA;AAEnD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