FebimaHermawan

Modal React From Function

Oct 13th, 2021
1,168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react'
  2. import classnames from "classnames"
  3. import { InertiaLink, Link } from '@inertiajs/inertia-react'
  4. import { Row, Col, Button, Modal, Form, Input, InputGroup, InputGroupAddon, InputGroupText, Label, FormGroup } from 'reactstrap'
  5. import {BootstrapTable, TableHeaderColumn} from 'react-bootstrap-table'
  6. import 'react-bootstrap-table/dist/react-bootstrap-table-all.min.css'
  7.  
  8. function filterType(cell) {
  9.     return cell.type;
  10. }
  11.  
  12. function actionFormatter(cell) {
  13.     return <Button className='btn btn-primary btn-sm' onClick={() => this.setFormModal(true)} value='${cell}'>Update Data</Button>
  14. }
  15.  
  16. function TableComponents() {
  17.     const [formModal, setFormModal] = React.useState(false);
  18.     const [emailFocus, setEmailFocus] = React.useState(false);
  19.     const [passwordFocus, setPasswordFocus] = React.useState(false);
  20.  
  21.     // Data For Datatable
  22.     var data                    = [
  23.         {
  24.             no              : 1,
  25.             id              : 1,
  26.             nama            : 'Febima Hermawan',
  27.             klpd            : 'Bagian Administrasi Pembangunan',
  28.             no_id           : '123456789012345678',
  29.             status          : 'Administrator',
  30.         },
  31.         {
  32.             no              : 2,
  33.             id              : 2,
  34.             nama            : 'Danang Dismantoro',
  35.             klpd            : 'Bagian Administrasi Pembangunan',
  36.             no_id           : '123456789012345678',
  37.             status          : 'PA/KPA',
  38.         }
  39.     ]
  40.  
  41.     // Konfiguration Table
  42.     const options = {
  43.         sizePerPageList: [
  44.             {
  45.                 text    : '5',
  46.                 value   : 5
  47.             },
  48.             {
  49.                 text    : '10',
  50.                 value   : 10
  51.             },
  52.             {
  53.                 text    : '50',
  54.                 value   : 50
  55.             },
  56.             {
  57.                 text    : '75',
  58.                 value   : 75
  59.             },
  60.             {
  61.                 text    : '100',
  62.                 value   : 100
  63.             }
  64.         ],
  65.         sizePerPage             : 5,
  66.         page                    : 1,
  67.         pageStartIndex          : 1,
  68.         prePage                 : 'Prev',
  69.         nextPage                : 'Next',
  70.         firstPage               : 'First',
  71.         lastPage                : 'Last',
  72.         paginationPosition      : 'bottom'
  73.     };
  74.  
  75.     return (
  76.         <React.Fragment>
  77.             <Row>
  78.                 <Modal modalClassName="modal-black" isOpen={formModal} toggle={() => setFormModal(false)} >
  79.                     <div className="modal-header justify-content-center">
  80.                         <button className="close" onClick={() => setFormModal(false)}>
  81.                             <i className="tim-icons icon-simple-remove text-white" />
  82.                         </button>
  83.                         <div className="text-muted text-center ml-auto mr-auto">
  84.                             <h3 className="mb-0">Sign in with</h3>
  85.                         </div>
  86.                     </div>
  87.                     <div className="modal-body">
  88.                         <div className="btn-wrapper text-center">
  89.                             <Button className="btn-neutral btn-icon" color="default" href="#pablo" onClick={(e) => e.preventDefault()} >
  90.                                 <img alt="..." src={require("../../../../assets/img/github.svg")} />
  91.                             </Button>
  92.                             <Button className="btn-neutral btn-icon" color="default" href="#pablo" onClick={(e) => e.preventDefault()} >
  93.                                 <img src={require("../../../../assets/img/google.svg")} alt="..." />
  94.                             </Button>
  95.                         </div>
  96.                         <div className="text-center text-muted mb-4 mt-3">
  97.                             <small>Or sign in with credentials</small>
  98.                         </div>
  99.                         <Form role="form">
  100.                             <FormGroup className="mb-3">
  101.                                 <InputGroup className={classnames("input-group-alternative", { "input-group-focus": emailFocus, })} >
  102.                                     <InputGroupAddon addonType="prepend">
  103.                                         <InputGroupText>
  104.                                             <i className="tim-icons icon-email-85" />
  105.                                         </InputGroupText>
  106.                                     </InputGroupAddon>
  107.                                     <Input placeholder="Email" type="email" onFocus={(e) => setEmailFocus(true)} onBlur={(e) => setEmailFocus(false)} />
  108.                                 </InputGroup>
  109.                             </FormGroup>
  110.                             <FormGroup>
  111.                                 <InputGroup className={classnames("input-group-alternative", { "input-group-focus": passwordFocus,  })} >
  112.                                     <InputGroupAddon addonType="prepend">
  113.                                         <InputGroupText>
  114.                                             <i className="tim-icons icon-key-25" />
  115.                                         </InputGroupText>
  116.                                     </InputGroupAddon>
  117.                                     <Input placeholder="Password" type="password" onFocus={(e) => setPasswordFocus(true)} onBlur={(e) => setPasswordFocus(false)} />
  118.                                 </InputGroup>
  119.                             </FormGroup>
  120.                             <FormGroup check className="mt-3">
  121.                                 <Label check>
  122.                                     <Input defaultChecked type="checkbox" />
  123.                                     <span className="form-check-sign" />
  124.                                     Remember me!
  125.                                 </Label>
  126.                             </FormGroup>
  127.                             <div className="text-center">
  128.                                 <Button className="my-4" color="primary" type="button">
  129.                                     Sign in
  130.                                 </Button>
  131.                             </div>
  132.                         </Form>
  133.                     </div>
  134.                 </Modal>
  135.                 <Col lg="12" sm="12">
  136.                     <BootstrapTable data={ data } search={ true } multiColumnSearch={ true } pagination={true} options={options}>
  137.                         <TableHeaderColumn row='0' width='50' dataField='no' dataSort={true} isKey>No</TableHeaderColumn>
  138.                         <TableHeaderColumn row='0' width='300' dataField='nama' dataSort={true}>Nama Pengguna</TableHeaderColumn>
  139.                         <TableHeaderColumn row='0' width='300' dataField='no_id' dataSort={true}>No. Identitas</TableHeaderColumn>
  140.                         <TableHeaderColumn row='0' width='150' dataField='klpd' dataSort={true}>Nama K/L/P/D</TableHeaderColumn>
  141.                         <TableHeaderColumn row='0' width='150' dataField='status' dataSort={true}>Status</TableHeaderColumn>
  142.                         <TableHeaderColumn row='0' width='150' dataField='id' filterValue={ filterType } dataFormat={ actionFormatter }>Action</TableHeaderColumn>
  143.                     </BootstrapTable>
  144.                 </Col>
  145.             </Row>
  146.         </React.Fragment>
  147.     )
  148. }
  149.  
  150. export default TableComponents
Advertisement
Add Comment
Please, Sign In to add comment