cozy-ui 124.2.0 → 125.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 (39) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/cozy-ui.min.css +1 -1
  3. package/package.json +1 -1
  4. package/react/AppTitle/index.jsx +2 -2
  5. package/react/CozyDialogs/useCozyDialog.js +7 -0
  6. package/react/Layout/Layout.jsx +89 -26
  7. package/react/Layout/styles.styl +5 -8
  8. package/react/MuiCozyTheme/overrides/makeLightNormalOverrides.js +12 -10
  9. package/react/Sidebar/Readme.md +3 -1
  10. package/react/Sidebar/index.jsx +1 -5
  11. package/react/helpers/breakpoints.js +10 -2
  12. package/react/providers/Breakpoints/Readme.md +2 -0
  13. package/react/providers/Breakpoints/index.jsx +23 -9
  14. package/react/providers/Breakpoints/useIframeConnection.jsx +31 -0
  15. package/react/providers/Breakpoints/useIframeToSendWidth.jsx +33 -0
  16. package/react/providers/Breakpoints/useParentBreakpoints.jsx +36 -0
  17. package/stylus/objects/layouts.styl +74 -87
  18. package/stylus/objects/sidebar.styl +9 -4
  19. package/transpiled/react/AppTitle/index.js +2 -2
  20. package/transpiled/react/CozyDialogs/useCozyDialog.js +6 -1
  21. package/transpiled/react/Layout/Layout.d.ts +5 -31
  22. package/transpiled/react/Layout/Layout.js +78 -50
  23. package/transpiled/react/MuiCozyTheme/overrides/makeDarkInvertedOverrides.d.ts +12 -10
  24. package/transpiled/react/MuiCozyTheme/overrides/makeDarkNormalOverrides.d.ts +12 -10
  25. package/transpiled/react/MuiCozyTheme/overrides/makeLightInvertedOverrides.d.ts +12 -10
  26. package/transpiled/react/MuiCozyTheme/overrides/makeLightNormalOverrides.d.ts +12 -10
  27. package/transpiled/react/MuiCozyTheme/overrides/makeLightNormalOverrides.js +14 -8
  28. package/transpiled/react/Sidebar/index.js +2 -3
  29. package/transpiled/react/helpers/breakpoints.d.ts +2 -1
  30. package/transpiled/react/helpers/breakpoints.js +9 -2
  31. package/transpiled/react/providers/Breakpoints/index.d.ts +12 -1
  32. package/transpiled/react/providers/Breakpoints/index.js +31 -10
  33. package/transpiled/react/providers/Breakpoints/useIframeConnection.d.ts +5 -0
  34. package/transpiled/react/providers/Breakpoints/useIframeConnection.js +35 -0
  35. package/transpiled/react/providers/Breakpoints/useIframeToSendWidth.d.ts +3 -0
  36. package/transpiled/react/providers/Breakpoints/useIframeToSendWidth.js +32 -0
  37. package/transpiled/react/providers/Breakpoints/useParentBreakpoints.d.ts +5 -0
  38. package/transpiled/react/providers/Breakpoints/useParentBreakpoints.js +34 -0
  39. package/transpiled/react/stylesheet.css +1 -1
@@ -24,10 +24,10 @@ import NotesIcon from "cozy-ui/transpiled/react/Icons/Notes";
24
24
  import NotesTextIcon from "cozy-ui/transpiled/react/Icons/NotesText";
25
25
  import PassIcon from "cozy-ui/transpiled/react/Icons/Pass";
26
26
  import PassTextIcon from "cozy-ui/transpiled/react/Icons/PassText";
27
- import StoreIcon from "cozy-ui/transpiled/react/Icons/Store";
28
- import StoreTextIcon from "cozy-ui/transpiled/react/Icons/StoreText";
29
27
  import PhotosIcon from "cozy-ui/transpiled/react/Icons/Photos";
