cozy-ui 60.10.1 → 60.11.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
|
+
# [60.11.0](https://github.com/cozy/cozy-ui/compare/v60.10.1...v60.11.0) (2022-02-02)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* BottomSheet settings accept `mediumHeight` new prop ([0e2b254](https://github.com/cozy/cozy-ui/commit/0e2b254))
|
|
7
|
+
|
|
1
8
|
## [60.10.1](https://github.com/cozy/cozy-ui/compare/v60.10.0...v60.10.1) (2022-02-02)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -37,7 +37,8 @@ export const defaultBottomSheetSpringConfig = {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
const defaultSettings = {
|
|
40
|
-
mediumHeightRatio: 0.33
|
|
40
|
+
mediumHeightRatio: 0.33,
|
|
41
|
+
mediumHeight: null
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
const computeMaxHeight = toolbarProps => {
|
|
@@ -54,17 +55,22 @@ const computeMaxHeight = toolbarProps => {
|
|
|
54
55
|
}
|
|
55
56
|
|
|
56
57
|
const BottomSheet = ({ toolbarProps, settings, children }) => {
|
|
58
|
+
const { mediumHeightRatio, mediumHeight } = useMemo(
|
|
59
|
+
() => ({
|
|
60
|
+
...defaultSettings,
|
|
61
|
+
...settings
|
|
62
|
+
}),
|
|
63
|
+
[settings]
|
|
64
|
+
)
|
|
65
|
+
|
|
57
66
|
const innerContentRef = useRef()
|
|
58
67
|
const headerRef = useRef()
|
|
59
68
|
const headerContentRef = useRef()
|
|
60
69
|
const [isTopPosition, setIsTopPosition] = useState(false)
|
|
61
70
|
const [peekHeights, setPeekHeights] = useState(null)
|
|
62
|
-
const [initPos, setInitPos] = useState(null)
|
|
63
71
|
const [bottomSpacerHeight, setBottomSpacerHeight] = useState(0)
|
|
72
|
+
const [initPos, setInitPos] = useState(mediumHeight)
|
|
64
73
|
|
|
65
|
-
const { mediumHeightRatio } = useMemo(() => settings || defaultSettings, [
|
|
66
|
-
settings
|
|
67
|
-
])
|
|
68
74
|
const styles = useMemo(() => makeStyles({ isTopPosition }), [isTopPosition])
|
|
69
75
|
|
|
70
76
|
// hack to prevent pull-down-to-refresh behavior when dragging down the bottom sheet.
|
|
@@ -79,7 +85,8 @@ const BottomSheet = ({ toolbarProps, settings, children }) => {
|
|
|
79
85
|
useEffect(() => {
|
|
80
86
|
const headerContent = headerContentRef.current
|
|
81
87
|
const maxHeight = computeMaxHeight(toolbarProps)
|
|
82
|
-
const
|
|
88
|
+
const computedMediumHeight =
|
|
89
|
+
mediumHeight || Math.round(maxHeight * mediumHeightRatio)
|
|
83
90
|
|
|
84
91
|
const actionButtonsHeight = headerContent
|
|
85
92
|
? parseFloat(getComputedStyle(headerContent).getPropertyValue('height'))
|
|
@@ -98,14 +105,15 @@ const BottomSheet = ({ toolbarProps, settings, children }) => {
|
|
|
98
105
|
// without stopping at the content height
|
|
99
106
|
const bottomSpacerHeight = maxHeight - innerContentRef.current.offsetHeight
|
|
100
107
|
|
|
101
|
-
setPeekHeights([minHeight,
|
|
102
|
-
setInitPos(
|
|
108
|
+
setPeekHeights([minHeight, computedMediumHeight, maxHeight])
|
|
109
|
+
setInitPos(computedMediumHeight)
|
|
103
110
|
setBottomSpacerHeight(bottomSpacerHeight)
|
|
104
111
|
}, [
|
|
105
112
|
innerContentRef,
|
|
106
113
|
headerContentRef.current,
|
|
107
114
|
toolbarProps,
|
|
108
|
-
mediumHeightRatio
|
|
115
|
+
mediumHeightRatio,
|
|
116
|
+
mediumHeight
|
|
109
117
|
])
|
|
110
118
|
|
|
111
119
|
const handleOnIndexChange = snapIndex => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Displays content coming up from the bottom of the screen. The pane can be swiped to the top of the screen.
|
|
1
|
+
Displays content coming up from the bottom of the screen. The pane can be swiped to the top of the screen. [API documentation is here](https://github.com/cozy/mui-bottom-sheet#props-options)
|
|
2
2
|
|
|
3
3
|
```jsx
|
|
4
4
|
import BottomSheet, { BottomSheetItem, BottomSheetHeader } from 'cozy-ui/transpiled/react/BottomSheet'
|
|
@@ -8,7 +8,7 @@ import Button from 'cozy-ui/transpiled/react/Buttons'
|
|
|
8
8
|
initialState = { isBottomSheetDisplayed: isTesting() }
|
|
9
9
|
const showBottomSheet = () => setState({ isBottomSheetDisplayed: true })
|
|
10
10
|
|
|
11
|
-
const settings =
|
|
11
|
+
const settings = isTesting() ? { mediumHeight: 450 } : undefined
|
|
12
12
|
// -->
|
|
13
13
|
|
|
14
14
|
;
|
|
@@ -39,7 +39,8 @@ export var defaultBottomSheetSpringConfig = {
|
|
|
39
39
|
clamp: true
|
|
40
40
|
};
|
|
41
41
|
var defaultSettings = {
|
|
42
|
-
mediumHeightRatio: 0.33
|
|
42
|
+
mediumHeightRatio: 0.33,
|
|
43
|
+
mediumHeight: null
|
|
43
44
|
};
|
|
44
45
|
|
|
45
46
|
var computeMaxHeight = function computeMaxHeight(toolbarProps) {
|
|
@@ -60,6 +61,13 @@ var BottomSheet = function BottomSheet(_ref2) {
|
|
|
60
61
|
var toolbarProps = _ref2.toolbarProps,
|
|
61
62
|
settings = _ref2.settings,
|
|
62
63
|
children = _ref2.children;
|
|
64
|
+
|
|
65
|
+
var _useMemo = useMemo(function () {
|
|
66
|
+
return _objectSpread({}, defaultSettings, settings);
|
|
67
|
+
}, [settings]),
|
|
68
|
+
mediumHeightRatio = _useMemo.mediumHeightRatio,
|
|
69
|
+
mediumHeight = _useMemo.mediumHeight;
|
|
70
|
+
|
|
63
71
|
var innerContentRef = useRef();
|
|
64
72
|
var headerRef = useRef();
|
|
65
73
|
var headerContentRef = useRef();
|
|
@@ -74,20 +82,15 @@ var BottomSheet = function BottomSheet(_ref2) {
|
|
|
74
82
|
peekHeights = _useState4[0],
|
|
75
83
|
setPeekHeights = _useState4[1];
|
|
76
84
|
|
|
77
|
-
var _useState5 = useState(
|
|
85
|
+
var _useState5 = useState(0),
|
|
78
86
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
79
|
-
|
|
80
|
-
|
|
87
|
+
bottomSpacerHeight = _useState6[0],
|
|
88
|
+
setBottomSpacerHeight = _useState6[1];
|
|
81
89
|
|
|
82
|
-
var _useState7 = useState(
|
|
90
|
+
var _useState7 = useState(mediumHeight),
|
|
83
91
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
var _useMemo = useMemo(function () {
|
|
88
|
-
return settings || defaultSettings;
|
|
89
|
-
}, [settings]),
|
|
90
|
-
mediumHeightRatio = _useMemo.mediumHeightRatio;
|
|
92
|
+
initPos = _useState8[0],
|
|
93
|
+
setInitPos = _useState8[1];
|
|
91
94
|
|
|
92
95
|
var styles = useMemo(function () {
|
|
93
96
|
return makeStyles({
|
|
@@ -105,17 +108,17 @@ var BottomSheet = function BottomSheet(_ref2) {
|
|
|
105
108
|
useEffect(function () {
|
|
106
109
|
var headerContent = headerContentRef.current;
|
|
107
110
|
var maxHeight = computeMaxHeight(toolbarProps);
|
|
108
|
-
var
|
|
111
|
+
var computedMediumHeight = mediumHeight || Math.round(maxHeight * mediumHeightRatio);
|
|
109
112
|
var actionButtonsHeight = headerContent ? parseFloat(getComputedStyle(headerContent).getPropertyValue('height')) : 0;
|
|
110
113
|
var actionButtonsBottomMargin = headerContent ? parseFloat(getComputedStyle(headerContent).getPropertyValue('padding-bottom')) : 0;
|
|
111
114
|
var minHeight = headerRef.current.offsetHeight + actionButtonsHeight + actionButtonsBottomMargin; // Used so that the bottomSheet can be opened to the top,
|
|
112
115
|
// without stopping at the content height
|
|
113
116
|
|
|
114
117
|
var bottomSpacerHeight = maxHeight - innerContentRef.current.offsetHeight;
|
|
115
|
-
setPeekHeights([minHeight,
|
|
116
|
-
setInitPos(
|
|
118
|
+
setPeekHeights([minHeight, computedMediumHeight, maxHeight]);
|
|
119
|
+
setInitPos(computedMediumHeight);
|
|
117
120
|
setBottomSpacerHeight(bottomSpacerHeight);
|
|
118
|
-
}, [innerContentRef, headerContentRef.current, toolbarProps, mediumHeightRatio]);
|
|
121
|
+
}, [innerContentRef, headerContentRef.current, toolbarProps, mediumHeightRatio, mediumHeight]);
|
|
119
122
|
|
|
120
123
|
var handleOnIndexChange = function handleOnIndexChange(snapIndex) {
|
|
121
124
|
var maxHeightSnapIndex = peekHeights.length - 1;
|