- updates and fixes;

This commit is contained in:
Vitalii Kiiko
2024-09-03 17:24:41 +02:00
parent 429ca3c1d1
commit 949ff95933
21 changed files with 342 additions and 117 deletions

View File

@@ -8,7 +8,7 @@ import { FileUpload } from 'primereact/fileupload';
import { Tag } from 'primereact/tag';
import { Button } from 'primereact/button';
const Fileupload = ({
const FileuploadAsync = ({
fieldName,
setDataFn,
label,
@@ -150,4 +150,4 @@ const Fileupload = ({
)
}
export default Fileupload;
export default FileuploadAsync;

View File

@@ -0,0 +1,41 @@
import React from 'react';
import { classNames } from 'primereact/utils';
import { Controller } from 'react-hook-form';
import { RadioButton } from 'primereact/radiobutton';
const Radio = ({
fieldName,
label,
control,
errors,
defaultValue,
config = {},
infoText = null,
options = []
}) => {
const input = <Controller
name={fieldName}
control={control}
defaultValue={defaultValue}
rules={config}
render={({ field, fieldState }) =>
options.map(o => <div className="appForm__fieldItem" key={o.name}>
<RadioButton
id={`${fieldName}_${o.name}`}
name={fieldName}
value={o.name}
onChange={(e) => field.onChange(e.value)}
checked={field.value === o.name}/>
<label htmlFor={`${fieldName}_${o.name}`}>{o.label}</label>
</div>)}/>
return (
<>
<label htmlFor={fieldName} className={classNames({ 'p-error': errors[fieldName] })}>
{label}{config.required ? '*' : null}
</label>
{input}
{infoText ? <small>{infoText}</small> : null}
</>)
}
export default Radio;

View File

@@ -0,0 +1,50 @@
import React from 'react';
import { classNames } from 'primereact/utils';
import { Controller } from 'react-hook-form';
import { Dropdown } from 'primereact/dropdown';
const Select = ({
fieldName,
label,
control,
errors,
defaultValue,
config = {},
infoText = null,
inputgroup = false,
icon = null,
placeholder = '',
options = []
}) => {
const input = <Controller
name={fieldName}
control={control}
defaultValue={defaultValue}
rules={config}
render={({ field, fieldState }) => (
<Dropdown
value={field.value}
onChange={(e) => field.onChange(e.value)}
options={options}
optionLabel="label"
placeholder={placeholder}
className={classNames({ 'p-invalid': fieldState.invalid })}/>
)}/>
return (
<>
<label htmlFor={fieldName} className={classNames({ 'p-error': errors[fieldName] })}>
{label}{config.required ? '*' : null}
</label>
{inputgroup
? <div className="p-inputgroup flex-1">
<span className="p-inputgroup-addon">
{icon}
</span>
{input}
</div>
: input}
{infoText ? <small>{infoText}</small> : null}
</>)
}
export default Select;

View File

@@ -7,9 +7,11 @@ import TextInput from './components/TextInput';
import TextArea from './components/TextArea';
import Datepicker from './components/Datepicker';
import DatepickerRange from './components/DatepickerRange';
import Fileupload from './components/Fileupload';
import FileuploadAsync from './components/FileuploadAsync';
import NumberInput from './components/NumberInput';
import Switch from './components/Switch';
import Select from './components/Select';
import Radio from './components/Radio';
const FormField = (props) => {
const fields = {
@@ -17,9 +19,11 @@ const FormField = (props) => {
textarea: TextArea,
datepicker: Datepicker,
datepickerrange: DatepickerRange,
fileupload: Fileupload,
fileuploadasync: FileuploadAsync,
numberinput: NumberInput,
switch: Switch
switch: Switch,
select: Select,
radio: Radio
}
const Comp = !isNil(fields[props.type]) ? fields[props.type] : null;