30
28
  import PhotosTextIcon from "cozy-ui/transpiled/react/Icons/PhotosText";
29
+ import StoreIcon from "cozy-ui/transpiled/react/Icons/Store";
30
+ import StoreTextIcon from "cozy-ui/transpiled/react/Icons/StoreText";
31
31
  import TwakeTextIcon from "cozy-ui/transpiled/react/Icons/TwakeText";
32
32
  import TwakeWorkplaceIcon from "cozy-ui/transpiled/react/Icons/TwakeWorkplace";
33
33
  import WorkplaceTextIcon from "cozy-ui/transpiled/react/Icons/WorkplaceText";
@@ -24,7 +24,7 @@ var useStyles = makeStyles({
24
24
  });
25
25
 
26
26
  var useCozyDialog = function useCozyDialog(props) {
27
- var _componentsProps$dial, _componentsProps$dial2, _componentsProps$dial3;
27
+ var _otherProps$BackdropP, _componentsProps$dial, _componentsProps$dial2, _componentsProps$dial3;
28
28
 
29
29
  var size = props.size,
30
30
  actions = props.actions,
@@ -70,6 +70,11 @@ var useCozyDialog = function useCozyDialog(props) {
70
70
  paper: "".concat(paperClassName, " ").concat(styles.paper, " ").concat(otherProps.classes ? otherProps.classes.paper : ''),
71
71
  scrollPaper: scrollPaperClassName
72
72
  }),
73
+ BackdropProps: _objectSpread({
74
+ style: _objectSpread({
75
+ transitionDelay: 50
76
+ }, otherProps === null || otherProps === void 0 ? void 0 : (_otherProps$BackdropP = otherProps.BackdropProps) === null || _otherProps$BackdropP === void 0 ? void 0 : _otherProps$BackdropP.style)
77
+ }, otherProps.BackdropProps),
73
78
  TransitionProps: _objectSpread({
74
79
  fullScreen: fullScreen
75
80
  }, otherProps.TransitionProps)
@@ -1,32 +1,6 @@
1
- export function Layout({ children, className, monoColumn, withTopBar, ...rest }: {
2
- [x: string]: any;
3
- children: any;
4
- className: any;
5
- monoColumn: any;
6
- withTopBar: any;
7
- }): JSX.Element;
8
- export namespace Layout {
9
- namespace propTypes {
10
- const children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
11
- const className: PropTypes.Requireable<string>;
12
- const withTopBar: PropTypes.Requireable<boolean>;
13
- const monoColumn: PropTypes.Requireable<boolean>;
14
- }
15
- namespace defaultProps {
16
- const withTopBar_1: boolean;
17
- export { withTopBar_1 as withTopBar };
18
- const monoColumn_1: boolean;
19
- export { monoColumn_1 as monoColumn };
20
- }
21
- }
22
- export function Main({ children, ...rest }: {
23
- [x: string]: any;
24
- children: any;
25
- }): JSX.Element;
26
- export class Content extends React.Component<any, any, any> {
27
- constructor(props: Readonly<any>);
28
- constructor(props: any, context?: any);
29
- render(): JSX.Element;
30
- }
31
- import PropTypes from "prop-types";
1
+ export const LayoutContext: React.Context<any>;
2
+ export function useLayout(): any;
3
+ export const Layout: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
4
+ export const Main: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
5
+ export const Content: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
32
6
  import React from "react";
@@ -1,71 +1,99 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _inherits from "@babel/runtime/helpers/inherits";
4
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
1
  import _extends from "@babel/runtime/helpers/extends";
7
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
3
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
9
4
  var _excluded = ["children", "className", "monoColumn", "withTopBar"],
10
- _excluded2 = ["children"],
11
- _excluded3 = ["children"];
12
-
13
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
14
-
15
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
16
-
5
+ _excluded2 = ["className", "children"],
6
+ _excluded3 = ["className", "children"];
17
7
  import cx from 'classnames';
