1.2.16 • Published 2 years ago

react-igmweb v1.2.16

Weekly downloads
266
License
UNLICENSED
Repository
-
Last release
2 years ago

react-igmweb

Global component packages for React & Bootstrap4:

  • Login
  • Notification
  • Alert Confirm
  • Pagination
  • Table
  • Modal
  • Typeahead
  • Calendar
  • Loader

Global utilities for React:

  • DownloadCSV

Instalation

To install, you can use npm or yarn:

npm install react-igmweb --save

or

yarn add react-igmweb

Usage

Example:

import {
    IGMLogin,
    IGMNotification,
    IGMAlertConfirm,
    IGMPagination,
    IGMTable,
    IGMModal,
    IGMTypeahead,
    IGMUtilidades,
    IGMCalendar,
    IGMOnBeforeUnload,
    IGMLoader
} from 'react-igmweb';

Login

alt text

<IGMLogin 
    className="myLogin" 
    logo={logo} 
    description={description} 
    onLogin={(data)=>{/* object data*/}}/>
PropsOptionsDefaultDescription
classNameStringnoneCustom styles
logoStringnoneString URL image
descriptionStringnoneDescription for the login
onLoginFunctionnoneCallback method

Notification

alt text

onLogin = (datos) => {
    IGMNotification({
        classContainer: 'myNotification',
        text: 'Mensaje de pruebas',
        type: 'success',
        timer: 2000
    })
}

/*text HTML*/
onLogin = (datos) => {
    IGMNotification({
        classContainer: 'myNotification',
        html: '<h1>Text h1</h1>',
        type: 'success',
        timer: 2000
    })
}
PropsOptionsDefaultDescription
classContainerStringnoneCustom styles for the Modal
textStringnoneDescription for the Modal
htmlString HTMLnoneDescription HTML for the Modal
typeStringnoneThe type of the Modal: warning, error, success, info, and question
timerNumber3500Auto close timer of the Modal. Set in ms (milliseconds)

Alert confirm

alt text

onClickConfirm = () => {
    IGMAlertConfirm({
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#aaa',
        position: 'center',
        title: 'title',
        text: 'text',
        type: 'success',
        confirmButtonText:'Ok',
        cancelButtonText: 'Cancel',
        allowOutsideClick: false,
        preConfirm: ()=> {
            /*Function to execute before confirm, may be async (Promise-returning) or sync*/
            return fetch(`[URL]`)
              .then(response => {
                //..
                //onConfirm
                return {value:true} 
              })
              .catch(error => {
                //...
                //onConfirm
                return {value:true} 
              })
        },
        onConfirm: ()=> {
            console.log('confirm')
        },
        onCancel: ()=> {
            console.log('cancel')
        }
    })
}
PropsOptionsDefaultDescription
confirmButtonColorString'#3085d6'Use this to change the background color of the "Confirm"-button. The default color is #3085d6
cancelButtonColorString'#aaa'Use this to change the background color of the "Cancel"-button. The default color is #aaa
positionStringcenterModal window position, can be 'top', 'top-start', 'top-end', 'center', 'center-start', 'center-end', 'bottom', 'bottom-start', or 'bottom-end'
titleStringnoneTitle for the Alert
textStringnoneText for the Alert
typeStringnoneThe type of the Alert: warning, error, success, info, and question
onConfirmFunctionnoneCallback method for Confirm
onCancelFunctionnoneCallback method for Cancel
confirmButtonTextString'Ok'Text button confirm
cancelButtonTextString'Cancel'Text button cancel
showCancelBtnbooleantrueSet to false to remove cancel button
showCloseBtnbooleantrueSet to false to remove close button
allowOutsideClickbooleanfalsef set to false, the user can't dismiss the modal by clicking outside it.
You can also pass a custom function returning a boolean value, e.g. if you want to disable outside clicks for the loading state of a modal.

Pagination

alt text

<IGMPagination 
    total={100} 
    itemsPag={5} 
    pag={pag} 
    onPagination={(pag) => {/* pag selected */}}/>
PropsOptionsDefaultDescription
totalNumbernoneTotal items
itemsPagNumbernoneItems per page
pagNumbernoneActual page
onPaginationFunctionnoneCallback method for return selected page

Table

alt text

<IGMTable
    className={"myTable"}
    header={header}
    visible={visible}
    body={body}
    pagination={pagination}
    selectItemPag={selectItemPag}
    options={options}    
    loading={loading}
    order={order}
