34 lines
1.3 KiB
JavaScript
34 lines
1.3 KiB
JavaScript
'use client';
|
|
import * as React from 'react';
|
|
import { getIntrinsicElementProps, slot } from '@fluentui/react-utilities';
|
|
import { useTableContext } from '../../contexts/tableContext';
|
|
/**
|
|
* Create the state required to render TableBody.
|
|
*
|
|
* The returned state can be modified with hooks such as useTableBodyStyles_unstable,
|
|
* before being passed to renderTableBody_unstable.
|
|
*
|
|
* @param props - props from this instance of TableBody
|
|
* @param ref - reference to root HTMLElement of TableBody
|
|
*/ export const useTableBody_unstable = (props, ref)=>{
|
|
const { noNativeElements } = useTableContext();
|
|
var _props_as;
|
|
const rootComponent = ((_props_as = props.as) !== null && _props_as !== void 0 ? _props_as : noNativeElements) ? 'div' : 'tbody';
|
|
return {
|
|
components: {
|
|
root: rootComponent
|
|
},
|
|
root: slot.always(getIntrinsicElementProps(rootComponent, {
|
|
// FIXME:
|
|
// `ref` is wrongly assigned to be `HTMLElement` instead of `HTMLDivElement`
|
|
// but since it would be a breaking change to fix it, we are casting ref to it's proper type
|
|
ref: ref,
|
|
role: rootComponent === 'div' ? 'rowgroup' : undefined,
|
|
...props
|
|
}), {
|
|
elementType: rootComponent
|
|
}),
|
|
noNativeElements
|
|
};
|
|
};
|