1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 | Object.defineProperty(exports, "__esModule", {
|
5 | value: true
|
6 | });
|
7 | exports.default = useOption;
|
8 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
9 | var React = _interopRequireWildcard(require("react"));
|
10 | var _utils = require("@mui/utils");
|
11 | var _useList = require("../useList");
|
12 | var _useCompoundItem = require("../utils/useCompoundItem");
|
13 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
14 | function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | function useOption(params) {
|
26 | const {
|
27 | value,
|
28 | label,
|
29 | disabled,
|
30 | rootRef: optionRefParam,
|
31 | id: idParam
|
32 | } = params;
|
33 | const {
|
34 | getRootProps: getListItemProps,
|
35 | rootRef: listItemRefHandler,
|
36 | highlighted,
|
37 | selected
|
38 | } = (0, _useList.useListItem)({
|
39 | item: value
|
40 | });
|
41 | const id = (0, _utils.unstable_useId)(idParam);
|
42 | const optionRef = React.useRef(null);
|
43 | const selectOption = React.useMemo(() => ({
|
44 | disabled,
|
45 | label,
|
46 | value,
|
47 | ref: optionRef,
|
48 | id
|
49 | }), [disabled, label, value, id]);
|
50 | const {
|
51 | index
|
52 | } = (0, _useCompoundItem.useCompoundItem)(value, selectOption);
|
53 | const handleRef = (0, _utils.unstable_useForkRef)(optionRefParam, optionRef, listItemRefHandler);
|
54 | return {
|
55 | getRootProps: (otherHandlers = {}) => (0, _extends2.default)({}, otherHandlers, getListItemProps(otherHandlers), {
|
56 | id,
|
57 | ref: handleRef,
|
58 | role: 'option',
|
59 | 'aria-selected': selected
|
60 | }),
|
61 | highlighted,
|
62 | index,
|
63 | selected,
|
64 | rootRef: handleRef
|
65 | };
|
66 | } |
\ | No newline at end of file |