cozy-ui 127.4.0 → 127.6.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.
Files changed (29) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cozy-ui.min.css +1 -1
  3. package/package.json +2 -2
  4. package/react/Layout/Layout.jsx +9 -19
  5. package/react/Layout/Layout.md +73 -23
  6. package/react/Table/Readme.md +3 -2
  7. package/react/Table/Virtualized/Cell.jsx +21 -3
  8. package/react/Table/Virtualized/Dnd/virtuosoComponents.jsx +3 -3
  9. package/react/Table/Virtualized/RowContent.jsx +2 -0
  10. package/react/Table/Virtualized/TableRow.jsx +3 -4
  11. package/react/Table/Virtualized/index.jsx +0 -1
  12. package/react/Table/Virtualized/virtuosoComponents.jsx +1 -1
  13. package/react/UploadQueue/Readme.md +1 -1
  14. package/scripts/screenshots/screenshotComponent.js +4 -8
  15. package/stylus/elements/defaults.styl +1 -11
  16. package/stylus/objects/layouts.styl +13 -47
  17. package/transpiled/react/Layout/Layout.js +9 -9
  18. package/transpiled/react/Table/Virtualized/Cell.d.ts +2 -1
  19. package/transpiled/react/Table/Virtualized/Cell.js +31 -6
  20. package/transpiled/react/Table/Virtualized/Dnd/virtuosoComponents.d.ts +1 -1
  21. package/transpiled/react/Table/Virtualized/Dnd/virtuosoComponents.js +3 -5
  22. package/transpiled/react/Table/Virtualized/RowContent.d.ts +2 -1
  23. package/transpiled/react/Table/Virtualized/RowContent.js +3 -1
  24. package/transpiled/react/Table/Virtualized/TableRow.d.ts +6 -2
  25. package/transpiled/react/Table/Virtualized/TableRow.js +5 -4
  26. package/transpiled/react/Table/Virtualized/index.js +3 -4
  27. package/transpiled/react/Table/Virtualized/virtuosoComponents.d.ts +1 -1
  28. package/transpiled/react/Table/Virtualized/virtuosoComponents.js +4 -6
  29. package/transpiled/react/stylesheet.css +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "127.4.0",
3
+ "version": "127.6.0",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -183,7 +183,7 @@
183
183
  "react-select": "^4.3.0",
184
184
  "react-swipeable-views": "^0.13.3",
185
185
  "react-virtuoso": "4.12.7",
186
- "rooks": "^5.11.2"
186
+ "rooks": "7.14.1"
187
187
  },