18
8
  import PropTypes from 'prop-types';
19
- import React, { Component } from 'react';
9
+ import React, { createContext, forwardRef, useContext, useMemo } from 'react';
20
10
  var styles = {
21
11
  "o-layout": "styles__o-layout___3TSz9",
12
+ "o-layout-topbar": "styles__o-layout-topbar___2SHWi",
22
13
  "o-layout-2panes": "styles__o-layout-2panes___1CDQw",
23
- "o-layout--withTopBar": "styles__o-layout--withTopBar___36qd5",
24
- "o-layout-2panes--withTopBar": "styles__o-layout-2panes--withTopBar___Ub1z2"
14
+ "o-layout-main": "styles__o-layout-main___3mPxz",
15
+ "o-layout-main-monocolumn": "styles__o-layout-main-monocolumn___2a7vz",
16
+ "o-layout-main-monocolumn--topbar": "styles__o-layout-main-monocolumn--topbar___9_4Xd",
17
+ "o-layout-main-2panes": "styles__o-layout-main-2panes___3ickD",
18
+ "o-layout-main-2panes--topbar": "styles__o-layout-main-2panes--topbar___cGi-H",
19
+ "o-layout-content": "styles__o-layout-content___3D5gN",
20
+ "o-layout-content-monocolumn": "styles__o-layout-content-monocolumn___1rpxp",
21
+ "o-layout-content-2panes": "styles__o-layout-content-2panes___2Hotr"
25
22
  };
