@astral/ui 4.29.0 → 4.30.0
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/components/Filename/Filename.js +2 -2
- package/components/Filename/styles.d.ts +4 -0
- package/components/Filename/styles.js +4 -1
- package/hook-form/FormFilters/AllFiltersButton/AllFiltersButton.d.ts +2 -0
- package/hook-form/FormFilters/AllFiltersButton/AllFiltersButton.js +10 -0
- package/hook-form/FormFilters/AllFiltersButton/index.d.ts +1 -0
- package/hook-form/FormFilters/AllFiltersButton/index.js +1 -0
- package/hook-form/FormFilters/AllFiltersButton/styles.d.ts +19 -0
- package/hook-form/FormFilters/AllFiltersButton/styles.js +53 -0
- package/hook-form/FormFilters/AllFiltersButton/types.d.ts +8 -0
- package/hook-form/FormFilters/AllFiltersButton/types.js +1 -0
- package/hook-form/FormFilters/AllFiltersButton/useLogic/index.d.ts +1 -0
- package/hook-form/FormFilters/AllFiltersButton/useLogic/index.js +1 -0
- package/hook-form/FormFilters/AllFiltersButton/useLogic/useLogic.d.ts +6 -0
- package/hook-form/FormFilters/AllFiltersButton/useLogic/useLogic.js +33 -0
- package/hook-form/FormFilters/FormFilters.js +5 -6
- package/hook-form/FormFilters/FormFiltersDialog/useLogic/useLogic.d.ts +1 -1
- package/hook-form/FormFilters/FormFiltersDialog/useLogic/useLogic.js +4 -7
- package/hook-form/FormFilters/constants.d.ts +0 -1
- package/hook-form/FormFilters/constants.js +0 -1
- package/hook-form/FormFilters/styles.d.ts +0 -18
- package/hook-form/FormFilters/styles.js +0 -51
- package/hook-form/FormFilters/types.d.ts +7 -16
- package/hook-form/FormFilters/useLogic/useLogic.d.ts +5 -6
- package/hook-form/FormFilters/useLogic/useLogic.js +7 -95
- package/hook-form/FormFiltersSearchField/FormFiltersSearchField.js +1 -1
- package/node/components/Filename/Filename.js +1 -1
- package/node/components/Filename/styles.d.ts +4 -0
- package/node/components/Filename/styles.js +5 -2
- package/node/hook-form/FormFilters/AllFiltersButton/AllFiltersButton.d.ts +2 -0
- package/node/hook-form/FormFilters/AllFiltersButton/AllFiltersButton.js +14 -0
- package/node/hook-form/FormFilters/AllFiltersButton/index.d.ts +1 -0
- package/node/hook-form/FormFilters/AllFiltersButton/index.js +5 -0
- package/node/hook-form/FormFilters/AllFiltersButton/styles.d.ts +19 -0
- package/node/hook-form/FormFilters/AllFiltersButton/styles.js +56 -0
- package/node/hook-form/FormFilters/AllFiltersButton/types.d.ts +8 -0
- package/node/hook-form/FormFilters/AllFiltersButton/types.js +2 -0
- package/node/hook-form/FormFilters/AllFiltersButton/useLogic/index.d.ts +1 -0
- package/node/hook-form/FormFilters/AllFiltersButton/useLogic/index.js +17 -0
- package/node/hook-form/FormFilters/AllFiltersButton/useLogic/useLogic.d.ts +6 -0
- package/node/hook-form/FormFilters/AllFiltersButton/useLogic/useLogic.js +37 -0
- package/node/hook-form/FormFilters/FormFilters.js +3 -4
- package/node/hook-form/FormFilters/FormFiltersDialog/useLogic/useLogic.d.ts +1 -1
- package/node/hook-form/FormFilters/FormFiltersDialog/useLogic/useLogic.js +4 -7
- package/node/hook-form/FormFilters/constants.d.ts +0 -1
- package/node/hook-form/FormFilters/constants.js +0 -1
- package/node/hook-form/FormFilters/styles.d.ts +0 -18
- package/node/hook-form/FormFilters/styles.js +1 -52
- package/node/hook-form/FormFilters/types.d.ts +7 -16
- package/node/hook-form/FormFilters/useLogic/useLogic.d.ts +5 -6
- package/node/hook-form/FormFilters/useLogic/useLogic.js +6 -94
- package/node/hook-form/FormFiltersSearchField/FormFiltersSearchField.js +1 -1
- package/package.json +1 -1
|
@@ -3,6 +3,10 @@ export declare const FileBaseName: import("@emotion/styled/dist/declarations/src
|
|
|
3
3
|
theme?: import("@emotion/react").Theme | undefined;
|
|
4
4
|
as?: import("react").ElementType<any, keyof import("react").JSX.IntrinsicElements> | undefined;
|
|
5
5
|
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, {}>;
|
|
6
|
+
export declare const FileSuffix: import("@emotion/styled/dist/declarations/src/types").StyledComponent<{
|
|
7
|
+
theme?: import("@emotion/react").Theme | undefined;
|
|
8
|
+
as?: import("react").ElementType<any, keyof import("react").JSX.IntrinsicElements> | undefined;
|
|
9
|
+
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, {}>;
|
|
6
10
|
export declare const StyledTypography: import("@emotion/styled/dist/declarations/src/types").StyledComponent<import("../Typography/types").TypographyPropsBase & {
|
|
7
11
|
color?: import("../Typography").TypographyColor | undefined;
|
|
8
12
|
variant?: import("../Typography").TypographyVariant | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StyledTypography = exports.FileBaseName = void 0;
|
|
3
|
+
exports.StyledTypography = exports.FileSuffix = exports.FileBaseName = void 0;
|
|
4
4
|
const styled_1 = require("../styled");
|
|
5
5
|
const Typography_1 = require("../Typography");
|
|
6
6
|
exports.FileBaseName = styled_1.styled.span `
|
|
@@ -9,7 +9,10 @@ exports.FileBaseName = styled_1.styled.span `
|
|
|
9
9
|
max-width: 100%;
|
|
10
10
|
|
|
11
11
|
text-overflow: ellipsis;
|
|
12
|
-
white-space: nowrap;
|
|
12
|
+
white-space: preserve nowrap;
|
|
13
|
+
`;
|
|
14
|
+
exports.FileSuffix = styled_1.styled.span `
|
|
15
|
+
white-space: pre;
|
|
13
16
|
`;
|
|
14
17
|
exports.StyledTypography = (0, styled_1.styled)(Typography_1.Typography, {
|
|
15
18
|
shouldForwardProp: (prop) => !['$align'].includes(prop),
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AllFiltersButton = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const Button_1 = require("../../../components/Button");
|
|
6
|
+
const Filter2OutlineMd_1 = require("../../../icons/Filter2OutlineMd");
|
|
7
|
+
const constants_1 = require("../constants");
|
|
8
|
+
const styles_1 = require("./styles");
|
|
9
|
+
const useLogic_1 = require("./useLogic");
|
|
10
|
+
const AllFiltersButton = (props) => {
|
|
11
|
+
const { allFiltersButtonClassName, counter, onOpenModal } = (0, useLogic_1.useLogic)(props);
|
|
12
|
+
return ((0, jsx_runtime_1.jsx)(styles_1.AllFiltersButtonWrapper, { className: allFiltersButtonClassName, children: (0, jsx_runtime_1.jsx)(styles_1.StyledBadge, { color: "error", badgeContent: counter, variant: "dot", children: (0, jsx_runtime_1.jsx)(Button_1.Button, { onClick: onOpenModal, variant: "outlined", color: "grey", startIcon: (0, jsx_runtime_1.jsx)(Filter2OutlineMd_1.Filter2OutlineMd, {}), endIcon: counter ? (0, jsx_runtime_1.jsx)(styles_1.StyledCounter, { color: "error", content: counter }) : null, className: constants_1.formFiltersClassnames.allFiltersButton, children: "\u0412\u0441\u0435 \u0444\u0438\u043B\u044C\u0442\u0440\u044B" }) }) }));
|
|
13
|
+
};
|
|
14
|
+
exports.AllFiltersButton = AllFiltersButton;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AllFiltersButton } from './AllFiltersButton';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AllFiltersButton = void 0;
|
|
4
|
+
var AllFiltersButton_1 = require("./AllFiltersButton");
|
|
5
|
+
Object.defineProperty(exports, "AllFiltersButton", { enumerable: true, get: function () { return AllFiltersButton_1.AllFiltersButton; } });
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const AllFiltersButtonWrapper: import("@emotion/styled/dist/declarations/src/types").StyledComponent<{
|
|
3
|
+
theme?: import("@emotion/react").Theme | undefined;
|
|
4
|
+
as?: import("react").ElementType<any, keyof import("react").JSX.IntrinsicElements> | undefined;
|
|
5
|
+
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
6
|
+
export declare const StyledBadge: import("@emotion/styled/dist/declarations/src/types").StyledComponent<Omit<import("../../..").WithoutEmotionSpecific<import("@mui/material/Badge").BadgeProps>, "color"> & {
|
|
7
|
+
color: import("../../../components/Badge").BadgeColor;
|
|
8
|
+
withBorder?: boolean | undefined;
|
|
9
|
+
variantColor?: import("../../../components/Badge").BadgeVariantsColor | undefined;
|
|
10
|
+
} & {
|
|
11
|
+
theme?: import("@emotion/react").Theme | undefined;
|
|
12
|
+
}, {}, {}>;
|
|
13
|
+
export declare const StyledCounter: import("@emotion/styled/dist/declarations/src/types").StyledComponent<Omit<import("../../..").WithoutEmotionSpecific<import("@mui/material/Badge").BadgeProps>, "content" | "color" | "children" | "variant" | "invisible" | "anchorOrigin" | "badgeContent" | "overlap" | "withBorder"> & {
|
|
14
|
+
color: import("../../../components/Counter/types").CounterColor;
|
|
15
|
+
variant?: import("../../../components/Counter/types").CounterVariants | undefined;
|
|
16
|
+
content?: number | undefined;
|
|
17
|
+
} & {
|
|
18
|
+
theme?: import("@emotion/react").Theme | undefined;
|
|
19
|
+
}, {}, {}>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StyledCounter = exports.StyledBadge = exports.AllFiltersButtonWrapper = void 0;
|
|
4
|
+
const Badge_1 = require("@mui/material/Badge");
|
|
5
|
+
const Badge_2 = require("../../../components/Badge");
|
|
6
|
+
const Counter_1 = require("../../../components/Counter");
|
|
7
|
+
const styled_1 = require("../../../components/styled");
|
|
8
|
+
const constants_1 = require("../constants");
|
|
9
|
+
exports.AllFiltersButtonWrapper = styled_1.styled.div `
|
|
10
|
+
display: none;
|
|
11
|
+
|
|
12
|
+
white-space: nowrap;
|
|
13
|
+
|
|
14
|
+
&.${constants_1.formFiltersClassnames.showAllFiltersButtonOnDesktop} {
|
|
15
|
+
display: flex;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
${({ theme }) => theme.breakpoints.down('sm')} {
|
|
19
|
+
margin-right: 0;
|
|
20
|
+
&.${constants_1.formFiltersClassnames.showAllFiltersButtonOnMobile} {
|
|
21
|
+
display: flex;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
&.${constants_1.formFiltersClassnames.withoutSearch} {
|
|
25
|
+
width: 100%;
|
|
26
|
+
|
|
27
|
+
.${constants_1.formFiltersClassnames.allFiltersButton} {
|
|
28
|
+
width: 100%;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
&.${constants_1.formFiltersClassnames.withSearch} {
|
|
33
|
+
.${constants_1.formFiltersClassnames.allFiltersButton} {
|
|
34
|
+
display: unset;
|
|
35
|
+
gap: 0;
|
|
36
|
+
|
|
37
|
+
padding: 8px;
|
|
38
|
+
|
|
39
|
+
font-size: 0;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
44
|
+
exports.StyledBadge = (0, styled_1.styled)(Badge_2.Badge) `
|
|
45
|
+
width: 100%;
|
|
46
|
+
.${Badge_1.badgeClasses.dot} {
|
|
47
|
+
${({ theme }) => theme.breakpoints.up('sm')} {
|
|
48
|
+
display: none;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
52
|
+
exports.StyledCounter = (0, styled_1.styled)(Counter_1.Counter) `
|
|
53
|
+
${({ theme }) => theme.breakpoints.down('sm')} {
|
|
54
|
+
display: none;
|
|
55
|
+
}
|
|
56
|
+
`;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type UseFormReturn } from 'react-hook-form';
|
|
2
|
+
export type AllFiltersButtonProps<TFieldValues extends Record<string, unknown>> = {
|
|
3
|
+
form: UseFormReturn<TFieldValues>;
|
|
4
|
+
onOpenModal: () => void;
|
|
5
|
+
hasMainFilters: boolean;
|
|
6
|
+
hasSecondaryFilters: boolean;
|
|
7
|
+
hasSearch: boolean;
|
|
8
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useLogic';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./useLogic"), exports);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type AllFiltersButtonProps } from '../types';
|
|
2
|
+
export declare const useLogic: <TFieldValues extends Record<string, unknown>>({ form, onOpenModal, hasMainFilters, hasSecondaryFilters, hasSearch, }: AllFiltersButtonProps<TFieldValues>) => {
|
|
3
|
+
allFiltersButtonClassName: string;
|
|
4
|
+
counter: number;
|
|
5
|
+
onOpenModal: () => void;
|
|
6
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useLogic = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
6
|
+
const classNames_1 = require("../../../../components/utils/classNames");
|
|
7
|
+
const constants_1 = require("../../../FormFiltersSearchField/constants");
|
|
8
|
+
const constants_2 = require("../../constants");
|
|
9
|
+
const useLogic = ({ form, onOpenModal, hasMainFilters, hasSecondaryFilters, hasSearch, }) => {
|
|
10
|
+
const formValues = (0, react_hook_form_1.useWatch)({
|
|
11
|
+
control: form.control,
|
|
12
|
+
});
|
|
13
|
+
const [searchName, setSearchName] = (0, react_1.useState)('');
|
|
14
|
+
(0, react_1.useEffect)(() => {
|
|
15
|
+
const searchFieldName = document
|
|
16
|
+
.getElementById(constants_1.FORM_FILTERS_SEARCH_FIELD_ID)
|
|
17
|
+
?.getAttribute('name') || '';
|
|
18
|
+
setSearchName(searchFieldName);
|
|
19
|
+
}, [hasSearch]);
|
|
20
|
+
// Исключаем поиск из счетчика фильтров
|
|
21
|
+
const counter = Object.values(formValues || {}).filter(Boolean).length -
|
|
22
|
+
(formValues?.[searchName] ? 1 : 0);
|
|
23
|
+
const allFiltersButtonClassName = (0, react_1.useMemo)(() => {
|
|
24
|
+
return (0, classNames_1.classNames)({
|
|
25
|
+
[constants_2.formFiltersClassnames.showAllFiltersButtonOnDesktop]: hasSecondaryFilters,
|
|
26
|
+
[constants_2.formFiltersClassnames.showAllFiltersButtonOnMobile]: hasMainFilters || hasSecondaryFilters,
|
|
27
|
+
[constants_2.formFiltersClassnames.withSearch]: hasSearch,
|
|
28
|
+
[constants_2.formFiltersClassnames.withoutSearch]: !hasSearch,
|
|
29
|
+
});
|
|
30
|
+
}, [hasMainFilters, hasSecondaryFilters, hasSearch]);
|
|
31
|
+
return {
|
|
32
|
+
allFiltersButtonClassName,
|
|
33
|
+
counter,
|
|
34
|
+
onOpenModal,
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
exports.useLogic = useLogic;
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FormFilters = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
const Button_1 = require("../../components/Button");
|
|
6
|
-
const Filter2OutlineMd_1 = require("../../icons/Filter2OutlineMd");
|
|
7
5
|
const Form_1 = require("../Form");
|
|
8
6
|
const FormControlProvider_1 = require("../FormControlProvider");
|
|
7
|
+
const AllFiltersButton_1 = require("./AllFiltersButton");
|
|
9
8
|
const constants_1 = require("./constants");
|
|
10
9
|
const FormFiltersDialog_1 = require("./FormFiltersDialog");
|
|
11
10
|
const FormFiltersSkeleton_1 = require("./FormFiltersSkeleton");
|
|
@@ -15,10 +14,10 @@ const useLogic_1 = require("./useLogic");
|
|
|
15
14
|
* Компонент для отображения фильтров формы
|
|
16
15
|
*/
|
|
17
16
|
const FormFilters = (props) => {
|
|
18
|
-
const {
|
|
17
|
+
const { form, onSubmit, searchField: SearchField, mainFilters: MainFilters, submitButton: SubmitButton, secondaryFilters: SecondaryFilters, onOpenModal, dialogProps, mainFiltersColumns, isLoading, } = (0, useLogic_1.useLogic)(props);
|
|
19
18
|
if (isLoading) {
|
|
20
19
|
return (0, jsx_runtime_1.jsx)(FormFiltersSkeleton_1.FormFiltersSkeleton, {});
|
|
21
20
|
}
|
|
22
|
-
return ((0, jsx_runtime_1.jsxs)(
|
|
21
|
+
return ((0, jsx_runtime_1.jsxs)(Form_1.Form, { name: "form", form: form, onSubmit: form.handleSubmit(onSubmit || (() => undefined)), children: [(0, jsx_runtime_1.jsx)(FormControlProvider_1.FormControlProvider, { size: "small", hideHelperText: true, children: (0, jsx_runtime_1.jsxs)(styles_1.Wrapper, { children: [SearchField && (0, jsx_runtime_1.jsx)(SearchField, { control: form.control }), (0, jsx_runtime_1.jsx)(AllFiltersButton_1.AllFiltersButton, { form: form, onOpenModal: onOpenModal, hasMainFilters: Boolean(MainFilters), hasSecondaryFilters: Boolean(SecondaryFilters), hasSearch: Boolean(SearchField) }), (0, jsx_runtime_1.jsx)(styles_1.MainFiltersWrapper, { columns: mainFiltersColumns, children: MainFilters && ((0, jsx_runtime_1.jsx)(MainFilters, { control: form.control, isModal: false })) }), SubmitButton && ((0, jsx_runtime_1.jsx)(styles_1.SubmitButtonWrapper, { children: (0, jsx_runtime_1.jsx)(SubmitButton, { size: "medium", className: constants_1.formFiltersClassnames.submitButton }) }))] }) }), (0, jsx_runtime_1.jsx)(FormFiltersDialog_1.FormFiltersDialog, { ...dialogProps })] }));
|
|
23
22
|
};
|
|
24
23
|
exports.FormFilters = FormFilters;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { type FormFiltersDialogProps } from '../types';
|
|
3
|
-
export declare const useLogic: <TFieldValues extends Record<string, unknown>>({ validationSchema,
|
|
3
|
+
export declare const useLogic: <TFieldValues extends Record<string, unknown>>({ validationSchema, mainFilters, secondaryFilters, isModalOpen, setIsModalOpen, onSubmit, form, }: FormFiltersDialogProps<TFieldValues>) => {
|
|
4
4
|
modalForm: import("react-hook-form").UseFormReturn<TFieldValues, any>;
|
|
5
5
|
onCloseModal: () => void;
|
|
6
6
|
onResetModal: () => void;
|
|
@@ -3,17 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useLogic = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const useForm_1 = require("../../../useForm");
|
|
6
|
-
const useLogic = ({ validationSchema,
|
|
6
|
+
const useLogic = ({ validationSchema, mainFilters, secondaryFilters, isModalOpen, setIsModalOpen, onSubmit, form, }) => {
|
|
7
7
|
const modalForm = (0, useForm_1.useForm)({
|
|
8
8
|
validationSchema,
|
|
9
|
-
defaultValues:
|
|
9
|
+
defaultValues: form.getValues(),
|
|
10
10
|
});
|
|
11
11
|
const onCloseModal = () => {
|
|
12
12
|
setIsModalOpen(false);
|
|
13
13
|
modalForm.reset();
|
|
14
14
|
};
|
|
15
15
|
const onResetModal = () => {
|
|
16
|
-
modalForm.reset(
|
|
16
|
+
modalForm.reset(form.getValues());
|
|
17
17
|
};
|
|
18
18
|
const onSubmitModal = (submittedValues) => {
|
|
19
19
|
onSubmit(submittedValues);
|
|
@@ -21,13 +21,10 @@ const useLogic = ({ validationSchema, values, mainFilters, secondaryFilters, isM
|
|
|
21
21
|
};
|
|
22
22
|
const isResetButtonDisabled = !modalForm.formState.isDirty;
|
|
23
23
|
(0, react_1.useEffect)(() => {
|
|
24
|
-
if (isModalOpen
|
|
24
|
+
if (isModalOpen) {
|
|
25
25
|
onResetModal();
|
|
26
26
|
}
|
|
27
27
|
}, [isModalOpen]);
|
|
28
|
-
(0, react_1.useEffect)(() => {
|
|
29
|
-
modalForm.reset(values);
|
|
30
|
-
}, [values]);
|
|
31
28
|
return {
|
|
32
29
|
modalForm,
|
|
33
30
|
onCloseModal,
|
|
@@ -4,7 +4,6 @@ exports.formFiltersClassnames = void 0;
|
|
|
4
4
|
const createUIKitClassname_1 = require("../../components/utils/createUIKitClassname");
|
|
5
5
|
exports.formFiltersClassnames = {
|
|
6
6
|
modalFilters: (0, createUIKitClassname_1.createUIKitClassname)('form-filters__modal-filters'),
|
|
7
|
-
pageHeaderFilters: (0, createUIKitClassname_1.createUIKitClassname)('form-filters__page-header-filters'),
|
|
8
7
|
submitButton: (0, createUIKitClassname_1.createUIKitClassname)('form-filters__submit-button'),
|
|
9
8
|
allFiltersButton: (0, createUIKitClassname_1.createUIKitClassname)('form-filters__all-filters-button'),
|
|
10
9
|
showAllFiltersButtonOnDesktop: (0, createUIKitClassname_1.createUIKitClassname)('form-filters_show-all-filters-button_desktop'),
|
|
@@ -3,30 +3,12 @@ export declare const Wrapper: import("@emotion/styled/dist/declarations/src/type
|
|
|
3
3
|
theme?: import("@emotion/react").Theme | undefined;
|
|
4
4
|
as?: import("react").ElementType<any, keyof import("react").JSX.IntrinsicElements> | undefined;
|
|
5
5
|
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
6
|
-
export declare const AllFiltersButtonWrapper: import("@emotion/styled/dist/declarations/src/types").StyledComponent<{
|
|
7
|
-
theme?: import("@emotion/react").Theme | undefined;
|
|
8
|
-
as?: import("react").ElementType<any, keyof import("react").JSX.IntrinsicElements> | undefined;
|
|
9
|
-
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
10
6
|
export declare const MainFiltersWrapper: import("@emotion/styled/dist/declarations/src/types").StyledComponent<{
|
|
11
7
|
theme?: import("@emotion/react").Theme | undefined;
|
|
12
8
|
as?: import("react").ElementType<any, keyof import("react").JSX.IntrinsicElements> | undefined;
|
|
13
9
|
} & {
|
|
14
10
|
columns?: string | undefined;
|
|
15
11
|
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
16
|
-
export declare const StyledBadge: import("@emotion/styled/dist/declarations/src/types").StyledComponent<Omit<import("../..").WithoutEmotionSpecific<import("@mui/material/Badge").BadgeProps>, "color"> & {
|
|
17
|
-
color: import("../../components/Badge").BadgeColor;
|
|
18
|
-
withBorder?: boolean | undefined;
|
|
19
|
-
variantColor?: import("../../components/Badge").BadgeVariantsColor | undefined;
|
|
20
|
-
} & {
|
|
21
|
-
theme?: import("@emotion/react").Theme | undefined;
|
|
22
|
-
}, {}, {}>;
|
|
23
|
-
export declare const StyledCounter: import("@emotion/styled/dist/declarations/src/types").StyledComponent<Omit<import("../..").WithoutEmotionSpecific<import("@mui/material/Badge").BadgeProps>, "content" | "color" | "children" | "variant" | "invisible" | "anchorOrigin" | "badgeContent" | "overlap" | "withBorder"> & {
|
|
24
|
-
color: import("../../components/Counter/types").CounterColor;
|
|
25
|
-
variant?: import("../../components/Counter/types").CounterVariants | undefined;
|
|
26
|
-
content?: number | undefined;
|
|
27
|
-
} & {
|
|
28
|
-
theme?: import("@emotion/react").Theme | undefined;
|
|
29
|
-
}, {}, {}>;
|
|
30
12
|
export declare const SubmitButtonWrapper: import("@emotion/styled/dist/declarations/src/types").StyledComponent<{
|
|
31
13
|
theme?: import("@emotion/react").Theme | undefined;
|
|
32
14
|
as?: import("react").ElementType<any, keyof import("react").JSX.IntrinsicElements> | undefined;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SubmitButtonWrapper = exports.
|
|
4
|
-
const Badge_1 = require("@mui/material/Badge");
|
|
3
|
+
exports.SubmitButtonWrapper = exports.MainFiltersWrapper = exports.Wrapper = void 0;
|
|
5
4
|
const FormLabel_1 = require("@mui/material/FormLabel");
|
|
6
5
|
const InputBase_1 = require("@mui/material/InputBase");
|
|
7
|
-
const Badge_2 = require("../../components/Badge");
|
|
8
|
-
const Counter_1 = require("../../components/Counter");
|
|
9
6
|
const styled_1 = require("../../components/styled");
|
|
10
7
|
const constants_1 = require("./constants");
|
|
11
8
|
exports.Wrapper = styled_1.styled.div `
|
|
@@ -35,41 +32,6 @@ exports.Wrapper = styled_1.styled.div `
|
|
|
35
32
|
}
|
|
36
33
|
}
|
|
37
34
|
`;
|
|
38
|
-
exports.AllFiltersButtonWrapper = styled_1.styled.div `
|
|
39
|
-
display: none;
|
|
40
|
-
|
|
41
|
-
white-space: nowrap;
|
|
42
|
-
|
|
43
|
-
&.${constants_1.formFiltersClassnames.showAllFiltersButtonOnDesktop} {
|
|
44
|
-
display: flex;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
${({ theme }) => theme.breakpoints.down('sm')} {
|
|
48
|
-
margin-right: 0;
|
|
49
|
-
&.${constants_1.formFiltersClassnames.showAllFiltersButtonOnMobile} {
|
|
50
|
-
display: flex;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
&.${constants_1.formFiltersClassnames.withoutSearch} {
|
|
54
|
-
width: 100%;
|
|
55
|
-
|
|
56
|
-
.${constants_1.formFiltersClassnames.allFiltersButton} {
|
|
57
|
-
width: 100%;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
&.${constants_1.formFiltersClassnames.withSearch} {
|
|
62
|
-
.${constants_1.formFiltersClassnames.allFiltersButton} {
|
|
63
|
-
display: unset;
|
|
64
|
-
gap: 0;
|
|
65
|
-
|
|
66
|
-
padding: 8px;
|
|
67
|
-
|
|
68
|
-
font-size: 0;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
`;
|
|
73
35
|
exports.MainFiltersWrapper = styled_1.styled.div `
|
|
74
36
|
display: grid;
|
|
75
37
|
grid-auto-flow: column;
|
|
@@ -82,19 +44,6 @@ exports.MainFiltersWrapper = styled_1.styled.div `
|
|
|
82
44
|
display: none;
|
|
83
45
|
}
|
|
84
46
|
`;
|
|
85
|
-
exports.StyledBadge = (0, styled_1.styled)(Badge_2.Badge) `
|
|
86
|
-
width: 100%;
|
|
87
|
-
.${Badge_1.badgeClasses.dot} {
|
|
88
|
-
${({ theme }) => theme.breakpoints.up('sm')} {
|
|
89
|
-
display: none;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
`;
|
|
93
|
-
exports.StyledCounter = (0, styled_1.styled)(Counter_1.Counter) `
|
|
94
|
-
${({ theme }) => theme.breakpoints.down('sm')} {
|
|
95
|
-
display: none;
|
|
96
|
-
}
|
|
97
|
-
`;
|
|
98
47
|
exports.SubmitButtonWrapper = styled_1.styled.div `
|
|
99
48
|
white-space: nowrap;
|
|
100
49
|
|
|
@@ -1,45 +1,36 @@
|
|
|
1
1
|
import { type ObjectAsyncGuard, type ObjectGuard } from '@astral/validations';
|
|
2
2
|
import { type ReactNode } from 'react';
|
|
3
|
-
import { type Control } from 'react-hook-form';
|
|
3
|
+
import { type Control, type UseFormReturn } from 'react-hook-form';
|
|
4
4
|
import type { ButtonProps } from '../../components/Button';
|
|
5
5
|
type InputsProps<TFieldValues extends Record<string, unknown>> = {
|
|
6
6
|
control: Control<TFieldValues>;
|
|
7
7
|
};
|
|
8
8
|
export type FormFiltersProps<TFieldValues extends Record<string, unknown>> = {
|
|
9
|
+
form: UseFormReturn<TFieldValues>;
|
|
10
|
+
onSubmit?: (values: TFieldValues) => void;
|
|
9
11
|
/**
|
|
10
12
|
* Схема валидации из @astral/validations
|
|
11
13
|
*/
|
|
12
14
|
validationSchema?: ObjectGuard<TFieldValues> | ObjectAsyncGuard<TFieldValues>;
|
|
13
|
-
/**
|
|
14
|
-
* Значения фильтров
|
|
15
|
-
*/
|
|
16
|
-
values?: TFieldValues;
|
|
17
|
-
/**
|
|
18
|
-
* Callback вызываемый при изменении значений фильтров. Вызывается с debounce (300ms)
|
|
19
|
-
*/
|
|
20
|
-
onChange: (values: TFieldValues) => void;
|
|
21
15
|
/**
|
|
22
16
|
* Поле поиска
|
|
23
17
|
*
|
|
24
18
|
* @example
|
|
25
19
|
* ```ts
|
|
26
20
|
* <FormFilters
|
|
27
|
-
* SearchField={(
|
|
21
|
+
* SearchField={({control}) => <FormFiltersSearchField control={control} placeholder="Поиск..." />}
|
|
28
22
|
* />
|
|
29
23
|
* ```
|
|
30
24
|
*/
|
|
31
|
-
searchField?: (props: InputsProps<TFieldValues>
|
|
32
|
-
fullWidth?: boolean;
|
|
33
|
-
}) => ReactNode;
|
|
25
|
+
searchField?: (props: InputsProps<TFieldValues>) => ReactNode;
|
|
34
26
|
/**
|
|
35
27
|
* Основные фильтры
|
|
36
28
|
*
|
|
37
29
|
* @example
|
|
38
30
|
* ```ts
|
|
39
31
|
* <FormFilters
|
|
40
|
-
* MainFilters={({ control, isModal
|
|
32
|
+
* MainFilters={({ control, isModal }) =>
|
|
41
33
|
* <FormTextField
|
|
42
|
-
* {...props}
|
|
43
34
|
* control={control}
|
|
44
35
|
* name="name"
|
|
45
36
|
* label="Название"
|
|
@@ -57,7 +48,7 @@ export type FormFiltersProps<TFieldValues extends Record<string, unknown>> = {
|
|
|
57
48
|
* @example
|
|
58
49
|
* ```ts
|
|
59
50
|
* <FormFilters
|
|
60
|
-
* SecondaryFilters={({ control
|
|
51
|
+
* SecondaryFilters={({ control }) => <FormTextField control={control} name="name" label="Название" placeholder="Введите название" />}
|
|
61
52
|
* />
|
|
62
53
|
* ```
|
|
63
54
|
*/
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import { type UseFormReturn } from '
|
|
1
|
+
import { type UseFormReturn } from 'react-hook-form';
|
|
2
2
|
import { type FormFiltersDialogProps } from '../FormFiltersDialog/types';
|
|
3
3
|
import { type FormFiltersProps } from '../types';
|
|
4
4
|
type UseLogicReturn<TFieldValues extends Record<string, unknown>> = {
|
|
5
|
-
|
|
5
|
+
form: UseFormReturn<TFieldValues>;
|
|
6
|
+
onSubmit?: (values: TFieldValues) => void;
|
|
6
7
|
searchField: FormFiltersProps<TFieldValues>['searchField'];
|
|
7
8
|
mainFilters: FormFiltersProps<TFieldValues>['mainFilters'];
|
|
8
9
|
submitButton: FormFiltersProps<TFieldValues>['submitButton'];
|
|
9
|
-
|
|
10
|
-
onSubmit: (submittedValues: TFieldValues) => void;
|
|
10
|
+
secondaryFilters: FormFiltersProps<TFieldValues>['secondaryFilters'];
|
|
11
11
|
onOpenModal: () => void;
|
|
12
12
|
dialogProps: FormFiltersDialogProps<TFieldValues>;
|
|
13
13
|
mainFiltersColumns?: string;
|
|
14
14
|
isLoading?: boolean;
|
|
15
|
-
allFiltersButtonClassName: string;
|
|
16
15
|
};
|
|
17
|
-
export declare const useLogic: <TFieldValues extends Record<string, unknown>>({
|
|
16
|
+
export declare const useLogic: <TFieldValues extends Record<string, unknown>>({ form, onSubmit, validationSchema, searchField, mainFilters, secondaryFilters, submitButton, mainFiltersColumns, isLoading, }: FormFiltersProps<TFieldValues>) => UseLogicReturn<TFieldValues>;
|
|
18
17
|
export {};
|
|
@@ -1,124 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useLogic = void 0;
|
|
4
|
-
const debounce_1 = require("@astral/utils/debounce");
|
|
5
4
|
const react_1 = require("react");
|
|
6
|
-
const
|
|
7
|
-
const checkIsDeepEqual_1 = require("../../../components/utils/checkIsDeepEqual");
|
|
8
|
-
const classNames_1 = require("../../../components/utils/classNames");
|
|
9
|
-
const constants_1 = require("../../FormFiltersSearchField/constants");
|
|
10
|
-
const useForm_1 = require("../../useForm");
|
|
11
|
-
const constants_2 = require("../constants");
|
|
12
|
-
const hooks_1 = require("./hooks");
|
|
13
|
-
const useLogic = ({ validationSchema, values, onChange, searchField, mainFilters, secondaryFilters, submitButton, mainFiltersColumns, isLoading, }) => {
|
|
5
|
+
const useLogic = ({ form, onSubmit, validationSchema, searchField, mainFilters, secondaryFilters, submitButton, mainFiltersColumns, isLoading, }) => {
|
|
14
6
|
const [isModalOpen, setIsModalOpen] = (0, react_1.useState)(false);
|
|
15
|
-
const isFirstMount = (0, hooks_1.useFirstMountAfterLoading)(isLoading);
|
|
16
7
|
const onOpenModal = () => {
|
|
17
8
|
setIsModalOpen(true);
|
|
18
9
|
};
|
|
19
|
-
const headerForm = (0, useForm_1.useForm)({
|
|
20
|
-
validationSchema,
|
|
21
|
-
defaultValues: values,
|
|
22
|
-
});
|
|
23
|
-
const headerFormValues = (0, react_hook_form_1.useWatch)({
|
|
24
|
-
control: headerForm.control,
|
|
25
|
-
});
|
|
26
|
-
// Ref для хранения debounced функции, чтобы можно было её отменить
|
|
27
|
-
const debouncedOnChangeRef = (0, react_1.useRef)(null);
|
|
28
|
-
// Ref для отслеживания внешнего reset (чтобы не вызывать onChange при внешнем reset)
|
|
29
|
-
const isExternalResetRef = (0, react_1.useRef)(false);
|
|
30
|
-
// Ref для хранения предыдущих внешних values (для сравнения)
|
|
31
|
-
const previousValuesRef = (0, react_1.useRef)(values);
|
|
32
|
-
// Отменяет предыдущий debounced вызов onChange, если он есть
|
|
33
|
-
const clearPreviousDebouncedOnChange = () => {
|
|
34
|
-
if (debouncedOnChangeRef.current) {
|
|
35
|
-
debouncedOnChangeRef.current.clear();
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
const hasSubmitButton = Boolean(submitButton);
|
|
39
|
-
(0, react_1.useEffect)(() => {
|
|
40
|
-
// Если есть submitButton, не вызываем onChange при изменении значений
|
|
41
|
-
if (hasSubmitButton || isLoading || isFirstMount) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
clearPreviousDebouncedOnChange();
|
|
45
|
-
// Пропускаем onChange если это внешний reset
|
|
46
|
-
if (isExternalResetRef.current) {
|
|
47
|
-
isExternalResetRef.current = false;
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
// Создаем новый debounced вызов
|
|
51
|
-
const debouncedOnChange = (0, debounce_1.debounce)(() => {
|
|
52
|
-
onChange(headerFormValues);
|
|
53
|
-
}, 300);
|
|
54
|
-
debouncedOnChangeRef.current = debouncedOnChange;
|
|
55
|
-
debouncedOnChange();
|
|
56
|
-
return () => {
|
|
57
|
-
debouncedOnChange.clear();
|
|
58
|
-
};
|
|
59
|
-
}, [headerFormValues, onChange, hasSubmitButton, isLoading]);
|
|
60
|
-
const searchName = document
|
|
61
|
-
.getElementById(constants_1.FORM_FILTERS_SEARCH_FIELD_ID)
|
|
62
|
-
?.getAttribute('name') || '';
|
|
63
|
-
// Исключаем поиск из счетчика фильтров
|
|
64
|
-
const counter = Object.values(headerFormValues).filter(Boolean).length -
|
|
65
|
-
(headerFormValues[searchName] ? 1 : 0);
|
|
66
|
-
const setFiltersValues = (newValues) => headerForm.reset(newValues);
|
|
67
|
-
// Функция отправки формы на SubmitButton. Приводит к вызову onChange без debounce.
|
|
68
|
-
const onSubmit = (submittedValues) => {
|
|
69
|
-
clearPreviousDebouncedOnChange();
|
|
70
|
-
onChange?.(submittedValues);
|
|
71
|
-
};
|
|
72
10
|
// Функция отправки формы на кнопку "Применить" в модальном окне
|
|
73
11
|
const onSubmitModal = (submittedValues) => {
|
|
74
|
-
|
|
75
|
-
onSubmit(submittedValues);
|
|
12
|
+
form.reset(submittedValues);
|
|
76
13
|
};
|
|
77
|
-
// Синхронизация внешних values с формой
|
|
78
|
-
(0, react_1.useEffect)(() => {
|
|
79
|
-
if (isFirstMount) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
// Сравниваем значения, чтобы избежать лишних reset
|
|
83
|
-
const valuesChanged = !(0, checkIsDeepEqual_1.checkIsDeepEqual)(previousValuesRef.current, values);
|
|
84
|
-
if (!valuesChanged) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
clearPreviousDebouncedOnChange();
|
|
88
|
-
isExternalResetRef.current = true;
|
|
89
|
-
previousValuesRef.current = values;
|
|
90
|
-
setFiltersValues(values);
|
|
91
|
-
}, [values, headerForm]);
|
|
92
|
-
const allFiltersButtonClassName = (0, react_1.useMemo)(() => {
|
|
93
|
-
return (0, classNames_1.classNames)({
|
|
94
|
-
[constants_2.formFiltersClassnames.showAllFiltersButtonOnDesktop]: Boolean(secondaryFilters),
|
|
95
|
-
[constants_2.formFiltersClassnames.showAllFiltersButtonOnMobile]: Boolean(mainFilters) || Boolean(secondaryFilters),
|
|
96
|
-
[constants_2.formFiltersClassnames.withSearch]: Boolean(searchField),
|
|
97
|
-
[constants_2.formFiltersClassnames.withoutSearch]: !searchField,
|
|
98
|
-
});
|
|
99
|
-
}, [mainFilters, secondaryFilters, searchField]);
|
|
100
14
|
const dialogProps = {
|
|
101
15
|
validationSchema,
|
|
102
|
-
|
|
16
|
+
form,
|
|
103
17
|
mainFilters,
|
|
104
18
|
secondaryFilters,
|
|
105
|
-
defaultValues: headerFormValues,
|
|
106
19
|
onSubmit: onSubmitModal,
|
|
107
20
|
isModalOpen,
|
|
108
21
|
setIsModalOpen,
|
|
109
22
|
};
|
|
110
23
|
return {
|
|
111
|
-
|
|
24
|
+
form,
|
|
25
|
+
onSubmit,
|
|
112
26
|
searchField,
|
|
113
27
|
mainFilters,
|
|
28
|
+
secondaryFilters,
|
|
114
29
|
submitButton,
|
|
115
|
-
counter,
|
|
116
|
-
onSubmit,
|
|
117
30
|
onOpenModal,
|
|
118
31
|
dialogProps,
|
|
119
32
|
mainFiltersColumns,
|
|
120
33
|
isLoading,
|
|
121
|
-
allFiltersButtonClassName,
|
|
122
34
|
};
|
|
123
35
|
};
|
|
124
36
|
exports.useLogic = useLogic;
|