Skip to content

Commit abfc11d

Browse files
authored
Loading state on confirmation dialog (#452)
* Add loading state to corfirmation dialog button * Update README * Fix default value in story * v2.13.2
1 parent d4b06f8 commit abfc11d

File tree

4 files changed

+50
-4
lines changed

4 files changed

+50
-4
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ export const MyComponent: FC<PropsT> = (props: PropsT) => <>...</>
2020

2121
You can find latest **master** storybook playground [here](https://netdata.github.io/netdata-ui/)
2222

23+
## Local development
24+
25+
First, install the dependencies
26+
```
27+
yarn
28+
```
29+
30+
then, build the project and start
31+
```
32+
yarn build && yarn start
33+
```
34+
35+
Open your browser to [localhost:6006](http://localhost:6006) and view the storybook locally.
36+
37+
2338
## Components
2439

2540
- [Theme and theme utils](https://github.com/netdata/netdata-ui/blob/master/src/theme)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@netdata/netdata-ui",
3-
"version": "2.13.1",
3+
"version": "2.13.2",
44
"description": "netdata UI kit",
55
"main": "./lib/index.js",
66
"files": [

src/components/confirmation-dialog/confirmation-dialog.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import React from "react"
22
import Flex from "src/components/templates/flex"
33
import { Button } from "src/components/button"
44
import { Text } from "src/components/typography"
5+
import useToggle from "react-use/lib/useToggle"
56
import { Actions, Body, CloseButton, Content, Dialog, Header, Title, TitleIcon } from "./styled"
67

78
const BodyMessage = ({ children, ...rest }) =>
89
typeof children === "object" ? children : <Text {...rest}>{children}</Text>
910

1011
const ConfirmationDialog = ({
1112
confirmLabel = "Yes, remove",
13+
confirmLoadingLabel = "Loading...",
1214
confirmWidth = "128px",
1315
"data-ga": dataGA = "confirmation-dialog",
1416
"data-testid": dataTestId = "confirmationDialog",
@@ -22,7 +24,16 @@ const ConfirmationDialog = ({
2224
isConfirmPositive,
2325
message,
2426
title,
27+
showConfirmLoading,
28+
disableConfirmOnLoading,
2529
}) => {
30+
const [loading, toggleLoading] = useToggle(false)
31+
32+
const onConfirm = e => {
33+
if (showConfirmLoading) toggleLoading()
34+
handleConfirm(e, toggleLoading)
35+
}
36+
2637
return (
2738
<Dialog onEsc={handleDecline}>
2839
<Content data-testid={dataTestId}>
@@ -53,10 +64,11 @@ const ConfirmationDialog = ({
5364
data-ga={`${dataGA}-::click-confirm::global-view`}
5465
data-testid={`${dataTestId}-confirmAction`}
5566
danger={!isConfirmPositive && true}
56-
disabled={isConfirmDisabled}
57-
label={confirmLabel}
58-
onClick={handleConfirm}
67+
disabled={isConfirmDisabled || (disableConfirmOnLoading && loading)}
68+
label={loading ? confirmLoadingLabel : confirmLabel}
69+
onClick={onConfirm}
5970
width={confirmWidth}
71+
isLoading={loading}
6072
/>
6173
</Actions>
6274
</Content>

src/components/confirmation-dialog/confirmation-dialog.stories.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,22 @@ Story.add("Confirmation dialog", () => {
1919
/>
2020
)
2121
})
22+
23+
Story.add("Confirmation dialog with loading", () => {
24+
return (
25+
<ConfirmationDialog
26+
confirmLabel="Yes"
27+
declineLabel="Please don't!"
28+
handleConfirm={(_, toggleLoading) => {
29+
console.log("Pressed confirm")
30+
setTimeout(() => toggleLoading(), 2000)
31+
}}
32+
handleDecline={() => alert("Pressed decline")}
33+
isConfirmPositive={boolean("isConfirmPositive", false)}
34+
message="We are about to fulfill your request, there is no return from here. Are you sure?"
35+
title="Are you sure you want to proceed?"
36+
showConfirmLoading={boolean("showConfirmLoading", true)}
37+
disableConfirmOnLoading={boolean("disableConfirmOnLoading", true)}
38+
/>
39+
)
40+
})

0 commit comments

Comments
 (0)