@ozen-ui/kit 0.31.0 → 0.32.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/__inner__/cjs/components/DataList/DataList.js +1 -1
  2. package/__inner__/cjs/components/FieldControl/FieldControl.js +6 -1
  3. package/__inner__/cjs/components/FieldControl/FieldControlContext.d.ts +2 -0
  4. package/__inner__/cjs/components/FieldControl/FieldControlContext.js +4 -2
  5. package/__inner__/cjs/components/FieldHint/FieldHint.js +1 -1
  6. package/__inner__/cjs/components/FieldIcon/FieldIcon.js +1 -1
  7. package/__inner__/cjs/components/FieldInput/FieldInput.js +1 -1
  8. package/__inner__/cjs/components/FieldLabel/FieldLabel.js +1 -1
  9. package/__inner__/cjs/components/Select/components/SelectConsumer/SelectInputConsumer.js +2 -2
  10. package/__inner__/cjs/components/Textarea/components/TextareaConsumer.js +1 -1
  11. package/__inner__/cjs/components/Textarea/components/TextareaCounter.js +2 -2
  12. package/__inner__/cjs/components/ThemeProvider/_color/Theme_color_ozenDark.css +7 -7
  13. package/__inner__/cjs/hooks/useHover/index.d.ts +1 -0
  14. package/__inner__/cjs/hooks/useHover/index.js +4 -0
  15. package/__inner__/cjs/hooks/useHover/useHover.d.ts +14 -0
  16. package/__inner__/cjs/hooks/useHover/useHover.js +37 -0
  17. package/__inner__/esm/components/DataList/DataList.js +1 -1
  18. package/__inner__/esm/components/FieldControl/FieldControl.js +7 -2
  19. package/__inner__/esm/components/FieldControl/FieldControlContext.d.ts +2 -0
  20. package/__inner__/esm/components/FieldControl/FieldControlContext.js +2 -1
  21. package/__inner__/esm/components/FieldHint/FieldHint.js +3 -3
  22. package/__inner__/esm/components/FieldIcon/FieldIcon.js +3 -3
  23. package/__inner__/esm/components/FieldInput/FieldInput.js +3 -3
  24. package/__inner__/esm/components/FieldLabel/FieldLabel.js +3 -3
  25. package/__inner__/esm/components/Select/components/SelectConsumer/SelectInputConsumer.js +3 -3
  26. package/__inner__/esm/components/Textarea/components/TextareaConsumer.js +3 -3
  27. package/__inner__/esm/components/Textarea/components/TextareaCounter.js +3 -3
  28. package/__inner__/esm/components/ThemeProvider/_color/Theme_color_ozenDark.css +7 -7
  29. package/__inner__/esm/hooks/useHover/index.d.ts +1 -0
  30. package/__inner__/esm/hooks/useHover/index.js +1 -0
  31. package/__inner__/esm/hooks/useHover/useHover.d.ts +14 -0
  32. package/__inner__/esm/hooks/useHover/useHover.js +33 -0
  33. package/package.json +1 -1
  34. package/useHover/package.json +5 -0
