Skip to content

[Timeline] Add support for align override on items #25862

@simonecervini

Description

@simonecervini
  • I have searched the issues of this repository and believe that this is not a duplicate.

Summary 💡

<Timeline /> component supports 3 different alignments: align: 'alternate' | 'left' | 'right'. While this is enough for most cases, I believe it could be useful to add support for override in each <TimelineItem /> with a align: 'left' | 'right' property or something similar.

Examples 🌈

import * as React from 'react';
import Timeline from '@material-ui/lab/Timeline';
import TimelineItem from '@material-ui/lab/TimelineItem';
import TimelineSeparator from '@material-ui/lab/TimelineSeparator';
import TimelineConnector from '@material-ui/lab/TimelineConnector';
import TimelineContent from '@material-ui/lab/TimelineContent';
import TimelineDot from '@material-ui/lab/TimelineDot';

export default function AlternateTimeline() {
  return (
    <Timeline align='alternate'>
      <TimelineItem align="right">
        <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 align='right'>
        <TimelineSeparator>
          <TimelineDot />
        </TimelineSeparator>
        <TimelineContent>Repeat</TimelineContent>
      </TimelineItem>
    </Timeline>
  );
}

Screenshot 2021-04-21 at 11 24 55

Motivation 🔦

It will allow to build an alternating timeline with grouped TimelineItem(s):

Screenshot 2021-04-21 at 11 44 24

I believe that the keyword is "groups". When you build a long <Timeline /> with multiple <TimelineItem />(s) rich of contents, align='alternate' helps to reduce void space in the page, but could also lead to a disorienting UI because similar components are placed in opposite positions. The best way to solve this problem is to group similar items.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready to takeHelp wanted. Guidance available. There is a high chance the change will be acceptedscope: timelineChanges related to the timeline.type: new featureExpand the scope of the product to solve a new problem.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions