@astral/ui 4.38.0 → 4.40.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/Button/Button.js +2 -8
- package/components/Button/constants.d.ts +12 -0
- package/components/Button/constants.js +9 -0
- package/components/Button/useLogic/useLogic.d.ts +2 -1
- package/components/Button/useLogic/useLogic.js +12 -3
- package/hook-form/EditableText/EditableText.d.ts +10 -1
- package/hook-form/EditableText/EditableText.js +16 -2
- package/hook-form/EditableText/constants.d.ts +3 -0
- package/hook-form/EditableText/constants.js +4 -0
- package/hook-form/EditableText/styles.js +9 -0
- package/node/components/Button/Button.js +2 -8
- package/node/components/Button/constants.d.ts +12 -0
- package/node/components/Button/constants.js +10 -1
- package/node/components/Button/useLogic/useLogic.d.ts +2 -1
- package/node/components/Button/useLogic/useLogic.js +11 -2
- package/node/hook-form/EditableText/EditableText.d.ts +10 -1
- package/node/hook-form/EditableText/EditableText.js +16 -2
- package/node/hook-form/EditableText/constants.d.ts +3 -0
- package/node/hook-form/EditableText/constants.js +5 -1
- package/node/hook-form/EditableText/styles.js +9 -0
- package/package.json +1 -1
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRefWithGeneric } from '../forwardRefWithGeneric';
|
|
3
|
-
import { classNames } from '../utils/classNames';
|
|
4
|
-
import { buttonClassnames } from './constants';
|
|
5
3
|
import { ButtonColors, ButtonVariants } from './enums';
|
|
6
4
|
import { StyledButton, StyledLoader } from './styles';
|
|
7
5
|
import { useLogic } from './useLogic';
|
|
8
6
|
const UnwrappedButton = (props, ref) => {
|
|
9
|
-
const { loadingIndicatorColor } = useLogic(props);
|
|
7
|
+
const { loadingIndicatorColor, classnames } = useLogic(props);
|
|
10
8
|
const { variant = ButtonVariants.Contained, color = variant === ButtonVariants.Text
|
|
11
9
|
? ButtonColors.Grey
|
|
12
10
|
: ButtonColors.Primary, loading, disabled, children, className, selected, ...restProps } = props;
|
|
13
|
-
return (_jsxs(StyledButton, { variant: variant, ref: ref, color: color, disabled: disabled || loading, selected: selected, ...restProps, className:
|
|
14
|
-
[buttonClassnames.loading]: loading,
|
|
15
|
-
[buttonClassnames.selected]: selected,
|
|
16
|
-
[buttonClassnames.disabled]: disabled,
|
|
17
|
-
}), "aria-disabled": loading, children: [loading && (_jsx(StyledLoader, { color: loadingIndicatorColor, size: "small", "$color": color, "$variant": variant, "$isDisabled": disabled })), children] }));
|
|
11
|
+
return (_jsxs(StyledButton, { variant: variant, ref: ref, color: color, disabled: disabled || loading, selected: selected, ...restProps, className: classnames, "aria-disabled": loading, children: [loading && (_jsx(StyledLoader, { color: loadingIndicatorColor, size: "small", "$color": color, "$variant": variant, "$isDisabled": disabled })), children] }));
|
|
18
12
|
};
|
|
19
13
|
export const Button = forwardRefWithGeneric(UnwrappedButton);
|
|
20
14
|
export default Button;
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
export { buttonClasses } from '@mui/material/Button';
|
|
2
|
+
export declare const buttonColorClassnames: {
|
|
3
|
+
primary: string;
|
|
4
|
+
error: string;
|
|
5
|
+
success: string;
|
|
6
|
+
warning: string;
|
|
7
|
+
grey: string;
|
|
8
|
+
};
|
|
2
9
|
export declare const buttonClassnames: {
|
|
10
|
+
primary: string;
|
|
11
|
+
error: string;
|
|
12
|
+
success: string;
|
|
13
|
+
warning: string;
|
|
14
|
+
grey: string;
|
|
3
15
|
root: string;
|
|
4
16
|
loading: string;
|
|
5
17
|
selected: string;
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { createUIKitClassname } from '../utils/createUIKitClassname';
|
|
2
|
+
import { ButtonColors } from './enums';
|
|
2
3
|
export { buttonClasses } from '@mui/material/Button';
|
|
4
|
+
export const buttonColorClassnames = {
|
|
5
|
+
[ButtonColors.Primary]: createUIKitClassname('button_color-primary'),
|
|
6
|
+
[ButtonColors.Error]: createUIKitClassname('button_color-error'),
|
|
7
|
+
[ButtonColors.Success]: createUIKitClassname('button_color-success'),
|
|
8
|
+
[ButtonColors.Warning]: createUIKitClassname('button_color-warning'),
|
|
9
|
+
[ButtonColors.Grey]: createUIKitClassname('button_color-grey'),
|
|
10
|
+
};
|
|
3
11
|
export const buttonClassnames = {
|
|
4
12
|
root: createUIKitClassname('button'),
|
|
5
13
|
loading: createUIKitClassname('button_loading'),
|
|
6
14
|
selected: createUIKitClassname('button_selected'),
|
|
7
15
|
disabled: createUIKitClassname('button_disabled'),
|
|
16
|
+
...buttonColorClassnames,
|
|
8
17
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type ButtonProps } from '../types';
|
|
2
2
|
type UseLogicParam = ButtonProps;
|
|
3
3
|
type Color = 'primary' | 'inverted';
|
|
4
|
-
export declare const useLogic: ({ variant, }: UseLogicParam) => {
|
|
4
|
+
export declare const useLogic: ({ loading, selected, variant, color, disabled, className, }: UseLogicParam) => {
|
|
5
5
|
loadingIndicatorColor: Color;
|
|
6
|
+
classnames: string;
|
|
6
7
|
};
|
|
7
8
|
export {};
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { classNames } from '../../utils/classNames';
|
|
3
|
+
import { buttonClassnames, buttonColorClassnames } from '../constants';
|
|
4
|
+
import { ButtonColors, ButtonVariants } from '../enums';
|
|
5
|
+
export const useLogic = ({ loading, selected, variant = ButtonVariants.Contained, color = variant === ButtonVariants.Text
|
|
6
|
+
? ButtonColors.Grey
|
|
7
|
+
: ButtonColors.Primary, disabled, className, }) => {
|
|
4
8
|
const loadingIndicatorColor = useMemo(() => {
|
|
5
9
|
if (variant !== ButtonVariants.Contained) {
|
|
6
10
|
return 'primary';
|
|
7
11
|
}
|
|
8
12
|
return 'inverted';
|
|
9
13
|
}, [variant]);
|
|
10
|
-
|
|
14
|
+
const classnames = useMemo(() => classNames(buttonClassnames.root, buttonColorClassnames[color], className, {
|
|
15
|
+
[buttonClassnames.loading]: loading,
|
|
16
|
+
[buttonClassnames.disabled]: disabled,
|
|
17
|
+
[buttonClassnames.selected]: selected,
|
|
18
|
+
}), [loading, selected, color, className, disabled]);
|
|
19
|
+
return { loadingIndicatorColor, classnames };
|
|
11
20
|
};
|
|
@@ -2,6 +2,7 @@ import { type ReactElement, type ReactNode } from 'react';
|
|
|
2
2
|
import { type UseFormReturn } from '../useForm';
|
|
3
3
|
import { type FIELD_NAME } from './constants';
|
|
4
4
|
import type { FormValues, ValidationFn } from './types';
|
|
5
|
+
export type ShowEditIconMode = 'always' | 'none' | 'onHover';
|
|
5
6
|
export type EditableTextProps<TValue = string> = {
|
|
6
7
|
/**
|
|
7
8
|
* Название класса, применяется к корневому компоненту
|
|
@@ -13,10 +14,18 @@ export type EditableTextProps<TValue = string> = {
|
|
|
13
14
|
*/
|
|
14
15
|
initialValue?: TValue;
|
|
15
16
|
/**
|
|
16
|
-
* Если false, иконка редактирования не будет
|
|
17
|
+
* Если false, иконка редактирования не будет отображаться.
|
|
18
|
+
* Для новых сценариев предпочтительнее `showEditIcon`.
|
|
19
|
+
* Если переданы оба параметра, для отображения иконки используется `showEditIcon`.
|
|
17
20
|
* @default true
|
|
18
21
|
*/
|
|
19
22
|
isShowIcon?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Режим отображения иконки редактирования (аналогично `CopyTypography.showCopyIcon`).
|
|
25
|
+
* Имеет приоритет над `isShowIcon`.
|
|
26
|
+
* @default если не задан — наследуется из `isShowIcon` (true → always, false → none)
|
|
27
|
+
*/
|
|
28
|
+
showEditIcon?: ShowEditIconMode;
|
|
20
29
|
/**
|
|
21
30
|
* Если true, будет отображаться лоадер
|
|
22
31
|
*/
|
|
@@ -1,17 +1,31 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { Tooltip } from '../../components/Tooltip';
|
|
3
|
+
import { classNames } from '../../components/utils/classNames';
|
|
4
|
+
import { editableTextClassnames } from './constants';
|
|
3
5
|
import { EditingForm } from './EditingForm';
|
|
4
6
|
import { DisplayValue, StyledEditIcon, StyledLoader, StyledPopover, } from './styles';
|
|
5
7
|
import { useLogic } from './useLogic';
|
|
8
|
+
const getShowEditIconMode = ({ showEditIcon, isShowIcon = true, }) => {
|
|
9
|
+
if (showEditIcon !== undefined) {
|
|
10
|
+
return showEditIcon;
|
|
11
|
+
}
|
|
12
|
+
return isShowIcon === false ? 'none' : 'always';
|
|
13
|
+
};
|
|
6
14
|
// biome-ignore lint/complexity/noUselessTypeConstraint: Фикс типизации в тестах
|
|
7
15
|
export const EditableText = (props) => {
|
|
8
16
|
const { isIconOnLeft, onClose, displayValueProps, tooltipProps, popoverProps, } = useLogic(props);
|
|
9
|
-
const { className, children, isShowIcon = true, isLoading, iconPosition = 'right', ...restProps } = props;
|
|
17
|
+
const { className, children, isShowIcon = true, isLoading, showEditIcon, iconPosition = 'right', ...restProps } = props;
|
|
18
|
+
const showEditIconMode = getShowEditIconMode({ showEditIcon, isShowIcon });
|
|
10
19
|
const renderIcon = () => {
|
|
11
20
|
if (isLoading) {
|
|
12
21
|
return _jsx(StyledLoader, { "$iconPosition": iconPosition });
|
|
13
22
|
}
|
|
14
|
-
|
|
23
|
+
if (showEditIconMode === 'none') {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return (_jsx(StyledEditIcon, { "$iconPosition": iconPosition, className: classNames({
|
|
27
|
+
[editableTextClassnames.showIconOnHover]: showEditIconMode === 'onHover',
|
|
28
|
+
}) }));
|
|
15
29
|
};
|
|
16
30
|
return (_jsxs(_Fragment, { children: [_jsx(Tooltip, { ...tooltipProps, placement: "bottom", children: _jsxs(DisplayValue, { "$isLoading": isLoading, className: className, variant: "inherit", ...displayValueProps, children: [isIconOnLeft && renderIcon(), children, !isIconOnLeft && renderIcon()] }) }), _jsx(StyledPopover, { anchorOrigin: {
|
|
17
31
|
vertical: 'bottom',
|
|
@@ -3,6 +3,7 @@ import { Popover } from '../../components/Popover';
|
|
|
3
3
|
import { styled } from '../../components/styled';
|
|
4
4
|
import { Typography } from '../../components/Typography';
|
|
5
5
|
import { EditOutlineMd } from '../../icons/EditOutlineMd';
|
|
6
|
+
import { editableTextClassnames } from './constants';
|
|
6
7
|
const getBackgroundColor = (theme, $isEdited, $isLoading) => {
|
|
7
8
|
if ($isEdited) {
|
|
8
9
|
return theme.palette.primary[100];
|
|
@@ -33,6 +34,10 @@ export const DisplayValue = styled(Typography, {
|
|
|
33
34
|
cursor: ${({ $isLoading }) => ($isLoading ? 'default' : 'pointer')};
|
|
34
35
|
|
|
35
36
|
text-decoration: ${({ $isLoading }) => $isLoading ? 'inherit' : 'underline'};
|
|
37
|
+
|
|
38
|
+
.${editableTextClassnames.showIconOnHover} {
|
|
39
|
+
display: unset;
|
|
40
|
+
}
|
|
36
41
|
}
|
|
37
42
|
`;
|
|
38
43
|
export const StyledEditIcon = styled(EditOutlineMd, {
|
|
@@ -49,6 +54,10 @@ export const StyledEditIcon = styled(EditOutlineMd, {
|
|
|
49
54
|
margin-left: ${({ $iconPosition, theme }) => $iconPosition === 'right' ? theme.spacing(1) : ''};
|
|
50
55
|
|
|
51
56
|
font-size: inherit;
|
|
57
|
+
|
|
58
|
+
&.${editableTextClassnames.showIconOnHover} {
|
|
59
|
+
display: none;
|
|
60
|
+
}
|
|
52
61
|
`;
|
|
53
62
|
export const StyledLoader = styled(Loader, {
|
|
54
63
|
shouldForwardProp: (prop) => !['$iconPosition'].includes(prop),
|
|
@@ -3,21 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Button = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const forwardRefWithGeneric_1 = require("../forwardRefWithGeneric");
|
|
6
|
-
const classNames_1 = require("../utils/classNames");
|
|
7
|
-
const constants_1 = require("./constants");
|
|
8
6
|
const enums_1 = require("./enums");
|
|
9
7
|
const styles_1 = require("./styles");
|
|
10
8
|
const useLogic_1 = require("./useLogic");
|
|
11
9
|
const UnwrappedButton = (props, ref) => {
|
|
12
|
-
const { loadingIndicatorColor } = (0, useLogic_1.useLogic)(props);
|
|
10
|
+
const { loadingIndicatorColor, classnames } = (0, useLogic_1.useLogic)(props);
|
|
13
11
|
const { variant = enums_1.ButtonVariants.Contained, color = variant === enums_1.ButtonVariants.Text
|
|
14
12
|
? enums_1.ButtonColors.Grey
|
|
15
13
|
: enums_1.ButtonColors.Primary, loading, disabled, children, className, selected, ...restProps } = props;
|
|
16
|
-
return ((0, jsx_runtime_1.jsxs)(styles_1.StyledButton, { variant: variant, ref: ref, color: color, disabled: disabled || loading, selected: selected, ...restProps, className: (0,
|
|
17
|
-
[constants_1.buttonClassnames.loading]: loading,
|
|
18
|
-
[constants_1.buttonClassnames.selected]: selected,
|
|
19
|
-
[constants_1.buttonClassnames.disabled]: disabled,
|
|
20
|
-
}), "aria-disabled": loading, children: [loading && ((0, jsx_runtime_1.jsx)(styles_1.StyledLoader, { color: loadingIndicatorColor, size: "small", "$color": color, "$variant": variant, "$isDisabled": disabled })), children] }));
|
|
14
|
+
return ((0, jsx_runtime_1.jsxs)(styles_1.StyledButton, { variant: variant, ref: ref, color: color, disabled: disabled || loading, selected: selected, ...restProps, className: classnames, "aria-disabled": loading, children: [loading && ((0, jsx_runtime_1.jsx)(styles_1.StyledLoader, { color: loadingIndicatorColor, size: "small", "$color": color, "$variant": variant, "$isDisabled": disabled })), children] }));
|
|
21
15
|
};
|
|
22
16
|
exports.Button = (0, forwardRefWithGeneric_1.forwardRefWithGeneric)(UnwrappedButton);
|
|
23
17
|
exports.default = exports.Button;
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
export { buttonClasses } from '@mui/material/Button';
|
|
2
|
+
export declare const buttonColorClassnames: {
|
|
3
|
+
primary: string;
|
|
4
|
+
error: string;
|
|
5
|
+
success: string;
|
|
6
|
+
warning: string;
|
|
7
|
+
grey: string;
|
|
8
|
+
};
|
|
2
9
|
export declare const buttonClassnames: {
|
|
10
|
+
primary: string;
|
|
11
|
+
error: string;
|
|
12
|
+
success: string;
|
|
13
|
+
warning: string;
|
|
14
|
+
grey: string;
|
|
3
15
|
root: string;
|
|
4
16
|
loading: string;
|
|
5
17
|
selected: string;
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buttonClassnames = exports.buttonClasses = void 0;
|
|
3
|
+
exports.buttonClassnames = exports.buttonColorClassnames = exports.buttonClasses = void 0;
|
|
4
4
|
const createUIKitClassname_1 = require("../utils/createUIKitClassname");
|
|
5
|
+
const enums_1 = require("./enums");
|
|
5
6
|
var Button_1 = require("@mui/material/Button");
|
|
6
7
|
Object.defineProperty(exports, "buttonClasses", { enumerable: true, get: function () { return Button_1.buttonClasses; } });
|
|
8
|
+
exports.buttonColorClassnames = {
|
|
9
|
+
[enums_1.ButtonColors.Primary]: (0, createUIKitClassname_1.createUIKitClassname)('button_color-primary'),
|
|
10
|
+
[enums_1.ButtonColors.Error]: (0, createUIKitClassname_1.createUIKitClassname)('button_color-error'),
|
|
11
|
+
[enums_1.ButtonColors.Success]: (0, createUIKitClassname_1.createUIKitClassname)('button_color-success'),
|
|
12
|
+
[enums_1.ButtonColors.Warning]: (0, createUIKitClassname_1.createUIKitClassname)('button_color-warning'),
|
|
13
|
+
[enums_1.ButtonColors.Grey]: (0, createUIKitClassname_1.createUIKitClassname)('button_color-grey'),
|
|
14
|
+
};
|
|
7
15
|
exports.buttonClassnames = {
|
|
8
16
|
root: (0, createUIKitClassname_1.createUIKitClassname)('button'),
|
|
9
17
|
loading: (0, createUIKitClassname_1.createUIKitClassname)('button_loading'),
|
|
10
18
|
selected: (0, createUIKitClassname_1.createUIKitClassname)('button_selected'),
|
|
11
19
|
disabled: (0, createUIKitClassname_1.createUIKitClassname)('button_disabled'),
|
|
20
|
+
...exports.buttonColorClassnames,
|
|
12
21
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type ButtonProps } from '../types';
|
|
2
2
|
type UseLogicParam = ButtonProps;
|
|
3
3
|
type Color = 'primary' | 'inverted';
|
|
4
|
-
export declare const useLogic: ({ variant, }: UseLogicParam) => {
|
|
4
|
+
export declare const useLogic: ({ loading, selected, variant, color, disabled, className, }: UseLogicParam) => {
|
|
5
5
|
loadingIndicatorColor: Color;
|
|
6
|
+
classnames: string;
|
|
6
7
|
};
|
|
7
8
|
export {};
|
|
@@ -2,14 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useLogic = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
+
const classNames_1 = require("../../utils/classNames");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
5
7
|
const enums_1 = require("../enums");
|
|
6
|
-
const useLogic = ({ variant = enums_1.ButtonVariants.Contained,
|
|
8
|
+
const useLogic = ({ loading, selected, variant = enums_1.ButtonVariants.Contained, color = variant === enums_1.ButtonVariants.Text
|
|
9
|
+
? enums_1.ButtonColors.Grey
|
|
10
|
+
: enums_1.ButtonColors.Primary, disabled, className, }) => {
|
|
7
11
|
const loadingIndicatorColor = (0, react_1.useMemo)(() => {
|
|
8
12
|
if (variant !== enums_1.ButtonVariants.Contained) {
|
|
9
13
|
return 'primary';
|
|
10
14
|
}
|
|
11
15
|
return 'inverted';
|
|
12
16
|
}, [variant]);
|
|
13
|
-
|
|
17
|
+
const classnames = (0, react_1.useMemo)(() => (0, classNames_1.classNames)(constants_1.buttonClassnames.root, constants_1.buttonColorClassnames[color], className, {
|
|
18
|
+
[constants_1.buttonClassnames.loading]: loading,
|
|
19
|
+
[constants_1.buttonClassnames.disabled]: disabled,
|
|
20
|
+
[constants_1.buttonClassnames.selected]: selected,
|
|
21
|
+
}), [loading, selected, color, className, disabled]);
|
|
22
|
+
return { loadingIndicatorColor, classnames };
|
|
14
23
|
};
|
|
15
24
|
exports.useLogic = useLogic;
|
|
@@ -2,6 +2,7 @@ import { type ReactElement, type ReactNode } from 'react';
|
|
|
2
2
|
import { type UseFormReturn } from '../useForm';
|
|
3
3
|
import { type FIELD_NAME } from './constants';
|
|
4
4
|
import type { FormValues, ValidationFn } from './types';
|
|
5
|
+
export type ShowEditIconMode = 'always' | 'none' | 'onHover';
|
|
5
6
|
export type EditableTextProps<TValue = string> = {
|
|
6
7
|
/**
|
|
7
8
|
* Название класса, применяется к корневому компоненту
|
|
@@ -13,10 +14,18 @@ export type EditableTextProps<TValue = string> = {
|
|
|
13
14
|
*/
|
|
14
15
|
initialValue?: TValue;
|
|
15
16
|
/**
|
|
16
|
-
* Если false, иконка редактирования не будет
|
|
17
|
+
* Если false, иконка редактирования не будет отображаться.
|
|
18
|
+
* Для новых сценариев предпочтительнее `showEditIcon`.
|
|
19
|
+
* Если переданы оба параметра, для отображения иконки используется `showEditIcon`.
|
|
17
20
|
* @default true
|
|
18
21
|
*/
|
|
19
22
|
isShowIcon?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Режим отображения иконки редактирования (аналогично `CopyTypography.showCopyIcon`).
|
|
25
|
+
* Имеет приоритет над `isShowIcon`.
|
|
26
|
+
* @default если не задан — наследуется из `isShowIcon` (true → always, false → none)
|
|
27
|
+
*/
|
|
28
|
+
showEditIcon?: ShowEditIconMode;
|
|
20
29
|
/**
|
|
21
30
|
* Если true, будет отображаться лоадер
|
|
22
31
|
*/
|
|
@@ -3,18 +3,32 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.EditableText = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const Tooltip_1 = require("../../components/Tooltip");
|
|
6
|
+
const classNames_1 = require("../../components/utils/classNames");
|
|
7
|
+
const constants_1 = require("./constants");
|
|
6
8
|
const EditingForm_1 = require("./EditingForm");
|
|
7
9
|
const styles_1 = require("./styles");
|
|
8
10
|
const useLogic_1 = require("./useLogic");
|
|
11
|
+
const getShowEditIconMode = ({ showEditIcon, isShowIcon = true, }) => {
|
|
12
|
+
if (showEditIcon !== undefined) {
|
|
13
|
+
return showEditIcon;
|
|
14
|
+
}
|
|
15
|
+
return isShowIcon === false ? 'none' : 'always';
|
|
16
|
+
};
|
|
9
17
|
// biome-ignore lint/complexity/noUselessTypeConstraint: Фикс типизации в тестах
|
|
10
18
|
const EditableText = (props) => {
|
|
11
19
|
const { isIconOnLeft, onClose, displayValueProps, tooltipProps, popoverProps, } = (0, useLogic_1.useLogic)(props);
|
|
12
|
-
const { className, children, isShowIcon = true, isLoading, iconPosition = 'right', ...restProps } = props;
|
|
20
|
+
const { className, children, isShowIcon = true, isLoading, showEditIcon, iconPosition = 'right', ...restProps } = props;
|
|
21
|
+
const showEditIconMode = getShowEditIconMode({ showEditIcon, isShowIcon });
|
|
13
22
|
const renderIcon = () => {
|
|
14
23
|
if (isLoading) {
|
|
15
24
|
return (0, jsx_runtime_1.jsx)(styles_1.StyledLoader, { "$iconPosition": iconPosition });
|
|
16
25
|
}
|
|
17
|
-
|
|
26
|
+
if (showEditIconMode === 'none') {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return ((0, jsx_runtime_1.jsx)(styles_1.StyledEditIcon, { "$iconPosition": iconPosition, className: (0, classNames_1.classNames)({
|
|
30
|
+
[constants_1.editableTextClassnames.showIconOnHover]: showEditIconMode === 'onHover',
|
|
31
|
+
}) }));
|
|
18
32
|
};
|
|
19
33
|
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Tooltip_1.Tooltip, { ...tooltipProps, placement: "bottom", children: (0, jsx_runtime_1.jsxs)(styles_1.DisplayValue, { "$isLoading": isLoading, className: className, variant: "inherit", ...displayValueProps, children: [isIconOnLeft && renderIcon(), children, !isIconOnLeft && renderIcon()] }) }), (0, jsx_runtime_1.jsx)(styles_1.StyledPopover, { anchorOrigin: {
|
|
20
34
|
vertical: 'bottom',
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FIELD_NAME = void 0;
|
|
3
|
+
exports.editableTextClassnames = exports.FIELD_NAME = void 0;
|
|
4
|
+
const createUIKitClassname_1 = require("../../components/utils/createUIKitClassname");
|
|
4
5
|
exports.FIELD_NAME = 'editableField';
|
|
6
|
+
exports.editableTextClassnames = {
|
|
7
|
+
showIconOnHover: (0, createUIKitClassname_1.createUIKitClassname)('editable-text__edit-icon_show-on-hover'),
|
|
8
|
+
};
|
|
@@ -6,6 +6,7 @@ const Popover_1 = require("../../components/Popover");
|
|
|
6
6
|
const styled_1 = require("../../components/styled");
|
|
7
7
|
const Typography_1 = require("../../components/Typography");
|
|
8
8
|
const EditOutlineMd_1 = require("../../icons/EditOutlineMd");
|
|
9
|
+
const constants_1 = require("./constants");
|
|
9
10
|
const getBackgroundColor = (theme, $isEdited, $isLoading) => {
|
|
10
11
|
if ($isEdited) {
|
|
11
12
|
return theme.palette.primary[100];
|
|
@@ -36,6 +37,10 @@ exports.DisplayValue = (0, styled_1.styled)(Typography_1.Typography, {
|
|
|
36
37
|
cursor: ${({ $isLoading }) => ($isLoading ? 'default' : 'pointer')};
|
|
37
38
|
|
|
38
39
|
text-decoration: ${({ $isLoading }) => $isLoading ? 'inherit' : 'underline'};
|
|
40
|
+
|
|
41
|
+
.${constants_1.editableTextClassnames.showIconOnHover} {
|
|
42
|
+
display: unset;
|
|
43
|
+
}
|
|
39
44
|
}
|
|
40
45
|
`;
|
|
41
46
|
exports.StyledEditIcon = (0, styled_1.styled)(EditOutlineMd_1.EditOutlineMd, {
|
|
@@ -52,6 +57,10 @@ exports.StyledEditIcon = (0, styled_1.styled)(EditOutlineMd_1.EditOutlineMd, {
|
|
|
52
57
|
margin-left: ${({ $iconPosition, theme }) => $iconPosition === 'right' ? theme.spacing(1) : ''};
|
|
53
58
|
|
|
54
59
|
font-size: inherit;
|
|
60
|
+
|
|
61
|
+
&.${constants_1.editableTextClassnames.showIconOnHover} {
|
|
62
|
+
display: none;
|
|
63
|
+
}
|
|
55
64
|
`;
|
|
56
65
|
exports.StyledLoader = (0, styled_1.styled)(Loader_1.Loader, {
|
|
57
66
|
shouldForwardProp: (prop) => !['$iconPosition'].includes(prop),
|