Skip to content

Instantly share code, notes, and snippets.

@mamadOuologuem
Last active August 10, 2021 05:38
Show Gist options
  • Save mamadOuologuem/d1df9d6e586cb4e5e8c376d7f0f18db9 to your computer and use it in GitHub Desktop.
Save mamadOuologuem/d1df9d6e586cb4e5e8c376d7f0f18db9 to your computer and use it in GitHub Desktop.
A Material Divider with text in middle
import React from "react";
import { Grid, Divider as MuiDivider } from "@material-ui/core";
const Divider = ({ children, ...props }) => (
<Grid container alignItems="center" spacing={3} {...props}>
<Grid item xs>
<MuiDivider />
</Grid>
<Grid item>{children}</Grid>
<Grid item xs>
<MuiDivider />
</Grid>
</Grid>
);
export default Divider;
@mamadOuologuem
Copy link
Author

Some comments

  • Here is a playground in codesandbox
  • It is based on Material-ui Divider
  • For now, it is handling only horizontal dividers (feel free to contribute if wanted 🙂)

How it looks:
image

@plusiv
Copy link

plusiv commented Jun 2, 2021

Great!! Good Job! Thank you

@dragon20002
Copy link

dragon20002 commented Aug 10, 2021

  • Add textAlign feature
import React from "react";
import { Grid, Divider as MuiDivider } from "@material-ui/core";

const Divider = ({ children, textAlign, ...props }) => (
  <Grid container alignItems="center" spacing={3} {...props}>
    <Grid item xs={textAlign === 'left' ? 2 : true}>
      <MuiDivider />
    </Grid>
    <Grid item>{children}</Grid>
    <Grid item xs={textAlign === 'right' ? 2 : true}>
      <MuiDivider />
    </Grid>
  </Grid>
);

export default Divider;
<Divider textAlign="left">LEFT</Divider>
<Divider>CENTER</Divider>
<Divider textAlign="right">RIGHT</Divider>

text-divider

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment