cozy-ui 73.3.0 → 74.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 +34 -0
- package/assets/icons/ui/help-outlined.svg +1 -0
- package/assets/icons/ui/refresh.svg +1 -0
- package/package.json +2 -2
- package/react/BottomSheet/BackdropOrFragment.jsx +0 -1
- package/react/BottomSheet/BottomSheet.jsx +221 -178
- package/react/BottomSheet/README.md +22 -2
- package/react/CozyDialogs/Readme.md +57 -8
- package/react/CozyTheme/index.jsx +2 -1
- package/react/Icon/Readme.md +5 -1
- package/react/Icon/icons-sprite.js +2 -2
- package/react/Icons/HelpOutlined.jsx +15 -0
- package/react/Icons/Refresh.jsx +15 -0
- package/react/__snapshots__/examples.spec.jsx.snap +138 -106
- package/transpiled/react/BottomSheet/BackdropOrFragment.js +0 -3
- package/transpiled/react/BottomSheet/BottomSheet.js +66 -24
- package/transpiled/react/CozyTheme/index.js +1 -1
- package/transpiled/react/Icon/icons-sprite.js +1 -1
- package/transpiled/react/Icons/HelpOutlined.js +14 -0
- package/transpiled/react/Icons/Refresh.js +14 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,37 @@
|
|
|
1
|
+
# [74.2.0](https://github.com/cozy/cozy-ui/compare/v74.1.0...v74.2.0) (2022-09-02)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **BottomSheet:** Adjust height when content changes ([1c0ad64](https://github.com/cozy/cozy-ui/commit/1c0ad64))
|
|
7
|
+
* **BottomSheet:** Force modal zindex value for BottomSheet ([a22405d](https://github.com/cozy/cozy-ui/commit/a22405d))
|
|
8
|
+
* **BottomSheet:** Remove container if no backdrop ([3830e52](https://github.com/cozy/cozy-ui/commit/3830e52))
|
|
9
|
+
* **BottomSheet:** Remove fragment prop if no portal ([cc49949](https://github.com/cozy/cozy-ui/commit/cc49949))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* **BottomSheet:** Upgrade mui-bottom-sheet to 1.0.9 ([59484ae](https://github.com/cozy/cozy-ui/commit/59484ae))
|
|
15
|
+
|
|
16
|
+
# [74.1.0](https://github.com/cozy/cozy-ui/compare/v74.0.0...v74.1.0) (2022-09-02)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
* Add help-outlined and refresh icons ([b33458c](https://github.com/cozy/cozy-ui/commit/b33458c))
|
|
22
|
+
|
|
23
|
+
# [74.0.0](https://github.com/cozy/cozy-ui/compare/v73.3.0...v74.0.0) (2022-09-01)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Features
|
|
27
|
+
|
|
28
|
+
* Wrap BottomSheet in Portal ([00156fe](https://github.com/cozy/cozy-ui/commit/00156fe))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### BREAKING CHANGES
|
|
32
|
+
|
|
33
|
+
* BottomSheet now use Portal by default to work as a modal, and so is attached to the body. If for some reasons you need to use the BottomSheet inside a specific place in the DOM, you can use `disablePortal` prop.
|
|
34
|
+
|
|
1
35
|
# [73.3.0](https://github.com/cozy/cozy-ui/compare/v73.2.3...v73.3.0) (2022-09-01)
|
|
2
36
|
|
|
3
37
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M9 8.802C10.122 8.355 11 7.21 11 6c0-1.552-1.448-3-3-3S5 4.448 5 6h2c0-.448.552-1 1-1 .448 0 1 .552 1 1 0 .448-.552 1-1 1a1 1 0 0 0-1 1v2h2V8.802ZM7 11v2h2v-2H7ZM1 8a7 7 0 1 0 14 0A7 7 0 0 0 1 8ZM0 8a8 8 0 1 0 16 0A8 8 0 0 0 0 8Z"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M8 0C3.589 0 0 3.589 0 8s3.589 8 8 8a8.039 8.039 0 0 0 7.229-4.571 1 1 0 1 0-1.806-.858A6.031 6.031 0 0 1 8 14c-3.309 0-6-2.691-6-6s2.691-6 6-6c1.482 0 2.866.571 3.938 1.507a.989.989 0 0 0-.706.353 1 1 0 0 0 .128 1.408l3 2.5A1 1 0 0 0 16 7V3a1 1 0 0 0-1-1 .987.987 0 0 0-.96.801C12.548 1.08 10.364 0 8 0Z"/></svg>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-ui",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "74.2.0",
|
|
4
4
|
"description": "Cozy apps UI SDK",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"bin": {
|
|
@@ -163,7 +163,7 @@
|
|
|
163
163
|
"hammerjs": "^2.0.8",
|
|
164
164
|
"intersection-observer": "0.11.0",
|
|
165
165
|
"mime-types": "2.1.35",
|
|
166
|
-
"mui-bottom-sheet": "https://github.com/cozy/mui-bottom-sheet.git#v1.0.
|
|
166
|
+
"mui-bottom-sheet": "https://github.com/cozy/mui-bottom-sheet.git#v1.0.9",
|
|
167
167
|
"node-polyglot": "^2.2.2",
|
|
168
168
|
"normalize.css": "^8.0.0",
|
|
169
169
|
"piwik-react-router": "0.12.1",
|
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
useState,
|
|
3
|
+
useEffect,
|
|
4
|
+
useRef,
|
|
5
|
+
useCallback,
|
|
6
|
+
forwardRef,
|
|
7
|
+
memo,
|
|
8
|
+
Fragment
|
|
9
|
+
} from 'react'
|
|
2
10
|
import PropTypes from 'prop-types'
|
|
3
11
|
import { BottomSheet as MuiBottomSheet } from 'mui-bottom-sheet'
|
|
4
12
|
import { useTimeoutWhen } from 'rooks'
|
|
5
13
|
import Fade from '@material-ui/core/Fade'
|
|
14
|
+
import Portal from '@material-ui/core/Portal'
|
|
6
15
|
|
|
7
16
|
import { getFlagshipMetadata } from 'cozy-device-helper'
|
|
8
17
|
|
|
18
|
+
import CozyTheme, { useCozyTheme } from '../CozyTheme'
|
|
9
19
|
import Stack from '../Stack'
|
|
10
20
|
import Paper from '../Paper'
|
|
11
21
|
import BackdropOrFragment from './BackdropOrFragment'
|
|
@@ -20,15 +30,33 @@ import {
|
|
|
20
30
|
} from './helpers'
|
|
21
31
|
import { ANIMATION_DURATION } from './constants'
|
|
22
32
|
|
|
33
|
+
const createContainerWrapperStyles = () => ({
|
|
34
|
+
container: {
|
|
35
|
+
position: 'fixed',
|
|
36
|
+
zIndex: 'var(--zIndex-modal)',
|
|
37
|
+
inset: 0
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const ContainerWrapper = ({ showBackdrop, children }) => {
|
|
42
|
+
const styles = createContainerWrapperStyles()
|
|
43
|
+
|
|
44
|
+
if (showBackdrop) {
|
|
45
|
+
return <div style={styles.container}>{children}</div>
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return children
|
|
49
|
+
}
|
|
50
|
+
|
|
23
51
|
const createStyles = ({ squared, hasToolbarProps }) => ({
|
|
24
52
|
root: {
|
|
25
53
|
borderTopLeftRadius: '1rem',
|
|
26
54
|
borderTopRightRadius: '1rem',
|
|
27
55
|
transition: 'border-radius 0.5s',
|
|
28
|
-
zIndex: 'var(--zIndex-drawer)',
|
|
29
56
|
boxShadow:
|
|
30
57
|
'0 -0.5px 0px 0 rgba(0, 0, 0, 0.10), 0 -2px 2px 0 rgba(0, 0, 0, 0.02), 0 -4px 4px 0 rgba(0, 0, 0, 0.02), 0 -8px 8px 0 rgba(0, 0, 0, 0.02), 0 -16px 16px 0 rgba(0, 0, 0, 0.02)',
|
|
31
58
|
backgroundColor: 'var(--paperBackgroundColor)',
|
|
59
|
+
zIndex: 'var(--zIndex-modal)',
|
|
32
60
|
...(squared && {
|
|
33
61
|
borderTopLeftRadius: 0,
|
|
34
62
|
borderTopRightRadius: 0,
|
|
@@ -52,8 +80,7 @@ const createStyles = ({ squared, hasToolbarProps }) => ({
|
|
|
52
80
|
position: 'fixed',
|
|
53
81
|
bottom: 0,
|
|
54
82
|
left: 0,
|
|
55
|
-
backgroundColor: 'var(--paperBackgroundColor)'
|
|
56
|
-
zIndex: 'var(--zIndex-overlay)'
|
|
83
|
+
backgroundColor: 'var(--paperBackgroundColor)'
|
|
57
84
|
},
|
|
58
85
|
flagshipImmersive: {
|
|
59
86
|
backgroundColor: 'var(--paperBackgroundColor)',
|
|
@@ -77,194 +104,192 @@ const defaultSettings = {
|
|
|
77
104
|
mediumHeight: null
|
|
78
105
|
}
|
|
79
106
|
|
|
80
|
-
const BottomSheet = (
|
|
81
|
-
toolbarProps,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
children
|
|
87
|
-
}) => {
|
|
88
|
-
const { mediumHeightRatio, mediumHeight } = {
|
|
89
|
-
...defaultSettings,
|
|
90
|
-
...settings
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const innerContentRef = useRef()
|
|
94
|
-
const headerRef = useRef()
|
|
95
|
-
const headerContentRef = useRef()
|
|
96
|
-
const [isTopPosition, setIsTopPosition] = useState(false)
|
|
97
|
-
const [isBottomPosition, setIsBottomPosition] = useState(false)
|
|
98
|
-
const [isHidden, setIsHidden] = useState(false)
|
|
99
|
-
const [showBackdrop, setShowBackdrop] = useState(backdrop)
|
|
100
|
-
const [peekHeights, setPeekHeights] = useState(null)
|
|
101
|
-
const [currentIndex, setCurrentIndex] = useState()
|
|
102
|
-
const [bottomSpacerHeight, setBottomSpacerHeight] = useState(0)
|
|
103
|
-
const [initPos, setInitPos] = useState(0)
|
|
107
|
+
const BottomSheet = memo(
|
|
108
|
+
({ toolbarProps, settings, backdrop, skipAnimation, onClose, children }) => {
|
|
109
|
+
const { mediumHeightRatio, mediumHeight } = {
|
|
110
|
+
...defaultSettings,
|
|
111
|
+
...settings
|
|
112
|
+
}
|
|
104
113
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
114
|
+
const innerContentRef = useRef()
|
|
115
|
+
const headerRef = useRef()
|
|
116
|
+
const headerContentRef = useRef()
|
|
117
|
+
const [isTopPosition, setIsTopPosition] = useState(false)
|
|
118
|
+
const [isBottomPosition, setIsBottomPosition] = useState(false)
|
|
119
|
+
const [isHidden, setIsHidden] = useState(false)
|
|
120
|
+
const [showBackdrop, setShowBackdrop] = useState(backdrop)
|
|
121
|
+
const [peekHeights, setPeekHeights] = useState(null)
|
|
122
|
+
const [currentIndex, setCurrentIndex] = useState()
|
|
123
|
+
const [bottomSpacerHeight, setBottomSpacerHeight] = useState(0)
|
|
124
|
+
const [initPos, setInitPos] = useState(0)
|
|
110
125
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
126
|
+
const squared = backdrop
|
|
127
|
+
? isTopPosition && bottomSpacerHeight <= 0
|
|
128
|
+
: isTopPosition
|
|
129
|
+
const hasToolbarProps = !!Object.keys(toolbarProps).length
|
|
130
|
+
const isClosable = !!onClose || backdrop
|
|
116
131
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
)
|
|
121
|
-
|
|
132
|
+
const styles = createStyles({
|
|
133
|
+
squared,
|
|
134
|
+
hasToolbarProps
|
|
135
|
+
})
|
|
136
|
+
const overriddenChildren = makeOverridenChildren(children, headerContentRef)
|
|
122
137
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
138
|
+
if (backdrop && !onClose) {
|
|
139
|
+
throw new Error(
|
|
140
|
+
'BottomSheet must have `onClose` method to work properly when setting `backdrop` to `true`'
|
|
141
|
+
)
|
|
142
|
+
}
|
|
128
143
|
|
|
129
|
-
|
|
130
|
-
|
|
144
|
+
const handleClose = useCallback(() => {
|
|
145
|
+
setShowBackdrop(false)
|
|
146
|
+
setIsHidden(true)
|
|
147
|
+
onClose && onClose()
|
|
148
|
+
}, [onClose])
|
|
131
149
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
snapIndex,
|
|
135
|
-
maxHeightSnapIndex,
|
|
136
|
-
isTopPosition,
|
|
137
|
-
setIsTopPosition
|
|
138
|
-
})
|
|
139
|
-
setBottomPosition({ snapIndex, isBottomPosition, setIsBottomPosition })
|
|
140
|
-
}
|
|
150
|
+
const handleOnIndexChange = snapIndex => {
|
|
151
|
+
const maxHeightSnapIndex = peekHeights.length - 1
|
|
141
152
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
153
|
+
setCurrentIndex(snapIndex)
|
|
154
|
+
setTopPosition({
|
|
155
|
+
snapIndex,
|
|
156
|
+
maxHeightSnapIndex,
|
|
157
|
+
isTopPosition,
|
|
158
|
+
setIsTopPosition
|
|
159
|
+
})
|
|
160
|
+
setBottomPosition({ snapIndex, isBottomPosition, setIsBottomPosition })
|
|
148
161
|
}
|
|
149
|
-
}, [])
|
|
150
162
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
() =>
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
163
|
+
// hack to prevent pull-down-to-refresh behavior when dragging down the bottom sheet.
|
|
164
|
+
// Needed for iOS Safari
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
document.body.style.overflow = 'hidden'
|
|
167
|
+
return () => {
|
|
168
|
+
document.body.style.overflow = 'auto'
|
|
169
|
+
}
|
|
170
|
+
}, [])
|
|
158
171
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
? parseFloat(
|
|
166
|
-
getComputedStyle(headerContent).getPropertyValue('padding-bottom')
|
|
167
|
-
)
|
|
168
|
-
: 0
|
|
172
|
+
// close the bottom sheet by swaping it below the minimum height
|
|
173
|
+
useTimeoutWhen(
|
|
174
|
+
() => handleClose(),
|
|
175
|
+
ANIMATION_DURATION,
|
|
176
|
+
isClosable && isBottomPosition
|
|
177
|
+
)
|
|
169
178
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
179
|
+
useEffect(() => {
|
|
180
|
+
const headerContent = headerContentRef.current
|
|
181
|
+
const innerContentHeight = innerContentRef.current.offsetHeight
|
|
182
|
+
const actionButtonsHeight = headerContent
|
|
183
|
+
? parseFloat(getComputedStyle(headerContent).getPropertyValue('height'))
|
|
184
|
+
: 0
|
|
185
|
+
const actionButtonsBottomMargin = headerContent
|
|
186
|
+
? parseFloat(
|
|
187
|
+
getComputedStyle(headerContent).getPropertyValue('padding-bottom')
|
|
188
|
+
)
|
|
189
|
+
: 0
|
|
190
|
+
|
|
191
|
+
const maxHeight = computeMaxHeight(toolbarProps)
|
|
192
|
+
const computedMediumHeight = computeMediumHeight({
|
|
193
|
+
backdrop,
|
|
194
|
+
maxHeight,
|
|
195
|
+
mediumHeight,
|
|
196
|
+
mediumHeightRatio,
|
|
197
|
+
innerContentHeight
|
|
198
|
+
})
|
|
199
|
+
const minHeight = computeMinHeight({
|
|
200
|
+
isClosable,
|
|
201
|
+
headerRef,
|
|
202
|
+
actionButtonsHeight,
|
|
203
|
+
actionButtonsBottomMargin
|
|
204
|
+
})
|
|
205
|
+
const bottomSpacerHeight = maxHeight - innerContentHeight
|
|
206
|
+
|
|
207
|
+
if (computedMediumHeight >= maxHeight) {
|
|
208
|
+
setIsTopPosition(true)
|
|
209
|
+
}
|
|
210
|
+
setPeekHeights([...new Set([minHeight, computedMediumHeight, maxHeight])])
|
|
211
|
+
setInitPos(computedMediumHeight)
|
|
212
|
+
// Used so that the BottomSheet can be opened to the top without stopping at the content height
|
|
213
|
+
setBottomSpacerHeight(bottomSpacerHeight)
|
|
214
|
+
}, [
|
|
215
|
+
innerContentRef,
|
|
216
|
+
toolbarProps,
|
|
175
217
|
mediumHeightRatio,
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
218
|
+
mediumHeight,
|
|
219
|
+
showBackdrop,
|
|
220
|
+
backdrop,
|
|
179
221
|
isClosable,
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
actionButtonsBottomMargin
|
|
183
|
-
})
|
|
184
|
-
const bottomSpacerHeight = maxHeight - innerContentHeight
|
|
222
|
+
children // to recompute data if content changes
|
|
223
|
+
])
|
|
185
224
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
225
|
+
return (
|
|
226
|
+
<ContainerWrapper showBackdrop={showBackdrop}>
|
|
227
|
+
{getFlagshipMetadata().immersive && (
|
|
228
|
+
<span style={styles.flagshipImmersive} />
|
|
229
|
+
)}
|
|
230
|
+
<BackdropOrFragment
|
|
231
|
+
showBackdrop={showBackdrop}
|
|
232
|
+
onClick={() =>
|
|
233
|
+
minimizeAndClose({
|
|
234
|
+
backdrop,
|
|
235
|
+
setCurrentIndex,
|
|
236
|
+
setIsTopPosition,
|
|
237
|
+
setIsBottomPosition,
|
|
238
|
+
handleClose
|
|
239
|
+
})
|
|
240
|
+
}
|
|
241
|
+
/>
|
|
242
|
+
<MuiBottomSheet
|
|
243
|
+
peekHeights={peekHeights}
|
|
244
|
+
defaultHeight={initPos}
|
|
245
|
+
backdrop={false}
|
|
246
|
+
fullHeight={hasToolbarProps ? false : true}
|
|
247
|
+
currentIndex={currentIndex}
|
|
248
|
+
onIndexChange={handleOnIndexChange}
|
|
249
|
+
styles={{ root: styles.root }}
|
|
250
|
+
threshold={0}
|
|
251
|
+
// springConfig doc : https://docs.pmnd.rs/react-spring/common/configs
|
|
252
|
+
springConfig={{
|
|
253
|
+
tension: defaultBottomSheetSpringConfig.tension,
|
|
254
|
+
friction: defaultBottomSheetSpringConfig.friction,
|
|
255
|
+
clamp: defaultBottomSheetSpringConfig.clamp
|
|
256
|
+
}}
|
|
257
|
+
disabledClosing={!onClose}
|
|
258
|
+
hidden={isHidden}
|
|
259
|
+
snapPointSeekerMode="next"
|
|
260
|
+
skipAnimation={skipAnimation}
|
|
261
|
+
>
|
|
262
|
+
<div ref={innerContentRef}>
|
|
263
|
+
<Paper
|
|
264
|
+
data-testid="bottomSheet-header"
|
|
265
|
+
className="u-w-100 u-h-2-half u-pos-relative u-flex u-flex-items-center u-flex-justify-center"
|
|
266
|
+
ref={headerRef}
|
|
267
|
+
elevation={0}
|
|
268
|
+
square
|
|
269
|
+
>
|
|
270
|
+
<div style={styles.indicator} />
|
|
271
|
+
</Paper>
|
|
272
|
+
<Stack
|
|
273
|
+
style={styles.stack}
|
|
274
|
+
className="u-flex u-flex-column u-ov-hidden"
|
|
275
|
+
spacing="s"
|
|
276
|
+
>
|
|
277
|
+
{overriddenChildren}
|
|
278
|
+
</Stack>
|
|
279
|
+
</div>
|
|
280
|
+
<div style={{ height: backdrop ? 0 : bottomSpacerHeight }} />
|
|
281
|
+
</MuiBottomSheet>
|
|
282
|
+
{!isBottomPosition && (
|
|
283
|
+
<Fade in timeout={ANIMATION_DURATION}>
|
|
284
|
+
<div style={styles.bounceSafer} />
|
|
285
|
+
</Fade>
|
|
286
|
+
)}
|
|
287
|
+
</ContainerWrapper>
|
|
288
|
+
)
|
|
289
|
+
}
|
|
290
|
+
)
|
|
202
291
|
|
|
203
|
-
|
|
204
|
-
<>
|
|
205
|
-
{getFlagshipMetadata().immersive && (
|
|
206
|
-
<span style={styles.flagshipImmersive} />
|
|
207
|
-
)}
|
|
208
|
-
<BackdropOrFragment
|
|
209
|
-
showBackdrop={showBackdrop}
|
|
210
|
-
onClick={() =>
|
|
211
|
-
minimizeAndClose({
|
|
212
|
-
backdrop,
|
|
213
|
-
setCurrentIndex,
|
|
214
|
-
setIsTopPosition,
|
|
215
|
-
setIsBottomPosition,
|
|
216
|
-
handleClose
|
|
217
|
-
})
|
|
218
|
-
}
|
|
219
|
-
/>
|
|
220
|
-
<MuiBottomSheet
|
|
221
|
-
peekHeights={peekHeights}
|
|
222
|
-
defaultHeight={initPos}
|
|
223
|
-
backdrop={false}
|
|
224
|
-
fullHeight={hasToolbarProps ? false : true}
|
|
225
|
-
currentIndex={currentIndex}
|
|
226
|
-
onIndexChange={handleOnIndexChange}
|
|
227
|
-
styles={{ root: styles.root }}
|
|
228
|
-
threshold={0}
|
|
229
|
-
// springConfig doc : https://docs.pmnd.rs/react-spring/common/configs
|
|
230
|
-
springConfig={{
|
|
231
|
-
tension: defaultBottomSheetSpringConfig.tension,
|
|
232
|
-
friction: defaultBottomSheetSpringConfig.friction,
|
|
233
|
-
clamp: defaultBottomSheetSpringConfig.clamp
|
|
234
|
-
}}
|
|
235
|
-
disabledClosing={!onClose}
|
|
236
|
-
hidden={isHidden}
|
|
237
|
-
snapPointSeekerMode="next"
|
|
238
|
-
skipAnimation={skipAnimation}
|
|
239
|
-
>
|
|
240
|
-
<div ref={innerContentRef}>
|
|
241
|
-
<Paper
|
|
242
|
-
data-testid="bottomSheet-header"
|
|
243
|
-
className="u-w-100 u-h-2-half u-pos-relative u-flex u-flex-items-center u-flex-justify-center"
|
|
244
|
-
ref={headerRef}
|
|
245
|
-
elevation={0}
|
|
246
|
-
square
|
|
247
|
-
>
|
|
248
|
-
<div style={styles.indicator} />
|
|
249
|
-
</Paper>
|
|
250
|
-
<Stack
|
|
251
|
-
style={styles.stack}
|
|
252
|
-
className="u-flex u-flex-column u-ov-hidden"
|
|
253
|
-
spacing="s"
|
|
254
|
-
>
|
|
255
|
-
{overriddenChildren}
|
|
256
|
-
</Stack>
|
|
257
|
-
</div>
|
|
258
|
-
<div style={{ height: backdrop ? 0 : bottomSpacerHeight }} />
|
|
259
|
-
</MuiBottomSheet>
|
|
260
|
-
{!isBottomPosition && (
|
|
261
|
-
<Fade in timeout={ANIMATION_DURATION}>
|
|
262
|
-
<div style={styles.bounceSafer} />
|
|
263
|
-
</Fade>
|
|
264
|
-
)}
|
|
265
|
-
</>
|
|
266
|
-
)
|
|
267
|
-
}
|
|
292
|
+
BottomSheet.displayName = 'BottomSheet'
|
|
268
293
|
|
|
269
294
|
BottomSheet.defaultProps = {
|
|
270
295
|
classes: {},
|
|
@@ -295,4 +320,22 @@ BottomSheet.propTypes = {
|
|
|
295
320
|
onClose: PropTypes.func
|
|
296
321
|
}
|
|
297
322
|
|
|
298
|
-
|
|
323
|
+
const BottomSheetPortal = forwardRef(({ portalProps, ...props }, ref) => {
|
|
324
|
+
const cozyTheme = useCozyTheme()
|
|
325
|
+
const CozyThemeWrapper = portalProps?.disablePortal ? Fragment : CozyTheme
|
|
326
|
+
const wrapperProps = portalProps?.disablePortal
|
|
327
|
+
? undefined
|
|
328
|
+
: { variant: cozyTheme }
|
|
329
|
+
|
|
330
|
+
return (
|
|
331
|
+
<Portal {...portalProps}>
|
|
332
|
+
<CozyThemeWrapper {...wrapperProps}>
|
|
333
|
+
<BottomSheet ref={ref} {...props} />
|
|
334
|
+
</CozyThemeWrapper>
|
|
335
|
+
</Portal>
|
|
336
|
+
)
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
BottomSheetPortal.displayName = 'BottomSheetPortal'
|
|
340
|
+
|
|
341
|
+
export default BottomSheetPortal
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
Display content coming up from the bottom of the screen. The pane can be swiped to the top of the screen. Based on cozy
|
|
2
|
-
/ mui-bottom-sheet: [API documentation is here](https://github.com/cozy/mui-bottom-sheet#props-options).
|
|
2
|
+
/ mui-bottom-sheet: [API documentation is here](https://github.com/cozy/mui-bottom-sheet#props-options). It uses `Portal` to have the same behavior as `Dialogs` / `Modals` (can be disabled with the `disablePortal` prop).
|
|
3
3
|
|
|
4
4
|
### Props
|
|
5
5
|
|
|
6
|
+
* **portalProps** : `<object>` – Portal properties
|
|
7
|
+
* **container** : `<HTMLElement> | <function> | <React.Component>` – Portal container
|
|
8
|
+
* **disablePortal** : `<boolean>` – Disable the portal behavior
|
|
6
9
|
* **toolbarProps** : `<object>` – Toolbar properties
|
|
7
10
|
* **ref** : `<object>` – React reference of the toolbar node
|
|
8
11
|
* **height** : `<number>` – Toolbar height value
|
|
@@ -48,11 +51,14 @@ const initialVariants = [{
|
|
|
48
51
|
}]
|
|
49
52
|
const initialState = {
|
|
50
53
|
isBottomSheetDisplayed: isTesting(),
|
|
54
|
+
isSecondBottomSheetDisplayed: false,
|
|
51
55
|
mediumHeight: isTesting() ? 450 : undefined,
|
|
52
56
|
mediumHeightRatio: undefined
|
|
53
57
|
}
|
|
54
58
|
const showBottomSheet = () => setState({ isBottomSheetDisplayed: true })
|
|
55
59
|
const hideBottomSheet = () => setState({ isBottomSheetDisplayed: false })
|
|
60
|
+
const showSecondBottomSheet = () => setState({ isSecondBottomSheetDisplayed: true })
|
|
61
|
+
const hideSecondBottomSheet = () => setState({ isSecondBottomSheetDisplayed: false })
|
|
56
62
|
|
|
57
63
|
const handleChangeMediumHeight = el => {
|
|
58
64
|
setState({ mediumHeight: Number(el.target.value) })
|
|
@@ -109,8 +115,22 @@ const settings = state.mediumHeight === undefined && state.mediumHeightRatio ===
|
|
|
109
115
|
>
|
|
110
116
|
{variant.withHeader && (
|
|
111
117
|
<BottomSheetHeader className="u-ph-1 u-pb-1">
|
|
112
|
-
<Button
|
|
118
|
+
<Button
|
|
119
|
+
className="u-mr-half"
|
|
120
|
+
variant="secondary"
|
|
121
|
+
label="Open BottomSheet"
|
|
122
|
+
fullWidth
|
|
123
|
+
onClick={showSecondBottomSheet}
|
|
124
|
+
/>
|
|
113
125
|
<Button variant="secondary" label="Button 2" fullWidth />
|
|
126
|
+
|
|
127
|
+
{state.isSecondBottomSheetDisplayed && (
|
|
128
|
+
<BottomSheet backdrop onClose={hideSecondBottomSheet}>
|
|
129
|
+
<BottomSheetItem>
|
|
130
|
+
{content.ada.short}
|
|
131
|
+
</BottomSheetItem>
|
|
132
|
+
</BottomSheet>
|
|
133
|
+
)}
|
|
114
134
|
</BottomSheetHeader>
|
|
115
135
|
)}
|
|
116
136
|
{!variant.withListContent && (
|
|
@@ -56,6 +56,8 @@ import RadioGroup from 'cozy-ui/transpiled/react/RadioGroup'
|
|
|
56
56
|
import Radio from 'cozy-ui/transpiled/react/Radios'
|
|
57
57
|
import FormControl from 'cozy-ui/transpiled/react/FormControl'
|
|
58
58
|
import FormLabel from 'cozy-ui/transpiled/react/FormLabel'
|
|
59
|
+
import BottomSheet, { BottomSheetItem } from 'cozy-ui/transpiled/react/BottomSheet'
|
|
60
|
+
import Stack from 'cozy-ui/transpiled/react/Stack'
|
|
59
61
|
|
|
60
62
|
import CloudIcon from "cozy-ui/transpiled/react/Icons/Cloud"
|
|
61
63
|
|
|
@@ -64,6 +66,12 @@ const handleBack = () => {
|
|
|
64
66
|
Alerter.success('Back button has been pressed', { duration: 5000 })
|
|
65
67
|
setState({ modalOpened: !state.modalOpened })
|
|
66
68
|
}
|
|
69
|
+
const hideBottomSheet = () => setState({ bottomSheetOpened: false })
|
|
70
|
+
const showBottomSheet = () => setState({ bottomSheetOpened: true })
|
|
71
|
+
const hideSecondConfirmDialog = () => setState({ secondConfirmDialogOpened: false })
|
|
72
|
+
const showSecondConfirmDialog = () => setState({ secondConfirmDialogOpened: true })
|
|
73
|
+
const hideBSConfirmDialog = () => setState({ BSConfirmDialogOpened: false })
|
|
74
|
+
const showBSConfirmDialog = () => setState({ BSConfirmDialogOpened: true })
|
|
67
75
|
|
|
68
76
|
const DialogComponent = state.modal
|
|
69
77
|
|
|
@@ -152,6 +160,9 @@ const toggleDialog = dialog => {
|
|
|
152
160
|
|
|
153
161
|
initialState = {
|
|
154
162
|
modalOpened: isTesting(),
|
|
163
|
+
bottomSheetOpened: false,
|
|
164
|
+
secondConfirmDialogOpened: false,
|
|
165
|
+
BSConfirmDialogOpened: false,
|
|
155
166
|
modal: Dialog,
|
|
156
167
|
size: 'medium',
|
|
157
168
|
content: 'default',
|
|
@@ -257,14 +268,52 @@ const initialVariants = [{
|
|
|
257
268
|
}
|
|
258
269
|
disableGutters={variant.disableGutters}
|
|
259
270
|
content={
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
271
|
+
<>
|
|
272
|
+
<Typography component="div" variant="body1">
|
|
273
|
+
{ state.content == 'default'
|
|
274
|
+
? dialogContents[DialogComponent.name]
|
|
275
|
+
: state.content == 'long'
|
|
276
|
+
? content.ada.long
|
|
277
|
+
: content.ada.short
|
|
278
|
+
}
|
|
279
|
+
<Stack className="u-mt-1" spacing="s">
|
|
280
|
+
<div>
|
|
281
|
+
<Button label="Show an alert" onClick={() => Alerter.success('Hello', { duration: 100000 })}/>
|
|
282
|
+
</div>
|
|
283
|
+
<div>
|
|
284
|
+
<Button label="Show inner bottom sheet" onClick={showBottomSheet}/>
|
|
285
|
+
</div>
|
|
286
|
+
<div>
|
|
287
|
+
<Button label="Show inner confirm dialog" onClick={showSecondConfirmDialog}/>
|
|
288
|
+
</div>
|
|
289
|
+
</Stack>
|
|
290
|
+
</Typography>
|
|
291
|
+
|
|
292
|
+
{state.secondConfirmDialogOpened && (
|
|
293
|
+
<ConfirmDialog open onClose={hideSecondConfirmDialog}
|
|
294
|
+
title="This is a simple title"
|
|
295
|
+
content="This is a simple content"
|
|
296
|
+
/>
|
|
297
|
+
)}
|
|
298
|
+
|
|
299
|
+
{state.bottomSheetOpened && (
|
|
300
|
+
<BottomSheet backdrop onClose={hideBottomSheet}>
|
|
301
|
+
<BottomSheetItem>
|
|
302
|
+
<div className="u-mb-1">
|
|
303
|
+
<Button label="Show inner confirm dialog" onClick={showBSConfirmDialog}/>
|
|
304
|
+
</div>
|
|
305
|
+
{content.ada.long}
|
|
306
|
+
{state.BSConfirmDialogOpened && (
|
|
307
|
+
<ConfirmDialog open onClose={hideBSConfirmDialog}
|
|
308
|
+
title="This is a simple title"
|
|
309
|
+
content="This is a simple content"
|
|
310
|
+
/>
|
|
311
|
+
)}
|
|
312
|
+
</BottomSheetItem>
|
|
313
|
+
</BottomSheet>
|
|
314
|
+
)}
|
|
315
|
+
</>
|
|
316
|
+
}
|
|
268
317
|
actions={variant.showActions && dialogActions[DialogComponent.name]}
|
|
269
318
|
actionsLayout={variant.actionsLayoutColumn ? 'column' : 'row'}
|
|
270
319
|
/>
|