120 lines
3.8 KiB
JavaScript
120 lines
3.8 KiB
JavaScript
'use client';
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
function _export(target, all) {
|
|
for(var name in all)Object.defineProperty(target, name, {
|
|
enumerable: true,
|
|
get: all[name]
|
|
});
|
|
}
|
|
_export(exports, {
|
|
useSwitchBase_unstable: function() {
|
|
return useSwitchBase_unstable;
|
|
},
|
|
useSwitch_unstable: function() {
|
|
return useSwitch_unstable;
|
|
}
|
|
});
|
|
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
const _reactfield = require("@fluentui/react-field");
|
|
const _reacticons = require("@fluentui/react-icons");
|
|
const _reactlabel = require("@fluentui/react-label");
|
|
const _reacttabster = require("@fluentui/react-tabster");
|
|
const _reactutilities = require("@fluentui/react-utilities");
|
|
const useSwitch_unstable = (props, ref)=>{
|
|
const { size = 'medium', ...baseProps } = props;
|
|
const baseState = useSwitchBase_unstable(baseProps, ref);
|
|
return {
|
|
...baseState,
|
|
size
|
|
};
|
|
};
|
|
const useSwitchBase_unstable = (props, ref)=>{
|
|
// Merge props from surrounding <Field>, if any
|
|
props = (0, _reactfield.useFieldControlProps_unstable)(props, {
|
|
supportsLabelFor: true,
|
|
supportsRequired: true
|
|
});
|
|
const { checked, defaultChecked, disabled, disabledFocusable = false, labelPosition = 'after', onChange, required } = props;
|
|
const nativeProps = (0, _reactutilities.getPartitionedNativeProps)({
|
|
props,
|
|
primarySlotTagName: 'input',
|
|
excludedPropNames: [
|
|
'checked',
|
|
'defaultChecked',
|
|
'onChange',
|
|
'disabledFocusable'
|
|
]
|
|
});
|
|
const id = (0, _reactutilities.useId)('switch-', nativeProps.primary.id);
|
|
const root = _reactutilities.slot.always(props.root, {
|
|
defaultProps: {
|
|
ref: (0, _reacttabster.useFocusWithin)(),
|
|
...nativeProps.root
|
|
},
|
|
elementType: 'div'
|
|
});
|
|
const indicator = _reactutilities.slot.always(props.indicator, {
|
|
defaultProps: {
|
|
'aria-hidden': true,
|
|
children: /*#__PURE__*/ _react.createElement(_reacticons.CircleFilled, null)
|
|
},
|
|
elementType: 'div'
|
|
});
|
|
const input = _reactutilities.slot.always(props.input, {
|
|
defaultProps: {
|
|
checked,
|
|
defaultChecked,
|
|
id,
|
|
ref,
|
|
role: 'switch',
|
|
type: 'checkbox',
|
|
...nativeProps.primary,
|
|
disabled: disabled && !disabledFocusable,
|
|
...disabledFocusable && {
|
|
'aria-disabled': true
|
|
}
|
|
},
|
|
elementType: 'input'
|
|
});
|
|
input.onChange = (0, _reactutilities.mergeCallbacks)(input.onChange, (ev)=>onChange === null || onChange === void 0 ? void 0 : onChange(ev, {
|
|
checked: ev.currentTarget.checked
|
|
}));
|
|
input.onClick = (0, _reactutilities.mergeCallbacks)(input.onClick, (ev)=>{
|
|
if (disabledFocusable) {
|
|
ev.preventDefault();
|
|
}
|
|
});
|
|
input.onKeyDown = (0, _reactutilities.mergeCallbacks)(input.onKeyDown, (ev)=>{
|
|
if (disabledFocusable && (ev.key === ' ' || ev.key === 'Enter')) {
|
|
ev.preventDefault();
|
|
}
|
|
});
|
|
const label = _reactutilities.slot.optional(props.label, {
|
|
defaultProps: {
|
|
disabled: disabled || disabledFocusable,
|
|
htmlFor: id,
|
|
required,
|
|
size: 'medium'
|
|
},
|
|
elementType: _reactlabel.Label
|
|
});
|
|
return {
|
|
disabledFocusable,
|
|
labelPosition,
|
|
components: {
|
|
root: 'div',
|
|
indicator: 'div',
|
|
input: 'input',
|
|
label: _reactlabel.Label
|
|
},
|
|
root,
|
|
indicator,
|
|
input,
|
|
label
|
|
};
|
|
};
|