cozy-ui 128.3.5 → 128.5.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 +14 -0
- package/package.json +1 -1
- package/react/DatePicker/Readme.md +3 -1
- package/react/providers/ConfirmDialog/Readme.md +35 -0
- package/react/providers/ConfirmDialog/index.jsx +60 -0
- package/transpiled/react/providers/ConfirmDialog/index.d.ts +7 -0
- package/transpiled/react/providers/ConfirmDialog/index.js +73 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [128.5.0](https://github.com/cozy/cozy-ui/compare/v128.4.0...v128.5.0) (2025-09-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **ConfirmDialogProviders:** Expose method to close the dialog ([7d3d841](https://github.com/cozy/cozy-ui/commit/7d3d841))
|
|
7
|
+
|
|
8
|
+
# [128.4.0](https://github.com/cozy/cozy-ui/compare/v128.3.5...v128.4.0) (2025-09-04)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* **Providers:** Add ConfirmDialog providers ([464286c](https://github.com/cozy/cozy-ui/commit/464286c))
|
|
14
|
+
|
|
1
15
|
## [128.3.5](https://github.com/cozy/cozy-ui/compare/v128.3.4...v128.3.5) (2025-09-04)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
```jsx
|
|
2
|
+
import DemoProvider from 'cozy-ui/docs/components/DemoProvider'
|
|
3
|
+
import ConfirmDialogProvider, { useConfirmDialog } from 'cozy-ui/transpiled/react/providers/ConfirmDialog'
|
|
4
|
+
import Button from 'cozy-ui/transpiled/react/Buttons'
|
|
5
|
+
|
|
6
|
+
const Component = () => {
|
|
7
|
+
const { showConfirmDialog, closeConfirmDialog } = useConfirmDialog()
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<Button
|
|
11
|
+
label="Show ConfirmDialog"
|
|
12
|
+
onClick={() =>
|
|
13
|
+
showConfirmDialog({
|
|
14
|
+
title: "Title of the ConfirmDialog",
|
|
15
|
+
content: "Content of the ConfirmDialog",
|
|
16
|
+
actions: (
|
|
17
|
+
<>
|
|
18
|
+
<Button label="Cancel" variant="secondary" onClick={closeConfirmDialog} />
|
|
19
|
+
<Button label="Ok" />
|
|
20
|
+
</>
|
|
21
|
+
)
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
/>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
;
|
|
29
|
+
|
|
30
|
+
<DemoProvider>
|
|
31
|
+
<ConfirmDialogProvider>
|
|
32
|
+
<Component />
|
|
33
|
+
</ConfirmDialogProvider>
|
|
34
|
+
</DemoProvider>
|
|
35
|
+
```
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React, { createContext, useState, useContext, useMemo } from 'react'
|
|
2
|
+
|
|
3
|
+
import { ConfirmDialog } from '../../CozyDialogs'
|
|
4
|
+
|
|
5
|
+
export const ConfirmDialogContext = createContext()
|
|
6
|
+
|
|
7
|
+
export const useConfirmDialog = () => {
|
|
8
|
+
const context = useContext(ConfirmDialogContext)
|
|
9
|
+
|
|
10
|
+
if (!context) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
'useConfirmDialog must be used within a ConfirmDialogProvider'
|
|
13
|
+
)
|
|
14
|
+
}
|
|
15
|
+
return context
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const defaultState = {
|
|
19
|
+
title: '',
|
|
20
|
+
content: '',
|
|
21
|
+
actions: null,
|
|
22
|
+
open: false
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const handleClose = (state, setState) => () => {
|
|
26
|
+
return setState({ ...state, open: false })
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const ConfirmDialogProvider = ({ children }) => {
|
|
30
|
+
const [state, setState] = useState(defaultState)
|
|
31
|
+
const { open, title, content, actions, ...confirmDialogProps } = state
|
|
32
|
+
|
|
33
|
+
const value = useMemo(
|
|
34
|
+
() => ({
|
|
35
|
+
showConfirmDialog: args => {
|
|
36
|
+
setState({ open: true, ...args })
|
|
37
|
+
},
|
|
38
|
+
closeConfirmDialog: handleClose(state, setState)
|
|
39
|
+
}),
|
|
40
|
+
[state]
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<ConfirmDialogContext.Provider value={value}>
|
|
45
|
+
{children}
|
|
46
|
+
{open && (
|
|
47
|
+
<ConfirmDialog
|
|
48
|
+
open
|
|
49
|
+
title={title}
|
|
50
|
+
content={content}
|
|
51
|
+
actions={actions}
|
|
52
|
+
onClose={handleClose(state, setState)}
|
|
53
|
+
{...confirmDialogProps}
|
|
54
|
+
/>
|
|
55
|
+
)}
|
|
56
|
+
</ConfirmDialogContext.Provider>
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export default React.memo(ConfirmDialogProvider)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
5
|
+
var _excluded = ["open", "title", "content", "actions"];
|
|
6
|
+
|
|
7
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
8
|
+
|
|
9
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
10
|
+
|
|
11
|
+
import React, { createContext, useState, useContext, useMemo } from 'react';
|
|
12
|
+
import { ConfirmDialog } from "cozy-ui/transpiled/react/CozyDialogs";
|
|
13
|
+
export var ConfirmDialogContext = /*#__PURE__*/createContext();
|
|
14
|
+
export var useConfirmDialog = function useConfirmDialog() {
|
|
15
|
+
var context = useContext(ConfirmDialogContext);
|
|
16
|
+
|
|
17
|
+
if (!context) {
|
|
18
|
+
throw new Error('useConfirmDialog must be used within a ConfirmDialogProvider');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return context;
|
|
22
|
+
};
|
|
23
|
+
var defaultState = {
|
|
24
|
+
title: '',
|
|
25
|
+
content: '',
|
|
26
|
+
actions: null,
|
|
27
|
+
open: false
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
var handleClose = function handleClose(state, setState) {
|
|
31
|
+
return function () {
|
|
32
|
+
return setState(_objectSpread(_objectSpread({}, state), {}, {
|
|
33
|
+
open: false
|
|
34
|
+
}));
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
var ConfirmDialogProvider = function ConfirmDialogProvider(_ref) {
|
|
39
|
+
var children = _ref.children;
|
|
40
|
+
|
|
41
|
+
var _useState = useState(defaultState),
|
|
42
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
43
|
+
state = _useState2[0],
|
|
44
|
+
setState = _useState2[1];
|
|
45
|
+
|
|
46
|
+
var open = state.open,
|
|
47
|
+
title = state.title,
|
|
48
|
+
content = state.content,
|
|
49
|
+
actions = state.actions,
|
|
50
|
+
confirmDialogProps = _objectWithoutProperties(state, _excluded);
|
|
51
|
+
|
|
52
|
+
var value = useMemo(function () {
|
|
53
|
+
return {
|
|
54
|
+
showConfirmDialog: function showConfirmDialog(args) {
|
|
55
|
+
setState(_objectSpread({
|
|
56
|
+
open: true
|
|
57
|
+
}, args));
|
|
58
|
+
},
|
|
59
|
+
closeConfirmDialog: handleClose(state, setState)
|
|
60
|
+
};
|
|
61
|
+
}, [state]);
|
|
62
|
+
return /*#__PURE__*/React.createElement(ConfirmDialogContext.Provider, {
|
|
63
|
+
value: value
|
|
64
|
+
}, children, open && /*#__PURE__*/React.createElement(ConfirmDialog, _extends({
|
|
65
|
+
open: true,
|
|
66
|
+
title: title,
|
|
67
|
+
content: content,
|
|
68
|
+
actions: actions,
|
|
69
|
+
onClose: handleClose(state, setState)
|
|
70
|
+
}, confirmDialogProps)));
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export default /*#__PURE__*/React.memo(ConfirmDialogProvider);
|