carbon-react 110.2.0 → 110.2.3
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/esm/__internal__/character-count/character-count.component.d.ts +8 -25
- package/esm/__internal__/character-count/character-count.component.js +12 -18
- package/esm/__internal__/character-count/character-count.style.d.ts +3 -1
- package/esm/__internal__/character-count/character-count.style.js +4 -0
- package/esm/__internal__/checkable-input/checkable-input-svg-wrapper.style.d.ts +1 -1
- package/esm/__internal__/checkable-input/checkable-input.component.d.ts +50 -0
- package/esm/__internal__/checkable-input/checkable-input.component.js +360 -98
- package/esm/__internal__/checkable-input/checkable-input.style.d.ts +11 -2
- package/esm/__internal__/checkable-input/checkable-input.style.js +0 -7
- package/esm/__internal__/checkable-input/hidden-checkable-input.component.d.ts +31 -0
- package/esm/__internal__/checkable-input/hidden-checkable-input.component.js +301 -45
- package/esm/__internal__/checkable-input/hidden-checkable-input.style.d.ts +1 -1
- package/esm/__internal__/checkable-input/index.d.ts +2 -5
- package/esm/__internal__/input/index.d.ts +1 -1
- package/esm/__internal__/input/input-presentation.style.d.ts +1 -1
- package/esm/__internal__/input/input.style.d.ts +1 -1
- package/esm/components/flat-table/flat-table-row/flat-table-row.style.js +1 -0
- package/esm/components/numeral-date/numeral-date-context.d.ts +6 -0
- package/esm/components/popover-container/popover-container.component.d.ts +2 -0
- package/esm/components/popover-container/popover-container.component.js +9 -4
- package/esm/components/select/multi-select/multi-select.component.js +1 -1
- package/esm/components/select/select-list/select-list.component.js +20 -11
- package/esm/components/textarea/textarea.component.js +6 -27
- package/esm/components/textarea/textarea.d.ts +2 -1
- package/esm/components/textbox/__internal__/prefix.style.d.ts +2 -0
- package/esm/components/textbox/index.d.ts +2 -1
- package/esm/components/textbox/index.js +1 -1
- package/esm/components/textbox/textbox.component.d.ts +92 -0
- package/esm/components/textbox/textbox.component.js +533 -197
- package/esm/components/textbox/textbox.style.d.ts +5 -0
- package/esm/components/textbox/textbox.style.js +0 -12
- package/esm/hooks/__internal__/useCharacterCount/useCharacterCount.d.ts +1 -1
- package/esm/hooks/__internal__/useCharacterCount/useCharacterCount.js +7 -6
- package/esm/hooks/__internal__/useInputAccessibility/useInputAccessibility.d.ts +6 -5
- package/lib/__internal__/character-count/character-count.component.d.ts +8 -25
- package/lib/__internal__/character-count/character-count.component.js +13 -23
- package/lib/__internal__/character-count/character-count.style.d.ts +3 -1
- package/lib/__internal__/character-count/character-count.style.js +7 -0
- package/lib/__internal__/checkable-input/checkable-input-svg-wrapper.style.d.ts +1 -1
- package/lib/__internal__/checkable-input/checkable-input.component.d.ts +50 -0
- package/lib/__internal__/checkable-input/checkable-input.component.js +360 -98
- package/lib/__internal__/checkable-input/checkable-input.style.d.ts +11 -2
- package/lib/__internal__/checkable-input/checkable-input.style.js +1 -9
- package/lib/__internal__/checkable-input/hidden-checkable-input.component.d.ts +31 -0
- package/lib/__internal__/checkable-input/hidden-checkable-input.component.js +301 -45
- package/lib/__internal__/checkable-input/hidden-checkable-input.style.d.ts +1 -1
- package/lib/__internal__/checkable-input/index.d.ts +2 -5
- package/lib/__internal__/input/index.d.ts +1 -1
- package/lib/__internal__/input/input-presentation.style.d.ts +1 -1
- package/lib/__internal__/input/input.style.d.ts +1 -1
- package/lib/components/flat-table/flat-table-row/flat-table-row.style.js +1 -0
- package/lib/components/numeral-date/numeral-date-context.d.ts +6 -0
- package/lib/components/popover-container/popover-container.component.d.ts +2 -0
- package/lib/components/popover-container/popover-container.component.js +9 -4
- package/lib/components/select/multi-select/multi-select.component.js +1 -1
- package/lib/components/select/select-list/select-list.component.js +20 -11
- package/lib/components/textarea/textarea.component.js +6 -27
- package/lib/components/textarea/textarea.d.ts +2 -1
- package/lib/components/textbox/__internal__/prefix.style.d.ts +2 -0
- package/lib/components/textbox/index.d.ts +2 -1
- package/lib/components/textbox/index.js +2 -10
- package/lib/components/textbox/textbox.component.d.ts +92 -0
- package/lib/components/textbox/textbox.component.js +534 -201
- package/lib/components/textbox/textbox.style.d.ts +5 -0
- package/lib/components/textbox/textbox.style.js +1 -16
- package/lib/hooks/__internal__/useCharacterCount/useCharacterCount.d.ts +1 -1
- package/lib/hooks/__internal__/useCharacterCount/useCharacterCount.js +7 -6
- package/lib/hooks/__internal__/useInputAccessibility/useInputAccessibility.d.ts +6 -5
- package/package.json +1 -1
- package/esm/__internal__/checkable-input/checkable-input.d.ts +0 -55
- package/esm/__internal__/checkable-input/hidden-checkable-input.d.ts +0 -42
- package/esm/components/textbox/textbox.d.ts +0 -125
- package/lib/__internal__/checkable-input/checkable-input.d.ts +0 -55
- package/lib/__internal__/checkable-input/hidden-checkable-input.d.ts +0 -42
- package/lib/components/textbox/textbox.d.ts +0 -125
|
@@ -5,22 +5,18 @@ import PropTypes from "prop-types";
|
|
|
5
5
|
import styledSystemPropTypes from "@styled-system/prop-types";
|
|
6
6
|
import { InputPresentation } from "../../__internal__/input";
|
|
7
7
|
import FormField from "../../__internal__/form-field";
|
|
8
|
-
import
|
|
8
|
+
import useCharacterCount from "../../hooks/__internal__/useCharacterCount";
|
|
9
9
|
import Input from "../../__internal__/input/input.component";
|
|
10
10
|
import { InputBehaviour } from "../../__internal__/input-behaviour";
|
|
11
11
|
import { filterStyledSystemMarginProps } from "../../style/utils";
|
|
12
12
|
import InputIconToggle from "../../__internal__/input-icon-toggle";
|
|
13
13
|
import guid from "../../__internal__/utils/helpers/guid";
|
|
14
14
|
import StyledTextarea, { MIN_HEIGHT } from "./textarea.style";
|
|
15
|
-
import LocaleContext from "../../__internal__/i18n-context";
|
|
16
15
|
import { TooltipProvider } from "../../__internal__/tooltip-provider";
|
|
17
16
|
import useInputAccessibility from "../../hooks/__internal__/useInputAccessibility";
|
|
18
17
|
import { NewValidationContext } from "../carbon-provider/carbon-provider.component";
|
|
19
18
|
import { ErrorBorder, StyledHintText } from "../textbox/textbox.style";
|
|
20
19
|
import ValidationMessage from "../../__internal__/validation-message";
|
|
21
|
-
|
|
22
|
-
const getFormatNumber = (value, locale) => new Intl.NumberFormat(locale).format(value);
|
|
23
|
-
|
|
24
20
|
const marginPropTypes = filterStyledSystemMarginProps(styledSystemPropTypes.space);
|
|
25
21
|
|
|
26
22
|
const Textarea = ({
|
|
@@ -61,7 +57,6 @@ const Textarea = ({
|
|
|
61
57
|
helpAriaLabel,
|
|
62
58
|
...props
|
|
63
59
|
}) => {
|
|
64
|
-
const locale = useContext(LocaleContext);
|
|
65
60
|
const {
|
|
66
61
|
validationRedesignOptIn
|
|
67
62
|
} = useContext(NewValidationContext);
|
|
@@ -98,6 +93,8 @@ const Textarea = ({
|
|
|
98
93
|
label,
|
|
99
94
|
fieldHelp
|
|
100
95
|
});
|
|
96
|
+
const [maxLength, characterCount] = useCharacterCount(value, // TODO: Can be removed after the characterLimit type is changed to number
|
|
97
|
+
typeof characterLimit === "string" ? parseInt(characterLimit, 10) : characterLimit, warnOverLimit, enforceCharacterLimit);
|
|
101
98
|
useEffect(() => {
|
|
102
99
|
if (rows) {
|
|
103
100
|
minHeight.current = inputRef.current.scrollHeight;
|
|
@@ -120,24 +117,6 @@ const Textarea = ({
|
|
|
120
117
|
}
|
|
121
118
|
};
|
|
122
119
|
}, [expandable]);
|
|
123
|
-
|
|
124
|
-
const isOverLimit = () => {
|
|
125
|
-
return (value || "").length > parseInt(characterLimit, 10);
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
const characterCount = () => {
|
|
129
|
-
if (!characterLimit) {
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
return /*#__PURE__*/React.createElement(CharacterCount, {
|
|
134
|
-
isOverLimit: isOverLimit() && warnOverLimit,
|
|
135
|
-
value: getFormatNumber((value || "").length, locale.locale()),
|
|
136
|
-
limit: getFormatNumber(characterLimit, locale.locale()),
|
|
137
|
-
"data-element": "character-limit"
|
|
138
|
-
});
|
|
139
|
-
};
|
|
140
|
-
|
|
141
120
|
return /*#__PURE__*/React.createElement(TooltipProvider, {
|
|
142
121
|
tooltipPosition: tooltipPosition,
|
|
143
122
|
helpAriaLabel: helpAriaLabel
|
|
@@ -186,7 +165,7 @@ const Textarea = ({
|
|
|
186
165
|
name: name,
|
|
187
166
|
value: value,
|
|
188
167
|
ref: inputRef,
|
|
189
|
-
maxLength:
|
|
168
|
+
maxLength: maxLength,
|
|
190
169
|
onChange: onChange,
|
|
191
170
|
disabled: disabled,
|
|
192
171
|
readOnly: readOnly,
|
|
@@ -206,7 +185,7 @@ const Textarea = ({
|
|
|
206
185
|
info: info,
|
|
207
186
|
validationIconId: validationRedesignOptIn ? undefined : validationIconId,
|
|
208
187
|
useValidationIcon: !(validationRedesignOptIn || validationOnLabel)
|
|
209
|
-
}))), characterCount
|
|
188
|
+
}))), characterCount)));
|
|
210
189
|
};
|
|
211
190
|
|
|
212
191
|
Textarea.propTypes = { ...marginPropTypes,
|
|
@@ -227,7 +206,7 @@ Textarea.propTypes = { ...marginPropTypes,
|
|
|
227
206
|
id: PropTypes.string,
|
|
228
207
|
|
|
229
208
|
/** Character limit of the textarea */
|
|
230
|
-
characterLimit: PropTypes.string,
|
|
209
|
+
characterLimit: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
231
210
|
|
|
232
211
|
/** Type of the icon that will be rendered next to the input */
|
|
233
212
|
children: PropTypes.node,
|
|
@@ -4,6 +4,7 @@ import { MarginProps } from "styled-system";
|
|
|
4
4
|
import { ValidationProps } from "../../__internal__/validations";
|
|
5
5
|
import { CommonInputProps } from "../../__internal__/input";
|
|
6
6
|
|
|
7
|
+
// TODO: Change characterLimit type to number - batch with other breaking changes
|
|
7
8
|
export interface TextareaProps
|
|
8
9
|
extends ValidationProps,
|
|
9
10
|
MarginProps,
|
|
@@ -19,7 +20,7 @@ export interface TextareaProps
|
|
|
19
20
|
/** Breakpoint for adaptive label (inline labels change to top aligned). Enables the adaptive behaviour when set */
|
|
20
21
|
adaptiveLabelBreakpoint?: number;
|
|
21
22
|
/** Character limit of the textarea */
|
|
22
|
-
characterLimit?: string;
|
|
23
|
+
characterLimit?: string | number;
|
|
23
24
|
/** Type of the icon that will be rendered next to the input */
|
|
24
25
|
children?: React.ReactNode;
|
|
25
26
|
/** The visible width of the text control, in average character widths */
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { default
|
|
1
|
+
export { default } from "./textbox.component";
|
|
2
|
+
export type { TextboxProps, CommonTextboxProps } from "./textbox.component";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default
|
|
1
|
+
export { default } from "./textbox.component";
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { MarginProps } from "styled-system";
|
|
3
|
+
import { CommonInputProps } from "../../__internal__/input";
|
|
4
|
+
import { ValidationProps } from "../../__internal__/validations";
|
|
5
|
+
import { IconType } from "../icon";
|
|
6
|
+
export interface CommonTextboxProps extends ValidationProps, MarginProps, Omit<CommonInputProps, "size"> {
|
|
7
|
+
/** Identifier used for testing purposes, applied to the root element of the component. */
|
|
8
|
+
"data-component"?: string;
|
|
9
|
+
/** Identifier used for testing purposes, applied to the root element of the component. */
|
|
10
|
+
"data-element"?: string;
|
|
11
|
+
/** Identifier used for testing purposes, applied to the root element of the component. */
|
|
12
|
+
"data-role"?: string;
|
|
13
|
+
/** Breakpoint for adaptive label (inline labels change to top aligned). Enables the adaptive behaviour when set */
|
|
14
|
+
adaptiveLabelBreakpoint?: number;
|
|
15
|
+
/** Integer to determine a timeout for the deferred callback */
|
|
16
|
+
deferTimeout?: number;
|
|
17
|
+
/** Help content to be displayed under an input */
|
|
18
|
+
fieldHelp?: React.ReactNode;
|
|
19
|
+
/**
|
|
20
|
+
* An optional alternative for props.value, this is useful if the
|
|
21
|
+
* real value is an ID but you want to show a human-readable version.
|
|
22
|
+
*/
|
|
23
|
+
formattedValue?: string;
|
|
24
|
+
/** Unique identifier for the input. Will use a randomly generated GUID if none is provided */
|
|
25
|
+
id?: string;
|
|
26
|
+
/** Type of the icon that will be rendered next to the input */
|
|
27
|
+
inputIcon?: IconType;
|
|
28
|
+
/** Optional handler for click event on Textbox icon */
|
|
29
|
+
iconOnClick?: (ev: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>) => void;
|
|
30
|
+
/** Optional handler for mouse down event on Textbox icon */
|
|
31
|
+
iconOnMouseDown?: (ev: React.MouseEvent<HTMLElement>) => void;
|
|
32
|
+
/** Overrides the default tabindex of the component */
|
|
33
|
+
iconTabIndex?: number;
|
|
34
|
+
/** The width of the input as a percentage */
|
|
35
|
+
inputWidth?: number;
|
|
36
|
+
/** Additional child elements to display before the input */
|
|
37
|
+
leftChildren?: React.ReactNode;
|
|
38
|
+
/** Label content */
|
|
39
|
+
label?: string;
|
|
40
|
+
/** Inline label alignment */
|
|
41
|
+
labelAlign?: "left" | "right";
|
|
42
|
+
/** A message that the Help component will display */
|
|
43
|
+
labelHelp?: React.ReactNode;
|
|
44
|
+
/** When true label is inline */
|
|
45
|
+
labelInline?: boolean;
|
|
46
|
+
/** Spacing between label and a field for inline label, given number will be multiplied by base spacing unit (8) */
|
|
47
|
+
labelSpacing?: 1 | 2;
|
|
48
|
+
/** Label width */
|
|
49
|
+
labelWidth?: number;
|
|
50
|
+
/** Specify a callback triggered on change */
|
|
51
|
+
onChange?: (ev: React.ChangeEvent<HTMLInputElement>) => void;
|
|
52
|
+
/** Deferred callback to be called after the onChange event */
|
|
53
|
+
onChangeDeferred?: () => void;
|
|
54
|
+
/** Specify a callback triggered on click */
|
|
55
|
+
onClick?: (ev: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>) => void;
|
|
56
|
+
/** Event handler for the focus event */
|
|
57
|
+
onFocus?: (ev: React.FocusEvent<HTMLInputElement>) => void;
|
|
58
|
+
/** Event handler for the blur event */
|
|
59
|
+
onBlur?: (ev: React.FocusEvent<HTMLInputElement>) => void;
|
|
60
|
+
/** Event handler for the mouse down event */
|
|
61
|
+
onMouseDown?: (ev: React.MouseEvent<HTMLElement>) => void;
|
|
62
|
+
/** Emphasized part of the displayed text */
|
|
63
|
+
prefix?: string;
|
|
64
|
+
/** Reverses label and input display */
|
|
65
|
+
reverse?: boolean;
|
|
66
|
+
/** Size of an input */
|
|
67
|
+
size?: "small" | "medium" | "large";
|
|
68
|
+
/** When true, validation icon will be placed on label instead of being placed on the input */
|
|
69
|
+
validationOnLabel?: boolean;
|
|
70
|
+
/** Overrides the default tooltip position */
|
|
71
|
+
tooltipPosition?: "top" | "bottom" | "left" | "right";
|
|
72
|
+
/** Aria label for rendered help component */
|
|
73
|
+
helpAriaLabel?: string;
|
|
74
|
+
}
|
|
75
|
+
export interface TextboxProps extends CommonTextboxProps {
|
|
76
|
+
/** Content to be rendered next to the input */
|
|
77
|
+
children?: React.ReactNode;
|
|
78
|
+
/** [Legacy] Flag to configure component as optional in Form */
|
|
79
|
+
isOptional?: boolean;
|
|
80
|
+
/** Container for DatePicker or SelectList components */
|
|
81
|
+
positionedChildren?: React.ReactNode;
|
|
82
|
+
/** Label id passed from Select component */
|
|
83
|
+
labelId?: string;
|
|
84
|
+
/** Character limit of the textarea */
|
|
85
|
+
characterLimit?: string | number;
|
|
86
|
+
/** Stop the user typing over the characterLimit */
|
|
87
|
+
enforceCharacterLimit?: boolean;
|
|
88
|
+
/** Whether to display the character count message in red */
|
|
89
|
+
warnOverLimit?: boolean;
|
|
90
|
+
}
|
|
91
|
+
export declare const Textbox: ({ align, autoFocus, children, disabled, inputIcon, leftChildren, labelId: externalLabelId, label, labelAlign, labelHelp, labelInline, labelSpacing, id, formattedValue, fieldHelp, error, warning, info, name, reverse, size, value, readOnly, placeholder, inputRef, onBlur, onClick, onFocus, onChange, onMouseDown, onChangeDeferred, deferTimeout, isOptional, iconOnClick, iconOnMouseDown, iconTabIndex, validationOnLabel, labelWidth, inputWidth, prefix, adaptiveLabelBreakpoint, required, positionedChildren, tooltipPosition, "data-component": dataComponent, "data-element": dataElement, "data-role": dataRole, enforceCharacterLimit, characterLimit, warnOverLimit, helpAriaLabel, ...props }: TextboxProps) => JSX.Element;
|
|
92
|
+
export default Textbox;
|