UNPKG

9.26 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 { alpha } from '@mui/system/colorManipulator';
8import { styled } from "../zero-styled/index.js";
9import memoTheme from "../utils/memoTheme.js";
10import { useDefaultProps } from "../DefaultPropsProvider/index.js";
11import { getDividerUtilityClass } from "./dividerClasses.js";
12import { jsx as _jsx } from "react/jsx-runtime";
13const useUtilityClasses = ownerState => {
14 const {
15 absolute,
16 children,
17 classes,
18 flexItem,
19 light,
20 orientation,
21 textAlign,
22 variant
23 } = ownerState;
24 const slots = {
25 root: ['root', absolute && 'absolute', variant, light && 'light', orientation === 'vertical' && 'vertical', flexItem && 'flexItem', children && 'withChildren', children && orientation === 'vertical' && 'withChildrenVertical', textAlign === 'right' && orientation !== 'vertical' && 'textAlignRight', textAlign === 'left' && orientation !== 'vertical' && 'textAlignLeft'],
26 wrapper: ['wrapper', orientation === 'vertical' && 'wrapperVertical']
27 };
28 return composeClasses(slots, getDividerUtilityClass, classes);
29};
30const DividerRoot = styled('div', {
31 name: 'MuiDivider',
32 slot: 'Root',
33 overridesResolver: (props, styles) => {
34 const {
35 ownerState
36 } = props;
37 return [styles.root, ownerState.absolute && styles.absolute, styles[ownerState.variant], ownerState.light && styles.light, ownerState.orientation === 'vertical' && styles.vertical, ownerState.flexItem && styles.flexItem, ownerState.children && styles.withChildren, ownerState.children && ownerState.orientation === 'vertical' && styles.withChildrenVertical, ownerState.textAlign === 'right' && ownerState.orientation !== 'vertical' && styles.textAlignRight, ownerState.textAlign === 'left' && ownerState.orientation !== 'vertical' && styles.textAlignLeft];
38 }
39})(memoTheme(({
40 theme
41}) => ({
42 margin: 0,
43 // Reset browser default style.
44 flexShrink: 0,
45 borderWidth: 0,
46 borderStyle: 'solid',
47 borderColor: (theme.vars || theme).palette.divider,
48 borderBottomWidth: 'thin',
49 variants: [{
50 props: {
51 absolute: true
52 },
53 style: {
54 position: 'absolute',
55 bottom: 0,
56 left: 0,
57 width: '100%'
58 }
59 }, {
60 props: {
61 light: true
62 },
63 style: {
64 borderColor: theme.vars ? `rgba(${theme.vars.palette.dividerChannel} / 0.08)` : alpha(theme.palette.divider, 0.08)
65 }
66 }, {
67 props: {
68 variant: 'inset'
69 },
70 style: {
71 marginLeft: 72
72 }
73 }, {
74 props: {
75 variant: 'middle',
76 orientation: 'horizontal'
77 },
78 style: {
79 marginLeft: theme.spacing(2),
80 marginRight: theme.spacing(2)
81 }
82 }, {
83 props: {
84 variant: 'middle',
85 orientation: 'vertical'
86 },
87 style: {
88 marginTop: theme.spacing(1),
89 marginBottom: theme.spacing(1)
90 }
91 }, {
92 props: {
93 orientation: 'vertical'
94 },
95 style: {
96 height: '100%',
97 borderBottomWidth: 0,
98 borderRightWidth: 'thin'
99 }
100 }, {
101 props: {
102 flexItem: true
103 },
104 style: {
105 alignSelf: 'stretch',
106 height: 'auto'
107 }
108 }, {
109 props: ({
110 ownerState
111 }) => !!ownerState.children,
112 style: {
113 display: 'flex',
114 textAlign: 'center',
115 border: 0,
116 borderTopStyle: 'solid',
117 borderLeftStyle: 'solid',
118 '&::before, &::after': {
119 content: '""',
120 alignSelf: 'center'
121 }
122 }
123 }, {
124 props: ({
125 ownerState
126 }) => ownerState.children && ownerState.orientation !== 'vertical',
127 style: {
128 '&::before, &::after': {
129 width: '100%',
130 borderTop: `thin solid ${(theme.vars || theme).palette.divider}`,
131 borderTopStyle: 'inherit'
132 }
133 }
134 }, {
135 props: ({
136 ownerState
137 }) => ownerState.orientation === 'vertical' && ownerState.children,
138 style: {
139 flexDirection: 'column',
140 '&::before, &::after': {
141 height: '100%',
142 borderLeft: `thin solid ${(theme.vars || theme).palette.divider}`,
143 borderLeftStyle: 'inherit'
144 }
145 }
146 }, {
147 props: ({
148 ownerState
149 }) => ownerState.textAlign === 'right' && ownerState.orientation !== 'vertical',
150 style: {
151 '&::before': {
152 width: '90%'
153 },
154 '&::after': {
155 width: '10%'
156 }
157 }
158 }, {
159 props: ({
160 ownerState
161 }) => ownerState.textAlign === 'left' && ownerState.orientation !== 'vertical',
162 style: {
163 '&::before': {
164 width: '10%'
165 },
166 '&::after': {
167 width: '90%'
168 }
169 }
170 }]
171})));
172const DividerWrapper = styled('span', {
173 name: 'MuiDivider',
174 slot: 'Wrapper',
175 overridesResolver: (props, styles) => {
176 const {
177 ownerState
178 } = props;
179 return [styles.wrapper, ownerState.orientation === 'vertical' && styles.wrapperVertical];
180 }
181})(memoTheme(({
182 theme
183}) => ({
184 display: 'inline-block',
185 paddingLeft: `calc(${theme.spacing(1)} * 1.2)`,
186 paddingRight: `calc(${theme.spacing(1)} * 1.2)`,
187 whiteSpace: 'nowrap',
188 variants: [{
189 props: {
190 orientation: 'vertical'
191 },
192 style: {
193 paddingTop: `calc(${theme.spacing(1)} * 1.2)`,
194 paddingBottom: `calc(${theme.spacing(1)} * 1.2)`
195 }
196 }]
197})));
198const Divider = /*#__PURE__*/React.forwardRef(function Divider(inProps, ref) {
199 const props = useDefaultProps({
200 props: inProps,
201 name: 'MuiDivider'
202 });
203 const {
204 absolute = false,
205 children,
206 className,
207 orientation = 'horizontal',
208 component = children || orientation === 'vertical' ? 'div' : 'hr',
209 flexItem = false,
210 light = false,
211 role = component !== 'hr' ? 'separator' : undefined,
212 textAlign = 'center',
213 variant = 'fullWidth',
214 ...other
215 } = props;
216 const ownerState = {
217 ...props,
218 absolute,
219 component,
220 flexItem,
221 light,
222 orientation,
223 role,
224 textAlign,
225 variant
226 };
227 const classes = useUtilityClasses(ownerState);
228 return /*#__PURE__*/_jsx(DividerRoot, {
229 as: component,
230 className: clsx(classes.root, className),
231 role: role,
232 ref: ref,
233 ownerState: ownerState,
234 "aria-orientation": role === 'separator' && (component !== 'hr' || orientation === 'vertical') ? orientation : undefined,
235 ...other,
236 children: children ? /*#__PURE__*/_jsx(DividerWrapper, {
237 className: classes.wrapper,
238 ownerState: ownerState,
239 children: children
240 }) : null
241 });
242});
243
244/**
245 * The following flag is used to ensure that this component isn't tabbable i.e.
246 * does not get highlight/focus inside of MUI List.
247 */
248if (Divider) {
249 Divider.muiSkipListHighlight = true;
250}
251process.env.NODE_ENV !== "production" ? Divider.propTypes /* remove-proptypes */ = {
252 // ┌────────────────────────────── Warning ──────────────────────────────┐
253 // │ These PropTypes are generated from the TypeScript type definitions. │
254 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
255 // └─────────────────────────────────────────────────────────────────────┘
256 /**
257 * Absolutely position the element.
258 * @default false
259 */
260 absolute: PropTypes.bool,
261 /**
262 * The content of the component.
263 */
264 children: PropTypes.node,
265 /**
266 * Override or extend the styles applied to the component.
267 */
268 classes: PropTypes.object,
269 /**
270 * @ignore
271 */
272 className: PropTypes.string,
273 /**
274 * The component used for the root node.
275 * Either a string to use a HTML element or a component.
276 */
277 component: PropTypes.elementType,
278 /**
279 * If `true`, a vertical divider will have the correct height when used in flex container.
280 * (By default, a vertical divider will have a calculated height of `0px` if it is the child of a flex container.)
281 * @default false
282 */
283 flexItem: PropTypes.bool,
284 /**
285 * If `true`, the divider will have a lighter color.
286 * @default false
287 * @deprecated Use <Divider sx={{ opacity: 0.6 }} /> (or any opacity or color) instead. See [Migrating from deprecated APIs](https://mui.com/material-ui/migration/migrating-from-deprecated-apis/) for more details.
288 */
289 light: PropTypes.bool,
290 /**
291 * The component orientation.
292 * @default 'horizontal'
293 */
294 orientation: PropTypes.oneOf(['horizontal', 'vertical']),
295 /**
296 * @ignore
297 */
298 role: PropTypes /* @typescript-to-proptypes-ignore */.string,
299 /**
300 * The system prop that allows defining system overrides as well as additional CSS styles.
301 */
302 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
303 /**
304 * The text alignment.
305 * @default 'center'
306 */
307 textAlign: PropTypes.oneOf(['center', 'left', 'right']),
308 /**
309 * The variant to use.
310 * @default 'fullWidth'
311 */
312 variant: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['fullWidth', 'inset', 'middle']), PropTypes.string])
313} : void 0;
314export default Divider;
\No newline at end of file