UNPKG

3.83 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3import * as React from 'react';
4import PropTypes from 'prop-types';
5import composeClasses from '../composeClasses';
6import { getOptionGroupUtilityClass } from './optionGroupClasses';
7import { useSlotProps } from '../utils';
8import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
9import { jsx as _jsx } from "react/jsx-runtime";
10import { jsxs as _jsxs } from "react/jsx-runtime";
11function useUtilityClasses(disabled) {
12 var slots = {
13 root: ['root', disabled && 'disabled'],
14 label: ['label'],
15 list: ['list']
16 };
17 return composeClasses(slots, useClassNamesOverride(getOptionGroupUtilityClass));
18}
19
20/**
21 * An unstyled option group to be used within a Select.
22 *
23 * Demos:
24 *
25 * - [Select](https://mui.com/base/react-select/)
26 *
27 * API:
28 *
29 * - [OptionGroup API](https://mui.com/base/react-select/components-api/#option-group)
30 */
31var OptionGroup = /*#__PURE__*/React.forwardRef(function OptionGroup(props, forwardedRef) {
32 var _props$disabled = props.disabled,
33 disabled = _props$disabled === void 0 ? false : _props$disabled,
34 _props$slotProps = props.slotProps,
35 slotProps = _props$slotProps === void 0 ? {} : _props$slotProps,
36 _props$slots = props.slots,
37 slots = _props$slots === void 0 ? {} : _props$slots,
38 other = _objectWithoutProperties(props, ["disabled", "slotProps", "slots"]);
39 var Root = (slots == null ? void 0 : slots.root) || 'li';
40 var Label = (slots == null ? void 0 : slots.label) || 'span';
41 var List = (slots == null ? void 0 : slots.list) || 'ul';
42 var classes = useUtilityClasses(disabled);
43 var rootProps = useSlotProps({
44 elementType: Root,
45 externalSlotProps: slotProps.root,
46 externalForwardedProps: other,
47 additionalProps: {
48 ref: forwardedRef
49 },
50 ownerState: props,
51 className: classes.root
52 });
53 var labelProps = useSlotProps({
54 elementType: Label,
55 externalSlotProps: slotProps.label,
56 ownerState: props,
57 className: classes.label
58 });
59 var listProps = useSlotProps({
60 elementType: List,
61 externalSlotProps: slotProps.list,
62 ownerState: props,
63 className: classes.list
64 });
65 return /*#__PURE__*/_jsxs(Root, _extends({}, rootProps, {
66 children: [/*#__PURE__*/_jsx(Label, _extends({}, labelProps, {
67 children: props.label
68 })), /*#__PURE__*/_jsx(List, _extends({}, listProps, {
69 children: props.children
70 }))]
71 }));
72});
73process.env.NODE_ENV !== "production" ? OptionGroup.propTypes /* remove-proptypes */ = {
74 // ----------------------------- Warning --------------------------------
75 // | These PropTypes are generated from the TypeScript type definitions |
76 // | To update them edit TypeScript types and run "yarn proptypes" |
77 // ----------------------------------------------------------------------
78 /**
79 * @ignore
80 */
81 children: PropTypes.node,
82 /**
83 * If `true` all the options in the group will be disabled.
84 * @default false
85 */
86 disabled: PropTypes.bool,
87 /**
88 * The human-readable description of the group.
89 */
90 label: PropTypes.node,
91 /**
92 * The props used for each slot inside the Input.
93 * @default {}
94 */
95 slotProps: PropTypes.shape({
96 label: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
97 list: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
98 root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
99 }),
100 /**
101 * The components used for each slot inside the OptionGroup.
102 * Either a string to use a HTML element or a component.
103 * @default {}
104 */
105 slots: PropTypes.shape({
106 label: PropTypes.elementType,
107 list: PropTypes.elementType,
108 root: PropTypes.elementType
109 })
110} : void 0;
111export default OptionGroup;
\No newline at end of file