diff --git a/example/src/components/UConfirmationButtonExample.js b/example/src/components/UConfirmationButtonExample.js
index 1be1ccd0d..0bc95930b 100644
--- a/example/src/components/UConfirmationButtonExample.js
+++ b/example/src/components/UConfirmationButtonExample.js
@@ -1,12 +1,36 @@
-import React from 'react'
+import React, { useState } from 'react'
import { UConfirmationButton } from 'unicef-material-ui'
-import { Typography, Grid } from '@material-ui/core'
+import {
+ Typography,
+ Grid,
+ IconButton,
+ Menu,
+ MenuItem,
+ Link,
+} from '@material-ui/core'
import LinkOffIcon from '@material-ui/icons/LinkOff'
+import MoreVertIcon from '@material-ui/icons/MoreVert'
+
export default function UConfirmationButtonExample() {
- const itemId = 1
+ const [anchorEl, setAnchorEl] = useState({ menu: null, popup: null })
+ const openMenuVariant = Boolean(anchorEl.menu)
+ const openPopupVariant = Boolean(anchorEl.popup)
+
function handleDelete(event, id) {
console.log(id)
}
+ function handleClick(event, type) {
+ setAnchorEl({
+ ...anchorEl,
+ [type]: event.currentTarget,
+ })
+ }
+ function handleClose(type) {
+ setAnchorEl({
+ ...anchorEl,
+ [type]: null,
+ })
+ }
return (
@@ -15,46 +39,154 @@ export default function UConfirmationButtonExample() {
Confirmation button
-
- Popup variant
-
+
+ Confirm popup variant
-
- Icon variant
-
+
+
+ Icon
+
+
+
+ Menu item
+ handleClick(e, 'popup')}
+ >
+
+
+
+
+
+ Button
+
+
+
+ Custom icon
+ }
+ />
+
-
- Menu item variant
-
+
+ Confirm menu variant
-
-
- Custom icon and confirm text
-
- }
- />
+
+
+ Icon
+
+
+
+ Menu item
+ handleClick(e, 'menu')}
+ >
+
+
+
+
+
+ Button
+
+
+
+ Custom icon
+ }
+ />
+
)
diff --git a/package.json b/package.json
index 3c2b14d25..3ded84618 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@unicef/material-ui",
- "version": "0.11.5",
+ "version": "0.11.6",
"description": "UNICEF theme and components of material-ui for react",
"main": "index.js",
"files": [
diff --git a/src/components/UConfirmationButton/UConfirmationButton.js b/src/components/UConfirmationButton/UConfirmationButton.js
index fa26e9068..b2be22f57 100644
--- a/src/components/UConfirmationButton/UConfirmationButton.js
+++ b/src/components/UConfirmationButton/UConfirmationButton.js
@@ -10,6 +10,7 @@ import {
DialogContent,
Typography,
DialogActions,
+ Box,
} from '@material-ui/core'
import DeleteOutlinedIcon from '@material-ui/icons/DeleteOutlined'
import UButton from '../UButton'
@@ -27,9 +28,14 @@ const useStyles = makeStyles(theme => ({
}))
const CONTROL_VARIANTS = {
- popup: 'popup',
menuItem: 'menuItem',
icon: 'icon',
+ button: 'button',
+}
+
+const CONFIRMATION_VARIANTS = {
+ menu: 'menu',
+ popup: 'popup',
}
/**
@@ -49,13 +55,19 @@ export default function UConfirmationButton(props) {
confirmText,
confirmActionText,
cancelText,
+ buttonVariant,
+ confirmVariant,
} = props
const [deleteAnchorEl, setDeleteAnchorEl] = useState(null)
const [openDialog, setOpenDialog] = useState(false)
const handleConfirm = e => {
onConfirm && onConfirm(e, id)
- if (variant !== CONTROL_VARIANTS.popup) handleDeleteOptionClicked(e)
+ if (confirmVariant === CONFIRMATION_VARIANTS.popup) {
+ setOpenDialog(false)
+ } else {
+ handleDeleteOptionClicked(e)
+ }
}
const handleDeleteOptionClicked = e => {
@@ -63,8 +75,11 @@ export default function UConfirmationButton(props) {
}
const handleClick = e => {
- if (variant !== CONTROL_VARIANTS.popup) setDeleteAnchorEl(e.currentTarget)
- else setOpenDialog(true)
+ if (confirmVariant === CONFIRMATION_VARIANTS.popup) {
+ setOpenDialog(true)
+ } else {
+ setDeleteAnchorEl(e.currentTarget)
+ }
}
const handleCancelPopup = e => {
@@ -76,8 +91,20 @@ export default function UConfirmationButton(props) {
{variant === CONTROL_VARIANTS.menuItem ? (
+ ) : variant === CONTROL_VARIANTS.button ? (
+
+ {buttonText}
+
) : (
)}
- {variant === CONTROL_VARIANTS.popup ? (
+ {confirmVariant === CONFIRMATION_VARIANTS.popup ? (