cozy-ui 83.4.0 → 84.0.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 +16 -0
- package/package.json +1 -1
- package/react/ActionMenu/ActionMenuWithClose.jsx +1 -0
- package/react/ActionMenu/ActionMenuWrapper.jsx +3 -0
- package/react/ActionMenu/index.jsx +7 -0
- package/react/ActionsMenu/Actions/call.js +30 -0
- package/react/ActionsMenu/Actions/divider.js +12 -0
- package/react/ActionsMenu/Actions/emailTo.js +30 -0
- package/react/ActionsMenu/Actions/helpers.js +63 -0
- package/react/ActionsMenu/Actions/helpers.spec.js +36 -0
- package/react/ActionsMenu/Actions/index.js +7 -0
- package/react/ActionsMenu/Actions/locales/withActionsLocales.jsx +11 -0
- package/react/ActionsMenu/Actions/modify.js +41 -0
- package/react/ActionsMenu/Actions/smsTo.js +30 -0
- package/react/ActionsMenu/Actions/viewInContacts.js +41 -0
- package/react/ActionsMenu/ActionsItems.jsx +51 -0
- package/react/ActionsMenu/ActionsMenuItem.jsx +18 -0
- package/react/ActionsMenu/ActionsMenuMobileHeader.jsx +33 -0
- package/react/ActionsMenu/ActionsMenuWrapper.jsx +55 -0
- package/react/ActionsMenu/Readme.md +222 -0
- package/react/ActionsMenu/index.jsx +60 -0
- package/react/MuiCozyTheme/Menu/Readme.md +101 -0
- package/react/MuiCozyTheme/makeOverrides.js +5 -9
- package/react/Viewer/Footer/FooterContent.jsx +1 -0
- package/react/Viewer/Panel/QualificationListItemInformation.spec.jsx +1 -1
- package/react/index.js +1 -1
- package/transpiled/react/ActionMenu/ActionMenuWithClose.js +1 -0
- package/transpiled/react/ActionMenu/ActionMenuWrapper.js +3 -0
- package/transpiled/react/ActionMenu/index.js +5 -0
- package/transpiled/react/ActionsMenu/Actions/call.js +33 -0
- package/transpiled/react/ActionsMenu/Actions/divider.js +12 -0
- package/transpiled/react/ActionsMenu/Actions/emailTo.js +33 -0
- package/transpiled/react/ActionsMenu/Actions/helpers.js +51 -0
- package/transpiled/react/ActionsMenu/Actions/index.js +7 -0
- package/transpiled/react/ActionsMenu/Actions/locales/withActionsLocales.js +20 -0
- package/transpiled/react/ActionsMenu/Actions/modify.js +40 -0
- package/transpiled/react/ActionsMenu/Actions/smsTo.js +33 -0
- package/transpiled/react/ActionsMenu/Actions/viewInContacts.js +40 -0
- package/transpiled/react/ActionsMenu/ActionsItems.js +58 -0
- package/transpiled/react/ActionsMenu/ActionsMenuItem.js +22 -0
- package/transpiled/react/ActionsMenu/ActionsMenuMobileHeader.js +37 -0
- package/transpiled/react/ActionsMenu/ActionsMenuWrapper.js +65 -0
- package/transpiled/react/ActionsMenu/index.js +67 -0
- package/transpiled/react/MuiCozyTheme/makeOverrides.js +5 -9
- package/transpiled/react/Viewer/Footer/FooterContent.js +3 -0
- package/transpiled/react/index.js +1 -1
- package/transpiled/react/stylesheet.css +1 -1
- package/react/Menu/Button.jsx +0 -17
- package/react/Menu/Readme.md +0 -104
- package/react/Menu/index.jsx +0 -207
- package/react/Menu/styles.styl +0 -67
- package/transpiled/react/Menu/Button.js +0 -28
- package/transpiled/react/Menu/index.js +0 -256
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
# [84.0.0](https://github.com/cozy/cozy-ui/compare/v83.4.0...v84.0.0) (2023-04-26)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* Add doc and adjust overrides for Menu from Mui. ([40b5f0d](https://github.com/cozy/cozy-ui/commit/40b5f0d))
|
|
7
|
+
* Add new component ActionsMenu ([d1a57b1](https://github.com/cozy/cozy-ui/commit/d1a57b1))
|
|
8
|
+
* Deprecates ActionMenu, use ActionsMenu instead ([c71f6d8](https://github.com/cozy/cozy-ui/commit/c71f6d8))
|
|
9
|
+
* Remove old deprecated Menu ([36a4f6e](https://github.com/cozy/cozy-ui/commit/36a4f6e))
|
|
10
|
+
* **Viewer:** Limit the average height of the BottomSheet ([ebd964f](https://github.com/cozy/cozy-ui/commit/ebd964f))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### BREAKING CHANGES
|
|
14
|
+
|
|
15
|
+
* You must replace `react/Menu` component by `react/ActionsMenu` or `react/MuiCozyTheme/Menu`. Since`react/Menu` has been depreciated for 3 years now, this should not be a problem.
|
|
16
|
+
|
|
1
17
|
# [83.4.0](https://github.com/cozy/cozy-ui/compare/v83.3.0...v83.4.0) (2023-04-25)
|
|
2
18
|
|
|
3
19
|
|
package/package.json
CHANGED
|
@@ -9,6 +9,7 @@ import ActionMenu from '.'
|
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Add onClose method on every children, to close the menu when clicking them
|
|
12
|
+
* @deprecated This component is depreacated, please use [ActionsMenu](#/ActionsMenu) instead.
|
|
12
13
|
*/
|
|
13
14
|
const ActionMenuWithClose = forwardRef(
|
|
14
15
|
({ onClose, children, ...props }, ref) => {
|
|
@@ -6,6 +6,9 @@ import BottomSheet from '../BottomSheet'
|
|
|
6
6
|
|
|
7
7
|
import NotInlineWrapper from './NotInlineWrapper'
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated This component is depreacated, please use [ActionsMenu](#/ActionsMenu) instead.
|
|
11
|
+
*/
|
|
9
12
|
const ActionMenuWrapper = ({
|
|
10
13
|
onClose,
|
|
11
14
|
anchorElRef,
|
|
@@ -16,10 +16,14 @@ import ActionsItems from './Actions/ActionsItems'
|
|
|
16
16
|
|
|
17
17
|
import styles from './styles.styl'
|
|
18
18
|
|
|
19
|
+
const logDepecratedMenu = createDepreciationLogger()
|
|
19
20
|
const logDepecratedPlacement = createDepreciationLogger()
|
|
20
21
|
const logDepecratedOverflow = createDepreciationLogger()
|
|
21
22
|
const logDepecratedContainer = createDepreciationLogger()
|
|
22
23
|
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated This component is depreacated, please use [ActionsMenu](#/ActionsMenu) instead.
|
|
26
|
+
*/
|
|
23
27
|
const ActionMenu = ({
|
|
24
28
|
className,
|
|
25
29
|
anchorElRef,
|
|
@@ -43,6 +47,9 @@ const ActionMenu = ({
|
|
|
43
47
|
logDepecratedContainer(
|
|
44
48
|
'<ActionMenu containerElRef /> is not needed anymore, it can be removed.'
|
|
45
49
|
)
|
|
50
|
+
logDepecratedMenu(
|
|
51
|
+
'The ActionMenu component has been deprecated and should be replaced by ActionsMenu. More infos: https://docs.cozy.io/cozy-ui/react/#!/ActionsMenu'
|
|
52
|
+
)
|
|
46
53
|
|
|
47
54
|
const { isMobile } = useBreakpoints()
|
|
48
55
|
const containerRef = React.createRef()
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
|
+
|
|
3
|
+
import TelephoneIcon from '../../Icons/Telephone'
|
|
4
|
+
import withActionsLocales from './locales/withActionsLocales'
|
|
5
|
+
import ActionsMenuItem from '../ActionsMenuItem'
|
|
6
|
+
import ListItemIcon from '../../MuiCozyTheme/ListItemIcon'
|
|
7
|
+
import Icon from '../../Icon'
|
|
8
|
+
import ListItemText from '../../ListItemText'
|
|
9
|
+
|
|
10
|
+
export const call = () => {
|
|
11
|
+
return {
|
|
12
|
+
name: 'call',
|
|
13
|
+
action: doc => {
|
|
14
|
+
const phoneNumber = doc?.phone?.[0]?.number
|
|
15
|
+
!!phoneNumber && window.open(`tel:${phoneNumber}`, '_self')
|
|
16
|
+
},
|
|
17
|
+
Component: withActionsLocales(
|
|
18
|
+
forwardRef(({ t, ...props }, ref) => {
|
|
19
|
+
return (
|
|
20
|
+
<ActionsMenuItem {...props} ref={ref}>
|
|
21
|
+
<ListItemIcon>
|
|
22
|
+
<Icon icon={TelephoneIcon} />
|
|
23
|
+
</ListItemIcon>
|
|
24
|
+
<ListItemText primary={t('call')} />
|
|
25
|
+
</ActionsMenuItem>
|
|
26
|
+
)
|
|
27
|
+
})
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
|
+
|
|
3
|
+
import EmailIcon from '../../Icons/Email'
|
|
4
|
+
import withActionsLocales from './locales/withActionsLocales'
|
|
5
|
+
import ActionsMenuItem from '../ActionsMenuItem'
|
|
6
|
+
import ListItemIcon from '../../MuiCozyTheme/ListItemIcon'
|
|
7
|
+
import Icon from '../../Icon'
|
|
8
|
+
import ListItemText from '../../ListItemText'
|
|
9
|
+
|
|
10
|
+
export const emailTo = () => {
|
|
11
|
+
return {
|
|
12
|
+
name: 'emailTo',
|
|
13
|
+
action: doc => {
|
|
14
|
+
const emailAddress = doc?.email?.[0]?.address
|
|
15
|
+
!!emailAddress && window.open(`mailto:${emailAddress}`, '_self')
|
|
16
|
+
},
|
|
17
|
+
Component: withActionsLocales(
|
|
18
|
+
forwardRef(({ t, ...props }, ref) => {
|
|
19
|
+
return (
|
|
20
|
+
<ActionsMenuItem {...props} ref={ref}>
|
|
21
|
+
<ListItemIcon>
|
|
22
|
+
<Icon icon={EmailIcon} />
|
|
23
|
+
</ListItemIcon>
|
|
24
|
+
<ListItemText primary={t('emailTo')} />
|
|
25
|
+
</ActionsMenuItem>
|
|
26
|
+
)
|
|
27
|
+
})
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Make array of actions for ActionsItems component
|
|
3
|
+
*
|
|
4
|
+
* @param {Function[]} actions - Array of actions to create ActionsMenuItem components with associated actions and conditions
|
|
5
|
+
* @param {object} actionOptions - Options that need to be passed on actions
|
|
6
|
+
* @returns {object[]} Array of actions
|
|
7
|
+
*/
|
|
8
|
+
export const makeActions = (actions = [], options = {}) => {
|
|
9
|
+
return actions.map(action => {
|
|
10
|
+
const actionMenu = action(options)
|
|
11
|
+
const name = actionMenu.name || action.name
|
|
12
|
+
|
|
13
|
+
return { [name]: actionMenu }
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const getActionName = actionObject => {
|
|
18
|
+
return Object.keys(actionObject)[0]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// We need to clean Actions since action has a displayable
|
|
22
|
+
// conditions and we can't know from the begining what the
|
|
23
|
+
// behavior will be. For instance, we can't know that
|
|
24
|
+
// hr will be the latest action in the sharing views for a
|
|
25
|
+
// folder.
|
|
26
|
+
// Or we can't know that we'll have two following hr if the
|
|
27
|
+
// display condition for the actions between are true or false
|
|
28
|
+
export const getOnlyNeededActions = (actions, file) => {
|
|
29
|
+
let previousAction = ''
|
|
30
|
+
const displayableActions = actions.filter(actionObject => {
|
|
31
|
+
const actionDefinition = Object.values(actionObject)[0]
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
!actionDefinition.displayCondition ||
|
|
35
|
+
actionDefinition.displayCondition([file])
|
|
36
|
+
)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
displayableActions
|
|
41
|
+
// We do not want to display the same 2 actions in a row
|
|
42
|
+
.map(actionObject => {
|
|
43
|
+
const actionName = getActionName(actionObject)
|
|
44
|
+
|
|
45
|
+
if (previousAction === actionName) {
|
|
46
|
+
previousAction = actionName
|
|
47
|
+
return null
|
|
48
|
+
} else {
|
|
49
|
+
previousAction = actionName
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return actionObject
|
|
53
|
+
})
|
|
54
|
+
.filter(Boolean)
|
|
55
|
+
// We don't want to have an hr as the latest actions available
|
|
56
|
+
.filter((cleanedAction, idx, cleanedActions) => {
|
|
57
|
+
return !(
|
|
58
|
+
getActionName(cleanedAction) === 'hr' &&
|
|
59
|
+
idx === cleanedActions.length - 1
|
|
60
|
+
)
|
|
61
|
+
})
|
|
62
|
+
)
|
|
63
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { makeActions } from './helpers'
|
|
2
|
+
|
|
3
|
+
describe('makeActions', () => {
|
|
4
|
+
it('should have empty actions array', () => {
|
|
5
|
+
const actions = makeActions()
|
|
6
|
+
|
|
7
|
+
expect(actions).toStrictEqual([])
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it('should have object with key named with name property of the object returned by the function and value is the full object returned by the function', () => {
|
|
11
|
+
const mockFuncActionWithName = jest.fn(() => ({
|
|
12
|
+
name: 'mockFuncActionWithName name'
|
|
13
|
+
}))
|
|
14
|
+
|
|
15
|
+
const actions = makeActions([mockFuncActionWithName])
|
|
16
|
+
|
|
17
|
+
expect(actions).toStrictEqual([
|
|
18
|
+
{
|
|
19
|
+
'mockFuncActionWithName name': {
|
|
20
|
+
name: 'mockFuncActionWithName name'
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
])
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('should have object with key named with name of function passed and value is the full object returned by the function', () => {
|
|
27
|
+
const mockFuncActionWithoutName = jest.fn(() => ({
|
|
28
|
+
propA: 0,
|
|
29
|
+
propB: 1
|
|
30
|
+
}))
|
|
31
|
+
|
|
32
|
+
const actions = makeActions([mockFuncActionWithoutName])
|
|
33
|
+
|
|
34
|
+
expect(actions).toStrictEqual([{ mockConstructor: { propA: 0, propB: 1 } }])
|
|
35
|
+
})
|
|
36
|
+
})
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { makeActions } from './helpers'
|
|
2
|
+
export { divider } from './divider'
|
|
3
|
+
export { modify } from './modify'
|
|
4
|
+
export { smsTo } from './smsTo'
|
|
5
|
+
export { call } from './call'
|
|
6
|
+
export { emailTo } from './emailTo'
|
|
7
|
+
export { viewInContacts } from './viewInContacts'
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import withLocales from '../../../I18n/withLocales'
|
|
2
|
+
|
|
3
|
+
import en from '../../../ActionMenu/Actions/locales/en.json'
|
|
4
|
+
import fr from '../../../ActionMenu/Actions/locales/fr.json'
|
|
5
|
+
|
|
6
|
+
export const locales = {
|
|
7
|
+
en,
|
|
8
|
+
fr
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default withLocales(locales)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
|
+
|
|
3
|
+
import { generateWebLink } from 'cozy-client'
|
|
4
|
+
|
|
5
|
+
import ListItemIcon from '../../MuiCozyTheme/ListItemIcon'
|
|
6
|
+
import ListItemText from '../../ListItemText'
|
|
7
|
+
import Icon from '../../Icon'
|
|
8
|
+
import PenIcon from '../../Icons/Pen'
|
|
9
|
+
import ActionsMenuItem from '../ActionsMenuItem'
|
|
10
|
+
import withActionsLocales from './locales/withActionsLocales'
|
|
11
|
+
|
|
12
|
+
export const modify = () => {
|
|
13
|
+
return {
|
|
14
|
+
name: 'modify',
|
|
15
|
+
action: (doc, { client }) => {
|
|
16
|
+
const contactId = doc._id
|
|
17
|
+
|
|
18
|
+
const webLink = generateWebLink({
|
|
19
|
+
slug: 'contacts',
|
|
20
|
+
cozyUrl: client.getStackClient().uri,
|
|
21
|
+
subDomainType: client.getInstanceOptions().subdomain,
|
|
22
|
+
pathname: '/',
|
|
23
|
+
hash: `/${contactId}/edit`
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
window.open(webLink, '_blank')
|
|
27
|
+
},
|
|
28
|
+
Component: withActionsLocales(
|
|
29
|
+
forwardRef(({ t, ...props }, ref) => {
|
|
30
|
+
return (
|
|
31
|
+
<ActionsMenuItem ref={ref} {...props}>
|
|
32
|
+
<ListItemIcon>
|
|
33
|
+
<Icon icon={PenIcon} />
|
|
34
|
+
</ListItemIcon>
|
|
35
|
+
<ListItemText primary={t('modify')} />
|
|
36
|
+
</ActionsMenuItem>
|
|
37
|
+
)
|
|
38
|
+
})
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
|
+
|
|
3
|
+
import CommentIcon from '../../Icons/Comment'
|
|
4
|
+
import withActionsLocales from './locales/withActionsLocales'
|
|
5
|
+
import ActionsMenuItem from '../ActionsMenuItem'
|
|
6
|
+
import ListItemIcon from '../../MuiCozyTheme/ListItemIcon'
|
|
7
|
+
import Icon from '../../Icon'
|
|
8
|
+
import ListItemText from '../../ListItemText'
|
|
9
|
+
|
|
10
|
+
export const smsTo = () => {
|
|
11
|
+
return {
|
|
12
|
+
name: 'smsTo',
|
|
13
|
+
action: doc => {
|
|
14
|
+
const phoneNumber = doc?.phone?.[0]?.number
|
|
15
|
+
!!phoneNumber && window.open(`sms:${phoneNumber}`, '_self')
|
|
16
|
+
},
|
|
17
|
+
Component: withActionsLocales(
|
|
18
|
+
forwardRef(({ t, ...props }, ref) => {
|
|
19
|
+
return (
|
|
20
|
+
<ActionsMenuItem {...props} ref={ref}>
|
|
21
|
+
<ListItemIcon>
|
|
22
|
+
<Icon icon={CommentIcon} />
|
|
23
|
+
</ListItemIcon>
|
|
24
|
+
<ListItemText primary={t('smsTo')} />
|
|
25
|
+
</ActionsMenuItem>
|
|
26
|
+
)
|
|
27
|
+
})
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
|
+
|
|
3
|
+
import { generateWebLink } from 'cozy-client'
|
|
4
|
+
|
|
5
|
+
import OpenappIcon from '../../Icons/Openapp'
|
|
6
|
+
import withActionsLocales from './locales/withActionsLocales'
|
|
7
|
+
import ActionsMenuItem from '../ActionsMenuItem'
|
|
8
|
+
import ListItemIcon from '../../MuiCozyTheme/ListItemIcon'
|
|
9
|
+
import Icon from '../../Icon'
|
|
10
|
+
import ListItemText from '../../ListItemText'
|
|
11
|
+
|
|
12
|
+
export const viewInContacts = () => {
|
|
13
|
+
return {
|
|
14
|
+
name: 'viewInContacts',
|
|
15
|
+
action: (doc, { client }) => {
|
|
16
|
+
const contactId = doc._id
|
|
17
|
+
|
|
18
|
+
const webLink = generateWebLink({
|
|
19
|
+
slug: 'contacts',
|
|
20
|
+
cozyUrl: client.getStackClient().uri,
|
|
21
|
+
subDomainType: client.getInstanceOptions().subdomain,
|
|
22
|
+
pathname: '/',
|
|
23
|
+
hash: `/${contactId}`
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
window.open(webLink, '_blank')
|
|
27
|
+
},
|
|
28
|
+
Component: withActionsLocales(
|
|
29
|
+
forwardRef(({ t, ...props }, ref) => {
|
|
30
|
+
return (
|
|
31
|
+
<ActionsMenuItem ref={ref} {...props}>
|
|
32
|
+
<ListItemIcon>
|
|
33
|
+
<Icon icon={OpenappIcon} />
|
|
34
|
+
</ListItemIcon>
|
|
35
|
+
<ListItemText primary={t('viewInContacts')} />
|
|
36
|
+
</ActionsMenuItem>
|
|
37
|
+
)
|
|
38
|
+
})
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React, { forwardRef, useMemo } from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
|
|
4
|
+
import { useClient } from 'cozy-client'
|
|
5
|
+
import { useI18n } from '../I18n'
|
|
6
|
+
import { getActionName, getOnlyNeededActions } from './Actions/helpers'
|
|
7
|
+
|
|
8
|
+
const ActionsItems = forwardRef(
|
|
9
|
+
({ doc, actions, isLast, setIsRenaming, onClick, ...props }, ref) => {
|
|
10
|
+
const client = useClient()
|
|
11
|
+
const { t } = useI18n()
|
|
12
|
+
const cleanedActions = useMemo(() => getOnlyNeededActions(actions, doc), [
|
|
13
|
+
actions,
|
|
14
|
+
doc
|
|
15
|
+
])
|
|
16
|
+
|
|
17
|
+
return cleanedActions.map((actionObject, idx) => {
|
|
18
|
+
const actionName = getActionName(actionObject)
|
|
19
|
+
const actionDefinition = Object.values(actionObject)[0]
|
|
20
|
+
|
|
21
|
+
const { Component: ActionComponent, action, isEnabled } = actionDefinition
|
|
22
|
+
|
|
23
|
+
const handleClick = () => {
|
|
24
|
+
action && action(doc, { client, t, isLast })
|
|
25
|
+
actionName === 'rename' && setIsRenaming(true)
|
|
26
|
+
onClick && onClick()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<ActionComponent
|
|
31
|
+
{...props}
|
|
32
|
+
ref={ref}
|
|
33
|
+
key={actionName + idx}
|
|
34
|
+
isEnabled={isEnabled}
|
|
35
|
+
doc={doc}
|
|
36
|
+
onClick={handleClick}
|
|
37
|
+
/>
|
|
38
|
+
)
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
ActionsItems.propTypes = {
|
|
44
|
+
doc: PropTypes.object,
|
|
45
|
+
actions: PropTypes.array,
|
|
46
|
+
isLast: PropTypes.bool,
|
|
47
|
+
setIsRenaming: PropTypes.func,
|
|
48
|
+
onClick: PropTypes.func
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export default ActionsItems
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
|
|
4
|
+
import MenuItem from 'cozy-ui/transpiled/react/MenuItem'
|
|
5
|
+
import ListItem from 'cozy-ui/transpiled/react/MuiCozyTheme/ListItem'
|
|
6
|
+
|
|
7
|
+
const ActionsMenuItem = forwardRef(({ isListItem, ...props }, ref) => {
|
|
8
|
+
const Component = isListItem ? ListItem : MenuItem
|
|
9
|
+
|
|
10
|
+
return <Component {...props} ref={ref} button />
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
ActionsMenuItem.propTypes = {
|
|
14
|
+
/** Whether the ActionsMenuItem will return a ListItem or MenuItem */
|
|
15
|
+
isListItem: PropTypes.bool
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default ActionsMenuItem
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
|
|
4
|
+
import ActionsMenuItem from './ActionsMenuItem'
|
|
5
|
+
import Divider from '../MuiCozyTheme/Divider'
|
|
6
|
+
import useBreakpoints from '../hooks/useBreakpoints'
|
|
7
|
+
|
|
8
|
+
const ActionsMenuMobileHeader = forwardRef(({ children, ...props }, ref) => {
|
|
9
|
+
const { isMobile } = useBreakpoints()
|
|
10
|
+
|
|
11
|
+
// To make accessibility work, we need to return a displayed item.
|
|
12
|
+
// The trick is to return an empty one with no padding to simulate a display none.
|
|
13
|
+
// Otherwise it will be impossible to use keyboard navigation for example
|
|
14
|
+
// probably due to the inner workings of Mui
|
|
15
|
+
if (!isMobile) {
|
|
16
|
+
return <ActionsMenuItem {...props} ref={ref} className="u-p-0" />
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<>
|
|
21
|
+
<ActionsMenuItem {...props} ref={ref} isListItem>
|
|
22
|
+
{children}
|
|
23
|
+
</ActionsMenuItem>
|
|
24
|
+
<Divider className="u-mv-half" />
|
|
25
|
+
</>
|
|
26
|
+
)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
ActionsMenuMobileHeader.propTypes = {
|
|
30
|
+
children: PropTypes.node
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default ActionsMenuMobileHeader
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
|
|
4
|
+
import Menu from '../MuiCozyTheme/Menu'
|
|
5
|
+
import useBreakpoints from '../hooks/useBreakpoints'
|
|
6
|
+
import BottomSheet from '../BottomSheet'
|
|
7
|
+
import isTesting from '../helpers/isTesting'
|
|
8
|
+
import Paper from '../Paper'
|
|
9
|
+
import { useActionMenuEffects } from '../ActionMenu/ActionMenuEffects'
|
|
10
|
+
|
|
11
|
+
const ActionsMenuWrapper = ({ children, autoClose, onClose, ...props }) => {
|
|
12
|
+
const { isMobile } = useBreakpoints()
|
|
13
|
+
|
|
14
|
+
useActionMenuEffects()
|
|
15
|
+
|
|
16
|
+
const overrideClick = props => () => {
|
|
17
|
+
props.onClick?.()
|
|
18
|
+
autoClose && onClose?.()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (isMobile) {
|
|
22
|
+
return (
|
|
23
|
+
<BottomSheet skipAnimation={isTesting()} backdrop onClose={onClose}>
|
|
24
|
+
<Paper square>
|
|
25
|
+
{React.Children.map(children, child =>
|
|
26
|
+
React.cloneElement(child, {
|
|
27
|
+
isListItem: true,
|
|
28
|
+
size: 'small',
|
|
29
|
+
onClick: overrideClick(child.props)
|
|
30
|
+
})
|
|
31
|
+
)}
|
|
32
|
+
</Paper>
|
|
33
|
+
</BottomSheet>
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<Menu {...props} onClose={onClose}>
|
|
39
|
+
{React.Children.map(children, child =>
|
|
40
|
+
React.cloneElement(child, {
|
|
41
|
+
onClick: overrideClick(child.props)
|
|
42
|
+
})
|
|
43
|
+
)}
|
|
44
|
+
</Menu>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
ActionsMenuWrapper.propTypes = {
|
|
49
|
+
/** Whether the menu should automatically close itself when an item is clicked */
|
|
50
|
+
autoClose: PropTypes.bool,
|
|
51
|
+
/** Function triggered when closing the Menu of BottomSheet */
|
|
52
|
+
onClose: PropTypes.func
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default ActionsMenuWrapper
|