carbon-react 110.0.1 → 110.0.4

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 (71) hide show
  1. package/esm/__internal__/focus-trap/focus-trap-utils.d.ts +4 -3
  2. package/esm/__internal__/focus-trap/focus-trap-utils.js +3 -12
  3. package/esm/__internal__/focus-trap/focus-trap.component.d.ts +19 -0
  4. package/esm/__internal__/focus-trap/focus-trap.component.js +61 -45
  5. package/esm/__internal__/focus-trap/index.d.ts +2 -0
  6. package/esm/__internal__/utils/helpers/tags/tags-specs/tags-specs.d.ts +1 -1
  7. package/esm/components/definition-list/__internal__/dl.context.d.ts +6 -0
  8. package/esm/components/definition-list/dd.component.d.ts +8 -0
  9. package/esm/components/definition-list/dd.component.js +310 -5
  10. package/esm/components/definition-list/definition-list.style.d.ts +22 -0
  11. package/esm/components/definition-list/definition-list.style.js +3 -4
  12. package/esm/components/definition-list/dl.component.d.ts +9 -0
  13. package/esm/components/definition-list/dl.component.js +323 -27
  14. package/esm/components/definition-list/dt.component.d.ts +8 -0
  15. package/esm/components/definition-list/dt.component.js +310 -5
  16. package/esm/components/definition-list/index.d.ts +6 -3
  17. package/esm/components/definition-list/index.js +2 -2
  18. package/esm/components/dialog/dialog.component.js +3 -3
  19. package/esm/components/dialog-full-screen/dialog-full-screen.component.js +2 -2
  20. package/esm/components/dialog-full-screen/dialog-full-screen.style.js +4 -0
  21. package/esm/components/flat-table/flat-table-row/flat-table-row.style.js +30 -2
  22. package/esm/components/modal/modal.component.d.ts +1 -20
  23. package/esm/components/modal/modal.component.js +8 -21
  24. package/esm/components/profile/index.d.ts +2 -1
  25. package/esm/components/profile/profile.component.d.ts +18 -0
  26. package/esm/components/profile/profile.component.js +8 -21
  27. package/esm/components/profile/profile.config.d.ts +55 -0
  28. package/esm/components/profile/profile.style.d.ts +16 -0
  29. package/esm/components/profile/profile.style.js +5 -14
  30. package/esm/components/sidebar/sidebar.component.js +1 -1
  31. package/esm/components/sidebar/sidebar.style.js +5 -0
  32. package/lib/__internal__/focus-trap/focus-trap-utils.d.ts +4 -3
  33. package/lib/__internal__/focus-trap/focus-trap-utils.js +5 -13
  34. package/lib/__internal__/focus-trap/focus-trap.component.d.ts +19 -0
  35. package/lib/__internal__/focus-trap/focus-trap.component.js +59 -43
  36. package/lib/__internal__/focus-trap/index.d.ts +2 -0
  37. package/lib/__internal__/utils/helpers/tags/tags-specs/tags-specs.d.ts +1 -1
  38. package/lib/components/definition-list/__internal__/dl.context.d.ts +6 -0
  39. package/lib/components/definition-list/dd.component.d.ts +8 -0
  40. package/lib/components/definition-list/dd.component.js +311 -7
  41. package/lib/components/definition-list/definition-list.style.d.ts +22 -0
  42. package/lib/components/definition-list/definition-list.style.js +3 -4
  43. package/lib/components/definition-list/dl.component.d.ts +9 -0
  44. package/lib/components/definition-list/dl.component.js +326 -28
  45. package/lib/components/definition-list/dt.component.d.ts +8 -0
  46. package/lib/components/definition-list/dt.component.js +311 -7
  47. package/lib/components/definition-list/index.d.ts +6 -3
  48. package/lib/components/definition-list/index.js +8 -8
  49. package/lib/components/dialog/dialog.component.js +3 -3
  50. package/lib/components/dialog-full-screen/dialog-full-screen.component.js +2 -2
  51. package/lib/components/dialog-full-screen/dialog-full-screen.style.js +4 -0
  52. package/lib/components/flat-table/flat-table-row/flat-table-row.style.js +30 -2
  53. package/lib/components/modal/modal.component.d.ts +1 -20
  54. package/lib/components/modal/modal.component.js +8 -20
  55. package/lib/components/profile/index.d.ts +2 -1
  56. package/lib/components/profile/profile.component.d.ts +18 -0
  57. package/lib/components/profile/profile.component.js +9 -24
  58. package/lib/components/profile/profile.config.d.ts +55 -0
  59. package/lib/components/profile/profile.style.d.ts +16 -0
  60. package/lib/components/profile/profile.style.js +5 -14
  61. package/lib/components/sidebar/sidebar.component.js +1 -1
  62. package/lib/components/sidebar/sidebar.style.js +5 -0
  63. package/package.json +1 -1
  64. package/esm/components/definition-list/dd.d.ts +0 -11
  65. package/esm/components/definition-list/dl.d.ts +0 -19
  66. package/esm/components/definition-list/dt.d.ts +0 -10
  67. package/esm/components/profile/profile.d.ts +0 -18
  68. package/lib/components/definition-list/dd.d.ts +0 -11
  69. package/lib/components/definition-list/dl.d.ts +0 -19
  70. package/lib/components/definition-list/dt.d.ts +0 -10
  71. package/lib/components/profile/profile.d.ts +0 -18
@@ -7,12 +7,12 @@ const ProfileNameStyle = styled.span`
7
7
  font-weight: bold;
8
8
  display: block;
9
9
  font-size: ${({
10
- size
10
+ size = "M"
11
11
  }) => profileConfigSizes[size].nameSize};
12
12
  `;
13
13
  const ProfileEmailStyle = styled.span`
14
14
  font-size: ${({
15
- size
15
+ size = "M"
16
16
  }) => profileConfigSizes[size].emailSize};
17
17
  `;
18
18
  const ProfileStyle = styled.div`
@@ -29,13 +29,13 @@ const ProfileDetailsStyle = styled.div`
29
29
  display: inline-block;
30
30
  margin-top: ${({
31
31
  hasSrc,
32
- size
32
+ size = "M"
33
33
  }) => hasSrc ? profileConfigSizes[size].marginTop : ""};
34
34
  line-height: ${({
35
- size
35
+ size = "M"
36
36
  }) => profileConfigSizes[size].lineHeight};
37
37
  margin-left: ${({
38
- size
38
+ size = "M"
39
39
  }) => profileConfigSizes[size].marginLeft};
40
40
  `;
41
41
  const ProfileAvatarStyle = styled(Portrait)`
@@ -44,13 +44,4 @@ const ProfileAvatarStyle = styled(Portrait)`
44
44
  ProfileStyle.defaultProps = {
45
45
  theme: baseTheme
46
46
  };
47
- ProfileNameStyle.defaultProps = {
48
- size: "M"
49
- };
50
- ProfileEmailStyle.defaultProps = {
51
- size: "M"
52
- };
53
- ProfileDetailsStyle.defaultProps = {
54
- size: "M"
55
- };
56
47
  export { ProfileStyle, ProfileNameStyle, ProfileDetailsStyle, ProfileAvatarStyle, ProfileEmailStyle };
@@ -33,7 +33,7 @@ const Sidebar = /*#__PURE__*/React.forwardRef(({
33
33
  const {
34
34
  current: titleId
35
35
  } = useRef(createGuid());
36
- let sidebarRef = useRef();
36
+ let sidebarRef = useRef(null);
37
37
  if (ref) sidebarRef = ref;
38
38
 
39
39
  const closeIcon = () => {
@@ -3,6 +3,11 @@ import baseTheme from "../../style/themes/base";
3
3
  import StyledIconButton from "../icon-button/icon-button.style";
4
4
  import { SIDEBAR_SIZES_CSS } from "./sidebar.config";
5
5
  const SidebarStyle = styled.div`
6
+ // prevents outline being added in safari
7
+ :focus {
8
+ outline: none;
9
+ }
10
+
6
11
  ${({
7
12
  onCancel,
8
13
  position,
@@ -1,3 +1,4 @@
1
- export const defaultFocusableSelectors: "button:not([disabled]), [href], input:not([type=\"hidden\"]):not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]";
2
- export function getNextElement(element: any, focusableElements: any, shiftKey: any): any;
3
- export function setElementFocus(element: any): void;
1
+ declare const defaultFocusableSelectors = "button:not([disabled]), [href], input:not([type=\"hidden\"]):not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]";
2
+ declare const setElementFocus: (element: HTMLElement) => void;
3
+ declare const getNextElement: (element: HTMLElement, focusableElements: HTMLElement[], shiftKey: boolean) => HTMLElement;
4
+ export { defaultFocusableSelectors, getNextElement, setElementFocus };
@@ -3,14 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.setElementFocus = setElementFocus;
7
- exports.getNextElement = exports.defaultFocusableSelectors = void 0;
6
+ exports.setElementFocus = exports.getNextElement = exports.defaultFocusableSelectors = void 0;
8
7
  const defaultFocusableSelectors = 'button:not([disabled]), [href], input:not([type="hidden"]):not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]';
9
8
  exports.defaultFocusableSelectors = defaultFocusableSelectors;
9
+ const INTERVAL = 10;
10
+ const MAX_TIME = 100;
10
11
 
11
- const waitForVisibleAndFocus = element => {
12
- const INTERVAL = 10;
13
- const MAX_TIME = 100;
12
+ const setElementFocus = element => {
14
13
  let timeSoFar = 0;
15
14
 
16
15
  const stylesMatch = () => {
@@ -32,14 +31,7 @@ const waitForVisibleAndFocus = element => {
32
31
  check();
33
32
  };
34
33
 
35
- function setElementFocus(element) {
36
- if (typeof element === "function") {
37
- element();
38
- } else {
39
- const el = element.current || element;
40
- waitForVisibleAndFocus(el);
41
- }
42
- }
34
+ exports.setElementFocus = setElementFocus;
43
35
 
44
36
  const isRadio = element => {
45
37
  return element.hasAttribute("type") && element.getAttribute("type") === "radio";
@@ -0,0 +1,19 @@
1
+ import React from "react";
2
+ declare type CustomRefObject<T> = {
3
+ current?: T | null;
4
+ };
5
+ export interface FocusTrapProps {
6
+ children: React.ReactNode;
7
+ autoFocus?: boolean;
8
+ /** provide a custom first element to focus */
9
+ focusFirstElement?: CustomRefObject<HTMLElement> | HTMLElement;
10
+ /** a custom callback that will override the default focus trap behaviour */
11
+ bespokeTrap?: (ev: KeyboardEvent, firstElement?: HTMLElement, lastElement?: HTMLElement) => void;
12
+ /** a ref to the container wrapping the focusable elements */
13
+ wrapperRef?: CustomRefObject<HTMLElement>;
14
+ isOpen?: boolean;
15
+ /** an optional array of refs to containers whose content should also be reachable from the FocusTrap */
16
+ additionalWrapperRefs?: CustomRefObject<HTMLElement>[];
17
+ }
18
+ declare const FocusTrap: ({ children, autoFocus, focusFirstElement, bespokeTrap, wrapperRef, isOpen, additionalWrapperRefs, }: FocusTrapProps) => JSX.Element;
19
+ export default FocusTrap;
@@ -46,7 +46,8 @@ const FocusTrap = ({
46
46
 
47
47
  return Array.from(candidate).some((el, i) => el !== focusableElements[i]);
48
48
  }, [focusableElements]);
49
- const allRefs = [wrapperRef, ...additionalWrapperRefs].map(ref => ref === null || ref === void 0 ? void 0 : ref.current);
49
+ const trapWrappers = (0, _react.useMemo)(() => additionalWrapperRefs !== null && additionalWrapperRefs !== void 0 && additionalWrapperRefs.length ? [wrapperRef, ...additionalWrapperRefs] : [wrapperRef], [additionalWrapperRefs, wrapperRef]);
50
+ const allRefs = trapWrappers.map(ref => ref === null || ref === void 0 ? void 0 : ref.current);
50
51
  const updateFocusableElements = (0, _react.useCallback)(() => {
51
52
  const elements = [];
52
53
  allRefs.forEach(ref => {
@@ -63,14 +64,18 @@ const FocusTrap = ({
63
64
  }, [hasNewInputs, allRefs]);
64
65
  (0, _react.useEffect)(() => {
65
66
  const observer = new MutationObserver(updateFocusableElements);
66
- observer.observe(trapRef.current, {
67
- subtree: true,
68
- childList: true,
69
- attributes: true,
70
- characterData: true
67
+ trapWrappers.forEach(wrapper => {
68
+ if (wrapper !== null && wrapper !== void 0 && wrapper.current) {
69
+ observer.observe(wrapper === null || wrapper === void 0 ? void 0 : wrapper.current, {
70
+ subtree: true,
71
+ childList: true,
72
+ attributes: true,
73
+ characterData: true
74
+ });
75
+ }
71
76
  });
72
77
  return () => observer.disconnect();
73
- }, [updateFocusableElements]);
78
+ }, [updateFocusableElements, trapWrappers]);
74
79
  (0, _react.useLayoutEffect)(() => {
75
80
  updateFocusableElements();
76
81
  }, [children, updateFocusableElements]);
@@ -78,7 +83,8 @@ const FocusTrap = ({
78
83
  const prevShouldSetFocus = (0, _usePrevious.default)(shouldSetFocus);
79
84
  (0, _react.useEffect)(() => {
80
85
  if (shouldSetFocus && !prevShouldSetFocus) {
81
- (0, _focusTrapUtils.setElementFocus)(focusFirstElement || (wrapperRef === null || wrapperRef === void 0 ? void 0 : wrapperRef.current));
86
+ const candidateFirstElement = focusFirstElement && "current" in focusFirstElement ? focusFirstElement.current : focusFirstElement;
87
+ (0, _focusTrapUtils.setElementFocus)(candidateFirstElement || (wrapperRef === null || wrapperRef === void 0 ? void 0 : wrapperRef.current));
82
88
  }
83
89
  }, [shouldSetFocus, prevShouldSetFocus, focusFirstElement, wrapperRef]);
84
90
  (0, _react.useEffect)(() => {
@@ -88,19 +94,17 @@ const FocusTrap = ({
88
94
  return;
89
95
  }
90
96
 
91
- const {
92
- activeElement
93
- } = document;
97
+ const activeElement = document.activeElement;
94
98
 
95
99
  if (ev.key === "Tab") {
96
- if (!focusableElements.length) {
100
+ if (!(focusableElements !== null && focusableElements !== void 0 && focusableElements.length)) {
97
101
  /* Block the trap */
98
102
  ev.preventDefault();
99
103
  } else if (ev.shiftKey) {
100
104
  /* shift + tab */
101
105
  let elementToFocus;
102
106
 
103
- if (activeElement === wrapperRef.current) {
107
+ if (activeElement === (wrapperRef === null || wrapperRef === void 0 ? void 0 : wrapperRef.current)) {
104
108
  elementToFocus = (0, _focusTrapUtils.getNextElement)(firstElement, focusableElements, ev.shiftKey);
105
109
  } else {
106
110
  elementToFocus = (0, _focusTrapUtils.getNextElement)(activeElement, focusableElements, ev.shiftKey);
@@ -116,9 +120,9 @@ const FocusTrap = ({
116
120
  }
117
121
  };
118
122
 
119
- document.addEventListener("keydown", trapFn);
123
+ document.addEventListener("keydown", trapFn, true);
120
124
  return function cleanup() {
121
- document.removeEventListener("keydown", trapFn);
125
+ document.removeEventListener("keydown", trapFn, true);
122
126
  };
123
127
  }, [firstElement, lastElement, focusableElements, bespokeTrap, wrapperRef]);
124
128
  const updateCurrentFocusedElement = (0, _react.useCallback)(() => {
@@ -170,7 +174,10 @@ const FocusTrap = ({
170
174
 
171
175
 
172
176
  const clonedChildren = _react.default.Children.map(children, child => {
173
- return /*#__PURE__*/_react.default.cloneElement(child, focusProps(child.props.tabIndex === undefined));
177
+ var _focusableChild$props;
178
+
179
+ const focusableChild = child;
180
+ return /*#__PURE__*/_react.default.cloneElement(focusableChild, focusProps((focusableChild === null || focusableChild === void 0 ? void 0 : (_focusableChild$props = focusableChild.props) === null || _focusableChild$props === void 0 ? void 0 : _focusableChild$props.tabIndex) === undefined));
174
181
  });
175
182
 
176
183
  return /*#__PURE__*/_react.default.createElement("div", {
@@ -179,34 +186,43 @@ const FocusTrap = ({
179
186
  };
180
187
 
181
188
  FocusTrap.propTypes = {
182
- children: _propTypes.default.node.isRequired,
183
-
184
- /** flag to set focus automatically on first render */
185
- autoFocus: _propTypes.default.bool,
186
-
187
- /** provide a custom first element to focus */
188
- focusFirstElement: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.shape({
189
- current: _propTypes.default.any
189
+ "additionalWrapperRefs": _propTypes.default.arrayOf(_propTypes.default.shape({
190
+ "current": function (props, propName) {
191
+ if (props[propName] == null) {
192
+ return null;
193
+ } else if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
194
+ return new Error("Expected prop '" + propName + "' to be of type Element");
195
+ }
196
+ }
197
+ })),
198
+ "autoFocus": _propTypes.default.bool,
199
+ "bespokeTrap": _propTypes.default.func,
200
+ "children": _propTypes.default.node,
201
+ "focusFirstElement": _propTypes.default.oneOfType([function (props, propName) {
202
+ if (props[propName] == null) {
203
+ return new Error("Prop '" + propName + "' is required but wasn't specified");
204
+ } else if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
205
+ return new Error("Expected prop '" + propName + "' to be of type Element");
206
+ }
207
+ }, _propTypes.default.shape({
208
+ "current": function (props, propName) {
209
+ if (props[propName] == null) {
210
+ return null;
211
+ } else if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
212
+ return new Error("Expected prop '" + propName + "' to be of type Element");
213
+ }
214
+ }
190
215
  })]),
191
-
192
- /** a custom callback that will override the default focus trap behaviour */
193
- bespokeTrap: _propTypes.default.func,
194
-
195
- /** a ref to the container wrapping the focusable elements */
196
- wrapperRef: _propTypes.default.shape({
197
- current: _propTypes.default.any
198
- }),
199
-
200
- /* whether the modal (etc.) component that the focus trap is inside is open or not */
201
- isOpen: _propTypes.default.bool,
202
-
203
- /** an optional array of refs to containers whose content should also be reachable from the FocusTrap */
204
- additionalWrapperRefs: _propTypes.default.arrayOf(_propTypes.default.shape({
205
- current: _propTypes.default.any
206
- }))
207
- };
208
- FocusTrap.defaultProps = {
209
- additionalWrapperRefs: []
216
+ "isOpen": _propTypes.default.bool,
217
+ "wrapperRef": _propTypes.default.shape({
218
+ "current": function (props, propName) {
219
+ if (props[propName] == null) {
220
+ return null;
221
+ } else if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
222
+ return new Error("Expected prop '" + propName + "' to be of type Element");
223
+ }
224
+ }
225
+ })
210
226
  };
211
227
  var _default = FocusTrap;
212
228
  exports.default = _default;
@@ -0,0 +1,2 @@
1
+ export { default } from "./focus-trap.component";
2
+ export type { FocusTrapProps } from "./focus-trap.component";
@@ -1,4 +1,4 @@
1
1
  import { ReactWrapper, ShallowWrapper } from "enzyme";
2
- declare const elementsTagTest: (wrapper: ReactWrapper, elements: string[]) => void;
2
+ declare const elementsTagTest: (wrapper: ReactWrapper | ShallowWrapper, elements: string[]) => void;
3
3
  declare const rootTagTest: (rootNode: ReactWrapper | ShallowWrapper, comp: string, elem?: string | undefined, role?: string | undefined) => void;
4
4
  export { elementsTagTest, rootTagTest };
@@ -0,0 +1,6 @@
1
+ import React from "react";
2
+ interface DlContextProps {
3
+ asSingleColumn?: boolean;
4
+ }
5
+ declare const _default: React.Context<DlContextProps>;
6
+ export default _default;
@@ -0,0 +1,8 @@
1
+ import React from "react";
2
+ import { SpaceProps } from "styled-system";
3
+ export interface DdProps extends SpaceProps {
4
+ /** Prop for what will render in the `<Dd></Dd>` tags */
5
+ children: React.ReactNode;
6
+ }
7
+ declare const Dd: ({ children, ...rest }: DdProps) => JSX.Element;
8
+ export default Dd;