UNPKG

4.03 kBJavaScriptView Raw
1'use client';
2
3import * as React from 'react';
4import PropTypes from 'prop-types';
5import clsx from 'clsx';
6import composeClasses from '@mui/utils/composeClasses';
7import { styled } from "../zero-styled/index.js";
8import { useDefaultProps } from "../DefaultPropsProvider/index.js";
9import ListContext from "./ListContext.js";
10import { getListUtilityClass } from "./listClasses.js";
11import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
12const useUtilityClasses = ownerState => {
13 const {
14 classes,
15 disablePadding,
16 dense,
17 subheader
18 } = ownerState;
19 const slots = {
20 root: ['root', !disablePadding && 'padding', dense && 'dense', subheader && 'subheader']
21 };
22 return composeClasses(slots, getListUtilityClass, classes);
23};
24const ListRoot = styled('ul', {
25 name: 'MuiList',
26 slot: 'Root',
27 overridesResolver: (props, styles) => {
28 const {
29 ownerState
30 } = props;
31 return [styles.root, !ownerState.disablePadding && styles.padding, ownerState.dense && styles.dense, ownerState.subheader && styles.subheader];
32 }
33})({
34 listStyle: 'none',
35 margin: 0,
36 padding: 0,
37 position: 'relative',
38 variants: [{
39 props: ({
40 ownerState
41 }) => !ownerState.disablePadding,
42 style: {
43 paddingTop: 8,
44 paddingBottom: 8
45 }
46 }, {
47 props: ({
48 ownerState
49 }) => ownerState.subheader,
50 style: {
51 paddingTop: 0
52 }
53 }]
54});
55const List = /*#__PURE__*/React.forwardRef(function List(inProps, ref) {
56 const props = useDefaultProps({
57 props: inProps,
58 name: 'MuiList'
59 });
60 const {
61 children,
62 className,
63 component = 'ul',
64 dense = false,
65 disablePadding = false,
66 subheader,
67 ...other
68 } = props;
69 const context = React.useMemo(() => ({
70 dense
71 }), [dense]);
72 const ownerState = {
73 ...props,
74 component,
75 dense,
76 disablePadding
77 };
78 const classes = useUtilityClasses(ownerState);
79 return /*#__PURE__*/_jsx(ListContext.Provider, {
80 value: context,
81 children: /*#__PURE__*/_jsxs(ListRoot, {
82 as: component,
83 className: clsx(classes.root, className),
84 ref: ref,
85 ownerState: ownerState,
86 ...other,
87 children: [subheader, children]
88 })
89 });
90});
91process.env.NODE_ENV !== "production" ? List.propTypes /* remove-proptypes */ = {
92 // ┌────────────────────────────── Warning ──────────────────────────────┐
93 // │ These PropTypes are generated from the TypeScript type definitions. │
94 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
95 // └─────────────────────────────────────────────────────────────────────┘
96 /**
97 * The content of the component.
98 */
99 children: PropTypes.node,
100 /**
101 * Override or extend the styles applied to the component.
102 */
103 classes: PropTypes.object,
104 /**
105 * @ignore
106 */
107 className: PropTypes.string,
108 /**
109 * The component used for the root node.
110 * Either a string to use a HTML element or a component.
111 */
112 component: PropTypes.elementType,
113 /**
114 * If `true`, compact vertical padding designed for keyboard and mouse input is used for
115 * the list and list items.
116 * The prop is available to descendant components as the `dense` context.
117 * @default false
118 */
119 dense: PropTypes.bool,
120 /**
121 * If `true`, vertical padding is removed from the list.
122 * @default false
123 */
124 disablePadding: PropTypes.bool,
125 /**
126 * The content of the subheader, normally `ListSubheader`.
127 */
128 subheader: PropTypes.node,
129 /**
130 * The system prop that allows defining system overrides as well as additional CSS styles.
131 */
132 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
133} : void 0;
134export default List;
\No newline at end of file