carbon-react 121.0.1 → 121.1.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.
Files changed (34) hide show
  1. package/esm/__internal__/character-count/character-count.style.js +4 -8
  2. package/esm/components/flat-table/flat-table.style.js +8 -2
  3. package/esm/components/pager/pager.style.js +2 -7
  4. package/esm/components/text-editor/__internal__/editor-validation-wrapper/editor-validation-wrapper.component.d.ts +11 -0
  5. package/esm/components/text-editor/__internal__/editor-validation-wrapper/editor-validation-wrapper.component.js +18 -0
  6. package/esm/components/text-editor/__internal__/editor-validation-wrapper/editor-validation-wrapper.style.d.ts +2 -0
  7. package/esm/components/text-editor/__internal__/editor-validation-wrapper/editor-validation-wrapper.style.js +11 -0
  8. package/esm/components/text-editor/__internal__/editor-validation-wrapper/index.d.ts +2 -0
  9. package/esm/components/text-editor/__internal__/editor-validation-wrapper/index.js +1 -0
  10. package/esm/components/text-editor/text-editor.component.d.ts +2 -0
  11. package/esm/components/text-editor/text-editor.component.js +48 -12
  12. package/lib/__internal__/character-count/character-count.style.js +4 -8
  13. package/lib/components/flat-table/flat-table.style.js +8 -2
  14. package/lib/components/pager/pager.style.js +2 -7
  15. package/lib/components/text-editor/__internal__/editor-validation-wrapper/editor-validation-wrapper.component.d.ts +11 -0
  16. package/lib/components/text-editor/__internal__/{editor-counter/editor-counter.component.js → editor-validation-wrapper/editor-validation-wrapper.component.js} +7 -11
  17. package/lib/components/text-editor/__internal__/editor-validation-wrapper/editor-validation-wrapper.style.d.ts +2 -0
  18. package/lib/components/text-editor/__internal__/editor-validation-wrapper/editor-validation-wrapper.style.js +19 -0
  19. package/lib/components/text-editor/__internal__/editor-validation-wrapper/index.d.ts +2 -0
  20. package/lib/components/text-editor/__internal__/{editor-counter → editor-validation-wrapper}/index.js +2 -2
  21. package/lib/components/text-editor/__internal__/{editor-counter → editor-validation-wrapper}/package.json +1 -1
  22. package/lib/components/text-editor/text-editor.component.d.ts +2 -0
  23. package/lib/components/text-editor/text-editor.component.js +46 -10
  24. package/package.json +1 -1
  25. package/esm/components/text-editor/__internal__/editor-counter/editor-counter.component.d.ts +0 -15
  26. package/esm/components/text-editor/__internal__/editor-counter/editor-counter.component.js +0 -22
  27. package/esm/components/text-editor/__internal__/editor-counter/editor-counter.style.d.ts +0 -5
  28. package/esm/components/text-editor/__internal__/editor-counter/editor-counter.style.js +0 -18
  29. package/esm/components/text-editor/__internal__/editor-counter/index.d.ts +0 -2
  30. package/esm/components/text-editor/__internal__/editor-counter/index.js +0 -1
  31. package/lib/components/text-editor/__internal__/editor-counter/editor-counter.component.d.ts +0 -15
  32. package/lib/components/text-editor/__internal__/editor-counter/editor-counter.style.d.ts +0 -5
  33. package/lib/components/text-editor/__internal__/editor-counter/editor-counter.style.js +0 -26
  34. package/lib/components/text-editor/__internal__/editor-counter/index.d.ts +0 -2
@@ -3,14 +3,10 @@ import baseTheme from "../../style/themes/base";
3
3
  import visuallyHidden from "../../style/utils/visually-hidden";
4
4
  const StyledCharacterCountWrapper = styled.div``;
5
5
  const StyledCharacterCount = styled.div`
6
- ::after {
7
- content: " ";
8
- }
9
-
10
6
  text-align: left;
11
- font-size: 12px;
12
- margin-top: 4px;
13
- margin-bottom: 4px;
7
+ font-size: var(--fontSizes100);
8
+ margin-top: var(--spacing050);
9
+ margin-bottom: var(--spacing050);
14
10
  color: ${({
15
11
  isOverLimit
16
12
  }) => isOverLimit ? "var(--colorsSemanticNegative500)" : "var(--colorsUtilityYin055)"};
@@ -18,7 +14,7 @@ const StyledCharacterCount = styled.div`
18
14
  ${({
19
15
  isOverLimit
20
16
  }) => isOverLimit && css`
21
- font-weight: 700;
17
+ font-weight: var(--fontWeights700);
22
18
  `}
