@astral/ui 1.28.6 → 1.28.9
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.
- package/BackdropStack/hooks/useBackdropStackToggle/useBackdropStackToggle.d.ts +2 -2
- package/BackdropStack/services/BackdropStackManager/BackdropStackManager.d.ts +1 -2
- package/DatePicker/DatePicker.d.ts +4 -3
- package/DatePicker/DatePicker.js +4 -5
- package/DatePicker/DatePickerPopper/DatePickerPopper.d.ts +3 -2
- package/DatePicker/DatePickerPopper/DatePickerPopper.js +5 -1
- package/Fab/Fab.js +2 -2
- package/FormHelperText/FormHelperTextContent/styles.js +3 -0
- package/esm/BackdropStack/hooks/useBackdropStackToggle/useBackdropStackToggle.d.ts +2 -2
- package/esm/BackdropStack/hooks/useBackdropStackToggle/useBackdropStackToggle.js +1 -1
- package/esm/BackdropStack/services/BackdropStackManager/BackdropStackManager.d.ts +1 -2
- package/esm/DatePicker/DatePicker.d.ts +4 -3
- package/esm/DatePicker/DatePicker.js +2 -3
- package/esm/DatePicker/DatePickerPopper/DatePickerPopper.d.ts +3 -2
- package/esm/DatePicker/DatePickerPopper/DatePickerPopper.js +5 -1
- package/esm/Fab/Fab.js +2 -2
- package/esm/FormHelperText/FormHelperTextContent/styles.js +3 -0
- package/esm/hooks/index.d.ts +1 -0
- package/esm/hooks/index.js +1 -0
- package/esm/hooks/useEscapeClickEffect/useEscapeClickEffect.d.ts +3 -3
- package/esm/hooks/useEscapeClickEffect/useEscapeClickEffect.js +3 -3
- package/esm/hooks/useToggle/useToggle.d.ts +39 -9
- package/esm/hooks/useToggle/useToggle.js +7 -5
- package/esm/types.d.ts +2 -0
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +1 -0
- package/hooks/useEscapeClickEffect/useEscapeClickEffect.d.ts +3 -3
- package/hooks/useEscapeClickEffect/useEscapeClickEffect.js +3 -3
- package/hooks/useToggle/useToggle.d.ts +39 -9
- package/hooks/useToggle/useToggle.js +7 -5
- package/package.json +2 -2
- package/types.d.ts +2 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SyntheticEvent } from 'react';
|
|
2
|
-
import { Reason } from '
|
|
2
|
+
import { Reason } from '../../../types';
|
|
3
3
|
/**
|
|
4
4
|
* @description необязательные настройки для использоввания хука
|
|
5
5
|
*/
|
|
@@ -23,7 +23,7 @@ declare type ReturnElements = {
|
|
|
23
23
|
/**
|
|
24
24
|
* @description метод вызываемый при закрытии элемента, внутри него определяется состояние isOpened
|
|
25
25
|
*/
|
|
26
|
-
handleClose: (event
|
|
26
|
+
handleClose: (event?: SyntheticEvent<Element, Event> | Event | {}, reason?: Reason) => void;
|
|
27
27
|
};
|
|
28
28
|
declare type UseBackdropStackToggleFunc = (options?: Options) => ReturnElements;
|
|
29
29
|
/**
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Reason } from '../../../types';
|
|
2
2
|
declare type PopId = string;
|
|
3
|
-
export declare type Reason = 'escapeKeyDown' | 'backdropClick' | 'toggleInput' | 'blur' | AutocompleteCloseReason | null;
|
|
4
3
|
declare class BackdropStackManager {
|
|
5
4
|
private stack;
|
|
6
5
|
private previousPopInfo;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { FocusEvent } from 'react';
|
|
1
|
+
import { FocusEvent, SyntheticEvent } from 'react';
|
|
2
2
|
import { TextFieldProps } from '../TextField';
|
|
3
3
|
import { DateMask } from '../utils/date';
|
|
4
|
+
import { Reason } from '../types';
|
|
4
5
|
import { MinMaxDate } from './types';
|
|
5
6
|
import { MondayFirst } from './DayPicker';
|
|
6
7
|
export declare type DatePickerProps = MondayFirst & Partial<MinMaxDate> & {
|
|
@@ -8,7 +9,7 @@ export declare type DatePickerProps = MondayFirst & Partial<MinMaxDate> & {
|
|
|
8
9
|
onChange?: (date: Date | string | null | undefined) => void;
|
|
9
10
|
onBlur?: (e: FocusEvent<HTMLInputElement>) => void;
|
|
10
11
|
onOpen?: () => void;
|
|
11
|
-
onClose?: () => void;
|
|
12
|
+
onClose?: (event?: SyntheticEvent<Element, Event> | Event, reason?: Reason) => void;
|
|
12
13
|
inputProps?: Omit<TextFieldProps, 'ref' | 'value' | 'onChange'>;
|
|
13
14
|
disabled?: boolean;
|
|
14
15
|
value?: Date;
|
|
@@ -18,7 +19,7 @@ export declare const DatePicker: import("react").ForwardRefExoticComponent<Monda
|
|
|
18
19
|
onChange?: ((date: Date | string | null | undefined) => void) | undefined;
|
|
19
20
|
onBlur?: ((e: FocusEvent<HTMLInputElement>) => void) | undefined;
|
|
20
21
|
onOpen?: (() => void) | undefined;
|
|
21
|
-
onClose?: (() => void) | undefined;
|
|
22
|
+
onClose?: ((event?: SyntheticEvent<Element, Event> | Event, reason?: Reason) => void) | undefined;
|
|
22
23
|
inputProps?: Omit<TextFieldProps, "ref" | "value" | "onChange"> | undefined;
|
|
23
24
|
disabled?: boolean | undefined;
|
|
24
25
|
value?: Date | undefined;
|
package/DatePicker/DatePicker.js
CHANGED
|
@@ -14,8 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
exports.DatePicker = void 0;
|
|
15
15
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
16
16
|
const react_1 = require("react");
|
|
17
|
-
const
|
|
18
|
-
const useToggle_1 = require("../hooks/useToggle");
|
|
17
|
+
const hooks_1 = require("../hooks");
|
|
19
18
|
const date_1 = require("../utils/date");
|
|
20
19
|
const DatePickerClickAwayListener_1 = require("./DatePickerClickAwayListener");
|
|
21
20
|
const DatePickerInput_1 = require("./DatePickerInput");
|
|
@@ -26,8 +25,8 @@ const useBaseDateInRange_1 = require("./hooks/useBaseDateInRange");
|
|
|
26
25
|
const useSelectedBaseDate_1 = require("./hooks/useSelectedBaseDate");
|
|
27
26
|
const DatePickerInner = (0, react_1.forwardRef)(({ onChange, onOpen, onBlur, onClose, mask = 'DD.MM.YYYY', isMondayFirst, inputProps, disabled, value: parentValue, }, forwardedRef) => {
|
|
28
27
|
const { maxDate, minDate } = (0, react_1.useContext)(MinMaxDateContext_1.MinMaxDateContext);
|
|
29
|
-
const ref = (0,
|
|
30
|
-
const [isActive, openPopper, closePopper] = (0,
|
|
28
|
+
const ref = (0, hooks_1.useForwardedRef)(forwardedRef);
|
|
29
|
+
const [isActive, openPopper, closePopper] = (0, hooks_1.useToggle)({
|
|
31
30
|
onActive: onOpen,
|
|
32
31
|
onInactive: onClose,
|
|
33
32
|
});
|
|
@@ -49,7 +48,7 @@ const DatePickerInner = (0, react_1.forwardRef)(({ onChange, onOpen, onBlur, onC
|
|
|
49
48
|
const handleDayPick = (date) => {
|
|
50
49
|
setMaskedDate((0, date_1.formatDate)(date, mask));
|
|
51
50
|
setSelectedDate(date);
|
|
52
|
-
closePopper();
|
|
51
|
+
closePopper(undefined, 'selectOption');
|
|
53
52
|
};
|
|
54
53
|
(0, react_1.useEffect)(() => onChange === null || onChange === void 0 ? void 0 : onChange(selectedDate || maskedDate), [selectedDate, maskedDate]);
|
|
55
54
|
(0, react_1.useEffect)(() => checkValue(parentValue || ''), [parentValue]);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { PropsWithChildren } from 'react';
|
|
1
|
+
import { PropsWithChildren, SyntheticEvent } from 'react';
|
|
2
2
|
import { PopperProps } from '@mui/material';
|
|
3
|
+
import { Reason } from '../../types';
|
|
3
4
|
export declare type DatePickerProps = PropsWithChildren<Omit<PopperProps, 'children'>> & {
|
|
4
|
-
onClose?: () => void;
|
|
5
|
+
onClose?: (_?: SyntheticEvent<Element, Event> | Event, reason?: Reason) => void;
|
|
5
6
|
};
|
|
6
7
|
export declare const DatePickerPopper: ({ children, onClose, ...props }: DatePickerProps) => JSX.Element;
|
|
@@ -17,7 +17,11 @@ const useEscapeClickEffect_1 = require("../../hooks/useEscapeClickEffect");
|
|
|
17
17
|
const styles_1 = require("./styles");
|
|
18
18
|
const DatePickerPopper = (_a) => {
|
|
19
19
|
var { children, onClose } = _a, props = __rest(_a, ["children", "onClose"]);
|
|
20
|
-
(0, useEscapeClickEffect_1.useEscapeClickEffect)({
|
|
20
|
+
(0, useEscapeClickEffect_1.useEscapeClickEffect)({
|
|
21
|
+
onEscape: onClose,
|
|
22
|
+
isActive: props.open,
|
|
23
|
+
preventBubbling: true,
|
|
24
|
+
});
|
|
21
25
|
return ((0, jsx_runtime_1.jsx)(styles_1.PopperWrapper, Object.assign({}, props, { placement: "bottom-start", disablePortal: true, modifiers: [
|
|
22
26
|
{
|
|
23
27
|
name: 'offset',
|
package/Fab/Fab.js
CHANGED
|
@@ -16,7 +16,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
16
16
|
const react_1 = require("react");
|
|
17
17
|
const styles_1 = require("./styles");
|
|
18
18
|
const enums_1 = require("./enums");
|
|
19
|
-
exports.Fab = (0, react_1.forwardRef)((_a) => {
|
|
20
|
-
var {
|
|
19
|
+
exports.Fab = (0, react_1.forwardRef)((_a, ref) => {
|
|
20
|
+
var { variant = 'square', size = enums_1.FabSizes.Large, color = 'primary' } = _a, props = __rest(_a, ["variant", "size", "color"]);
|
|
21
21
|
return ((0, jsx_runtime_1.jsx)(styles_1.StyledFab, Object.assign({}, props, { variant: variant === 'square' ? 'circular' : variant, isSquare: variant === 'square', size: size, color: color, ref: ref })));
|
|
22
22
|
});
|
|
@@ -9,7 +9,10 @@ const getStyles = (theme) => {
|
|
|
9
9
|
font-size: ${theme.typography.h5.fontSize};
|
|
10
10
|
vertical-align: middle;`;
|
|
11
11
|
};
|
|
12
|
+
// flex необходим, для того, чтобы span не менял высоту полей и имел фиксированную высоту в 16px
|
|
12
13
|
exports.FormHelperTextWrapper = styles_1.styled.span `
|
|
14
|
+
display: flex;
|
|
15
|
+
|
|
13
16
|
color: ${({ success, error, theme }) => {
|
|
14
17
|
if (success) {
|
|
15
18
|
return theme.palette.success.dark;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SyntheticEvent } from 'react';
|
|
2
|
-
import { Reason } from '
|
|
2
|
+
import { Reason } from '../../../types';
|
|
3
3
|
/**
|
|
4
4
|
* @description необязательные настройки для использоввания хука
|
|
5
5
|
*/
|
|
@@ -23,7 +23,7 @@ declare type ReturnElements = {
|
|
|
23
23
|
/**
|
|
24
24
|
* @description метод вызываемый при закрытии элемента, внутри него определяется состояние isOpened
|
|
25
25
|
*/
|
|
26
|
-
handleClose: (event
|
|
26
|
+
handleClose: (event?: SyntheticEvent<Element, Event> | Event | {}, reason?: Reason) => void;
|
|
27
27
|
};
|
|
28
28
|
declare type UseBackdropStackToggleFunc = (options?: Options) => ReturnElements;
|
|
29
29
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from 'react';
|
|
2
|
-
import { backdropStackManager
|
|
2
|
+
import { backdropStackManager } from '../../services/BackdropStackManager';
|
|
3
3
|
/**
|
|
4
4
|
* @description хук предназначен для быстрого использования backdropStackManager в реакт компонентах, хранит неуправляемый стейт, если вам нужно управлять этим стейтом, воспользуйтесь backdropStackManager в своем компоненте напрямую.
|
|
5
5
|
*/
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Reason } from '../../../types';
|
|
2
2
|
declare type PopId = string;
|
|
3
|
-
export declare type Reason = 'escapeKeyDown' | 'backdropClick' | 'toggleInput' | 'blur' | AutocompleteCloseReason | null;
|
|
4
3
|
declare class BackdropStackManager {
|
|
5
4
|
private stack;
|
|
6
5
|
private previousPopInfo;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { FocusEvent } from 'react';
|
|
1
|
+
import { FocusEvent, SyntheticEvent } from 'react';
|
|
2
2
|
import { TextFieldProps } from '../TextField';
|
|
3
3
|
import { DateMask } from '../utils/date';
|
|
4
|
+
import { Reason } from '../types';
|
|
4
5
|
import { MinMaxDate } from './types';
|
|
5
6
|
import { MondayFirst } from './DayPicker';
|
|
6
7
|
export declare type DatePickerProps = MondayFirst & Partial<MinMaxDate> & {
|
|
@@ -8,7 +9,7 @@ export declare type DatePickerProps = MondayFirst & Partial<MinMaxDate> & {
|
|
|
8
9
|
onChange?: (date: Date | string | null | undefined) => void;
|
|
9
10
|
onBlur?: (e: FocusEvent<HTMLInputElement>) => void;
|
|
10
11
|
onOpen?: () => void;
|
|
11
|
-
onClose?: () => void;
|
|
12
|
+
onClose?: (event?: SyntheticEvent<Element, Event> | Event, reason?: Reason) => void;
|
|
12
13
|
inputProps?: Omit<TextFieldProps, 'ref' | 'value' | 'onChange'>;
|
|
13
14
|
disabled?: boolean;
|
|
14
15
|
value?: Date;
|
|
@@ -18,7 +19,7 @@ export declare const DatePicker: import("react").ForwardRefExoticComponent<Monda
|
|
|
18
19
|
onChange?: ((date: Date | string | null | undefined) => void) | undefined;
|
|
19
20
|
onBlur?: ((e: FocusEvent<HTMLInputElement>) => void) | undefined;
|
|
20
21
|
onOpen?: (() => void) | undefined;
|
|
21
|
-
onClose?: (() => void) | undefined;
|
|
22
|
+
onClose?: ((event?: SyntheticEvent<Element, Event> | Event, reason?: Reason) => void) | undefined;
|
|
22
23
|
inputProps?: Omit<TextFieldProps, "ref" | "value" | "onChange"> | undefined;
|
|
23
24
|
disabled?: boolean | undefined;
|
|
24
25
|
value?: Date | undefined;
|
|
@@ -11,8 +11,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
import { forwardRef, useCallback, useContext, useEffect, useState, } from 'react';
|
|
14
|
-
import { useForwardedRef } from '../hooks
|
|
15
|
-
import { useToggle } from '../hooks/useToggle';
|
|
14
|
+
import { useForwardedRef, useToggle } from '../hooks';
|
|
16
15
|
import { areDatesSame, formatDate, isDate, parseDate, } from '../utils/date';
|
|
17
16
|
import { DatePickerClickAwayListener } from './DatePickerClickAwayListener';
|
|
18
17
|
import { DatePickerInput } from './DatePickerInput';
|
|
@@ -46,7 +45,7 @@ const DatePickerInner = forwardRef(({ onChange, onOpen, onBlur, onClose, mask =
|
|
|
46
45
|
const handleDayPick = (date) => {
|
|
47
46
|
setMaskedDate(formatDate(date, mask));
|
|
48
47
|
setSelectedDate(date);
|
|
49
|
-
closePopper();
|
|
48
|
+
closePopper(undefined, 'selectOption');
|
|
50
49
|
};
|
|
51
50
|
useEffect(() => onChange === null || onChange === void 0 ? void 0 : onChange(selectedDate || maskedDate), [selectedDate, maskedDate]);
|
|
52
51
|
useEffect(() => checkValue(parentValue || ''), [parentValue]);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { PropsWithChildren } from 'react';
|
|
1
|
+
import { PropsWithChildren, SyntheticEvent } from 'react';
|
|
2
2
|
import { PopperProps } from '@mui/material';
|
|
3
|
+
import { Reason } from '../../types';
|
|
3
4
|
export declare type DatePickerProps = PropsWithChildren<Omit<PopperProps, 'children'>> & {
|
|
4
|
-
onClose?: () => void;
|
|
5
|
+
onClose?: (_?: SyntheticEvent<Element, Event> | Event, reason?: Reason) => void;
|
|
5
6
|
};
|
|
6
7
|
export declare const DatePickerPopper: ({ children, onClose, ...props }: DatePickerProps) => JSX.Element;
|
|
@@ -14,7 +14,11 @@ import { useEscapeClickEffect } from '../../hooks/useEscapeClickEffect';
|
|
|
14
14
|
import { DatePickerPopoverInner, PopperWrapper } from './styles';
|
|
15
15
|
export const DatePickerPopper = (_a) => {
|
|
16
16
|
var { children, onClose } = _a, props = __rest(_a, ["children", "onClose"]);
|
|
17
|
-
useEscapeClickEffect({
|
|
17
|
+
useEscapeClickEffect({
|
|
18
|
+
onEscape: onClose,
|
|
19
|
+
isActive: props.open,
|
|
20
|
+
preventBubbling: true,
|
|
21
|
+
});
|
|
18
22
|
return (_jsx(PopperWrapper, Object.assign({}, props, { placement: "bottom-start", disablePortal: true, modifiers: [
|
|
19
23
|
{
|
|
20
24
|
name: 'offset',
|
package/esm/Fab/Fab.js
CHANGED
|
@@ -13,7 +13,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
13
13
|
import { forwardRef } from 'react';
|
|
14
14
|
import { StyledFab } from './styles';
|
|
15
15
|
import { FabSizes } from './enums';
|
|
16
|
-
export const Fab = forwardRef((_a) => {
|
|
17
|
-
var {
|
|
16
|
+
export const Fab = forwardRef((_a, ref) => {
|
|
17
|
+
var { variant = 'square', size = FabSizes.Large, color = 'primary' } = _a, props = __rest(_a, ["variant", "size", "color"]);
|
|
18
18
|
return (_jsx(StyledFab, Object.assign({}, props, { variant: variant === 'square' ? 'circular' : variant, isSquare: variant === 'square', size: size, color: color, ref: ref })));
|
|
19
19
|
});
|
|
@@ -6,7 +6,10 @@ const getStyles = (theme) => {
|
|
|
6
6
|
font-size: ${theme.typography.h5.fontSize};
|
|
7
7
|
vertical-align: middle;`;
|
|
8
8
|
};
|
|
9
|
+
// flex необходим, для того, чтобы span не менял высоту полей и имел фиксированную высоту в 16px
|
|
9
10
|
export const FormHelperTextWrapper = styled.span `
|
|
11
|
+
display: flex;
|
|
12
|
+
|
|
10
13
|
color: ${({ success, error, theme }) => {
|
|
11
14
|
if (success) {
|
|
12
15
|
return theme.palette.success.dark;
|
package/esm/hooks/index.d.ts
CHANGED
package/esm/hooks/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { Reason } from '../../types';
|
|
2
|
+
export declare type UseEscapeClickEffectProps = {
|
|
2
3
|
/**
|
|
3
4
|
* @description колбэк который будет вызываться при нажатии на кнопку `esc`
|
|
4
5
|
*/
|
|
5
|
-
onEscape?: () => void;
|
|
6
|
+
onEscape?: (event: Event, reason: Reason) => void;
|
|
6
7
|
/**
|
|
7
8
|
* @description флаг активности
|
|
8
9
|
*/
|
|
@@ -16,4 +17,3 @@ declare type UseEscapeClickEffectProps = {
|
|
|
16
17
|
* @description хук клика по кнопке клавиатуры `esc`
|
|
17
18
|
*/
|
|
18
19
|
export declare const useEscapeClickEffect: ({ onEscape, isActive, preventBubbling, }: UseEscapeClickEffectProps) => void;
|
|
19
|
-
export {};
|
|
@@ -13,12 +13,12 @@ export const useEscapeClickEffect = ({ onEscape, isActive, preventBubbling, }) =
|
|
|
13
13
|
e.stopPropagation();
|
|
14
14
|
e.stopImmediatePropagation();
|
|
15
15
|
}
|
|
16
|
-
onEscape === null || onEscape === void 0 ? void 0 : onEscape();
|
|
16
|
+
onEscape === null || onEscape === void 0 ? void 0 : onEscape(e, 'escape');
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
|
-
window.addEventListener('keydown', onKeydown);
|
|
19
|
+
window.addEventListener('keydown', onKeydown, true);
|
|
20
20
|
return () => {
|
|
21
|
-
window.removeEventListener('keydown', onKeydown);
|
|
21
|
+
window.removeEventListener('keydown', onKeydown, true);
|
|
22
22
|
};
|
|
23
23
|
}, [isActive]);
|
|
24
24
|
};
|
|
@@ -1,13 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare type
|
|
1
|
+
/**
|
|
2
|
+
* @description тип обозначающий какой угодно рест аргументов
|
|
3
|
+
*/
|
|
4
|
+
declare type Arguments = unknown[];
|
|
5
|
+
/**
|
|
6
|
+
* @description хэндлер принимающий на вход неизвестное колличество аргументов, неизвестного вида
|
|
7
|
+
*/
|
|
8
|
+
declare type Handler<Args extends Arguments> = (...a: Args) => void;
|
|
9
|
+
/**
|
|
10
|
+
* @description хэндлер на открытие с неизвестным колличеством аргументов, неизвестного вида
|
|
11
|
+
*/
|
|
12
|
+
declare type OpenHandler<Args extends Arguments> = Handler<Args>;
|
|
13
|
+
/**
|
|
14
|
+
* @description хэндлер на закрытие с неизвестным колличеством аргументов, неизвестного вида
|
|
15
|
+
*/
|
|
16
|
+
declare type CloseHandler<Args extends Arguments> = Handler<Args>;
|
|
17
|
+
declare type UseToggleResultTuple<CloseArgs extends Arguments, OpenArgs extends Arguments> = [
|
|
18
|
+
/**
|
|
19
|
+
* @description флаг активности состояния
|
|
20
|
+
*/
|
|
21
|
+
boolean,
|
|
22
|
+
OpenHandler<OpenArgs>,
|
|
23
|
+
CloseHandler<CloseArgs>
|
|
24
|
+
];
|
|
25
|
+
declare type UseToggleOptions<CloseArgs extends Arguments, OpenArgs extends Arguments> = {
|
|
26
|
+
/**
|
|
27
|
+
* @description изначальное состояние активности
|
|
28
|
+
*/
|
|
5
29
|
initialState?: boolean;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
30
|
+
/**
|
|
31
|
+
* @description коллбэк на открытие
|
|
32
|
+
*/
|
|
33
|
+
onActive?: OpenHandler<OpenArgs>;
|
|
34
|
+
/**
|
|
35
|
+
* @description коллбэк на закрытие
|
|
36
|
+
*/
|
|
37
|
+
onInactive?: CloseHandler<CloseArgs>;
|
|
38
|
+
};
|
|
9
39
|
/**
|
|
10
|
-
* @description хук хранящий стейт активности, и предоставляющий методы
|
|
40
|
+
* @description хук хранящий стейт активности, и предоставляющий методы переключения c проксируемыми аргументами, позволяет уменьшить бойлерплейт код
|
|
11
41
|
*/
|
|
12
|
-
export declare const useToggle: (params
|
|
42
|
+
export declare const useToggle: <CloseArgs extends Arguments, OpenArgs extends Arguments>(params?: UseToggleOptions<CloseArgs, OpenArgs> | undefined) => UseToggleResultTuple<CloseArgs, OpenArgs>;
|
|
13
43
|
export {};
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
/**
|
|
3
|
-
* @description хук хранящий стейт активности, и предоставляющий методы
|
|
3
|
+
* @description хук хранящий стейт активности, и предоставляющий методы переключения c проксируемыми аргументами, позволяет уменьшить бойлерплейт код
|
|
4
4
|
*/
|
|
5
5
|
export const useToggle = (params) => {
|
|
6
6
|
const { initialState = false, onInactive, onActive } = params || {};
|
|
7
7
|
const [isActive, setActive] = useState(initialState);
|
|
8
|
-
|
|
8
|
+
// выставляем флаг активности в true, и проксируем все принятые аргументы
|
|
9
|
+
const handleActive = (...args) => {
|
|
9
10
|
setActive(true);
|
|
10
|
-
onActive === null || onActive === void 0 ? void 0 : onActive();
|
|
11
|
+
onActive === null || onActive === void 0 ? void 0 : onActive(...args);
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
+
// выставляем флаг активности в false, и проксируем все принятые аргументы
|
|
14
|
+
const handleInactive = (...args) => {
|
|
13
15
|
setActive(false);
|
|
14
|
-
onInactive === null || onInactive === void 0 ? void 0 : onInactive();
|
|
16
|
+
onInactive === null || onInactive === void 0 ? void 0 : onInactive(...args);
|
|
15
17
|
};
|
|
16
18
|
return [isActive, handleActive, handleInactive];
|
|
17
19
|
};
|
package/esm/types.d.ts
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
+
import { AutocompleteCloseReason } from '@mui/base/AutocompleteUnstyled/useAutocomplete';
|
|
1
2
|
export declare type WithoutEmotionSpecific<Props> = Omit<Props, 'sx' | 'css'>;
|
|
3
|
+
export declare type Reason = 'escapeKeyDown' | 'backdropClick' | 'toggleInput' | 'blur' | AutocompleteCloseReason | null;
|
package/hooks/index.d.ts
CHANGED
package/hooks/index.js
CHANGED
|
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./useLocalStorage"), exports);
|
|
18
18
|
__exportStar(require("./useMenu"), exports);
|
|
19
|
+
__exportStar(require("./useToggle"), exports);
|
|
19
20
|
__exportStar(require("./useForwardedRef"), exports);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { Reason } from '../../types';
|
|
2
|
+
export declare type UseEscapeClickEffectProps = {
|
|
2
3
|
/**
|
|
3
4
|
* @description колбэк который будет вызываться при нажатии на кнопку `esc`
|
|
4
5
|
*/
|
|
5
|
-
onEscape?: () => void;
|
|
6
|
+
onEscape?: (event: Event, reason: Reason) => void;
|
|
6
7
|
/**
|
|
7
8
|
* @description флаг активности
|
|
8
9
|
*/
|
|
@@ -16,4 +17,3 @@ declare type UseEscapeClickEffectProps = {
|
|
|
16
17
|
* @description хук клика по кнопке клавиатуры `esc`
|
|
17
18
|
*/
|
|
18
19
|
export declare const useEscapeClickEffect: ({ onEscape, isActive, preventBubbling, }: UseEscapeClickEffectProps) => void;
|
|
19
|
-
export {};
|
|
@@ -16,12 +16,12 @@ const useEscapeClickEffect = ({ onEscape, isActive, preventBubbling, }) => {
|
|
|
16
16
|
e.stopPropagation();
|
|
17
17
|
e.stopImmediatePropagation();
|
|
18
18
|
}
|
|
19
|
-
onEscape === null || onEscape === void 0 ? void 0 : onEscape();
|
|
19
|
+
onEscape === null || onEscape === void 0 ? void 0 : onEscape(e, 'escape');
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
|
-
window.addEventListener('keydown', onKeydown);
|
|
22
|
+
window.addEventListener('keydown', onKeydown, true);
|
|
23
23
|
return () => {
|
|
24
|
-
window.removeEventListener('keydown', onKeydown);
|
|
24
|
+
window.removeEventListener('keydown', onKeydown, true);
|
|
25
25
|
};
|
|
26
26
|
}, [isActive]);
|
|
27
27
|
};
|
|
@@ -1,13 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare type
|
|
1
|
+
/**
|
|
2
|
+
* @description тип обозначающий какой угодно рест аргументов
|
|
3
|
+
*/
|
|
4
|
+
declare type Arguments = unknown[];
|
|
5
|
+
/**
|
|
6
|
+
* @description хэндлер принимающий на вход неизвестное колличество аргументов, неизвестного вида
|
|
7
|
+
*/
|
|
8
|
+
declare type Handler<Args extends Arguments> = (...a: Args) => void;
|
|
9
|
+
/**
|
|
10
|
+
* @description хэндлер на открытие с неизвестным колличеством аргументов, неизвестного вида
|
|
11
|
+
*/
|
|
12
|
+
declare type OpenHandler<Args extends Arguments> = Handler<Args>;
|
|
13
|
+
/**
|
|
14
|
+
* @description хэндлер на закрытие с неизвестным колличеством аргументов, неизвестного вида
|
|
15
|
+
*/
|
|
16
|
+
declare type CloseHandler<Args extends Arguments> = Handler<Args>;
|
|
17
|
+
declare type UseToggleResultTuple<CloseArgs extends Arguments, OpenArgs extends Arguments> = [
|
|
18
|
+
/**
|
|
19
|
+
* @description флаг активности состояния
|
|
20
|
+
*/
|
|
21
|
+
boolean,
|
|
22
|
+
OpenHandler<OpenArgs>,
|
|
23
|
+
CloseHandler<CloseArgs>
|
|
24
|
+
];
|
|
25
|
+
declare type UseToggleOptions<CloseArgs extends Arguments, OpenArgs extends Arguments> = {
|
|
26
|
+
/**
|
|
27
|
+
* @description изначальное состояние активности
|
|
28
|
+
*/
|
|
5
29
|
initialState?: boolean;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
30
|
+
/**
|
|
31
|
+
* @description коллбэк на открытие
|
|
32
|
+
*/
|
|
33
|
+
onActive?: OpenHandler<OpenArgs>;
|
|
34
|
+
/**
|
|
35
|
+
* @description коллбэк на закрытие
|
|
36
|
+
*/
|
|
37
|
+
onInactive?: CloseHandler<CloseArgs>;
|
|
38
|
+
};
|
|
9
39
|
/**
|
|
10
|
-
* @description хук хранящий стейт активности, и предоставляющий методы
|
|
40
|
+
* @description хук хранящий стейт активности, и предоставляющий методы переключения c проксируемыми аргументами, позволяет уменьшить бойлерплейт код
|
|
11
41
|
*/
|
|
12
|
-
export declare const useToggle: (params
|
|
42
|
+
export declare const useToggle: <CloseArgs extends Arguments, OpenArgs extends Arguments>(params?: UseToggleOptions<CloseArgs, OpenArgs> | undefined) => UseToggleResultTuple<CloseArgs, OpenArgs>;
|
|
13
43
|
export {};
|
|
@@ -3,18 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useToggle = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
/**
|
|
6
|
-
* @description хук хранящий стейт активности, и предоставляющий методы
|
|
6
|
+
* @description хук хранящий стейт активности, и предоставляющий методы переключения c проксируемыми аргументами, позволяет уменьшить бойлерплейт код
|
|
7
7
|
*/
|
|
8
8
|
const useToggle = (params) => {
|
|
9
9
|
const { initialState = false, onInactive, onActive } = params || {};
|
|
10
10
|
const [isActive, setActive] = (0, react_1.useState)(initialState);
|
|
11
|
-
|
|
11
|
+
// выставляем флаг активности в true, и проксируем все принятые аргументы
|
|
12
|
+
const handleActive = (...args) => {
|
|
12
13
|
setActive(true);
|
|
13
|
-
onActive === null || onActive === void 0 ? void 0 : onActive();
|
|
14
|
+
onActive === null || onActive === void 0 ? void 0 : onActive(...args);
|
|
14
15
|
};
|
|
15
|
-
|
|
16
|
+
// выставляем флаг активности в false, и проксируем все принятые аргументы
|
|
17
|
+
const handleInactive = (...args) => {
|
|
16
18
|
setActive(false);
|
|
17
|
-
onInactive === null || onInactive === void 0 ? void 0 : onInactive();
|
|
19
|
+
onInactive === null || onInactive === void 0 ? void 0 : onInactive(...args);
|
|
18
20
|
};
|
|
19
21
|
return [isActive, handleActive, handleInactive];
|
|
20
22
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astral/ui",
|
|
3
|
-
"version": "1.28.
|
|
3
|
+
"version": "1.28.9",
|
|
4
4
|
"browser": "./esm/index.js",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@astral/icons": "^1.28.
|
|
7
|
+
"@astral/icons": "^1.28.9",
|
|
8
8
|
"@emotion/cache": "11.7.1",
|
|
9
9
|
"@emotion/react": "11.9.0",
|
|
10
10
|
"@emotion/server": "11.4.0",
|
package/types.d.ts
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
+
import { AutocompleteCloseReason } from '@mui/base/AutocompleteUnstyled/useAutocomplete';
|
|
1
2
|
export declare type WithoutEmotionSpecific<Props> = Omit<Props, 'sx' | 'css'>;
|
|
3
|
+
export declare type Reason = 'escapeKeyDown' | 'backdropClick' | 'toggleInput' | 'blur' | AutocompleteCloseReason | null;
|