/>
PropsOptionsDefaultDescription
classNameStringnoneCustom styles
headerObjectnoneData header
bodyObjectArrayData body
optionsObjectnoneOptions for the table
visibleObjectnoneColumns visible
paginationObjectnoneConfig pagination
selectItemPagObjectnoneConfig items by page
loadingObjectnoneConfig loading
orderObjectnoneConfig order

Example:

let header = [
    {key: 'col1', value: 'COLUMNA 1', className: 'text-left', order: 'asc'},
    {key: 'col2', value: 'COLUMNA 2', className: 'text-left'},
    {key: 'col3', value: 'COLUMNA 3', className: 'text-left'}
]

let body = [
    { col1: 0, col2: 1, col3: 3},
    { col1: 1, col2: 3, col3: 6},
    { col1: 2, col2: 5, col3: 9},
    { col1: 3, col2: 7, col3: 12},
    { col1: 4, col2: 9, col3: 15},
    { col1: 5, col2: 11, col3: 18}
]

let options = {
    table: {
        align: 'center',
        size: 'sm',
        color: 'dark',
        striped: false,
        bordered: true,
        borderless: false,
        hover: false
    },
    thead: {
        showHeaderResultados: true,
        showHeaderCabecera:true,
        textNone: 'No se ha encontrado registros',
        textOnly: 'Se ha encontrado {X} registro',
        textMore: 'Se ha encontrado {X} registros',
        color: 'light'
    },
    actions: ['get', 'update', 'delete', 'historial', 'export', 'create'],
    textActions: {
        get: 'Ver',
        update: 'Modificar',
        delete: 'Suprimir',
        historial: 'Cambios históricos',
        create: 'Nuevo',
        export: 'Descargar CSV',
    },
    callbacks: {
        onGet: (item, index) => {/**/},
        onUpdate: (item, index) => {/**/},
        onDelete: (item, index) => {/**/},
        onHistorial: (item, index) => {/**/},
        onExport: ()=> {/**/},
        onOrder: (item) => {/**/},
        onCreate: ()=> {/**/},
    },
    leyendas: [
        {text: 'No operativo', color: '#F45B67' }
    ],
    onColorRow: (item) => {
        /* Por si necesitamos colorear una row */
        if (item.col1 === 5) return '#F45B67'
        return ''
    },
    onFormatCell: (item, key, idxRow, idxCol, currentPage) => {
        /* Por si queremos formatear el valor de una celda */
        if (key === 'col1' && item[key] === 'S') return 'Sí'
        return item[key]
    },
    onFormatCellHead: (item, idxCol) => {   
        /* Por si queremos formatear el valor de una celda del thead */   
        if (item.key === 'col1') {
            return <button>*</button>
        }
        return item.value
    },
    onFormatCellAction: (item, index, action) => {
        /* Mostrar o ocultar el botón de action (get, update, delete, ..) en la celda de la fila segun sus datos */
        return true
    },
    onClassCell: (key, item, idxRow, idxCol) => {
        /* Por si queremos incluir classes de estilos a una celda (<td>)*/
        return ''
    },
    otherComponentsThead: () => {
        /* Añadir cualquier otro componente en el Thead */
        return (
            <>
                <button type="button" className="btn btn-sm btn-dark ml-1">Otro</button>
            </>
        )
    }
}

let visible = {
    show: true,
    cols: ['col1', 'col2', 'col3', 'col4'],
    onVisible: (data)=> {
        /* array visible keys columns */
        console.log('onVisible', data)
    }
}

let paginacion = {
    total: 100,
    itemsPag: 5,
    pag: 1,
    onPagination: (pag) => {/* pag selected */}
}

let selectItemPag = {
    options: ['5', '15', '30'],
    callback: (item) => {
        /* item selected */        
    }
}

let loading = {
    show: true,
    message: 'Loading, please wait',
    renderChildren: true,
    type: 'ball-beat',
    color: '#02a17c',
    export: true // loading exportar
}

let order = {
    cols: ['col2', 'col3', 'col4'], // show columns with order
}

Más info:

Modal

alt text

<IGMModal
    className="myModal"
    show={show}
    options={options} 
    disableConfirm={false}
    loading={false}>        
        <form>
            <label>Username</label>
            <input type="text" className="form-control"/>
        </form>        
</IGMModal>
PropsOptionsDefaultDescription
classNameStringnoneCustom styles
showBooleanfalseShow/Hide modal
optionsObjectnoneOptions for the modal
disableConfirmBooleannoneDisabled button confirm
loadingBooleanfalseLoading content modal

