mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-08 22:53:25 +00:00
feat: add optionnal "required" param on TextBox and Selector inputs
This commit is contained in:
@@ -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}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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 {
|
||||
|
||||
4
src/types/types.d.ts
vendored
4
src/types/types.d.ts
vendored
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user