@elliemae/ds-dialog 2.4.2-rc.0 → 2.4.2-rc.9

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.
@@ -3,19 +3,8 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var react = require('react');
6
- var defaultProps = require('./defaultProps.js');
7
6
 
8
- const defaultContext = {
9
- props: defaultProps.defaultProps,
10
- actualPortalRef: /*#__PURE__*/react.createRef(),
11
- containerRef: /*#__PURE__*/react.createRef(),
12
- portalClassName: '',
13
- portalInfo: {
14
- overflow: false,
15
- paddingRight: '0px',
16
- scrollbarWidth: '0px'
17
- }
18
- };
7
+ const defaultContext = {};
19
8
  const DSDialogContext = /*#__PURE__*/react.createContext(defaultContext);
20
9
 
21
10
  exports.DSDialogContext = DSDialogContext;
@@ -15,6 +15,7 @@ var uid = require('uid');
15
15
  var dsPropsHelpers = require('@elliemae/ds-props-helpers');
16
16
  var defaultProps = require('../defaultProps.js');
17
17
  var propTypes = require('../propTypes.js');
18
+ var utils = require('../utils.js');
18
19
 
19
20
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
20
21
 
@@ -34,8 +35,7 @@ const useDialog = props => {
34
35
  const containerRef = react.useRef(null);
35
36
  const [portalInfo, setPortalInfo] = react.useState({
36
37
  paddingRight: '0px',
37
- scrollbarWidth: '0px',
38
- overflow: false
38
+ scrollbarWidth: '0px'
39
39
  });
40
40
  const portalClassName = react.useMemo(() => "ds-dialog-".concat(uid.uid(8)), []);
41
41
  react.useEffect(() => {
@@ -52,38 +52,28 @@ const useDialog = props => {
52
52
  }, [actualPortalRef, isOpen, portalClassName]);
53
53
  react.useEffect(() => {
54
54
  if (actualPortalRef.current) {
55
- var _window$getComputedSt;
56
-
57
- const paddingRight = (_window$getComputedSt = window.getComputedStyle(actualPortalRef.current, null)) === null || _window$getComputedSt === void 0 ? void 0 : _window$getComputedSt.getPropertyValue('padding-right');
58
55
  setPortalInfo(prev => _objectSpread(_objectSpread({}, prev), {}, {
59
- paddingRight
56
+ paddingRight: utils.getCurrentRightPadding(actualPortalRef.current)
60
57
  }));
61
58
  }
62
59
  }, []);
63
- const calculateScrollbarAndOverflow = react.useCallback(() => {
64
- if (actualPortalRef.current) {
65
- const body = actualPortalRef.current;
66
- const {
67
- clientWidth,
68
- clientHeight,
69
- scrollHeight
70
- } = body;
60
+ const calculateScrollbar = react.useCallback(() => {
61
+ if (actualPortalRef.current && !isOpen) {
71
62
  setPortalInfo(prev => _objectSpread(_objectSpread({}, prev), {}, {
72
- scrollbarWidth: "".concat(window.innerWidth - clientWidth, "px"),
73
- overflow: scrollHeight > clientHeight
63
+ scrollbarWidth: utils.getScrollbarWidth(actualPortalRef.current)
74
64
  }));
75
65
  }
76
- }, [actualPortalRef]);
77
- const debouncedCalculateScrollbarAndOverflow = react.useMemo(() => lodash.debounce(calculateScrollbarAndOverflow, 300), [calculateScrollbarAndOverflow]);
66
+ }, [isOpen]);
67
+ const debouncedCalculateScrollbar = react.useMemo(() => lodash.debounce(calculateScrollbar, 300), [calculateScrollbar]);
78
68
  react.useEffect(() => {
79
- window.addEventListener('resize', debouncedCalculateScrollbarAndOverflow);
69
+ window.addEventListener('resize', debouncedCalculateScrollbar);
80
70
  return () => {
81
- window.removeEventListener('resize', debouncedCalculateScrollbarAndOverflow);
71
+ window.removeEventListener('resize', debouncedCalculateScrollbar);
82
72
  };
83
- }, [calculateScrollbarAndOverflow, debouncedCalculateScrollbarAndOverflow]);
73
+ }, [calculateScrollbar, debouncedCalculateScrollbar]);
84
74
  react.useEffect(() => {
85
- calculateScrollbarAndOverflow();
86
- }, [calculateScrollbarAndOverflow]);
75
+ calculateScrollbar();
76
+ }, [calculateScrollbar, isOpen]);
87
77
  const ctx = react.useMemo(() => ({
88
78
  props: propsWithDefault,
89
79
  actualPortalRef,
package/cjs/styles.js CHANGED
@@ -23,7 +23,7 @@ const PortalStyles = dsSystem.createGlobalStyle(_templateObject || (_templateObj
23
23
  let {
24
24
  portalInfo
25
25
  } = _ref2;
26
- return portalInfo.overflow ? "padding-right: calc( ".concat(portalInfo.paddingRight, " + ").concat(portalInfo.scrollbarWidth, " ) !important;") : "";
26
+ return portalInfo.scrollbarWidth !== '0px' ? "padding-right: calc( ".concat(portalInfo.paddingRight, " + ").concat(portalInfo.scrollbarWidth, " ) !important;") : "";
27
27
  });
28
28
  const StyledDialogBackground = /*#__PURE__*/styled__default["default"].div.withConfig({
29
29
  componentId: "sc-106vqwv-0"
package/cjs/utils.js CHANGED
@@ -28,8 +28,16 @@ const allSizes = {
28
28
  'x-large': '1042px',
29
29
  'xx-large': '1440px'
30
30
  };
31
+ const getScrollbarWidth = element => element.tagName === 'BODY' ? "".concat(window.innerWidth - element.clientWidth, "px") : "".concat(element.offsetWidth - element.clientWidth, "px");
32
+ const getCurrentRightPadding = element => {
33
+ var _window$getComputedSt;
34
+
35
+ return (_window$getComputedSt = window.getComputedStyle(element, null)) === null || _window$getComputedSt === void 0 ? void 0 : _window$getComputedSt.getPropertyValue('padding-right');
36
+ };
31
37
 
32
38
  exports.DSDialogSizes = DSDialogSizes;
33
39
  exports.DSDialogSizesArrayValues = DSDialogSizesArrayValues;
34
40
  exports.allSizes = allSizes;
41
+ exports.getCurrentRightPadding = getCurrentRightPadding;
42
+ exports.getScrollbarWidth = getScrollbarWidth;
35
43
  exports.getSpaceProps = getSpaceProps;
@@ -1,17 +1,6 @@
1
- import { createContext, createRef } from 'react';
2
- import { defaultProps } from './defaultProps.js';
1
+ import { createContext } from 'react';
3
2
 
4
- const defaultContext = {
5
- props: defaultProps,
6
- actualPortalRef: /*#__PURE__*/createRef(),
7
- containerRef: /*#__PURE__*/createRef(),
8
- portalClassName: '',
9
- portalInfo: {
10
- overflow: false,
11
- paddingRight: '0px',
12
- scrollbarWidth: '0px'
13
- }
14
- };
3
+ const defaultContext = {};
15
4
  const DSDialogContext = /*#__PURE__*/createContext(defaultContext);
16
5
 
17
6
  export { DSDialogContext };
@@ -11,6 +11,7 @@ import { uid } from 'uid';
11
11
  import { useValidateTypescriptPropTypes, useMemoMergePropsWithDefault } from '@elliemae/ds-props-helpers';
12
12
  import { defaultProps } from '../defaultProps.js';
13
13
  import { propTypes } from '../propTypes.js';
14
+ import { getCurrentRightPadding, getScrollbarWidth } from '../utils.js';
14
15
 
15
16
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
16
17
 
@@ -26,8 +27,7 @@ const useDialog = props => {
26
27
  const containerRef = useRef(null);
27
28
  const [portalInfo, setPortalInfo] = useState({
28
29
  paddingRight: '0px',
29
- scrollbarWidth: '0px',
30
- overflow: false
30
+ scrollbarWidth: '0px'
31
31
  });
32
32
  const portalClassName = useMemo(() => "ds-dialog-".concat(uid(8)), []);
33
33
  useEffect(() => {
@@ -44,38 +44,28 @@ const useDialog = props => {
44
44
  }, [actualPortalRef, isOpen, portalClassName]);
45
45
  useEffect(() => {
46
46
  if (actualPortalRef.current) {
47
- var _window$getComputedSt;
48
-
49
- const paddingRight = (_window$getComputedSt = window.getComputedStyle(actualPortalRef.current, null)) === null || _window$getComputedSt === void 0 ? void 0 : _window$getComputedSt.getPropertyValue('padding-right');
50
47
  setPortalInfo(prev => _objectSpread(_objectSpread({}, prev), {}, {
51
- paddingRight
48
+ paddingRight: getCurrentRightPadding(actualPortalRef.current)
52
49
  }));
53
50
  }
54
51
  }, []);
55
- const calculateScrollbarAndOverflow = useCallback(() => {
56
- if (actualPortalRef.current) {
57
- const body = actualPortalRef.current;
58
- const {
59
- clientWidth,
60
- clientHeight,
61
- scrollHeight
62
- } = body;
52
+ const calculateScrollbar = useCallback(() => {
53
+ if (actualPortalRef.current && !isOpen) {
63
54
  setPortalInfo(prev => _objectSpread(_objectSpread({}, prev), {}, {
64
- scrollbarWidth: "".concat(window.innerWidth - clientWidth, "px"),
65
- overflow: scrollHeight > clientHeight
55
+ scrollbarWidth: getScrollbarWidth(actualPortalRef.current)
66
56
  }));
67
57
  }
68
- }, [actualPortalRef]);
69
- const debouncedCalculateScrollbarAndOverflow = useMemo(() => debounce(calculateScrollbarAndOverflow, 300), [calculateScrollbarAndOverflow]);
58
+ }, [isOpen]);
59
+ const debouncedCalculateScrollbar = useMemo(() => debounce(calculateScrollbar, 300), [calculateScrollbar]);
70
60
  useEffect(() => {
71
- window.addEventListener('resize', debouncedCalculateScrollbarAndOverflow);
61
+ window.addEventListener('resize', debouncedCalculateScrollbar);
72
62
  return () => {
73
- window.removeEventListener('resize', debouncedCalculateScrollbarAndOverflow);
63
+ window.removeEventListener('resize', debouncedCalculateScrollbar);
74
64
  };
75
- }, [calculateScrollbarAndOverflow, debouncedCalculateScrollbarAndOverflow]);
65
+ }, [calculateScrollbar, debouncedCalculateScrollbar]);
76
66
  useEffect(() => {
77
- calculateScrollbarAndOverflow();
78
- }, [calculateScrollbarAndOverflow]);
67
+ calculateScrollbar();
68
+ }, [calculateScrollbar, isOpen]);
79
69
  const ctx = useMemo(() => ({
80
70
  props: propsWithDefault,
81
71
  actualPortalRef,
package/esm/styles.js CHANGED
@@ -14,7 +14,7 @@ const PortalStyles = createGlobalStyle(_templateObject || (_templateObject = _ta
14
14
  let {
15
15
  portalInfo
16
16
  } = _ref2;
17
- return portalInfo.overflow ? "padding-right: calc( ".concat(portalInfo.paddingRight, " + ").concat(portalInfo.scrollbarWidth, " ) !important;") : "";
17
+ return portalInfo.scrollbarWidth !== '0px' ? "padding-right: calc( ".concat(portalInfo.paddingRight, " + ").concat(portalInfo.scrollbarWidth, " ) !important;") : "";
18
18
  });
19
19
  const StyledDialogBackground = /*#__PURE__*/styled.div.withConfig({
20
20
  componentId: "sc-106vqwv-0"
package/esm/utils.js CHANGED
@@ -24,5 +24,11 @@ const allSizes = {
24
24
  'x-large': '1042px',
25
25
  'xx-large': '1440px'
26
26
  };
27
+ const getScrollbarWidth = element => element.tagName === 'BODY' ? "".concat(window.innerWidth - element.clientWidth, "px") : "".concat(element.offsetWidth - element.clientWidth, "px");
28
+ const getCurrentRightPadding = element => {
29
+ var _window$getComputedSt;
27
30
 
28
- export { DSDialogSizes, DSDialogSizesArrayValues, allSizes, getSpaceProps };
31
+ return (_window$getComputedSt = window.getComputedStyle(element, null)) === null || _window$getComputedSt === void 0 ? void 0 : _window$getComputedSt.getPropertyValue('padding-right');
32
+ };
33
+
34
+ export { DSDialogSizes, DSDialogSizesArrayValues, allSizes, getCurrentRightPadding, getScrollbarWidth, getSpaceProps };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elliemae/ds-dialog",
3
- "version": "2.4.2-rc.0",
3
+ "version": "2.4.2-rc.9",
4
4
  "license": "MIT",
5
5
  "description": "ICE MT - Dimsum - Dialog",
6
6
  "module": "./esm/index.js",
@@ -80,10 +80,10 @@
80
80
  "build": "node ../../scripts/build/build.js"
81
81
  },
82
82
  "dependencies": {
83
- "@elliemae/ds-button": "2.4.2-rc.0",
84
- "@elliemae/ds-icons": "2.4.2-rc.0",
85
- "@elliemae/ds-props-helpers": "2.4.2-rc.0",
86
- "@elliemae/ds-system": "2.4.2-rc.0",
83
+ "@elliemae/ds-button": "2.4.2-rc.9",
84
+ "@elliemae/ds-icons": "2.4.2-rc.9",
85
+ "@elliemae/ds-props-helpers": "2.4.2-rc.9",
86
+ "@elliemae/ds-system": "2.4.2-rc.9",
87
87
  "react-desc": "~4.1.3"
88
88
  },
89
89
  "devDependencies": {
@@ -2,7 +2,6 @@
2
2
  import type { DSDialogT } from './propTypes';
3
3
  export declare namespace DSDialogInternalsT {
4
4
  interface PortalInfo {
5
- overflow: boolean;
6
5
  scrollbarWidth: string;
7
6
  paddingRight: string;
8
7
  }
package/types/utils.d.ts CHANGED
@@ -18,3 +18,5 @@ export declare const allSizes: {
18
18
  'x-large': string;
19
19
  'xx-large': string;
20
20
  };
21
+ export declare const getScrollbarWidth: (element: HTMLElement) => string;
22
+ export declare const getCurrentRightPadding: (element: HTMLElement) => string;