blob: eea60cc4755b7bc20b93aac43ac9bcfc19a174e6 (
plain)
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 { ComponentPropsWithoutRef, Ref } from "react";
import classNames from "classnames";
import Button from "./Button";
import FlatButton from "./FlatButton";
import IconButton from "./IconButton";
import LoadingButton from "./LoadingButton";
import "./ButtonRow.css";
type ButtonRowButton = (
| {
type: "normal";
props: ComponentPropsWithoutRef<typeof Button>;
}
| {
type: "flat";
props: ComponentPropsWithoutRef<typeof FlatButton>;
}
| {
type: "icon";
props: ComponentPropsWithoutRef<typeof IconButton>;
}
| { type: "loading"; props: ComponentPropsWithoutRef<typeof LoadingButton> }
) & { key: string | number };
interface ButtonRowProps {
className?: string;
containerRef?: Ref<HTMLDivElement>;
buttons: ButtonRowButton[];
buttonsClassName?: string;
}
export default function ButtonRow({
className,
containerRef,
buttons,
buttonsClassName,
}: ButtonRowProps) {
return (
<div ref={containerRef} className={classNames("cru-button-row", className)}>
{buttons.map((button) => {
const { type, key, props } = button;
const newClassName = classNames(props.className, buttonsClassName);
switch (type) {
case "normal":
return <Button key={key} {...props} className={newClassName} />;
case "flat":
return <FlatButton key={key} {...props} className={newClassName} />;
case "icon":
return <IconButton key={key} {...props} className={newClassName} />;
case "loading":
return (
<LoadingButton key={key} {...props} className={newClassName} />
);
default:
throw new Error();
}
})}
</div>
);
}
|