cozy-ui 125.0.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 (24) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/package.json +1 -1
  3. package/react/MuiCozyTheme/overrides/makeLightNormalOverrides.js +12 -10
  4. package/react/helpers/breakpoints.js +10 -2
  5. package/react/providers/Breakpoints/Readme.md +2 -0
  6. package/react/providers/Breakpoints/index.jsx +23 -9
  7. package/react/providers/Breakpoints/useIframeConnection.jsx +31 -0
  8. package/react/providers/Breakpoints/useIframeToSendWidth.jsx +33 -0
  9. package/react/providers/Breakpoints/useParentBreakpoints.jsx +36 -0
  10. package/transpiled/react/MuiCozyTheme/overrides/makeDarkInvertedOverrides.d.ts +12 -10
  11. package/transpiled/react/MuiCozyTheme/overrides/makeDarkNormalOverrides.d.ts +12 -10
  12. package/transpiled/react/MuiCozyTheme/overrides/makeLightInvertedOverrides.d.ts +12 -10
  13. package/transpiled/react/MuiCozyTheme/overrides/makeLightNormalOverrides.d.ts +12 -10
  14. package/transpiled/react/MuiCozyTheme/overrides/makeLightNormalOverrides.js +14 -8
  15. package/transpiled/react/helpers/breakpoints.d.ts +2 -1
  16. package/transpiled/react/helpers/breakpoints.js +9 -2
  17. package/transpiled/react/providers/Breakpoints/index.d.ts +12 -1
  18. package/transpiled/react/providers/Breakpoints/index.js +31 -10
  19. package/transpiled/react/providers/Breakpoints/useIframeConnection.d.ts +5 -0
  20. package/transpiled/react/providers/Breakpoints/useIframeConnection.js +35 -0
  21. package/transpiled/react/providers/Breakpoints/useIframeToSendWidth.d.ts +3 -0
  22. package/transpiled/react/providers/Breakpoints/useIframeToSendWidth.js +32 -0
  23. package/transpiled/react/providers/Breakpoints/useParentBreakpoints.d.ts +5 -0
  24. package/transpiled/react/providers/Breakpoints/useParentBreakpoints.js +34 -0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # [125.1.0](https://github.com/cozy/cozy-ui/compare/v125.0.0...v125.1.0) (2025-06-11)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **Dialog:** Width wasn't correct for small screens ([0951f70](https://github.com/cozy/cozy-ui/commit/0951f70))
