ag-common 0.0.220 → 0.0.221
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,55 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import { ITextEdit } from './types';
|
|
2
3
|
import { StyledComponent } from 'styled-components';
|
|
3
4
|
export declare const ValueReadonly: StyledComponent<"div", any, {}, never>;
|
|
4
|
-
export declare const TextEdit: ({ defaultValue, defaultEditing, disableEdit, placeholder, className, singleLine, noGrow, attributes, leftContent, onSubmit, onEditingChange, onClickOutsideWithNoValue, onClickNotEditing, allowUndo, onEscape, }:
|
|
5
|
-
/**
|
|
6
|
-
* forces single row input style. will also enable 'Enter' to auto submit
|
|
7
|
-
*/
|
|
8
|
-
singleLine?: boolean | undefined;
|
|
9
|
-
className?: string | undefined;
|
|
10
|
-
/**
|
|
11
|
-
* default value of field. default empty
|
|
12
|
-
*/
|
|
13
|
-
defaultValue?: string | undefined;
|
|
14
|
-
/**
|
|
15
|
-
* if truthy will enable text edit mode by default. if focus is true, will also focus on open
|
|
16
|
-
*/
|
|
17
|
-
defaultEditing?: {
|
|
18
|
-
focus?: boolean | undefined;
|
|
19
|
-
} | undefined;
|
|
20
|
-
onSubmit: (val: string, enterPressed: boolean) => void;
|
|
21
|
-
/**
|
|
22
|
-
* disable edit text functionality
|
|
23
|
-
*/
|
|
24
|
-
disableEdit?: boolean | undefined;
|
|
25
|
-
placeholder?: string | undefined;
|
|
26
|
-
/**
|
|
27
|
-
* when the user edits or unselects edit
|
|
28
|
-
*/
|
|
29
|
-
onEditingChange?: ((editing: boolean) => void) | undefined;
|
|
30
|
-
/**
|
|
31
|
-
* if null will disable click outside
|
|
32
|
-
*/
|
|
33
|
-
onClickOutsideWithNoValue?: (() => void) | null | undefined;
|
|
34
|
-
onClickNotEditing?: (() => void) | undefined;
|
|
35
|
-
/**
|
|
36
|
-
* if true, will not grow. default false
|
|
37
|
-
*/
|
|
38
|
-
noGrow?: boolean | undefined;
|
|
39
|
-
/**
|
|
40
|
-
* will set these attributes directly on element. can put data-* here
|
|
41
|
-
*/
|
|
42
|
-
attributes?: Record<string, string | number | boolean> | undefined;
|
|
43
|
-
/**
|
|
44
|
-
* optional content at the left of the box
|
|
45
|
-
*/
|
|
46
|
-
leftContent?: JSX.Element | undefined;
|
|
47
|
-
/**
|
|
48
|
-
* if true, will add undo button after changes. if false, will submit after every keypress. default true
|
|
49
|
-
*/
|
|
50
|
-
allowUndo?: boolean | undefined;
|
|
51
|
-
/**
|
|
52
|
-
* will call on user pressed escape
|
|
53
|
-
*/
|
|
54
|
-
onEscape?: (() => void) | undefined;
|
|
55
|
-
}) => JSX.Element;
|
|
5
|
+
export declare const TextEdit: ({ defaultValue, defaultEditing, disableEdit, placeholder, className, singleLine, noGrow, attributes, leftContent, onSubmit, onEditingChange, onClickOutsideWithNoValue, onClickNotEditing, allowUndo, onEscape, maxLength, onKeyDown, }: ITextEdit) => JSX.Element;
|
|
@@ -73,7 +73,7 @@ const Icon = styled_components_1.default.div `
|
|
|
73
73
|
filter: saturate(3);
|
|
74
74
|
}
|
|
75
75
|
`;
|
|
76
|
-
const TextEdit = ({ defaultValue = '', defaultEditing, disableEdit = false, placeholder, className, singleLine = false, noGrow = false, attributes, leftContent, onSubmit, onEditingChange, onClickOutsideWithNoValue, onClickNotEditing, allowUndo = true, onEscape, }) => {
|
|
76
|
+
const TextEdit = ({ defaultValue = '', defaultEditing, disableEdit = false, placeholder, className, singleLine = false, noGrow = false, attributes, leftContent, onSubmit, onEditingChange, onClickOutsideWithNoValue, onClickNotEditing, allowUndo = true, onEscape, maxLength, onKeyDown, }) => {
|
|
77
77
|
const ref = (0, react_1.useRef)(null);
|
|
78
78
|
const taref = (0, react_1.useRef)(null);
|
|
79
79
|
const [value, setValue] = (0, react_1.useState)(defaultValue);
|
|
@@ -138,7 +138,11 @@ const TextEdit = ({ defaultValue = '', defaultEditing, disableEdit = false, plac
|
|
|
138
138
|
if (!allowUndo) {
|
|
139
139
|
onSubmit(v.currentTarget.value, false);
|
|
140
140
|
}
|
|
141
|
-
}, placeholder: placeholder, rows: singleLine ? 1 : undefined, onKeyDown: (e) => {
|
|
141
|
+
}, placeholder: placeholder, rows: singleLine ? 1 : undefined, maxLength: maxLength, onKeyDown: (e) => {
|
|
142
|
+
if ((onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e)) === false) {
|
|
143
|
+
e.preventDefault();
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
142
146
|
if (singleLine && e.code.endsWith('Enter')) {
|
|
143
147
|
onSubmit(value, true);
|
|
144
148
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface ITextEdit {
|
|
3
|
+
/**
|
|
4
|
+
* forces single row input style. will also enable 'Enter' to auto submit
|
|
5
|
+
*/
|
|
6
|
+
singleLine?: boolean;
|
|
7
|
+
className?: string;
|
|
8
|
+
/**
|
|
9
|
+
* default value of field. default empty
|
|
10
|
+
*/
|
|
11
|
+
defaultValue?: string;
|
|
12
|
+
/**
|
|
13
|
+
* if truthy will enable text edit mode by default. if focus is true, will also focus on open
|
|
14
|
+
*/
|
|
15
|
+
defaultEditing?: {
|
|
16
|
+
focus?: boolean;
|
|
17
|
+
};
|
|
18
|
+
onSubmit: (val: string,
|
|
19
|
+
/**
|
|
20
|
+
* if true, was passed by pressing Enter
|
|
21
|
+
*/
|
|
22
|
+
enterPressed: boolean) => void;
|
|
23
|
+
/**
|
|
24
|
+
* disable edit text functionality
|
|
25
|
+
*/
|
|
26
|
+
disableEdit?: boolean;
|
|
27
|
+
placeholder?: string;
|
|
28
|
+
/**
|
|
29
|
+
* when the user edits or unselects edit
|
|
30
|
+
*/
|
|
31
|
+
onEditingChange?: (editing: boolean) => void;
|
|
32
|
+
/**
|
|
33
|
+
* if null will disable click outside
|
|
34
|
+
*/
|
|
35
|
+
onClickOutsideWithNoValue?: (() => void) | null;
|
|
36
|
+
onClickNotEditing?: () => void;
|
|
37
|
+
/**
|
|
38
|
+
* if true, will not grow. default false
|
|
39
|
+
*/
|
|
40
|
+
noGrow?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* will set these attributes directly on element. can put data-* here
|
|
43
|
+
*/
|
|
44
|
+
attributes?: Record<string, string | number | boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* optional content at the left of the box
|
|
47
|
+
*/
|
|
48
|
+
leftContent?: JSX.Element;
|
|
49
|
+
/**
|
|
50
|
+
* if true, will add undo button after changes. if false, will submit after every keypress. default true
|
|
51
|
+
*/
|
|
52
|
+
allowUndo?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* will call on user pressed escape
|
|
55
|
+
*/
|
|
56
|
+
onEscape?: () => void;
|
|
57
|
+
maxLength?: number;
|
|
58
|
+
/**
|
|
59
|
+
* if provided and return false, will cancel keydown
|
|
60
|
+
*/
|
|
61
|
+
onKeyDown?: (e: React.KeyboardEvent<HTMLTextAreaElement>) => boolean;
|
|
62
|
+
}
|