Repository navigation
Expand file tree
/
Copy pathStack.tsx
More file actions
62 lines (55 loc) · 1.59 KB
/
Copy pathStack.tsx
File metadata and controls
62 lines (55 loc) · 1.59 KB
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
import { makeStyles } from "@material-ui/core/styles"
import { CSSProperties } from "@material-ui/core/styles/withStyles"
import { FC } from "react"
import { ReactNode } from "react-markdown/lib/react-markdown"
import { combineClasses } from "../../util/combineClasses"
type Direction = "column" | "row"
export type StackProps = {
className?: string
direction?: Direction
spacing?: number
alignItems?: CSSProperties["alignItems"]
justifyContent?: CSSProperties["justifyContent"]
maxWidth?: CSSProperties["maxWidth"]
wrap?: CSSProperties["flexWrap"]
} & React.HTMLProps<HTMLDivElement>
type StyleProps = Omit<StackProps, "className">
const useStyles = makeStyles((theme) => ({
stack: {
display: "flex",
flexDirection: ({ direction }: StyleProps) => direction,
gap: ({ spacing }: StyleProps) => spacing && theme.spacing(spacing),
alignItems: ({ alignItems }: StyleProps) => alignItems,
justifyContent: ({ justifyContent }: StyleProps) => justifyContent,
flexWrap: ({ wrap }: StyleProps) => wrap,
maxWidth: ({ maxWidth }: StyleProps) => maxWidth,
[theme.breakpoints.down("sm")]: {
width: "100%",
},
},
}))
export const Stack: FC<StackProps & { children: ReactNode | ReactNode[] }> = ({
children,
className,
direction = "column",
spacing = 2,
alignItems,
justifyContent,
maxWidth,
wrap,
...divProps
}) => {
const styles = useStyles({
spacing,
direction,
alignItems,
justifyContent,
wrap,
maxWidth,
})
return (
<div {...divProps} className={combineClasses([styles.stack, className])}>
{children}
</div>
)
}