cozy-ui 129.0.0 → 130.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "129.0.0",
3
+ "version": "130.1.0",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -55,6 +55,7 @@ Additionally, all the CozyDialogs support [MUI Dialog's props](https://v4.mui.co
55
55
  ### Exemples
56
56
 
57
57
  ```jsx
58
+ import { useRef, useEffect, useState } from 'react'
58
59
  import {
59
60
  Dialog,
60
61
  ConfirmDialog,
@@ -78,7 +79,14 @@ import FormControl from 'cozy-ui/transpiled/react/FormControl'
78
79
  import FormLabel from 'cozy-ui/transpiled/react/FormLabel'
79
80
  import BottomSheet, { BottomSheetItem } from 'cozy-ui/transpiled/react/BottomSheet'
80
81
  import Stack from 'cozy-ui/transpiled/react/Stack'
81
-
82
+ import Menu from 'cozy-ui/transpiled/react/Menu'
83
+ import MenuItem from 'cozy-ui/transpiled/react/MenuItem'
84
+ import ListItemIcon from 'cozy-ui/transpiled/react/ListItemIcon'
85
+ import ListItemText from 'cozy-ui/transpiled/react/ListItemText'
86
+
87
+ import PenIcon from 'cozy-ui/transpiled/react/Icons/Pen'
88
+ import PeopleIcon from 'cozy-ui/transpiled/react/Icons/People'
89
+ import AttachmentIcon from 'cozy-ui/transpiled/react/Icons/Attachment'
82
90
  import ToTheCloudIcon from 'cozy-ui/transpiled/react/Icons/ToTheCloud'
83
91
  import CloudIcon from "cozy-ui/transpiled/react/Icons/Cloud"
84
92
  import BackgroundImg from './background.png'
@@ -90,6 +98,8 @@ const handleBack = () => {
90
98
  }
91
99
  const hideBottomSheet = () => setState({ bottomSheetOpened: false })
92
100
  const showBottomSheet = () => setState({ bottomSheetOpened: true })
101
+ const hideMenu = () => setState({ menuOpened: false })
102
+ const showMenu = () => setState({ menuOpened: true })
93
103
  const hideSecondConfirmDialog = () => setState({ secondConfirmDialogOpened: false })
94
104
  const showSecondConfirmDialog = () => setState({ secondConfirmDialogOpened: true })
95
105
  const hideSecondDialog = () => setState({ secondDialogOpened: false })
@@ -189,6 +199,7 @@ const toggleDialog = dialog => {
189
199
  initialState = {
190
200
  modalOpened: isTesting(),
191
201
  bottomSheetOpened: false,
202
+ menuOpened: false,
192
203
  secondConfirmDialogOpened: false,
193
204
  secondDialogOpened: false,
194
205
  BSConfirmDialogOpened: false,
@@ -212,6 +223,60 @@ const initialVariants = [{
212
223
  withBackground: false
213
224
  }]
214
225
 
226
+ const ButtonMenu = () => {
227
+ const [forceRender, setForceRender] = useState(0)
228
+ const menuRef = useRef()
229
+
230
+ useEffect(() => {
231
+ if (menuRef.current) {
232
+ setForceRender(1)
233
+ }
234
+ }, [menuRef])
235
+
236
+ return (
237
+ <div ref={menuRef}>
238
+ <Button label="Show menu" onClick={showMenu}/>
239
+
240
+ {state.menuOpened && menuRef.current && (
241
+ <Menu
242
+ open
243
+ anchorEl={menuRef.current}
244
+ getContentAnchorEl={null}
245
+ anchorOrigin={{
246
+ vertical: 'bottom',
247
+ horizontal: 'left'
248
+ }}
249
+ transformOrigin={{
250
+ vertical: 'top',
251
+ horizontal: 'left'
252
+ }}
253
+ keepMounted
254
+ onClose={hideMenu}
255
+ >
256
+ <MenuItem onClick={hideMenu}>
257
+ <ListItemIcon>
258
+ <Icon icon={PenIcon} />
259
+ </ListItemIcon>
260
+ <ListItemText primary="Modify" />
261
+ </MenuItem>
262
+ <MenuItem onClick={hideMenu}>
263
+ <ListItemIcon>
264
+ <Icon icon={PeopleIcon} />
265
+ </ListItemIcon>
266
+ <ListItemText primary="People" />
267
+ </MenuItem>
268
+ <MenuItem onClick={hideMenu}>
269
+ <ListItemIcon>
270
+ <Icon icon={AttachmentIcon} />
271
+ </ListItemIcon>
272
+ <ListItemText primary="Attachment" />
273
+ </MenuItem>
274
+ </Menu>
275
+ )}
276
+ </div>
277
+ )
278
+ }
279
+
215
280
  ;
216
281
 
217
282
  <DemoProvider>
@@ -329,6 +394,7 @@ const initialVariants = [{
329
394
  <div>
330
395
  <Button label="Show inner dialog" onClick={showSecondDialog}/>
331
396
  </div>
397
+ <ButtonMenu />
332
398
  </Stack>
333
399
  </Typography>
334
400
 
@@ -121,7 +121,7 @@ const ExampleTable = ({ variant, ...props }) => {
121
121
  <Typography className="u-mt-1" variant="h4">Sorted table</Typography>
122
122
  <div className="u-mt-half" style={{ border: "1px solid var(--borderMainColor)", height: 400, width: "100%" }}>
123
123
  <SelectionProvider>
124
- <ExampleTable variant={variant} defaultOrder={columns[0].id} />
124
+ <ExampleTable variant={variant} defaultOrder={{by: columns[0].id, direction: 'asc'}} />
125
125
  </SelectionProvider>
126
126
  </div>
127
127
  </>
@@ -28,8 +28,10 @@ const VirtualizedTable = forwardRef(
28
28
  },
29
29
  ref
30
30
  ) => {
31
- const [orderDirection, setOrderDirection] = useState('asc')
32
- const [orderBy, setOrderBy] = useState(defaultOrder)
31
+ const [orderDirection, setOrderDirection] = useState(
32
+ defaultOrder?.direction ?? 'asc'
33
+ )
34
+ const [orderBy, setOrderBy] = useState(defaultOrder?.by ?? undefined)
33
35
 
34
36
  const sortedData = orderBy
35
37
  ? stableSort(rows, getComparator(orderDirection, orderBy))
@@ -117,10 +119,27 @@ VirtualizedTable.defaultProps = {
117
119
  }
118
120
 
119
121
  VirtualizedTable.propTypes = {
120
- /** Column ID to be used for initiating the sort */
121
- defaultOrder: PropTypes.string,
122
+ /** Rows to display in the table */
123
+ rows: PropTypes.array,
124
+ /** Column configuration */
125
+ columns: PropTypes.array,
122
126
  /** Returned object is: PropTypes.shape({ groupLabels: PropTypes.array, groupCounts: PropTypes.array }) */
123
127
  groups: PropTypes.func,
128
+ /** Default sorting configuration */
129
+ defaultOrder: PropTypes.shape({
130
+ direction: PropTypes.oneOf(['asc', 'desc']),
131
+ by: PropTypes.string
132
+ }),
133
+ /** Sort files by type to put directory and trash before files */
134
+ secondarySort: PropTypes.func,
135
+ /** Array of selected items */
136
+ selectedItems: PropTypes.array,
137
+ /** Callback function when a row is selected */
138
+ onSelect: PropTypes.func,
139
+ /** Callback function when all rows are selected/deselected */
140
+ onSelectAll: PropTypes.func,
141
+ /** Function to determine if a row is selected */
142
+ isSelectedItem: PropTypes.func,
124
143
  /** Callback called after the sort */
125
144
  onSortChange: PropTypes.func
126
145
  }
@@ -11,12 +11,15 @@
11
11
  $sidebar
12
12
  width rem(236)
13
13
  background-color var(--defaultBackgroundColor)
14
- overflow-y auto
14
+ overflow-y hidden
15
15
  overflow-x hidden
16
16
  display flex
17
17
  flex-direction column
18
18
  flex 0 0 auto
19
19
 
20
+ &:hover
21
+ overflow-y auto
22
+
20
23
  &--border
21
24
  border-right rem(1) solid var(--dividerColor)
22
25
 
@@ -17,6 +17,8 @@ import { stableSort, getComparator } from "cozy-ui/transpiled/react/Table/Virtua
17
17
  import virtuosoComponents from "cozy-ui/transpiled/react/Table/Virtualized/virtuosoComponents";
18
18
  import TableCell from "cozy-ui/transpiled/react/TableCell";
19
19
  var VirtualizedTable = /*#__PURE__*/forwardRef(function (_ref, ref) {
20
+ var _defaultOrder$directi, _defaultOrder$by;
21
+
20
22
  var rows = _ref.rows,
21
23
  columns = _ref.columns,
22
24
  groups = _ref.groups,
@@ -32,12 +34,12 @@ var VirtualizedTable = /*#__PURE__*/forwardRef(function (_ref, ref) {
32
34
  onSortChange = _ref.onSortChange,
33
35
  props = _objectWithoutProperties(_ref, _excluded);
34
36
 
35
- var _useState = useState('asc'),
37
+ var _useState = useState((_defaultOrder$directi = defaultOrder === null || defaultOrder === void 0 ? void 0 : defaultOrder.direction) !== null && _defaultOrder$directi !== void 0 ? _defaultOrder$directi : 'asc'),
36
38
  _useState2 = _slicedToArray(_useState, 2),
37
39
  orderDirection = _useState2[0],
38
40
  setOrderDirection = _useState2[1];
39
41
 
40
- var _useState3 = useState(defaultOrder),
42
+ var _useState3 = useState((_defaultOrder$by = defaultOrder === null || defaultOrder === void 0 ? void 0 : defaultOrder.by) !== null && _defaultOrder$by !== void 0 ? _defaultOrder$by : undefined),
41
43
  _useState4 = _slicedToArray(_useState3, 2),
42
44
  orderBy = _useState4[0],
43
45
  setOrderBy = _useState4[1];
@@ -129,12 +131,36 @@ VirtualizedTable.defaultProps = {
129
131
  onSelectAll: function onSelectAll() {}
130
132
  };
131
133
  VirtualizedTable.propTypes = {
132
- /** Column ID to be used for initiating the sort */
133
- defaultOrder: PropTypes.string,
134
+ /** Rows to display in the table */
135
+ rows: PropTypes.array,
136
+
137
+ /** Column configuration */
138
+ columns: PropTypes.array,
134
139
 
135
140
  /** Returned object is: PropTypes.shape({ groupLabels: PropTypes.array, groupCounts: PropTypes.array }) */
136
141
  groups: PropTypes.func,
137
142
 
143
+ /** Default sorting configuration */
144
+ defaultOrder: PropTypes.shape({
145
+ direction: PropTypes.oneOf(['asc', 'desc']),
146
+ by: PropTypes.string
147
+ }),
148
+
149
+ /** Sort files by type to put directory and trash before files */
150
+ secondarySort: PropTypes.func,
151
+
152
+ /** Array of selected items */
153
+ selectedItems: PropTypes.array,
154
+
155
+ /** Callback function when a row is selected */
156
+ onSelect: PropTypes.func,
157
+
158
+ /** Callback function when all rows are selected/deselected */
159
+ onSelectAll: PropTypes.func,
160
+
161
+ /** Function to determine if a row is selected */
162
+ isSelectedItem: PropTypes.func,
163
+
138
164
  /** Callback called after the sort */
139
165
  onSortChange: PropTypes.func
140
166
  };