@@ -81,7 +81,7 @@ var DataListRender = function (inProps, ref) {
81
81
  var _a, _b;
82
82
  var current = focused || selected || '';
83
83
  var idx = nodes.get(current);
84
- if (idx) {
84
+ if (idx !== undefined) {
85
85
  setSelectedElRef({
86
86
  current: (_b = (_a = listRef.current) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b[idx],
87
87
  });
@@ -4,6 +4,8 @@ exports.FieldControl = exports.cnFieldControl = exports.FIELD_CONTROL_DEFAULT_TA
4
4
  var tslib_1 = require("tslib");
5
5
  require("./FieldControl.css");
6
6
  var react_1 = tslib_1.__importStar(require("react"));
7
+ var useHover_1 = require("../../hooks/useHover");
8
+ var useMultiRef_1 = require("../../hooks/useMultiRef");
7
9
  var useThemeProps_1 = require("../../hooks/useThemeProps");
8
10
  var classname_1 = require("../../utils/classname");
9
11
  var polymorphicComponentWithRef_1 = require("../../utils/polymorphicComponentWithRef");
@@ -15,6 +17,8 @@ exports.FieldControl = (0, polymorphicComponentWithRef_1.polymorphicComponentWit
15
17
  props: inProps,
16
18
  name: 'FieldControl',
17
19
  });
20
+ var innerRef = (0, react_1.useRef)(null);
21
+ var hovered = (0, useHover_1.useHover)(innerRef);
18
22
  var _a = props.as, Tag = _a === void 0 ? exports.FIELD_CONTROL_DEFAULT_TAG : _a, sizeProp = props.size, disabledProp = props.disabled, requiredProp = props.required, errorProp = props.error, fullWidthProp = props.fullWidth, filledProp = props.filled, focusedProp = props.focused, children = props.children, className = props.className, otherProp = tslib_1.__rest(props, ["as", "size", "disabled", "required", "error", "fullWidth", "filled", "focused", "children", "className"]);
19
23
  var focused = focusedProp;
20
24
  var filled = filledProp;
@@ -64,7 +68,7 @@ exports.FieldControl = (0, polymorphicComponentWithRef_1.polymorphicComponentWit
64
68
  filled: filled,
65
69
  focused: focused,
66
70
  hasLabel: !!label,
67
- }, [className]) }, otherProp, { ref: ref }),
71
+ }, [className]) }, otherProp, { ref: (0, useMultiRef_1.useMultiRef)([ref, innerRef]) }),
68
72
  react_1.default.createElement(index_1.FieldControlContext.Provider, { value: [
69
73
  {
70
74
  error: error,
@@ -75,6 +79,7 @@ exports.FieldControl = (0, polymorphicComponentWithRef_1.polymorphicComponentWit
75
79
  size: size,
76
80
  filled: filled,
77
81
  focused: focused,
82
+ hovered: hovered,
78
83
  value: value,
79
84
  },
80
85
  setState,
@@ -9,7 +9,9 @@ export type FieldControlContextValue = {
9
9
  fullWidth?: boolean;
10
10
  filled?: boolean;
11
11
  focused?: boolean;
12
+ hovered?: boolean;
12
13
  label?: string;
13
14
  value?: string | number;
14
15
  };
15
16
  export declare const FieldControlContext: React.Context<[FieldControlContextValue, Dispatch<SetStateAction<FieldControlContextValue>>]>;
17
+ export declare const useFieldControl: () => [FieldControlContextValue, Dispatch<SetStateAction<FieldControlContextValue>>];
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FieldControlContext = void 0;
3
+ exports.useFieldControl = exports.FieldControlContext = void 0;
4
4
  var tslib_1 = require("tslib");
5
- var react_1 = tslib_1.__importDefault(require("react"));
5
+ var react_1 = tslib_1.__importStar(require("react"));
6
6
  exports.FieldControlContext = react_1.default.createContext([{}, function () { return undefined; }]);
7
+ var useFieldControl = function () { return (0, react_1.useContext)(exports.FieldControlContext); };
8
+ exports.useFieldControl = useFieldControl;
@@ -10,7 +10,7 @@ exports.FIELD_HINT_DEFAULT_TAG = 'div';
10
10
  exports.cnFieldHint = (0, classname_1.cn)('FieldHint');
11
11
  exports.FieldHint = (0, react_1.forwardRef)(function (_a, ref) {
12
12
  var children = _a.children, errorProp = _a.error, disabledProp = _a.disabled, sizeProp = _a.size, className = _a.className, other = tslib_1.__rest(_a, ["children", "error", "disabled", "size", "className"]);
13
- var context = (0, react_1.useContext)(FieldControl_1.FieldControlContext);
13
+ var context = (0, FieldControl_1.useFieldControl)();
14
14
  var _b = tslib_1.__read(context, 1), fieldControl = _b[0];
15
15
  var Tag = exports.FIELD_HINT_DEFAULT_TAG;
16
16
  var size = sizeProp;
@@ -12,7 +12,7 @@ exports.FIELD_ICON_DEFAULT_TAG = 'div';
12
12
  exports.cnFieldIcon = (0, classname_1.cn)('FieldIcon');
13
13
  exports.FieldIcon = (0, react_1.forwardRef)(function (_a, ref) {
14
14
  var icon = _a.icon, className = _a.className, sizeProp = _a.size, other = tslib_1.__rest(_a, ["icon", "className", "size"]);
15
- var context = (0, react_1.useContext)(FieldControl_1.FieldControlContext);
15
+ var context = (0, FieldControl_1.useFieldControl)();
16
16
  var _b = tslib_1.__read(context, 1), fieldControl = _b[0];
17
17
  var Tag = exports.FIELD_ICON_DEFAULT_TAG;
18
18
  var size = sizeProp;
@@ -13,7 +13,7 @@ exports.cnFieldInput = (0, classname_1.cn)('FieldInput');
13
13
  exports.FieldInput = (0, polymorphicComponentWithRef_1.polymorphicComponentWithRef)(function (_a, ref) {
14
14
  var _b = _a.as, Tag = _b === void 0 ? exports.FIELD_INPUT_DEFAULT_TAG : _b, className = _a.className, requiredProp = _a.required, disabledProp = _a.disabled, valueProp = _a.value, onChange = _a.onChange, defaultValue = _a.defaultValue, children = _a.children, onFocus = _a.onFocus, onBlur = _a.onBlur, other = tslib_1.__rest(_a, ["as", "className", "required", "disabled", "value", "onChange", "defaultValue", "children", "onFocus", "onBlur"]);
15
15
  var _c = tslib_1.__read((0, react_1.useState)(), 2), focused = _c[0], setFocused = _c[1];
16
- var context = (0, react_1.useContext)(FieldControl_1.FieldControlContext);
16
+ var context = (0, FieldControl_1.useFieldControl)();
17
17
  var _d = tslib_1.__read(context, 2), fieldControl = _d[0], setFieldControl = _d[1];
18
18
  var _e = tslib_1.__read((0, useControlled_1.useControlled)({
19
19
  value: valueProp,
@@ -11,7 +11,7 @@ exports.FIELD_LABEL_DEFAULT_TAG = 'span';
11
11
  exports.cnFieldLabel = (0, classname_1.cn)('FieldLabel');
12
12
  exports.FieldLabel = (0, react_1.forwardRef)(function (_a, ref) {
13
13
  var focusedProp = _a.focused, children = _a.children, filledProp = _a.filled, shrink = _a.shrink, requiredProp = _a.required, disabledProp = _a.disabled, className = _a.className, sizeProp = _a.size;
14
- var context = (0, react_1.useContext)(FieldControl_1.FieldControlContext);
14
+ var context = (0, FieldControl_1.useFieldControl)();
15
15
  var _b = tslib_1.__read(context, 2), fieldControl = _b[0], setFieldControl = _b[1];
16
16
  var Tag = exports.FIELD_LABEL_DEFAULT_TAG;
17
17
  var size = sizeProp;
@@ -2,12 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SelectInputConsumer = void 0;
4
4
  var tslib_1 = require("tslib");
5
- var react_1 = tslib_1.__importStar(require("react"));
5
+ var react_1 = tslib_1.__importDefault(require("react"));
6
6
  var FieldControl_1 = require("../../../FieldControl");
7
7
  var index_1 = require("../../index");
8
8
  var SelectInputConsumer = function (_a) {
9
9
  var id = _a.id, name = _a.name, _b = _a.value, valueProp = _b === void 0 ? '' : _b, placeholderProp = _a.placeholder, defaultValue = _a.defaultValue, inputProps = _a.inputProps, inputRef = _a.inputRef, fieldRef = _a.fieldRef, fieldProps = _a.fieldProps, renderedValue = _a.renderedValue;
10
- var context = (0, react_1.useContext)(FieldControl_1.FieldControlContext);
10
+ var context = (0, FieldControl_1.useFieldControl)();
11
11
  var _c = tslib_1.__read(context, 1), fieldControl = _c[0];
12
12
  var disabled = fieldControl.disabled, required = fieldControl.required, filled = fieldControl.filled, focused = fieldControl.focused, label = fieldControl.label;
13
13
  var hasLabel = !!label;
@@ -14,7 +14,7 @@ var index_1 = require("./index");
14
14
  var TextareaConsumer = function (_a) {
15
15
  var labelProps = _a.labelProps, labelRef = _a.labelRef, maxLength = _a.maxLength, label = _a.label, id = _a.id, name = _a.name, cols = _a.cols, rows = _a.rows, disabled = _a.disabled, valueProp = _a.value, required = _a.required, defaultValue = _a.defaultValue, placeholder = _a.placeholder, autoFocus = _a.autoFocus, textareaProps = _a.textareaProps, onChange = _a.onChange, textareaRef = _a.textareaRef, expand = _a.expand, hint = _a.hint;
16
16
  var fieldRef = (0, react_1.useRef)(null);
17
- var context = (0, react_1.useContext)(FieldControl_1.FieldControlContext);
17
+ var context = (0, FieldControl_1.useFieldControl)();
18
18
  var _b = tslib_1.__read(context, 1), value = _b[0].value;
19
19
  // autoSize
20
20
  (0, react_1.useEffect)(function () {
@@ -2,13 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TextareaCounter = void 0;
4
4
  var tslib_1 = require("tslib");
5
- var react_1 = tslib_1.__importStar(require("react"));
5
+ var react_1 = tslib_1.__importDefault(require("react"));
6
6
  var FieldControl_1 = require("../../FieldControl");
7
7
  var index_1 = require("../index");
8
8
  var TextareaCounter = function (_a) {
9
9
  var _b, _c, _d;
10
10
  var maxLength = _a.maxLength, disabledProp = _a.disabled;
11
- var context = (0, react_1.useContext)(FieldControl_1.FieldControlContext);
11
+ var context = (0, FieldControl_1.useFieldControl)();
12
12
  var _e = tslib_1.__read(context, 1), fieldControl = _e[0];
13
13
  var disabled = disabledProp;
14
14
  // maxLength
@@ -64,8 +64,8 @@
64
64
  --color-background-action-secondary-pressed: #aeb1c4;
65
65
  --color-background-action-secondary-active-disabled: #636574;
66
66
  --color-background-action-secondary-light: #2c2c33;
67
- --color-background-action-secondary-light-hover: #636574;
68
- --color-background-action-secondary-light-pressed: #474853;
67
+ --color-background-action-secondary-light-hover: #474853;
68
+ --color-background-action-secondary-light-pressed: #636574;
69
69
  --color-background-accent-action-secondary-light: #2c2c33;
70
70
  --color-background-accent-action-secondary-light-hover: #474853;
71
71
  --color-background-accent-action-secondary-light-pressed: #636574;
@@ -118,10 +118,10 @@
118
118
  --color-border-secondary-pressed: #636574;
119
119
  --color-border-disabled: #2c2c33;
120
120
  --color-border-ghost-disabled: rgb(255 255 255 / 40%);
121
- --color-border-focused: #0e290f;
122
- --color-border-action: #067607;
123
- --color-border-action-hover: #0a540b;
124
- --color-border-action-pressed: #0d310e;
121
+ --color-border-focused: #0d310e;
122
+ --color-border-action: #039904;
123
+ --color-border-action-hover: #067607;
124
+ --color-border-action-pressed: #0a540b;
125
125
  --color-border-action-secondary: #d7d8e1;
126
126
  --color-border-action-secondary-hover: #c2c5d3;
127
127
  --color-border-action-secondary-pressed: #aeb1c4;
@@ -132,7 +132,7 @@
132
132
  --color-border-main-on: #fff;
133
133
  --color-border-accent-main: #989aa5;
134
134
  --color-border-accent-disabled: #5f6374;
135
- --color-border-accent-focused: #0e290f;
135
+ --color-border-accent-focused: #0d310e;
136
136
  --color-accent-main-hover: #1b1c24;
137
137
  --color-accent-main-pressed: #252732;
138
138
  --color-accent-primary-hover: #252732;
@@ -0,0 +1 @@
1
+ export * from './useHover';
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./useHover"), exports);
@@ -0,0 +1,14 @@
1
+ import type { RefObject } from 'react';
2
+ export type UseHoverOptions = {
3
+ /** Функция обратного вызова на событие перехода курсора на целевой элемент */
4
+ onEnter?: (e: PointerEvent) => void;
5
+ /** Функция обратного вызова на событие покидания курсора с целевого элемента */
6
+ onLeave?: (e: PointerEvent) => void;
7
+ /** Признак активности обработчика события, используется для повышения производительности. */
8
+ active?: boolean;
9
+ };
10
+ export declare function useHover<T extends HTMLElement = HTMLElement>(
11
+ /** Ссылка на элемент к которому будет привязано событие */
12
+ elRef: RefObject<T>,
13
+ /** Дополнительные опции */
14
+ options?: UseHoverOptions): boolean;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useHover = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var useBoolean_1 = require("../useBoolean");
6
+ var useEventListener_1 = require("../useEventListener");
7
+ function useHover(
8
+ /** Ссылка на элемент к которому будет привязано событие */
9
+ elRef,
10
+ /** Дополнительные опции */
11
+ options) {
12
+ if (options === void 0) { options = { active: true }; }
13
+ var onLeave = options.onLeave, onEnter = options.onEnter, active = options.active;
14
+ var _a = tslib_1.__read((0, useBoolean_1.useBoolean)(false), 2), value = _a[0], _b = _a[1], on = _b.on, off = _b.off;
15
+ var handleEnter = function (e) {
16
+ on();
17
+ onEnter === null || onEnter === void 0 ? void 0 : onEnter(e);
18
+ };
19
+ var handleLeave = function (e) {
20
+ off();
21
+ onLeave === null || onLeave === void 0 ? void 0 : onLeave(e);
22
+ };
23
+ (0, useEventListener_1.useEventListener)({
24
+ handler: handleEnter,
25
+ element: elRef,
26
+ eventName: 'pointerenter',
27
+ active: active,
28
+ });
29
+ (0, useEventListener_1.useEventListener)({
30
+ handler: handleLeave,
31
+ element: elRef,
32
+ eventName: 'pointerleave',
33
+ active: active,
34
+ });
35
+ return value;
36
+ }
37
+ exports.useHover = useHover;
@@ -78,7 +78,7 @@ var DataListRender = function (inProps, ref) {
78
78
  var _a, _b;
79
79
  var current = focused || selected || '';
80
80
  var idx = nodes.get(current);
81
- if (idx) {
81
+ if (idx !== undefined) {
82
82
  setSelectedElRef({
83
83
  current: (_b = (_a = listRef.current) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b[idx],
84
84
  });
@@ -1,6 +1,8 @@
1
1
  import { __assign, __read, __rest } from "tslib";
2
2
  import './FieldControl.css';
3
- import React, { useState } from 'react';
3
+ import React, { useRef, useState } from 'react';
4
+ import { useHover } from '../../hooks/useHover';
5
+ import { useMultiRef } from '../../hooks/useMultiRef';
4
6
  import { useThemeProps } from '../../hooks/useThemeProps';
5
7
  import { cn } from '../../utils/classname';
6
8
  import { polymorphicComponentWithRef, } from '../../utils/polymorphicComponentWithRef';
@@ -12,6 +14,8 @@ export var FieldControl = polymorphicComponentWithRef(function (inProps, ref) {
12
14
  props: inProps,
13
15
  name: 'FieldControl',
14
16
  });
17
+ var innerRef = useRef(null);
18
+ var hovered = useHover(innerRef);
15
19
  var _a = props.as, Tag = _a === void 0 ? FIELD_CONTROL_DEFAULT_TAG : _a, sizeProp = props.size, disabledProp = props.disabled, requiredProp = props.required, errorProp = props.error, fullWidthProp = props.fullWidth, filledProp = props.filled, focusedProp = props.focused, children = props.children, className = props.className, otherProp = __rest(props, ["as", "size", "disabled", "required", "error", "fullWidth", "filled", "focused", "children", "className"]);
16
20
  var focused = focusedProp;
17
21
  var filled = filledProp;
@@ -61,7 +65,7 @@ export var FieldControl = polymorphicComponentWithRef(function (inProps, ref) {
61
65
  filled: filled,
62
66
  focused: focused,
63
67
  hasLabel: !!label,
64
- }, [className]) }, otherProp, { ref: ref }),
68
+ }, [className]) }, otherProp, { ref: useMultiRef([ref, innerRef]) }),
65
69
  React.createElement(FieldControlContext.Provider, { value: [
66
70
  {
67
71
  error: error,
@@ -72,6 +76,7 @@ export var FieldControl = polymorphicComponentWithRef(function (inProps, ref) {
72
76
  size: size,
73
77
  filled: filled,
74
78
  focused: focused,
79
+ hovered: hovered,
75
80
  value: value,
76
81
  },
77
82
  setState,
@@ -9,7 +9,9 @@ export type FieldControlContextValue = {
9
9
  fullWidth?: boolean;
10
10
  filled?: boolean;
11
11
  focused?: boolean;
12
+ hovered?: boolean;
12
13
  label?: string;
13
14
  value?: string | number;
14
15
  };
15
16
  export declare const FieldControlContext: React.Context<[FieldControlContextValue, Dispatch<SetStateAction<FieldControlContextValue>>]>;
17
+ export declare const useFieldControl: () => [FieldControlContextValue, Dispatch<SetStateAction<FieldControlContextValue>>];
@@ -1,2 +1,3 @@
1
- import React from 'react';
1
+ import React, { useContext } from 'react';
2
2
  export var FieldControlContext = React.createContext([{}, function () { return undefined; }]);
3
+ export var useFieldControl = function () { return useContext(FieldControlContext); };
@@ -1,13 +1,13 @@
1
1
  import { __assign, __read, __rest } from "tslib";
2
2
  import './FieldHint.css';
3
- import React, { forwardRef, useContext, Children } from 'react';
3
+ import React, { forwardRef, Children } from 'react';
4
4
  import { cn } from '../../utils/classname';
5
- import { FieldControlContext } from '../FieldControl';
5
+ import { useFieldControl } from '../FieldControl';
6
6
  export var FIELD_HINT_DEFAULT_TAG = 'div';
7
7
  export var cnFieldHint = cn('FieldHint');
8
8
  export var FieldHint = forwardRef(function (_a, ref) {
9
9
  var children = _a.children, errorProp = _a.error, disabledProp = _a.disabled, sizeProp = _a.size, className = _a.className, other = __rest(_a, ["children", "error", "disabled", "size", "className"]);
10
- var context = useContext(FieldControlContext);
10
+ var context = useFieldControl();
11
11
  var _b = __read(context, 1), fieldControl = _b[0];
12
12
  var Tag = FIELD_HINT_DEFAULT_TAG;
13
13
  var size = sizeProp;
@@ -1,15 +1,15 @@
1
1
  import { __assign, __read, __rest } from "tslib";
2
2
  import './FieldIcon.css';
3
- import React, { forwardRef, useContext } from 'react';
3
+ import React, { forwardRef } from 'react';
4
4
  import { cn } from '../../utils/classname';
5
5
  import { getIconSizeToFormElement } from '../../utils/getIconSizeToFormElement';
6
6
  import { renderContent } from '../../utils/renderContent';
7
- import { FieldControlContext } from '../FieldControl';
7
+ import { useFieldControl } from '../FieldControl';
8
8
  export var FIELD_ICON_DEFAULT_TAG = 'div';
9
9
  export var cnFieldIcon = cn('FieldIcon');
10
10
  export var FieldIcon = forwardRef(function (_a, ref) {
11
11
  var icon = _a.icon, className = _a.className, sizeProp = _a.size, other = __rest(_a, ["icon", "className", "size"]);
12
- var context = useContext(FieldControlContext);
12
+ var context = useFieldControl();
13
13
  var _b = __read(context, 1), fieldControl = _b[0];
14
14
  var Tag = FIELD_ICON_DEFAULT_TAG;
15
15
  var size = sizeProp;
@@ -1,16 +1,16 @@
1
1
  import { __assign, __read, __rest } from "tslib";
2
- import React, { useCallback, useContext, useState } from 'react';
2
+ import React, { useCallback, useState } from 'react';
3
3
  import { useControlled } from '../../hooks/useControlled';
4
4
  import { useIsomorphicEffect } from '../../hooks/useIsomorphicEffect';
5
5
  import { cn } from '../../utils/classname';
6
6
  import { polymorphicComponentWithRef } from '../../utils/polymorphicComponentWithRef';
7
- import { FieldControlContext } from '../FieldControl';
7
+ import { useFieldControl } from '../FieldControl';
8
8
  export var FIELD_INPUT_DEFAULT_TAG = 'input';
9
9
  export var cnFieldInput = cn('FieldInput');
10
10
  export var FieldInput = polymorphicComponentWithRef(function (_a, ref) {
11
11
  var _b = _a.as, Tag = _b === void 0 ? FIELD_INPUT_DEFAULT_TAG : _b, className = _a.className, requiredProp = _a.required, disabledProp = _a.disabled, valueProp = _a.value, onChange = _a.onChange, defaultValue = _a.defaultValue, children = _a.children, onFocus = _a.onFocus, onBlur = _a.onBlur, other = __rest(_a, ["as", "className", "required", "disabled", "value", "onChange", "defaultValue", "children", "onFocus", "onBlur"]);
12
12
  var _c = __read(useState(), 2), focused = _c[0], setFocused = _c[1];
13
- var context = useContext(FieldControlContext);
13
+ var context = useFieldControl();
14
14
  var _d = __read(context, 2), fieldControl = _d[0], setFieldControl = _d[1];
15
15
  var _e = __read(useControlled({
16
16
  value: valueProp,
@@ -1,14 +1,14 @@
1
1
  import { __assign, __read } from "tslib";
2
2
  import './FieldLabel.css';
3
- import React, { forwardRef, useContext } from 'react';
3
+ import React, { forwardRef } from 'react';
4
4
  import { useIsomorphicEffect } from '../../hooks/useIsomorphicEffect';
5
5
  import { cn } from '../../utils/classname';
6
- import { FieldControlContext } from '../FieldControl';
6
+ import { useFieldControl } from '../FieldControl';
7
7
  export var FIELD_LABEL_DEFAULT_TAG = 'span';
8
8
  export var cnFieldLabel = cn('FieldLabel');
9
9
  export var FieldLabel = forwardRef(function (_a, ref) {
10
10
  var focusedProp = _a.focused, children = _a.children, filledProp = _a.filled, shrink = _a.shrink, requiredProp = _a.required, disabledProp = _a.disabled, className = _a.className, sizeProp = _a.size;
11
- var context = useContext(FieldControlContext);
11
+ var context = useFieldControl();
12
12
  var _b = __read(context, 2), fieldControl = _b[0], setFieldControl = _b[1];
13
13
  var Tag = FIELD_LABEL_DEFAULT_TAG;
14
14
  var size = sizeProp;
@@ -1,10 +1,10 @@
1
1
  import { __assign, __read } from "tslib";
2
- import React, { useContext } from 'react';
3
- import { FieldControlContext } from '../../../FieldControl';
2
+ import React from 'react';
3
+ import { useFieldControl } from '../../../FieldControl';
4
4
  import { cnSelect } from '../../index';
5
5
  export var SelectInputConsumer = function (_a) {
6
6
  var id = _a.id, name = _a.name, _b = _a.value, valueProp = _b === void 0 ? '' : _b, placeholderProp = _a.placeholder, defaultValue = _a.defaultValue, inputProps = _a.inputProps, inputRef = _a.inputRef, fieldRef = _a.fieldRef, fieldProps = _a.fieldProps, renderedValue = _a.renderedValue;
7
- var context = useContext(FieldControlContext);
7
+ var context = useFieldControl();
8
8
  var _c = __read(context, 1), fieldControl = _c[0];
9
9
  var disabled = fieldControl.disabled, required = fieldControl.required, filled = fieldControl.filled, focused = fieldControl.focused, label = fieldControl.label;
10
10
  var hasLabel = !!label;
@@ -1,7 +1,7 @@
1
1
  import { __assign, __read } from "tslib";
2
- import React, { useContext, useEffect, useRef } from 'react';
2
+ import React, { useEffect, useRef } from 'react';
3
3
  import { useMultiRef } from '../../../hooks/useMultiRef';
4
- import { FieldControlContext } from '../../FieldControl';
4
+ import { useFieldControl } from '../../FieldControl';
5
5
  import { FieldHint } from '../../FieldHint';
6
6
  import { FieldInput } from '../../FieldInput';
7
7
  import { FieldLabel } from '../../FieldLabel';
@@ -11,7 +11,7 @@ import { TextareaCounter } from './index';
11
11
  export var TextareaConsumer = function (_a) {
12
12
  var labelProps = _a.labelProps, labelRef = _a.labelRef, maxLength = _a.maxLength, label = _a.label, id = _a.id, name = _a.name, cols = _a.cols, rows = _a.rows, disabled = _a.disabled, valueProp = _a.value, required = _a.required, defaultValue = _a.defaultValue, placeholder = _a.placeholder, autoFocus = _a.autoFocus, textareaProps = _a.textareaProps, onChange = _a.onChange, textareaRef = _a.textareaRef, expand = _a.expand, hint = _a.hint;
13
13
  var fieldRef = useRef(null);
14
- var context = useContext(FieldControlContext);
14
+ var context = useFieldControl();
15
15
  var _b = __read(context, 1), value = _b[0].value;
16
16
  // autoSize
17
17
  useEffect(function () {
@@ -1,11 +1,11 @@
1
1
  import { __read } from "tslib";
2
- import React, { useContext } from 'react';
3
- import { FieldControlContext } from '../../FieldControl';
2
+ import React from 'react';
3
+ import { useFieldControl } from '../../FieldControl';
4
4
  import { cnTextarea } from '../index';
5
5
  export var TextareaCounter = function (_a) {
6
6
  var _b, _c, _d;
7
7
  var maxLength = _a.maxLength, disabledProp = _a.disabled;
8
- var context = useContext(FieldControlContext);
8
+ var context = useFieldControl();
9
9
  var _e = __read(context, 1), fieldControl = _e[0];
10
10
  var disabled = disabledProp;
11
11
  // maxLength
@@ -64,8 +64,8 @@
64
64
  --color-background-action-secondary-pressed: #aeb1c4;
65
65
  --color-background-action-secondary-active-disabled: #636574;
66
66
  --color-background-action-secondary-light: #2c2c33;
67
- --color-background-action-secondary-light-hover: #636574;
68
- --color-background-action-secondary-light-pressed: #474853;
67
+ --color-background-action-secondary-light-hover: #474853;
68
+ --color-background-action-secondary-light-pressed: #636574;
69
69
  --color-background-accent-action-secondary-light: #2c2c33;
70
70
  --color-background-accent-action-secondary-light-hover: #474853;
71
71
  --color-background-accent-action-secondary-light-pressed: #636574;
@@ -118,10 +118,10 @@
118
118
  --color-border-secondary-pressed: #636574;
119
119
  --color-border-disabled: #2c2c33;
120
120
  --color-border-ghost-disabled: rgb(255 255 255 / 40%);
121
- --color-border-focused: #0e290f;
122
- --color-border-action: #067607;
123
- --color-border-action-hover: #0a540b;
124
- --color-border-action-pressed: #0d310e;
121
+ --color-border-focused: #0d310e;
122
+ --color-border-action: #039904;
123
+ --color-border-action-hover: #067607;
124
+ --color-border-action-pressed: #0a540b;
125
125
  --color-border-action-secondary: #d7d8e1;
126
126
  --color-border-action-secondary-hover: #c2c5d3;
127
127
  --color-border-action-secondary-pressed: #aeb1c4;
@@ -132,7 +132,7 @@
132
132
  --color-border-main-on: #fff;
133
133
  --color-border-accent-main: #989aa5;
134
134
  --color-border-accent-disabled: #5f6374;
135
- --color-border-accent-focused: #0e290f;
135
+ --color-border-accent-focused: #0d310e;
136
136
  --color-accent-main-hover: #1b1c24;
137
137
  --color-accent-main-pressed: #252732;
138
138
  --color-accent-primary-hover: #252732;
@@ -0,0 +1 @@
1
+ export * from './useHover';
@@ -0,0 +1 @@
1
+ export * from './useHover';
@@ -0,0 +1,14 @@
1
+ import type { RefObject } from 'react';
2
+ export type UseHoverOptions = {
3
+ /** Функция обратного вызова на событие перехода курсора на целевой элемент */
4
+ onEnter?: (e: PointerEvent) => void;
5
+ /** Функция обратного вызова на событие покидания курсора с целевого элемента */
6
+ onLeave?: (e: PointerEvent) => void;
7
+ /** Признак активности обработчика события, используется для повышения производительности. */
8
+ active?: boolean;
9
+ };
10
+ export declare function useHover<T extends HTMLElement = HTMLElement>(
11
+ /** Ссылка на элемент к которому будет привязано событие */
12
+ elRef: RefObject<T>,
13
+ /** Дополнительные опции */
14
+ options?: UseHoverOptions): boolean;
@@ -0,0 +1,33 @@
1
+ import { __read } from "tslib";
2
+ import { useBoolean } from '../useBoolean';
3
+ import { useEventListener } from '../useEventListener';
4
+ export function useHover(
5
+ /** Ссылка на элемент к которому будет привязано событие */
6
+ elRef,
7
+ /** Дополнительные опции */
8
+ options) {
9
+ if (options === void 0) { options = { active: true }; }
10
+ var onLeave = options.onLeave, onEnter = options.onEnter, active = options.active;
11
+ var _a = __read(useBoolean(false), 2), value = _a[0], _b = _a[1], on = _b.on, off = _b.off;
12
+ var handleEnter = function (e) {
13
+ on();
14
+ onEnter === null || onEnter === void 0 ? void 0 : onEnter(e);
15
+ };
16
+ var handleLeave = function (e) {
17
+ off();
18
+ onLeave === null || onLeave === void 0 ? void 0 : onLeave(e);
19
+ };
20
+ useEventListener({
21
+ handler: handleEnter,
22
+ element: elRef,
23
+ eventName: 'pointerenter',
24
+ active: active,
25
+ });
26
+ useEventListener({
27
+ handler: handleLeave,
28
+ element: elRef,
29
+ eventName: 'pointerleave',
30
+ active: active,
31
+ });
32
+ return value;
33
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ozen-ui/kit",
3
- "version": "0.31.0",
3
+ "version": "0.32.1",
4
4
  "description": "React component library",
5
5
  "files": [
6
6
  "*"
@@ -0,0 +1,5 @@
1
+ {
2
+ "main": "../__inner__/cjs/hooks/useHover/index.js",
3
+ "module": "../__inner__/esm/hooks/useHover/index.js",
4
+ "types": "../__inner__/esm/hooks/useHover/index.d.ts"
5
+ }