Files
powerpoint-toolbox/node_modules/@fluentui/react-label/lib/components/Label/useLabel.js
T
2025-03-07 19:22:02 +01:00

38 lines
1.3 KiB
JavaScript

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 { disabled = false, required = false, weight = 'regular', size = 'medium' } = props;
return {
disabled,
required: slot.optional(required === true ? '*' : required || undefined, {
defaultProps: {
'aria-hidden': 'true'
},
elementType: 'span'
}),
weight,
size,
components: {
root: 'label',
required: 'span'
},
root: slot.always(getIntrinsicElementProps('label', {
// FIXME:
// `ref` is wrongly assigned to be `HTMLElement` instead of `HTMLLabelElement`
// but since it would be a breaking change to fix it, we are casting ref to it's proper type
ref: ref,
...props
}), {
elementType: 'label'
})
};
};