Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Timeline] Add alternate reverse position #37311

Merged
merged 17 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions docs/data/material/components/timeline/AlternateReverseTimeline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as React from 'react';
import Timeline from '@mui/lab/Timeline';
import TimelineItem from '@mui/lab/TimelineItem';
import TimelineSeparator from '@mui/lab/TimelineSeparator';
import TimelineConnector from '@mui/lab/TimelineConnector';
import TimelineContent from '@mui/lab/TimelineContent';
import TimelineDot from '@mui/lab/TimelineDot';

export default function AlternateReverseTimeline() {
return (
<Timeline position="alternate-reverse">
<TimelineItem>
<TimelineSeparator>
<TimelineDot />
<TimelineConnector />
</TimelineSeparator>
<TimelineContent>Eat</TimelineContent>
</TimelineItem>
<TimelineItem>
<TimelineSeparator>
<TimelineDot />
<TimelineConnector />
</TimelineSeparator>
<TimelineContent>Code</TimelineContent>
</TimelineItem>
<TimelineItem>
<TimelineSeparator>
<TimelineDot />
<TimelineConnector />
</TimelineSeparator>
<TimelineContent>Sleep</TimelineContent>
</TimelineItem>
<TimelineItem>
<TimelineSeparator>
<TimelineDot />
</TimelineSeparator>
<TimelineContent>Repeat</TimelineContent>
</TimelineItem>
</Timeline>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as React from 'react';
import Timeline from '@mui/lab/Timeline';
import TimelineItem from '@mui/lab/TimelineItem';
import TimelineSeparator from '@mui/lab/TimelineSeparator';
import TimelineConnector from '@mui/lab/TimelineConnector';
import TimelineContent from '@mui/lab/TimelineContent';
import TimelineDot from '@mui/lab/TimelineDot';

export default function AlternateReverseTimeline() {
return (
<Timeline position="alternate-reverse">
<TimelineItem>
<TimelineSeparator>
<TimelineDot />
<TimelineConnector />
</TimelineSeparator>
<TimelineContent>Eat</TimelineContent>
</TimelineItem>
<TimelineItem>
<TimelineSeparator>
<TimelineDot />
<TimelineConnector />
</TimelineSeparator>
<TimelineContent>Code</TimelineContent>
</TimelineItem>
<TimelineItem>
<TimelineSeparator>
<TimelineDot />
<TimelineConnector />
</TimelineSeparator>
<TimelineContent>Sleep</TimelineContent>
</TimelineItem>
<TimelineItem>
<TimelineSeparator>
<TimelineDot />
</TimelineSeparator>
<TimelineContent>Repeat</TimelineContent>
</TimelineItem>
</Timeline>
);
}
6 changes: 6 additions & 0 deletions docs/data/material/components/timeline/timeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ The timeline can display the events on alternating sides.

{{"demo": "AlternateTimeline.js"}}

## Reverse Alternating timeline

The timeline can display the events on alternating sides in reverse order.

{{"demo": "AlternateReverseTimeline.js"}}

## Color

The `TimelineDot` can appear in different colors from theme palette.
Expand Down
8 changes: 7 additions & 1 deletion docs/pages/material-ui/api/timeline-content.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
},
"name": "TimelineContent",
"styles": {
"classes": ["root", "positionRight", "positionLeft", "positionAlternate"],
"classes": [
"root",
"positionRight",
"positionLeft",
"positionAlternate",
"positionAlternateReverse"
],
"globalClasses": {},
"name": "MuiTimelineContent"
},
Expand Down
8 changes: 7 additions & 1 deletion docs/pages/material-ui/api/timeline-item.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"props": {
"children": { "type": { "name": "node" } },
"classes": { "type": { "name": "object" } },
"position": { "type": { "name": "enum", "description": "'left'<br>&#124;&nbsp;'right'" } },
"position": {
"type": {
"name": "enum",
"description": "'alternate-reverse'<br>&#124;&nbsp;'alternate'<br>&#124;&nbsp;'left'<br>&#124;&nbsp;'right'"
}
},
"sx": {
"type": {
"name": "union",
Expand All @@ -17,6 +22,7 @@
"positionLeft",
"positionRight",
"positionAlternate",
"positionAlternateReverse",
"missingOppositeContent"
],
"globalClasses": {},
Expand Down
8 changes: 7 additions & 1 deletion docs/pages/material-ui/api/timeline-opposite-content.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
},
"name": "TimelineOppositeContent",
"styles": {
"classes": ["root", "positionRight", "positionLeft", "positionAlternate"],
"classes": [
"root",
"positionRight",
"positionLeft",
"positionAlternate",
"positionAlternateReverse"
],
"globalClasses": {},
"name": "MuiTimelineOppositeContent"
},
Expand Down
10 changes: 8 additions & 2 deletions docs/pages/material-ui/api/timeline.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"position": {
"type": {
"name": "enum",
"description": "'alternate'<br>&#124;&nbsp;'left'<br>&#124;&nbsp;'right'"
"description": "'alternate-reverse'<br>&#124;&nbsp;'alternate'<br>&#124;&nbsp;'left'<br>&#124;&nbsp;'right'"
},
"default": "'right'"
},
Expand All @@ -19,7 +19,13 @@
},
"name": "Timeline",
"styles": {
"classes": ["root", "positionLeft", "positionRight", "positionAlternate"],
"classes": [
"root",
"positionLeft",
"positionRight",
"positionAlternate",
"positionAlternateReverse"
],
"globalClasses": {},
"name": "MuiTimeline"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
"description": "Estilos aplicados para {{nodeName}} se {{conditions}}.",
"nodeName": "o elemento raiz",
"conditions": "<code>position=\"alternate\"</code>"
},
"positionAlternateReverse": {
"description": "Estilos aplicados para {{nodeName}} se {{conditions}}.",
"nodeName": "o elemento raiz",
"conditions": "<code>position=\"alternate-reverse\"</code>"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>position=\"alternate\"</code>"
},
"positionAlternateReverse": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>position=\"alternate-reverse\"</code>"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>position=\"alternate\"</code>"
},
"positionAlternateReverse": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>position=\"alternate-reverse\"</code>"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
"nodeName": "o elemento raiz",
"conditions": "<code>position=\"alternate\"</code>"
},
"positionAlternateReverse": {
"description": "Estilos aplicados para {{nodeName}} se {{conditions}}.",
"nodeName": "o elemento raiz",
"conditions": "<code>position=\"alternate-reverse\"</code>"
},
"missingOppositeContent": {
"description": "Estilos aplicados para {{nodeName}} se {{conditions}}.",
"nodeName": "o elemento raiz",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
"nodeName": "the root element",
"conditions": "<code>position=\"alternate\"</code>"
},
"positionAlternateReverse": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>position=\"alternate-reverse\"</code>"
},
"missingOppositeContent": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
Expand Down
5 changes: 5 additions & 0 deletions docs/translations/api-docs/timeline-item/timeline-item.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
"nodeName": "the root element",
"conditions": "<code>position=\"alternate\"</code>"
},
"positionAlternateReverse": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>position=\"alternate-reverse\"</code>"
},
"missingOppositeContent": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
"description": "Estilos aplicados para {{nodeName}} se {{conditions}}.",
"nodeName": "o elemento raiz",
"conditions": "<code>position=\"alternate\"</code>"
},
"positionAlternateReverse": {
"description": "Estilos aplicados para {{nodeName}} se {{conditions}}.",
"nodeName": "o elemento raiz",
"conditions": "<code>position=\"alternate-reverse\"</code>"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>position=\"alternate\"</code>"
},
"positionAlternateReverse": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>position=\"alternate-reverse\"</code>"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>position=\"alternate\"</code>"
},
"positionAlternateReverse": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>position=\"alternate-reverse\"</code>"
}
}
}
5 changes: 5 additions & 0 deletions docs/translations/api-docs/timeline/timeline-pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
"description": "Estilos aplicados para {{nodeName}} se {{conditions}}.",
"nodeName": "o elemento raiz",
"conditions": "<code>position=\"alternate\"</code>"
},
"positionAlternateReverse": {
"description": "Estilos aplicados para {{nodeName}} se {{conditions}}.",
"nodeName": "o elemento raiz",
"conditions": "<code>position=\"alternate-reverse\"</code>"
}
}
}
5 changes: 5 additions & 0 deletions docs/translations/api-docs/timeline/timeline-zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>position=\"alternate\"</code>"
},
"positionAlternateReverse": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>position=\"alternate-reverse\"</code>"
}
}
}
5 changes: 5 additions & 0 deletions docs/translations/api-docs/timeline/timeline.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>position=\"alternate\"</code>"
},
"positionAlternateReverse": {
"description": "Styles applied to {{nodeName}} if {{conditions}}.",
"nodeName": "the root element",
"conditions": "<code>position=\"alternate-reverse\"</code>"
}
}
}
6 changes: 4 additions & 2 deletions packages/mui-lab/src/Timeline/Timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface TimelineProps extends StandardProps<React.HTMLAttributes<HTMLUL
* The position where the TimelineContent should appear relative to the time axis.
* @default 'right'
*/
position?: 'left' | 'right' | 'alternate';
position?: 'left' | 'right' | 'alternate' | 'alternate-reverse';
/**
* The content of the component.
*/
Expand All @@ -34,6 +34,8 @@ export interface TimelineProps extends StandardProps<React.HTMLAttributes<HTMLUL
positionRight?: string;
/** Styles applied to the root element if `position="alternate"`. */
positionAlternate?: string;
/** Styles applied to the root element if `position="alternate-reverse"`. */
positionAlternateReverse?: string;
};

