@mui/joy
Version:
Joy UI is an open-source React component library that implements MUI's own design principles. It's comprehensive and can be used in production out of the box.
146 lines (145 loc) • 5.35 kB
JavaScript
'use client';
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
import _extends from "@babel/runtime/helpers/esm/extends";
const _excluded = ["children", "component", "color", "variant", "className", "slots", "slotProps"];
import * as React from 'react';
import clsx from 'clsx';
import PropTypes from 'prop-types';
import { unstable_capitalize as capitalize } from '@mui/utils';
import { unstable_composeClasses as composeClasses } from '@mui/base/composeClasses';
import { StyledListItemButton } from '../ListItemButton/ListItemButton';
import { styled, useThemeProps } from '../styles';
import { useVariantColor } from '../styles/variantColorInheritance';
import { getAutocompleteOptionUtilityClass } from './autocompleteOptionClasses';
import useSlot from '../utils/useSlot';
import { jsx as _jsx } from "react/jsx-runtime";
const useUtilityClasses = ownerState => {
const {
color,
variant
} = ownerState;
const slots = {
root: ['root', color && `color${capitalize(color)}`, variant && `variant${capitalize(variant)}`]
};
return composeClasses(slots, getAutocompleteOptionUtilityClass, {});
};
export const StyledAutocompleteOption = styled(StyledListItemButton)(({
theme,
ownerState
}) => {
var _theme$variants, _theme$variants2;
return {
'&[aria-disabled="true"]': (_theme$variants = theme.variants[`${ownerState.variant}Disabled`]) == null ? void 0 : _theme$variants[ownerState.color],
'&[aria-selected="true"]': _extends({}, (_theme$variants2 = theme.variants[`${ownerState.variant}Active`]) == null ? void 0 : _theme$variants2[ownerState.color], {
fontWeight: theme.vars.fontWeight.md
})
};
});
const AutocompleteOptionRoot = styled(StyledAutocompleteOption, {
name: 'JoyAutocompleteOption',
slot: 'Root',
overridesResolver: (props, styles) => styles.root
})({});
/**
*
* Demos:
*
* - [Autocomplete](https://mui.com/joy-ui/react-autocomplete/)
*
* API:
*
* - [AutocompleteOption API](https://mui.com/joy-ui/api/autocomplete-option/)
*/
const AutocompleteOption = /*#__PURE__*/React.forwardRef(function AutocompleteOption(inProps, ref) {
const props = useThemeProps({
props: inProps,
name: 'JoyAutocompleteOption'
});
const {
children,
component = 'li',
color: colorProp = 'neutral',
variant: variantProp = 'plain',
className,
slots = {},
slotProps = {}
} = props,
other = _objectWithoutPropertiesLoose(props, _excluded);
const {
variant = variantProp,
color = colorProp
} = useVariantColor(inProps.variant, inProps.color);
const ownerState = _extends({}, props, {
component,
color,
variant
});
const classes = useUtilityClasses(ownerState);
const externalForwardedProps = _extends({}, other, {
component,
slots,
slotProps
});
const [SlotRoot, rootProps] = useSlot('root', {
ref,
className: clsx(classes.root, className),
elementType: AutocompleteOptionRoot,
externalForwardedProps,
ownerState,
additionalProps: {
as: component,
role: 'option'
}
});
return /*#__PURE__*/_jsx(SlotRoot, _extends({}, rootProps, {
children: children
}));
});
process.env.NODE_ENV !== "production" ? AutocompleteOption.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* @ignore
*/
children: PropTypes.node,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The color of the component. It supports those theme colors that make sense for this component.
* @default 'neutral'
*/
color: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['danger', 'neutral', 'primary', 'success', 'warning']), PropTypes.string]),
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component: PropTypes.elementType,
/**
* The props used for each slot inside.
* @default {}
*/
slotProps: PropTypes.shape({
root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
}),
/**
* The components used for each slot inside.
* @default {}
*/
slots: PropTypes.shape({
root: PropTypes.elementType
}),
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
/**
* The [global variant](https://mui.com/joy-ui/main-features/global-variants/) to use.
* @default 'plain'
*/
variant: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['contained', 'light', 'outlined', 'text']), PropTypes.string])
} : void 0;
export default AutocompleteOption;