Example:

const options = {
    title:'Enter username',
    onOk: (action) => {/* 'OK' */},
    onCancel: (action) => {/* 'CANCEL' */},
    onBackdrop: (action) => {/* 'OUT' */},
    onOther: (action) => {/* 'OTHER' */},
    onClose: (action) => {/* 'CLOSE' */},
    textOk: 'Ok',
    textCancel: 'Cancelar',
    size: '', // sm, lg (size modal)
    btSize: 'sm', // sm, lg (size button OK, Cancel)
    iconButton: true,
    iconOK: faCheck, // 'add', 'update', 'ok' or Object Font Awesome (ex: faUsers) --> import {faCheck} from "@fortawesome/free-solid-svg-icons";
    iconCancel: faTimes,
    colorOk: 'primary', // ('primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark', 'link')
    colorCancel: 'secondary',
    textOther:'back',
    colorOther:'info',
    iconOther: faAngleLeft,
    footer: {
        textHtml: '* Required fields'
    }
}

Typeahead

alt text

<IGMTypeahead
    isValid="{isValid}"
    mounted={flag}
    defaultInputValue={defaultInput}   
    isLoading={loading}
    config={config}
    options={options}
    onSearch={onSearch}
    onChange={onChange}
    onKeyDown={onKeyDown}
    clear={clear} 
    onBlur={onBlur}
    onInputChange={onInputChange}
    />
    
PropsOptionsDefaultDescription
isValidBooleannullshow input error/ok validation
mountedBooleannoneMounted/Unmounted component
defaultInputValueStringnoneThe initial value displayed in the text input
isLoadingBooleannoneShow/Hide loading icon
configObjectnoneConfiguration for the Typeahead
optionsArraynoneData
onSearchCallback methodnoneCallback to perform when the search is executed. query is the text string entered by the user.
onChangeCallback methodnoneInvoked when the set of selections changes
onKeyDownCallback methodnoneInvoked when a key is pressed. Receives an event
clearBooleanfalseClear input text
onBlurCallback methodnoneInvoked when the input is blurred. Receives an event.
onInputChangeCallback methodnoneInvoked when the input value changes. Receives the string value of the input (text), as well as the original event.

While the component relies primarily on Bootstrap for styles, some additional CSS is necessary for everything to behave correctly. You must include the provided CSS file in your project:

// Import as a module in your JS
import 'react-bootstrap-typeahead/css/Typeahead.css';
let config = {
    id: 'idsearch',
    promptText: 'No hay registro',
    searchText: 'Buscando...',
    labelKey: 'text',
    filterBy: ['text'], // List searching
    placeholder: 'Buscar...',
    minLength: 3,
    size: 'sm' // "large", "lg", "small", "sm"
}
    
const onSearch = (text) => {
    /* execute request */
    // ...
    setOptions([
        {id: '1', text: 'opcion 1'},
        {id: '2', text: 'opcion 2'},
        {id: '3', text: 'opcion 3'}
    ])
}

const onChange = (search) => {
    /* Object selected */
}
const onKeyDown = (e) => {
    console.log(e.key)
}
const onInputChange = (text) => {
    console.log(text)
}

Calendar

alt text

<IGMCalendar
    startDate={startDate}
    callback={(date, isEmpty) => { setStartDate(date) }}
/>
PropsTypeDefaultDescription
startDateDatenullDate calendar
callbackFunctionnullCallback set date
classNameStringnullcustom styles
isInvalidBooleanfalseshow error date invalid
sizeStringnullSize calendar ('sm', 'lg')
dateFormatString'dd/MM/yyyy'Format date
localeString'es'Locale date
minDateDatenullMinimum date
maxDateDatenullMaximum date
disabledBooleanfalseCalendar disabled
readOnlyBooleanfalseCalendar readOnly
showMonthDropdownBooleantrueShow month select
showYearDropdownBooleanfalseShow year select
showPopperArrowBooleanfalseShow arrow popper
popperPlacementString'bottom-end'Position calendar ('bottom-end','top-end', 'top-start', 'bottom-start')
tabIndexNumber1Position z-Index calendar
maskCharString'_'Character mask

Loader

alt text

<IGMLoader
    isLoading={isLoading}
/>
PropsTypeDefaultDescription
isLoadingBooleannullShow loading
isFullscreenBooleantrueOverlay fullscreen loading

