carbon-react 109.5.0 → 109.6.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 (51) hide show
  1. package/esm/__internal__/form-field/form-field.component.d.ts +59 -0
  2. package/esm/__internal__/form-field/form-field.component.js +202 -57
  3. package/esm/__internal__/form-field/form-field.style.d.ts +7 -0
  4. package/esm/__internal__/form-field/form-field.style.js +6 -12
  5. package/esm/__internal__/form-field/index.d.ts +2 -5
  6. package/esm/__internal__/label/label.component.d.ts +2 -4
  7. package/esm/__internal__/label/label.component.js +0 -3
  8. package/esm/components/button/button-types.style.js +4 -0
  9. package/esm/components/button-toggle-group/button-toggle-group.component.js +9 -10
  10. package/esm/components/button-toggle-group/button-toggle-group.d.ts +3 -1
  11. package/esm/components/dialog/dialog.d.ts +1 -1
  12. package/esm/components/dialog-full-screen/dialog-full-screen.d.ts +1 -1
  13. package/esm/components/loader/loader-square.style.d.ts +2 -0
  14. package/esm/components/loader/loader.config.d.ts +1 -0
  15. package/esm/components/modal/__internal__/modal-manager.d.ts +19 -6
  16. package/esm/components/modal/__internal__/modal-manager.js +23 -40
  17. package/esm/components/modal/index.d.ts +1 -0
  18. package/esm/components/modal/modal.component.d.ts +44 -33
  19. package/esm/components/modal/modal.component.js +10 -14
  20. package/esm/components/modal/modal.style.d.ts +7 -2
  21. package/esm/components/switch/switch.component.js +0 -3
  22. package/esm/components/switch/switch.d.ts +0 -2
  23. package/esm/components/tabs/tab/tab.d.ts +3 -3
  24. package/lib/__internal__/form-field/form-field.component.d.ts +59 -0
  25. package/lib/__internal__/form-field/form-field.component.js +201 -57
  26. package/lib/__internal__/form-field/form-field.style.d.ts +7 -0
  27. package/lib/__internal__/form-field/form-field.style.js +9 -13
  28. package/lib/__internal__/form-field/index.d.ts +2 -5
  29. package/lib/__internal__/label/label.component.d.ts +2 -4
  30. package/lib/__internal__/label/label.component.js +0 -3
  31. package/lib/components/button/button-types.style.js +5 -0
  32. package/lib/components/button-toggle-group/button-toggle-group.component.js +9 -10
  33. package/lib/components/button-toggle-group/button-toggle-group.d.ts +3 -1
  34. package/lib/components/dialog/dialog.d.ts +1 -1
  35. package/lib/components/dialog-full-screen/dialog-full-screen.d.ts +1 -1
  36. package/lib/components/loader/loader-square.style.d.ts +2 -0
  37. package/lib/components/loader/loader.config.d.ts +1 -0
  38. package/lib/components/modal/__internal__/modal-manager.d.ts +19 -6
  39. package/lib/components/modal/__internal__/modal-manager.js +23 -41
  40. package/lib/components/modal/index.d.ts +1 -0
  41. package/lib/components/modal/modal.component.d.ts +44 -33
  42. package/lib/components/modal/modal.component.js +9 -14
  43. package/lib/components/modal/modal.style.d.ts +7 -2
  44. package/lib/components/switch/switch.component.js +0 -3
  45. package/lib/components/switch/switch.d.ts +0 -2
  46. package/lib/components/tabs/tab/tab.d.ts +3 -3
  47. package/package.json +3 -3
  48. package/esm/__internal__/form-field/form-field.d.ts +0 -66
  49. package/esm/components/modal/modal.d.ts +0 -35
  50. package/lib/__internal__/form-field/form-field.d.ts +0 -66
  51. package/lib/components/modal/modal.d.ts +0 -35
@@ -6,44 +6,27 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
6
6
 
7
7
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
8
 
