diff options
Diffstat (limited to 'FrontEnd/src/views/common/button')
-rw-r--r-- | FrontEnd/src/views/common/button/Button.css | 72 | ||||
-rw-r--r-- | FrontEnd/src/views/common/button/Button.tsx | 33 | ||||
-rw-r--r-- | FrontEnd/src/views/common/button/FlatButton.css | 8 | ||||
-rw-r--r-- | FrontEnd/src/views/common/button/FlatButton.tsx | 31 | ||||
-rw-r--r-- | FrontEnd/src/views/common/button/LoadingButton.tsx | 21 | ||||
-rw-r--r-- | FrontEnd/src/views/common/button/TextButton.css | 8 | ||||
-rw-r--r-- | FrontEnd/src/views/common/button/TextButton.tsx | 31 | ||||
-rw-r--r-- | FrontEnd/src/views/common/button/common.ts | 31 |
8 files changed, 173 insertions, 62 deletions
diff --git a/FrontEnd/src/views/common/button/Button.css b/FrontEnd/src/views/common/button/Button.css new file mode 100644 index 00000000..b6df222f --- /dev/null +++ b/FrontEnd/src/views/common/button/Button.css @@ -0,0 +1,72 @@ +.cru-button {
+ color: white;
+ cursor: pointer;
+ padding: 0.2em 0.5em;
+ border-radius: 0.2em;
+ border: none;
+ transition: all 0.6s;
+}
+
+.cru-button.primary {
+ background-color: var(--tl-primary-color);
+}
+
+.cru-button.primary:hover {
+ background-color: var(--tl-primary-f1-color);
+}
+
+.cru-button.primary:active {
+ background-color: var(--tl-primary-f2-color);
+}
+
+.cru-button.primary.disabled {
+ background-color: var(--tl-primary-f3-color);
+}
+
+.cru-button.secondary {
+ background-color: var(--tl-secondary-color);
+}
+
+.cru-button.secondary:hover {
+ background-color: var(--tl-secondary-f1-color);
+}
+
+.cru-button.secondary:active {
+ background-color: var(--tl-secondary-f2-color);
+}
+
+.cru-button.secondary.disabled {
+ background-color: var(--tl-secondary-f3-color);
+}
+
+.cru-button.success {
+ background-color: var(--tl-success-color);
+}
+
+.cru-button.success:hover {
+ background-color: var(--tl-success-f1-color);
+}
+
+.cru-button.success:active {
+ background-color: var(--tl-success-f2-color);
+}
+
+.cru-button.success.disabled {
+ background-color: var(--tl-success-f3-color);
+}
+
+.cru-button.danger {
+ background-color: var(--tl-danger-color);
+}
+
+.cru-button.danger:hover {
+ background-color: var(--tl-danger-f1-color);
+}
+
+.cru-button.danger:active {
+ background-color: var(--tl-danger-f2-color);
+}
+
+.cru-button.danger.disabled {
+ background-color: var(--tl-danger-f3-color);
+}
diff --git a/FrontEnd/src/views/common/button/Button.tsx b/FrontEnd/src/views/common/button/Button.tsx new file mode 100644 index 00000000..a39ef8a7 --- /dev/null +++ b/FrontEnd/src/views/common/button/Button.tsx @@ -0,0 +1,33 @@ +import React from "react"; +import { useTranslation } from "react-i18next"; + +import { calculateProps, CommonButtonProps } from "./common"; + +import "./Button.css"; + +function _Button( + props: CommonButtonProps & { + outline?: boolean; + customButtonClassName?: string; + }, + ref: React.ForwardedRef<HTMLButtonElement> +): React.ReactElement | null { + const { t } = useTranslation(); + + const { customButtonClassName, outline, ...otherProps } = props; + + const { newProps, children } = calculateProps( + otherProps, + customButtonClassName ?? "cru-button" + (outline ? " outline" : ""), + t + ); + + return ( + <button ref={ref} {...newProps}> + {children} + </button> + ); +} + +const Button = React.forwardRef(_Button); +export default Button; diff --git a/FrontEnd/src/views/common/button/FlatButton.css b/FrontEnd/src/views/common/button/FlatButton.css index 522563b9..c3c0dbb3 100644 --- a/FrontEnd/src/views/common/button/FlatButton.css +++ b/FrontEnd/src/views/common/button/FlatButton.css @@ -20,7 +20,7 @@ }
.cru-flat-button.primary.disabled {
- color: var(--tl-primary-lighter-color);
+ color: var(--tl-primary-l1-color);
}
.cru-flat-button.secondary {
@@ -28,7 +28,7 @@ }
.cru-flat-button.secondary.disabled {
- color: var(--tl-secondary-lighter-color);
+ color: var(--tl-secondary-l1-color);
}
.cru-flat-button.success {
@@ -36,7 +36,7 @@ }
.cru-flat-button.success.disabled {
- color: var(--tl-success-lighter-color);
+ color: var(--tl-success-l1-color);
}
.cru-flat-button.danger {
@@ -44,5 +44,5 @@ }
.cru-flat-button.danger.disabled {
- color: var(--tl-danger-ligher-color);
+ color: var(--tl-danger-l1-color);
}
diff --git a/FrontEnd/src/views/common/button/FlatButton.tsx b/FrontEnd/src/views/common/button/FlatButton.tsx index 6351971a..266ea908 100644 --- a/FrontEnd/src/views/common/button/FlatButton.tsx +++ b/FrontEnd/src/views/common/button/FlatButton.tsx @@ -1,39 +1,16 @@ import React from "react"; -import { useTranslation } from "react-i18next"; -import classNames from "classnames"; -import { convertI18nText, I18nText } from "@/common"; -import { PaletteColorType } from "@/palette"; +import { CommonButtonProps } from "./common"; +import Button from "./Button"; import "./FlatButton.css"; function _FlatButton( - { - text, - color, - onClick, - className, - style, - }: { - text: I18nText; - color?: PaletteColorType; - onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void; - className?: string; - style?: React.CSSProperties; - }, + props: CommonButtonProps, ref: React.ForwardedRef<HTMLButtonElement> ): React.ReactElement | null { - const { t } = useTranslation(); - return ( - <button - ref={ref} - className={classNames("cru-flat-button", color ?? "primary", className)} - onClick={onClick} - style={style} - > - {convertI18nText(text, t)} - </button> + <Button ref={ref} customButtonClassName="cru-flat-button" {...props} /> ); } diff --git a/FrontEnd/src/views/common/button/LoadingButton.tsx b/FrontEnd/src/views/common/button/LoadingButton.tsx new file mode 100644 index 00000000..aee83aa2 --- /dev/null +++ b/FrontEnd/src/views/common/button/LoadingButton.tsx @@ -0,0 +1,21 @@ +import React from "react"; + +import { CommonButtonProps } from "./common"; +import Button from "./Button"; +import Spinner from "../Spinner"; + +const LoadingButton: React.FC<{ loading?: boolean } & CommonButtonProps> = ({ + loading, + disabled, + color, + ...otherProps +}) => { + return ( + <Button color={color} disabled={disabled || loading} {...otherProps}> + {otherProps.children} + {loading ? <Spinner color={color} /> : null} + </Button> + ); +}; + +export default LoadingButton; diff --git a/FrontEnd/src/views/common/button/TextButton.css b/FrontEnd/src/views/common/button/TextButton.css index dc5abaaa..d267fb38 100644 --- a/FrontEnd/src/views/common/button/TextButton.css +++ b/FrontEnd/src/views/common/button/TextButton.css @@ -8,7 +8,7 @@ }
.cru-text-button.primary:hover {
- color: var(--tl-primary-lighter-color);
+ color: var(--tl-primary-l1-color);
}
.cru-text-button.secondary {
@@ -16,7 +16,7 @@ }
.cru-text-button.secondary:hover {
- color: var(--tl-secondary-lighter-color);
+ color: var(--tl-secondary-l1-color);
}
.cru-text-button.success {
@@ -24,7 +24,7 @@ }
.cru-text-button.success:hover {
- color: var(--tl-success-lighter-color);
+ color: var(--tl-success-l1-color);
}
.cru-text-button.danger {
@@ -32,5 +32,5 @@ }
.cru-text-button.danger:hover {
- color: var(--tl-danger-lighter-color);
+ color: var(--tl-danger-l1-color);
}
diff --git a/FrontEnd/src/views/common/button/TextButton.tsx b/FrontEnd/src/views/common/button/TextButton.tsx index 1a2bac94..1d8e7a4b 100644 --- a/FrontEnd/src/views/common/button/TextButton.tsx +++ b/FrontEnd/src/views/common/button/TextButton.tsx @@ -1,39 +1,16 @@ import React from "react"; -import { useTranslation } from "react-i18next"; -import classNames from "classnames"; -import { convertI18nText, I18nText } from "@/common"; -import { PaletteColorType } from "@/palette"; +import { CommonButtonProps } from "./common"; +import Button from "./Button"; import "./TextButton.css"; function _TextButton( - { - text, - color, - onClick, - className, - style, - }: { - text: I18nText; - color?: PaletteColorType; - onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void; - className?: string; - style?: React.CSSProperties; - }, + props: CommonButtonProps, ref: React.ForwardedRef<HTMLButtonElement> ): React.ReactElement | null { - const { t } = useTranslation(); - return ( - <button - ref={ref} - className={classNames("cru-text-button", color ?? "primary", className)} - onClick={onClick} - style={style} - > - {convertI18nText(text, t)} - </button> + <Button ref={ref} customButtonClassName="cru-flat-button" {...props} /> ); } 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, + }; +} |