cozy-ui 102.1.0 → 102.1.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 +7 -0
- package/package.json +1 -1
- package/react/BottomSheet/BottomSheet.jsx +2 -2
- package/react/BottomSheet/README.md +1 -1
- package/react/BottomSheet/helpers.js +1 -1
- package/react/BottomSheet/helpers.spec.js +1 -1
- package/react/CozyDialogs/Readme.md +0 -41
- package/react/Dialog/DialogEffects.spec.tsx +5 -2
- package/react/Dialog/DialogEffects.ts +8 -5
- package/react/deprecated/ActionMenu/ActionMenuEffects.ts +6 -4
- package/react/deprecated/Modal/ModalEffects.ts +2 -1
- package/react/hooks/useSetFlagshipUi/helpers.js +149 -0
- package/react/hooks/useSetFlagshipUi/useSetFlagshipUI.ts +7 -3
- package/transpiled/react/BottomSheet/BottomSheet.js +5 -7
- package/transpiled/react/BottomSheet/helpers.js +1 -1
- package/transpiled/react/Dialog/DialogEffects.js +4 -2
- package/transpiled/react/deprecated/ActionMenu/ActionMenuEffects.js +2 -1
- package/transpiled/react/deprecated/Modal/ModalEffects.js +2 -1
- package/transpiled/react/hooks/useSetFlagshipUi/helpers.d.ts +18 -0
- package/transpiled/react/hooks/useSetFlagshipUi/helpers.js +143 -0
- package/transpiled/react/hooks/useSetFlagshipUi/useSetFlagshipUI.js +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [102.1.1](https://github.com/cozy/cozy-ui/compare/v102.1.0...v102.1.1) (2024-01-29)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **BottomSheet:** Default offset value wasn't good if flagship immersive [secure] ([b1551d2](https://github.com/cozy/cozy-ui/commit/b1551d2))
|
|
7
|
+
|
|
1
8
|
# [102.1.0](https://github.com/cozy/cozy-ui/compare/v102.0.0...v102.1.0) (2024-01-25)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@ import { useMutationObserver, useTimeoutWhen } from 'rooks'
|
|
|
13
13
|
import Fade from '@material-ui/core/Fade'
|
|
14
14
|
import Portal from '@material-ui/core/Portal'
|
|
15
15
|
|
|
16
|
-
import { getFlagshipMetadata } from '
|
|
16
|
+
import { getFlagshipMetadata } from '../hooks/useSetFlagshipUi/helpers'
|
|
17
17
|
|
|
18
18
|
import { useSetFlagshipUI } from '../hooks/useSetFlagshipUi/useSetFlagshipUI'
|
|
19
19
|
import CozyTheme, { useCozyTheme } from '../providers/CozyTheme'
|
|
@@ -392,7 +392,7 @@ BottomSheet.defaultProps = {
|
|
|
392
392
|
toolbarProps: {},
|
|
393
393
|
backdrop: false,
|
|
394
394
|
offset:
|
|
395
|
-
(getFlagshipMetadata().immersive && getFlagshipMetadata().navbarHeight)
|
|
395
|
+
(getFlagshipMetadata().immersive && getFlagshipMetadata().navbarHeight) || 0
|
|
396
396
|
}
|
|
397
397
|
|
|
398
398
|
BottomSheet.propTypes = {
|
|
@@ -94,7 +94,7 @@ const initialState = {
|
|
|
94
94
|
isSecondBottomSheetDisplayed: false,
|
|
95
95
|
mediumHeight: isTesting() ? 450 : undefined,
|
|
96
96
|
mediumHeightRatio: undefined,
|
|
97
|
-
offset:
|
|
97
|
+
offset: undefined
|
|
98
98
|
}
|
|
99
99
|
const showBottomSheet = () => setState({ isBottomSheetDisplayed: true })
|
|
100
100
|
const hideBottomSheet = () => setState({ isBottomSheetDisplayed: false })
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import { getFlagshipMetadata } from 'cozy-device-helper'
|
|
3
2
|
|
|
4
3
|
import { ANIMATION_DURATION } from './constants'
|
|
5
4
|
import { getSafeAreaValue } from '../helpers/getSafeArea'
|
|
5
|
+
import { getFlagshipMetadata } from '../hooks/useSetFlagshipUi/helpers'
|
|
6
6
|
|
|
7
7
|
export const computeToolbarHeight = (toolbarProps = {}) => {
|
|
8
8
|
const { ref, height } = toolbarProps
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
jest.mock('../helpers/getSafeArea', () => ({
|
|
13
13
|
getSafeAreaValue: jest.fn().mockReturnValue(15)
|
|
14
14
|
}))
|
|
15
|
-
jest.mock('
|
|
15
|
+
jest.mock('../hooks/useSetFlagshipUi/helpers', () => ({
|
|
16
16
|
getFlagshipMetadata: jest.fn(() => ({ navbarHeight: 10 }))
|
|
17
17
|
}))
|
|
18
18
|
const windowSpy = jest.spyOn(window, 'window', 'get')
|
|
@@ -208,50 +208,9 @@ const initialVariants = [{
|
|
|
208
208
|
withBackground: false
|
|
209
209
|
}]
|
|
210
210
|
|
|
211
|
-
// The goal of this method is to simulate the
|
|
212
|
-
// immersive mode of the flagship app. So we
|
|
213
|
-
// add the flagship-app class to the body and
|
|
214
|
-
// we set 2 css variables:
|
|
215
|
-
// flagship-top-height
|
|
216
|
-
// flagship-bottom-height
|
|
217
|
-
const setFlagshipVars = () => {
|
|
218
|
-
const root = document.getElementsByTagName('body')[0]
|
|
219
|
-
root.style.setProperty('--flagship-top-height', "40px")
|
|
220
|
-
root.style.setProperty('--flagship-bottom-height', "40px")
|
|
221
|
-
root.classList.add('flagship-app')
|
|
222
|
-
|
|
223
|
-
const statusBarDiv = document.createElement("div")
|
|
224
|
-
statusBarDiv.style.cssText = "position:fixed;top:0;height:40px;z-index:10000000;background-color:red;width:100%"
|
|
225
|
-
// and give it some content
|
|
226
|
-
const statusBarDivContent = document.createTextNode("Top Status Bar with clock")
|
|
227
|
-
|
|
228
|
-
// add the text node to the newly created div
|
|
229
|
-
statusBarDiv.appendChild(statusBarDivContent)
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
const bottomBarDiv = document.createElement("div")
|
|
233
|
-
bottomBarDiv.style.cssText = "position:fixed;bottom:0;height:40px;z-index:10000000;background-color:red;width:100%"
|
|
234
|
-
// and give it some content
|
|
235
|
-
const bottomBarDivContent = document.createTextNode("BottomBar")
|
|
236
|
-
|
|
237
|
-
// add the text node to the newly created div
|
|
238
|
-
bottomBarDiv.appendChild(bottomBarDivContent)
|
|
239
|
-
|
|
240
|
-
// add the newly created element and its content into the DOM
|
|
241
|
-
const currentDiv = document.getElementById("rsg-root")
|
|
242
|
-
document.body.insertBefore(statusBarDiv, currentDiv)
|
|
243
|
-
document.body.insertBefore(bottomBarDiv, currentDiv)
|
|
244
|
-
}
|
|
245
|
-
|
|
246
211
|
;
|
|
247
212
|
|
|
248
213
|
<DemoProvider>
|
|
249
|
-
<Button
|
|
250
|
-
className="u-mb-1"
|
|
251
|
-
variant="secondary"
|
|
252
|
-
label={'Simulate Immersive Flagship Mode'}
|
|
253
|
-
onClick={() => setFlagshipVars()}
|
|
254
|
-
/>
|
|
255
214
|
<Variants initialVariants={initialVariants}>
|
|
256
215
|
{variant => (
|
|
257
216
|
<>
|
|
@@ -238,8 +238,11 @@ it('should provide the inversed UI when Cozybar is not black on white, but white
|
|
|
238
238
|
})
|
|
239
239
|
|
|
240
240
|
jest.mock('cozy-device-helper', () => ({
|
|
241
|
-
isFlagshipApp: (): boolean => true
|
|
242
|
-
|
|
241
|
+
isFlagshipApp: (): boolean => true
|
|
242
|
+
}))
|
|
243
|
+
jest.mock('../hooks/useSetFlagshipUi/helpers', () => ({
|
|
244
|
+
getFlagshipMetadata: (): Record<string, never> => ({}),
|
|
245
|
+
setRsgFlagshipElements: (): null => null
|
|
243
246
|
}))
|
|
244
247
|
|
|
245
248
|
const onOpenMountExpected = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getLuminance, Theme, useTheme } from '@material-ui/core'
|
|
2
2
|
import { useEffect } from 'react'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { isFlagshipApp } from 'cozy-device-helper'
|
|
5
5
|
import { useWebviewIntent } from 'cozy-intent'
|
|
6
6
|
|
|
7
7
|
import {
|
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
ThemeColor,
|
|
10
10
|
parseArg
|
|
11
11
|
} from '../hooks/useSetFlagshipUi/useSetFlagshipUI'
|
|
12
|
+
import { getFlagshipMetadata } from '../hooks/useSetFlagshipUi/helpers'
|
|
13
|
+
import { isRsg } from '../hooks/useSetFlagshipUi/helpers'
|
|
12
14
|
|
|
13
15
|
interface DialogEffectsOptions {
|
|
14
16
|
cozybar?: Element | null
|
|
@@ -192,7 +194,8 @@ export const useDialogSetFlagshipUI = (
|
|
|
192
194
|
}, [open, webviewIntent]) // eslint-disable-line react-hooks/exhaustive-deps
|
|
193
195
|
}
|
|
194
196
|
|
|
195
|
-
export const useDialogEffects =
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
197
|
+
export const useDialogEffects =
|
|
198
|
+
isFlagshipApp() || isRsg
|
|
199
|
+
? useHook
|
|
200
|
+
: // eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
201
|
+
(): void => {}
|
|
@@ -7,6 +7,7 @@ import { Theme, useTheme } from '@material-ui/core'
|
|
|
7
7
|
import { isFlagshipApp } from 'cozy-device-helper'
|
|
8
8
|
|
|
9
9
|
import { useSetFlagshipUI } from '../../hooks/useSetFlagshipUi/useSetFlagshipUI'
|
|
10
|
+
import { isRsg } from '../../hooks/useSetFlagshipUi/helpers'
|
|
10
11
|
|
|
11
12
|
const getBottomBackground = (theme: Theme): string => {
|
|
12
13
|
const sidebar = document.getElementById('sidebar')
|
|
@@ -40,7 +41,8 @@ const useHook = (): void => {
|
|
|
40
41
|
)
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
export const useActionMenuEffects =
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
export const useActionMenuEffects =
|
|
45
|
+
isFlagshipApp() || isRsg
|
|
46
|
+
? useHook
|
|
47
|
+
: // eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
48
|
+
(): void => {}
|
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
import { Theme, useTheme } from '@material-ui/core'
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { isFlagshipApp } from 'cozy-device-helper'
|
|
8
8
|
|
|
9
9
|
import { useSetFlagshipUI } from '../../hooks/useSetFlagshipUi/useSetFlagshipUI'
|
|
10
|
+
import { getFlagshipMetadata } from '../../hooks/useSetFlagshipUi/helpers'
|
|
10
11
|
|
|
11
12
|
const getTopBackground = (theme: Theme, cozyBar: Element | null): string =>
|
|
12
13
|
(cozyBar && getComputedStyle(cozyBar).getPropertyValue('background-color')) ||
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// eslint-disable-next-line no-unused-vars
|
|
2
|
+
import { FlagshipUI } from './useSetFlagshipUI'
|
|
3
|
+
import { getFlagshipMetadata as getFlagshipMetadataFromDeviceHelper } from 'cozy-device-helper'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The goal of this method is to simulate the immersive mode of the flagship app.
|
|
7
|
+
* So we add the flagship-app class to the body and we set css variables:
|
|
8
|
+
* If the "contained" mode is activated, it simulates an classic app behavior
|
|
9
|
+
* If the "immersive" mode is activated, it simulates a fullscreen app like Home
|
|
10
|
+
*/
|
|
11
|
+
export const addFlagshipElements = () => {
|
|
12
|
+
const root = document.getElementsByTagName('body')[0]
|
|
13
|
+
root.style.setProperty('--flagship-top-height', '40px')
|
|
14
|
+
root.style.setProperty('--flagship-top-bgcolor', 'white') // used only for cozy-ui docs
|
|
15
|
+
root.style.setProperty('--flagship-top-overlay', 'transparent') // used only for cozy-ui docs
|
|
16
|
+
root.style.setProperty('--flagship-top-color', 'black') // used only for cozy-ui docs
|
|
17
|
+
root.style.setProperty('--flagship-bottom-height', '40px')
|
|
18
|
+
root.style.setProperty('--flagship-bottom-bgcolor', 'white') // used only for cozy-ui docs
|
|
19
|
+
root.style.setProperty('--flagship-bottom-overlay', 'transparent') // used only for cozy-ui docs
|
|
20
|
+
root.style.setProperty('--flagship-bottom-color', 'black') // used only for cozy-ui docs
|
|
21
|
+
root.classList.add('flagship-app')
|
|
22
|
+
|
|
23
|
+
// create status bar
|
|
24
|
+
const statusBarDiv = document.createElement('div')
|
|
25
|
+
statusBarDiv.setAttribute('id', 'flagshipStatusBar')
|
|
26
|
+
statusBarDiv.style.cssText =
|
|
27
|
+
'position:fixed;top:0;height:var(--flagship-top-height);z-index:10000000;color:var(--flagship-top-color);background-color:var(--flagship-top-bgcolor);width:100%;display:flex;align-items:center;justify-content:center'
|
|
28
|
+
// create status bar overlay
|
|
29
|
+
const statusBarOverlay = document.createElement('div')
|
|
30
|
+
statusBarOverlay.setAttribute('id', 'flagshipStatusBarOverlay')
|
|
31
|
+
statusBarOverlay.style.cssText =
|
|
32
|
+
'position:absolute;top:0;left:0;width:100%;height:100%;z-index:-1;background-color:var(--flagship-top-overlay)'
|
|
33
|
+
statusBarDiv.appendChild(statusBarOverlay)
|
|
34
|
+
// create status bar text
|
|
35
|
+
const statusBarText = document.createElement('div')
|
|
36
|
+
statusBarText.setAttribute('id', 'flagshipStatusBarText')
|
|
37
|
+
statusBarText.innerText = 'Flagship Top Status Bar with clock'
|
|
38
|
+
statusBarDiv.appendChild(statusBarText)
|
|
39
|
+
|
|
40
|
+
// create nav bar
|
|
41
|
+
const navBarDiv = document.createElement('div')
|
|
42
|
+
navBarDiv.setAttribute('id', 'flagshipNavBar')
|
|
43
|
+
navBarDiv.style.cssText =
|
|
44
|
+
'position:fixed;bottom:0;height:var(--flagship-bottom-height);z-index:10000000;color:var(--flagship-bottom-color);background-color:var(--flagship-bottom-bgcolor);width:100%;display:flex;align-items:center;justify-content:center'
|
|
45
|
+
// create nav bar overlay
|
|
46
|
+
const navBarOverlay = document.createElement('div')
|
|
47
|
+
navBarOverlay.setAttribute('id', 'flagshipNavBarOverlay')
|
|
48
|
+
navBarOverlay.style.cssText =
|
|
49
|
+
'position:absolute;top:0;left:0;width:100%;height:100%;z-index:-1;background-color:var(--flagship-bottom-overlay)'
|
|
50
|
+
navBarDiv.appendChild(navBarOverlay)
|
|
51
|
+
// create nav bar text
|
|
52
|
+
const navBarText = document.createElement('div')
|
|
53
|
+
navBarText.setAttribute('id', 'flagshipNavBarText')
|
|
54
|
+
navBarText.innerText = 'Flagship Nav Bar'
|
|
55
|
+
navBarDiv.appendChild(navBarText)
|
|
56
|
+
|
|
57
|
+
// add status and nav bar and its content into the DOM
|
|
58
|
+
const currentDiv = document.getElementById('rsg-root')
|
|
59
|
+
document.body.insertBefore(statusBarDiv, currentDiv)
|
|
60
|
+
document.body.insertBefore(navBarDiv, currentDiv)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Remove fake DOM element that simulates native Status and Nav bar
|
|
65
|
+
*/
|
|
66
|
+
export const removeFlagshipElements = () => {
|
|
67
|
+
const root = document.getElementsByTagName('body')[0]
|
|
68
|
+
root.style.removeProperty('--flagship-top-height')
|
|
69
|
+
root.style.removeProperty('--flagship-top-bgcolor')
|
|
70
|
+
root.style.removeProperty('--flagship-top-overlay')
|
|
71
|
+
root.style.removeProperty('--flagship-top-color')
|
|
72
|
+
root.style.removeProperty('--flagship-bottom-height')
|
|
73
|
+
root.style.removeProperty('--flagship-bottom-bgcolor')
|
|
74
|
+
root.style.removeProperty('--flagship-bottom-overlay')
|
|
75
|
+
root.style.removeProperty('--flagship-bottom-color')
|
|
76
|
+
root.classList.remove('flagship-app')
|
|
77
|
+
|
|
78
|
+
document.getElementById('flagshipStatusBar')?.remove()
|
|
79
|
+
document.getElementById('flagshipNavBar')?.remove()
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Whether we are in cozy-ui documentation (Rsg is for ReactStyleGuide)
|
|
84
|
+
* @returns {boolean}
|
|
85
|
+
*/
|
|
86
|
+
export const isRsg = !!document.getElementById('rsg-root')
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Overrides flagship metadata
|
|
90
|
+
* See https://github.com/cozy/cozy-libs/blob/master/packages/cozy-device-helper/src/flagship.ts#L13
|
|
91
|
+
*/
|
|
92
|
+
export const getFlagshipMetadata = isRsg
|
|
93
|
+
? () => ({
|
|
94
|
+
immersive:
|
|
95
|
+
JSON.parse(localStorage.getItem('flagship-app'))?.contained === 'off' ||
|
|
96
|
+
false,
|
|
97
|
+
statusBarHeight: 40,
|
|
98
|
+
navbarHeight: 40
|
|
99
|
+
})
|
|
100
|
+
: getFlagshipMetadataFromDeviceHelper
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Set the css values for Status and Nav bar inside cozy-ui documentation
|
|
104
|
+
* see https://github.com/cozy/cozy-libs/blob/master/packages/cozy-intent/src/api/models/applications.ts#L33
|
|
105
|
+
* @param {undefined | Partial<FlagshipUI>} param0
|
|
106
|
+
* @returns
|
|
107
|
+
*/
|
|
108
|
+
export const setRsgFlagshipElements = ({
|
|
109
|
+
topBackground,
|
|
110
|
+
topOverlay,
|
|
111
|
+
topTheme,
|
|
112
|
+
bottomBackground,
|
|
113
|
+
bottomOverlay,
|
|
114
|
+
bottomTheme
|
|
115
|
+
} = {}) => {
|
|
116
|
+
if (!isRsg) return
|
|
117
|
+
|
|
118
|
+
const root = document.getElementsByTagName('body')[0]
|
|
119
|
+
|
|
120
|
+
if (topBackground) {
|
|
121
|
+
root.style.setProperty('--flagship-top-bgcolor', topBackground)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (topOverlay) {
|
|
125
|
+
root.style.setProperty('--flagship-top-overlay', topOverlay)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (topTheme) {
|
|
129
|
+
root.style.setProperty(
|
|
130
|
+
'--flagship-top-color',
|
|
131
|
+
topTheme === 'dark' ? 'black' : 'white'
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (bottomBackground) {
|
|
136
|
+
root.style.setProperty('--flagship-bottom-bgcolor', bottomBackground)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (bottomOverlay) {
|
|
140
|
+
root.style.setProperty('--flagship-bottom-overlay', bottomOverlay)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (bottomTheme) {
|
|
144
|
+
root.style.setProperty(
|
|
145
|
+
'--flagship-bottom-color',
|
|
146
|
+
bottomTheme === 'dark' ? 'black' : 'white'
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -8,6 +8,8 @@ import { useWebviewIntent } from 'cozy-intent'
|
|
|
8
8
|
import { FlagshipUI as IntentInterface } from 'cozy-intent/dist/api/models/applications'
|
|
9
9
|
import { WebviewService } from 'cozy-intent/dist/api/services/WebviewService'
|
|
10
10
|
|
|
11
|
+
import { setRsgFlagshipElements } from './helpers'
|
|
12
|
+
|
|
11
13
|
export enum ThemeColor {
|
|
12
14
|
Dark = 'dark',
|
|
13
15
|
Light = 'light'
|
|
@@ -23,11 +25,13 @@ export const parseArg = (
|
|
|
23
25
|
arg?: FlagshipUI,
|
|
24
26
|
caller?: string
|
|
25
27
|
): void => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const sanitized = isObject(arg) && pickBy(arg, identity)
|
|
28
|
+
const sanitized = isObject(arg) ? pickBy(arg, identity) : undefined
|
|
29
29
|
const validUI = !isEmpty(sanitized) && sanitized
|
|
30
30
|
|
|
31
|
+
setRsgFlagshipElements(sanitized)
|
|
32
|
+
|
|
33
|
+
if (!webviewIntent) return
|
|
34
|
+
|
|
31
35
|
validUI && webviewIntent.call('setFlagshipUI', validUI, caller)
|
|
32
36
|
}
|
|
33
37
|
|
|
@@ -5,8 +5,6 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
5
5
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
6
6
|
var _excluded = ["portalProps"];
|
|
7
7
|
|
|
8
|
-
var _ref4;
|
|
9
|
-
|
|
10
8
|
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; }
|
|
11
9
|
|
|
12
10
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
@@ -17,7 +15,7 @@ import { BottomSheet as MuiBottomSheet } from 'mui-bottom-sheet';
|
|
|
17
15
|
import { useMutationObserver, useTimeoutWhen } from 'rooks';
|
|
18
16
|
import Fade from '@material-ui/core/Fade';
|
|
19
17
|
import Portal from '@material-ui/core/Portal';
|
|
20
|
-
import { getFlagshipMetadata } from
|
|
18
|
+
import { getFlagshipMetadata } from "cozy-ui/transpiled/react/hooks/useSetFlagshipUi/helpers";
|
|
21
19
|
import { useSetFlagshipUI } from "cozy-ui/transpiled/react/hooks/useSetFlagshipUi/useSetFlagshipUI";
|
|
22
20
|
import CozyTheme, { useCozyTheme } from "cozy-ui/transpiled/react/providers/CozyTheme";
|
|
23
21
|
import Stack from "cozy-ui/transpiled/react/Stack";
|
|
@@ -384,7 +382,7 @@ BottomSheet.defaultProps = {
|
|
|
384
382
|
classes: {},
|
|
385
383
|
toolbarProps: {},
|
|
386
384
|
backdrop: false,
|
|
387
|
-
offset:
|
|
385
|
+
offset: getFlagshipMetadata().immersive && getFlagshipMetadata().navbarHeight || 0
|
|
388
386
|
};
|
|
389
387
|
BottomSheet.propTypes = {
|
|
390
388
|
/** Toolbar properties */
|
|
@@ -417,9 +415,9 @@ BottomSheet.propTypes = {
|
|
|
417
415
|
/** To totally close the BottomSheet by swaping it down */
|
|
418
416
|
onClose: PropTypes.func
|
|
419
417
|
};
|
|
420
|
-
var BottomSheetPortal = /*#__PURE__*/forwardRef(function (
|
|
421
|
-
var portalProps =
|
|
422
|
-
props = _objectWithoutProperties(
|
|
418
|
+
var BottomSheetPortal = /*#__PURE__*/forwardRef(function (_ref4, ref) {
|
|
419
|
+
var portalProps = _ref4.portalProps,
|
|
420
|
+
props = _objectWithoutProperties(_ref4, _excluded);
|
|
423
421
|
|
|
424
422
|
var _useCozyTheme = useCozyTheme(),
|
|
425
423
|
variant = _useCozyTheme.variant;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { getFlagshipMetadata } from 'cozy-device-helper';
|
|
3
2
|
import { ANIMATION_DURATION } from "cozy-ui/transpiled/react/BottomSheet/constants";
|
|
4
3
|
import { getSafeAreaValue } from "cozy-ui/transpiled/react/helpers/getSafeArea";
|
|
4
|
+
import { getFlagshipMetadata } from "cozy-ui/transpiled/react/hooks/useSetFlagshipUi/helpers";
|
|
5
5
|
export var computeToolbarHeight = function computeToolbarHeight() {
|
|
6
6
|
var toolbarProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
7
7
|
var ref = toolbarProps.ref,
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { getLuminance, useTheme } from '@material-ui/core';
|
|
2
2
|
import { useEffect } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { isFlagshipApp } from 'cozy-device-helper';
|
|
4
4
|
import { useWebviewIntent } from 'cozy-intent';
|
|
5
5
|
import { ThemeColor, parseArg } from "cozy-ui/transpiled/react/hooks/useSetFlagshipUi/useSetFlagshipUI";
|
|
6
|
+
import { getFlagshipMetadata } from "cozy-ui/transpiled/react/hooks/useSetFlagshipUi/helpers";
|
|
7
|
+
import { isRsg } from "cozy-ui/transpiled/react/hooks/useSetFlagshipUi/helpers";
|
|
6
8
|
export var DOMStrings;
|
|
7
9
|
|
|
8
10
|
(function (DOMStrings) {
|
|
@@ -131,5 +133,5 @@ export var useDialogSetFlagshipUI = function useDialogSetFlagshipUI(open, onMoun
|
|
|
131
133
|
*/
|
|
132
134
|
}, [open, webviewIntent]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
133
135
|
};
|
|
134
|
-
export var useDialogEffects = isFlagshipApp() ? useHook : // eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
136
|
+
export var useDialogEffects = isFlagshipApp() || isRsg ? useHook : // eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
135
137
|
function () {};
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { useTheme } from '@material-ui/core';
|
|
4
4
|
import { isFlagshipApp } from 'cozy-device-helper';
|
|
5
5
|
import { useSetFlagshipUI } from "cozy-ui/transpiled/react/hooks/useSetFlagshipUi/useSetFlagshipUI";
|
|
6
|
+
import { isRsg } from "cozy-ui/transpiled/react/hooks/useSetFlagshipUi/helpers";
|
|
6
7
|
|
|
7
8
|
var getBottomBackground = function getBottomBackground(theme) {
|
|
8
9
|
var sidebar = document.getElementById('sidebar');
|
|
@@ -28,5 +29,5 @@ var useHook = function useHook() {
|
|
|
28
29
|
}, 'cozy-ui/ActionMenu');
|
|
29
30
|
};
|
|
30
31
|
|
|
31
|
-
export var useActionMenuEffects = isFlagshipApp() ? useHook : // eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
32
|
+
export var useActionMenuEffects = isFlagshipApp() || isRsg ? useHook : // eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
32
33
|
function () {};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
2
2
|
// TODO: remove eslint-disable and @ts-ignore rules
|
|
3
3
|
import { useTheme } from '@material-ui/core';
|
|
4
|
-
import {
|
|
4
|
+
import { isFlagshipApp } from 'cozy-device-helper';
|
|
5
5
|
import { useSetFlagshipUI } from "cozy-ui/transpiled/react/hooks/useSetFlagshipUi/useSetFlagshipUI";
|
|
6
|
+
import { getFlagshipMetadata } from "cozy-ui/transpiled/react/hooks/useSetFlagshipUi/helpers";
|
|
6
7
|
|
|
7
8
|
var getTopBackground = function getTopBackground(theme, cozyBar) {
|
|
8
9
|
return cozyBar && getComputedStyle(cozyBar).getPropertyValue('background-color') || theme.palette.background.paper;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function addFlagshipElements(): void;
|
|
2
|
+
export function removeFlagshipElements(): void;
|
|
3
|
+
/**
|
|
4
|
+
* Whether we are in cozy-ui documentation (Rsg is for ReactStyleGuide)
|
|
5
|
+
* @returns {boolean}
|
|
6
|
+
*/
|
|
7
|
+
export const isRsg: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Overrides flagship metadata
|
|
10
|
+
* See https://github.com/cozy/cozy-libs/blob/master/packages/cozy-device-helper/src/flagship.ts#L13
|
|
11
|
+
*/
|
|
12
|
+
export const getFlagshipMetadata: (() => {
|
|
13
|
+
immersive: boolean;
|
|
14
|
+
statusBarHeight: number;
|
|
15
|
+
navbarHeight: number;
|
|
16
|
+
}) | (() => import("cozy-device-helper/dist/flagship").FlagshipMetadata);
|
|
17
|
+
export function setRsgFlagshipElements({ topBackground, topOverlay, topTheme, bottomBackground, bottomOverlay, bottomTheme }?: undefined | Partial<FlagshipUI>): void;
|
|
18
|
+
import { FlagshipUI } from "./useSetFlagshipUI";
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// eslint-disable-next-line no-unused-vars
|
|
2
|
+
import { FlagshipUI } from "cozy-ui/transpiled/react/hooks/useSetFlagshipUi/useSetFlagshipUI";
|
|
3
|
+
import { getFlagshipMetadata as getFlagshipMetadataFromDeviceHelper } from 'cozy-device-helper';
|
|
4
|
+
/**
|
|
5
|
+
* The goal of this method is to simulate the immersive mode of the flagship app.
|
|
6
|
+
* So we add the flagship-app class to the body and we set css variables:
|
|
7
|
+
* If the "contained" mode is activated, it simulates an classic app behavior
|
|
8
|
+
* If the "immersive" mode is activated, it simulates a fullscreen app like Home
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export var addFlagshipElements = function addFlagshipElements() {
|
|
12
|
+
var root = document.getElementsByTagName('body')[0];
|
|
13
|
+
root.style.setProperty('--flagship-top-height', '40px');
|
|
14
|
+
root.style.setProperty('--flagship-top-bgcolor', 'white'); // used only for cozy-ui docs
|
|
15
|
+
|
|
16
|
+
root.style.setProperty('--flagship-top-overlay', 'transparent'); // used only for cozy-ui docs
|
|
17
|
+
|
|
18
|
+
root.style.setProperty('--flagship-top-color', 'black'); // used only for cozy-ui docs
|
|
19
|
+
|
|
20
|
+
root.style.setProperty('--flagship-bottom-height', '40px');
|
|
21
|
+
root.style.setProperty('--flagship-bottom-bgcolor', 'white'); // used only for cozy-ui docs
|
|
22
|
+
|
|
23
|
+
root.style.setProperty('--flagship-bottom-overlay', 'transparent'); // used only for cozy-ui docs
|
|
24
|
+
|
|
25
|
+
root.style.setProperty('--flagship-bottom-color', 'black'); // used only for cozy-ui docs
|
|
26
|
+
|
|
27
|
+
root.classList.add('flagship-app'); // create status bar
|
|
28
|
+
|
|
29
|
+
var statusBarDiv = document.createElement('div');
|
|
30
|
+
statusBarDiv.setAttribute('id', 'flagshipStatusBar');
|
|
31
|
+
statusBarDiv.style.cssText = 'position:fixed;top:0;height:var(--flagship-top-height);z-index:10000000;color:var(--flagship-top-color);background-color:var(--flagship-top-bgcolor);width:100%;display:flex;align-items:center;justify-content:center'; // create status bar overlay
|
|
32
|
+
|
|
33
|
+
var statusBarOverlay = document.createElement('div');
|
|
34
|
+
statusBarOverlay.setAttribute('id', 'flagshipStatusBarOverlay');
|
|
35
|
+
statusBarOverlay.style.cssText = 'position:absolute;top:0;left:0;width:100%;height:100%;z-index:-1;background-color:var(--flagship-top-overlay)';
|
|
36
|
+
statusBarDiv.appendChild(statusBarOverlay); // create status bar text
|
|
37
|
+
|
|
38
|
+
var statusBarText = document.createElement('div');
|
|
39
|
+
statusBarText.setAttribute('id', 'flagshipStatusBarText');
|
|
40
|
+
statusBarText.innerText = 'Flagship Top Status Bar with clock';
|
|
41
|
+
statusBarDiv.appendChild(statusBarText); // create nav bar
|
|
42
|
+
|
|
43
|
+
var navBarDiv = document.createElement('div');
|
|
44
|
+
navBarDiv.setAttribute('id', 'flagshipNavBar');
|
|
45
|
+
navBarDiv.style.cssText = 'position:fixed;bottom:0;height:var(--flagship-bottom-height);z-index:10000000;color:var(--flagship-bottom-color);background-color:var(--flagship-bottom-bgcolor);width:100%;display:flex;align-items:center;justify-content:center'; // create nav bar overlay
|
|
46
|
+
|
|
47
|
+
var navBarOverlay = document.createElement('div');
|
|
48
|
+
navBarOverlay.setAttribute('id', 'flagshipNavBarOverlay');
|
|
49
|
+
navBarOverlay.style.cssText = 'position:absolute;top:0;left:0;width:100%;height:100%;z-index:-1;background-color:var(--flagship-bottom-overlay)';
|
|
50
|
+
navBarDiv.appendChild(navBarOverlay); // create nav bar text
|
|
51
|
+
|
|
52
|
+
var navBarText = document.createElement('div');
|
|
53
|
+
navBarText.setAttribute('id', 'flagshipNavBarText');
|
|
54
|
+
navBarText.innerText = 'Flagship Nav Bar';
|
|
55
|
+
navBarDiv.appendChild(navBarText); // add status and nav bar and its content into the DOM
|
|
56
|
+
|
|
57
|
+
var currentDiv = document.getElementById('rsg-root');
|
|
58
|
+
document.body.insertBefore(statusBarDiv, currentDiv);
|
|
59
|
+
document.body.insertBefore(navBarDiv, currentDiv);
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Remove fake DOM element that simulates native Status and Nav bar
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
export var removeFlagshipElements = function removeFlagshipElements() {
|
|
66
|
+
var _document$getElementB, _document$getElementB2;
|
|
67
|
+
|
|
68
|
+
var root = document.getElementsByTagName('body')[0];
|
|
69
|
+
root.style.removeProperty('--flagship-top-height');
|
|
70
|
+
root.style.removeProperty('--flagship-top-bgcolor');
|
|
71
|
+
root.style.removeProperty('--flagship-top-overlay');
|
|
72
|
+
root.style.removeProperty('--flagship-top-color');
|
|
73
|
+
root.style.removeProperty('--flagship-bottom-height');
|
|
74
|
+
root.style.removeProperty('--flagship-bottom-bgcolor');
|
|
75
|
+
root.style.removeProperty('--flagship-bottom-overlay');
|
|
76
|
+
root.style.removeProperty('--flagship-bottom-color');
|
|
77
|
+
root.classList.remove('flagship-app');
|
|
78
|
+
(_document$getElementB = document.getElementById('flagshipStatusBar')) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.remove();
|
|
79
|
+
(_document$getElementB2 = document.getElementById('flagshipNavBar')) === null || _document$getElementB2 === void 0 ? void 0 : _document$getElementB2.remove();
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Whether we are in cozy-ui documentation (Rsg is for ReactStyleGuide)
|
|
83
|
+
* @returns {boolean}
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
export var isRsg = !!document.getElementById('rsg-root');
|
|
87
|
+
/**
|
|
88
|
+
* Overrides flagship metadata
|
|
89
|
+
* See https://github.com/cozy/cozy-libs/blob/master/packages/cozy-device-helper/src/flagship.ts#L13
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
export var getFlagshipMetadata = isRsg ? function () {
|
|
93
|
+
var _JSON$parse;
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
immersive: ((_JSON$parse = JSON.parse(localStorage.getItem('flagship-app'))) === null || _JSON$parse === void 0 ? void 0 : _JSON$parse.contained) === 'off' || false,
|
|
97
|
+
statusBarHeight: 40,
|
|
98
|
+
navbarHeight: 40
|
|
99
|
+
};
|
|
100
|
+
} : getFlagshipMetadataFromDeviceHelper;
|
|
101
|
+
/**
|
|
102
|
+
* Set the css values for Status and Nav bar inside cozy-ui documentation
|
|
103
|
+
* see https://github.com/cozy/cozy-libs/blob/master/packages/cozy-intent/src/api/models/applications.ts#L33
|
|
104
|
+
* @param {undefined | Partial<FlagshipUI>} param0
|
|
105
|
+
* @returns
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
export var setRsgFlagshipElements = function setRsgFlagshipElements() {
|
|
109
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
110
|
+
topBackground = _ref.topBackground,
|
|
111
|
+
topOverlay = _ref.topOverlay,
|
|
112
|
+
topTheme = _ref.topTheme,
|
|
113
|
+
bottomBackground = _ref.bottomBackground,
|
|
114
|
+
bottomOverlay = _ref.bottomOverlay,
|
|
115
|
+
bottomTheme = _ref.bottomTheme;
|
|
116
|
+
|
|
117
|
+
if (!isRsg) return;
|
|
118
|
+
var root = document.getElementsByTagName('body')[0];
|
|
119
|
+
|
|
120
|
+
if (topBackground) {
|
|
121
|
+
root.style.setProperty('--flagship-top-bgcolor', topBackground);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (topOverlay) {
|
|
125
|
+
root.style.setProperty('--flagship-top-overlay', topOverlay);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (topTheme) {
|
|
129
|
+
root.style.setProperty('--flagship-top-color', topTheme === 'dark' ? 'black' : 'white');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (bottomBackground) {
|
|
133
|
+
root.style.setProperty('--flagship-bottom-bgcolor', bottomBackground);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (bottomOverlay) {
|
|
137
|
+
root.style.setProperty('--flagship-bottom-overlay', bottomOverlay);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (bottomTheme) {
|
|
141
|
+
root.style.setProperty('--flagship-bottom-color', bottomTheme === 'dark' ? 'black' : 'white');
|
|
142
|
+
}
|
|
143
|
+
};
|
|
@@ -4,6 +4,7 @@ import identity from 'lodash/identity';
|
|
|
4
4
|
import isEmpty from 'lodash/isEmpty';
|
|
5
5
|
import isObject from 'lodash/isObject';
|
|
6
6
|
import { useWebviewIntent } from 'cozy-intent';
|
|
7
|
+
import { setRsgFlagshipElements } from "cozy-ui/transpiled/react/hooks/useSetFlagshipUi/helpers";
|
|
7
8
|
export var ThemeColor;
|
|
8
9
|
|
|
9
10
|
(function (ThemeColor) {
|
|
@@ -12,9 +13,10 @@ export var ThemeColor;
|
|
|
12
13
|
})(ThemeColor || (ThemeColor = {}));
|
|
13
14
|
|
|
14
15
|
export var parseArg = function parseArg(webviewIntent, arg, caller) {
|
|
15
|
-
|
|
16
|
-
var sanitized = isObject(arg) && pickBy(arg, identity);
|
|
16
|
+
var sanitized = isObject(arg) ? pickBy(arg, identity) : undefined;
|
|
17
17
|
var validUI = !isEmpty(sanitized) && sanitized;
|
|
18
|
+
setRsgFlagshipElements(sanitized);
|
|
19
|
+
if (!webviewIntent) return;
|
|
18
20
|
validUI && webviewIntent.call('setFlagshipUI', validUI, caller);
|
|
19
21
|
};
|
|
20
22
|
export var useSetFlagshipUI = function useSetFlagshipUI(onMount, onUnmount, caller) {
|