{"version":3,"file":"Indicator.mjs","sources":["../../../src/components/Indicator/Indicator.tsx"],"sourcesContent":["import {\n  Box,\n  BoxProps,\n  createVarsResolver,\n  ElementProps,\n  factory,\n  Factory,\n  getAutoContrastValue,\n  getContrastColor,\n  getRadius,\n  getThemeColor,\n  RaikouColor,\n  RaikouRadius,\n  rem,\n  StylesApiProps,\n  useProps,\n  useStyles,\n} from '../../core';\nimport { getPositionVariables } from './get-position-variables/get-position-variables';\nimport { IndicatorPosition } from './Indicator.types';\nimport { IndicatorIndicatorStyle, IndicatorRootStyle } from './Indicator.css';\n\nexport type IndicatorPositionVariables =\n  | '--indicator-top'\n  | '--indicator-bottom'\n  | '--indicator-left'\n  | '--indicator-right'\n  | '--indicator-translate-x'\n  | '--indicator-translate-y';\n\nexport type IndicatorStylesNames = 'root' | 'indicator';\nexport type IndicatorCssVariables = {\n  root:\n    | '--indicator-color'\n    | '--indicator-text-color'\n    | '--indicator-size'\n    | '--indicator-radius'\n    | '--indicator-z-index'\n    | IndicatorPositionVariables;\n};\n\nexport interface IndicatorProps\n  extends BoxProps,\n    StylesApiProps<IndicatorFactory>,\n    ElementProps<'div'> {\n  /** Indicator position relative to the target element, `'top-end'` by default */\n  position?: IndicatorPosition;\n\n  /** Indicator offset relative to the target element, usually used for elements with border-radius, equals to `size` by default */\n  offset?: number;\n\n  /** Determines whether the indicator container should be an inline element, `false` by default */\n  inline?: boolean;\n\n  /** Indicator width and height, `10` by default */\n  size?: number | string;\n\n  /** Label rendered inside the indicator, for example, notification count */\n  label?: React.ReactNode;\n\n  /** Key of `theme.radius` or any valid CSS value to set `border-radius`, `100` by default */\n  radius?: RaikouRadius;\n\n  /** Key of `theme.colors` or any valid CSS color value, `theme.primaryColor` by default */\n  color?: RaikouColor;\n\n  /** Determines whether the indicator should have a border (color of the border is the same as the body element), `false` by default */\n  withBorder?: boolean;\n\n  /** When Indicator is disabled it renders children only */\n  disabled?: boolean;\n\n  /** Determines whether the indicator should have processing animation, `false` by default */\n  processing?: boolean;\n\n  /** Indicator z-index, `200` by default */\n  zIndex?: string | number;\n\n  /** Determines whether text color should depend on `background-color`. If luminosity of the `color` prop is less than `theme.luminosityThreshold`, then `theme.white` will be used for text color, otherwise `theme.black`. Overrides `theme.autoContrast`. */\n  autoContrast?: boolean;\n}\n\nexport type IndicatorFactory = Factory<{\n  props: IndicatorProps;\n  ref: HTMLDivElement;\n  stylesNames: IndicatorStylesNames;\n  vars: IndicatorCssVariables;\n}>;\n\nconst defaultProps: Partial<IndicatorProps> = {\n  position: 'top-end',\n  offset: 0,\n  inline: false,\n  withBorder: false,\n  disabled: false,\n  processing: false,\n};\n\nconst varsResolver = createVarsResolver<IndicatorFactory>(\n  (theme, { color, position, offset, size, radius, zIndex, autoContrast }) => ({\n    root: {\n      '--indicator-color': color ? getThemeColor(color, theme) : undefined,\n      '--indicator-text-color': getAutoContrastValue(autoContrast, theme)\n        ? getContrastColor({ color, theme, autoContrast })\n        : undefined,\n      '--indicator-size': rem(size),\n      '--indicator-radius': radius === undefined ? undefined : getRadius(radius),\n      '--indicator-z-index': zIndex?.toString(),\n      ...getPositionVariables(position, offset),\n    },\n  })\n);\n\nexport const Indicator = factory<IndicatorFactory>((_props, ref) => {\n  const props = useProps('Indicator', defaultProps, _props);\n  const {\n    classNames,\n    className,\n    style,\n    styles,\n    unstyled,\n    vars,\n    children,\n    position,\n    offset,\n    inline,\n    label,\n    radius,\n    color,\n    withBorder,\n    disabled,\n    processing,\n    zIndex,\n    autoContrast,\n    mod,\n    ...others\n  } = props;\n\n  const getStyles = useStyles<IndicatorFactory>({\n    name: 'Indicator',\n    classes: {\n      root: IndicatorRootStyle,\n      indicator: IndicatorIndicatorStyle,\n    },\n    props,\n    className,\n    style,\n    classNames,\n    styles,\n    unstyled,\n    vars,\n    varsResolver,\n  });\n\n  return (\n    <Box ref={ref} {...getStyles('root')} mod={[{ inline }, mod]} {...others}>\n      {!disabled && (\n        <Box\n          mod={{ 'with-label': !!label, 'with-border': withBorder, processing }}\n          {...getStyles('indicator')}\n        >\n          {label}\n        </Box>\n      )}\n      {children}\n    </Box>\n  );\n});\n\nIndicator.displayName = '@raikou/core/Indicator';\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAyFA,MAAM,YAAwC,GAAA;AAAA,EAC5C,QAAU,EAAA,SAAA;AAAA,EACV,MAAQ,EAAA,CAAA;AAAA,EACR,MAAQ,EAAA,KAAA;AAAA,EACR,UAAY,EAAA,KAAA;AAAA,EACZ,QAAU,EAAA,KAAA;AAAA,EACV,UAAY,EAAA;AACd,CAAA;AAEA,MAAM,YAAe,GAAA,kBAAA;AAAA,EACnB,CAAC,KAAO,EAAA,EAAE,KAAO,EAAA,QAAA,EAAU,QAAQ,IAAM,EAAA,MAAA,EAAQ,MAAQ,EAAA,YAAA,EAAoB,MAAA;AAAA,IAC3E,IAAM,EAAA;AAAA,MACJ,mBAAqB,EAAA,KAAA,GAAQ,aAAc,CAAA,KAAA,EAAO,KAAK,CAAI,GAAA,KAAA,CAAA;AAAA,MAC3D,wBAAA,EAA0B,oBAAqB,CAAA,YAAA,EAAc,KAAK,CAAA,GAC9D,gBAAiB,CAAA,EAAE,KAAO,EAAA,KAAA,EAAO,YAAa,EAAC,CAC/C,GAAA,KAAA,CAAA;AAAA,MACJ,kBAAA,EAAoB,IAAI,IAAI,CAAA;AAAA,MAC5B,oBAAsB,EAAA,MAAA,KAAW,KAAY,CAAA,GAAA,KAAA,CAAA,GAAY,UAAU,MAAM,CAAA;AAAA,MACzE,qBAAA,EAAuB,QAAQ,QAAS,EAAA;AAAA,MACxC,GAAG,oBAAqB,CAAA,QAAA,EAAU,MAAM;AAAA;AAC1C,GACF;AACF,CAAA;AAEO,MAAM,SAAY,GAAA,OAAA,CAA0B,CAAC,MAAA,EAAQ,GAAQ,KAAA;AAClE,EAAA,MAAM,KAAQ,GAAA,QAAA,CAAS,WAAa,EAAA,YAAA,EAAc,MAAM,CAAA;AACxD,EAAM,MAAA;AAAA,IACJ,UAAA;AA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