23
19
  `;
24
20
  const VisuallyHiddenCharacterCount = styled.div`
@@ -335,6 +335,12 @@ StyledFlatTableWrapper.defaultProps = {
335
335
  theme: baseTheme
336
336
  };
337
337
  const StyledFlatTableFooter = styled.div`
338
+ & > ${StyledPagerContainer} {
339
+ border-top: none;
340
+ border-top-left-radius: 0;
341
+ border-top-right-radius: 0;
342
+ }
343
+
338
344
  ${({
339
345
  hasStickyFooter,
340
346
  theme
@@ -344,8 +350,8 @@ const StyledFlatTableFooter = styled.div`
344
350
  z-index: ${theme.zIndex.overlay + STICKY_FOOTER_OVERLAY_INCREMENT};
345
351
 
346
352
  ${StyledPagerContainer} {
347
- border-bottom-left-radius: var(--borderRadius000);
348
- border-bottom-right-radius: var(--borderRadius000);
353
+ border-bottom-left-radius: 0;
354
+ border-bottom-right-radius: 0;
349
355
  }
350
356
  `}
351
357
  `;
@@ -20,19 +20,14 @@ const StyledPagerContainer = styled.div`
20
20
  justify-content: space-between;
21
21
  padding: 0px 24px;
22
22
  align-items: center;
23
- border-top-width: 0;
24
23
  font-size: 13px;
25
- border-top: none;
26
24
  color: var(--colorsUtilityYin090);
25
+ border: 1px solid var(--colorsUtilityMajor100);
26
+ border-radius: var(--borderRadius100);
27
27
 
28
28
  ${({
29
29
  variant
30
30
  }) => css`
31
- border-width: 1px 1px 1px 1px;
32
- border-style: none solid solid solid;
33
- border-bottom-left-radius: var(--borderRadius100);
34
- border-bottom-right-radius: var(--borderRadius100);
35
- border-color: var(--colorsUtilityMajor100);
36
31
  background-color: ${variant === "alternate" ? "var(--colorsUtilityMajor040)" : "var(--colorsUtilityMajor010)"};
37
32
  `}
38
33
  `;
@@ -0,0 +1,11 @@
1
+ import React from "react";
2
+ export interface EditorValidationWrapperProps {
3
+ /** Message to be displayed when there is an error */
4
+ error?: string;
5
+ /** Message to be displayed when there is a warning */
6
+ warning?: string;
7
+ /** Message to be displayed when there is an info */
8
+ info?: string;
9
+ }
10
+ declare const ValidationWrapper: ({ error, warning, info, }: EditorValidationWrapperProps) => React.JSX.Element;
11
+ export default ValidationWrapper;
@@ -0,0 +1,18 @@
1
+ import React from "react";
2
+ import PropTypes from "prop-types";
3
+ import StyledValidationWrapper from "./editor-validation-wrapper.style";
4
+ import ValidationIcon from "../../../../__internal__/validations";
5
+ const ValidationWrapper = ({
6
+ error,
7
+ warning,
8
+ info
9
+ }) => /*#__PURE__*/React.createElement(StyledValidationWrapper, {
10
+ "data-component": "text-editor-validation-wrapper"
11
+ }, /*#__PURE__*/React.createElement(ValidationIcon, {
12
+ error: error,
13
+ warning: warning,
14
+ info: info,
15
+ tooltipPosition: "top",
16
+ tabIndex: 0
17
+ }));
18
+ export default ValidationWrapper;
@@ -0,0 +1,2 @@
1
+ declare const StyledValidationWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
2
+ export default StyledValidationWrapper;
@@ -0,0 +1,11 @@
1
+ import styled from "styled-components";
2
+ const StyledValidationWrapper = styled.div`
3
+ margin: var(--spacing200) var(--spacing200) var(--spacing000)
4
+ var(--spacing050);
5
+ min-width: var(--sizing500);
6
+ height: var(--sizing275);
7
+ display: flex;
8
+ float: right;
9
+ align-items: center;
10
+ `;
11
+ export default StyledValidationWrapper;
@@ -0,0 +1,2 @@
1
+ export { default } from "./editor-validation-wrapper.component";
2
+ export type { EditorValidationWrapperProps } from "./editor-validation-wrapper.component";
@@ -0,0 +1 @@
1
+ export { default } from "./editor-validation-wrapper.component";
@@ -30,6 +30,8 @@ export interface TextEditorProps extends MarginProps {
30
30
  previews?: React.ReactNode;
31
31
  /** Callback to report a url when a link is added */
32
32
  onLinkAdded?: (url: string) => void;
33
+ /** Hint text to be rendered when validationRedesignOptIn flag is set */
34
+ inputHint?: string;
33
35
  }
