-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLabel.tsx
44 lines (38 loc) · 1.02 KB
/
Label.tsx
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
import * as React from 'react';
import type { ElementRef } from 'react';
import clsx from 'clsx';
import { LabelProps } from './Label.props';
import { Slot } from '@radix-ui/react-slot';
import { withGlobalPrefix } from '../../helpers/with-global-prefix';
const componentName = 'Label';
const componentClassName = withGlobalPrefix(componentName);
type LabelElement = ElementRef<'label'>;
export const Label = React.forwardRef<LabelElement, LabelProps>(
(
{
children,
asChild,
as: Tag = 'label',
disabled,
nested,
disableUserSelect,
className,
...props
},
ref
) => {
return (
<Slot
ref={ref}
className={clsx(componentClassName, className)}
data-disabled={disabled ? '' : undefined}
data-nested={nested ? '' : undefined}
data-disable-user-select={disableUserSelect ? '' : undefined}
{...props}
>
{asChild ? children : <Tag>{children}</Tag>}
</Slot>
);
}
);
Label.displayName = componentName;