aboutsummaryrefslogtreecommitdiff
path: root/FrontEnd/src/views/common/button/common.ts
blob: a9db959e580c27e783771ff6fe9e08f262903705 (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
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,
  };
}