blob: 2ec614f1e9792a3d9738bba76f46f075d2b913ae (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
import { FC, ReactNode } from 'react';
import styles from './label.module.scss';
export type LabelProps = {
/**
* An accessible name for the label.
*/
'aria-label'?: string;
/**
* The label body.
*/
children: ReactNode;
/**
* Add classnames to the label.
*/
className?: string;
/**
* The field id.
*/
htmlFor?: string;
/**
* Is the field required? Default: false.
*/
required?: boolean;
/**
* The label size. Default: small.
*/
size?: 'medium' | 'small';
};
/**
* Label Component
*
* Render a HTML label element.
*/
const Label: FC<LabelProps> = ({
children,
className = '',
required = false,
size = 'small',
...props
}) => {
const sizeClass = styles[`label--${size}`];
return (
<label className={`${styles.label} ${sizeClass} ${className}`} {...props}>
{children}
{required && <span className={styles.required}> *</span>}
</label>
);
};
export default Label;
|