34
36
  export declare const TextEditor: React.ForwardRefExoticComponent<TextEditorProps & React.RefAttributes<Editor>>;
35
37
  export declare const TextEditorState: typeof EditorState;
@@ -1,15 +1,21 @@
1
- import React, { useCallback, useEffect, useRef, useState } from "react";
1
+ import React, { useCallback, useEffect, useRef, useState, useContext } from "react";
2
2
  import PropTypes from "prop-types";
3
3
  import { ContentState, EditorState, RichUtils, getDefaultKeyBinding, Modifier, Editor } from "draft-js";
4
4
  import { computeBlockType, getContent, getContentInfo, getDecoratedValue, getSelectedLength, moveSelectionToEnd, resetBlockType, isASCIIChar, replaceText, hasInlineStyle, hasBlockStyle, blockStyleFn } from "./__internal__/utils";
5
5
  import { StyledEditorWrapper, StyledEditorOutline, StyledEditorContainer } from "./text-editor.style";
6
- import Counter from "./__internal__/editor-counter";
6
+ import ValidationWrapper from "./__internal__/editor-validation-wrapper";
7
7
  import Toolbar from "./__internal__/toolbar";
8
8
  import Label from "../../__internal__/label";
9
9
  import Events from "../../__internal__/utils/helpers/events";
10
- import createGuid from "../../__internal__/utils/helpers/guid";
10
+ import guid from "../../__internal__/utils/helpers/guid";
11
11
  import LabelWrapper from "./__internal__/label-wrapper";
12
12
  import { BOLD, ITALIC, UNORDERED_LIST, ORDERED_LIST } from "./types";
13
+ import { NewValidationContext } from "../carbon-provider/carbon-provider.component";
14
+ import { ErrorBorder, StyledHintText } from "../textbox/textbox.style";
15
+ import ValidationMessage from "../../__internal__/validation-message";
16
+ import useInputAccessibility from "../../hooks/__internal__/useInputAccessibility";
17
+ import Box from "../box";
18
+ import useCharacterCount from "../../hooks/__internal__/useCharacterCount";
13
19
  const NUMBERS = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
14
20
  const INLINE_STYLES = [BOLD, ITALIC];
15
21
  export const EditorContext = /*#__PURE__*/React.createContext({});
