Unrefactor Properties form to allow more freedom on the input types and form (#32)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
- The css style is now in IProperties.Style again. - Forms are divided in DynamicForm and StaticForm - Faster because less logic - Add RadioGroupButton - Add InputGroup - Fix Children Dimensions not using x for their origin Co-authored-by: Eric NGUYEN <enguyen@techform.fr> Reviewed-on: https://git.siklos-chaneru.duckdns.org/Siklos/svg-layout-designer-react/pulls/32
This commit is contained in:
parent
3d7baafc17
commit
5f8e011bc6
19 changed files with 529 additions and 134 deletions
|
@ -1,12 +1,12 @@
|
|||
import React, { useState } from 'react';
|
||||
import ContainerProperties from '../../Interfaces/IProperties';
|
||||
import IProperties from '../../Interfaces/IProperties';
|
||||
import { ToggleButton } from '../ToggleButton/ToggleButton';
|
||||
import { INPUT_TYPES } from './PropertiesInputTypes';
|
||||
import { Form } from './Form';
|
||||
|
||||
interface IPropertiesProps {
|
||||
properties?: ContainerProperties
|
||||
onChange: (key: string, value: string | number | boolean) => void
|
||||
onSubmit: (event: React.FormEvent<HTMLFormElement>, properties: ContainerProperties) => void
|
||||
properties?: IProperties
|
||||
onChange: (key: string, value: string | number | boolean, isStyle?: boolean) => void
|
||||
onSubmit: (event: React.FormEvent<HTMLFormElement>) => void
|
||||
}
|
||||
|
||||
export const Properties: React.FC<IPropertiesProps> = (props: IPropertiesProps) => {
|
||||
|
@ -16,26 +16,6 @@ export const Properties: React.FC<IPropertiesProps> = (props: IPropertiesProps)
|
|||
return <div></div>;
|
||||
}
|
||||
|
||||
const groupInput: React.ReactNode[] = [];
|
||||
Object
|
||||
.entries(props.properties)
|
||||
.forEach((pair) => handleProperties(pair, groupInput, isDynamicInput, props.onChange));
|
||||
|
||||
const form = isDynamicInput
|
||||
? <div className='grid grid-cols-2 gap-4'>
|
||||
{ groupInput }
|
||||
</div>
|
||||
: <form
|
||||
key={props.properties.id}
|
||||
onSubmit={(event) => props.onSubmit(event, props.properties as ContainerProperties)}
|
||||
>
|
||||
<input type='submit' className='normal-btn block mx-auto mb-4 border-2 border-blue-400 cursor-pointer' value='Submit'/>
|
||||
<div className='grid grid-cols-2 gap-y-4'>
|
||||
{ groupInput }
|
||||
</div>
|
||||
</form>
|
||||
;
|
||||
|
||||
return (
|
||||
<div className='h-3/5 p-3 bg-slate-200 overflow-y-auto'>
|
||||
<ToggleButton
|
||||
|
@ -45,72 +25,12 @@ export const Properties: React.FC<IPropertiesProps> = (props: IPropertiesProps)
|
|||
checked={isDynamicInput}
|
||||
onChange={() => setIsDynamicInput(!isDynamicInput)}
|
||||
/>
|
||||
{ form }
|
||||
<Form
|
||||
properties={props.properties}
|
||||
isDynamicInput={isDynamicInput}
|
||||
onChange={props.onChange}
|
||||
onSubmit={props.onSubmit}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const handleProperties = (
|
||||
[key, value]: [string, string | number],
|
||||
groupInput: React.ReactNode[],
|
||||
isDynamicInput: boolean,
|
||||
onChange: (key: string, value: string | number | boolean) => void
|
||||
): void => {
|
||||
const id = `property-${key}`;
|
||||
let type = 'text';
|
||||
let checked;
|
||||
|
||||
/// hardcoded stuff for ergonomy ///
|
||||
if (typeof value === 'boolean') {
|
||||
checked = value;
|
||||
}
|
||||
|
||||
if (key in INPUT_TYPES) {
|
||||
type = INPUT_TYPES[key];
|
||||
}
|
||||
|
||||
const className = `
|
||||
w-full
|
||||
text-xs font-medium transition-all text-gray-800 mt-1 px-3 py-2
|
||||
bg-white border-2 border-white rounded-lg placeholder-gray-800
|
||||
focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500
|
||||
disabled:bg-slate-300 disabled:text-gray-500 disabled:border-slate-300 disabled:shadow-none`;
|
||||
const isDisabled = ['id', 'parentId'].includes(key);
|
||||
const input = isDynamicInput
|
||||
? <input
|
||||
key={key}
|
||||
id={key}
|
||||
className={className}
|
||||
type={type}
|
||||
value={value}
|
||||
checked={checked}
|
||||
onChange={(event) => {
|
||||
if (type === 'checkbox') {
|
||||
onChange(key, event.target.checked);
|
||||
return;
|
||||
}
|
||||
onChange(key, event.target.value);
|
||||
}}
|
||||
disabled={isDisabled}
|
||||
/>
|
||||
: <input
|
||||
key={key}
|
||||
id={key}
|
||||
className={className}
|
||||
type={type}
|
||||
defaultValue={value}
|
||||
defaultChecked={checked}
|
||||
disabled={isDisabled}
|
||||
/>;
|
||||
|
||||
groupInput.push(
|
||||
<label
|
||||
key={id}
|
||||
className='mt-4 text-xs font-medium text-gray-800'
|
||||
htmlFor={key}
|
||||
>
|
||||
{key}
|
||||
</label>
|
||||
);
|
||||
groupInput.push(input);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue