@automattic/vip-design-system 0.18.5-0 → 0.19.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.
@@ -153,7 +153,8 @@ var WithDialog = function WithDialog() {
153
153
 
154
154
  var _React$useState5 = _react["default"].useState(false),
155
155
  menuOpen = _React$useState5[0],
156
- setMenuOpen = _React$useState5[1];
156
+ setMenuOpen = _React$useState5[1]; // eslint-disable-next-line react/prop-types
157
+
157
158
 
158
159
  var AreYouSureDialog = function AreYouSureDialog(_ref) {
159
160
  var onConfirm = _ref.onConfirm,
@@ -7,6 +7,8 @@ exports.NewDialog = void 0;
7
7
 
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
 
10
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
11
+
10
12
  var _react = _interopRequireDefault(require("react"));
11
13
 
12
14
  var _propTypes = _interopRequireDefault(require("prop-types"));
@@ -25,19 +27,12 @@ var _DialogContent = require("./DialogContent");
25
27
 
26
28
  var _jsxRuntime = require("theme-ui/jsx-runtime");
27
29
 
30
+ var _excluded = ["trigger", "description", "title", "content", "showHeading", "disabled", "style", "contentProps", "portalProps"];
31
+
28
32
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
29
33
 
30
34
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
31
35
 
32
- /** @jsxImportSource theme-ui */
33
-
34
- /**
35
- * External dependencies
36
- */
37
-
38
- /**
39
- * Internal dependencies
40
- */
41
36
  var NewDialog = function NewDialog(_ref) {
42
37
  var _ref$trigger = _ref.trigger,
43
38
  trigger = _ref$trigger === void 0 ? null : _ref$trigger,
@@ -54,20 +49,9 @@ var NewDialog = function NewDialog(_ref) {
54
49
  contentProps = _ref$contentProps === void 0 ? {} : _ref$contentProps,
55
50
  _ref$portalProps = _ref.portalProps,
56
51
  portalProps = _ref$portalProps === void 0 ? {} : _ref$portalProps,
57
- _ref$defaultOpen = _ref.defaultOpen,
58
- defaultOpen = _ref$defaultOpen === void 0 ? false : _ref$defaultOpen,
59
- _ref$allowPinchZoom = _ref.allowPinchZoom,
60
- allowPinchZoom = _ref$allowPinchZoom === void 0 ? false : _ref$allowPinchZoom,
61
- _ref$onOpenChange = _ref.onOpenChange,
62
- onOpenChange = _ref$onOpenChange === void 0 ? undefined : _ref$onOpenChange,
63
- _ref$open = _ref.open,
64
- open = _ref$open === void 0 ? undefined : _ref$open,
65
- _ref$id = _ref.id,
66
- id = _ref$id === void 0 ? undefined : _ref$id;
67
-
68
- var _React$useState = _react["default"].useState(open || defaultOpen),
69
- isOpen = _React$useState[0],
70
- setIsOpen = _React$useState[1];
52
+ props = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
53
+
54
+ var closeRef = _react["default"].useRef(null);
71
55
 
72
56
  if (disabled) {
73
57
  return;
@@ -76,24 +60,13 @@ var NewDialog = function NewDialog(_ref) {
76
60
 
77
61
  var isContentFunction = typeof content === 'function';
78
62
 
79
- var handleOnOpenChange = function handleOnOpenChange(status) {
80
- setIsOpen(status);
63
+ var onClose = function onClose() {
64
+ var _closeRef$current;
81
65
 
82
- if (onOpenChange) {
83
- onOpenChange(status);
84
- }
66
+ closeRef == null ? void 0 : (_closeRef$current = closeRef.current) == null ? void 0 : _closeRef$current.click();
85
67
  };
86
68
 
87
- _react["default"].useEffect(function () {
88
- handleOnOpenChange(open);
89
- }, [open]);
90
-
91
- return (0, _jsxRuntime.jsxs)(DialogPrimitive.Root, {
92
- id: id,
93
- open: isOpen,
94
- onOpenChange: handleOnOpenChange,
95
- defaultOpen: defaultOpen,
96
- allowPinchZoom: allowPinchZoom,
69
+ return (0, _jsxRuntime.jsxs)(DialogPrimitive.Root, (0, _extends2["default"])({}, props, {
97
70
  children: [trigger && (0, _jsxRuntime.jsx)(DialogPrimitive.Trigger, {
98
71
  asChild: true,
99
72
  children: trigger
@@ -102,7 +75,9 @@ var NewDialog = function NewDialog(_ref) {
102
75
  className: "vip-dialog-component",
103
76
  sx: (0, _extends2["default"])({}, _DialogContent.contentStyles, extraStyles)
104
77
  }, contentProps, {
105
- children: [(0, _jsxRuntime.jsx)(_DialogClose.DialogCloseDefault, {}), (0, _jsxRuntime.jsx)(_DialogTitle.DialogTitle, {
78
+ children: [(0, _jsxRuntime.jsx)(_DialogClose.DialogCloseDefault, {
79
+ ref: closeRef
80
+ }), (0, _jsxRuntime.jsx)(_DialogTitle.DialogTitle, {
106
81
  title: title,
107
82
  hidden: !showHeading
108
83
  }), (0, _jsxRuntime.jsx)(_DialogDescription.DialogDescription, {
@@ -111,14 +86,12 @@ var NewDialog = function NewDialog(_ref) {
111
86
  }), (0, _jsxRuntime.jsx)("div", {
112
87
  role: "document",
113
88
  children: isContentFunction ? content({
114
- onClose: function onClose() {
115
- return setIsOpen(false);
116
- }
89
+ onClose: onClose
117
90
  }) : content
118
91
  })]
119
92
  }))]
120
93
  }))]
121
- });
94
+ }));
122
95
  };
123
96
 
124
97
  exports.NewDialog = NewDialog;
@@ -133,12 +106,5 @@ NewDialog.propTypes = {
133
106
  // Content props in: https://www.radix-ui.com/docs/primitives/components/dialog#content
134
107
  contentProps: _propTypes["default"].any,
135
108
  // Portal props in: https://www.radix-ui.com/docs/primitives/components/dialog#portal
136
- portalProps: _propTypes["default"].any,
137
- // Radix DialogPrimitive.Root properties
138
- // https://www.radix-ui.com/docs/primitives/components/dialog#root
139
- id: _propTypes["default"].string,
140
- open: _propTypes["default"].bool,
141
- defaultOpen: _propTypes["default"].bool,
142
- allowPinchZoom: _propTypes["default"].bool,
143
- onOpenChange: _propTypes["default"].func
109
+ portalProps: _propTypes["default"].any
144
110
  };
@@ -225,7 +225,7 @@ var CustomStateManagement = function CustomStateManagement() {
225
225
  onOpenChange: function onOpenChange(status) {
226
226
  // eslint-disable-next-line no-console
227
227
  console.log('New status changed', status);
228
- setOpen(!!open);
228
+ setOpen(!open);
229
229
  },
230
230
  trigger: (0, _jsxRuntime.jsx)(_system.Button, {
231
231
  children: "Trigger Dialog"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/vip-design-system",
3
- "version": "0.18.5-0",
3
+ "version": "0.19.0",
4
4
  "main": "build/system/index.js",
5
5
  "scripts": {
6
6
  "build-storybook": "build-storybook",
@@ -117,6 +117,7 @@ export const WithDialog = () => {
117
117
  const [ alertOpen, setAlertOpen ] = React.useState( false );
118
118
  const [ menuOpen, setMenuOpen ] = React.useState( false );
119
119
 
120
+ // eslint-disable-next-line react/prop-types
120
121
  const AreYouSureDialog = ( { onConfirm, ...props } ) => (
121
122
  <NewDialog.Root
122
123
  { ...props }
@@ -125,7 +126,6 @@ export const WithDialog = () => {
125
126
  <Button variant="secondary" onClick={ () => onConfirm() }>
126
127
  Custom Close.
127
128
  </Button>
128
-
129
129
  <p>Teste abc.</p>
130
130
  </>
131
131
  }
@@ -25,15 +25,9 @@ export const NewDialog = ( {
25
25
  style: extraStyles,
26
26
  contentProps = {},
27
27
  portalProps = {},
28
-
29
- // Radix Specific Properties
30
- defaultOpen = false,
31
- allowPinchZoom = false,
32
- onOpenChange = undefined,
33
- open = undefined,
34
- id = undefined,
28
+ ...props
35
29
  } ) => {
36
- const [ isOpen, setIsOpen ] = React.useState( open || defaultOpen );
30
+ const closeRef = React.useRef( null );
37
31
 
38
32
  if ( disabled ) {
39
33
  return;
@@ -42,26 +36,12 @@ export const NewDialog = ( {
42
36
  // if content is a function, pass in onClose
43
37
  const isContentFunction = typeof content === 'function';
44
38
 
45
- const handleOnOpenChange = status => {
46
- setIsOpen( status );
47
-
48
- if ( onOpenChange ) {
49
- onOpenChange( status );
50
- }
39
+ const onClose = () => {
40
+ closeRef?.current?.click();
51
41
  };
52
42
 
53
- React.useEffect( () => {
54
- handleOnOpenChange( open );
55
- }, [ open ] );
56
-
57
43
  return (
58
- <DialogPrimitive.Root
59
- id={ id }
60
- open={ isOpen }
61
- onOpenChange={ handleOnOpenChange }
62
- defaultOpen={ defaultOpen }
63
- allowPinchZoom={ allowPinchZoom }
64
- >
44
+ <DialogPrimitive.Root { ...props }>
65
45
  { trigger && <DialogPrimitive.Trigger asChild>{ trigger }</DialogPrimitive.Trigger> }
66
46
 
67
47
  <DialogPrimitive.Portal { ...portalProps }>
@@ -72,13 +52,11 @@ export const NewDialog = ( {
72
52
  sx={ { ...contentStyles, ...extraStyles } }
73
53
  { ...contentProps }
74
54
  >
75
- <DialogClose />
55
+ <DialogClose ref={ closeRef } />
76
56
  <DialogTitle title={ title } hidden={ ! showHeading } />
77
57
  <DialogDescription description={ description } hidden={ ! showHeading } />
78
58
 
79
- <div role="document">
80
- { isContentFunction ? content( { onClose: () => setIsOpen( false ) } ) : content }
81
- </div>
59
+ <div role="document">{ isContentFunction ? content( { onClose } ) : content }</div>
82
60
  </DialogPrimitive.Content>
83
61
  </DialogPrimitive.Portal>
84
62
  </DialogPrimitive.Root>
@@ -99,12 +77,4 @@ NewDialog.propTypes = {
99
77
 
100
78
  // Portal props in: https://www.radix-ui.com/docs/primitives/components/dialog#portal
101
79
  portalProps: PropTypes.any,
102
-
103
- // Radix DialogPrimitive.Root properties
104
- // https://www.radix-ui.com/docs/primitives/components/dialog#root
105
- id: PropTypes.string,
106
- open: PropTypes.bool,
107
- defaultOpen: PropTypes.bool,
108
- allowPinchZoom: PropTypes.bool,
109
- onOpenChange: PropTypes.func,
110
80
  };
@@ -155,7 +155,7 @@ export const CustomStateManagement = () => {
155
155
  // eslint-disable-next-line no-console
156
156
  console.log( 'New status changed', status );
157
157
 
158
- setOpen( !! open );
158
+ setOpen( ! open );
159
159
  } }
160
160
  trigger={ <Button>Trigger Dialog</Button> }
161
161
  content={