9
- function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
10
-
11
- function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
12
-
13
- function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
14
-
15
- function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
16
-
17
- function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
18
-
19
- function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
20
-
21
- var _modalList = /*#__PURE__*/new WeakMap();
22
-
23
- var _getTopModal = /*#__PURE__*/new WeakSet();
24
-
25
9
  let ModalManagerInstance = /*#__PURE__*/function () {
26
10
  function ModalManagerInstance() {
27
11
  _classCallCheck(this, ModalManagerInstance);
28
12
 
29
- _getTopModal.add(this);
30
-
31
- _modalList.set(this, {
32
- writable: true,
33
- value: void 0
34
- });
13
+ _defineProperty(this, "modalList", void 0);
35
14
 
36
15
  _defineProperty(this, "addModal", (modal, setTriggerRefocusFlag) => {
16
+ if (!modal) {
17
+ return;
18
+ }
19
+
37
20
  const {
38
21
  modal: topModal,
39
22
  setTriggerRefocusFlag: setTrapFlag
40
- } = _classPrivateMethodGet(this, _getTopModal, _getTopModal2).call(this);
23
+ } = this.getTopModal();
41
24
 
42
25
  if (topModal && setTrapFlag) {
43
26
  setTrapFlag(false);
44
27
  }
45
28
 
46
- _classPrivateFieldGet(this, _modalList).push({
29
+ this.modalList.push({
47
30
  modal,
48
31
  setTriggerRefocusFlag
49
32
  });
@@ -55,15 +38,24 @@ let ModalManagerInstance = /*#__PURE__*/function () {
55
38
  window.__CARBON_INTERNALS_MODAL_LIST = [];
56
39
  }
57
40
 
58
- _classPrivateFieldSet(this, _modalList, window.__CARBON_INTERNALS_MODAL_LIST);
41
+ this.modalList = window.__CARBON_INTERNALS_MODAL_LIST;
59
42
  }
60
43
 
61
44
  _createClass(ModalManagerInstance, [{
45
+ key: "getTopModal",
46
+ value: function getTopModal() {
47
+ if (!this.modalList.length) {
48
+ return {};
49
+ }
50
+
51
+ return this.modalList[this.modalList.length - 1];
52
+ }
53
+ }, {
62
54
  key: "isTopmost",
63
55
  value: function isTopmost(modal) {
64
56
  const {
65
57
  modal: topModal
66
- } = _classPrivateMethodGet(this, _getTopModal, _getTopModal2).call(this);
58
+ } = this.getTopModal();
67
59
 
68
60
  if (!modal || !topModal) {
69
61
  return false;
@@ -74,7 +66,7 @@ let ModalManagerInstance = /*#__PURE__*/function () {
74
66
  }, {
75
67
  key: "removeModal",
76
68
  value: function removeModal(modal) {
77
- const modalIndex = _classPrivateFieldGet(this, _modalList).findIndex(({
69
+ const modalIndex = this.modalList.findIndex(({
78
70
  modal: m
79
71
  }) => m === modal);
80
72
 
@@ -82,15 +74,15 @@ let ModalManagerInstance = /*#__PURE__*/function () {
82
74
  return;
83
75
  }
84
76
 
85
- _classPrivateFieldGet(this, _modalList).splice(modalIndex, 1);
77
+ this.modalList.splice(modalIndex, 1);
86
78
 
87
- if (!_classPrivateFieldGet(this, _modalList).length) {
79
+ if (!this.modalList.length) {
88
80
  return;
89
81
  }
90
82
 
91
83
  const {
92
84
  setTriggerRefocusFlag
93
- } = _classPrivateMethodGet(this, _getTopModal, _getTopModal2).call(this);
85
+ } = this.getTopModal();
94
86
 
95
87
  if (setTriggerRefocusFlag) {
96
88
  setTriggerRefocusFlag(true);
@@ -100,22 +92,13 @@ let ModalManagerInstance = /*#__PURE__*/function () {
100
92
  key: "clearList",
101
93
  value: function clearList() {
102
94
  window.__CARBON_INTERNALS_MODAL_LIST = [];
103
-
104
- _classPrivateFieldSet(this, _modalList, window.__CARBON_INTERNALS_MODAL_LIST);
95
+ this.modalList = window.__CARBON_INTERNALS_MODAL_LIST;
105
96
  }
106
97
  }]);
107
98
 
108
99
  return ModalManagerInstance;
109
100
  }();
110
101
 
111
- function _getTopModal2() {
112
- if (!_classPrivateFieldGet(this, _modalList).length) {
113
- return {};
114
- }
115
-
116
- return _classPrivateFieldGet(this, _modalList)[_classPrivateFieldGet(this, _modalList).length - 1];
117
- }
118
-
119
102
  const ModalManager = new ModalManagerInstance();
120
103
  export { ModalManagerInstance };
121
104
  export default ModalManager;
@@ -1 +1,2 @@
1
1
  export { default, ModalContext } from "./modal.component";
2
+ export type { ModalProps, ModalContextProps } from "./modal.component";
@@ -1,35 +1,46 @@
1
- export const ModalContext: React.Context<{}>;
2
- export default Modal;
3
1
  import React from "react";
4
- declare function Modal({ children, open, onCancel, disableEscKey, disableClose, enableBackgroundUI, timeout, ...rest }: {
5
- [x: string]: any;
6
- children: any;
7
- open: any;
8
- onCancel: any;
9
- disableEscKey: any;
10
- disableClose: any;
11
- enableBackgroundUI: any;
12
- timeout: any;
13
- }): JSX.Element;
14
- declare namespace Modal {
15
- namespace propTypes {
16
- const children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
17
- const onCancel: PropTypes.Requireable<(...args: any[]) => any>;
18
- const open: PropTypes.Validator<boolean>;
19
- const enableBackgroundUI: PropTypes.Requireable<boolean>;
20
- const disableEscKey: PropTypes.Requireable<boolean>;
21
- const disableClose: PropTypes.Requireable<boolean>;
22
- const timeout: PropTypes.Requireable<number>;
23
- }
24
- namespace defaultProps {
25
- const onCancel_1: null;
26
- export { onCancel_1 as onCancel };
27
- const enableBackgroundUI_1: boolean;
28
- export { enableBackgroundUI_1 as enableBackgroundUI };
29
- const disableEscKey_1: boolean;
30
- export { disableEscKey_1 as disableEscKey };
31
- const timeout_1: number;
32
- export { timeout_1 as timeout };
33
- }
34
- }
35
2
  import PropTypes from "prop-types";
3
+ export interface ModalContextProps {
4
+ isInModal?: boolean;
5
+ isAnimationComplete?: boolean;
6
+ triggerRefocusFlag?: boolean;
7
+ }
8
+ export declare const ModalContext: React.Context<ModalContextProps>;
9
+ export interface ModalProps {
10
+ /** Modal content */
11
+ children?: React.ReactNode;
12
+ /** The ARIA role to be applied to the modal */
13
+ ariaRole?: string;
14
+ /** Determines if the Esc Key closes the modal */
15
+ disableEscKey?: boolean;
16
+ /** Determines if the Dialog can be closed */
17
+ disableClose?: boolean;
18
+ /** Determines if the background is disabled when the modal is open */
19
+ enableBackgroundUI?: boolean;
20
+ /** A custom close event handler */
21
+ onCancel?: (ev: React.KeyboardEvent<HTMLElement>) => void;
22
+ /** Sets the open state of the modal */
23
+ open: boolean;
24
+ /** Transition time */
25
+ timeout?: number;
26
+ }
27
+ declare const Modal: {
28
+ ({ children, open, onCancel, disableEscKey, disableClose, enableBackgroundUI, timeout, ...rest }: ModalProps): JSX.Element;
29
+ propTypes: {
30
+ /** Modal content */
31
+ children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
32
+ /** A custom close event handler */
33
+ onCancel: PropTypes.Requireable<(...args: any[]) => any>;
34
+ /** Controls the open state of the modal */
35
+ open: PropTypes.Validator<boolean>;
36
+ /** Determines if the background is disabled when the modal is open */
37
+ enableBackgroundUI: PropTypes.Requireable<boolean>;
38
+ /** Determines if the Esc Key closes the modal */
39
+ disableEscKey: PropTypes.Requireable<boolean>;
40
+ /** Determines if the Dialog can be closed */
41
+ disableClose: PropTypes.Requireable<boolean>;
42
+ /** Transition time */
43
+ timeout: PropTypes.Requireable<number>;
44
+ };
45
+ };
46
+ export default Modal;
@@ -2,6 +2,7 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
2
2
 
3
3
  import React, { useEffect, useRef, useCallback, useState } from "react";
4
4
  import PropTypes from "prop-types";
5
+ import PropTypes from "prop-types";
5
6
  import { TransitionGroup, CSSTransition } from "react-transition-group";
6
7
  import useScrollBlock from "../../hooks/__internal__/useScrollBlock";
7
8
  import Portal from "../portal";
@@ -14,15 +15,15 @@ const Modal = ({
14
15
  children,
15
16
  open,
16
17
  onCancel,
17
- disableEscKey,
18
+ disableEscKey = false,
18
19
  disableClose,
19
- enableBackgroundUI,
20
- timeout,
20
+ enableBackgroundUI = false,
21
+ timeout = 300,
21
22
  ...rest
22
23
  }) => {
23
- const ref = useRef();
24
- const backgroundNodeRef = useRef();
25
- const contentNodeRef = useRef();
24
+ const ref = useRef(null);
25
+ const backgroundNodeRef = useRef(null);
26
+ const contentNodeRef = useRef(null);
26
27
  const [isAnimationComplete, setAnimationComplete] = useState(false);
27
28
  const [triggerRefocusFlag, setTriggerRefocusFlag] = useState(false);
28
29
  const {
@@ -90,9 +91,10 @@ const Modal = ({
90
91
  isAnimationComplete,
91
92
  triggerRefocusFlag,
92
93
  isInModal: true
93
- },
94
+ }
95
+ }, /*#__PURE__*/React.createElement("div", {
94
96
  ref: contentNodeRef
95
- }, content)))));
97
+ }, content))))));
96
98
  };
