Refactor the library

This commit is contained in:
Daniel Garcia 2021-09-09 15:27:26 +02:00
parent 0386054842
commit f7c162a866
15 changed files with 102 additions and 72 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -7,10 +7,11 @@ import MCF_Checkbox from './components/MCF_Checkbox'
import MCF_CheckboxesGroup from './components/MCF_CheckboxesGroup' import MCF_CheckboxesGroup from './components/MCF_CheckboxesGroup'
import MCF_Dialog from './components/MCF_Dialog' import MCF_Dialog from './components/MCF_Dialog'
import MCF_Divider from './components/MCF_Divider' import MCF_Divider from './components/MCF_Divider'
import MCF_FileUpload from './components/MCF_FileUpload'
import MCF_MediaCard from './components/MCF_MediaCard' import MCF_MediaCard from './components/MCF_MediaCard'
import MCF_Select from './components/MCF_Select' import MCF_Select from './components/MCF_Select'
import MCF_Text from './components/MCF_Text' import MCF_Text from './components/MCF_Text'
import MCF_FileUpload from './components/MCF_FileUpload'
export default class ComponentFactory { export default class ComponentFactory {

View file

@ -1,8 +1,10 @@
/* eslint-disable react/prop-types */ /* eslint-disable react/prop-types */
import React, { useState } from 'react' import React, { useState } from 'react'
import TextField from '@material-ui/core/TextField'
import Autocomplete from '@material-ui/lab/Autocomplete' import Autocomplete from '@material-ui/lab/Autocomplete'
import TextField from '@material-ui/core/TextField'
export default function MCF_Autocomplete (props) { export default function MCF_Autocomplete (props) {
@ -18,15 +20,15 @@ export default function MCF_Autocomplete (props) {
return ( return (
<Autocomplete <Autocomplete
id={params.id} id={params.id} // string
value={params.value} value={params.value} // string
style={{width: params.width}} style={{width: params.width}} // number
options={params.options} options={params.options} // options to select
getOptionLabel={option => option.key} getOptionLabel={option => option.key}
onChange={handleChange} onChange={handleChange}
renderInput={parameters => <TextField renderInput={parameters => <TextField
{...parameters} {...parameters}
label={params.label} label={params.label} // string
variant={params.variant} // 'filled' | 'outlined' | 'standard' variant={params.variant} // 'filled' | 'outlined' | 'standard'
margin={params.margin} // 'dense' | 'none' | 'normal' margin={params.margin} // 'dense' | 'none' | 'normal'
/>} />}

View file

@ -1,4 +1,5 @@
/* eslint-disable react/prop-types */ /* eslint-disable react/prop-types */
import React, {useState} from 'react' import React, {useState} from 'react'
import Button from '@material-ui/core/Button' import Button from '@material-ui/core/Button'
@ -6,6 +7,7 @@ import Button from '@material-ui/core/Button'
import { useStyles } from '../index' import { useStyles } from '../index'
export default function MCF_Button (props) { export default function MCF_Button (props) {
const [params, setParams] = useState(props.params) const [params, setParams] = useState(props.params)
const classes = useStyles() const classes = useStyles()
@ -13,14 +15,13 @@ export default function MCF_Button (props) {
return ( return (
<Button <Button
className={classes.button} className={classes.button}
variant={params.variant} color={params.color} // 'default' | 'inherit' | 'primary' | 'secondary'
color={params.color} size={params.size} // 'large' | 'medium' | 'small'
disabled={params.disabled} variant={params.variant} // 'contained' | 'outlined' | 'text'
size={params.size} disabled={params.disabled} // boolean
value={params.value}
onClick={params.onClickListener} onClick={params.onClickListener}
> >
{params.text} {params.text/* string */}
</Button> </Button>
) )
} }

View file

@ -1,13 +1,14 @@
/* eslint-disable react/prop-types */ /* eslint-disable react/prop-types */
import React, {useState} from 'react' import React, {useState} from 'react'
import Card from '@material-ui/core/Card' import Card from '@material-ui/core/Card'
import CardContent from '@material-ui/core/CardContent' import CardContent from '@material-ui/core/CardContent'
import CardHeader from '@material-ui/core/CardHeader' import CardHeader from '@material-ui/core/CardHeader'
import ComponentFactory from '../ComponentFactory'
import {useStyles} from '../index' import {useStyles} from '../index'
import ComponentFactory from '../ComponentFactory'
export default function MCF_Card (props) { export default function MCF_Card (props) {
@ -24,8 +25,8 @@ export default function MCF_Card (props) {
return ( return (
<Card className={classes.card}> <Card className={classes.card}>
<CardHeader <CardHeader
title={params.mainText} title={params.mainText} // string
subheader={params.secondaryText} subheader={params.secondaryText} // string
/> />
<CardContent> <CardContent>
{renderContents()} {renderContents()}

View file

@ -1,10 +1,12 @@
/* eslint-disable react/prop-types */ /* eslint-disable react/prop-types */
import React, {useState} from 'react' import React, {useState} from 'react'
import Checkbox from '@material-ui/core/Checkbox' import Checkbox from '@material-ui/core/Checkbox'
import FormControlLabel from '@material-ui/core/FormControlLabel' import FormControlLabel from '@material-ui/core/FormControlLabel'
export default function MCF_Checkbox (props) { export default function MCF_Checkbox (props) {
const [params, setParams] = useState(props.params) const [params, setParams] = useState(props.params)
@ -15,16 +17,16 @@ export default function MCF_Checkbox (props) {
return ( return (
<FormControlLabel <FormControlLabel
id={params.id} id={params.id} // string
key={params.id} key={params.id}
control={ control={
<Checkbox <Checkbox
checked={params.checked} checked={params.checked} // boolean
onChange={handleChange} onChange={handleChange}
name={params.id} name={params.id}
/> />
} }
label={params.label} label={params.label} // string
/> />
) )
} }

View file

@ -1,15 +1,17 @@
/* eslint-disable react/prop-types */ /* eslint-disable react/prop-types */
import React, {useState} from 'react' import React, {useState} from 'react'
import FormControl from '@material-ui/core/FormControl' import FormControl from '@material-ui/core/FormControl'
import FormGroup from '@material-ui/core/FormGroup' import FormGroup from '@material-ui/core/FormGroup'
import FormHelperText from '@material-ui/core/FormHelperText' import FormHelperText from '@material-ui/core/FormHelperText'
import FormLabel from '@material-ui/core/FormLabel' import FormLabel from '@material-ui/core/FormLabel'
import ComponentFactory from '../ComponentFactory'
import ComponentFactory from '../ComponentFactory'
import {useStyles} from '../index' import {useStyles} from '../index'
export default function MCF_CheckboxesGroup (props) { export default function MCF_CheckboxesGroup (props) {
const [params, setParams] = useState(props.params) const [params, setParams] = useState(props.params)
const classes = useStyles() const classes = useStyles()
@ -30,9 +32,9 @@ export default function MCF_CheckboxesGroup (props) {
const checkboxConfig = { const checkboxConfig = {
type: 'checkbox', type: 'checkbox',
params: { params: {
id: checkbox.id, id: checkbox.id, // string
checked: checkbox.checked, checked: checkbox.checked, // boolean
label: checkbox.label, label: checkbox.label, // string
onChangeListener: handleChange, onChangeListener: handleChange,
}, },
} }
@ -45,10 +47,10 @@ export default function MCF_CheckboxesGroup (props) {
return ( return (
<FormControl component="fieldset" className={classes.formControl}> <FormControl component="fieldset" className={classes.formControl}>
<FormLabel component="legend">{params.label}</FormLabel> <FormLabel component="legend">{params.label}</FormLabel>
<FormHelperText>{params.helperText}</FormHelperText> <FormHelperText>{params.helperText/* string */}</FormHelperText>
<FormGroup <FormGroup
id={params.id} id={params.id} // string
row={params.isRow} row={params.isRow} // boolean
> >
{createCheckboxes()} {createCheckboxes()}
</FormGroup> </FormGroup>

View file

@ -1,4 +1,5 @@
/* eslint-disable react/prop-types */ /* eslint-disable react/prop-types */
import React, {useState} from 'react' import React, {useState} from 'react'
import Button from '@material-ui/core/Button' import Button from '@material-ui/core/Button'
@ -11,6 +12,7 @@ import DialogTitle from '@material-ui/core/DialogTitle'
import ComponentFactory from '../ComponentFactory' import ComponentFactory from '../ComponentFactory'
export default function MCF_Dialog (props) { export default function MCF_Dialog (props) {
const [params, setParams] = useState(props.params) const [params, setParams] = useState(props.params)
@ -52,32 +54,32 @@ export default function MCF_Dialog (props) {
return ( return (
<div> <div>
<Button <Button
variant={params.openButtonVariant} variant={params.openButtonVariant} // 'contained' | 'outlined' | 'text'
color={params.openButtonColor} color={params.openButtonColor} // 'default' | 'inherit' | 'primary' | 'secondary'
onClick={handleOpen}> onClick={handleOpen}>
{params.openButtonText} {params.openButtonText/* string */}
</Button> </Button>
<Dialog <Dialog
open={params.open} open={params.open} // boolean
onClose={handleClose} onClose={handleClose}
aria-labelledby={params.id} aria-labelledby={params.id}
> >
<DialogTitle id={params.id}> <DialogTitle id={params.id/* string */}>
{params.titleText} {params.titleText/* string */}
</DialogTitle> </DialogTitle>
<DialogContent> <DialogContent>
<DialogContentText> <DialogContentText>
{params.contentText} {params.contentText/* string */}
</DialogContentText> </DialogContentText>
{renderContents()} {renderContents()}
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
{renderActionContents()} {renderActionContents()}
<Button <Button
variant={params.closeButtonVariant} variant={params.closeButtonVariant} // 'contained' | 'outlined' | 'text'
color={params.closeButtonColor} color={params.closeButtonColor} // 'default' | 'inherit' | 'primary' | 'secondary'
onClick={handleClose}> onClick={handleClose}>
{params.closeButtonText} {params.closeButtonText/* string */}
</Button> </Button>
</DialogActions> </DialogActions>
</Dialog> </Dialog>

View file

@ -3,6 +3,7 @@ import React from 'react'
import {useStyles} from '../index' import {useStyles} from '../index'
export default function MCF_Divider () { export default function MCF_Divider () {
const classes = useStyles() const classes = useStyles()

View file

@ -1,9 +1,13 @@
/* eslint-disable react/prop-types */
import React, {useState, useEffect} from 'react' import React, {useState, useEffect} from 'react'
import Button from '@material-ui/core/Button' import Button from '@material-ui/core/Button'
import {useStyles} from '../index' import {useStyles} from '../index'
export default function MCF_FileUpload (props) { export default function MCF_FileUpload (props) {
const [params, setParams] = useState(props.params) const [params, setParams] = useState(props.params)
const classes = useStyles() const classes = useStyles()
@ -52,18 +56,18 @@ export default function MCF_FileUpload (props) {
return ( return (
<div> <div>
<input <input
id={params.id} id={params.id} // string
className={classes.input} className={classes.input}
accept={params.acceptedFormats} accept={params.acceptedFormats} // strings array
multiple multiple
type="file" type="file"
/> />
<label htmlFor={params.id}> <label htmlFor={params.id}>
<Button <Button
className={classes.button} className={classes.button}
variant={params.variant} color={params.color} // 'default' | 'inherit' | 'primary' | 'secondary'
color={params.color} size={params.size} // 'large' | 'medium' | 'small'
size={params.size} variant={params.variant} // 'contained' | 'outlined' | 'text'
component="span"> component="span">
{params.text} {params.text}
</Button> </Button>

View file

@ -1,7 +1,6 @@
/* eslint-disable react/prop-types */ /* eslint-disable react/prop-types */
import React, {useState} from 'react'
import {useStyles} from '../index' import React, {useState} from 'react'
import Card from '@material-ui/core/Card' import Card from '@material-ui/core/Card'
import CardContent from '@material-ui/core/CardContent' import CardContent from '@material-ui/core/CardContent'
@ -9,6 +8,8 @@ import CardHeader from '@material-ui/core/CardHeader'
import CardMedia from '@material-ui/core/CardMedia' import CardMedia from '@material-ui/core/CardMedia'
import ComponentFactory from '../ComponentFactory' import ComponentFactory from '../ComponentFactory'
import {useStyles} from '../index'
export default function MCF_MediaCard (props) { export default function MCF_MediaCard (props) {
@ -25,14 +26,14 @@ export default function MCF_MediaCard (props) {
return ( return (
<Card className={classes.card}> <Card className={classes.card}>
<CardHeader <CardHeader
title={params.mainText} title={params.mainText} // string
subheader={params.secondaryText} subheader={params.secondaryText} // string
/> />
<CardMedia <CardMedia
className={classes.media} className={classes.media}
image={params.imageURL} image={params.imageURL} // string: URL
title={params.imageTitle} title={params.imageTitle} // string
alt={params.imageAlt} alt={params.imageAlt} // string
/> />
<CardContent> <CardContent>
{renderContents()} {renderContents()}

View file

@ -1,4 +1,5 @@
/* eslint-disable react/prop-types */ /* eslint-disable react/prop-types */
import React, {useState} from 'react' import React, {useState} from 'react'
import FormControl from '@material-ui/core/FormControl' import FormControl from '@material-ui/core/FormControl'
@ -11,6 +12,7 @@ import Select from '@material-ui/core/Select'
import {useStyles} from '../index' import {useStyles} from '../index'
export default function MCF_Select (props) { export default function MCF_Select (props) {
const [params, setParams] = useState(props.params) const [params, setParams] = useState(props.params)
const classes = useStyles() const classes = useStyles()
@ -26,10 +28,10 @@ export default function MCF_Select (props) {
params.options.map(option => { params.options.map(option => {
return ( return (
<MenuItem <MenuItem
key={option.id} key={option.id} // string
value={option.value} value={option.value}
> >
{option.label} {option.label/*string*/}
</MenuItem> </MenuItem>
) )
}) })
@ -39,31 +41,31 @@ export default function MCF_Select (props) {
return ( return (
<FormControl <FormControl
className={classes.formControl} className={classes.formControl}
disabled={params.disabled} disabled={params.disabled} // boolean
error={params.error} error={params.error} // boolean
required={params.required} required={params.required} // boolean
> >
<InputLabel <InputLabel
shrink={params.shrink} shrink={params.shrink} // boolean
htmlFor={params.id} htmlFor={params.id}
> >
{params.label} {params.label}
</InputLabel> </InputLabel>
<Select <Select
value={params.value} value={params.value}
displayEmpty={params.displayEmpty} displayEmpty={params.displayEmpty} // boolean
autoWidth={params.autoWidth} autoWidth={params.autoWidth} // boolean
onChange={handleInteraction} onChange={handleInteraction}
input={<Input input={<Input
name={params.id} name={params.id}
id={params.id} id={params.id} // string
readOnly={params.readOnly} readOnly={params.readOnly} // boolean
/>} />}
> >
{createList()} {createList()}
</Select> </Select>
<FormHelperText> <FormHelperText>
{params.helperText} {params.helperText/* string */}
</FormHelperText> </FormHelperText>
</FormControl> </FormControl>
) )

View file

@ -1,10 +1,13 @@
/* eslint-disable react/prop-types */ /* eslint-disable react/prop-types */
import React, {useState} from 'react' import React, {useState} from 'react'
import TextField from '@material-ui/core/TextField' import TextField from '@material-ui/core/TextField'
import {useStyles} from '../index' import {useStyles} from '../index'
export default function MCF_Text (props) { export default function MCF_Text (props) {
const [params, setParams] = useState(props.params) const [params, setParams] = useState(props.params)
const classes = useStyles() const classes = useStyles()
@ -25,22 +28,22 @@ export default function MCF_Text (props) {
return ( return (
<form className={classes.container} noValidate autoComplete="off"> <form className={classes.container} noValidate autoComplete="off">
<TextField <TextField
id={params.id} id={params.id} // string
label={params.label} label={params.label} // string
className={classes.textField} className={classes.textField}
value={params.value} value={params.value}
onChange={handleChange} onChange={handleChange}
margin={params.margin} // 'dense' | 'none' | 'normal' margin={params.margin} // 'dense' | 'none' | 'normal'
required={params.required} required={params.required} // boolean
error={params.error} error={params.error} // boolean
disabled={params.disabled} disabled={params.disabled} // boolean
placeholder={params.placeholder} placeholder={params.placeholder} // string
helperText={params.helperText} helperText={params.helperText} // string
fullWidth={params.fullWidth} fullWidth={params.fullWidth} // boolean
variant={params.variant} // 'filled' | 'outlined' | 'standard' variant={params.variant} // 'filled' | 'outlined' | 'standard'
type={params.type} // HTML input type type={params.type} // HTML input type
InputLabelProps={{ InputLabelProps={{
shrink: params.shrink, shrink: params.shrink, // boolean
}} }}
/> />
</form> </form>

View file

@ -1,8 +1,16 @@
//TODO: incluir gestion de estados
//TODO: Añadir las funciones: createSelectFromDictionary, createCheckboxGroupFromDictionary
//TODO: Hacer una función que permita cambiar un atributo de un mcf_component a partir del id del componente, el nombre del atributo y el nuevo valor del atributo
//TODO: Hacer una función que permita encontrar un MCF_Component a partir de su id
import ReactDOM from 'react-dom' import ReactDOM from 'react-dom'
import {makeStyles} from '@material-ui/core/styles'
import ComponentFactory from './ComponentFactory' import ComponentFactory from './ComponentFactory'
import {makeStyles} from '@material-ui/core/styles'
const useStyles = makeStyles(theme => ({ const useStyles = makeStyles(theme => ({