|
1 |
| -import { makeStyles } from "@mui/styles"; |
2 |
| -import { CSSProperties } from "@mui/styles/withStyles"; |
3 |
| -import { FC } from "react"; |
4 |
| -import { ReactNode } from "react-markdown/lib/react-markdown"; |
5 |
| -import { combineClasses } from "utils/combineClasses"; |
6 |
| - |
7 |
| -type Direction = "column" | "row"; |
| 1 | +import type { FC } from "react"; |
| 2 | +import type { CSSObject } from "@emotion/react"; |
8 | 3 |
|
9 | 4 | export type StackProps = {
|
10 | 5 | className?: string;
|
11 |
| - direction?: Direction; |
| 6 | + direction?: "column" | "row"; |
12 | 7 | spacing?: number;
|
13 |
| - alignItems?: CSSProperties["alignItems"]; |
14 |
| - justifyContent?: CSSProperties["justifyContent"]; |
15 |
| - maxWidth?: CSSProperties["maxWidth"]; |
16 |
| - wrap?: CSSProperties["flexWrap"]; |
| 8 | + alignItems?: CSSObject["alignItems"]; |
| 9 | + justifyContent?: CSSObject["justifyContent"]; |
| 10 | + maxWidth?: CSSObject["maxWidth"]; |
| 11 | + wrap?: CSSObject["flexWrap"]; |
17 | 12 | } & React.HTMLProps<HTMLDivElement>;
|
18 | 13 |
|
19 |
| -type StyleProps = Omit<StackProps, "className">; |
20 |
| - |
21 |
| -const useStyles = makeStyles((theme) => ({ |
22 |
| - stack: { |
23 |
| - display: "flex", |
24 |
| - flexDirection: ({ direction }: StyleProps) => direction, |
25 |
| - gap: ({ spacing }: StyleProps) => spacing && theme.spacing(spacing), |
26 |
| - alignItems: ({ alignItems }: StyleProps) => alignItems, |
27 |
| - justifyContent: ({ justifyContent }: StyleProps) => justifyContent, |
28 |
| - flexWrap: ({ wrap }: StyleProps) => wrap, |
29 |
| - maxWidth: ({ maxWidth }: StyleProps) => maxWidth, |
30 |
| - |
31 |
| - [theme.breakpoints.down("md")]: { |
32 |
| - width: "100%", |
33 |
| - }, |
34 |
| - }, |
35 |
| -})); |
36 |
| - |
37 |
| -export const Stack: FC<StackProps & { children: ReactNode | ReactNode[] }> = ({ |
38 |
| - children, |
39 |
| - className, |
40 |
| - direction = "column", |
41 |
| - spacing = 2, |
42 |
| - alignItems, |
43 |
| - justifyContent, |
44 |
| - maxWidth, |
45 |
| - wrap, |
46 |
| - ...divProps |
47 |
| -}) => { |
48 |
| - const styles = useStyles({ |
49 |
| - spacing, |
50 |
| - direction, |
| 14 | +export const Stack: FC<StackProps> = (props) => { |
| 15 | + const { |
| 16 | + children, |
| 17 | + direction = "column", |
| 18 | + spacing = 2, |
51 | 19 | alignItems,
|
52 | 20 | justifyContent,
|
53 |
| - wrap, |
54 | 21 | maxWidth,
|
55 |
| - }); |
| 22 | + wrap, |
| 23 | + ...divProps |
| 24 | + } = props; |
56 | 25 |
|
57 | 26 | return (
|
58 |
| - <div {...divProps} className={combineClasses([styles.stack, className])}> |
| 27 | + <div |
| 28 | + {...divProps} |
| 29 | + css={(theme) => ({ |
| 30 | + display: "flex", |
| 31 | + flexDirection: direction, |
| 32 | + gap: spacing && theme.spacing(spacing), |
| 33 | + alignItems: alignItems, |
| 34 | + justifyContent: justifyContent, |
| 35 | + flexWrap: wrap, |
| 36 | + maxWidth: maxWidth, |
| 37 | + |
| 38 | + [theme.breakpoints.down("md")]: { |
| 39 | + width: "100%", |
| 40 | + }, |
| 41 | + })} |
| 42 | + > |
59 | 43 | {children}
|
60 | 44 | </div>
|
61 | 45 | );
|
|
0 commit comments