Debian Codegraph @

node/@patternfly/react-core/src/components/Modal/examples/ModalWithForm.tsx

raw
1 import { Fragment, useRef, useState } from 'react';
2 import {
3 Button,
4 Form,
5 FormGroup,
6 FormGroupLabelHelp,
7 Modal,
8 ModalBody,
9 ModalFooter,
10 ModalHeader,
11 ModalVariant,
12 Popover,
13 TextInput
14 } from '@patternfly/react-core';
15
16 export const ModalWithForm: React.FunctionComponent = () => {
17 const [isModalOpen, setModalOpen] = useState(false);
18 const [nameValue, setNameValue] = useState('');
19 const [emailValue, setEmailValue] = useState('');
20 const [addressValue, setAddressValue] = useState('');
21 const nameLabelHelpRef = useRef(null);
22 const emailLabelHelpRef = useRef(null);
23 const addressLabelHelpRef = useRef(null);
24
25 const handleModalToggle = (_event: KeyboardEvent | React.MouseEvent) => {
26 setModalOpen(!isModalOpen);
27 };
28
29 const handleNameInputChange = (_event, value: string) => {
30 setNameValue(value);
31 };
32
33 const handleEmailInputChange = (_event, value: string) => {
34 setEmailValue(value);
35 };
36 const handleAddressInputChange = (_event, value: string) => {
37 setAddressValue(value);
38 };
39
40 return (
41 <Fragment>
42 <Button variant="primary" onClick={handleModalToggle}>
43 Show modal with form
44 </Button>
45 <Modal
46 variant={ModalVariant.small}
47 isOpen={isModalOpen}
48 onClose={handleModalToggle}
49 aria-labelledby="form-modal-title"
50 aria-describedby="modal-box-description-form"
51 >
52 <ModalHeader
53 title="Create account"
54 description="Enter your personal information below to create an account."
55 descriptorId="modal-box-description-form"
56 labelId="form-modal-title"
57 />
58 <ModalBody>
59 <Form id="modal-with-form-form">
60 <FormGroup
61 label="Name"
62 labelHelp={
63 <Popover
64 triggerRef={nameLabelHelpRef}
65 headerContent={
66 <div>
67 The
68 <a href="https://schema.org/name" target="_blank" rel="noopener noreferrer">
69 name
70 </a>
71 of a
72 <a href="https://schema.org/Person" target="_blank" rel="noopener noreferrer">
73 Person
74 </a>
75 </div>
76 }
77 bodyContent={
78 <div>
79 Often composed of
80 <a href="https://schema.org/givenName" target="_blank" rel="noopener noreferrer">
81 givenName
82 </a>
83 and
84 <a href="https://schema.org/familyName" target="_blank" rel="noopener noreferrer">
85 familyName
86 </a>
87 .
88 </div>
89 }
90 >
91 <FormGroupLabelHelp ref={nameLabelHelpRef} aria-label="More info for name field" />
92 </Popover>
93 }
94 isRequired
95 fieldId="modal-with-form-form-name"
96 >
97 <TextInput
98 isRequired
99 type="email"
100 id="modal-with-form-form-name"
101 name="modal-with-form-form-name"
102 value={nameValue}
103 onChange={handleNameInputChange}
104 />
105 </FormGroup>
106 <FormGroup
107 label="E-mail"
108 labelHelp={
109 <Popover
110 triggerRef={emailLabelHelpRef}
111 headerContent={
112 <div>
113 The
114 <a href="https://schema.org/email" target="_blank" rel="noopener noreferrer">
115 e-mail
116 </a>
117 of a
118 <a href="https://schema.org/Person" target="_blank" rel="noopener noreferrer">
119 person
120 </a>
121 </div>
122 }
123 bodyContent={
124 <div>
125 Valid
126 <a href="https://schema.org/email" target="_blank" rel="noopener noreferrer">
127 e-mail
128 </a>
129 address.
130 </div>
131 }
132 >
133 <FormGroupLabelHelp ref={emailLabelHelpRef} aria-label="More info for e-mail field" />
134 </Popover>
135 }
136 isRequired
137 fieldId="modal-with-form-form-email"
138 >
139 <TextInput
140 isRequired
141 type="email"
142 id="modal-with-form-form-email"
143 name="modal-with-form-form-email"
144 value={emailValue}
145 onChange={handleEmailInputChange}
146 />
147 </FormGroup>
148 <FormGroup
149 label="Address"
150 labelHelp={
151 <Popover
152 triggerRef={addressLabelHelpRef}
153 headerContent={
154 <div>
155 The
156 <a href="https://schema.org/address" target="_blank" rel="noopener noreferrer">
157 address
158 </a>
159 of a
160 <a href="https://schema.org/Person" target="_blank" rel="noopener noreferrer">
161 person
162 </a>
163 </div>
164 }
165 bodyContent={
166 <div>
167 Valid
168 <a href="https://schema.org/PostalAddress" target="_blank" rel="noopener noreferrer">
169 postal address.
170 </a>
171 </div>
172 }
173 >
174 <FormGroupLabelHelp ref={addressLabelHelpRef} aria-label="More info for address field" />
175 </Popover>
176 }
177 isRequired
178 fieldId="modal-with-form-form-address"
179 >
180 <TextInput
181 isRequired
182 type="email"
183 id="modal-with-form-form-address"
184 name="modal-with-form-form-address"
185 value={addressValue}
186 onChange={handleAddressInputChange}
187 />
188 </FormGroup>
189 </Form>
190 </ModalBody>
191 <ModalFooter>
192 <Button key="create" variant="primary" form="modal-with-form-form" onClick={handleModalToggle}>
193 Confirm
194 </Button>
195 <Button key="cancel" variant="link" onClick={handleModalToggle}>
196 Cancel
197 </Button>
198 </ModalFooter>
199 </Modal>
200 </Fragment>
201 );
202 };