@astral/ui 4.39.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/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/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
|
@@ -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),
|
|
@@ -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),
|