-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
/
Copy pathTimelineItem.js
133 lines (119 loc) · 4.24 KB
/
TimelineItem.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
'use client';
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { isMuiElement } from '@mui/material/utils';
import { styled, useThemeProps } from '@mui/material/styles';
import { unstable_composeClasses as composeClasses } from '@mui/base';
import { timelineContentClasses } from '../TimelineContent';
import { timelineOppositeContentClasses } from '../TimelineOppositeContent';
import TimelineContext from '../Timeline/TimelineContext';
import { getTimelineItemUtilityClass } from './timelineItemClasses';
import convertTimelinePositionToClass from '../internal/convertTimelinePositionToClass';
const useUtilityClasses = (ownerState) => {
const { position, classes, hasOppositeContent } = ownerState;
const slots = {
root: [
'root',
convertTimelinePositionToClass(position),
!hasOppositeContent && 'missingOppositeContent',
],
};
return composeClasses(slots, getTimelineItemUtilityClass, classes);
};
const TimelineItemRoot = styled('li', {
name: 'MuiTimelineItem',
slot: 'Root',
overridesResolver: (props, styles) => {
const { ownerState } = props;
return [styles.root, styles[convertTimelinePositionToClass(ownerState.position)]];
},
})(({ ownerState }) => ({
listStyle: 'none',
display: 'flex',
position: 'relative',
minHeight: 70,
...(ownerState.position === 'left' && {
flexDirection: 'row-reverse',
}),
...((ownerState.position === 'alternate' || ownerState.position === 'alternate-reverse') && {
[`&:nth-of-type(${ownerState.position === 'alternate' ? 'even' : 'odd'})`]: {
flexDirection: 'row-reverse',
[`& .${timelineContentClasses.root}`]: {
textAlign: 'right',
},
[`& .${timelineOppositeContentClasses.root}`]: {
textAlign: 'left',
},
},
}),
...(!ownerState.hasOppositeContent && {
'&::before': {
content: '""',
flex: 1,
padding: '6px 16px',
},
}),
}));
const TimelineItem = React.forwardRef(function TimelineItem(inProps, ref) {
const props = useThemeProps({ props: inProps, name: 'MuiTimelineItem' });
const { position: positionProp, className, ...other } = props;
const { position: positionContext } = React.useContext(TimelineContext);
let hasOppositeContent = false;
React.Children.forEach(props.children, (child) => {
if (isMuiElement(child, ['TimelineOppositeContent'])) {
hasOppositeContent = true;
}
});
const ownerState = {
...props,
position: positionProp || positionContext || 'right',
hasOppositeContent,
};
const classes = useUtilityClasses(ownerState);
const contextValue = React.useMemo(
() => ({ position: ownerState.position }),
[ownerState.position],
);
return (
<TimelineContext.Provider value={contextValue}>
<TimelineItemRoot
className={clsx(classes.root, className)}
ownerState={ownerState}
ref={ref}
{...other}
/>
</TimelineContext.Provider>
);
});
TimelineItem.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the d.ts file and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* The content of the component.
*/
children: PropTypes.node,
/**
* Override or extend the styles applied to the component.
*/
classes: PropTypes.object,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The position where the timeline's item should appear.
*/
position: PropTypes.oneOf(['alternate-reverse', 'alternate', 'left', 'right']),
/**
* 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,
]),
};
export default TimelineItem;