Private
Public Access
1
0
Files
power-apps-codeapps-blog-part2/node_modules/@fluentui/react-menu/lib/components/MenuItemSwitch/useMenuItemSwitch.js

49 lines
2.0 KiB
JavaScript

'use client';
import * as React from 'react';
import { slot } from '@fluentui/react-utilities';
import { useMenuItemCheckboxBase_unstable } from '../MenuItemCheckbox/useMenuItemCheckbox';
import { CircleFilled } from '@fluentui/react-icons';
import { circleFilledClassName } from './useMenuItemSwitchStyles.styles';
/**
* Create the state required to render MenuItemSwitch.
*
* The returned state can be modified with hooks such as useMenuItemSwitchStyles_unstable,
* before being passed to renderMenuItemSwitch_unstable.
*
* @param props - props from this instance of MenuItemSwitch
* @param ref - reference to root HTMLDivElement of MenuItemSwitch
*/ export const useMenuItemSwitch_unstable = (props, ref)=>{
const state = useMenuItemSwitchBase_unstable(props, ref);
// Set default icon for switch indicator
if (state.switchIndicator) {
var _state_switchIndicator;
var _children;
(_children = (_state_switchIndicator = state.switchIndicator).children) !== null && _children !== void 0 ? _children : _state_switchIndicator.children = /*#__PURE__*/ React.createElement(CircleFilled, {
className: circleFilledClassName
});
}
return state;
};
/**
* Base hook for MenuItemSwitch component, produces state required to render the component.
* It doesn't set any design-related props specific to MenuItemSwitch.
*
* @internal
* @param props - props from this instance of MenuItemSwitch
* @param ref - reference to root HTMLDivElement of MenuItemSwitch
*/ export const useMenuItemSwitchBase_unstable = (props, ref)=>{
const baseState = useMenuItemCheckboxBase_unstable(props, ref);
return {
...baseState,
switchIndicator: slot.optional(props.switchIndicator, {
renderByDefault: true,
elementType: 'span'
}),
components: {
// eslint-disable-next-line @typescript-eslint/no-deprecated
...baseState.components,
switchIndicator: 'span'
}
};
};