feat: add optionnal "required" param on TextBox and Selector inputs

This commit is contained in:
Sonny
2024-04-09 23:00:43 +02:00
parent 5a792aef13
commit cf6b87306e
4 changed files with 22 additions and 6 deletions

View File

@@ -23,6 +23,7 @@ interface SelectorProps {
) => ReactNode;
disabled?: boolean;
required?: boolean;
}
export default function Selector({
@@ -36,6 +37,7 @@ export default function Selector({
onChangeCallback,
formatOptionLabel,
disabled = false,
required = false,
}: SelectorProps): JSX.Element {
const [selectorValue, setSelectorValue] = useState<Option>();
@@ -56,7 +58,7 @@ export default function Selector({
}
return (
<div className={`input-field ${fieldClass}`}>
<div className={`input-field ${fieldClass} ${required && 'required'}`}>
{label && (
<label
htmlFor={name}

View File

@@ -10,6 +10,7 @@ interface InputProps {
inputClass?: string;
value?: string;
onChangeCallback?: (value) => void;
required?: boolean;
}
export default function TextBox({
@@ -22,6 +23,7 @@ export default function TextBox({
inputClass = '',
value,
onChangeCallback,
required = false,
}: InputProps): JSX.Element {
const [inputValue, setInputValue] = useState<string>(value);
@@ -33,11 +35,11 @@ export default function TextBox({
}
return (
<div className={`input-field ${fieldClass}`}>
<div className={`input-field ${fieldClass} ${required && 'required'}`}>
{label && (
<label
htmlFor={name}
title={`${name} field`}
title={label}
>
{label}
</label>

View File

@@ -160,11 +160,23 @@ input::placeholder {
}
.input-field {
& label,
& input,
& select {
width: 100%;
}
& label {
position: relative;
width: fit-content;
}
&.required label::after {
content: '*';
position: absolute;
top: 0;
right: -0.75em;
color: $red;
}
}
.checkbox-field {

View File

@@ -1,11 +1,11 @@
import { Category, User } from '@prisma/client';
import { Category, Link, User } from '@prisma/client';
import { Profile } from 'next-auth';
export type CategoryWithLinks = Category & {
author: User;
links: LinkWithCategory[];
};
export type LinkWithCategory = LinkWithCategory & {
export type LinkWithCategory = Link & {
author: User;
category: CategoryWithLinks;
};