@@ -26,8 +32,12 @@ const TextEditor = /*#__PURE__*/React.forwardRef(({
26
32
  rows,
27
33
  previews,
28
34
  onLinkAdded,
35
+ inputHint,
29
36
  ...rest
30
37
  }, ref) => {
38
+ const {
39
+ validationRedesignOptIn
40
+ } = useContext(NewValidationContext);
31
41
  const [isFocused, setIsFocused] = useState(false);
32
42
  const [inlines, setInlines] = useState([]);
33
43
  const [activeInlines, setActiveInlines] = useState({});
@@ -37,7 +47,24 @@ const TextEditor = /*#__PURE__*/React.forwardRef(({
37
47
  const contentLength = getContent(value).getPlainText("").length;
38
48
  const moveCursor = useRef(contentLength > 0);
39
49
  const lastKeyPressed = useRef();
40
- const labelId = useRef(`text-editor-label-${createGuid()}`);
50
+ const inputHintId = useRef(`${guid()}-hint`);
51
+ const {
52
+ current: id
53
+ } = useRef(guid());
54
+ const {
55
+ labelId,
56
+ validationId,
57
+ ariaDescribedBy
58
+ } = useInputAccessibility({
59
+ id,
60
+ validationRedesignOptIn,
61
+ error,
62
+ warning,
63
+ info,
64
+ label: labelText
65
+ });
66
+ const [characterCount, visuallyHiddenHintId] = useCharacterCount(getContent(value).getPlainText(""), characterLimit);
67
+ const combinedAriaDescribedBy = [ariaDescribedBy, inputHint ? inputHintId.current : undefined, visuallyHiddenHintId].filter(Boolean).join(" ");
41
68
  if (rows && (typeof rows !== "number" || rows < 2)) {
42
69
  // eslint-disable-next-line no-console
43
70
  console.warn(`Prop rows must be a number value that is 2 or greater to override the min-height of the \`${TextEditor.displayName}\``);
@@ -223,9 +250,19 @@ const TextEditor = /*#__PURE__*/React.forwardRef(({
223
250
  }, /*#__PURE__*/React.createElement(StyledEditorWrapper, rest, /*#__PURE__*/React.createElement(LabelWrapper, {
224
251
  onClick: () => handleEditorFocus(true)
225
252
  }, /*#__PURE__*/React.createElement(Label, {
226
- labelId: labelId.current,
253
+ labelId: labelId,
227
254
  isRequired: required
228
- }, labelText)), /*#__PURE__*/React.createElement(StyledEditorOutline, {
255
+ }, labelText)), inputHint && /*#__PURE__*/React.createElement(StyledHintText, {
256
+ id: inputHintId.current
257
+ }, inputHint), /*#__PURE__*/React.createElement(Box, {
258
+ position: "relative"
259
+ }, validationRedesignOptIn && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ValidationMessage, {
260
+ error: error,
261
+ validationId: validationId,
262
+ warning: warning
263
+ }), (error || warning) && /*#__PURE__*/React.createElement(ErrorBorder, {
264
+ warning: !!(!error && warning)
265
+ })), /*#__PURE__*/React.createElement(StyledEditorOutline, {
229
266
  isFocused: isFocused,
230
267
  hasError: !!error
231
268
  }, /*#__PURE__*/React.createElement(StyledEditorContainer, {
@@ -233,9 +270,7 @@ const TextEditor = /*#__PURE__*/React.forwardRef(({
233
270
  hasError: !!error,
234
271
  rows: rows,
235
272
  hasPreview: !!React.Children.count(previews)
236
- }, /*#__PURE__*/React.createElement(Counter, {
237
- limit: characterLimit,
238
- count: contentLength,
273
+ }, !validationRedesignOptIn && (error || warning || info) && /*#__PURE__*/React.createElement(ValidationWrapper, {
239
274
  error: error,
240
275
  warning: warning,
241
276
  info: info
@@ -248,8 +283,8 @@ const TextEditor = /*#__PURE__*/React.forwardRef(({
248
283
  handleBeforeInput: handleBeforeInput,
249
284
  handlePastedText: handlePastedText,
250
285
  handleKeyCommand: handleKeyCommand,
251
- ariaLabelledBy: labelId.current,
252
- ariaDescribedBy: labelId.current,
286
+ ariaLabelledBy: labelId,
287
+ ariaDescribedBy: combinedAriaDescribedBy,
253
288
  blockStyleFn: blockStyleFn,
254
289
  keyBindingFn: keyBindingFn,
255
290
  tabIndex: 0
@@ -270,12 +305,13 @@ const TextEditor = /*#__PURE__*/React.forwardRef(({
270
305
  activeControls: activeControls,
271
306
  canFocus: focusToolbar,
272
307
  toolbarElements: toolbarElements
273
- })))));
308
+ }))), characterCount)));
274
309
  });
275
310
  TextEditor.propTypes = {
276
311
  "characterLimit": PropTypes.number,
277
312
  "error": PropTypes.string,
278
313
  "info": PropTypes.string,
314
+ "inputHint": PropTypes.string,
279
315
  "labelText": PropTypes.string.isRequired,
280
316
  "m": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.oneOf([null]), PropTypes.number, PropTypes.shape({
281
317
  "__@toStringTag": PropTypes.string.isRequired,
@@ -13,14 +13,10 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
13
13
  const StyledCharacterCountWrapper = _styledComponents.default.div``;
14
14
  exports.StyledCharacterCountWrapper = StyledCharacterCountWrapper;
15
15
  const StyledCharacterCount = _styledComponents.default.div`
16
- ::after {
17
- content: " ";
18
- }
19
-
20
16
  text-align: left;
21
- font-size: 12px;
22
- margin-top: 4px;
23
- margin-bottom: 4px;
17
+ font-size: var(--fontSizes100);
18
+ margin-top: var(--spacing050);
19
+ margin-bottom: var(--spacing050);
24
20
  color: ${({
25
21
  isOverLimit
26
22
  }) => isOverLimit ? "var(--colorsSemanticNegative500)" : "var(--colorsUtilityYin055)"};
@@ -28,7 +24,7 @@ const StyledCharacterCount = _styledComponents.default.div`
28
24
  ${({
29
25
  isOverLimit
30
26
  }) => isOverLimit && (0, _styledComponents.css)`
31
- font-weight: 700;
27
+ font-weight: var(--fontWeights700);
32
28
  `}
33
29
  `;
34
30
  exports.StyledCharacterCount = StyledCharacterCount;
@@ -347,6 +347,12 @@ StyledFlatTableWrapper.defaultProps = {
347
347
  theme: _themes.baseTheme
348
348
  };
349
349
  const StyledFlatTableFooter = _styledComponents.default.div`
350
+ & > ${_pager.StyledPagerContainer} {
351
+ border-top: none;
352
+ border-top-left-radius: 0;
353
+ border-top-right-radius: 0;
354
+ }
355
+
350
356
  ${({
351
357
  hasStickyFooter,
352
358
  theme
@@ -356,8 +362,8 @@ const StyledFlatTableFooter = _styledComponents.default.div`
356
362
  z-index: ${theme.zIndex.overlay + STICKY_FOOTER_OVERLAY_INCREMENT};
357
363
 
358
364
  ${_pager.StyledPagerContainer} {
359
- border-bottom-left-radius: var(--borderRadius000);
360
- border-bottom-right-radius: var(--borderRadius000);
365
+ border-bottom-left-radius: 0;
366
+ border-bottom-right-radius: 0;
361
367
  }
362
368
  `}
363
369
  `;
@@ -30,19 +30,14 @@ const StyledPagerContainer = _styledComponents.default.div`
30
30
  justify-content: space-between;
31
31
  padding: 0px 24px;
32
32
  align-items: center;
33
- border-top-width: 0;
34
33
  font-size: 13px;
35
- border-top: none;
36
34
  color: var(--colorsUtilityYin090);
35
+ border: 1px solid var(--colorsUtilityMajor100);
36
+ border-radius: var(--borderRadius100);
37
37
 
38
38
  ${({
39
39
  variant
40
40
  }) => (0, _styledComponents.css)`
41
- border-width: 1px 1px 1px 1px;
42
- border-style: none solid solid solid;
43
- border-bottom-left-radius: var(--borderRadius100);
44
- border-bottom-right-radius: var(--borderRadius100);
45
- border-color: var(--colorsUtilityMajor100);
46
41
  background-color: ${variant === "alternate" ? "var(--colorsUtilityMajor040)" : "var(--colorsUtilityMajor010)"};
47
42
  `}
48
43
  `;
@@ -0,0 +1,11 @@
1
+ import React from "react";
2
+ export interface EditorValidationWrapperProps {
3
+ /** Message to be displayed when there is an error */
4
+ error?: string;
5
+ /** Message to be displayed when there is a warning */
6
+ warning?: string;
7
+ /** Message to be displayed when there is an info */
8
+ info?: string;
9
+ }
10
+ declare const ValidationWrapper: ({ error, warning, info, }: EditorValidationWrapperProps) => React.JSX.Element;
11
+ export default ValidationWrapper;
@@ -6,25 +6,21 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _react = _interopRequireDefault(require("react"));
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
- var _editorCounter = require("./editor-counter.style");
9
+ var _editorValidationWrapper = _interopRequireDefault(require("./editor-validation-wrapper.style"));
10
10
  var _validations = _interopRequireDefault(require("../../../../__internal__/validations"));
11
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
- const Counter = ({
13
- count = 0,
14
- limit = 3000,
12
+ const ValidationWrapper = ({
15
13
  error,
16
14
  warning,
17
15
  info
18
- }) => /*#__PURE__*/_react.default.createElement(_editorCounter.StyledCounterWrapper, {
19
- "data-component": "text-editor-counter"
20
- }, !!(error || warning || info) && /*#__PURE__*/_react.default.createElement(_validations.default, {
16
+ }) => /*#__PURE__*/_react.default.createElement(_editorValidationWrapper.default, {
17
+ "data-component": "text-editor-validation-wrapper"
18
+ }, /*#__PURE__*/_react.default.createElement(_validations.default, {
21
19
  error: error,
22
20
  warning: warning,
23
21
  info: info,
24
22
  tooltipPosition: "top",
25
23
  tabIndex: 0
26
- }), /*#__PURE__*/_react.default.createElement(_editorCounter.StyledCounter, {
27
- hasError: !!error
28
- }, `${limit - count}`));
29
- var _default = Counter;
24
+ }));
25
+ var _default = ValidationWrapper;
30
26
  exports.default = _default;
@@ -0,0 +1,2 @@
1
+ declare const StyledValidationWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
2
+ export default StyledValidationWrapper;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _styledComponents = _interopRequireDefault(require("styled-components"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ const StyledValidationWrapper = _styledComponents.default.div`
10
+ margin: var(--spacing200) var(--spacing200) var(--spacing000)
11
+ var(--spacing050);
12
+ min-width: var(--sizing500);
13
+ height: var(--sizing275);
14
+ display: flex;
15
+ float: right;
16
+ align-items: center;
17
+ `;
18
+ var _default = StyledValidationWrapper;
19
+ exports.default = _default;
@@ -0,0 +1,2 @@
1
+ export { default } from "./editor-validation-wrapper.component";
2
+ export type { EditorValidationWrapperProps } from "./editor-validation-wrapper.component";
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  Object.defineProperty(exports, "default", {
7
7
  enumerable: true,
8
8
  get: function () {
9
- return _editorCounter.default;
9
+ return _editorValidationWrapper.default;
10
10
  }
11
11
  });
12
- var _editorCounter = _interopRequireDefault(require("./editor-counter.component"));
12
+ var _editorValidationWrapper = _interopRequireDefault(require("./editor-validation-wrapper.component"));
13
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "sideEffects": false,
3
- "module": "../../../../../esm/components/text-editor/__internal__/editor-counter/index.js",
3
+ "module": "../../../../../esm/components/text-editor/__internal__/editor-validation-wrapper/index.js",
4
4
  "main": "./index.js",
5
5
  "types": "./index.d.ts"
6
6
  }
@@ -30,6 +30,8 @@ export interface TextEditorProps extends MarginProps {
30
30
  previews?: React.ReactNode;
31
31
  /** Callback to report a url when a link is added */
32
32
  onLinkAdded?: (url: string) => void;
33
+ /** Hint text to be rendered when validationRedesignOptIn flag is set */
34
+ inputHint?: string;
33
35
  }
34
36
  export declare const TextEditor: React.ForwardRefExoticComponent<TextEditorProps & React.RefAttributes<Editor>>;
35
37
  export declare const TextEditorState: typeof EditorState;
@@ -9,13 +9,19 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
9
9
  var _draftJs = require("draft-js");
10
10
  var _utils = require("./__internal__/utils");
11
11
  var _textEditor = require("./text-editor.style");
12
- var _editorCounter = _interopRequireDefault(require("./__internal__/editor-counter"));
12
+ var _editorValidationWrapper = _interopRequireDefault(require("./__internal__/editor-validation-wrapper"));
13
13
  var _toolbar = _interopRequireDefault(require("./__internal__/toolbar"));
14
14
  var _label = _interopRequireDefault(require("../../__internal__/label"));
15
15
  var _events = _interopRequireDefault(require("../../__internal__/utils/helpers/events"));
16
16
  var _guid = _interopRequireDefault(require("../../__internal__/utils/helpers/guid"));
17
17
  var _labelWrapper = _interopRequireDefault(require("./__internal__/label-wrapper"));
18
18
  var _types = require("./types");
19
+ var _carbonProvider = require("../carbon-provider/carbon-provider.component");
20
+ var _textbox = require("../textbox/textbox.style");
21
+ var _validationMessage = _interopRequireDefault(require("../../__internal__/validation-message"));
22
+ var _useInputAccessibility = _interopRequireDefault(require("../../hooks/__internal__/useInputAccessibility"));
23
+ var _box = _interopRequireDefault(require("../box"));
24
+ var _useCharacterCount = _interopRequireDefault(require("../../hooks/__internal__/useCharacterCount"));
19
25
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
26
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
27
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -36,8 +42,12 @@ const TextEditor = /*#__PURE__*/_react.default.forwardRef(({
36
42
  rows,
37
43
  previews,
38
44
  onLinkAdded,
45
+ inputHint,
39
46
  ...rest
40
47
  }, ref) => {
48
+ const {
49
+ validationRedesignOptIn
50
+ } = (0, _react.useContext)(_carbonProvider.NewValidationContext);
41
51
  const [isFocused, setIsFocused] = (0, _react.useState)(false);
42
52
  const [inlines, setInlines] = (0, _react.useState)([]);
43
53
  const [activeInlines, setActiveInlines] = (0, _react.useState)({});
@@ -47,7 +57,24 @@ const TextEditor = /*#__PURE__*/_react.default.forwardRef(({
47
57
  const contentLength = (0, _utils.getContent)(value).getPlainText("").length;
48
58
  const moveCursor = (0, _react.useRef)(contentLength > 0);
49
59
  const lastKeyPressed = (0, _react.useRef)();
50
- const labelId = (0, _react.useRef)(`text-editor-label-${(0, _guid.default)()}`);
60
+ const inputHintId = (0, _react.useRef)(`${(0, _guid.default)()}-hint`);
61
+ const {
62
+ current: id
63
+ } = (0, _react.useRef)((0, _guid.default)());
64
+ const {
65
+ labelId,
66
+ validationId,
67
+ ariaDescribedBy
68
+ } = (0, _useInputAccessibility.default)({
69
+ id,
70
+ validationRedesignOptIn,
71
+ error,
72
+ warning,
73
+ info,
74
+ label: labelText
75
+ });
76
+ const [characterCount, visuallyHiddenHintId] = (0, _useCharacterCount.default)((0, _utils.getContent)(value).getPlainText(""), characterLimit);
77
+ const combinedAriaDescribedBy = [ariaDescribedBy, inputHint ? inputHintId.current : undefined, visuallyHiddenHintId].filter(Boolean).join(" ");
51
78
  if (rows && (typeof rows !== "number" || rows < 2)) {
52
79
  // eslint-disable-next-line no-console
53
80
  console.warn(`Prop rows must be a number value that is 2 or greater to override the min-height of the \`${TextEditor.displayName}\``);
@@ -233,9 +260,19 @@ const TextEditor = /*#__PURE__*/_react.default.forwardRef(({
233
260
  }, /*#__PURE__*/_react.default.createElement(_textEditor.StyledEditorWrapper, rest, /*#__PURE__*/_react.default.createElement(_labelWrapper.default, {
234
261
  onClick: () => handleEditorFocus(true)
235
262
  }, /*#__PURE__*/_react.default.createElement(_label.default, {
236
- labelId: labelId.current,
263
+ labelId: labelId,
237
264
  isRequired: required
238
- }, labelText)), /*#__PURE__*/_react.default.createElement(_textEditor.StyledEditorOutline, {
265
+ }, labelText)), inputHint && /*#__PURE__*/_react.default.createElement(_textbox.StyledHintText, {
266
+ id: inputHintId.current
267
+ }, inputHint), /*#__PURE__*/_react.default.createElement(_box.default, {
268
+ position: "relative"
269
+ }, validationRedesignOptIn && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_validationMessage.default, {
270
+ error: error,
271
+ validationId: validationId,
272
+ warning: warning
273
+ }), (error || warning) && /*#__PURE__*/_react.default.createElement(_textbox.ErrorBorder, {
274
+ warning: !!(!error && warning)
275
+ })), /*#__PURE__*/_react.default.createElement(_textEditor.StyledEditorOutline, {
239
276
  isFocused: isFocused,
240
277
  hasError: !!error
241
278
  }, /*#__PURE__*/_react.default.createElement(_textEditor.StyledEditorContainer, {
@@ -243,9 +280,7 @@ const TextEditor = /*#__PURE__*/_react.default.forwardRef(({
243
280
  hasError: !!error,
244
281
  rows: rows,
245
282
  hasPreview: !!_react.default.Children.count(previews)
246
- }, /*#__PURE__*/_react.default.createElement(_editorCounter.default, {
247
- limit: characterLimit,
248
- count: contentLength,
283
+ }, !validationRedesignOptIn && (error || warning || info) && /*#__PURE__*/_react.default.createElement(_editorValidationWrapper.default, {
249
284
  error: error,
250
285
  warning: warning,
251
286
  info: info
@@ -258,8 +293,8 @@ const TextEditor = /*#__PURE__*/_react.default.forwardRef(({
258
293
  handleBeforeInput: handleBeforeInput,
259
294
  handlePastedText: handlePastedText,
260
295
  handleKeyCommand: handleKeyCommand,
261
- ariaLabelledBy: labelId.current,
262
- ariaDescribedBy: labelId.current,
296
+ ariaLabelledBy: labelId,
297
+ ariaDescribedBy: combinedAriaDescribedBy,
263
298
  blockStyleFn: _utils.blockStyleFn,
264
299
  keyBindingFn: keyBindingFn,
265
300
  tabIndex: 0
@@ -280,13 +315,14 @@ const TextEditor = /*#__PURE__*/_react.default.forwardRef(({
280
315
  activeControls: activeControls,
281
316
  canFocus: focusToolbar,
282
317
  toolbarElements: toolbarElements
283
- })))));
318
+ }))), characterCount)));
284
319
  });
285
320
  exports.TextEditor = TextEditor;
286
321
  TextEditor.propTypes = {
287
322
  "characterLimit": _propTypes.default.number,
288
323
  "error": _propTypes.default.string,
289
324
  "info": _propTypes.default.string,
325
+ "inputHint": _propTypes.default.string,
290
326
  "labelText": _propTypes.default.string.isRequired,
291
327
  "m": _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.oneOf([null]), _propTypes.default.number, _propTypes.default.shape({
292
328
  "__@toStringTag": _propTypes.default.string.isRequired,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "121.0.1",
3
+ "version": "121.1.0",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "files": [
6
6
  "lib",
@@ -1,15 +0,0 @@
1
- import React from "react";
2
- export interface EditorCounterProps {
3
- /** Sets the current count value */
4
- count?: number;
5
- /** Sets the current limit value */
6
- limit?: number;
7
- /** Message to be displayed when there is an error */
8
- error?: string;
9
- /** Message to be displayed when there is a warning */
10
- warning?: string;
11
- /** Message to be displayed when there is an info */
12
- info?: string;
13
- }
14
- declare const Counter: ({ count, limit, error, warning, info, }: EditorCounterProps) => React.JSX.Element;
15
- export default Counter;
@@ -1,22 +0,0 @@
1
- import React from "react";
2
- import PropTypes from "prop-types";
3
- import { StyledCounterWrapper, StyledCounter } from "./editor-counter.style";
4
- import ValidationIcon from "../../../../__internal__/validations";
5
- const Counter = ({
6
- count = 0,
7
- limit = 3000,
8
- error,
9
- warning,
10
- info
11
- }) => /*#__PURE__*/React.createElement(StyledCounterWrapper, {
12
- "data-component": "text-editor-counter"
13
- }, !!(error || warning || info) && /*#__PURE__*/React.createElement(ValidationIcon, {
14
- error: error,
15
- warning: warning,
16
- info: info,
17
- tooltipPosition: "top",
18
- tabIndex: 0
19
- }), /*#__PURE__*/React.createElement(StyledCounter, {
20
- hasError: !!error
21
- }, `${limit - count}`));
22
- export default Counter;
@@ -1,5 +0,0 @@
1
- declare const StyledCounter: import("styled-components").StyledComponent<"span", any, {
2
- hasError: boolean;
3
- }, never>;
4
- declare const StyledCounterWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
5
- export { StyledCounter, StyledCounterWrapper };
@@ -1,18 +0,0 @@
1
- import styled from "styled-components";
2
- const StyledCounter = styled.span`
3
- color: ${({
4
- hasError
5
- }) => hasError ? "var(--colorsSemanticNegative500)" : "var(--colorsUtilityYin055)"};
6
- width: 100%;
7
- `;
8
- const StyledCounterWrapper = styled.div`
9
- margin: 16px 16px 0px 4px;
10
- min-width: 40px;
11
- height: 21px;
12
- font-size: 14px;
13
- display: flex;
14
- float: right;
15
- text-align: right;
16
- align-items: center;
17
- `;
18
- export { StyledCounter, StyledCounterWrapper };
@@ -1,2 +0,0 @@
1
- export { default } from "./editor-counter.component";
2
- export type { EditorCounterProps } from "./editor-counter.component";
@@ -1 +0,0 @@
1
- export { default } from "./editor-counter.component";
@@ -1,15 +0,0 @@
1
- import React from "react";
2
- export interface EditorCounterProps {
3
- /** Sets the current count value */
4
- count?: number;
5
- /** Sets the current limit value */
6
- limit?: number;
7
- /** Message to be displayed when there is an error */
8
- error?: string;
9
- /** Message to be displayed when there is a warning */
10
- warning?: string;
11
- /** Message to be displayed when there is an info */
12
- info?: string;
13
- }
14
- declare const Counter: ({ count, limit, error, warning, info, }: EditorCounterProps) => React.JSX.Element;
15
- export default Counter;
@@ -1,5 +0,0 @@
1
- declare const StyledCounter: import("styled-components").StyledComponent<"span", any, {
2
- hasError: boolean;
3
- }, never>;
4
- declare const StyledCounterWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
5
- export { StyledCounter, StyledCounterWrapper };
@@ -1,26 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.StyledCounterWrapper = exports.StyledCounter = void 0;
7
- var _styledComponents = _interopRequireDefault(require("styled-components"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
- const StyledCounter = _styledComponents.default.span`
10
- color: ${({
11
- hasError
12
- }) => hasError ? "var(--colorsSemanticNegative500)" : "var(--colorsUtilityYin055)"};
13
- width: 100%;
14
- `;
15
- exports.StyledCounter = StyledCounter;
16
- const StyledCounterWrapper = _styledComponents.default.div`
17
- margin: 16px 16px 0px 4px;
18
- min-width: 40px;
19
- height: 21px;
20
- font-size: 14px;
21
- display: flex;
22
- float: right;
23
- text-align: right;
24
- align-items: center;
25
- `;
26
- exports.StyledCounterWrapper = StyledCounterWrapper;
@@ -1,2 +0,0 @@
1
- export { default } from "./editor-counter.component";
2
- export type { EditorCounterProps } from "./editor-counter.component";