UNPKG

3.67 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/esm/extends";
2import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3const _excluded = ["disabled", "slotProps", "slots"];
4import * as React from 'react';
5import PropTypes from 'prop-types';
6import composeClasses from '../composeClasses';
7import { getOptionGroupUtilityClass } from './optionGroupClasses';
8import { useSlotProps } from '../utils';
9import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
10import { jsx as _jsx } from "react/jsx-runtime";
11import { jsxs as _jsxs } from "react/jsx-runtime";
12function useUtilityClasses(disabled) {
13 const slots = {
14 root: ['root', disabled && 'disabled'],
15 label: ['label'],
16 list: ['list']
17 };
18 return composeClasses(slots, useClassNamesOverride(getOptionGroupUtilityClass));
19}
20
21/**
22 * An unstyled option group to be used within a Select.
23 *
24 * Demos:
25 *
26 * - [Select](https://mui.com/base/react-select/)
27 *
28 * API:
29 *
30 * - [OptionGroup API](https://mui.com/base/react-select/components-api/#option-group)
31 */
32const OptionGroup = /*#__PURE__*/React.forwardRef(function OptionGroup(props, forwardedRef) {
33 const {
34 disabled = false,
35 slotProps = {},
36 slots = {}
37 } = props,
38 other = _objectWithoutPropertiesLoose(props, _excluded);
39 const Root = (slots == null ? void 0 : slots.root) || 'li';
40 const Label = (slots == null ? void 0 : slots.label) || 'span';
41 const List = (slots == null ? void 0 : slots.list) || 'ul';
42 const classes = useUtilityClasses(disabled);
43 const 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 const labelProps = useSlotProps({
54 elementType: Label,
55 externalSlotProps: slotProps.label,
56 ownerState: props,
57 className: classes.label
58 });
59 const 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