cozy-ui 111.1.1 → 111.2.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [111.2.0](https://github.com/cozy/cozy-ui/compare/v111.1.1...v111.2.0) (2024-07-25)
2
+
3
+
4
+ ### Features
5
+
6
+ * **CozyTheme:** Add `ignoreCozySettings` prop to bypass settings query ([e49a312](https://github.com/cozy/cozy-ui/commit/e49a312))
7
+
1
8
  ## [111.1.1](https://github.com/cozy/cozy-ui/compare/v111.1.0...v111.1.1) (2024-07-18)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "111.1.1",
3
+ "version": "111.2.0",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -3,7 +3,7 @@ import React from 'react'
3
3
  import { useQuery, isQueryLoading, hasQueryBeenLoaded } from 'cozy-client'
4
4
 
5
5
  import { buildSettingsInstanceQuery } from './queries'
6
- import { DumbCozyTheme } from './index'
6
+ import DumbCozyTheme from './DumbCozyTheme'
7
7
 
8
8
  const CozyThemeWithQuery = props => {
9
9
  const instanceQuery = buildSettingsInstanceQuery()
@@ -0,0 +1,71 @@
1
+ import React from 'react'
2
+ import PropTypes from 'prop-types'
3
+ import cx from 'classnames'
4
+
5
+ import flag from 'cozy-flags'
6
+ import useMediaQuery from '../../hooks/useMediaQuery'
7
+ import MuiCozyTheme from '../../MuiCozyTheme'
8
+
9
+ import { CozyThemeContext } from './index'
10
+
11
+ const DumbCozyTheme = ({
12
+ variant,
13
+ className,
14
+ ignoreItself,
15
+ settingsThemeType,
16
+ children
17
+ }) => {
18
+ const uiThemeType = localStorage.getItem('ui-theme-type') // use only for cozy-ui documentation and argos screenshots
19
+ const uiThemeVariant = localStorage.getItem('ui-theme-variant') // use only for cozy-ui documentation and argos screenshots
20
+
21
+ const isOnlyLight = !!flag('ui.darkmode.enabled') // should be remove when dark mode is validated on all apps
22
+ const deviceThemeType = useMediaQuery('(prefers-color-scheme: dark)')
23
+ ? isOnlyLight
24
+ ? 'dark'
25
+ : 'light'
26
+ : 'light'
27
+ const filteredSettingsThemeType = ['light', 'dark'].includes(
28
+ settingsThemeType
29
+ )
30
+ ? settingsThemeType
31
+ : undefined
32
+
33
+ const selfThemeType =
34
+ uiThemeType || filteredSettingsThemeType || deviceThemeType
35
+ const selfThemeVariant = uiThemeVariant || variant
36
+
37
+ return (
38
+ <CozyThemeContext.Provider
39
+ value={{
40
+ type: selfThemeType,
41
+ variant: selfThemeVariant,
42
+ isLight: selfThemeType === 'light'
43
+ }}
44
+ >
45
+ <MuiCozyTheme type={selfThemeType} variant={selfThemeVariant}>
46
+ <div
47
+ className={cx(className, {
48
+ [`CozyTheme--${selfThemeType}-${selfThemeVariant}`]: Boolean(
49
+ selfThemeVariant
50
+ ),
51
+ 'u-dc': ignoreItself
52
+ })}
53
+ >
54
+ {children}
55
+ </div>
56
+ </MuiCozyTheme>
57
+ </CozyThemeContext.Provider>
58
+ )
59
+ }
60
+
61
+ DumbCozyTheme.propTypes = {
62
+ variant: PropTypes.oneOf(['normal', 'inverted']),
63
+ /** Causes this element's children to appear as if they were direct children of the element's parent, ignoring the element itself. */
64
+ ignoreItself: PropTypes.bool,
65
+ className: PropTypes.string,
66
+ /** Theme type from io.cozy.settings.instance */
67
+ settingsThemeType: PropTypes.oneOf(['light', 'dark', 'auto']),
68
+ children: PropTypes.node
69
+ }
70
+
71
+ export default DumbCozyTheme
@@ -1,14 +1,11 @@
1
1
  import React, { createContext, useContext } from 'react'
2
2
  import PropTypes from 'prop-types'
3
- import cx from 'classnames'
4
3
 
5
- import flag from 'cozy-flags'
6
4
  import log from 'cozy-logger'
7
5
 
8
6
  import { isRsg } from '../../hooks/useSetFlagshipUi/helpers'
9
- import useMediaQuery from '../../hooks/useMediaQuery'
10
- import MuiCozyTheme from '../../MuiCozyTheme'
11
7
  import CozyThemeWithQuery from './CozyThemeWithQuery'
8
+ import DumbCozyTheme from './DumbCozyTheme'
12
9
 
13
10
  export const CozyThemeContext = createContext()
14
11
 
@@ -30,81 +27,29 @@ export const useCozyTheme = () => {
30
27
  return context
31
28
  }
32
29
 
33
- const DumbCozyTheme = ({
34
- variant,
35
- className,
36
- ignoreItself,
37
- settingsThemeType,
38
- children
39
- }) => {
40
- const uiThemeType = localStorage.getItem('ui-theme-type') // use only for cozy-ui documentation and argos screenshots
41
- const uiThemeVariant = localStorage.getItem('ui-theme-variant') // use only for cozy-ui documentation and argos screenshots
42
-
43
- const isOnlyLight = !!flag('ui.darkmode.enabled') // should be remove when dark mode is validated on all apps
44
- const deviceThemeType = useMediaQuery('(prefers-color-scheme: dark)')
45
- ? isOnlyLight
46
- ? 'dark'
47
- : 'light'
48
- : 'light'
49
-
50
- const selfThemeType =
51
- uiThemeType ||
52
- (['light', 'dark'].includes(settingsThemeType)
53
- ? settingsThemeType
54
- : deviceThemeType)
55
- const selfThemeVariant = uiThemeVariant || variant
56
-
57
- return (
58
- <CozyThemeContext.Provider
59
- value={{
60
- type: selfThemeType,
61
- variant: selfThemeVariant,
62
- isLight: selfThemeType === 'light'
63
- }}
64
- >
65
- <MuiCozyTheme type={selfThemeType} variant={selfThemeVariant}>
66
- <div
67
- className={cx(className, {
68
- [`CozyTheme--${selfThemeType}-${selfThemeVariant}`]: Boolean(
69
- selfThemeVariant
70
- ),
71
- 'u-dc': ignoreItself
72
- })}
73
- >
74
- {children}
75
- </div>
76
- </MuiCozyTheme>
77
- </CozyThemeContext.Provider>
78
- )
79
- }
80
- DumbCozyTheme.propTypes = CozyThemeProptypes
81
- DumbCozyTheme.defaultProps = CozyThemeDefaultProps
82
-
83
- const CozyTheme = props => {
30
+ const CozyTheme = ({ ignoreCozySettings, ...props }) => {
84
31
  const Comp =
85
- process.env.NODE_ENV === 'test' || isRsg
32
+ ignoreCozySettings || process.env.NODE_ENV === 'test' || isRsg
86
33
  ? DumbCozyTheme
87
34
  : CozyThemeWithQuery
88
35
 
89
36
  return <Comp {...props} />
90
37
  }
91
38
 
92
- const CozyThemeProptypes = {
39
+ CozyTheme.propTypes = {
93
40
  variant: PropTypes.oneOf(['normal', 'inverted']),
94
41
  /** Causes this element's children to appear as if they were direct children of the element's parent, ignoring the element itself. */
95
42
  ignoreItself: PropTypes.bool,
43
+ /** Bypasses the request that retrieves the app's settings in order to define the theme type */
44
+ ignoreCozySettings: PropTypes.bool,
96
45
  className: PropTypes.string,
97
- settingsThemeType: PropTypes.string,
98
46
  children: PropTypes.node
99
47
  }
100
48
 
101
- const CozyThemeDefaultProps = {
49
+ CozyTheme.defaultProps = {
102
50
  variant: 'normal',
51
+ ignoreCozySettings: false,
103
52
  ignoreItself: true
104
53
  }
105
- CozyTheme.propTypes = CozyThemeProptypes
106
- CozyTheme.defaultProps = CozyThemeDefaultProps
107
54
 
108
- // export this way to help doc generates correct component and props
109
55
  export default CozyTheme
110
- export { DumbCozyTheme }
@@ -4,7 +4,7 @@ var _excluded = ["data"];
4
4
  import React from 'react';
5
5
  import { useQuery, isQueryLoading, hasQueryBeenLoaded } from 'cozy-client';
6
6
  import { buildSettingsInstanceQuery } from "cozy-ui/transpiled/react/providers/CozyTheme/queries";
7
- import { DumbCozyTheme } from "cozy-ui/transpiled/react/providers/CozyTheme/index";
7
+ import DumbCozyTheme from "cozy-ui/transpiled/react/providers/CozyTheme/DumbCozyTheme";
8
8
 
9
9
  var CozyThemeWithQuery = function CozyThemeWithQuery(props) {
10
10
  var instanceQuery = buildSettingsInstanceQuery();
@@ -0,0 +1,18 @@
1
+ export default DumbCozyTheme;
2
+ declare function DumbCozyTheme({ variant, className, ignoreItself, settingsThemeType, children }: {
3
+ variant: any;
4
+ className: any;
5
+ ignoreItself: any;
6
+ settingsThemeType: any;
7
+ children: any;
8
+ }): JSX.Element;
9
+ declare namespace DumbCozyTheme {
10
+ namespace propTypes {
11
+ const variant: PropTypes.Requireable<string>;
12
+ const ignoreItself: PropTypes.Requireable<boolean>;
13
+ const className: PropTypes.Requireable<string>;
14
+ const settingsThemeType: PropTypes.Requireable<string>;
15
+ const children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
16
+ }
17
+ }
18
+ import PropTypes from "prop-types";
@@ -0,0 +1,53 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import React from 'react';
3
+ import PropTypes from 'prop-types';
4
+ import cx from 'classnames';
5
+ import flag from 'cozy-flags';
6
+ import useMediaQuery from "cozy-ui/transpiled/react/hooks/useMediaQuery";
7
+ import MuiCozyTheme from "cozy-ui/transpiled/react/MuiCozyTheme";
8
+ import { CozyThemeContext } from "cozy-ui/transpiled/react/providers/CozyTheme/index";
9
+
10
+ var DumbCozyTheme = function DumbCozyTheme(_ref) {
11
+ var _cx;
12
+
13
+ var variant = _ref.variant,
14
+ className = _ref.className,
15
+ ignoreItself = _ref.ignoreItself,
16
+ settingsThemeType = _ref.settingsThemeType,
17
+ children = _ref.children;
18
+ var uiThemeType = localStorage.getItem('ui-theme-type'); // use only for cozy-ui documentation and argos screenshots
19
+
20
+ var uiThemeVariant = localStorage.getItem('ui-theme-variant'); // use only for cozy-ui documentation and argos screenshots
21
+
22
+ var isOnlyLight = !!flag('ui.darkmode.enabled'); // should be remove when dark mode is validated on all apps
23
+
24
+ var deviceThemeType = useMediaQuery('(prefers-color-scheme: dark)') ? isOnlyLight ? 'dark' : 'light' : 'light';
25
+ var filteredSettingsThemeType = ['light', 'dark'].includes(settingsThemeType) ? settingsThemeType : undefined;
26
+ var selfThemeType = uiThemeType || filteredSettingsThemeType || deviceThemeType;
27
+ var selfThemeVariant = uiThemeVariant || variant;
28
+ return /*#__PURE__*/React.createElement(CozyThemeContext.Provider, {
29
+ value: {
30
+ type: selfThemeType,
31
+ variant: selfThemeVariant,
32
+ isLight: selfThemeType === 'light'
33
+ }
34
+ }, /*#__PURE__*/React.createElement(MuiCozyTheme, {
35
+ type: selfThemeType,
36
+ variant: selfThemeVariant
37
+ }, /*#__PURE__*/React.createElement("div", {
38
+ className: cx(className, (_cx = {}, _defineProperty(_cx, "CozyTheme--".concat(selfThemeType, "-").concat(selfThemeVariant), Boolean(selfThemeVariant)), _defineProperty(_cx, 'u-dc', ignoreItself), _cx))
39
+ }, children)));
40
+ };
41
+
42
+ DumbCozyTheme.propTypes = {
43
+ variant: PropTypes.oneOf(['normal', 'inverted']),
44
+
45
+ /** Causes this element's children to appear as if they were direct children of the element's parent, ignoring the element itself. */
46
+ ignoreItself: PropTypes.bool,
47
+ className: PropTypes.string,
48
+
49
+ /** Theme type from io.cozy.settings.instance */
50
+ settingsThemeType: PropTypes.oneOf(['light', 'dark', 'auto']),
51
+ children: PropTypes.node
52
+ };
53
+ export default DumbCozyTheme;
@@ -6,33 +6,25 @@ export function useCozyTheme(): {
6
6
  };
7
7
  export default CozyTheme;
8
8
  import React from "react";
9
- declare function CozyTheme(props: any): JSX.Element;
10
- declare namespace CozyTheme {
11
- export { CozyThemeProptypes as propTypes };
12
- export { CozyThemeDefaultProps as defaultProps };
13
- }
14
- export function DumbCozyTheme({ variant, className, ignoreItself, settingsThemeType, children }: {
15
- variant: any;
16
- className: any;
17
- ignoreItself: any;
18
- settingsThemeType: any;
19
- children: any;
9
+ declare function CozyTheme({ ignoreCozySettings, ...props }: {
10
+ [x: string]: any;
11
+ ignoreCozySettings: any;
20
12
  }): JSX.Element;
21
- export namespace DumbCozyTheme {
22
- export { CozyThemeProptypes as propTypes };
23
- export { CozyThemeDefaultProps as defaultProps };
24
- }
25
- declare namespace CozyThemeProptypes {
26
- const variant: PropTypes.Requireable<string>;
27
- const ignoreItself: PropTypes.Requireable<boolean>;
28
- const className: PropTypes.Requireable<string>;
29
- const settingsThemeType: PropTypes.Requireable<string>;
30
- const children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
31
- }
32
- declare namespace CozyThemeDefaultProps {
33
- const variant_1: string;
34
- export { variant_1 as variant };
35
- const ignoreItself_1: boolean;
36
- export { ignoreItself_1 as ignoreItself };
13
+ declare namespace CozyTheme {
14
+ namespace propTypes {
15
+ const variant: PropTypes.Requireable<string>;
16
+ const ignoreItself: PropTypes.Requireable<boolean>;
17
+ const ignoreCozySettings: PropTypes.Requireable<boolean>;
18
+ const className: PropTypes.Requireable<string>;
19
+ const children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
20
+ }
21
+ namespace defaultProps {
22
+ const variant_1: string;
23
+ export { variant_1 as variant };
24
+ const ignoreCozySettings_1: boolean;
25
+ export { ignoreCozySettings_1 as ignoreCozySettings };
26
+ const ignoreItself_1: boolean;
27
+ export { ignoreItself_1 as ignoreItself };
28
+ }
37
29
  }
38
30
  import PropTypes from "prop-types";
@@ -1,13 +1,11 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
2
+ var _excluded = ["ignoreCozySettings"];
2
3
  import React, { createContext, useContext } from 'react';
3
4
  import PropTypes from 'prop-types';
4
- import cx from 'classnames';
5
- import flag from 'cozy-flags';
6
5
  import log from 'cozy-logger';
7
6
  import { isRsg } from "cozy-ui/transpiled/react/hooks/useSetFlagshipUi/helpers";
8
- import useMediaQuery from "cozy-ui/transpiled/react/hooks/useMediaQuery";
9
- import MuiCozyTheme from "cozy-ui/transpiled/react/MuiCozyTheme";
10
7
  import CozyThemeWithQuery from "cozy-ui/transpiled/react/providers/CozyTheme/CozyThemeWithQuery";
8
+ import DumbCozyTheme from "cozy-ui/transpiled/react/providers/CozyTheme/DumbCozyTheme";
11
9
  export var CozyThemeContext = /*#__PURE__*/createContext();
12
10
  /**
13
11
  * @returns {{ type: 'light'|'dark', variant: 'normal'|'inverted', isLight: boolean }}
@@ -28,60 +26,28 @@ export var useCozyTheme = function useCozyTheme() {
28
26
  return context;
29
27
  };
30
28
 
31
- var DumbCozyTheme = function DumbCozyTheme(_ref) {
32
- var _cx;
29
+ var CozyTheme = function CozyTheme(_ref) {
30
+ var ignoreCozySettings = _ref.ignoreCozySettings,
31
+ props = _objectWithoutProperties(_ref, _excluded);
33
32
 
34
- var variant = _ref.variant,
35
- className = _ref.className,
36
- ignoreItself = _ref.ignoreItself,
37
- settingsThemeType = _ref.settingsThemeType,
38
- children = _ref.children;
39
- var uiThemeType = localStorage.getItem('ui-theme-type'); // use only for cozy-ui documentation and argos screenshots
40
-
41
- var uiThemeVariant = localStorage.getItem('ui-theme-variant'); // use only for cozy-ui documentation and argos screenshots
42
-
43
- var isOnlyLight = !!flag('ui.darkmode.enabled'); // should be remove when dark mode is validated on all apps
44
-
45
- var deviceThemeType = useMediaQuery('(prefers-color-scheme: dark)') ? isOnlyLight ? 'dark' : 'light' : 'light';
46
- var selfThemeType = uiThemeType || (['light', 'dark'].includes(settingsThemeType) ? settingsThemeType : deviceThemeType);
47
- var selfThemeVariant = uiThemeVariant || variant;
48
- return /*#__PURE__*/React.createElement(CozyThemeContext.Provider, {
49
- value: {
50
- type: selfThemeType,
51
- variant: selfThemeVariant,
52
- isLight: selfThemeType === 'light'
53
- }
54
- }, /*#__PURE__*/React.createElement(MuiCozyTheme, {
55
- type: selfThemeType,
56
- variant: selfThemeVariant
57
- }, /*#__PURE__*/React.createElement("div", {
58
- className: cx(className, (_cx = {}, _defineProperty(_cx, "CozyTheme--".concat(selfThemeType, "-").concat(selfThemeVariant), Boolean(selfThemeVariant)), _defineProperty(_cx, 'u-dc', ignoreItself), _cx))
59
- }, children)));
60
- };
61
-
62
- DumbCozyTheme.propTypes = CozyThemeProptypes;
63
- DumbCozyTheme.defaultProps = CozyThemeDefaultProps;
64
-
65
- var CozyTheme = function CozyTheme(props) {
66
- var Comp = process.env.NODE_ENV === 'test' || isRsg ? DumbCozyTheme : CozyThemeWithQuery;
33
+ var Comp = ignoreCozySettings || process.env.NODE_ENV === 'test' || isRsg ? DumbCozyTheme : CozyThemeWithQuery;
67
34
  return /*#__PURE__*/React.createElement(Comp, props);
68
35
  };
69
36
 
70
- var CozyThemeProptypes = {
37
+ CozyTheme.propTypes = {
71
38
  variant: PropTypes.oneOf(['normal', 'inverted']),
72
39
 
73
40
  /** Causes this element's children to appear as if they were direct children of the element's parent, ignoring the element itself. */
74
41
  ignoreItself: PropTypes.bool,
42
+
43
+ /** Bypasses the request that retrieves the app's settings in order to define the theme type */
44
+ ignoreCozySettings: PropTypes.bool,
75
45
  className: PropTypes.string,
76
- settingsThemeType: PropTypes.string,
77
46
  children: PropTypes.node
78
47
  };
79
- var CozyThemeDefaultProps = {
48
+ CozyTheme.defaultProps = {
80
49
  variant: 'normal',
50
+ ignoreCozySettings: false,
81
51
  ignoreItself: true
82
52
  };
83
- CozyTheme.propTypes = CozyThemeProptypes;
84
- CozyTheme.defaultProps = CozyThemeDefaultProps; // export this way to help doc generates correct component and props
85
-
86
- export default CozyTheme;
87
- export { DumbCozyTheme };
53
+ export default CozyTheme;