carbon-react 110.2.0 → 110.2.1

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.
Files changed (43) hide show
  1. package/esm/__internal__/character-count/character-count.component.d.ts +8 -25
  2. package/esm/__internal__/character-count/character-count.component.js +12 -18
  3. package/esm/__internal__/character-count/character-count.style.d.ts +3 -1
  4. package/esm/__internal__/character-count/character-count.style.js +4 -0
  5. package/esm/__internal__/input/index.d.ts +1 -1
  6. package/esm/components/numeral-date/numeral-date-context.d.ts +6 -0
  7. package/esm/components/select/multi-select/multi-select.component.js +1 -1
  8. package/esm/components/select/select-list/select-list.component.js +20 -11
  9. package/esm/components/textarea/textarea.component.js +6 -27
  10. package/esm/components/textarea/textarea.d.ts +2 -1
  11. package/esm/components/textbox/__internal__/prefix.style.d.ts +2 -0
  12. package/esm/components/textbox/index.d.ts +2 -1
  13. package/esm/components/textbox/index.js +1 -1
  14. package/esm/components/textbox/textbox.component.d.ts +92 -0
  15. package/esm/components/textbox/textbox.component.js +533 -197
  16. package/esm/components/textbox/textbox.style.d.ts +5 -0
  17. package/esm/components/textbox/textbox.style.js +0 -12
  18. package/esm/hooks/__internal__/useCharacterCount/useCharacterCount.d.ts +1 -1
  19. package/esm/hooks/__internal__/useCharacterCount/useCharacterCount.js +7 -6
  20. package/esm/hooks/__internal__/useInputAccessibility/useInputAccessibility.d.ts +6 -5
  21. package/lib/__internal__/character-count/character-count.component.d.ts +8 -25
  22. package/lib/__internal__/character-count/character-count.component.js +13 -23
  23. package/lib/__internal__/character-count/character-count.style.d.ts +3 -1
  24. package/lib/__internal__/character-count/character-count.style.js +7 -0
  25. package/lib/__internal__/input/index.d.ts +1 -1
  26. package/lib/components/numeral-date/numeral-date-context.d.ts +6 -0
  27. package/lib/components/select/multi-select/multi-select.component.js +1 -1
  28. package/lib/components/select/select-list/select-list.component.js +20 -11
  29. package/lib/components/textarea/textarea.component.js +6 -27
  30. package/lib/components/textarea/textarea.d.ts +2 -1
  31. package/lib/components/textbox/__internal__/prefix.style.d.ts +2 -0
  32. package/lib/components/textbox/index.d.ts +2 -1
  33. package/lib/components/textbox/index.js +2 -10
  34. package/lib/components/textbox/textbox.component.d.ts +92 -0
  35. package/lib/components/textbox/textbox.component.js +534 -201
  36. package/lib/components/textbox/textbox.style.d.ts +5 -0
  37. package/lib/components/textbox/textbox.style.js +1 -16
  38. package/lib/hooks/__internal__/useCharacterCount/useCharacterCount.d.ts +1 -1
  39. package/lib/hooks/__internal__/useCharacterCount/useCharacterCount.js +7 -6
  40. package/lib/hooks/__internal__/useInputAccessibility/useInputAccessibility.d.ts +6 -5
  41. package/package.json +1 -1
  42. package/esm/components/textbox/textbox.d.ts +0 -125
  43. package/lib/components/textbox/textbox.d.ts +0 -125
@@ -1,26 +1,9 @@
1
- declare var _default: React.ForwardRefExoticComponent<{
2
- [x: string]: any;
3
- [x: number]: any;
4
- } & {
5
- theme?: any;
6
- }>;
7
- export default _default;
8
- import React from "react";
9
- export function CharacterCount({ value, limit, theme, ...props }: {
10
- [x: string]: any;
11
- value: any;
12
- limit: any;
13
- theme: any;
14
- }): JSX.Element;
15
- export namespace CharacterCount {
16
- namespace propTypes {
17
- const value: PropTypes.Validator<string>;
18
- const limit: PropTypes.Validator<string>;
19
- const theme: PropTypes.Requireable<object>;
20
- }
21
- namespace defaultProps {
22
- export { baseTheme as theme };
23
- }
1
+ /// <reference types="react" />
2
+ interface CharacterCountProps {
3
+ value: string;
4
+ limit: string;
5
+ isOverLimit: boolean;
6
+ "data-element"?: string;
24
7
  }
25
- import PropTypes from "prop-types";
26
- import baseTheme from "../../style/themes/base";
8
+ declare const CharacterCount: ({ value, limit, isOverLimit, "data-element": dataElement, }: CharacterCountProps) => JSX.Element;
9
+ export default CharacterCount;
@@ -1,28 +1,22 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
3
1
  import React from "react";
4
2
  import PropTypes from "prop-types";
5
- import { withTheme } from "styled-components";
6
- import baseTheme from "../../style/themes/base";
7
3
  import StyledCharacterCount from "./character-count.style";
8
4
 
9
5
  const CharacterCount = ({
10
6
  value,
11
7
  limit,
12
- theme,
13
- ...props
14
- }) => /*#__PURE__*/React.createElement(StyledCharacterCount, _extends({
15
- theme: theme,
16
- "aria-live": "polite"
17
- }, props), `${value}/${limit}`);
8
+ isOverLimit,
9
+ "data-element": dataElement
10
+ }) => /*#__PURE__*/React.createElement(StyledCharacterCount, {
11
+ "aria-live": "polite",
12
+ isOverLimit: isOverLimit,
13
+ "data-element": dataElement
14
+ }, `${value}/${limit}`);
18
15
 
19
16
  CharacterCount.propTypes = {
20
- value: PropTypes.string.isRequired,
21
- limit: PropTypes.string.isRequired,
22
- theme: PropTypes.object
23
- };
24
- CharacterCount.defaultProps = {
25
- theme: baseTheme
17
+ "data-element": PropTypes.string,
18
+ "isOverLimit": PropTypes.bool.isRequired,
19
+ "limit": PropTypes.string.isRequired,
20
+ "value": PropTypes.string.isRequired
26
21
  };
27
- export default withTheme(CharacterCount);
28
- export { CharacterCount };
22
+ export default CharacterCount;
@@ -1,2 +1,4 @@
1
+ declare const StyledCharacterCount: import("styled-components").StyledComponent<"div", any, {
2
+ isOverLimit: boolean;
3
+ }, never>;
1
4
  export default StyledCharacterCount;
2
- declare const StyledCharacterCount: import("styled-components").StyledComponent<"div", any, {}, never>;
@@ -1,4 +1,5 @@
1
1
  import styled, { css } from "styled-components";
2
+ import baseTheme from "../../style/themes/base";
2
3
  const StyledCharacterCount = styled.div`
3
4
  text-align: right;
4
5
  font-size: 12px;
@@ -14,4 +15,7 @@ const StyledCharacterCount = styled.div`
14
15
  font-weight: 700;
15
16
  `}
16
17
  `;
18
+ StyledCharacterCount.defaultProps = {
19
+ theme: baseTheme
20
+ };
17
21
  export default StyledCharacterCount;
@@ -1,5 +1,5 @@
1
1
  import Input from "./input.component";
2
2
  import InputPresentation from "./input-presentation.component";
3
- export type { InputProps } from "./input.component";
3
+ export type { InputProps, CommonInputProps } from "./input.component";
4
4
  export { Input, InputPresentation };
5
5
  export default Input;
@@ -0,0 +1,6 @@
1
+ import React from "react";
2
+ declare type NumeralContextType = {
3
+ disableErrorBorder?: boolean;
4
+ };
5
+ declare const _default: React.Context<NumeralContextType>;
6
+ export default _default;
@@ -208,7 +208,7 @@ const MultiSelect = /*#__PURE__*/React.forwardRef(({
208
208
  wrapText: wrapPillText
209
209
  }, pillProps), title));
210
210
  }); // eslint-disable-next-line react-hooks/exhaustive-deps
211
- }, [children, disabled, readOnly, selectedValue]);
211
+ }, [children, disabled, readOnly, actualValue]);
212
212
  useEffect(() => {
213
213
  const modeSwitchedMessage = "Input elements should not switch from uncontrolled to controlled (or vice versa). " + "Decide between using a controlled or uncontrolled input element for the lifetime of the component";
214
214
  const onChangeMissingMessage = "onChange prop required when using a controlled input element";
@@ -61,6 +61,24 @@ const SelectList = /*#__PURE__*/React.forwardRef(({
61
61
  blockScroll,
62
62
  allowScroll
63
63
  } = useScrollBlock();
64
+
65
+ const updateListHeight = () => {
66
+ let newHeight = listRef.current.clientHeight;
67
+
68
+ if (listActionButtonRef.current) {
69
+ newHeight += listActionButtonRef.current.parentElement.clientHeight;
70
+ }
71
+
72
+ setListHeight(`${newHeight}px`);
73
+ };
74
+
75
+ const listCallbackRef = useCallback(element => {
76
+ listRef.current = element;
77
+
78
+ if (element) {
79
+ setTimeout(updateListHeight, 0);
80
+ }
81
+ }, []);
64
82
  useEffect(() => {
65
83
  blockScroll();
66
84
  return () => {
@@ -225,16 +243,7 @@ const SelectList = /*#__PURE__*/React.forwardRef(({
225
243
  window.removeEventListener("resize", assignListWidth);
226
244
  };
227
245
  }, [assignListWidth]);
228
- useLayoutEffect(() => {
229
- let newHeight;
230
- newHeight = listRef.current.clientHeight;
231
-
232
- if (listActionButtonRef.current) {
233
- newHeight += listActionButtonRef.current.parentElement.clientHeight;
234
- }
235
-
236
- setListHeight(`${newHeight}px`);
237
- }, [children]);
246
+ useLayoutEffect(updateListHeight, [children]);
238
247
  useEffect(() => {
239
248
  const keyboardEvent = "keydown";
240
249
  const listElement = listRef.current;
@@ -325,7 +334,7 @@ const SelectList = /*#__PURE__*/React.forwardRef(({
325
334
  "aria-labelledby": labelId,
326
335
  "data-element": "select-list",
327
336
  role: "listbox",
328
- ref: listRef,
337
+ ref: listCallbackRef,
329
338
  tabIndex: "-1",
330
339
  isLoading: isLoading,
331
340
  multiColumn: multiColumn
@@ -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 CharacterCount from "../../__internal__/character-count";
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: enforceCharacterLimit && characterLimit ? characterLimit : undefined,
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 */
@@ -0,0 +1,2 @@
1
+ declare const StyledPrefix: import("styled-components").StyledComponent<"span", any, {}, never>;
2
+ export default StyledPrefix;
@@ -1 +1,2 @@
1
- export { default, TextboxProps, CommonTextboxProps } from "./textbox";
1
+ export { default } from "./textbox.component";
2
+ export type { TextboxProps, CommonTextboxProps } from "./textbox.component";
@@ -1 +1 @@
1
- export { default, OriginalTextbox } from "./textbox.component";
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;