Last active
January 18, 2022 03:39
-
-
Save kgregory/963f68663ea46bb6ba572ee34954ea96 to your computer and use it in GitHub Desktop.
Inline component, horizontally flex components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from "react"; | |
import { makeStyles } from "@material-ui/core/styles"; | |
interface InlineProps | |
extends React.DetailedHTMLProps< | |
React.HTMLAttributes<HTMLDivElement>, | |
HTMLDivElement | |
> { | |
gap?: number; | |
reverse?: boolean; | |
} | |
const useStyles = makeStyles((theme) => ({ | |
root: ({ gap, reverse }: { gap: number; reverse: boolean }) => { | |
const attribute = reverse ? "marginLeft" : "marginRight"; | |
const direction = reverse ? "row-reverse" : "row"; | |
return { | |
display: "flex", | |
flexDirection: direction, | |
"& > *": { | |
[attribute]: theme.spacing(gap) | |
}, | |
"& > *:last-child": { | |
[attribute]: 0 | |
} | |
}; | |
} | |
})); | |
const Inline: React.FC<InlineProps> = ({ | |
gap = 1, | |
reverse = false, | |
children, | |
...other | |
}) => { | |
const classes = useStyles({ gap, reverse }); | |
return ( | |
<div className={classes.root} {...other}> | |
{children} | |
</div> | |
); | |
}; | |
export default Inline; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment