carbon-react 142.7.0 → 142.8.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.
@@ -1,5 +1,5 @@
1
1
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
- import React, { useRef, useEffect, useLayoutEffect, useCallback, useImperativeHandle, forwardRef } from "react";
2
+ import React, { useRef, useEffect, useLayoutEffect, useCallback, useImperativeHandle, forwardRef, useState } from "react";
3
3
  import PropTypes from "prop-types";
4
4
  import createGuid from "../../__internal__/utils/helpers/guid";
5
5
  import Modal from "../modal";
@@ -46,6 +46,8 @@ const Dialog = /*#__PURE__*/forwardRef(({
46
46
  const containerRef = useRef(null);
47
47
  const innerContentRef = useRef(null);
48
48
  const titleRef = useRef(null);
49
+ const [breakpointOffset, setBreakpointOffset] = useState(undefined);
50
+ const isDialogMaximised = size === "maximise";
49
51
  const listenersAdded = useRef(false);
50
52
  const {
51
53
  current: titleId
@@ -78,9 +80,15 @@ const Dialog = /*#__PURE__*/forwardRef(({
78
80
  if (midPointX < 0) {
79
81
  midPointX = 0;
80
82
  }
83
+ if (isDialogMaximised) {
84
+ const breakPoint = window.innerWidth > 960 ? 32 : 16;
85
+ midPointX = breakPoint;
86
+ midPointY = breakPoint;
87
+ setBreakpointOffset(breakPoint);
88
+ }
81
89
  containerRef.current.style.top = `${midPointY}px`;
82
90
  containerRef.current.style.left = `${midPointX}px`;
83
- }, []);
91
+ }, [size]);
84
92
  useResizeObserver(innerContentRef, centerDialog, !open);
85
93
  const addListeners = useCallback(() => {
86
94
  /* istanbul ignore else */
@@ -172,7 +180,7 @@ const Dialog = /*#__PURE__*/forwardRef(({
172
180
  "data-role": dataRole,
173
181
  "aria-modal": isTopModal ? true : undefined,
174
182
  ref: containerRef,
175
- topMargin: TOP_MARGIN
183
+ topMargin: isDialogMaximised && breakpointOffset ? breakpointOffset * 2 : TOP_MARGIN
176
184
  }, dialogProps, {
177
185
  role: role,
178
186
  tabIndex: -1
@@ -243,7 +251,7 @@ if (process.env.NODE_ENV !== "production") {
243
251
  "open": PropTypes.bool.isRequired,
244
252
  "role": PropTypes.string,
245
253
  "showCloseIcon": PropTypes.bool,
246
- "size": PropTypes.oneOf(["auto", "extra-large", "extra-small", "large", "medium-large", "medium-small", "medium", "small"]),
254
+ "size": PropTypes.oneOf(["auto", "extra-large", "extra-small", "large", "maximise", "medium-large", "medium-small", "medium", "small"]),
247
255
  "subtitle": PropTypes.node,
248
256
  "timeout": PropTypes.number,
249
257
  "title": PropTypes.node,
@@ -1,4 +1,4 @@
1
- export declare const DIALOG_SIZES: readonly ["auto", "extra-small", "small", "medium-small", "medium", "medium-large", "large", "extra-large"];
1
+ export declare const DIALOG_SIZES: readonly ["auto", "extra-small", "small", "medium-small", "medium", "medium-large", "large", "extra-large", "maximise"];
2
2
  export declare const TOP_MARGIN = 20;
3
3
  export declare const CONTENT_TOP_PADDING = 24;
4
4
  export declare const HORIZONTAL_PADDING = 32;
@@ -1,4 +1,4 @@
1
- export const DIALOG_SIZES = ["auto", "extra-small", "small", "medium-small", "medium", "medium-large", "large", "extra-large"];
1
+ export const DIALOG_SIZES = ["auto", "extra-small", "small", "medium-small", "medium", "medium-large", "large", "extra-large", "maximise"];
2
2
  export const TOP_MARGIN = 20;
3
3
  export const CONTENT_TOP_PADDING = 24;
4
4
  export const HORIZONTAL_PADDING = 32;
@@ -6,7 +6,11 @@ declare type StyledDialogProps = {
6
6
  dialogHeight?: string;
7
7
  backgroundColor: string;
8
8
  };
9
- declare const StyledDialog: import("styled-components").StyledComponent<"div", any, StyledDialogProps & ContentPaddingInterface, never>;
9
+ declare const StyledDialog: import("styled-components").StyledComponent<"div", any, {
10
+ isDialogMaximised: boolean;
11
+ isDialogMaximisedSmallViewport: boolean;
12
+ isDialogMaximisedLargeViewport: boolean;
13
+ } & StyledDialogProps & ContentPaddingInterface, "isDialogMaximised" | "isDialogMaximisedSmallViewport" | "isDialogMaximisedLargeViewport">;
10
14
  declare type StyledDialogTitleProps = {
11
15
  showCloseIcon?: boolean;
12
16
  hasSubtitle?: boolean;
@@ -20,7 +20,19 @@ const calculatePaddingTopInnerContent = ({
20
20
  py,
21
21
  p
22
22
  }) => [py, p].some(padding => padding !== undefined) ? 0 : `${CONTENT_TOP_PADDING}px`;
23
- const StyledDialog = styled.div`
23
+ const StyledDialog = styled.div.attrs(({
24
+ topMargin,
25
+ size
26
+ }) => {
27
+ const isDialogMaximised = size === "maximise";
28
+ const isDialogMaximisedSmallViewport = topMargin === 32;
29
+ const isDialogMaximisedLargeViewport = topMargin === 64;
30
+ return {
31
+ isDialogMaximised,
32
+ isDialogMaximisedSmallViewport,
33
+ isDialogMaximisedLargeViewport
34
+ };
35
+ })`
24
36
  box-shadow: var(--boxShadow300);
25
37
  display: flex;
26
38
  flex-direction: column;
@@ -33,6 +45,9 @@ const StyledDialog = styled.div`
33
45
  max-height: ${({
34
46
  topMargin
35
47
  }) => `calc(100vh - ${topMargin}px)`};
48
+ ${({
49
+ isDialogMaximised
50
+ }) => isDialogMaximised && "height: 100%"};
36
51
 
37
52
  &:focus {
38
53
  outline: none;
@@ -45,9 +60,10 @@ const StyledDialog = styled.div`
45
60
  `}
46
61
 
47
62
  ${({
48
- size
63
+ size,
64
+ topMargin
49
65
  }) => size && css`
50
- max-width: ${dialogSizes[size]};
66
+ max-width: ${size === "maximise" ? `calc(100vw - ${topMargin}px)` : dialogSizes[size]};
51
67
  width: 100%;
52
68
  `}
53
69
 
@@ -57,7 +73,17 @@ const StyledDialog = styled.div`
57
73
  height: ${dialogHeight}px;
58
74
  `}
59
75
 
76
+ /* We're overriding the max-height on the form content to account for a larger height when in a smaller viewport.
77
+ TODO: Remove this upon the completion of FE-6643. */
60
78
  ${StyledForm} {
79
+ ${({
80
+ isDialogMaximised,
81
+ isDialogMaximisedSmallViewport
82
+ }) => isDialogMaximised && css`
83
+ ${isDialogMaximisedSmallViewport && "max-height: calc(100vh - 184px);"}
84
+ height: 100%;
85
+ `}
86
+
61
87
  padding-bottom: 0px;
62
88
  box-sizing: border-box;
63
89
  }
@@ -55,6 +55,8 @@ const Dialog = exports.Dialog = /*#__PURE__*/(0, _react.forwardRef)(({
55
55
  const containerRef = (0, _react.useRef)(null);
56
56
  const innerContentRef = (0, _react.useRef)(null);
57
57
  const titleRef = (0, _react.useRef)(null);
58
+ const [breakpointOffset, setBreakpointOffset] = (0, _react.useState)(undefined);
59
+ const isDialogMaximised = size === "maximise";
58
60
  const listenersAdded = (0, _react.useRef)(false);
59
61
  const {
60
62
  current: titleId
@@ -87,9 +89,15 @@ const Dialog = exports.Dialog = /*#__PURE__*/(0, _react.forwardRef)(({
87
89
  if (midPointX < 0) {
88
90
  midPointX = 0;
89
91
  }
92
+ if (isDialogMaximised) {
93
+ const breakPoint = window.innerWidth > 960 ? 32 : 16;
94
+ midPointX = breakPoint;
95
+ midPointY = breakPoint;
96
+ setBreakpointOffset(breakPoint);
97
+ }
90
98
  containerRef.current.style.top = `${midPointY}px`;
91
99
  containerRef.current.style.left = `${midPointX}px`;
92
- }, []);
100
+ }, [size]);
93
101
  (0, _useResizeObserver.default)(innerContentRef, centerDialog, !open);
94
102
  const addListeners = (0, _react.useCallback)(() => {
95
103
  /* istanbul ignore else */
@@ -181,7 +189,7 @@ const Dialog = exports.Dialog = /*#__PURE__*/(0, _react.forwardRef)(({
181
189
  "data-role": dataRole,
182
190
  "aria-modal": isTopModal ? true : undefined,
183
191
  ref: containerRef,
184
- topMargin: _dialog2.TOP_MARGIN
192
+ topMargin: isDialogMaximised && breakpointOffset ? breakpointOffset * 2 : _dialog2.TOP_MARGIN
185
193
  }, dialogProps, {
186
194
  role: role,
187
195
  tabIndex: -1
@@ -252,7 +260,7 @@ if (process.env.NODE_ENV !== "production") {
252
260
  "open": _propTypes.default.bool.isRequired,
253
261
  "role": _propTypes.default.string,
254
262
  "showCloseIcon": _propTypes.default.bool,
255
- "size": _propTypes.default.oneOf(["auto", "extra-large", "extra-small", "large", "medium-large", "medium-small", "medium", "small"]),
263
+ "size": _propTypes.default.oneOf(["auto", "extra-large", "extra-small", "large", "maximise", "medium-large", "medium-small", "medium", "small"]),
256
264
  "subtitle": _propTypes.default.node,
257
265
  "timeout": _propTypes.default.number,
258
266
  "title": _propTypes.default.node,
@@ -1,4 +1,4 @@
1
- export declare const DIALOG_SIZES: readonly ["auto", "extra-small", "small", "medium-small", "medium", "medium-large", "large", "extra-large"];
1
+ export declare const DIALOG_SIZES: readonly ["auto", "extra-small", "small", "medium-small", "medium", "medium-large", "large", "extra-large", "maximise"];
2
2
  export declare const TOP_MARGIN = 20;
3
3
  export declare const CONTENT_TOP_PADDING = 24;
4
4
  export declare const HORIZONTAL_PADDING = 32;
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.TOP_MARGIN = exports.HORIZONTAL_PADDING = exports.DIALOG_SIZES = exports.CONTENT_TOP_PADDING = exports.CONTENT_BOTTOM_PADDING = void 0;
7
- const DIALOG_SIZES = exports.DIALOG_SIZES = ["auto", "extra-small", "small", "medium-small", "medium", "medium-large", "large", "extra-large"];
7
+ const DIALOG_SIZES = exports.DIALOG_SIZES = ["auto", "extra-small", "small", "medium-small", "medium", "medium-large", "large", "extra-large", "maximise"];
8
8
  const TOP_MARGIN = exports.TOP_MARGIN = 20;
9
9
  const CONTENT_TOP_PADDING = exports.CONTENT_TOP_PADDING = 24;
10
10
  const HORIZONTAL_PADDING = exports.HORIZONTAL_PADDING = 32;
@@ -6,7 +6,11 @@ declare type StyledDialogProps = {
6
6
  dialogHeight?: string;
7
7
  backgroundColor: string;
8
8
  };
9
- declare const StyledDialog: import("styled-components").StyledComponent<"div", any, StyledDialogProps & ContentPaddingInterface, never>;
9
+ declare const StyledDialog: import("styled-components").StyledComponent<"div", any, {
10
+ isDialogMaximised: boolean;
11
+ isDialogMaximisedSmallViewport: boolean;
12
+ isDialogMaximisedLargeViewport: boolean;
13
+ } & StyledDialogProps & ContentPaddingInterface, "isDialogMaximised" | "isDialogMaximisedSmallViewport" | "isDialogMaximisedLargeViewport">;
10
14
  declare type StyledDialogTitleProps = {
11
15
  showCloseIcon?: boolean;
12
16
  hasSubtitle?: boolean;
@@ -29,7 +29,19 @@ const calculatePaddingTopInnerContent = ({
29
29
  py,
30
30
  p
31
31
  }) => [py, p].some(padding => padding !== undefined) ? 0 : `${_dialog.CONTENT_TOP_PADDING}px`;
32
- const StyledDialog = exports.StyledDialog = _styledComponents.default.div`
32
+ const StyledDialog = exports.StyledDialog = _styledComponents.default.div.attrs(({
33
+ topMargin,
34
+ size
35
+ }) => {
36
+ const isDialogMaximised = size === "maximise";
37
+ const isDialogMaximisedSmallViewport = topMargin === 32;
38
+ const isDialogMaximisedLargeViewport = topMargin === 64;
39
+ return {
40
+ isDialogMaximised,
41
+ isDialogMaximisedSmallViewport,
42
+ isDialogMaximisedLargeViewport
43
+ };
44
+ })`
33
45
  box-shadow: var(--boxShadow300);
34
46
  display: flex;
35
47
  flex-direction: column;
@@ -42,6 +54,9 @@ const StyledDialog = exports.StyledDialog = _styledComponents.default.div`
42
54
  max-height: ${({
43
55
  topMargin
44
56
  }) => `calc(100vh - ${topMargin}px)`};
57
+ ${({
58
+ isDialogMaximised
59
+ }) => isDialogMaximised && "height: 100%"};
45
60
 
46
61
  &:focus {
47
62
  outline: none;
@@ -54,9 +69,10 @@ const StyledDialog = exports.StyledDialog = _styledComponents.default.div`
54
69
  `}
55
70
 
56
71
  ${({
57
- size
72
+ size,
73
+ topMargin
58
74
  }) => size && (0, _styledComponents.css)`
59
- max-width: ${dialogSizes[size]};
75
+ max-width: ${size === "maximise" ? `calc(100vw - ${topMargin}px)` : dialogSizes[size]};
60
76
  width: 100%;
61
77
  `}
62
78
 
@@ -66,7 +82,17 @@ const StyledDialog = exports.StyledDialog = _styledComponents.default.div`
66
82
  height: ${dialogHeight}px;
67
83
  `}
68
84
 
85
+ /* We're overriding the max-height on the form content to account for a larger height when in a smaller viewport.
86
+ TODO: Remove this upon the completion of FE-6643. */
69
87
  ${_form.StyledForm} {
88
+ ${({
89
+ isDialogMaximised,
90
+ isDialogMaximisedSmallViewport
91
+ }) => isDialogMaximised && (0, _styledComponents.css)`
92
+ ${isDialogMaximisedSmallViewport && "max-height: calc(100vh - 184px);"}
93
+ height: 100%;
94
+ `}
95
+
70
96
  padding-bottom: 0px;
71
97
  box-sizing: border-box;
72
98
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "142.7.0",
3
+ "version": "142.8.0",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "files": [
6
6
  "lib",