26
- export var Layout = function Layout(_ref) {
27
- var children = _ref.children,
28
- className = _ref.className,
29
- monoColumn = _ref.monoColumn,
30
- withTopBar = _ref.withTopBar,
31
- rest = _objectWithoutProperties(_ref, _excluded);
23
+ export var LayoutContext = /*#__PURE__*/createContext();
24
+ export var useLayout = function useLayout() {
25
+ var context = useContext(LayoutContext);
32
26
 
33
- return /*#__PURE__*/React.createElement("div", _extends({
34
- className: cx(monoColumn ? styles['o-layout'] : styles['o-layout-2panes'], className, _defineProperty({}, styles["o-layout".concat(monoColumn ? '' : '-2panes', "--withTopBar")], withTopBar))
35
- }, rest), children);
36
- };
37
- export var Main = function Main(_ref2) {
38
- var children = _ref2.children,
39
- rest = _objectWithoutProperties(_ref2, _excluded2);
27
+ if (!context) {
28
+ throw new Error('useLayout must be used within a LayoutContext');
29
+ }
40
30
 
41
- return /*#__PURE__*/React.createElement("main", rest, children);
31
+ return context;
42
32
  };
43
- export var Content = /*#__PURE__*/function (_Component) {
44
- _inherits(Content, _Component);
45
-
46
- var _super = _createSuper(Content);
33
+ var LayoutProvider = /*#__PURE__*/React.memo(function (_ref) {
34
+ var monoColumn = _ref.monoColumn,
35
+ withTopBar = _ref.withTopBar,
36
+ children = _ref.children;
37
+ var value = useMemo(function () {
38
+ return {
39
+ monoColumn: monoColumn,
40
+ withTopBar: withTopBar
41
+ };
42
+ }, [monoColumn, withTopBar]);
43
+ return /*#__PURE__*/React.createElement(LayoutContext.Provider, {
44
+ value: value
45
+ }, children);
46
+ });
47
+ LayoutProvider.displayName = 'LayoutProvider';
48
+ export var Layout = /*#__PURE__*/forwardRef(function (_ref2, ref) {
49
+ var children = _ref2.children,
50
+ className = _ref2.className,
51
+ monoColumn = _ref2.monoColumn,
52
+ withTopBar = _ref2.withTopBar,
53
+ props = _objectWithoutProperties(_ref2, _excluded);
47
54
 
48
- function Content() {
49
- _classCallCheck(this, Content);
55
+ var variant = monoColumn ? 'monocolumn' : '2panes';
56
+ return /*#__PURE__*/React.createElement(LayoutProvider, {
57
+ monoColumn: monoColumn,
58
+ withTopBar: withTopBar
59
+ }, /*#__PURE__*/React.createElement("div", _extends({
60
+ ref: ref,
61
+ className: cx(className, styles['o-layout'], styles["o-layout-".concat(variant)], _defineProperty({}, styles["o-layout-topbar"], withTopBar))
62
+ }, props), children));
63
+ });
64
+ Layout.displayName = 'Layout';
65
+ export var Main = /*#__PURE__*/forwardRef(function (_ref3, ref) {
66
+ var className = _ref3.className,
67
+ children = _ref3.children,
68
+ props = _objectWithoutProperties(_ref3, _excluded2);
50
69
 
51
- return _super.apply(this, arguments);
52
- }
70
+ var _useLayout = useLayout(),
71
+ monoColumn = _useLayout.monoColumn,
72
+ withTopBar = _useLayout.withTopBar;
53
73
 
54
- _createClass(Content, [{
55
- key: "render",
56
- value: function render() {
57
- var _this$props = this.props,
58
- children = _this$props.children,
59
- rest = _objectWithoutProperties(_this$props, _excluded3);
74
+ var variant = monoColumn ? 'monocolumn' : '2panes';
75
+ return /*#__PURE__*/React.createElement("main", _extends({
76
+ ref: ref,
77
+ className: cx(className, styles['o-layout-main'], styles["o-layout-main-".concat(variant)], _defineProperty({}, styles["o-layout-main-".concat(variant, "--topbar")], withTopBar))
78
+ }, props), children);
79
+ });
80
+ Main.displayName = 'Main';
81
+ export var Content = /*#__PURE__*/forwardRef(function (_ref4, ref) {
82
+ var className = _ref4.className,
83
+ children = _ref4.children,
84
+ props = _objectWithoutProperties(_ref4, _excluded3);
60
85
 
61
- return /*#__PURE__*/React.createElement("div", _extends({
62
- role: "main"
63
- }, rest), children);
64
- }
65
- }]);
86
+ var _useLayout2 = useLayout(),
87
+ monoColumn = _useLayout2.monoColumn;
66
88
 
67
- return Content;
68
- }(Component);
89
+ var variant = monoColumn ? 'monocolumn' : '2panes';
90
+ return /*#__PURE__*/React.createElement("div", _extends({
91
+ role: "main",
92
+ ref: ref,
93
+ className: cx(className, styles['o-layout-content'], styles["o-layout-content-".concat(variant)])
94
+ }, props), children);
95
+ });
96
+ Content.displayName = 'Content';
69
97
  Layout.propTypes = {
70
98
  children: PropTypes.node,
71
99
  className: PropTypes.string,
@@ -656,6 +656,7 @@ export function makeDarkInvertedOverrides(theme: any): {
656
656
  };
657
657
  MuiDialog: {
658
658
  paper: {
659
+ width: string;
659
660
  '&.small': {
660
661
  [x: number]: {
661
662
  margin: string;
@@ -668,23 +669,15 @@ export function makeDarkInvertedOverrides(theme: any): {
668
669
  marginRight: string;
669
670
  };
670
671
  };
671
- width: string;
672
672
  maxWidth: string;
673
673
  };
674
674
  '&.medium': {
675
- [x: number]: {
676
- width: string;
677
- maxWidth: string;
678
- };
675
+ maxWidth: string;
679
676
  };
680
677
  '&.large': {
681
- [x: number]: {
682
- width: string;
683
- maxWidth: string;
684
- };
678
+ maxWidth: string;
685
679
  };
686
680
  '&.full': {
687
- width: string;
688
681
  maxWidth: string;
689
682
  };
690
683
  };
@@ -694,6 +687,15 @@ export function makeDarkInvertedOverrides(theme: any): {
694
687
  };
695
688
  };
696
689
  paperFullScreen: {
690
+ '&.small': {
691
+ maxWidth: string;
692
+ };
693
+ '&.medium': {
694
+ maxWidth: string;
695
+ };
696
+ '&.large': {
697
+ maxWidth: string;
698
+ };
697
699
  '& .cozyDialogActions': {
698
700
  paddingBottom: string;
699
701
  };
@@ -656,6 +656,7 @@ export function makeDarkNormalOverrides(theme: any): {
656
656
  };
657
657
  MuiDialog: {
658
658
  paper: {
659
+ width: string;
659
660
  '&.small': {
660
661
  [x: number]: {
661
662
  margin: string;
@@ -668,23 +669,15 @@ export function makeDarkNormalOverrides(theme: any): {
668
669
  marginRight: string;
669
670
  };
670
671
  };
671
- width: string;
672
672
  maxWidth: string;
673
673
  };
674
674
  '&.medium': {
675
- [x: number]: {
676
- width: string;
677
- maxWidth: string;
678
- };
675
+ maxWidth: string;
679
676
  };
680
677
  '&.large': {
681
- [x: number]: {
682
- width: string;
683
- maxWidth: string;
684
- };
678
+ maxWidth: string;
685
679
  };
686
680
  '&.full': {
687
- width: string;
688
681
  maxWidth: string;
689
682
  };
690
683
  };
@@ -694,6 +687,15 @@ export function makeDarkNormalOverrides(theme: any): {
694
687
  };
695
688
  };
696
689
  paperFullScreen: {
690
+ '&.small': {
691
+ maxWidth: string;
692
+ };
693
+ '&.medium': {
694
+ maxWidth: string;
695
+ };
696
+ '&.large': {
697
+ maxWidth: string;
698
+ };
697
699
  '& .cozyDialogActions': {
698
700
  paddingBottom: string;
699
701
  };
@@ -656,6 +656,7 @@ export function makeLightInvertedOverrides(theme: any): {
656
656
  };
657
657
  MuiDialog: {
658
658
  paper: {
659
+ width: string;
659
660
  '&.small': {
660
661
  [x: number]: {
661
662
  margin: string;
@@ -668,23 +669,15 @@ export function makeLightInvertedOverrides(theme: any): {
668
669
  marginRight: string;
669
670
  };
670
671
  };
671
- width: string;
672
672
  maxWidth: string;
673
673
  };
674
674
  '&.medium': {
675
- [x: number]: {
676
- width: string;
677
- maxWidth: string;
678
- };
675
+ maxWidth: string;
679
676
  };
680
677
  '&.large': {
681
- [x: number]: {
682
- width: string;
683
- maxWidth: string;
684
- };
678
+ maxWidth: string;
685
679
  };
686
680
  '&.full': {
687
- width: string;
688
681
  maxWidth: string;
689
682
  };
690
683
  };
@@ -694,6 +687,15 @@ export function makeLightInvertedOverrides(theme: any): {
694
687
  };
695
688
  };
696
689
  paperFullScreen: {
690
+ '&.small': {
691
+ maxWidth: string;
692
+ };
693
+ '&.medium': {
694
+ maxWidth: string;
695
+ };
696
+ '&.large': {
697
+ maxWidth: string;
698
+ };
697
699
  '& .cozyDialogActions': {
698
700
  paddingBottom: string;
699
701
  };
@@ -656,6 +656,7 @@ export function makeLightNormalOverrides(theme: any): {
656
656
  };
657
657
  MuiDialog: {
658
658
  paper: {
659
+ width: string;
659
660
  '&.small': {
660
661
  [x: number]: {
661
662
  margin: string;
@@ -668,23 +669,15 @@ export function makeLightNormalOverrides(theme: any): {
668
669
  marginRight: string;
669
670
  };
670
671
  };
671
- width: string;
672
672
  maxWidth: string;
673
673
  };
674
674
  '&.medium': {
675
- [x: number]: {
676
- width: string;
677
- maxWidth: string;
678
- };
675
+ maxWidth: string;
679
676
  };
680
677
  '&.large': {
681
- [x: number]: {
682
- width: string;
683
- maxWidth: string;
684
- };
678
+ maxWidth: string;
685
679
  };
686
680
  '&.full': {
687
- width: string;
688
681
  maxWidth: string;
689
682
  };
690
683
  };
@@ -694,6 +687,15 @@ export function makeLightNormalOverrides(theme: any): {
694
687
  };
695
688
  };
696
689
  paperFullScreen: {
690
+ '&.small': {
691
+ maxWidth: string;
692
+ };
693
+ '&.medium': {
694
+ maxWidth: string;
695
+ };
696
+ '&.large': {
697
+ maxWidth: string;
698
+ };
697
699
  '& .cozyDialogActions': {
698
700
  paddingBottom: string;
699
701
  };
@@ -561,8 +561,8 @@ export var makeLightNormalOverrides = function makeLightNormalOverrides(theme) {
561
561
  },
562
562
  MuiDialog: {
563
563
  paper: {
564
+ width: '100%',
564
565
  '&.small': _defineProperty({
565
- width: '480px',
566
566
  maxWidth: '480px'
567
567
  }, theme.breakpoints.down('md'), {
568
568
  margin: '16px',
@@ -575,16 +575,13 @@ export var makeLightNormalOverrides = function makeLightNormalOverrides(theme) {
575
575
  marginRight: '-8px'
576
576
  }
577
577
  }),
578
- '&.medium': _defineProperty({}, theme.breakpoints.up('md'), {
579
- width: '544px',
578
+ '&.medium': {
580
579
  maxWidth: '544px'
581
- }),
582
- '&.large': _defineProperty({}, theme.breakpoints.up('md'), {
583
- width: '800px',
580
+ },
581
+ '&.large': {
584
582
  maxWidth: '800px'
585
- }),
583
+ },
586
584
  '&.full': {
587
- width: '100%',
588
585
  maxWidth: '100%'
589
586
  }
590
587
  },
@@ -594,6 +591,15 @@ export var makeLightNormalOverrides = function makeLightNormalOverrides(theme) {
594
591
  }
595
592
  },
596
593
  paperFullScreen: {
594
+ '&.small': {
595
+ maxWidth: '100%'
596
+ },
597
+ '&.medium': {
598
+ maxWidth: '100%'
599
+ },
600
+ '&.large': {
601
+ maxWidth: '100%'
602
+ },
597
603
  '& .cozyDialogActions': {
598
604
  paddingBottom: "calc(env(safe-area-inset-bottom) + ".concat(getFlagshipCssVar('bottom'), ")")
599
605
  },
@@ -7,8 +7,7 @@ import PropTypes from 'prop-types';
7
7
  import React from 'react';
8
8
  var styles = {
9
9
  "o-sidebar": "styles__o-sidebar___1295j",
10
- "o-sidebar--border": "styles__o-sidebar--border___32tfw",
11
- "o-sidebar--large": "styles__o-sidebar--large___1mT8H"
10
+ "o-sidebar--border": "styles__o-sidebar--border___32tfw"
12
11
  };
13
12
  import { useSetFlagshipUI } from "cozy-ui/transpiled/react/hooks/useSetFlagshipUi/useSetFlagshipUI";
14
13
  import { useCozyTheme } from "cozy-ui/transpiled/react/providers/CozyTheme";
@@ -31,7 +30,7 @@ var Sidebar = function Sidebar(_ref) {
31
30
  }, 'cozy-ui/Sidebar');
32
31
  return /*#__PURE__*/React.createElement("aside", _extends({
33
32
  id: "sidebar",
34
- className: cx(styles['o-sidebar'], [styles['o-sidebar--large']], className)
33
+ className: cx(styles['o-sidebar'], className)
35
34
  }, restProps), children);
36
35
  };
37
36
 
@@ -1,6 +1,7 @@
1
- export function getBreakpointsStatus(breakpoints: any): {
1
+ export function getBreakpointsStatus(breakpoints: any, innerWidth: any): {
2
2
  [x: string]: boolean;
3
3
  };
4
+ export function isInsideIframe(): boolean;
4
5
  export default breakpoints;
5
6
  declare namespace breakpoints {
6
7
  const isExtraLarge: number[];
@@ -14,8 +14,8 @@ var breakpoints = {
14
14
  isTablet: [small + 1, medium],
15
15
  isMobile: [0, small]
16
16
  };
17
- export var getBreakpointsStatus = function getBreakpointsStatus(breakpoints) {
18
- var width = window.innerWidth;
17
+ export var getBreakpointsStatus = function getBreakpointsStatus(breakpoints, innerWidth) {
18
+ var width = innerWidth || window.innerWidth;
19
19
  return mapValues(breakpoints, function (_ref) {
20
20
  var _ref2 = _slicedToArray(_ref, 2),
21
21
  min = _ref2[0],
@@ -24,4 +24,11 @@ export var getBreakpointsStatus = function getBreakpointsStatus(breakpoints) {
24
24
  return width >= min && (max === undefined || width <= max);
25
25
  });
26
26
  };
27
+ export var isInsideIframe = function isInsideIframe() {
28
+ try {
29
+ return window.self !== window.top;
30
+ } catch (e) {
31
+ return true;
32
+ }
33
+ };
27
34
  export default breakpoints;
@@ -1,5 +1,16 @@
1
- export function BreakpointsProvider({ children }: {
1
+ export function BreakpointsProvider({ parentBasedIframe, children }: {
2
+ parentBasedIframe: any;
2
3
  children: any;
3
4
  }): JSX.Element;
5
+ export namespace BreakpointsProvider {
6
+ namespace defaultProps {
7
+ const parentBasedIframe: boolean;
8
+ }
9
+ namespace propTypes {
10
+ const parentBasedIframe_1: PropTypes.Requireable<boolean>;
11
+ export { parentBasedIframe_1 as parentBasedIframe };
12
+ }
13
+ }
4
14
  export function useBreakpoints(): never;
5
15
  export default useBreakpoints;
16
+ import PropTypes from "prop-types";
@@ -1,24 +1,38 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import throttle from 'lodash/throttle';
3
+ import PropTypes from 'prop-types';
3
4
  import React, { createContext, useContext, useState, useEffect } from 'react';
4
- import breakpointDefs, { getBreakpointsStatus as _getBreakpointsStatus } from "cozy-ui/transpiled/react/helpers/breakpoints";
5
-
6
- var getBreakpointsStatus = function getBreakpointsStatus() {
7
- return _getBreakpointsStatus(breakpointDefs);
8
- };
9
-
5
+ import { useIframeConnection } from "cozy-ui/transpiled/react/providers/Breakpoints/useIframeConnection";
6
+ import { useIframeToSendWidth } from "cozy-ui/transpiled/react/providers/Breakpoints/useIframeToSendWidth";
7
+ import { useParentBreakpoints } from "cozy-ui/transpiled/react/providers/Breakpoints/useParentBreakpoints";
8
+ import breakpointDefs, { getBreakpointsStatus } from "cozy-ui/transpiled/react/helpers/breakpoints";
10
9
  var BreakpointsCtx = /*#__PURE__*/createContext(null);
11
10
  export var BreakpointsProvider = function BreakpointsProvider(_ref) {
12
- var children = _ref.children;
11
+ var parentBasedIframe = _ref.parentBasedIframe,
12
+ children = _ref.children;
13
13
 
14
- var _useState = useState(getBreakpointsStatus()),
14
+ var _useState = useState(getBreakpointsStatus(breakpointDefs)),
15
15
  _useState2 = _slicedToArray(_useState, 2),
16
16
  breakpoints = _useState2[0],
17
17
  setBreakpoints = _useState2[1];
18
18
 
19
+ var _useIframeConnection = useIframeConnection({
20
+ parentBasedIframe: parentBasedIframe
21
+ }),
22
+ hasIframe = _useIframeConnection.hasIframe;
23
+
24
+ useIframeToSendWidth({
25
+ hasIframe: hasIframe
26
+ });
27
+
28
+ var _useParentBreakpoints = useParentBreakpoints({
29
+ parentBasedIframe: parentBasedIframe
30
+ }),
31
+ parentBreakpoints = _useParentBreakpoints.parentBreakpoints;
32
+
19
33
  useEffect(function () {
20
34
  var handleResize = throttle(function () {
21
- setBreakpoints(getBreakpointsStatus());
35
+ setBreakpoints(getBreakpointsStatus(breakpointDefs));
22
36
  }, 100);
23
37
  window.addEventListener('resize', handleResize);
24
38
  return function () {
@@ -26,9 +40,16 @@ export var BreakpointsProvider = function BreakpointsProvider(_ref) {
26
40
  };
27
41
  }, []);
28
42
  return /*#__PURE__*/React.createElement(BreakpointsCtx.Provider, {
29
- value: breakpoints
43
+ value: parentBreakpoints || breakpoints
30
44
  }, children);
31
45
  };
46
+ BreakpointsProvider.defaultProps = {
47
+ parentBasedIframe: false
48
+ };
49
+ BreakpointsProvider.propTypes = {
50
+ /** Iframes breakpoints are based on parent window inner width instead of iframe inner width */
51
+ parentBasedIframe: PropTypes.bool
52
+ };
32
53
  export var useBreakpoints = function useBreakpoints() {
33
54
  var v = useContext(BreakpointsCtx);
34
55
 
@@ -0,0 +1,5 @@
1
+ export function useIframeConnection({ parentBasedIframe }: {
2
+ parentBasedIframe: any;
3
+ }): {
4
+ hasIframe: boolean;
5
+ };
@@ -0,0 +1,35 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import { useEffect, useState } from 'react';
3
+ import { isInsideIframe } from "cozy-ui/transpiled/react/helpers/breakpoints";
4
+ export var useIframeConnection = function useIframeConnection(_ref) {
5
+ var parentBasedIframe = _ref.parentBasedIframe;
6
+
7
+ var _useState = useState(false),
8
+ _useState2 = _slicedToArray(_useState, 2),
9
+ hasIframe = _useState2[0],
10
+ setHasIframe = _useState2[1];
11
+
12
+ var isIframe = parentBasedIframe && isInsideIframe(); // parent window receives from iframe to give breakpoints
13
+
14
+ useEffect(function () {
15
+ var handleMessage = function handleMessage(ev) {
16
+ if (ev.data === 'UI-breakpoints-needParentBreakpoints') {
17
+ setHasIframe(true);
18
+ }
19
+ };
20
+
21
+ window.addEventListener('message', handleMessage);
22
+ return function () {
23
+ return window.removeEventListener('message', handleMessage);
24
+ };
25
+ }, []); // iframe send to parent window ask for its breakpoints
26
+
27
+ useEffect(function () {
28
+ if (isIframe) {
29
+ window.parent.postMessage('UI-breakpoints-needParentBreakpoints', '*');
30
+ }
31
+ }, [isIframe]);
32
+ return {
33
+ hasIframe: hasIframe
34
+ };
35
+ };
@@ -0,0 +1,3 @@
1
+ export function useIframeToSendWidth({ hasIframe }: {
2
+ hasIframe: any;
3
+ }): void;