@astral/ui 4.6.0 → 4.7.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/MenuOrganization/OrganizationButton/OrganizationButton.d.ts +7 -1
- package/components/MenuOrganization/OrganizationButton/OrganizationButton.js +4 -2
- package/components/MenuOrganization/types.d.ts +13 -0
- package/components/MenuOrganization/useLogic/useLogic.d.ts +4 -1
- package/components/MenuOrganization/useLogic/useLogic.js +5 -1
- package/node/components/MenuOrganization/OrganizationButton/OrganizationButton.d.ts +7 -1
- package/node/components/MenuOrganization/OrganizationButton/OrganizationButton.js +4 -2
- package/node/components/MenuOrganization/types.d.ts +13 -0
- package/node/components/MenuOrganization/useLogic/useLogic.d.ts +4 -1
- package/node/components/MenuOrganization/useLogic/useLogic.js +5 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type SyntheticEvent } from 'react';
|
|
1
|
+
import { type ReactNode, type SyntheticEvent } from 'react';
|
|
2
2
|
import { type Organization } from '../types';
|
|
3
3
|
export type OrganizationButtonProps = {
|
|
4
4
|
onClick: (event: SyntheticEvent) => void;
|
|
@@ -10,5 +10,11 @@ export type OrganizationButtonProps = {
|
|
|
10
10
|
* Скрытие персональных данных от инструментов мониторинга
|
|
11
11
|
*/
|
|
12
12
|
isHidePersonalData?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Render-props, позволяет кастомизировать содержимое кнопки
|
|
15
|
+
*/
|
|
16
|
+
renderPreview?: (organization: Organization & Record<string, unknown>, params: {
|
|
17
|
+
className?: string;
|
|
18
|
+
}) => ReactNode;
|
|
13
19
|
};
|
|
14
20
|
export declare const OrganizationButton: import("react").ForwardRefExoticComponent<OrganizationButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
@@ -5,12 +5,14 @@ import { useHidePersonalData } from '../../personalDataSecurity';
|
|
|
5
5
|
import { Tooltip } from '../../Tooltip';
|
|
6
6
|
import { OrganizationData } from '../styles';
|
|
7
7
|
import { Container, StyledButton, StyledChevron, StyledTypography, } from './styles';
|
|
8
|
-
export const OrganizationButton = forwardRef(({ onClick, isOpen, currentOrganization, isDisabled, disabledReason, isHidePersonalData, }, ref) => {
|
|
8
|
+
export const OrganizationButton = forwardRef(({ onClick, isOpen, currentOrganization, isDisabled, disabledReason, isHidePersonalData, renderPreview, }, ref) => {
|
|
9
9
|
const { name, inn, kpp } = currentOrganization;
|
|
10
10
|
const hidePersonalDataClassname = useHidePersonalData({
|
|
11
11
|
isEnabled: isHidePersonalData,
|
|
12
12
|
});
|
|
13
|
-
const renderButton = () => (_jsx(StyledButton, { ref: ref, variant: "text", disabled: isDisabled, onClick: onClick, endIcon: _jsx(StyledChevron, { isActive: isOpen, width: 24, height: 24 }), children:
|
|
13
|
+
const renderButton = () => (_jsx(StyledButton, { ref: ref, variant: "text", disabled: isDisabled, onClick: onClick, endIcon: _jsx(StyledChevron, { isActive: isOpen, width: 24, height: 24 }), children: renderPreview ? (renderPreview(currentOrganization, {
|
|
14
|
+
className: hidePersonalDataClassname,
|
|
15
|
+
})) : (_jsxs(Container, { className: hidePersonalDataClassname, children: [_jsx(OverflowTypography, { variant: "h6", component: "div", children: name }), _jsxs(OrganizationData, { children: [_jsxs(StyledTypography, { "$isDisabled": isDisabled, variant: "caption", color: "textSecondary", children: ["\u0418\u041D\u041D ", inn] }), kpp && (_jsxs(StyledTypography, { "$isDisabled": isDisabled, variant: "caption", color: "textSecondary", children: ["\u041A\u041F\u041F ", kpp] }))] })] })) }));
|
|
14
16
|
if (isDisabled && disabledReason) {
|
|
15
17
|
return (_jsx(Tooltip, { title: disabledReason, withoutContainer: false, placement: "bottom", children: renderButton() }));
|
|
16
18
|
}
|
|
@@ -113,4 +113,17 @@ export type MenuOrganizationProps<TData extends Organization = Organization> = {
|
|
|
113
113
|
* )}
|
|
114
114
|
*/
|
|
115
115
|
renderItem?: (params: RenderItemParams<TData>) => ReactNode;
|
|
116
|
+
/**
|
|
117
|
+
* Render-props, позволяет кастомизировать содержимое кнопки OrganizationButton
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* renderPreview={(organization) => (
|
|
121
|
+
* <Avatar color="#EC4899" size="md">
|
|
122
|
+
* {getInitials(organization.name)}
|
|
123
|
+
* </Avatar>
|
|
124
|
+
* )}
|
|
125
|
+
*/
|
|
126
|
+
renderPreview?: (organization: TData, params: {
|
|
127
|
+
className?: string;
|
|
128
|
+
}) => ReactNode;
|
|
116
129
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ChangeEvent, type SyntheticEvent } from 'react';
|
|
2
2
|
import { type MenuOrganizationProps, type Organization } from '../types';
|
|
3
3
|
type UseLogicParams<TData extends Organization & Record<string, unknown>> = MenuOrganizationProps<TData>;
|
|
4
|
-
export declare const useLogic: <TData extends Organization & Record<string, unknown>>({ organizations, onChangeSearch, onChange, currentOrganizationGroupLabel, currentOrganization, groupBy, onClose, onOpen, isOpen: isOpenPopover, isDisabled, disabledReason, isHidePersonalData, action, isLoading, isError, onRetry, renderItem, }: UseLogicParams<TData>) => {
|
|
4
|
+
export declare const useLogic: <TData extends Organization & Record<string, unknown>>({ organizations, onChangeSearch, onChange, currentOrganizationGroupLabel, currentOrganization, groupBy, onClose, onOpen, isOpen: isOpenPopover, isDisabled, disabledReason, isHidePersonalData, action, isLoading, isError, onRetry, renderItem, renderPreview, }: UseLogicParams<TData>) => {
|
|
5
5
|
action: ({
|
|
6
6
|
text: string;
|
|
7
7
|
} & Pick<import("../..").ButtonProps, "onClick" | "href" | "endIcon" | "startIcon" | "variant" | "component">) | undefined;
|
|
@@ -19,6 +19,9 @@ export declare const useLogic: <TData extends Organization & Record<string, unkn
|
|
|
19
19
|
isDisabled: boolean | undefined;
|
|
20
20
|
disabledReason: string | undefined;
|
|
21
21
|
isHidePersonalData: boolean | undefined;
|
|
22
|
+
renderPreview: ((organization: Organization & Record<string, unknown>, params: {
|
|
23
|
+
className?: string;
|
|
24
|
+
}) => import("react").ReactNode) | undefined;
|
|
22
25
|
ref: (node: HTMLButtonElement | null) => void;
|
|
23
26
|
};
|
|
24
27
|
searchProps: {
|
|
@@ -2,7 +2,7 @@ import { useCallback, useContext, useMemo, useState, } from 'react';
|
|
|
2
2
|
import { DashboardContext } from '../../DashboardLayout';
|
|
3
3
|
import { usePopover } from '../../hooks';
|
|
4
4
|
import { useHidePersonalData } from '../../personalDataSecurity';
|
|
5
|
-
export const useLogic = ({ organizations = [], onChangeSearch, onChange, currentOrganizationGroupLabel, currentOrganization, groupBy, onClose, onOpen, isOpen: isOpenPopover, isDisabled, disabledReason, isHidePersonalData, action, isLoading, isError, onRetry, renderItem, }) => {
|
|
5
|
+
export const useLogic = ({ organizations = [], onChangeSearch, onChange, currentOrganizationGroupLabel, currentOrganization, groupBy, onClose, onOpen, isOpen: isOpenPopover, isDisabled, disabledReason, isHidePersonalData, action, isLoading, isError, onRetry, renderItem, renderPreview, }) => {
|
|
6
6
|
const { isLoading: isDashboardLoading } = useContext(DashboardContext);
|
|
7
7
|
const [searchValue, setSearchValue] = useState('');
|
|
8
8
|
const [anchorButtonEl, setAnchorButtonEl] = useState(null);
|
|
@@ -50,6 +50,9 @@ export const useLogic = ({ organizations = [], onChangeSearch, onChange, current
|
|
|
50
50
|
}
|
|
51
51
|
return !isError && !isLoading && organizations.length > 10;
|
|
52
52
|
}, [searchValue.length, isError, isLoading, organizations.length]);
|
|
53
|
+
const renderPreviewWrapper = useMemo(() => renderPreview
|
|
54
|
+
? (organization, params) => renderPreview(organization, params)
|
|
55
|
+
: undefined, [renderPreview]);
|
|
53
56
|
return {
|
|
54
57
|
action,
|
|
55
58
|
isLoading,
|
|
@@ -64,6 +67,7 @@ export const useLogic = ({ organizations = [], onChangeSearch, onChange, current
|
|
|
64
67
|
isDisabled,
|
|
65
68
|
disabledReason,
|
|
66
69
|
isHidePersonalData,
|
|
70
|
+
renderPreview: renderPreviewWrapper,
|
|
67
71
|
ref: buttonRef,
|
|
68
72
|
},
|
|
69
73
|
searchProps: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type SyntheticEvent } from 'react';
|
|
1
|
+
import { type ReactNode, type SyntheticEvent } from 'react';
|
|
2
2
|
import { type Organization } from '../types';
|
|
3
3
|
export type OrganizationButtonProps = {
|
|
4
4
|
onClick: (event: SyntheticEvent) => void;
|
|
@@ -10,5 +10,11 @@ export type OrganizationButtonProps = {
|
|
|
10
10
|
* Скрытие персональных данных от инструментов мониторинга
|
|
11
11
|
*/
|
|
12
12
|
isHidePersonalData?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Render-props, позволяет кастомизировать содержимое кнопки
|
|
15
|
+
*/
|
|
16
|
+
renderPreview?: (organization: Organization & Record<string, unknown>, params: {
|
|
17
|
+
className?: string;
|
|
18
|
+
}) => ReactNode;
|
|
13
19
|
};
|
|
14
20
|
export declare const OrganizationButton: import("react").ForwardRefExoticComponent<OrganizationButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
@@ -8,12 +8,14 @@ const personalDataSecurity_1 = require("../../personalDataSecurity");
|
|
|
8
8
|
const Tooltip_1 = require("../../Tooltip");
|
|
9
9
|
const styles_1 = require("../styles");
|
|
10
10
|
const styles_2 = require("./styles");
|
|
11
|
-
exports.OrganizationButton = (0, react_1.forwardRef)(({ onClick, isOpen, currentOrganization, isDisabled, disabledReason, isHidePersonalData, }, ref) => {
|
|
11
|
+
exports.OrganizationButton = (0, react_1.forwardRef)(({ onClick, isOpen, currentOrganization, isDisabled, disabledReason, isHidePersonalData, renderPreview, }, ref) => {
|
|
12
12
|
const { name, inn, kpp } = currentOrganization;
|
|
13
13
|
const hidePersonalDataClassname = (0, personalDataSecurity_1.useHidePersonalData)({
|
|
14
14
|
isEnabled: isHidePersonalData,
|
|
15
15
|
});
|
|
16
|
-
const renderButton = () => ((0, jsx_runtime_1.jsx)(styles_2.StyledButton, { ref: ref, variant: "text", disabled: isDisabled, onClick: onClick, endIcon: (0, jsx_runtime_1.jsx)(styles_2.StyledChevron, { isActive: isOpen, width: 24, height: 24 }), children:
|
|
16
|
+
const renderButton = () => ((0, jsx_runtime_1.jsx)(styles_2.StyledButton, { ref: ref, variant: "text", disabled: isDisabled, onClick: onClick, endIcon: (0, jsx_runtime_1.jsx)(styles_2.StyledChevron, { isActive: isOpen, width: 24, height: 24 }), children: renderPreview ? (renderPreview(currentOrganization, {
|
|
17
|
+
className: hidePersonalDataClassname,
|
|
18
|
+
})) : ((0, jsx_runtime_1.jsxs)(styles_2.Container, { className: hidePersonalDataClassname, children: [(0, jsx_runtime_1.jsx)(OverflowTypography_1.OverflowTypography, { variant: "h6", component: "div", children: name }), (0, jsx_runtime_1.jsxs)(styles_1.OrganizationData, { children: [(0, jsx_runtime_1.jsxs)(styles_2.StyledTypography, { "$isDisabled": isDisabled, variant: "caption", color: "textSecondary", children: ["\u0418\u041D\u041D ", inn] }), kpp && ((0, jsx_runtime_1.jsxs)(styles_2.StyledTypography, { "$isDisabled": isDisabled, variant: "caption", color: "textSecondary", children: ["\u041A\u041F\u041F ", kpp] }))] })] })) }));
|
|
17
19
|
if (isDisabled && disabledReason) {
|
|
18
20
|
return ((0, jsx_runtime_1.jsx)(Tooltip_1.Tooltip, { title: disabledReason, withoutContainer: false, placement: "bottom", children: renderButton() }));
|
|
19
21
|
}
|
|
@@ -113,4 +113,17 @@ export type MenuOrganizationProps<TData extends Organization = Organization> = {
|
|
|
113
113
|
* )}
|
|
114
114
|
*/
|
|
115
115
|
renderItem?: (params: RenderItemParams<TData>) => ReactNode;
|
|
116
|
+
/**
|
|
117
|
+
* Render-props, позволяет кастомизировать содержимое кнопки OrganizationButton
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* renderPreview={(organization) => (
|
|
121
|
+
* <Avatar color="#EC4899" size="md">
|
|
122
|
+
* {getInitials(organization.name)}
|
|
123
|
+
* </Avatar>
|
|
124
|
+
* )}
|
|
125
|
+
*/
|
|
126
|
+
renderPreview?: (organization: TData, params: {
|
|
127
|
+
className?: string;
|
|
128
|
+
}) => ReactNode;
|
|
116
129
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ChangeEvent, type SyntheticEvent } from 'react';
|
|
2
2
|
import { type MenuOrganizationProps, type Organization } from '../types';
|
|
3
3
|
type UseLogicParams<TData extends Organization & Record<string, unknown>> = MenuOrganizationProps<TData>;
|
|
4
|
-
export declare const useLogic: <TData extends Organization & Record<string, unknown>>({ organizations, onChangeSearch, onChange, currentOrganizationGroupLabel, currentOrganization, groupBy, onClose, onOpen, isOpen: isOpenPopover, isDisabled, disabledReason, isHidePersonalData, action, isLoading, isError, onRetry, renderItem, }: UseLogicParams<TData>) => {
|
|
4
|
+
export declare const useLogic: <TData extends Organization & Record<string, unknown>>({ organizations, onChangeSearch, onChange, currentOrganizationGroupLabel, currentOrganization, groupBy, onClose, onOpen, isOpen: isOpenPopover, isDisabled, disabledReason, isHidePersonalData, action, isLoading, isError, onRetry, renderItem, renderPreview, }: UseLogicParams<TData>) => {
|
|
5
5
|
action: ({
|
|
6
6
|
text: string;
|
|
7
7
|
} & Pick<import("../..").ButtonProps, "onClick" | "href" | "endIcon" | "startIcon" | "variant" | "component">) | undefined;
|
|
@@ -19,6 +19,9 @@ export declare const useLogic: <TData extends Organization & Record<string, unkn
|
|
|
19
19
|
isDisabled: boolean | undefined;
|
|
20
20
|
disabledReason: string | undefined;
|
|
21
21
|
isHidePersonalData: boolean | undefined;
|
|
22
|
+
renderPreview: ((organization: Organization & Record<string, unknown>, params: {
|
|
23
|
+
className?: string;
|
|
24
|
+
}) => import("react").ReactNode) | undefined;
|
|
22
25
|
ref: (node: HTMLButtonElement | null) => void;
|
|
23
26
|
};
|
|
24
27
|
searchProps: {
|
|
@@ -5,7 +5,7 @@ const react_1 = require("react");
|
|
|
5
5
|
const DashboardLayout_1 = require("../../DashboardLayout");
|
|
6
6
|
const hooks_1 = require("../../hooks");
|
|
7
7
|
const personalDataSecurity_1 = require("../../personalDataSecurity");
|
|
8
|
-
const useLogic = ({ organizations = [], onChangeSearch, onChange, currentOrganizationGroupLabel, currentOrganization, groupBy, onClose, onOpen, isOpen: isOpenPopover, isDisabled, disabledReason, isHidePersonalData, action, isLoading, isError, onRetry, renderItem, }) => {
|
|
8
|
+
const useLogic = ({ organizations = [], onChangeSearch, onChange, currentOrganizationGroupLabel, currentOrganization, groupBy, onClose, onOpen, isOpen: isOpenPopover, isDisabled, disabledReason, isHidePersonalData, action, isLoading, isError, onRetry, renderItem, renderPreview, }) => {
|
|
9
9
|
const { isLoading: isDashboardLoading } = (0, react_1.useContext)(DashboardLayout_1.DashboardContext);
|
|
10
10
|
const [searchValue, setSearchValue] = (0, react_1.useState)('');
|
|
11
11
|
const [anchorButtonEl, setAnchorButtonEl] = (0, react_1.useState)(null);
|
|
@@ -53,6 +53,9 @@ const useLogic = ({ organizations = [], onChangeSearch, onChange, currentOrganiz
|
|
|
53
53
|
}
|
|
54
54
|
return !isError && !isLoading && organizations.length > 10;
|
|
55
55
|
}, [searchValue.length, isError, isLoading, organizations.length]);
|
|
56
|
+
const renderPreviewWrapper = (0, react_1.useMemo)(() => renderPreview
|
|
57
|
+
? (organization, params) => renderPreview(organization, params)
|
|
58
|
+
: undefined, [renderPreview]);
|
|
56
59
|
return {
|
|
57
60
|
action,
|
|
58
61
|
isLoading,
|
|
@@ -67,6 +70,7 @@ const useLogic = ({ organizations = [], onChangeSearch, onChange, currentOrganiz
|
|
|
67
70
|
isDisabled,
|
|
68
71
|
disabledReason,
|
|
69
72
|
isHidePersonalData,
|
|
73
|
+
renderPreview: renderPreviewWrapper,
|
|
70
74
|
ref: buttonRef,
|
|
71
75
|
},
|
|
72
76
|
searchProps: {
|