@antscorp/antsomi-ui 1.3.5-beta.278 → 1.3.5-beta.280

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.
@@ -1,6 +1,7 @@
1
1
  import Icon from '@antscorp/icons';
2
2
  import React, { useCallback, useMemo, useState } from 'react';
3
- import { Input, Text } from '@antscorp/antsomi-ui/es/components/atoms';
3
+ import { Input } from 'antd';
4
+ import { Text } from '@antscorp/antsomi-ui/es/components/atoms';
4
5
  import { AccountItem } from './components';
5
6
  import { AccountSelectionStyled } from './styled';
6
7
  import { PORTALS_IDS } from '@antscorp/antsomi-ui/es/constants';
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ export interface EditableNameHandle {
3
+ value: () => string;
4
+ }
5
+ interface EditableNameProps {
6
+ className?: string;
7
+ isLoading?: boolean;
8
+ defaultValue?: string;
9
+ required?: boolean;
10
+ error?: string;
11
+ value?: string;
12
+ onBlur?: React.FocusEventHandler<HTMLInputElement>;
13
+ onChange?: (value: string) => void;
14
+ }
15
+ export declare const EditableName: React.ForwardRefExoticComponent<EditableNameProps & React.RefAttributes<EditableNameHandle>>;
16
+ export {};
@@ -0,0 +1,53 @@
1
+ import React, { useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
2
+ import { InputWrapperStyled } from './styled';
3
+ import { Input, Tooltip } from 'antd';
4
+ import { THEME } from '@antscorp/antsomi-ui/es/constants';
5
+ import Icon from '@antscorp/icons';
6
+ import { Spin } from '../../atoms';
7
+ export const EditableName = React.forwardRef((props, ref) => {
8
+ var _a;
9
+ const { className, isLoading, defaultValue, required, error, value, onBlur, onChange } = props;
10
+ const [inputWidth, setInputWidth] = useState(1);
11
+ const [internalValue, setInternalValue] = useState(defaultValue || '');
12
+ const requiredError = useMemo(() => (required && internalValue.trim().length === 0 ? 'This field is required' : ''), [required, internalValue]);
13
+ const spanRef = useRef(null);
14
+ const inputRef = useRef(null);
15
+ useImperativeHandle(ref, () => ({
16
+ value() {
17
+ return internalValue;
18
+ },
19
+ }), [internalValue]);
20
+ const onKeyDown = (e) => {
21
+ var _a;
22
+ if (e.key === 'Enter') {
23
+ onChange === null || onChange === void 0 ? void 0 : onChange(e.currentTarget.value);
24
+ (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
25
+ }
26
+ };
27
+ useEffect(() => {
28
+ var _a;
29
+ if (spanRef.current) {
30
+ spanRef.current.innerText = value || defaultValue || '';
31
+ setInputWidth(((_a = spanRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 1);
32
+ }
33
+ // NOTE: the defaultValue props should need use only one time and don't change in component life circle
34
+ // eslint-disable-next-line react-hooks/exhaustive-deps
35
+ }, []);
36
+ return (React.createElement(InputWrapperStyled, { className: className || '' },
37
+ React.createElement(Tooltip, { title: value || internalValue },
38
+ React.createElement(Input, { ref: inputRef, style: { width: inputWidth + 2 }, defaultValue: defaultValue, value: value, onChange: event => {
39
+ var _a;
40
+ const newValue = event.target.value;
41
+ if (spanRef.current)
42
+ spanRef.current.innerText = newValue;
43
+ setInputWidth(((_a = spanRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 1);
44
+ setInternalValue(newValue);
45
+ onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
46
+ }, onBlur: onBlur, onKeyDown: onKeyDown })),
47
+ isLoading ? (React.createElement(Spin, { indicatorSize: 20, style: { paddingLeft: '5px', marginLeft: '10px' } })) : null,
48
+ (error || requiredError) && !isLoading ? (React.createElement("div", { className: "suffix-icon-error" },
49
+ React.createElement(Tooltip, { title: error || requiredError },
50
+ React.createElement(Icon, { type: "icon-ants-warning-circle", style: { color: '#F44336', fontSize: '19.2px' } })))) : (React.createElement("div", { className: "suffix-icon" },
51
+ React.createElement(Icon, { type: "icon-ants-pencil", style: { color: (_a = THEME.token) === null || _a === void 0 ? void 0 : _a.blue7, fontSize: '24px' } }))),
52
+ React.createElement("span", { ref: spanRef, className: "hidden-span" })));
53
+ });
@@ -0,0 +1 @@
1
+ export { EditableName, EditableNameHandle } from './EditableName';
@@ -0,0 +1 @@
1
+ export { EditableName } from './EditableName';
@@ -0,0 +1 @@
1
+ export declare const InputWrapperStyled: import("styled-components").StyledComponent<"div", any, {}, never>;
@@ -0,0 +1,67 @@
1
+ var _a;
2
+ import styled from 'styled-components';
3
+ import { THEME } from '@antscorp/antsomi-ui/es/constants';
4
+ export const InputWrapperStyled = styled.div `
5
+ display: inline-block;
6
+ position: relative;
7
+ background-color: #fff;
8
+ border-bottom: 1px solid transparent;
9
+ max-width: 100%;
10
+
11
+ display: inline-flex;
12
+ align-items: baseline;
13
+
14
+ &:has(input:focus) {
15
+ border-bottom: 1px solid ${(_a = THEME.token) === null || _a === void 0 ? void 0 : _a.blue1};
16
+ }
17
+
18
+ input {
19
+ font-size: 20px !important;
20
+ font-weight: 700;
21
+ min-width: 23px !important;
22
+ height: 30px;
23
+ transition: none !important;
24
+ padding: 5px 0 !important;
25
+ border: none !important;
26
+ text-overflow: ellipsis;
27
+ }
28
+
29
+ .suffix-icon-error,
30
+ .suffix-icon {
31
+ display: flex;
32
+ align-self: stretch;
33
+ align-items: center;
34
+ padding: 0 5px;
35
+ margin-left: 10px;
36
+ }
37
+
38
+ .suffix-icon {
39
+ display: none;
40
+ }
41
+
42
+ input:hover {
43
+ background-color: transparent;
44
+
45
+ & + .suffix-icon {
46
+ display: flex;
47
+ }
48
+ }
49
+
50
+ input:focus + .suffix-icon {
51
+ display: none;
52
+ }
53
+
54
+ .hidden-span {
55
+ box-sizing: border-box;
56
+ visibility: hidden;
57
+ white-space: pre;
58
+ position: absolute;
59
+ top: 0;
60
+ left: 0;
61
+ height: 30px;
62
+ font-family: inherit;
63
+ font-size: 20px;
64
+ font-weight: 700;
65
+ padding: 5px 0; /* Match the padding of the Input component */
66
+ }
67
+ `;
@@ -46,6 +46,7 @@ export * from './SelectMulti';
46
46
  export * from './SelectEventAttribute';
47
47
  export * from './DatePickerV2';
48
48
  export { ModalSelect } from './ModalSelect';
49
+ export { EditableName } from './EditableName';
49
50
  export * from './EmptyData';
50
51
  export * from './PreviewModal';
51
52
  export * from './Drawer';
@@ -65,3 +66,4 @@ export type { SelectProps as SelectV2Props } from './SelectV2';
65
66
  export type { InputNumberProps as InputNumberWithLabelProps } from './InputNumber';
66
67
  export type { ModalSelectProps } from './ModalSelect';
67
68
  export type { ImageResizeHandle } from './ImageEditor';
69
+ export type { EditableNameHandle } from './EditableName';
@@ -46,6 +46,7 @@ export * from './SelectMulti';
46
46
  export * from './SelectEventAttribute';
47
47
  export * from './DatePickerV2';
48
48
  export { ModalSelect } from './ModalSelect';
49
+ export { EditableName } from './EditableName';
49
50
  export * from './EmptyData';
50
51
  export * from './PreviewModal';
51
52
  export * from './Drawer';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.5-beta.278",
3
+ "version": "1.3.5-beta.280",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",