cozy-ui 109.2.0 → 110.0.1
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 +19 -0
- package/package.json +1 -1
- package/react/ActionsMenu/Actions/print.js +7 -1
- package/react/providers/CozyTheme/CozyThemeWithQuery.jsx +25 -0
- package/react/providers/CozyTheme/Readme.md +1 -0
- package/react/providers/CozyTheme/index.jsx +46 -13
- package/react/providers/CozyTheme/queries.js +14 -0
- package/transpiled/react/ActionsMenu/Actions/print.js +7 -1
- package/transpiled/react/providers/CozyTheme/CozyThemeWithQuery.js +25 -0
- package/transpiled/react/providers/CozyTheme/index.js +28 -10
- package/transpiled/react/providers/CozyTheme/queries.js +13 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
## [110.0.1](https://github.com/cozy/cozy-ui/compare/v110.0.0...v110.0.1) (2024-06-19)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Print in Safari ([03bab6b](https://github.com/cozy/cozy-ui/commit/03bab6b))
|
|
7
|
+
|
|
8
|
+
# [110.0.0](https://github.com/cozy/cozy-ui/compare/v109.2.0...v110.0.0) (2024-06-18)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* **CozyTheme:** Use `io.cozy.settings` to determine default type ([9c513d4](https://github.com/cozy/cozy-ui/commit/9c513d4))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### BREAKING CHANGES
|
|
17
|
+
|
|
18
|
+
* **CozyTheme:** To use `<CozyTheme>` properly, you must have permission in your app to get `io.cozy.settings` documents. The experience would be even better with realtime on this doctypes.
|
|
19
|
+
|
|
1
20
|
# [109.2.0](https://github.com/cozy/cozy-ui/compare/v109.1.1...v109.2.0) (2024-06-17)
|
|
2
21
|
|
|
3
22
|
|
package/package.json
CHANGED
|
@@ -48,7 +48,13 @@ export const print = () => {
|
|
|
48
48
|
docUrl = URL.createObjectURL(blob)
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
/*
|
|
52
|
+
We need to write window.open in a setTimeout because
|
|
53
|
+
Safari does not allow window.open in an async function.
|
|
54
|
+
*/
|
|
55
|
+
setTimeout(() => {
|
|
56
|
+
window.open(docUrl, '_blank')
|
|
57
|
+
})
|
|
52
58
|
} catch (error) {
|
|
53
59
|
logger.error(
|
|
54
60
|
`Error trying to print document ${
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
import { useQuery, isQueryLoading, hasQueryBeenLoaded } from 'cozy-client'
|
|
4
|
+
|
|
5
|
+
import { buildSettingsInstanceQuery } from './queries'
|
|
6
|
+
import { DumbCozyTheme } from './index'
|
|
7
|
+
|
|
8
|
+
const CozyThemeWithQuery = props => {
|
|
9
|
+
const instanceQuery = buildSettingsInstanceQuery()
|
|
10
|
+
const { data: instance, ...instanceQueryLeft } = useQuery(
|
|
11
|
+
instanceQuery.definition,
|
|
12
|
+
instanceQuery.options
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
if (
|
|
16
|
+
isQueryLoading(instanceQueryLeft) &&
|
|
17
|
+
!hasQueryBeenLoaded(instanceQueryLeft)
|
|
18
|
+
) {
|
|
19
|
+
return null
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return <DumbCozyTheme {...props} settingsThemeType={instance?.colorScheme} />
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default CozyThemeWithQuery
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import React, { createContext, useContext, useLayoutEffect } from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import cx from 'classnames'
|
|
4
|
-
import flag from 'cozy-flags'
|
|
5
4
|
|
|
5
|
+
import flag from 'cozy-flags'
|
|
6
6
|
import log from 'cozy-logger'
|
|
7
7
|
|
|
8
|
+
import { isRsg } from '../../hooks/useSetFlagshipUi/helpers'
|
|
8
9
|
import useMediaQuery from '../../hooks/useMediaQuery'
|
|
9
10
|
import MuiCozyTheme from '../../MuiCozyTheme'
|
|
11
|
+
import CozyThemeWithQuery from './CozyThemeWithQuery'
|
|
10
12
|
|
|
11
13
|
export const CozyThemeContext = createContext()
|
|
12
14
|
|
|
@@ -25,7 +27,13 @@ export const useCozyTheme = () => {
|
|
|
25
27
|
return context
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
const
|
|
30
|
+
const DumbCozyTheme = ({
|
|
31
|
+
variant,
|
|
32
|
+
className,
|
|
33
|
+
ignoreItself,
|
|
34
|
+
settingsThemeType,
|
|
35
|
+
children
|
|
36
|
+
}) => {
|
|
29
37
|
const uiThemeType = localStorage.getItem('ui-theme-type') // use only for cozy-ui documentation and argos screenshots
|
|
30
38
|
const uiThemeVariant = localStorage.getItem('ui-theme-variant') // use only for cozy-ui documentation and argos screenshots
|
|
31
39
|
|
|
@@ -36,17 +44,26 @@ const CozyTheme = ({ variant, className, ignoreItself, children }) => {
|
|
|
36
44
|
: 'light'
|
|
37
45
|
: 'light'
|
|
38
46
|
|
|
39
|
-
const selfThemeType =
|
|
47
|
+
const selfThemeType =
|
|
48
|
+
uiThemeType ||
|
|
49
|
+
(['light', 'dark'].includes(settingsThemeType)
|
|
50
|
+
? settingsThemeType
|
|
51
|
+
: deviceThemeType)
|
|
40
52
|
const selfThemeVariant = uiThemeVariant || variant
|
|
41
53
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
54
|
+
useLayoutEffect(() => {
|
|
55
|
+
const negativeThemeType = selfThemeType === 'light' ? 'dark' : 'light'
|
|
56
|
+
|
|
57
|
+
// remove "negative" value because can be changed without refresh
|
|
58
|
+
document
|
|
59
|
+
.querySelector('body')
|
|
60
|
+
.classList.remove(`CozyTheme--${negativeThemeType}-normal`)
|
|
61
|
+
|
|
62
|
+
// add css var to body to be able to use them on it
|
|
63
|
+
document
|
|
64
|
+
.querySelector('body')
|
|
65
|
+
.classList.add(`CozyTheme--${selfThemeType}-normal`) // `add` omits if already present
|
|
66
|
+
}, [selfThemeType])
|
|
50
67
|
|
|
51
68
|
return (
|
|
52
69
|
<CozyThemeContext.Provider
|
|
@@ -67,18 +84,34 @@ const CozyTheme = ({ variant, className, ignoreItself, children }) => {
|
|
|
67
84
|
</CozyThemeContext.Provider>
|
|
68
85
|
)
|
|
69
86
|
}
|
|
87
|
+
DumbCozyTheme.propTypes = CozyThemeProptypes
|
|
88
|
+
DumbCozyTheme.defaultProps = CozyThemeDefaultProps
|
|
89
|
+
|
|
90
|
+
const CozyTheme = props => {
|
|
91
|
+
const Comp =
|
|
92
|
+
process.env.NODE_ENV === 'test' || isRsg
|
|
93
|
+
? DumbCozyTheme
|
|
94
|
+
: CozyThemeWithQuery
|
|
95
|
+
|
|
96
|
+
return <Comp {...props} />
|
|
97
|
+
}
|
|
70
98
|
|
|
71
|
-
|
|
99
|
+
const CozyThemeProptypes = {
|
|
72
100
|
variant: PropTypes.oneOf(['normal', 'inverted']),
|
|
73
101
|
/** Causes this element's children to appear as if they were direct children of the element's parent, ignoring the element itself. */
|
|
74
102
|
ignoreItself: PropTypes.bool,
|
|
75
103
|
className: PropTypes.string,
|
|
104
|
+
settingsThemeType: PropTypes.string,
|
|
76
105
|
children: PropTypes.node
|
|
77
106
|
}
|
|
78
107
|
|
|
79
|
-
|
|
108
|
+
const CozyThemeDefaultProps = {
|
|
80
109
|
variant: 'normal',
|
|
81
110
|
ignoreItself: true
|
|
82
111
|
}
|
|
112
|
+
CozyTheme.propTypes = CozyThemeProptypes
|
|
113
|
+
CozyTheme.defaultProps = CozyThemeDefaultProps
|
|
83
114
|
|
|
115
|
+
// export this way to help doc generates correct component and props
|
|
84
116
|
export default CozyTheme
|
|
117
|
+
export { DumbCozyTheme }
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Q, fetchPolicies } from 'cozy-client'
|
|
2
|
+
|
|
3
|
+
const SETTINGS_DOCTYPE = 'io.cozy.settings'
|
|
4
|
+
|
|
5
|
+
const defaultFetchPolicy = fetchPolicies.olderThan(5 * 60 * 1000)
|
|
6
|
+
|
|
7
|
+
export const buildSettingsInstanceQuery = () => ({
|
|
8
|
+
definition: Q(SETTINGS_DOCTYPE).getById('io.cozy.settings.instance'),
|
|
9
|
+
options: {
|
|
10
|
+
as: `${SETTINGS_DOCTYPE}/io.cozy.settings.instance`,
|
|
11
|
+
fetchPolicy: defaultFetchPolicy,
|
|
12
|
+
singleDocData: true
|
|
13
|
+
}
|
|
14
|
+
})
|
|
@@ -102,7 +102,13 @@ export var print = function print() {
|
|
|
102
102
|
docUrl = URL.createObjectURL(_blob);
|
|
103
103
|
|
|
104
104
|
case 30:
|
|
105
|
-
|
|
105
|
+
/*
|
|
106
|
+
We need to write window.open in a setTimeout because
|
|
107
|
+
Safari does not allow window.open in an async function.
|
|
108
|
+
*/
|
|
109
|
+
setTimeout(function () {
|
|
110
|
+
window.open(docUrl, '_blank');
|
|
111
|
+
});
|
|
106
112
|
_context.next = 36;
|
|
107
113
|
break;
|
|
108
114
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["data"];
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { useQuery, isQueryLoading, hasQueryBeenLoaded } from 'cozy-client';
|
|
6
|
+
import { buildSettingsInstanceQuery } from "cozy-ui/transpiled/react/providers/CozyTheme/queries";
|
|
7
|
+
import { DumbCozyTheme } from "cozy-ui/transpiled/react/providers/CozyTheme/index";
|
|
8
|
+
|
|
9
|
+
var CozyThemeWithQuery = function CozyThemeWithQuery(props) {
|
|
10
|
+
var instanceQuery = buildSettingsInstanceQuery();
|
|
11
|
+
|
|
12
|
+
var _useQuery = useQuery(instanceQuery.definition, instanceQuery.options),
|
|
13
|
+
instance = _useQuery.data,
|
|
14
|
+
instanceQueryLeft = _objectWithoutProperties(_useQuery, _excluded);
|
|
15
|
+
|
|
16
|
+
if (isQueryLoading(instanceQueryLeft) && !hasQueryBeenLoaded(instanceQueryLeft)) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return /*#__PURE__*/React.createElement(DumbCozyTheme, _extends({}, props, {
|
|
21
|
+
settingsThemeType: instance === null || instance === void 0 ? void 0 : instance.colorScheme
|
|
22
|
+
}));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default CozyThemeWithQuery;
|
|
@@ -4,8 +4,10 @@ import PropTypes from 'prop-types';
|
|
|
4
4
|
import cx from 'classnames';
|
|
5
5
|
import flag from 'cozy-flags';
|
|
6
6
|
import log from 'cozy-logger';
|
|
7
|
+
import { isRsg } from "cozy-ui/transpiled/react/hooks/useSetFlagshipUi/helpers";
|
|
7
8
|
import useMediaQuery from "cozy-ui/transpiled/react/hooks/useMediaQuery";
|
|
8
9
|
import MuiCozyTheme from "cozy-ui/transpiled/react/MuiCozyTheme";
|
|
10
|
+
import CozyThemeWithQuery from "cozy-ui/transpiled/react/providers/CozyTheme/CozyThemeWithQuery";
|
|
9
11
|
export var CozyThemeContext = /*#__PURE__*/createContext();
|
|
10
12
|
export var useCozyTheme = function useCozyTheme() {
|
|
11
13
|
var context = useContext(CozyThemeContext);
|
|
@@ -21,12 +23,13 @@ export var useCozyTheme = function useCozyTheme() {
|
|
|
21
23
|
return context;
|
|
22
24
|
};
|
|
23
25
|
|
|
24
|
-
var
|
|
26
|
+
var DumbCozyTheme = function DumbCozyTheme(_ref) {
|
|
25
27
|
var _cx;
|
|
26
28
|
|
|
27
29
|
var variant = _ref.variant,
|
|
28
30
|
className = _ref.className,
|
|
29
31
|
ignoreItself = _ref.ignoreItself,
|
|
32
|
+
settingsThemeType = _ref.settingsThemeType,
|
|
30
33
|
children = _ref.children;
|
|
31
34
|
var uiThemeType = localStorage.getItem('ui-theme-type'); // use only for cozy-ui documentation and argos screenshots
|
|
32
35
|
|
|
@@ -35,13 +38,15 @@ var CozyTheme = function CozyTheme(_ref) {
|
|
|
35
38
|
var isOnlyLight = !!flag('ui.darkmode.enabled'); // should be remove when dark mode is validated on all apps
|
|
36
39
|
|
|
37
40
|
var deviceThemeType = useMediaQuery('(prefers-color-scheme: dark)') ? isOnlyLight ? 'dark' : 'light' : 'light';
|
|
38
|
-
var selfThemeType = uiThemeType || deviceThemeType;
|
|
39
|
-
var selfThemeVariant = uiThemeVariant || variant;
|
|
40
|
-
|
|
41
|
+
var selfThemeType = uiThemeType || (['light', 'dark'].includes(settingsThemeType) ? settingsThemeType : deviceThemeType);
|
|
42
|
+
var selfThemeVariant = uiThemeVariant || variant;
|
|
41
43
|
useLayoutEffect(function () {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
var negativeThemeType = selfThemeType === 'light' ? 'dark' : 'light'; // remove "negative" value because can be changed without refresh
|
|
45
|
+
|
|
46
|
+
document.querySelector('body').classList.remove("CozyTheme--".concat(negativeThemeType, "-normal")); // add css var to body to be able to use them on it
|
|
47
|
+
|
|
48
|
+
document.querySelector('body').classList.add("CozyTheme--".concat(selfThemeType, "-normal")); // `add` omits if already present
|
|
49
|
+
}, [selfThemeType]);
|
|
45
50
|
return /*#__PURE__*/React.createElement(CozyThemeContext.Provider, {
|
|
46
51
|
value: {
|
|
47
52
|
type: selfThemeType,
|
|
@@ -55,16 +60,29 @@ var CozyTheme = function CozyTheme(_ref) {
|
|
|
55
60
|
}, children)));
|
|
56
61
|
};
|
|
57
62
|
|
|
58
|
-
|
|
63
|
+
DumbCozyTheme.propTypes = CozyThemeProptypes;
|
|
64
|
+
DumbCozyTheme.defaultProps = CozyThemeDefaultProps;
|
|
65
|
+
|
|
66
|
+
var CozyTheme = function CozyTheme(props) {
|
|
67
|
+
var Comp = process.env.NODE_ENV === 'test' || isRsg ? DumbCozyTheme : CozyThemeWithQuery;
|
|
68
|
+
return /*#__PURE__*/React.createElement(Comp, props);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
var CozyThemeProptypes = {
|
|
59
72
|
variant: PropTypes.oneOf(['normal', 'inverted']),
|
|
60
73
|
|
|
61
74
|
/** Causes this element's children to appear as if they were direct children of the element's parent, ignoring the element itself. */
|
|
62
75
|
ignoreItself: PropTypes.bool,
|
|
63
76
|
className: PropTypes.string,
|
|
77
|
+
settingsThemeType: PropTypes.string,
|
|
64
78
|
children: PropTypes.node
|
|
65
79
|
};
|
|
66
|
-
|
|
80
|
+
var CozyThemeDefaultProps = {
|
|
67
81
|
variant: 'normal',
|
|
68
82
|
ignoreItself: true
|
|
69
83
|
};
|
|
70
|
-
|
|
84
|
+
CozyTheme.propTypes = CozyThemeProptypes;
|
|
85
|
+
CozyTheme.defaultProps = CozyThemeDefaultProps; // export this way to help doc generates correct component and props
|
|
86
|
+
|
|
87
|
+
export default CozyTheme;
|
|
88
|
+
export { DumbCozyTheme };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Q, fetchPolicies } from 'cozy-client';
|
|
2
|
+
var SETTINGS_DOCTYPE = 'io.cozy.settings';
|
|
3
|
+
var defaultFetchPolicy = fetchPolicies.olderThan(5 * 60 * 1000);
|
|
4
|
+
export var buildSettingsInstanceQuery = function buildSettingsInstanceQuery() {
|
|
5
|
+
return {
|
|
6
|
+
definition: Q(SETTINGS_DOCTYPE).getById('io.cozy.settings.instance'),
|
|
7
|
+
options: {
|
|
8
|
+
as: "".concat(SETTINGS_DOCTYPE, "/io.cozy.settings.instance"),
|
|
9
|
+
fetchPolicy: defaultFetchPolicy,
|
|
10
|
+
singleDocData: true
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
};
|