UNPKG

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