/**
Expand Down Expand Up @@ -128,7 +130,7 @@ Timeline.propTypes /* remove-proptypes */ = {
* The position where the TimelineContent should appear relative to the time axis.
* @default 'right'
*/
position: PropTypes.oneOf(['alternate', 'left', 'right']),
position: PropTypes.oneOf(['alternate-reverse', 'alternate', 'left', 'right']),
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
Expand Down
1 change: 1 addition & 0 deletions packages/mui-lab/src/Timeline/timelineClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const timelineClasses = generateUtilityClasses('MuiTimeline', [
'positionLeft',
'positionRight',
'positionAlternate',
'positionAlternateReverse',
]);

export default timelineClasses;
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export interface TimelineContentClasses {
positionLeft: string;
/** Styles applied to the root element if `position="alternate"`. */
positionAlternate: string;
/** Styles applied to the root element if `position="alternate-reverse"`. */
positionAlternateReverse: string;
}

export type TimelineContentClassKey = keyof TimelineContentClasses;
Expand All @@ -20,7 +22,7 @@ export function getTimelineContentUtilityClass(slot: string): string {

const timelineContentClasses: TimelineContentClasses = generateUtilityClasses(
'MuiTimelineContent',
['root', 'positionLeft', 'positionRight', 'positionAlternate'],
['root', 'positionLeft', 'positionRight', 'positionAlternate', 'positionAlternateReverse'],
);

export default timelineContentClasses;
2 changes: 1 addition & 1 deletion packages/mui-lab/src/TimelineItem/TimelineItem.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface TimelineItemProps extends StandardProps<React.HTMLAttributes<HT
/**
* The position where the timeline's item should appear.
*/
position?: 'left' | 'right';
position?: 'left' | 'right' | 'alternate' | 'alternate-reverse';
/**
* The content of the component.
*/
Expand Down
6 changes: 3 additions & 3 deletions packages/mui-lab/src/TimelineItem/TimelineItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ const TimelineItemRoot = styled('li', {
...(ownerState.position === 'left' && {
flexDirection: 'row-reverse',
}),
...(ownerState.position === 'alternate' && {
'&:nth-of-type(even)': {
...((ownerState.position === 'alternate' || ownerState.position === 'alternate-reverse') && {
[`&:nth-of-type(${ownerState.position === 'alternate' ? 'even' : 'odd'})`]: {
flexDirection: 'row-reverse',
[`& .${timelineContentClasses.root}`]: {
textAlign: 'right',
Expand Down Expand Up @@ -117,7 +117,7 @@ TimelineItem.propTypes /* remove-proptypes */ = {
/**
* The position where the timeline's item should appear.
*/
position: PropTypes.oneOf(['left', 'right']),
position: PropTypes.oneOf(['alternate-reverse', 'alternate', 'left', 'right']),
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
Expand Down
Loading