@unicef/material-ui 0.11.2 → 0.11.3

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/lib/dev.js CHANGED
@@ -49315,12 +49315,17 @@ var useStyles$n = makeStyles$1(function (theme) {
49315
49315
  };
49316
49316
  });
49317
49317
 
49318
- /**
49319
- * UConfirmationButton is a component to get confirmation from the user before processing it.
49320
- * This button displays the confirmation where user has clicked the button
49321
- * It has two varint icon/menu item
49322
- */
49323
- function UConfirmationButton(props) {
49318
+ var CONTROL_VARIANTS = {
49319
+ popup: 'popup',
49320
+ menuItem: 'menuItem',
49321
+ icon: 'icon'
49322
+
49323
+ /**
49324
+ * UConfirmationButton is a component to get confirmation from the user before processing it.
49325
+ * This button displays the confirmation where user has clicked the button
49326
+ * It has two varint icon/menu item
49327
+ */
49328
+ };function UConfirmationButton(props) {
49324
49329
  var classes = useStyles$n();
49325
49330
  var onConfirm = props.onConfirm,
49326
49331
  id = props.id,
@@ -49330,32 +49335,41 @@ function UConfirmationButton(props) {
49330
49335
  icon = props.icon,
49331
49336
  confirmText = props.confirmText,
49332
49337
  confirmActionText = props.confirmActionText,
49333
- others = objectWithoutProperties(props, ['onConfirm', 'id', 'buttonText', 'enabled', 'variant', 'icon', 'confirmText', 'confirmActionText']);
49338
+ cancelText = props.cancelText;
49334
49339
 
49335
49340
  var _useState = React.useState(null),
49336
49341
  _useState2 = slicedToArray(_useState, 2),
49337
49342
  deleteAnchorEl = _useState2[0],
49338
49343
  setDeleteAnchorEl = _useState2[1];
49339
49344
 
49345
+ var _useState3 = React.useState(false),
49346
+ _useState4 = slicedToArray(_useState3, 2),
49347
+ openDialog = _useState4[0],
49348
+ setOpenDialog = _useState4[1];
49349
+
49340
49350
  var handleConfirm = function handleConfirm(e) {
49341
- onConfirm(e, id);
49342
- handleDeleteOptionClicked();
49351
+ onConfirm && onConfirm(e, id);
49352
+ if (variant !== CONTROL_VARIANTS.popup) handleDeleteOptionClicked();
49343
49353
  };
49344
49354
 
49345
49355
  var handleDeleteOptionClicked = function handleDeleteOptionClicked(e) {
49346
49356
  setDeleteAnchorEl(null);
49347
49357
  };
49358
+
49359
+ var handleClick = function handleClick(e) {
49360
+ if (variant !== CONTROL_VARIANTS.popup) setDeleteAnchorEl(e.currentTarget);else setOpenDialog(true);
49361
+ };
49362
+
49363
+ var handleCancelPopup = function handleCancelPopup(e) {
49364
+ setOpenDialog(false);
49365
+ };
49366
+
49348
49367
  return React__default.createElement(
49349
49368
  React__default.Fragment,
49350
49369
  null,
49351
- variant === 'menuItem' ? React__default.createElement(
49370
+ variant === CONTROL_VARIANTS.menuItem ? React__default.createElement(
49352
49371
  MenuItem$1,
49353
- {
49354
- onClick: function onClick(e) {
49355
- return setDeleteAnchorEl(e.currentTarget);
49356
- },
49357
- className: classes.menuLabel
49358
- },
49372
+ { onClick: handleClick, className: classes.menuLabel },
49359
49373
  icon,
49360
49374
  React__default.createElement(
49361
49375
  'span',
@@ -49370,16 +49384,40 @@ function UConfirmationButton(props) {
49370
49384
  {
49371
49385
  'aria-controls': 'delete-confirmation-menu-' + id,
49372
49386
  'aria-haspopup': 'true',
49373
- onClick: function onClick(e) {
49374
- return setDeleteAnchorEl(e.currentTarget);
49375
- },
49387
+ onClick: handleClick,
49376
49388
  disabled: !enabled,
49377
49389
  className: classes.menuLabel
49378
49390
  },
49379
49391
  icon
49380
49392
  )
49381
49393
  ),
49382
- React__default.createElement(
49394
+ variant === CONTROL_VARIANTS.popup ? React__default.createElement(
49395
+ Dialog$1,
49396
+ { id: 'delete-confirmation-menu-' + id, open: openDialog },
49397
+ React__default.createElement(
49398
+ DialogContent$1,
49399
+ null,
49400
+ React__default.createElement(
49401
+ Typography$1,
49402
+ { variant: 'body1' },
49403
+ confirmText || ''
49404
+ )
49405
+ ),
49406
+ React__default.createElement(
49407
+ DialogActions$1,
49408
+ null,
49409
+ React__default.createElement(
49410
+ UButton,
49411
+ { onClick: handleCancelPopup, variant: 'uDefault' },
49412
+ cancelText || ''
49413
+ ),
49414
+ React__default.createElement(
49415
+ UButton,
49416
+ { onClick: handleConfirm, variant: 'uPrimary', color: 'primary' },
49417
+ confirmActionText || ''
49418
+ )
49419
+ )
49420
+ ) : React__default.createElement(
49383
49421
  Menu$1,
49384
49422
  {
49385
49423
  id: 'delete-confirmation-menu-' + id,
@@ -49413,9 +49451,11 @@ UConfirmationButton.propTypes = {
49413
49451
  /** trigger confirmation function */
49414
49452
  onConfirm: PropTypes__default.func.isRequired,
49415
49453
  /** variant: menu or icon */
49416
- variant: PropTypes__default.oneOf(['menuItem', 'icon']),
49454
+ variant: PropTypes__default.oneOf([CONTROL_VARIANTS.popup, CONTROL_VARIANTS.menuItem, CONTROL_VARIANTS.icon]),
49417
49455
  /** if the variant is menuitem, this prop make sure the item enable or not */
49418
49456
  enabled: PropTypes__default.bool,
49457
+ /** button cancel text for popup variant */
49458
+ cancelText: PropTypes__default.string,
49419
49459
  /** button confirm text */
49420
49460
  confirmText: PropTypes__default.string,
49421
49461
  /** confirm action text */
@@ -49430,6 +49470,7 @@ UConfirmationButton.defaultProps = {
49430
49470
  enabled: true,
49431
49471
  confirmText: 'Confirm deletion?',
49432
49472
  confirmActionText: 'Yes, delete',
49473
+ cancelText: 'No',
49433
49474
  icon: React__default.createElement(DeleteOutlinedIcon, null)
49434
49475
  };
49435
49476
 
@@ -49609,21 +49650,14 @@ function UAsyncBadge(_ref) {
49609
49650
  }
49610
49651
  }, [variant]);
49611
49652
 
49612
- React.useEffect(function () {
49613
- // When the badge becomes visible, set focus to it.
49614
- if (visible && variant) {
49615
- chipRef.current.focus();
49616
- }
49617
- }, [visible, variant]);
49618
-
49619
49653
  return React__default.createElement(
49620
49654
  'span',
49621
49655
  { className: classes.root },
49622
49656
  visible && React__default.createElement(Chip$1, {
49623
49657
  ref: chipRef,
49624
- tabIndex: 0,
49625
- 'aria-live': 'assertive' // Announce changes to screen readers
49626
- , className: classes.chip + ' ' + classes[variant],
49658
+ role: 'status',
49659
+ 'aria-live': 'polite',
49660
+ className: classes.chip + ' ' + classes[variant],
49627
49661
  avatar: variant === 'loading' ? React__default.createElement(CircularProgress$1, { size: 16 }) : variant === 'error' ? React__default.createElement(HighlightOffIcon, { size: 16 }) : variant === 'success' && React__default.createElement(DoneIcon, { size: 16 }),
49628
49662
  classes: { avatar: classes[variant] },
49629
49663
  size: 'medium',