97
99
 
98
100
  Modal.propTypes = {
@@ -117,10 +119,4 @@ Modal.propTypes = {
117
119
  /** Transition time */
118
120
  timeout: PropTypes.number
119
121
  };
120
- Modal.defaultProps = {
121
- onCancel: null,
122
- enableBackgroundUI: false,
123
- disableEscKey: false,
124
- timeout: 300
125
- };
126
122
  export default Modal;
@@ -1,2 +1,7 @@
1
- export const StyledModal: import("styled-components").StyledComponent<"div", any, {}, never>;
2
- export const StyledModalBackground: import("styled-components").StyledComponent<"div", any, {}, never>;
1
+ declare type TransitionProps = {
2
+ transitionName: string;
3
+ transitionTime: number;
4
+ };
5
+ declare const StyledModalBackground: import("styled-components").StyledComponent<"div", any, TransitionProps, never>;
6
+ declare const StyledModal: import("styled-components").StyledComponent<"div", any, TransitionProps, never>;
7
+ export { StyledModal, StyledModalBackground };
@@ -184,9 +184,6 @@ Switch.propTypes = {
184
184
  /** When true, validation icon will be placed on label instead of being placed by the input */
185
185
  validationOnLabel: PropTypes.bool,
186
186
 
187
- /** Override tab index on the validation and help icon */
188
- helpTabIndex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
189
-
190
187
  /** Triggers loading animation */
191
188
  loading: PropTypes.bool,
192
189
 
@@ -15,8 +15,6 @@ export interface SwitchProps extends CommonCheckableInputProps, MarginProps {
15
15
  adaptiveLabelBreakpoint?: number;
16
16
  /** Set the default value of the Switch if component is meant to be used as uncontrolled */
17
17
  defaultChecked?: boolean;
18
- /** Overrides the default tabindex of the Help component */
19
- helpTabIndex?: number | string;
20
18
  /** Text alignment of the label */
21
19
  labelAlign?: LabelAlign;
22
20
  /** When true label is inline */
@@ -2,9 +2,9 @@ import * as React from "react";
2
2
  import { PaddingProps } from "styled-system";
3
3
 
4
4
  export interface TabContextProps {
5
- setError: (childId: string, hasError: boolean) => void;
6
- setWarning: (childId: string, hasWarning: boolean) => void;
7
- setInfo: (childId: string, hasInfo: boolean) => void;
5
+ setError?: (childId: string, hasError: boolean) => void;
6
+ setWarning?: (childId: string, hasWarning: boolean) => void;
7
+ setInfo?: (childId: string, hasInfo: boolean) => void;
8
8
  }
9
9
 
10
10
  export interface TabProps extends PaddingProps {
@@ -0,0 +1,59 @@
1
+ import React from "react";
2
+ import { ValidationProps } from "__internal__/validations";
3
+ import { MarginProps } from "styled-system";
4
+ import { TagProps } from "../utils/helpers/tags/tags";
5
+ import { IconType } from "../../components/icon";
6
+ interface CommonFormFieldProps extends MarginProps, ValidationProps {
7
+ /** If true, the component will be disabled */
8
+ disabled?: boolean;
9
+ /** Help content to be displayed under an input */
10
+ fieldHelp?: React.ReactNode;
11
+ /** The unique id of the Help component tooltip, used for accessibility */
12
+ tooltipId?: string;
13
+ /** The unique id of the FieldHelp component */
14
+ fieldHelpId?: string;
15
+ /** Label content */
16
+ label?: React.ReactNode;
17
+ /** Text alignment of the label */
18
+ labelAlign?: "left" | "right";
19
+ /** A message that the Help component will display */
20
+ labelHelp?: React.ReactNode;
21
+ /** Help Icon type */
22
+ labelHelpIcon?: IconType;
23
+ /** The unique id of the label element */
24
+ labelId?: string;
25
+ /** When true label is inline */
26
+ labelInline?: boolean;
27
+ /** Spacing between label and a field for inline label, given number will be multiplied by base spacing unit (8) */
28
+ labelSpacing?: 1 | 2;
29
+ /** Label width */
30
+ labelWidth?: number;
31
+ /** If true the label switches position with the input */
32
+ reverse?: boolean;
33
+ /** Id of the validation icon */
34
+ validationIconId?: string;
35
+ }
36
+ export interface FormFieldProps extends CommonFormFieldProps, TagProps {
37
+ /** Breakpoint for adaptive label (inline labels change to top aligned). Enables the adaptive behaviour when set */
38
+ adaptiveLabelBreakpoint?: number;
39
+ /** Content to be rendered inside the FormField */
40
+ children?: React.ReactNode;
41
+ /**
42
+ * If true, the FieldHelp will be displayed inline
43
+ * To be used with labelInline prop set to true
44
+ */
45
+ fieldHelpInline?: boolean;
46
+ /** Id of the element a label should be bound to */
47
+ id: string;
48
+ /** [Legacy] Flag to configure component as optional in Form */
49
+ isOptional?: boolean;
50
+ /** Flag to configure component as mandatory */
51
+ isRequired?: boolean;
52
+ /** Whether to show the validation icon */
53
+ useValidationIcon?: boolean;
54
+ }
55
+ declare const FormField: {
56
+ ({ children, disabled, fieldHelp: fieldHelpContent, fieldHelpInline, error, warning, info, tooltipId, fieldHelpId, label, labelId, labelAlign, labelHelp, labelHelpIcon, labelInline, labelSpacing, labelWidth, id, reverse, isOptional, useValidationIcon, adaptiveLabelBreakpoint, isRequired, validationIconId, ...rest }: FormFieldProps): JSX.Element;
57
+ displayName: string;
58
+ };
59
+ export default FormField;