mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-04-05 01:05:02 -05:00
* Initial * Calendar initial * Extract EventCalendar * Events list initial * Winners * SQL fixes * List events by series * Leaderboards * Series leaderboard * Own entry peek * Edit page skeleton * RHF initial test * RHF stuff * Form etc. progress * Fix tournament series description * Fix tabs layout * Fix socials insert * Check for not removing admin * Adding series * TODOs * Allow updating org with no series * FormFieldset * Allow series without events * TextAreaFormfield accepting array syntax * Input form array field * ToggleFormField * SelectFormField * UserSearchFormField * Fetch badgeOptions * Badge editing * Progress * Use native preventScrollReset * Rename func * Fix sticky scroll * Fix translation * i18n errors * handle,meta in edit * Add ref to user search * TODOs * Done
49 lines
1.0 KiB
TypeScript
49 lines
1.0 KiB
TypeScript
import clsx from "clsx";
|
|
|
|
type LabelProps = Pick<
|
|
React.DetailedHTMLProps<
|
|
React.LabelHTMLAttributes<HTMLLabelElement>,
|
|
HTMLLabelElement
|
|
>,
|
|
"children" | "htmlFor"
|
|
> & {
|
|
valueLimits?: {
|
|
current: number;
|
|
max: number;
|
|
};
|
|
required?: boolean;
|
|
className?: string;
|
|
labelClassName?: string;
|
|
spaced?: boolean;
|
|
};
|
|
|
|
export function Label({
|
|
valueLimits,
|
|
required,
|
|
children,
|
|
htmlFor,
|
|
className,
|
|
labelClassName,
|
|
spaced = true,
|
|
}: LabelProps) {
|
|
return (
|
|
<div className={clsx("label__container", className, { "mb-0": !spaced })}>
|
|
<label htmlFor={htmlFor} className={labelClassName}>
|
|
{children} {required && <span className="text-error">*</span>}
|
|
</label>
|
|
{valueLimits ? (
|
|
<div className={clsx("label__value", lengthWarning(valueLimits))}>
|
|
{valueLimits.current}/{valueLimits.max}
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function lengthWarning(valueLimits: NonNullable<LabelProps["valueLimits"]>) {
|
|
if (valueLimits.current > valueLimits.max) return "error";
|
|
if (valueLimits.current / valueLimits.max >= 0.9) return "warning";
|
|
|
|
return;
|
|
}
|