Utilidades

DownloadCSV

DownloadCSV is a function that allows you to download a csv file from some data information.

import { IGMUtilidades } from 'react-igmweb'
IGMUtilidades.downloadCSV(fileName, dataCSV, DataType)
ParametersOptionsDefaultDescription
fileNameStringfile.csvThe name of the file without extension
dataCSVString, Array of arrays, Arrays of objectsnoneThe information of the table
DataTypeStringStringThe type of data that you are sending: 'String', 'Arrays' or 'Objects'

This function accepts three kind of data types:

  • A string concatenated variable separating each value with symbols or characters like ';'.
let dataCSV = "name;city;age\nkoldo;barcelona;38\npedro;sabadell;25"

IGMUtilidades.downloadCSV('example', dataCSV, 'String')
  • An array of arrays with the header in the first position: dataCSV0.
let dataCSV = [
    ["Name", "City", "Age"],
    ["Koldo", "Barcelona", 38],
    ["Jaime", "Málaga", 32],
    ["Javi", "Masnou", 35],
]

IGMUtilidades.downloadCSV('example', dataCSV, 'Arrays')
  • An array of objects.
let dataCSV = [
    {name: 'Silvia', city:'Hospitalet', age: 32},
    {name: 'Silvia', city:'La Escala', age: 30},
    {name: 'Pedro Fernando', city:'Sabadell', age: 32}
]

IGMUtilidades.downloadCSV('example', dataCSV, 'Objects')
1.2.16

2 years ago

1.2.15

2 years ago

1.2.15-beta.0

3 years ago

1.2.15-beta.1

3 years ago

1.2.15-beta.2

3 years ago

1.2.13

3 years ago

1.2.14

3 years ago

1.2.12

3 years ago

1.2.10

3 years ago

1.2.11

3 years ago

1.2.9

4 years ago

1.2.8

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.0

4 years ago

1.2.1

4 years ago

1.1.6

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.99

4 years ago

1.0.98

4 years ago

1.0.97

4 years ago

1.0.96

4 years ago

1.0.95

4 years ago

1.0.94

4 years ago

1.0.93

4 years ago

1.0.92

4 years ago

1.0.89

4 years ago

1.0.91

4 years ago

1.0.90

4 years ago

1.0.88

4 years ago

1.0.87

4 years ago

1.0.86

4 years ago

1.0.85

4 years ago

1.0.84

4 years ago

1.0.83

4 years ago

1.0.82

4 years ago

1.0.81

4 years ago

1.0.80

4 years ago

1.0.79

4 years ago

1.0.7-8.2

5 years ago

1.0.7-8.1

5 years ago

1.0.78

5 years ago

1.0.77

5 years ago

1.0.76

5 years ago

1.0.75

5 years ago

1.0.74

5 years ago

1.0.73

5 years ago

1.0.72

5 years ago

1.0.71

5 years ago

1.0.70

5 years ago

1.0.69

5 years ago

1.0.68

5 years ago

1.0.67

5 years ago

1.0.66

5 years ago

1.0.65

5 years ago

1.0.64

5 years ago

1.0.63

5 years ago

1.0.62

5 years ago

1.0.61

5 years ago

1.0.60

5 years ago

1.0.59

5 years ago

1.0.58

5 years ago

1.0.5-7.1

5 years ago

1.0.57

5 years ago

1.0.56

5 years ago

1.0.55

5 years ago

1.0.54

5 years ago

1.0.53

5 years ago

1.0.52

5 years ago

1.0.51

5 years ago

1.0.50

5 years ago

1.0.49

5 years ago

1.0.47

5 years ago

1.0.46

5 years ago

1.0.45

5 years ago

1.0.43

5 years ago

1.0.42-b

5 years ago

1.0.42

5 years ago

1.0.41

5 years ago

1.0.40

5 years ago

1.0.39

5 years ago

1.0.38

5 years ago

1.0.37

5 years ago

1.0.36

5 years ago

1.0.35

5 years ago

1.0.34

5 years ago

1.0.33

5 years ago

1.0.32

5 years ago

1.0.31

5 years ago

1.0.30

5 years ago

1.0.29

5 years ago

1.0.28

5 years ago

1.0.27

5 years ago

1.0.26

5 years ago

1.0.25

5 years ago

1.0.24

5 years ago

1.0.23

5 years ago

1.0.22

5 years ago

1.0.21

5 years ago

1.0.20

5 years ago

1.0.19

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago