|
1 | 1 | import React, { useState } from "react"; |
2 | | -import { DxcDialog, DxcButton } from "@dxc-technology/halstack-react"; |
| 2 | +import { |
| 3 | + DxcDialog, |
| 4 | + DxcButton, |
| 5 | + DxcTextInput, |
| 6 | + DxcFlex, |
| 7 | + DxcHeading, |
| 8 | + DxcParagraph, |
| 9 | + DxcAlert, |
| 10 | + DxcTextarea, |
| 11 | + DxcSelect, |
| 12 | + DxcDateInput, |
| 13 | + DxcDropdown, |
| 14 | +} from "@dxc-technology/halstack-react"; |
| 15 | + |
| 16 | +const options = [ |
| 17 | + { |
| 18 | + value: 1, |
| 19 | + label: "Android", |
| 20 | + }, |
| 21 | + { |
| 22 | + value: 2, |
| 23 | + label: "Windows", |
| 24 | + }, |
| 25 | + { |
| 26 | + value: 3, |
| 27 | + label: "IOS", |
| 28 | + }, |
| 29 | +]; |
3 | 30 |
|
4 | 31 | function App() { |
5 | 32 | const [isDialog1Visible, setIsDialog1Visible] = useState(false); |
| 33 | + const [nameValue, setNameValue] = useState(""); |
| 34 | + const [descriptionValue, setDescriptionValue] = useState(""); |
| 35 | + |
6 | 36 | const [isDialog2Visible, setIsDialog2Visible] = useState(false); |
7 | | - const [isDialog3Visible, setIsDialog3Visible] = useState(false); |
| 37 | + const [isVisible, changeIsVisible] = useState(false); |
| 38 | + const [isDisabled, changeIsDisabled] = useState(false); |
| 39 | + const handleDisabled = () => { |
| 40 | + changeIsDisabled((isDisabled) => !isDisabled); |
| 41 | + }; |
8 | 42 |
|
| 43 | + const handleVisibility = () => { |
| 44 | + changeIsVisible((isVisible) => !isVisible); |
| 45 | + }; |
9 | 46 | const onClickDialog1 = () => { |
10 | 47 | setIsDialog1Visible(!isDialog1Visible); |
11 | | - }; |
12 | | - const onClickDialog2 = () => { |
13 | | - setIsDialog2Visible(!isDialog2Visible); |
14 | | - }; |
15 | | - const onClickDialog3 = () => { |
16 | | - setIsDialog3Visible(!isDialog3Visible); |
| 48 | + changeIsVisible(false); |
| 49 | + setNameValue(""); |
| 50 | + setDescriptionValue(""); |
17 | 51 | }; |
18 | 52 |
|
19 | 53 | return ( |
20 | | - <div> |
21 | | - <DxcButton |
22 | | - label="Dialog 1" |
23 | | - onClick={onClickDialog1} |
24 | | - margin="medium" |
25 | | - ></DxcButton> |
| 54 | + <DxcFlex gap="1.5rem"> |
| 55 | + <DxcButton label="Example" onClick={onClickDialog1} /> |
26 | 56 | {isDialog1Visible && ( |
27 | | - <DxcDialog isCloseVisible={true} onCloseClick={onClickDialog1}> |
28 | | - Close Icon |
| 57 | + <DxcDialog onCloseClick={onClickDialog1}> |
| 58 | + <DxcFlex direction="column" gap="2rem"> |
| 59 | + <DxcHeading level={4} text="User form" /> |
| 60 | + <DxcFlex direction="column" gap="1rem"> |
| 61 | + {isVisible && ( |
| 62 | + <DxcAlert |
| 63 | + type="error" |
| 64 | + inlineText="To be valid, you need to fill every field." |
| 65 | + size="fillParent" |
| 66 | + onClose={handleVisibility} |
| 67 | + /> |
| 68 | + )} |
| 69 | + <DxcDropdown label="Options" options={options} /> |
| 70 | + <DxcTextInput |
| 71 | + label="Name" |
| 72 | + value={nameValue} |
| 73 | + onChange={({ value }) => { |
| 74 | + setNameValue(value); |
| 75 | + }} |
| 76 | + size="fillParent" |
| 77 | + disabled={isDisabled} |
| 78 | + tabIndex={-1} |
| 79 | + /> |
| 80 | + <DxcDateInput label="Start date" size="fillParent" /> |
| 81 | + <DxcSelect |
| 82 | + label="Example select" |
| 83 | + options={options} |
| 84 | + size="fillParent" |
| 85 | + /> |
| 86 | + <DxcTextarea |
| 87 | + label="Description" |
| 88 | + value={descriptionValue} |
| 89 | + onChange={({ value }) => { |
| 90 | + setDescriptionValue(value); |
| 91 | + }} |
| 92 | + size="fillParent" |
| 93 | + disabled={isDisabled} |
| 94 | + /> |
| 95 | + </DxcFlex> |
| 96 | + <DxcFlex justifyContent="flex-end" gap="0.5rem"> |
| 97 | + <DxcButton |
| 98 | + label="Disable fields" |
| 99 | + mode="text" |
| 100 | + onClick={handleDisabled} |
| 101 | + /> |
| 102 | + <DxcButton |
| 103 | + label="Cancel" |
| 104 | + mode="secondary" |
| 105 | + onClick={onClickDialog1} |
| 106 | + /> |
| 107 | + <DxcButton |
| 108 | + label="Save" |
| 109 | + onClick={() => { |
| 110 | + if (nameValue === "" || nameValue === "") |
| 111 | + changeIsVisible(true); |
| 112 | + else { |
| 113 | + changeIsVisible(false); |
| 114 | + setIsDialog1Visible(false); |
| 115 | + } |
| 116 | + }} |
| 117 | + /> |
| 118 | + </DxcFlex> |
| 119 | + </DxcFlex> |
29 | 120 | </DxcDialog> |
30 | 121 | )} |
31 | | - |
32 | 122 | <DxcButton |
33 | | - label="Dialog 2" |
34 | | - onClick={onClickDialog2} |
35 | | - margin="medium" |
36 | | - ></DxcButton> |
| 123 | + label="Empty" |
| 124 | + onClick={() => { |
| 125 | + setIsDialog2Visible((isVisible) => !isVisible); |
| 126 | + }} |
| 127 | + /> |
37 | 128 | {isDialog2Visible && ( |
38 | 129 | <DxcDialog |
39 | | - padding="xxlarge" |
40 | | - onBackgroundClick={onClickDialog2} |
41 | 130 | isCloseVisible={false} |
| 131 | + onCloseClick={() => { |
| 132 | + setIsDialog2Visible((isVisible) => !isVisible); |
| 133 | + }} |
| 134 | + onBackgroundClick={() => { |
| 135 | + setIsDialog2Visible((isVisible) => !isVisible); |
| 136 | + }} |
42 | 137 | > |
43 | | - Overlay close |
44 | | - </DxcDialog> |
45 | | - )} |
46 | | - |
47 | | - <DxcButton |
48 | | - label="Dialog 3" |
49 | | - onClick={onClickDialog3} |
50 | | - margin="medium" |
51 | | - ></DxcButton> |
52 | | - {isDialog3Visible && ( |
53 | | - <DxcDialog padding="xxlarge" isCloseVisible={false}> |
54 | | - <DxcButton |
55 | | - label="Close" |
56 | | - onClick={onClickDialog3} |
57 | | - margin="small" |
58 | | - ></DxcButton> |
| 138 | + <DxcParagraph>Example text</DxcParagraph> |
59 | 139 | </DxcDialog> |
60 | 140 | )} |
61 | | - </div> |
| 141 | + </DxcFlex> |
62 | 142 | ); |
63 | 143 | } |
64 | 144 |
|
|
0 commit comments