Removed styles from one section that ended up in generic component

This commit is contained in:
Alejandro Celaya 2021-08-23 18:31:40 +02:00
parent 9887cae4fd
commit 13785c7beb
2 changed files with 32 additions and 21 deletions

View file

@ -26,9 +26,15 @@ export const ServerForm: FC<ServerFormProps> = ({ onSubmit, initialValues, child
return (
<form className="server-form" onSubmit={handleSubmit}>
<SimpleCard className="mb-3" title={title}>
<FormGroupContainer value={name} onChange={setName}>Name</FormGroupContainer>
<FormGroupContainer type="url" value={url} onChange={setUrl}>URL</FormGroupContainer>
<FormGroupContainer value={apiKey} onChange={setApiKey}>API key</FormGroupContainer>
<FormGroupContainer labelClassName="create-server__label" value={name} onChange={setName}>
Name
</FormGroupContainer>
<FormGroupContainer labelClassName="create-server__label" type="url" value={url} onChange={setUrl}>
URL
</FormGroupContainer>
<FormGroupContainer labelClassName="create-server__label" value={apiKey} onChange={setApiKey}>API
key
</FormGroupContainer>
</SimpleCard>
<div className="text-right">{children}</div>

View file

@ -1,4 +1,4 @@
import { FC } from 'react';
import { FC, useRef } from 'react';
import { v4 as uuid } from 'uuid';
import { InputType } from 'reactstrap/lib/Input';
@ -10,23 +10,28 @@ interface FormGroupContainerProps {
required?: boolean;
placeholder?: string;
className?: string;
labelClassName?: string;
}
export const FormGroupContainer: FC<FormGroupContainerProps> = (
{ children, value, onChange, id = uuid(), type = 'text', required = true, placeholder, className = '' },
) => (
<div className={`form-group ${className}`}>
<label htmlFor={id} className="create-server__label">
{children}:
</label>
<input
className="form-control"
type={type}
id={id}
value={value}
required={required}
placeholder={placeholder}
onChange={(e) => onChange(e.target.value)}
/>
</div>
);
{ children, value, onChange, id, type, required, placeholder, className, labelClassName },
) => {
const forId = useRef<string>(id ?? uuid());
return (
<div className={`form-group ${className ?? ''}`}>
<label htmlFor={forId.current} className={labelClassName ?? ''}>
{children}:
</label>
<input
className="form-control"
type={type ?? 'text'}
id={forId.current}
value={value}
required={required ?? true}
placeholder={placeholder}
onChange={(e) => onChange(e.target.value)}
/>
</div>
);
};