UNPKG

4.61 kBJavaScriptView Raw
1import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2import _extends from "@babel/runtime/helpers/esm/extends";
3const _excluded = ["className", "color", "component", "disableGutters", "disableSticky", "inset"];
4import * as React from 'react';
5import PropTypes from 'prop-types';
6import clsx from 'clsx';
7import { unstable_composeClasses as composeClasses } from '@mui/base';
8import styled from '../styles/styled';
9import useThemeProps from '../styles/useThemeProps';
10import capitalize from '../utils/capitalize';
11import { getListSubheaderUtilityClass } from './listSubheaderClasses';
12import { jsx as _jsx } from "react/jsx-runtime";
13
14const useUtilityClasses = ownerState => {
15 const {
16 classes,
17 color,
18 disableGutters,
19 inset,
20 disableSticky
21 } = ownerState;
22 const slots = {
23 root: ['root', color !== 'default' && `color${capitalize(color)}`, !disableGutters && 'gutters', inset && 'inset', !disableSticky && 'sticky']
24 };
25 return composeClasses(slots, getListSubheaderUtilityClass, classes);
26};
27
28const ListSubheaderRoot = styled('li', {
29 name: 'MuiListSubheader',
30 slot: 'Root',
31 overridesResolver: (props, styles) => {
32 const {
33 ownerState
34 } = props;
35 return [styles.root, ownerState.color !== 'default' && styles[`color${capitalize(ownerState.color)}`], !ownerState.disableGutters && styles.gutters, ownerState.inset && styles.inset, !ownerState.disableSticky && styles.sticky];
36 }
37})(({
38 theme,
39 ownerState
40}) => _extends({
41 boxSizing: 'border-box',
42 lineHeight: '48px',
43 listStyle: 'none',
44 color: (theme.vars || theme).palette.text.secondary,
45 fontFamily: theme.typography.fontFamily,
46 fontWeight: theme.typography.fontWeightMedium,
47 fontSize: theme.typography.pxToRem(14)
48}, ownerState.color === 'primary' && {
49 color: (theme.vars || theme).palette.primary.main
50}, ownerState.color === 'inherit' && {
51 color: 'inherit'
52}, !ownerState.disableGutters && {
53 paddingLeft: 16,
54 paddingRight: 16
55}, ownerState.inset && {
56 paddingLeft: 72
57}, !ownerState.disableSticky && {
58 position: 'sticky',
59 top: 0,
60 zIndex: 1,
61 backgroundColor: (theme.vars || theme).palette.background.paper
62}));
63const ListSubheader = /*#__PURE__*/React.forwardRef(function ListSubheader(inProps, ref) {
64 const props = useThemeProps({
65 props: inProps,
66 name: 'MuiListSubheader'
67 });
68
69 const {
70 className,
71 color = 'default',
72 component = 'li',
73 disableGutters = false,
74 disableSticky = false,
75 inset = false
76 } = props,
77 other = _objectWithoutPropertiesLoose(props, _excluded);
78
79 const ownerState = _extends({}, props, {
80 color,
81 component,
82 disableGutters,
83 disableSticky,
84 inset
85 });
86
87 const classes = useUtilityClasses(ownerState);
88 return /*#__PURE__*/_jsx(ListSubheaderRoot, _extends({
89 as: component,
90 className: clsx(classes.root, className),
91 ref: ref,
92 ownerState: ownerState
93 }, other));
94});
95process.env.NODE_ENV !== "production" ? ListSubheader.propTypes
96/* remove-proptypes */
97= {
98 // ----------------------------- Warning --------------------------------
99 // | These PropTypes are generated from the TypeScript type definitions |
100 // | To update them edit the d.ts file and run "yarn proptypes" |
101 // ----------------------------------------------------------------------
102
103 /**
104 * The content of the component.
105 */
106 children: PropTypes.node,
107
108 /**
109 * Override or extend the styles applied to the component.
110 */
111 classes: PropTypes.object,
112
113 /**
114 * @ignore
115 */
116 className: PropTypes.string,
117
118 /**
119 * The color of the component. It supports those theme colors that make sense for this component.
120 * @default 'default'
121 */
122 color: PropTypes.oneOf(['default', 'inherit', 'primary']),
123
124 /**
125 * The component used for the root node.
126 * Either a string to use a HTML element or a component.
127 */
128 component: PropTypes.elementType,
129
130 /**
131 * If `true`, the List Subheader will not have gutters.
132 * @default false
133 */
134 disableGutters: PropTypes.bool,
135
136 /**
137 * If `true`, the List Subheader will not stick to the top during scroll.
138 * @default false
139 */
140 disableSticky: PropTypes.bool,
141
142 /**
143 * If `true`, the List Subheader is indented.
144 * @default false
145 */
146 inset: PropTypes.bool,
147
148 /**
149 * The system prop that allows defining system overrides as well as additional CSS styles.
150 */
151 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
152} : void 0;
153export default ListSubheader;
\No newline at end of file