{"version":3,"file":"Input.cjs","sources":["../../../src/components/Input/Input.tsx"],"sourcesContent":["import {\n  Box,\n  BoxProps,\n  createVarsResolver,\n  extractStyleProps,\n  getFontSize,\n  getRadius,\n  getSize,\n  polymorphicFactory,\n  PolymorphicFactory,\n  RaikouRadius,\n  RaikouSize,\n  rem,\n  StylesApiProps,\n  useProps,\n  useStyles,\n} from '../../core';\nimport { InputDescription } from './InputDescription/InputDescription';\nimport { InputError } from './InputError/InputError';\nimport { InputLabel } from './InputLabel/InputLabel';\nimport { InputPlaceholder } from './InputPlaceholder/InputPlaceholder';\nimport { useInputWrapperContext } from './InputWrapper.context';\nimport {\n  __InputWrapperProps,\n  InputWrapper,\n  InputWrapperStylesNames,\n} from './InputWrapper/InputWrapper';\nimport {\n  InputDescriptionStyle,\n  InputErrorStyle,\n  InputInputStyle,\n  InputLabelStyle,\n  InputRequiredStyle,\n  InputRootStyle,\n  InputSectionStyle,\n  InputWrapperStyle,\n} from './Input.css';\n\nexport interface __BaseInputProps extends __InputWrapperProps, Omit<__InputProps, 'wrapperProps'> {\n  /** Props passed down to the root element */\n  wrapperProps?: Record<string, any>;\n}\n\nexport type __InputStylesNames = InputStylesNames | InputWrapperStylesNames;\n\nexport type InputStylesNames = 'input' | 'wrapper' | 'section';\nexport type InputVariant = 'default' | 'filled' | 'unstyled';\nexport type InputCssVariables = {\n  wrapper:\n    | '--input-height'\n    | '--input-fz'\n    | '--input-radius'\n    | '--input-left-section-width'\n    | '--input-right-section-width'\n    | '--input-left-section-pointer-events'\n    | '--input-right-section-pointer-events'\n    | '--input-padding-y'\n    | '--input-margin-top'\n    | '--input-margin-bottom';\n};\n\nexport interface InputStylesCtx {\n  offsetTop: boolean | undefined;\n  offsetBottom: boolean | undefined;\n}\n\nexport interface __InputProps {\n  /** Content section rendered on the left side of the input */\n  leftSection?: React.ReactNode;\n\n  /** Left section width, used to set `width` of the section and input `padding-left`, by default equals to the input height */\n  leftSectionWidth?: React.CSSProperties['width'];\n\n  /** Props passed down to the `leftSection` element */\n  leftSectionProps?: React.ComponentPropsWithoutRef<'div'>;\n\n  /** Sets `pointer-events` styles on the `leftSection` element, `'none'` by default */\n  leftSectionPointerEvents?: React.CSSProperties['pointerEvents'];\n\n  /** Content section rendered on the right side of the input */\n  rightSection?: React.ReactNode;\n\n  /** Right section width, used to set `width` of the section and input `padding-right`, by default equals to the input height */\n  rightSectionWidth?: React.CSSProperties['width'];\n\n  /** Props passed down to the `rightSection` element */\n  rightSectionProps?: React.ComponentPropsWithoutRef<'div'>;\n\n  /** Sets `pointer-events` styles on the `rightSection` element, `'none'` by default */\n  rightSectionPointerEvents?: React.CSSProperties['pointerEvents'];\n\n  /** Props passed down to the root element of the `Input` component */\n  wrapperProps?: Record<string, any>;\n\n  /** Sets `required` attribute on the `input` element */\n  required?: boolean;\n\n  /** Key of `theme.radius` or any valid CSS value to set `border-radius`, numbers are converted to rem, `theme.defaultRadius` by default */\n  radius?: RaikouRadius;\n\n  /** Sets `disabled` attribute on the `input` element */\n  disabled?: boolean;\n\n  /** Controls input `height` and horizontal `padding`, `'sm'` by default */\n  size?: RaikouSize | (string & {});\n\n  /** Determines whether the input should have `cursor: pointer` style, `false` by default */\n  pointer?: boolean;\n\n  /** Determines whether the input should have red border and red text color when the `error` prop is set, `true` by default */\n  withErrorStyles?: boolean;\n\n  /** `size` prop added to the input element */\n  inputSize?: string;\n}\n\nexport interface InputProps extends BoxProps, __InputProps, StylesApiProps<InputFactory> {\n  __staticSelector?: string;\n\n  /** Props passed to Styles API context, replaces `Input.Wrapper` props */\n  __stylesApiProps?: Record<string, any>;\n\n  /** Determines whether the input should have error styles and `aria-invalid` attribute */\n  error?: React.ReactNode;\n\n  /** Determines whether the input can have multiple lines, for example when `component=\"textarea\"`, `false` by default */\n  multiline?: boolean;\n\n  /** Input element id */\n  id?: string;\n\n  /** Determines whether `aria-` and other accessibility attributes should be added to the input, `true` by default */\n  withAria?: boolean;\n}\n\nexport type InputFactory = PolymorphicFactory<{\n  props: InputProps;\n  defaultRef: HTMLInputElement;\n  defaultComponent: 'input';\n  stylesNames: InputStylesNames;\n  variant: InputVariant;\n  vars: InputCssVariables;\n  ctx: InputStylesCtx;\n  staticComponents: {\n    Label: typeof InputLabel;\n    Error: typeof InputError;\n    Description: typeof InputDescription;\n    Placeholder: typeof InputPlaceholder;\n    Wrapper: typeof InputWrapper;\n  };\n}>;\n\nconst defaultProps: Partial<InputProps> = {\n  variant: 'default',\n  leftSectionPointerEvents: 'none',\n  rightSectionPointerEvents: 'none',\n  withAria: true,\n  withErrorStyles: true,\n};\n\nconst varsResolver = createVarsResolver<InputFactory>((_, props, ctx) => ({\n  wrapper: {\n    '--input-margin-top': ctx.offsetTop ? 'calc(var(--raikou-spacing-xs) / 2)' : undefined,\n    '--input-margin-bottom': ctx.offsetBottom ? 'calc(var(--raikou-spacing-xs) / 2)' : undefined,\n    '--input-height': getSize(props.size, 'input-height'),\n    '--input-fz': getFontSize(props.size),\n    '--input-radius': props.radius === undefined ? undefined : getRadius(props.radius),\n    '--input-left-section-width':\n      props.leftSectionWidth !== undefined ? rem(props.leftSectionWidth) : undefined,\n    '--input-right-section-width':\n      props.rightSectionWidth !== undefined ? rem(props.rightSectionWidth) : undefined,\n    '--input-padding-y': props.multiline ? getSize(props.size, 'input-padding-y') : undefined,\n    '--input-left-section-pointer-events': props.leftSectionPointerEvents,\n    '--input-right-section-pointer-events': props.rightSectionPointerEvents,\n  },\n}));\n\nexport const Input = polymorphicFactory<InputFactory>((_props, ref) => {\n  const props = useProps('Input', defaultProps, _props);\n  const {\n    classNames,\n    className,\n    style,\n    styles,\n    unstyled,\n    required,\n    __staticSelector,\n    __stylesApiProps,\n    size,\n    wrapperProps,\n    error,\n    disabled,\n    leftSection,\n    leftSectionProps,\n    leftSectionWidth,\n    rightSection,\n    rightSectionProps,\n    rightSectionWidth,\n    rightSectionPointerEvents,\n    leftSectionPointerEvents,\n    variant,\n    vars,\n    pointer,\n    multiline,\n    radius,\n    id,\n    withAria,\n    withErrorStyles,\n    mod,\n    inputSize,\n    ...others\n  } = props;\n\n  const { styleProps, rest } = extractStyleProps(others);\n  const ctx = useInputWrapperContext();\n  const stylesCtx: InputStylesCtx = { offsetBottom: ctx?.offsetBottom, offsetTop: ctx?.offsetTop };\n\n  const getStyles = useStyles<InputFactory>({\n    name: ['Input', __staticSelector],\n    props: __stylesApiProps || props,\n    classes: {\n      root: InputRootStyle,\n      input: InputInputStyle,\n      wrapper: InputWrapperStyle,\n      section: InputSectionStyle,\n      label: InputLabelStyle,\n      required: InputRequiredStyle,\n      description: InputDescriptionStyle,\n      error: InputErrorStyle,\n    },\n    className,\n    style,\n    classNames,\n    styles,\n    unstyled,\n    stylesCtx,\n    rootSelector: 'wrapper',\n    vars,\n    varsResolver,\n  });\n\n  const ariaAttributes = withAria\n    ? {\n        required,\n        disabled,\n        'aria-invalid': !!error,\n        'aria-describedby': ctx?.describedBy,\n        id: ctx?.inputId || id,\n      }\n    : {};\n\n  return (\n    <Box\n      {...getStyles('wrapper')}\n      {...styleProps}\n      {...wrapperProps}\n      mod={[\n        {\n          error: !!error && withErrorStyles,\n          pointer,\n          disabled,\n          multiline,\n          'data-with-right-section': !!rightSection,\n          'data-with-left-section': !!leftSection,\n        },\n        mod,\n      ]}\n      variant={variant}\n      size={size}\n    >\n      {leftSection && (\n        <div\n          {...leftSectionProps}\n          data-position=\"left\"\n          {...getStyles('section', {\n            className: leftSectionProps?.className,\n            style: leftSectionProps?.style,\n          })}\n        >\n          {leftSection}\n        </div>\n      )}\n\n      <Box\n        component=\"input\"\n        {...rest}\n        {...ariaAttributes}\n        ref={ref}\n        required={required}\n        mod={{ disabled, error: !!error && withErrorStyles }}\n        variant={variant}\n        __size={inputSize}\n        {...getStyles('input')}\n      />\n\n      {rightSection && (\n        <div\n          {...rightSectionProps}\n          data-position=\"right\"\n          {...getStyles('section', {\n            className: rightSectionProps?.className,\n            style: rightSectionProps?.style,\n          })}\n        >\n          {rightSection}\n        </div>\n      )}\n    </Box>\n  );\n});\n\nInput.Wrapper = InputWrapper;\nInput.Label = InputLabel;\nInput.Error = InputError;\nInput.Description = InputDescription;\nInput.Placeholder = InputPlaceholder;\nInput.displayName = '@raikou/core/Input';\n"],"names":["createVarsResolver","getSize","getFontSize","getRadius","rem","polymorphicFactory","useProps","extractStyleProps","useInputWrapperContext","useStyles","InputRootStyle","InputInputStyle","InputWrapperStyle","InputSectionStyle","InputLabelStyle","InputRequiredStyle","InputDescriptionStyle","InputErrorStyle","jsxs","Box","jsx","InputWrapper","InputLabel","InputError","InputDescription","InputPlaceholder"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAwJA,MAAM,YAAoC,GAAA;AAAA,EACxC,OAAS,EAAA,SAAA;AAAA,EACT,wBAA0B,EAAA,MAAA;AAAA,EAC1B,yBAA2B,EAAA,MAAA;AAAA,EAC3B,QAAU,EAAA,IAAA;AAAA,EACV,eAAiB,EAAA;AACnB,CAAA;AAEA,MAAM,YAAe,GAAAA,qCAAA,CAAiC,CAAC,CAAA,EAAG,OAAO,GAAS,MAAA;AAAA,EACxE,OAAS,EAAA;AAAA,IACP,oBAAA,EAAsB,GAAI,CAAA,SAAA,GAAY,oCAAuC,GAAA,KAAA,CAAA;AAAA,IAC7E,uBAAA,EAAyB,GAAI,CAAA,YAAA,GAAe,oCAAuC,GAAA,KAAA,CAAA;AAAA,IACnF,gBAAkB,EAAAC,eAAA,CAAQ,KAAM,CAAA,IAAA,EAAM,cAAc,CAAA;AAAA,IACpD,YAAA,EAAcC,mBAAY,CAAA,KAAA,CAAM,IAAI,CAAA;AAAA,IACpC,kBAAkB,KAAM,CAAA,MAAA,KAAW,SAAY,KAAY,CAAA,GAAAC,iBAAA,CAAU,MAAM,MAAM,CAAA;AAAA,IACjF,8BACE,KAAM,CAAA,gBAAA,KAAqB,SAAYC,OAAI,CAAA,KAAA,CAAM,gBAAgB,CAAI,GAAA,KAAA,CAAA;AAAA,IACvE,+BACE,KAAM,CAAA,iBAAA,KAAsB,SAAY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