diff options
author | crupest <crupest@outlook.com> | 2023-07-30 20:52:13 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2023-07-30 20:52:13 +0800 |
commit | a148f11c193d35ba489f887ed393aedf58a1c714 (patch) | |
tree | 0028ec26d0cce5fb5a460777105be94a2084b704 /FrontEnd/src/views/common/button | |
parent | 001712ec0ae0de86ec7d2c36e2fff8bccc55bab5 (diff) | |
download | timeline-a148f11c193d35ba489f887ed393aedf58a1c714.tar.gz timeline-a148f11c193d35ba489f887ed393aedf58a1c714.tar.bz2 timeline-a148f11c193d35ba489f887ed393aedf58a1c714.zip |
...
Diffstat (limited to 'FrontEnd/src/views/common/button')
-rw-r--r-- | FrontEnd/src/views/common/button/ButtonRow.css | 0 | ||||
-rw-r--r-- | FrontEnd/src/views/common/button/ButtonRow.tsx | 62 | ||||
-rw-r--r-- | FrontEnd/src/views/common/button/index.tsx | 3 |
3 files changed, 64 insertions, 1 deletions
diff --git a/FrontEnd/src/views/common/button/ButtonRow.css b/FrontEnd/src/views/common/button/ButtonRow.css new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/FrontEnd/src/views/common/button/ButtonRow.css diff --git a/FrontEnd/src/views/common/button/ButtonRow.tsx b/FrontEnd/src/views/common/button/ButtonRow.tsx new file mode 100644 index 00000000..eea60cc4 --- /dev/null +++ b/FrontEnd/src/views/common/button/ButtonRow.tsx @@ -0,0 +1,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> + ); +} diff --git a/FrontEnd/src/views/common/button/index.tsx b/FrontEnd/src/views/common/button/index.tsx index cff5ba3f..73038849 100644 --- a/FrontEnd/src/views/common/button/index.tsx +++ b/FrontEnd/src/views/common/button/index.tsx @@ -2,5 +2,6 @@ import Button from "./Button"; import FlatButton from "./FlatButton"; import IconButton from "./IconButton"; import LoadingButton from "./LoadingButton"; +import ButtonRow from "./ButtonRow"; -export { Button, FlatButton, IconButton, LoadingButton }; +export { Button, FlatButton, IconButton, LoadingButton, ButtonRow }; |