ConceptPortal-public/rsconcept/frontend/src/components/Input/Label.tsx

33 lines
675 B
TypeScript
Raw Normal View History

import clsx from 'clsx';
import { type Label as LabelStyle } from '../props';
interface LabelProps extends LabelStyle {
2024-10-30 21:35:55 +03:00
/** Text to display. */
2023-12-28 14:04:44 +03:00
text?: string;
2023-07-15 17:46:19 +03:00
}
2024-10-30 21:35:55 +03:00
/**
* Displays a label with optional text.
*
* Note: Html label component is used only if `htmlFor` prop is set.
*/
2025-02-07 10:54:47 +03:00
export function Label({ text, className, ...restProps }: LabelProps) {
if (!text) {
return null;
}
if (restProps.htmlFor) {
return (
<label className={clsx('cc-label', className)} {...restProps}>
{text}
</label>
);
} else {
return (
<span className={clsx('cc-label', className)} {...restProps}>
{text}
</span>
);
}
2023-07-15 17:46:19 +03:00
}