7
+
8
+
9
+ ### Features
10
+
11
+ * **BreakpointsProvider:** Add `parentBasedIframe` prop ([4a49946](https://github.com/cozy/cozy-ui/commit/4a49946))
12
+
1
13
  # [125.0.0](https://github.com/cozy/cozy-ui/compare/v124.2.0...v125.0.0) (2025-06-05)
2
14
 
3
15
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "125.0.0",
3
+ "version": "125.1.0",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -586,8 +586,8 @@ export const makeLightNormalOverrides = theme => ({
586
586
  },
587
587
  MuiDialog: {
588
588
  paper: {
589
+ width: '100%',
589
590
  '&.small': {
590
- width: '480px',
591
591
  maxWidth: '480px',
592
592
  [theme.breakpoints.down('md')]: {
593
593
  margin: '16px',
@@ -602,19 +602,12 @@ export const makeLightNormalOverrides = theme => ({
602
602
  }
603
603
  },
604
604
  '&.medium': {
605
- [theme.breakpoints.up('md')]: {
606
- width: '544px',
607
- maxWidth: '544px'
608
- }
605
+ maxWidth: '544px'
609
606
  },
610
607
  '&.large': {
611
- [theme.breakpoints.up('md')]: {
612
- width: '800px',
613
- maxWidth: '800px'
614
- }
608
+ maxWidth: '800px'
615
609
  },
616
610
  '&.full': {
617
- width: '100%',
618
611
  maxWidth: '100%'
619
612
  }
620
613
  },
@@ -624,6 +617,15 @@ export const makeLightNormalOverrides = theme => ({
624
617
  }
625
618
  },
626
619
  paperFullScreen: {
620
+ '&.small': {
621
+ maxWidth: '100%'
622
+ },
623
+ '&.medium': {
624
+ maxWidth: '100%'
625
+ },
626
+ '&.large': {
627
+ maxWidth: '100%'
628
+ },
627
629
  '& .cozyDialogActions': {
628
630
  paddingBottom: `calc(env(safe-area-inset-bottom) + ${getFlagshipCssVar(
629
631
  'bottom'
@@ -16,12 +16,20 @@ const breakpoints = {
16
16
  isMobile: [0, small]
17
17
  }
18
18
 
19
- export const getBreakpointsStatus = breakpoints => {
20
- const width = window.innerWidth
19
+ export const getBreakpointsStatus = (breakpoints, innerWidth) => {
20
+ const width = innerWidth || window.innerWidth
21
21
  return mapValues(
22
22
  breakpoints,
23
23
  ([min, max]) => width >= min && (max === undefined || width <= max)
24
24
  )
25
25
  }
26
26
 
27
+ export const isInsideIframe = () => {
28
+ try {
29
+ return window.self !== window.top
30
+ } catch (e) {
31
+ return true
32
+ }
33
+ }
34
+
27
35
  export default breakpoints
@@ -15,6 +15,8 @@ completely change the content, the layout, or prune away complete
15
15
  subtrees (useful on mobile where space is at a premium). Here for
16
16
  example, the square contents changes on desktop or mobile.
17
17
 
18
+ By default, using `useBreakpoints` inside an iframe will refere to the iframe inner width. If you use `parentBasedIframe=true` on the provider wrapping the iframe, the breakpoints returned inside the iframe will refere to the parent window inner width instead.
19
+
18
20
  ```jsx
19
21
  import useBreakpoints, { BreakpointsProvider } from 'cozy-ui/transpiled/react/providers/Breakpoints'
20
22
 
@@ -1,20 +1,25 @@
1
1
  import throttle from 'lodash/throttle'
2
+ import PropTypes from 'prop-types'
2
3
  import React, { createContext, useContext, useState, useEffect } from 'react'
3
4
 
4
- import breakpointDefs, {
5
- getBreakpointsStatus as _getBreakpointsStatus
6
- } from '../../helpers/breakpoints'
7
-
8
- const getBreakpointsStatus = () => _getBreakpointsStatus(breakpointDefs)
5
+ import { useIframeConnection } from './useIframeConnection'
6
+ import { useIframeToSendWidth } from './useIframeToSendWidth'
7
+ import { useParentBreakpoints } from './useParentBreakpoints'
8
+ import breakpointDefs, { getBreakpointsStatus } from '../../helpers/breakpoints'
9
9
 
10
10
  const BreakpointsCtx = createContext(null)
11
11
 
12
- export const BreakpointsProvider = ({ children }) => {
13
- const [breakpoints, setBreakpoints] = useState(getBreakpointsStatus())
12
+ export const BreakpointsProvider = ({ parentBasedIframe, children }) => {
13
+ const [breakpoints, setBreakpoints] = useState(
14
+ getBreakpointsStatus(breakpointDefs)
15
+ )
16
+ const { hasIframe } = useIframeConnection({ parentBasedIframe })
17
+ useIframeToSendWidth({ hasIframe })
18
+ const { parentBreakpoints } = useParentBreakpoints({ parentBasedIframe })
14
19
 
15
20
  useEffect(() => {
16
21
  const handleResize = throttle(() => {
17
- setBreakpoints(getBreakpointsStatus())
22
+ setBreakpoints(getBreakpointsStatus(breakpointDefs))
18
23
  }, 100)
19
24
 
20
25
  window.addEventListener('resize', handleResize)
@@ -25,12 +30,21 @@ export const BreakpointsProvider = ({ children }) => {
25
30
  }, [])
26
31
 
27
32
  return (
28
- <BreakpointsCtx.Provider value={breakpoints}>
33
+ <BreakpointsCtx.Provider value={parentBreakpoints || breakpoints}>
29
34
  {children}
30
35
  </BreakpointsCtx.Provider>
31
36
  )
32
37
  }
33
38
 
39
+ BreakpointsProvider.defaultProps = {
40
+ parentBasedIframe: false
41
+ }
42
+
43
+ BreakpointsProvider.propTypes = {
44
+ /** Iframes breakpoints are based on parent window inner width instead of iframe inner width */
45
+ parentBasedIframe: PropTypes.bool
46
+ }
47
+
34
48
  export const useBreakpoints = () => {
35
49
  const v = useContext(BreakpointsCtx)
36
50
  if (v === null) {
@@ -0,0 +1,31 @@
1
+ import { useEffect, useState } from 'react'
2
+
3
+ import { isInsideIframe } from '../../helpers/breakpoints'
4
+
5
+ export const useIframeConnection = ({ parentBasedIframe }) => {
6
+ const [hasIframe, setHasIframe] = useState(false)
7
+
8
+ const isIframe = parentBasedIframe && isInsideIframe()
9
+
10
+ // parent window receives from iframe to give breakpoints
11
+ useEffect(() => {
12
+ const handleMessage = ev => {
13
+ if (ev.data === 'UI-breakpoints-needParentBreakpoints') {
14
+ setHasIframe(true)
15
+ }
16
+ }
17
+
18
+ window.addEventListener('message', handleMessage)
19
+
20
+ return () => window.removeEventListener('message', handleMessage)
21
+ }, [])
22
+
23
+ // iframe send to parent window ask for its breakpoints
24
+ useEffect(() => {
25
+ if (isIframe) {
26
+ window.parent.postMessage('UI-breakpoints-needParentBreakpoints', '*')
27
+ }
28
+ }, [isIframe])
29
+
30
+ return { hasIframe }
31
+ }
@@ -0,0 +1,33 @@
1
+ import throttle from 'lodash/throttle'
2
+ import { useEffect } from 'react'
3
+
4
+ /**
5
+ * To send window innerWidth to first iframe
6
+ * @returns
7
+ */
8
+ const sendWidthToIframe = () =>
9
+ window.frames[1].postMessage(`UI-breakpoints-value:${window.innerWidth}`, '*')
10
+
11
+ export const useIframeToSendWidth = ({ hasIframe }) => {
12
+ // parent window send its innerWidth
13
+ useEffect(() => {
14
+ if (hasIframe) {
15
+ sendWidthToIframe()
16
+ }
17
+ }, [hasIframe])
18
+
19
+ // parent window send its innerWidth on resize
20
+ useEffect(() => {
21
+ const handleResize = throttle(() => {
22
+ if (hasIframe) {
23
+ sendWidthToIframe()
24
+ }
25
+ }, 100)
26
+
27
+ window.addEventListener('resize', handleResize)
28
+
29
+ return () => {
30
+ window.removeEventListener('resize', handleResize)
31
+ }
32
+ }, [hasIframe])
33
+ }
@@ -0,0 +1,36 @@
1
+ import { useState, useEffect } from 'react'
2
+
3
+ import breakpointDefs, {
4
+ getBreakpointsStatus,
5
+ isInsideIframe
6
+ } from '../../helpers/breakpoints'
7
+
8
+ export const useParentBreakpoints = ({ parentBasedIframe }) => {
9
+ const [parentBreakpoints, setParentBreakpoints] = useState()
10
+
11
+ const isIframe = parentBasedIframe && isInsideIframe()
12
+
13
+ // iframe receives breakpoints from parent window
14
+ useEffect(() => {
15
+ const handleMessage = ev => {
16
+ if (!isIframe) return
17
+
18
+ if (
19
+ typeof ev.data === 'string' &&
20
+ ev.data.includes?.('UI-breakpoints-value:')
21
+ ) {
22
+ const parentInnerWidth = ev.data.split(':')[1]
23
+
24
+ setParentBreakpoints(
25
+ getBreakpointsStatus(breakpointDefs, parentInnerWidth)
26
+ )
27
+ }
28
+ }
29
+
30
+ window.addEventListener('message', handleMessage)
31
+
32
+ return () => window.removeEventListener('message', handleMessage)
33
+ }, [isIframe])
34
+
35
+ return { parentBreakpoints }
36
+ }
@@ -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
  },
@@ -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;
@@ -0,0 +1,32 @@
1
+ import throttle from 'lodash/throttle';
2
+ import { useEffect } from 'react';
3
+ /**
4
+ * To send window innerWidth to first iframe
5
+ * @returns
6
+ */
7
+
8
+ var sendWidthToIframe = function sendWidthToIframe() {
9
+ return window.frames[1].postMessage("UI-breakpoints-value:".concat(window.innerWidth), '*');
10
+ };
11
+
12
+ export var useIframeToSendWidth = function useIframeToSendWidth(_ref) {
13
+ var hasIframe = _ref.hasIframe;
14
+ // parent window send its innerWidth
15
+ useEffect(function () {
16
+ if (hasIframe) {
17
+ sendWidthToIframe();
18
+ }
19
+ }, [hasIframe]); // parent window send its innerWidth on resize
20
+
21
+ useEffect(function () {
22
+ var handleResize = throttle(function () {
23
+ if (hasIframe) {
24
+ sendWidthToIframe();
25
+ }
26
+ }, 100);
27
+ window.addEventListener('resize', handleResize);
28
+ return function () {
29
+ window.removeEventListener('resize', handleResize);
30
+ };
31
+ }, [hasIframe]);
32
+ };
@@ -0,0 +1,5 @@
1
+ export function useParentBreakpoints({ parentBasedIframe }: {
2
+ parentBasedIframe: any;
3
+ }): {
4
+ parentBreakpoints: undefined;
5
+ };
@@ -0,0 +1,34 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import { useState, useEffect } from 'react';
3
+ import breakpointDefs, { getBreakpointsStatus, isInsideIframe } from "cozy-ui/transpiled/react/helpers/breakpoints";
4
+ export var useParentBreakpoints = function useParentBreakpoints(_ref) {
5
+ var parentBasedIframe = _ref.parentBasedIframe;
6
+
7
+ var _useState = useState(),
8
+ _useState2 = _slicedToArray(_useState, 2),
9
+ parentBreakpoints = _useState2[0],
10
+ setParentBreakpoints = _useState2[1];
11
+
12
+ var isIframe = parentBasedIframe && isInsideIframe(); // iframe receives breakpoints from parent window
13
+
14
+ useEffect(function () {
15
+ var handleMessage = function handleMessage(ev) {
16
+ var _ev$data$includes, _ev$data;
17
+
18
+ if (!isIframe) return;
19
+
20
+ if (typeof ev.data === 'string' && (_ev$data$includes = (_ev$data = ev.data).includes) !== null && _ev$data$includes !== void 0 && _ev$data$includes.call(_ev$data, 'UI-breakpoints-value:')) {
21
+ var parentInnerWidth = ev.data.split(':')[1];
22
+ setParentBreakpoints(getBreakpointsStatus(breakpointDefs, parentInnerWidth));
23
+ }
24
+ };
25
+
26
+ window.addEventListener('message', handleMessage);
27
+ return function () {
28
+ return window.removeEventListener('message', handleMessage);
29
+ };
30
+ }, [isIframe]);
31
+ return {
32
+ parentBreakpoints: parentBreakpoints
33
+ };
34
+ };