cozy-ui 128.3.4 → 128.4.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,17 @@
1
+ # [128.4.0](https://github.com/cozy/cozy-ui/compare/v128.3.5...v128.4.0) (2025-09-04)
2
+
3
+
4
+ ### Features
5
+
6
+ * **Providers:** Add ConfirmDialog providers ([464286c](https://github.com/cozy/cozy-ui/commit/464286c))
7
+
8
+ ## [128.3.5](https://github.com/cozy/cozy-ui/compare/v128.3.4...v128.3.5) (2025-09-04)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * Postinstall hook not working using Yarn 4 ([ce9711f](https://github.com/cozy/cozy-ui/commit/ce9711f))
14
+
1
15
  ## [128.3.4](https://github.com/cozy/cozy-ui/compare/v128.3.3...v128.3.4) (2025-09-04)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "128.3.4",
3
+ "version": "128.4.0",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -50,7 +50,7 @@
50
50
  "test": "jest",
51
51
  "screenshots:server": "nodemon ./scripts/pixelmatch-server/server.js -e js,hbs",
52
52
  "postbuild": "postcss transpiled/react/stylesheet.css --replace",
53
- "postinstall": "if [ -d 'node_modules/@fastify/deepmerge' ]; then patch-package; fi",
53
+ "postinstall": "/bin/bash -c 'if [ -d node_modules/@fastify/deepmerge ]; then patch-package; fi'",
54
54
  "travis-deploy-once": "travis-deploy-once",
55
55
  "start:css:utils": "yarn build:css:utils --watch",
56
56
  "start:css": "yarn build:css --watch",
@@ -0,0 +1,30 @@
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 } = 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: <Button label="Ok" />
17
+ })
18
+ }
19
+ />
20
+ )
21
+ }
22
+
23
+ ;
24
+
25
+ <DemoProvider>
26
+ <ConfirmDialogProvider>
27
+ <Component />
28
+ </ConfirmDialogProvider>
29
+ </DemoProvider>
30
+ ```
@@ -0,0 +1,59 @@
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
+ }),
39
+ []
40
+ )
41
+
42
+ return (
43
+ <ConfirmDialogContext.Provider value={value}>
44
+ {children}
45
+ {open && (
46
+ <ConfirmDialog
47
+ open
48
+ title={title}
49
+ content={content}
50
+ actions={actions}
51
+ onClose={handleClose(state, setState)}
52
+ {...confirmDialogProps}
53
+ />
54
+ )}
55
+ </ConfirmDialogContext.Provider>
56
+ )
57
+ }
58
+
59
+ export default React.memo(ConfirmDialogProvider)
@@ -0,0 +1,7 @@
1
+ export const ConfirmDialogContext: React.Context<any>;
2
+ export function useConfirmDialog(): any;
3
+ declare var _default: React.MemoExoticComponent<({ children }: {
4
+ children: any;
5
+ }) => JSX.Element>;
6
+ export default _default;
7
+ import React from "react";
@@ -0,0 +1,72 @@
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
+ };
60
+ }, []);
61
+ return /*#__PURE__*/React.createElement(ConfirmDialogContext.Provider, {
62
+ value: value
63
+ }, children, open && /*#__PURE__*/React.createElement(ConfirmDialog, _extends({
64
+ open: true,
65
+ title: title,
66
+ content: content,
67
+ actions: actions,
68
+ onClose: handleClose(state, setState)
69
+ }, confirmDialogProps)));
70
+ };
71
+
72
+ export default /*#__PURE__*/React.memo(ConfirmDialogProvider);