|
1 | | -import React from 'react'; |
2 | | -import ReactDOM from 'react-dom/client'; |
3 | | -import './index.css'; |
4 | | -import { IgrTextarea, IgrTextareaModule, IgrButton, IgrButtonModule, IgrToast, IgrToastModule } from 'igniteui-react'; |
5 | | -import 'igniteui-webcomponents/themes/light/bootstrap.css'; |
6 | | - |
7 | | -IgrTextareaModule.register(); |
8 | | -IgrButtonModule.register(); |
9 | | -IgrToastModule.register(); |
10 | | - |
11 | | -export default class TextAreaFormIntegration extends React.Component<any, any> { |
12 | | - |
13 | | - public toastRef: IgrToast; |
14 | | - |
15 | | - constructor(props: any) { |
16 | | - super(props); |
17 | | - this.onSubmitButtonClicked = this.onSubmitButtonClicked.bind(this); |
18 | | - this.onToastRef = this.onToastRef.bind(this); |
19 | | - } |
20 | | - |
21 | | - public render(): JSX.Element { |
22 | | - return ( |
23 | | - <div className="sample"> |
24 | | - <form id="form" onSubmit={this.onSubmitButtonClicked}> |
25 | | - <IgrTextarea rows={3} name="user_feedback" label="Your review" required> |
26 | | - </IgrTextarea> |
27 | | - <div className="controls"> |
28 | | - <IgrButton type="submit"><span>Submit review</span></IgrButton> |
29 | | - <IgrButton type="reset" variant="outlined"><span>Reset</span></IgrButton> |
30 | | - </div> |
31 | | - <IgrToast id="submitted" position="top" display-time="1e3" ref={this.onToastRef}><span>Your review was submitted</span></IgrToast> |
32 | | - </form> |
33 | | - </div> |
34 | | - ); |
35 | | - } |
36 | | - |
37 | | - public onToastRef(toast: IgrToast){ |
38 | | - if (!toast) { return; } |
39 | | - this.toastRef = toast; |
| 1 | +import React from "react"; |
| 2 | +import ReactDOM from "react-dom/client"; |
| 3 | +import "./index.css"; |
| 4 | +import { IgrTextarea, IgrButton, IgrToast } from "igniteui-react"; |
| 5 | +import "igniteui-webcomponents/themes/light/bootstrap.css"; |
| 6 | + |
| 7 | +export default function TextAreaFormIntegration() { |
| 8 | + let toastRef: IgrToast; |
| 9 | + |
| 10 | + const onToastRef = (toast: IgrToast) => { |
| 11 | + if (!toast) { |
| 12 | + return; |
40 | 13 | } |
| 14 | + toastRef = toast; |
| 15 | + }; |
41 | 16 |
|
42 | | - public onSubmitButtonClicked(e:React.FormEvent<HTMLFormElement>) { |
43 | | - if(this.toastRef){ |
44 | | - e.preventDefault(); |
45 | | - this.toastRef.show(); |
46 | | - } |
| 17 | + const onSubmitButtonClicked = (e: React.FormEvent<HTMLFormElement>) => { |
| 18 | + if (toastRef) { |
| 19 | + e.preventDefault(); |
| 20 | + toastRef.show(); |
47 | 21 | } |
| 22 | + }; |
| 23 | + |
| 24 | + return ( |
| 25 | + <div className="sample"> |
| 26 | + <form id="form" onSubmit={onSubmitButtonClicked}> |
| 27 | + <IgrTextarea |
| 28 | + rows={3} |
| 29 | + name="user_feedback" |
| 30 | + label="Your review" |
| 31 | + required |
| 32 | + ></IgrTextarea> |
| 33 | + <div className="controls"> |
| 34 | + <IgrButton type="submit"> |
| 35 | + <span>Submit review</span> |
| 36 | + </IgrButton> |
| 37 | + <IgrButton type="reset" variant="outlined"> |
| 38 | + <span>Reset</span> |
| 39 | + </IgrButton> |
| 40 | + </div> |
| 41 | + <IgrToast |
| 42 | + id="submitted" |
| 43 | + position="top" |
| 44 | + displayTime={1000} |
| 45 | + ref={onToastRef} |
| 46 | + > |
| 47 | + <span>Your review was submitted</span> |
| 48 | + </IgrToast> |
| 49 | + </form> |
| 50 | + </div> |
| 51 | + ); |
48 | 52 | } |
49 | 53 |
|
50 | 54 | // rendering above class to the React DOM |
51 | | -const root = ReactDOM.createRoot(document.getElementById('root')); |
52 | | -root.render(<TextAreaFormIntegration/>); |
| 55 | +const root = ReactDOM.createRoot(document.getElementById("root")); |
| 56 | +root.render(<TextAreaFormIntegration />); |
0 commit comments