Skip to content

Commit

Permalink
style: cleans up edit #3
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotBraem committed Jul 9, 2022
1 parent 5defcb1 commit 7952ee7
Showing 1 changed file with 52 additions and 37 deletions.
89 changes: 52 additions & 37 deletions src/components/AttributeField.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,46 +36,61 @@ const AttributeField = React.forwardRef(function AttributeField(props, ref) {

return (
<>
<div className="flex flex-row">
{edit ? (
<>
<form onSubmit={handleSubmit(onSubmit)}>
<Controller
name={`${attribute.id}`}
control={control}
defaultValue={options.find((it) => it.value === option.id)}
render={({ field }) => (
// TODO : Add check for type
<Select
options={options}
{...field}
label={attribute.name}
// isMulti={char.isMulti}
// className={`${char.isMulti ? "basic-multi-select" : ""}`}
classNamePrefix="select"
/>
)}
/>
<button type="submit" className="w-4 ml-2">
<CheckMarkIcon />
</button>
<button onClick={() => setEdit(!edit)} className="w-4 ml-2">
<DeleteIcon />
</button>
</form>
</>
) : (
<>
<span className="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">
{attribute.name}:
</span>{" "}
{option.value}
{edit ? (
<>
<form onSubmit={handleSubmit(onSubmit)}>
<div className="flex flex-row w-full justify-between border-t-2">
<div className="flex w-32 p-4">
<span className="font-medium text-gray-600 dark:text-gray-400">
{attribute.name}:
</span>
</div>
<div className="flex flex-1">
<Controller
name={`${attribute.id}`}
control={control}
defaultValue={options.find((it) => it.value === option.id)}
render={({ field }) => (
// TODO : Add check for type
<Select
options={options}
{...field}
label={attribute.name}
// isMulti={char.isMulti}
// className={`${char.isMulti ? "basic-multi-select" : ""}`}
classNamePrefix="select"
/>
)}
/>
</div>
<div className="flex align-middle">
<button type="submit" className="w-4 ml-2">
<CheckMarkIcon />
</button>
<button onClick={() => setEdit(!edit)} className="w-4 ml-2">
<DeleteIcon />
</button>
</div>
</div>
</form>
</>
) : (
<>
<div className="flex flex-row w-full justify-between border-t-2">
<div className="flex w-32 p-4">
<span className="font-medium text-gray-600 dark:text-gray-400">
{attribute.name}:
</span>
</div>
<div className="flex flex-1 p-4">
<span>{option.value}</span>
</div>
<button className="w-4 ml-2" onClick={() => setEdit(!edit)}>
<EditIcon />
</button>
</>
)}
</div>
</div>
</>
)}
</>
);
});
Expand Down

0 comments on commit 7952ee7

Please sign in to comment.