188
188
  "peerDependencies": {
189
189
  "cozy-client": ">=52.1.0",
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
3
3
  import React, { createContext, forwardRef, useContext, useMemo } from 'react'
4
4
 
5
5
  import styles from './styles.styl'
6
+ import { useBreakpoints } from '../providers/Breakpoints'
6
7
 
7
8
  export const LayoutContext = createContext()
8
9
 
@@ -33,20 +34,13 @@ LayoutProvider.displayName = 'LayoutProvider'
33
34
 
34
35
  export const Layout = forwardRef(
35
36
  ({ children, className, monoColumn, withTopBar, ...props }, ref) => {
36
- const variant = monoColumn ? 'monocolumn' : '2panes'
37
-
38
37
  return (
39
38
  <LayoutProvider monoColumn={monoColumn} withTopBar={withTopBar}>
40
39
  <div
41
40
  ref={ref}
42
- className={cx(
43
- className,
44
- styles['o-layout'],
45
- styles[`o-layout-${variant}`],
46
- {
47
- [styles[`o-layout-topbar`]]: withTopBar
48
- }
49
- )}
41
+ className={cx(className, styles['o-layout'], {
42
+ [styles['o-layout-main-2panes']]: !monoColumn
43
+ })}
50
44
  {...props}
51
45
  >
52
46
  {children}
@@ -59,20 +53,16 @@ export const Layout = forwardRef(
59
53
  Layout.displayName = 'Layout'
60
54
 
61
55
  export const Main = forwardRef(({ className, children, ...props }, ref) => {
56
+ const { isDesktop } = useBreakpoints()
62
57
  const { monoColumn, withTopBar } = useLayout()
63
- const variant = monoColumn ? 'monocolumn' : '2panes'
64
58
 
65
59
  return (
66
60
  <main
67
61
  ref={ref}
68
- className={cx(
69
- className,
70
- styles['o-layout-main'],
71
- styles[`o-layout-main-${variant}`],
72
- {
73
- [styles[`o-layout-main-${variant}--topbar`]]: withTopBar
74
- }
75
- )}
62
+ className={cx(className, styles['o-layout-main'], {
63
+ [styles['o-layout-main-2panes']]: !monoColumn,
64
+ [styles[`o-layout-main-topbar`]]: withTopBar && !isDesktop
65
+ })}
76
66
  {...props}
77
67
  >
78
68
  {children}
@@ -29,8 +29,13 @@ import Sidebar from 'cozy-ui/transpiled/react/Sidebar'
29
29
  import Nav, { NavItem, NavIcon, NavText, genNavLink, NavDesktopLimiter } from 'cozy-ui/transpiled/react/Nav'
30
30
  import cx from 'classnames'
31
31
  import isEqual from 'lodash/isEqual'
32
+ import Icon from 'cozy-ui/transpiled/react/Icon'
33
+ import IconButton from 'cozy-ui/transpiled/react/IconButton'
32
34
  import WarnIcon from 'cozy-ui/transpiled/react/Icons/Warn'
33
35
  import CheckIcon from 'cozy-ui/transpiled/react/Icons/Check'
36
+ import CrossMediumIcon from 'cozy-ui/transpiled/react/Icons/CrossMedium'
37
+ import Button from 'cozy-ui/transpiled/react/Buttons'
38
+ import Dialog from 'cozy-ui/transpiled/react/Dialog'
34
39
  import DownloadIcon from 'cozy-ui/transpiled/react/Icons/Download'
35
40
  import DemoProvider from 'cozy-ui/docs/components/DemoProvider'
36
41
  import { makeStyles } from 'cozy-ui/transpiled/react/styles'
@@ -51,18 +56,36 @@ const ExampleRouterNavLink = ({ children, className, active, activeClassName, on
51
56
  const NavLink = genNavLink(ExampleRouterNavLink)
52
57
 
53
58
  // Not necessary in a normal app
54
- const useStyles = makeStyles({
55
- layout: {
56
- position: 'relative',
57
- transform: 'translateZ(0)',
58
- '& > main': {
59
- minHeight: 'unset'
59
+ const useStyles = makeStyles(theme => ({
60
+ topBar: { // same style than the cozy-bar
61
+ display: 'flex',
62
+ alignItems: 'center',
63
+ padding: '0 1rem',
64
+ minHeight: '3rem',
65
+ width: '100%',
66
+ boxSizing: 'border-box',
67
+ zIndex: 'var(--zIndex-bar)',
68
+ backgroundColor: theme.palette.background.default,
69
+ borderBottom: `1px solid ${theme.palette.divider}`,
70
+ position: 'fixed',
71
+ top: 0,
72
+ right: 0,
73
+ [theme.breakpoints.up('lg')]: {
74
+ position: 'relative',
60
75
  }
76
+ },
77
+ closeButton: {
78
+ position: 'absolute',
79
+ top: '1.15rem',
80
+ right: '1.15rem',
81
+ zIndex: 'var(--zIndex-modal-toolbar)',
82
+ backgroundColor: theme.palette.background.paper
61
83
  }
62
- })
84
+ }))
63
85
 
64
- const initialVariants = [{ monoColumn: false, withTopBar: true }]
86
+ const initialVariants = [{ monoColumn: false, withTopBar: true, longContent: true }]
65
87
  const [active, setActive] = useState(['Section 1', 'Subsection 1'])
88
+ const [showDialog, setShowDialog] = useState(isTesting() ? true : false)
66
89
  const styles = useStyles()
67
90
 
68
91
  ;
@@ -112,23 +135,50 @@ const SideBar = ({ variant }) => {
112
135
  )
113
136
  }
114
137
 
115
- <Variants initialVariants={initialVariants} screenshotAllVariants>
138
+ <Variants initialVariants={initialVariants}>
116
139
  {variant => (
117
140
  <DemoProvider>
118
- <Layout
119
- className={styles.layout}
120
- withTopBar={variant.withTopBar}
121
- monoColumn={variant.monoColumn}
122
- >
123
- {!variant.monoColumn && <SideBar variant={variant} />}
124
- {variant.withTopBar && <div className="u-flex-m u-dn u-flex-items-center u-pos-absolute u-top-0 u-w-100" style={{ height: '48px', backgroundColor: 'var(--defaultBackgroundColor)' }}>Fake TopBar</div>}
125
- <Main>
126
- <Content className='u-p-1'>
127
- <h2 className='u-mt-0'>{ active.join(' / ') }</h2>
128
- { content.ada.short }
129
- </Content>
130
- </Main>
131
- </Layout>
141
+ <Button className="u-mb-1" label="Open layout in modal" onClick={() => setShowDialog(true)} />
142
+ {showDialog && (
143
+ <Dialog
144
+ className="cozy-ui-body"
145
+ open
146
+ fullScreen
147
+ fullWidth
148
+ >
149
+ <IconButton
150
+ className={styles.closeButton}
151
+ onClick={() => setShowDialog(false)}
152
+ >
153
+ <Icon icon={CrossMediumIcon} />
154
+ </IconButton>
155
+ {variant.withTopBar &&
156
+ <div
157
+ id="coz-bar"
158
+ role="banner"
159
+ className={styles.topBar}
160
+ >
161
+ Fake TopBar
162
+ </div>
163
+ }
164
+ <div role="application">
165
+ <Layout
166
+ withTopBar={variant.withTopBar}
167
+ monoColumn={variant.monoColumn}
168
+ >
169
+ {!variant.monoColumn && <SideBar variant={variant} />}
170
+ <Main>
171
+ <Content className='u-p-1'>
172
+ <h2 className='u-mt-0'>{ active.join(' / ') }</h2>
173
+ <p>---Start---</p>
174
+ {variant.longContent ? content.ada.long : content.ada.short}
175
+ <p>---END---</p>
176
+ </Content>
177
+ </Main>
178
+ </Layout>
179
+ </div>
180
+ </Dialog>
181
+ )}
132
182
  </DemoProvider>
133
183
  )}
134
184
  </Variants>
@@ -110,8 +110,9 @@ const onSelectAll = rows => {
110
110
  onSelectAll={onSelectAll}
111
111
  componentsProps={{
112
112
  rowContent: {
113
- onClick: (row, column) => { console.info(`click on cell. Row ${row['id']}, Column ${column['id']}`) }
114
- }
113
+ onClick: (row, column) => { console.info(`click on cell. Row ${row['id']}, Column ${column['id']}`) },
114
+ onLongPress: (row, column) => { console.info(`long press on cell. Row ${row['id']}, Column ${column['id']}`) },
115
+ },
115
116
  }}
116
117
  />
117
118
  </div>
@@ -1,5 +1,6 @@
1
1
  import get from 'lodash/get'
2
- import React from 'react'
2
+ import React, { useState } from 'react'
3
+ import { useOnLongPress } from 'rooks'
3
4
 
4
5
  import TableCell from '../../TableCell'
5
6
  import { makeStyles } from '../../styles'
@@ -12,17 +13,34 @@ const useStyles = makeStyles({
12
13
  }
13
14
  })
14
15
 
15
- const Cell = ({ row, columns, column, onClick, children }) => {
16
+ const Cell = ({ row, columns, column, onClick, onLongPress, children }) => {
17
+ const [isLongPress, setIsLongPress] = useState(false) // onClick is triggered after a long press anyway, so we need this bool to avoid this behavior
18
+
16
19
  const classes = useStyles({ column, isClickable: !!onClick })
17
20
  const cellContent = get(row, column.id, '—')
18
21
 
22
+ const longPressRef = useOnLongPress(() => {
23
+ setIsLongPress(true)
24
+ onLongPress?.(row, column)
25
+ })
26
+
27
+ const handleClick = () => {
28
+ if (!isLongPress) {
29
+ onClick?.(row, column)
30
+ } else {
31
+ setIsLongPress(false)
32
+ }
33
+ }
34
+
19
35
  return (
20
36
  <TableCell
21
37
  key={column.id}
38
+ ref={longPressRef}
22
39
  classes={classes}
23
40
  align={column.textAlign ?? 'left'}
24
41
  padding={column.disablePadding ? 'none' : 'normal'}
25
- onClick={() => onClick?.(row, column)}
42
+ onClick={handleClick}
43
+ onContextMenu={isLongPress ? ev => ev.preventDefault() : undefined}
26
44
  >
27
45
  {children
28
46
  ? React.Children.map(children, child =>
@@ -17,9 +17,9 @@ const virtuosoComponentsDnd = {
17
17
  <TableContainer {...props} ref={ref} />
18
18
  </DnDConfigWrapper>
19
19
  )),
20
- TableRow: forwardRef((props, ref) => {
21
- return <TableRowDnD {...props} ref={ref} />
22
- })
20
+ TableRow: props => {
21
+ return <TableRowDnD {...props} />
22
+ }
23
23
  }
24
24
 
25
25
  export default virtuosoComponentsDnd
@@ -12,6 +12,7 @@ const RowContent = ({
12
12
  context,
13
13
  children,
14
14
  onSelectClick,
15
+ onLongPress,
15
16
  onClick
16
17
  }) => {
17
18
  const selectedCount = context.selectedItems.length
@@ -39,6 +40,7 @@ const RowContent = ({
39
40
  columns={columns}
40
41
  column={column}
41
42
  onClick={onClick}
43
+ onLongPress={onLongPress}
42
44
  >
43
45
  {children}
44
46
  </Cell>
@@ -1,20 +1,19 @@
1
1
  import cx from 'classnames'
2
- import React, { forwardRef } from 'react'
2
+ import React from 'react'
3
3
 
4
4
  import TableRowClassic from '../../TableRow'
5
5
 
6
- const TableRow = forwardRef(({ item, context, className, ...props }, ref) => {
6
+ const TableRow = ({ item, context, className, ...props }) => {
7
7
  const isSelected = context?.isSelectedItem(item)
8
8
 
9
9
  return (
10
10
  <TableRowClassic
11
11
  {...props}
12
12
  className={cx(className, 'virtualized')}
13
- ref={ref}
14
13
  selected={isSelected}
15
14
  hover
16
15
  />
17
16
  )
18
- })
17
+ }
19
18
 
20
19
  export default TableRow
@@ -76,7 +76,6 @@ const VirtualizedTable = forwardRef(
76
76
  columns={columns}
77
77
  context={context}
78
78
  onSelectClick={onSelect}
79
- onClick={componentsProps?.rowContent?.onClick}
80
79
  >
81
80
  {componentsProps?.rowContent?.children}
82
81
  </RowContent>
@@ -29,7 +29,7 @@ const virtuosoComponents = {
29
29
  TableFooter: forwardRef(({ context, ...props }, ref) => (
30
30
  <TableFooter {...props} ref={ref} />
31
31
  )),
32
- TableRow: forwardRef((props, ref) => <TableRow {...props} ref={ref} />)
32
+ TableRow: props => <TableRow {...props} />
33
33
  }
34
34
 
35
35
  export default virtuosoComponents
@@ -44,7 +44,7 @@ const data = {
44
44
  loaded: 100,
45
45
  total: 400,
46
46
  speed: 135000,
47
- remainingTime: 90
47
+ remainingTime: 120
48
48
  },
49
49
  status: 'loading'
50
50
  }, {
@@ -1,4 +1,5 @@
1
1
  const path = require('path')
2
+
2
3
  const { sleep } = require('./helpers')
3
4
 
4
5
  const rootDirectory = path.join(__dirname, '../')
@@ -22,17 +23,12 @@ const getDefaultScreenshotName = ({
22
23
  * component.
23
24
  */
24
25
  const screenshotComponent = async (page, options) => {
25
- const {
26
- component,
27
- screenshotDir,
28
- viewport,
29
- type,
30
- variant,
31
- componentConfig
32
- } = options
26
+ const { component, screenshotDir, viewport, type, variant, componentConfig } =
27
+ options
33
28
  const { link, name } = component
34
29
 
35
30
  await page.goto(link)
31
+ await page.addStyleTag({ content: 'body {height: auto;}' }) // to resize viewport according to its content
36
32
  await sleep(200) // to be sure the page is entirely loaded
37
33
 
38
34
  const getScreenshotName =
@@ -35,21 +35,11 @@ body
35
35
  textarea
36
36
  @extend $font-labor
37
37
 
38
- html
39
- body
40
- +medium-screen()
41
- display block
42
- height auto
43
-
44
38
  [role=application]
45
39
  display flex
46
40
  height inherit
47
41
  flex 1 1 100%
48
- overflow-x hidden
49
- overflow-y auto
50
-
51
- +medium-screen()
52
- overflow visible
42
+ overflow hidden auto
53
43
 
54
44
  // FORMS
55
45
  @require '../components/forms'
@@ -59,87 +59,53 @@ $app-layout
59
59
  background-color var(--paperBackgroundColor)
60
60
  color var(--primaryTextColor)
61
61
 
62
- +medium-screen() // mobile + tablet
63
- display block
64
-
65
- &-topbar
66
- +medium-screen() // mobile + tablet
67
- // this pseudo-element is "ghost" element replacing bar
68
- &:before
69
- content ''
70
- display block
71
- height barHeight
72
-
73
62
  // When you want a sidebar
74
63
  &-2panes
75
64
  flex 0 0 100%
76
65
  align-items stretch
77
66
 
78
- +medium-screen() // mobile + tablet
79
- // this pseudo-element is "ghost" element replacing nav
80
- &:after
81
- content ''
82
- display block
83
- height navHeight
84
-
85
67
  $app-main
86
68
  display flex
87
69
  flex-direction column
88
70
  position relative
89
71
  flex 1 1 auto
90
72
  box-sizing border-box
91
- overflow-x hidden
92
- overflow-y auto
73
+ overflow hidden
74
+ height 100%
93
75
 
94
76
  +medium-screen() // mobile + tablet
95
- display block
96
- overflow visible
97
77
  // iPhone X environment tweak
98
78
  padding-left env(safe-area-inset-left)
99
79
  padding-right env(safe-area-inset-right)
100
80
  padding-bottom env(safe-area-inset-bottom)
101
81
 
102
- &-monocolumn
103
- height 100%
104
-
105
- +medium-screen() // mobile + tablet
106
- min-height 100vh
107
-
108
- &--topbar
109
- +medium-screen() // mobile + tablet
110
- min-height 'calc(100vh - %s)' % barHeight
82
+ &-topbar
83
+ // this pseudo-element is "ghost" element replacing bar
84
+ &:before
85
+ content ''
86
+ display block
87
+ height barHeight
88
+ width 100%
89
+ background-color var(--paperBackgroundColor)
111
90
 
112
91
  &-2panes
113
- height auto
114
92
  background-color var(--defaultBackgroundColor)
115
93
 
116
94
  +medium-screen() // mobile + tablet
117
- min-height calc(100vh - var(--sidebarHeight))
95
+ height calc(100vh - var(--sidebarHeight))
118
96
  background-color transparent
119
97
 
120
- &--topbar
121
- +medium-screen() // mobile + tablet
122
- min-height 'calc(100vh - var(--sidebarHeight) - %s)' % barHeight
123
-
124
98
  $app-content
125
99
  position relative
126
100
  display flex
127
101
  flex-direction column
128
102
  flex 1 1 auto
129
103
  box-sizing border-box
130
- overflow-x hidden
131
- overflow-y auto
104
+ overflow hidden auto
132
105
  background-color var(--paperBackgroundColor)
133
-
134
- +medium-screen() // mobile + tablet
135
- display block
136
- overflow visible
137
-
138
- &-monocolumn
139
- height 100%
106
+ height 100%
140
107
 
141
108
  &-2panes
142
- height auto
143
109
  margin 1rem 1rem 1rem 0
144
110
  border-radius 1rem
145
111
 
@@ -9,17 +9,14 @@ import PropTypes from 'prop-types';
9
9
  import React, { createContext, forwardRef, useContext, useMemo } from 'react';
10
10
  var styles = {
11
11
  "o-layout": "styles__o-layout___3TSz9",
12
- "o-layout-topbar": "styles__o-layout-topbar___2SHWi",
13
12
  "o-layout-2panes": "styles__o-layout-2panes___1CDQw",
14
13
  "o-layout-main": "styles__o-layout-main___3mPxz",
15
- "o-layout-main-monocolumn": "styles__o-layout-main-monocolumn___2a7vz",
16
- "o-layout-main-monocolumn--topbar": "styles__o-layout-main-monocolumn--topbar___9_4Xd",
14
+ "o-layout-main-topbar": "styles__o-layout-main-topbar___3FSE_",
17
15
  "o-layout-main-2panes": "styles__o-layout-main-2panes___3ickD",
18
- "o-layout-main-2panes--topbar": "styles__o-layout-main-2panes--topbar___cGi-H",
19
16
  "o-layout-content": "styles__o-layout-content___3D5gN",
20
- "o-layout-content-monocolumn": "styles__o-layout-content-monocolumn___1rpxp",
21
17
  "o-layout-content-2panes": "styles__o-layout-content-2panes___2Hotr"
22
18
  };
19
+ import { useBreakpoints } from "cozy-ui/transpiled/react/providers/Breakpoints";
23
20
  export var LayoutContext = /*#__PURE__*/createContext();
24
21
  export var useLayout = function useLayout() {
25
22
  var context = useContext(LayoutContext);
@@ -52,29 +49,32 @@ export var Layout = /*#__PURE__*/forwardRef(function (_ref2, ref) {
52
49
  withTopBar = _ref2.withTopBar,
53
50
  props = _objectWithoutProperties(_ref2, _excluded);
54
51
 
55
- var variant = monoColumn ? 'monocolumn' : '2panes';
56
52
  return /*#__PURE__*/React.createElement(LayoutProvider, {
57
53
  monoColumn: monoColumn,
58
54
  withTopBar: withTopBar
59
55
  }, /*#__PURE__*/React.createElement("div", _extends({
60
56
  ref: ref,
61
- className: cx(className, styles['o-layout'], styles["o-layout-".concat(variant)], _defineProperty({}, styles["o-layout-topbar"], withTopBar))
57
+ className: cx(className, styles['o-layout'], _defineProperty({}, styles['o-layout-main-2panes'], !monoColumn))
62
58
  }, props), children));
63
59
  });
64
60
  Layout.displayName = 'Layout';
65
61
  export var Main = /*#__PURE__*/forwardRef(function (_ref3, ref) {
62
+ var _cx2;
63
+
66
64
  var className = _ref3.className,
67
65
  children = _ref3.children,
68
66
  props = _objectWithoutProperties(_ref3, _excluded2);
69
67
 
68
+ var _useBreakpoints = useBreakpoints(),
69
+ isDesktop = _useBreakpoints.isDesktop;
70
+
70
71
  var _useLayout = useLayout(),
71
72
  monoColumn = _useLayout.monoColumn,
72
73
  withTopBar = _useLayout.withTopBar;
73
74
 
74
- var variant = monoColumn ? 'monocolumn' : '2panes';
75
75
  return /*#__PURE__*/React.createElement("main", _extends({
76
76
  ref: ref,
77
- className: cx(className, styles['o-layout-main'], styles["o-layout-main-".concat(variant)], _defineProperty({}, styles["o-layout-main-".concat(variant, "--topbar")], withTopBar))
77
+ className: cx(className, styles['o-layout-main'], (_cx2 = {}, _defineProperty(_cx2, styles['o-layout-main-2panes'], !monoColumn), _defineProperty(_cx2, styles["o-layout-main-topbar"], withTopBar && !isDesktop), _cx2))
78
78
  }, props), children);
79
79
  });
80
80
  Main.displayName = 'Main';
@@ -1,8 +1,9 @@
1
- declare var _default: React.MemoExoticComponent<({ row, columns, column, onClick, children }: {
1
+ declare var _default: React.MemoExoticComponent<({ row, columns, column, onClick, onLongPress, children }: {
2
2
  row: any;
3
3
  columns: any;
4
4
  column: any;
5
5
  onClick: any;
6
+ onLongPress: any;
6
7
  children: any;
7
8
  }) => JSX.Element>;
8
9
  export default _default;
@@ -1,5 +1,7 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
1
2
  import get from 'lodash/get';
2
- import React from 'react';
3
+ import React, { useState } from 'react';
4
+ import { useOnLongPress } from 'rooks';
3
5
  import TableCell from "cozy-ui/transpiled/react/TableCell";
4
6
  import { makeStyles } from "cozy-ui/transpiled/react/styles";
5
7
  var useStyles = makeStyles({
@@ -25,21 +27,44 @@ var Cell = function Cell(_ref4) {
25
27
  var row = _ref4.row,
26
28
  columns = _ref4.columns,
27
29
  column = _ref4.column,
28
- _onClick = _ref4.onClick,
30
+ onClick = _ref4.onClick,
31
+ onLongPress = _ref4.onLongPress,
29
32
  children = _ref4.children;
33
+
34
+ var _useState = useState(false),
35
+ _useState2 = _slicedToArray(_useState, 2),
36
+ isLongPress = _useState2[0],
37
+ setIsLongPress = _useState2[1]; // onClick is triggered after a long press anyway, so we need this bool to avoid this behavior
38
+
39
+
30
40
  var classes = useStyles({
31
41
  column: column,
32
- isClickable: !!_onClick
42
+ isClickable: !!onClick
33
43
  });
34
44
  var cellContent = get(row, column.id, '—');
45
+ var longPressRef = useOnLongPress(function () {
46
+ setIsLongPress(true);
47
+ onLongPress === null || onLongPress === void 0 ? void 0 : onLongPress(row, column);
48
+ });
49
+
50
+ var handleClick = function handleClick() {
51
+ if (!isLongPress) {
52
+ onClick === null || onClick === void 0 ? void 0 : onClick(row, column);
53
+ } else {
54
+ setIsLongPress(false);
55
+ }
56
+ };
57
+
35
58
  return /*#__PURE__*/React.createElement(TableCell, {
36
59
  key: column.id,
60
+ ref: longPressRef,
37
61
  classes: classes,
38
62
  align: (_column$textAlign = column.textAlign) !== null && _column$textAlign !== void 0 ? _column$textAlign : 'left',
39
63
  padding: column.disablePadding ? 'none' : 'normal',
40
- onClick: function onClick() {
41
- return _onClick === null || _onClick === void 0 ? void 0 : _onClick(row, column);
42
- }
64
+ onClick: handleClick,
65
+ onContextMenu: isLongPress ? function (ev) {
66
+ return ev.preventDefault();
67
+ } : undefined
43
68
  }, children ? React.Children.map(children, function (child) {
44
69
  return /*#__PURE__*/React.isValidElement(child) ? /*#__PURE__*/React.cloneElement(child, {
45
70
  row: row,
@@ -5,7 +5,7 @@ export default virtuosoComponentsDnd;
5
5
  */
6
6
  declare const virtuosoComponentsDnd: {
7
7
  Scroller: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
8
- TableRow: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
8
+ TableRow: (props: any) => JSX.Element;
9
9
  Table: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
10
10
  TableHead: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
11
11
  TableBody: React.ForwardRefExoticComponent<React.RefAttributes<any>>;
@@ -29,11 +29,9 @@ var virtuosoComponentsDnd = _objectSpread(_objectSpread({}, virtuosoComponents),
29
29
  ref: ref
30
30
  })));
31
31
  }),
32
- TableRow: /*#__PURE__*/forwardRef(function (props, ref) {
33
- return /*#__PURE__*/React.createElement(TableRowDnD, _extends({}, props, {
34
- ref: ref
35
- }));
36
- })
32
+ TableRow: function TableRow(props) {
33
+ return /*#__PURE__*/React.createElement(TableRowDnD, props);
34
+ }
37
35
  });
38
36
 
39
37
  export default virtuosoComponentsDnd;
@@ -1,10 +1,11 @@
1
- declare var _default: React.MemoExoticComponent<({ index, row, columns, context, children, onSelectClick, onClick }: {
1
+ declare var _default: React.MemoExoticComponent<({ index, row, columns, context, children, onSelectClick, onLongPress, onClick }: {
2
2
  index: any;
3
3
  row: any;
4
4
  columns: any;
5
5
  context: any;
6
6
  children: any;
7
7
  onSelectClick: any;
8
+ onLongPress: any;
8
9
  onClick: any;
9
10
  }) => JSX.Element>;
10
11
  export default _default;