DEV;Wrap all Field to field-container class
This commit is contained in:
parent
98e7126f5e
commit
2ee1106169
10 changed files with 75 additions and 58 deletions
|
@ -39,7 +39,7 @@ const Checkbox: React.FC<ICheckboxFieldProps> = (props) => {
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative mt-1">
|
<div className="checkbox-container">
|
||||||
<label className="cursor-pointer text-primary" htmlFor={name} onClick={handleClick}>
|
<label className="cursor-pointer text-primary" htmlFor={name} onClick={handleClick}>
|
||||||
<div className="block text-black pb-2 field-label">{title}</div>
|
<div className="block text-black pb-2 field-label">{title}</div>
|
||||||
<FontAwesomeIcon size="lg" icon={checked ? 'check-square' : 'square'} />
|
<FontAwesomeIcon size="lg" icon={checked ? 'check-square' : 'square'} />
|
||||||
|
|
|
@ -52,18 +52,16 @@ const DatePicker: React.FC<IDatePickerFieldProps> = (props) => {
|
||||||
}, [name, value, title]);
|
}, [name, value, title]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<TextField
|
||||||
<TextField
|
name={name}
|
||||||
name={name}
|
title={title}
|
||||||
title={title}
|
onClick={handleOpenModal}
|
||||||
onClick={handleOpenModal}
|
onFocus={handleOpenModal}
|
||||||
onFocus={handleOpenModal}
|
onBlur={handleBlur}
|
||||||
onBlur={handleBlur}
|
value={value}
|
||||||
value={value}
|
status={status}
|
||||||
status={status}
|
readonly
|
||||||
readonly
|
/>
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,7 @@ const RadioButton: React.FC<IRadioButtonFieldProps> = (props) => {
|
||||||
}, [value, options, props.name]);
|
}, [value, options, props.name]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative mt-1">
|
<div className="radiobutton-container">
|
||||||
<div className="block text-black pb-2 field-label">{title}</div>
|
<div className="block text-black pb-2 field-label">{title}</div>
|
||||||
{horizontal ? <div className="flex">{optionElements}</div> : optionElements}
|
{horizontal ? <div className="flex">{optionElements}</div> : optionElements}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -112,16 +112,16 @@ const TextField: React.FC<ITextFieldProps> = (props) => {
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="field-container">
|
<div className="textfield-container">
|
||||||
<label className="field-label" htmlFor={name}>
|
<label className="field-label" htmlFor={name}>
|
||||||
{title}
|
{title}
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
className={cx('field-input masked', {
|
className={cx('textfield-input masked', {
|
||||||
'field-input--info': status === STATUS.info,
|
'textfield-input--info': status === STATUS.info,
|
||||||
'field-input--success': status === STATUS.success,
|
'textfield-input--success': status === STATUS.success,
|
||||||
'field-input--warning': status === STATUS.warning,
|
'textfield-input--warning': status === STATUS.warning,
|
||||||
'field-input--error': status === STATUS.error,
|
'textfield-input--error': status === STATUS.error,
|
||||||
})}
|
})}
|
||||||
ref={inputRef}
|
ref={inputRef}
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
import TimePicker from './components/TimePicker';
|
import TimePicker, { ITimePickerFieldProps } from './components/TimePicker';
|
||||||
|
|
||||||
|
export { ITimePickerFieldProps };
|
||||||
export default TimePicker;
|
export default TimePicker;
|
||||||
|
|
|
@ -15,22 +15,29 @@ type IProps<F> = F & IField;
|
||||||
function Field<F>(props: IProps<F>) {
|
function Field<F>(props: IProps<F>) {
|
||||||
const { component, ...other } = props as any;
|
const { component, ...other } = props as any;
|
||||||
|
|
||||||
|
let render = null;
|
||||||
switch (component) {
|
switch (component) {
|
||||||
case FIELD_TYPE.TEXT_FIELD:
|
case FIELD_TYPE.TEXT_FIELD:
|
||||||
return <TextField {...other} />;
|
render = <TextField {...other} />;
|
||||||
|
break;
|
||||||
case FIELD_TYPE.CHECKBOX:
|
case FIELD_TYPE.CHECKBOX:
|
||||||
return <CheckboxField {...other} />;
|
render = <CheckboxField {...other} />;
|
||||||
|
break;
|
||||||
case FIELD_TYPE.RADIO_BUTTON:
|
case FIELD_TYPE.RADIO_BUTTON:
|
||||||
return <RadioButtonField {...other} />;
|
render = <RadioButtonField {...other} />;
|
||||||
|
break;
|
||||||
case FIELD_TYPE.SELECT_BOX:
|
case FIELD_TYPE.SELECT_BOX:
|
||||||
return <SelectBoxField {...other} />;
|
render = <SelectBoxField {...other} />;
|
||||||
|
break;
|
||||||
case FIELD_TYPE.DATE_PICKER:
|
case FIELD_TYPE.DATE_PICKER:
|
||||||
return <DatePickerField {...other} />;
|
render = <DatePickerField {...other} />;
|
||||||
|
break;
|
||||||
case FIELD_TYPE.TIME_PICKER:
|
case FIELD_TYPE.TIME_PICKER:
|
||||||
return <TimePickerField {...other} />;
|
render = <TimePickerField {...other} />;
|
||||||
default:
|
break;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return <div className="field-container">{render}</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Field;
|
export default Field;
|
||||||
|
|
|
@ -6,4 +6,5 @@ export type FormSubmit<FormData> = SubmitHandler<FormData>;
|
||||||
|
|
||||||
export type IField = {
|
export type IField = {
|
||||||
component: FIELD_TYPE;
|
component: FIELD_TYPE;
|
||||||
|
name: string;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
const field = (theme) => ({
|
const field = (theme) => ({
|
||||||
'.field-container': {
|
'.field-container': {
|
||||||
|
marginBottom: '1rem',
|
||||||
|
},
|
||||||
|
'.textfield-container': {
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
'& svg': {
|
'& svg': {
|
||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
},
|
},
|
||||||
'.field-input': {
|
'.textfield-input': {
|
||||||
border: 'none',
|
border: 'none',
|
||||||
backgroundColor: theme('colors.gray.50'),
|
backgroundColor: theme('colors.gray.50'),
|
||||||
padding: '0.5rem',
|
padding: '0.5rem',
|
||||||
|
@ -41,29 +44,37 @@ const field = (theme) => ({
|
||||||
cursor: 'auto',
|
cursor: 'auto',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
'.field-icon': {
|
},
|
||||||
position: 'absolute',
|
'.checkbox-container': {
|
||||||
top: '1.27rem',
|
position: 'relative',
|
||||||
right: '0',
|
marginTop: '1rem',
|
||||||
padding: '0.51rem',
|
},
|
||||||
color: theme('colors.primary.DEFAULT'),
|
'.radiobutton-container': {
|
||||||
fontSize: '1.125rem',
|
position: 'relative',
|
||||||
lineHeight: '1.25rem',
|
marginTop: '1rem',
|
||||||
'&--clear': {
|
},
|
||||||
display: 'none',
|
'.field-icon': {
|
||||||
borderRadius: '0 2px 2px 0',
|
position: 'absolute',
|
||||||
color: theme('colors.error.dark'),
|
top: '1.27rem',
|
||||||
},
|
right: '0',
|
||||||
'.field-input:disabled &': {
|
padding: '0.51rem',
|
||||||
color: theme('colors.gray.500'),
|
color: theme('colors.primary.DEFAULT'),
|
||||||
'& svg': {
|
fontSize: '1.125rem',
|
||||||
cursor: 'auto',
|
lineHeight: '1.25rem',
|
||||||
},
|
'&--clear': {
|
||||||
},
|
display: 'none',
|
||||||
'.field-input:hover + &, .field-input + &:hover': {
|
borderRadius: '0 2px 2px 0',
|
||||||
display: 'inline',
|
color: theme('colors.error.dark'),
|
||||||
|
},
|
||||||
|
'.field-input:disabled &': {
|
||||||
|
color: theme('colors.gray.500'),
|
||||||
|
'& svg': {
|
||||||
|
cursor: 'auto',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
'.field-input:hover + &, .field-input + &:hover': {
|
||||||
|
display: 'inline',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
'.field-label': {
|
'.field-label': {
|
||||||
fontSize: '0.8rem',
|
fontSize: '0.8rem',
|
||||||
|
@ -73,7 +84,6 @@ const field = (theme) => ({
|
||||||
'.field-validationMessage': {
|
'.field-validationMessage': {
|
||||||
color: theme('colors.error.DEFAULT'),
|
color: theme('colors.error.DEFAULT'),
|
||||||
textAlign: 'left',
|
textAlign: 'left',
|
||||||
marginBottom: '0.5rem',
|
|
||||||
fontSize: '0.7rem',
|
fontSize: '0.7rem',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,5 +6,5 @@ export type IHTMLElement<Value> = {
|
||||||
onChange?: (value: Value, e: React.MouseEvent | React.ChangeEvent | null) => void;
|
onChange?: (value: Value, e: React.MouseEvent | React.ChangeEvent | null) => void;
|
||||||
onClick?: (value: Value, e: React.MouseEvent) => void;
|
onClick?: (value: Value, e: React.MouseEvent) => void;
|
||||||
onFocus?: (value: Value, e: React.FocusEvent) => void;
|
onFocus?: (value: Value, e: React.FocusEvent) => void;
|
||||||
title: string;
|
title?: string;
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,12 +3,12 @@ import React, { useCallback } from 'react';
|
||||||
import * as Yup from 'yup';
|
import * as Yup from 'yup';
|
||||||
|
|
||||||
import Button from '@treejs/components/Button';
|
import Button from '@treejs/components/Button';
|
||||||
import type { ICheckboxFieldProps } from '@treejs/components/Checkbox';
|
import { ICheckboxFieldProps } from '@treejs/components/Checkbox';
|
||||||
import type { IDatePickerFieldProps } from '@treejs/components/DatePicker';
|
import { IDatePickerFieldProps } from '@treejs/components/DatePicker';
|
||||||
import { Grid, GridCol } from '@treejs/components/Grid';
|
import { Grid, GridCol } from '@treejs/components/Grid';
|
||||||
import type { IRadioButtonFieldProps } from '@treejs/components/RadioButton/components/RadioButton';
|
import { IRadioButtonFieldProps } from '@treejs/components/RadioButton/components/RadioButton';
|
||||||
import type { ISelectBoxFieldProps } from '@treejs/components/SelectBox';
|
import { ISelectBoxFieldProps } from '@treejs/components/SelectBox';
|
||||||
import type { ITextFieldProps } from '@treejs/components/TextField';
|
import { ITextFieldProps } from '@treejs/components/TextField';
|
||||||
import { ITimePickerFieldProps } from '@treejs/components/TimePicker';
|
import { ITimePickerFieldProps } from '@treejs/components/TimePicker';
|
||||||
import Field from '@treejs/forms/components/Field';
|
import Field from '@treejs/forms/components/Field';
|
||||||
import Form from '@treejs/forms/components/Form';
|
import Form from '@treejs/forms/components/Form';
|
||||||
|
|
Loading…
Add table
Reference in a new issue