aboutsummaryrefslogtreecommitdiff
path: root/FrontEnd/src/views/common/button/common.ts
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-06-26 00:00:54 +0800
committercrupest <crupest@outlook.com>2021-06-26 00:00:54 +0800
commitfa540c046d126449f77e46edd379bbc84e02d05d (patch)
tree1245f3fb8e9f505809da75a6ffbd2a62b06ebaed /FrontEnd/src/views/common/button/common.ts
parent8ee00da87e2fbfefeefecb01c68a2d297bdfb34b (diff)
downloadtimeline-fa540c046d126449f77e46edd379bbc84e02d05d.tar.gz
timeline-fa540c046d126449f77e46edd379bbc84e02d05d.tar.bz2
timeline-fa540c046d126449f77e46edd379bbc84e02d05d.zip
...
Diffstat (limited to 'FrontEnd/src/views/common/button/common.ts')
-rw-r--r--FrontEnd/src/views/common/button/common.ts31
1 files changed, 31 insertions, 0 deletions
diff --git a/FrontEnd/src/views/common/button/common.ts b/FrontEnd/src/views/common/button/common.ts
new file mode 100644
index 00000000..a9db959e
--- /dev/null
+++ b/FrontEnd/src/views/common/button/common.ts
@@ -0,0 +1,31 @@
+import React from "react";
+import classNames from "classnames";
+import { TFunction } from "i18next";
+
+import { convertI18nText, I18nText } from "@/common";
+import { PaletteColorType } from "@/palette";
+
+export type CommonButtonProps = {
+ text?: I18nText;
+ color?: PaletteColorType;
+} & React.ButtonHTMLAttributes<HTMLButtonElement>;
+
+export function calculateProps(
+ props: CommonButtonProps,
+ buttonClassName: string,
+ t: TFunction
+): {
+ children: React.ReactNode;
+ newProps: React.ButtonHTMLAttributes<HTMLButtonElement>;
+} {
+ const { text, color, className, children, ...otherProps } = props;
+ const newProps = {
+ className: classNames(buttonClassName, color ?? "primary", className),
+ ...otherProps,
+ };
+
+ return {
+ children: text != null ? convertI18nText(text, t) : children,
+ newProps: newProps,
+ };
+}