Private
Public Access
1
0
Files

48 lines
1.5 KiB
JavaScript

'use client';
import * as React from 'react';
import { getIntrinsicElementProps, slot } from '@fluentui/react-utilities';
/**
* Create the state required to render Label.
*
* The returned state can be modified with hooks such as useLabelStyles_unstable,
* before being passed to renderLabel_unstable.
*
* @param props - props from this instance of Label
* @param ref - reference to root HTMLElement of Label
*/ export const useLabel_unstable = (props, ref)=>{
const { weight = 'regular', size = 'medium', ...baseProps } = props;
const state = useLabelBase_unstable(baseProps, ref);
return {
weight,
size,
...state
};
};
/**
* Create the base state required to render Label, without design-specific props (size, weight).
*
* @param props - props from this instance of Label
* @param ref - reference to root HTMLElement of Label
*/ export const useLabelBase_unstable = (props, ref)=>{
const { disabled = false, required = false, ...rest } = props;
return {
disabled,
required: slot.optional(required === true ? '*' : required || undefined, {
defaultProps: {
'aria-hidden': 'true'
},
elementType: 'span'
}),
components: {
root: 'label',
required: 'span'
},
root: slot.always(getIntrinsicElementProps('label', {
ref: ref,
...rest
}), {
elementType: 'label'
})
};
};