feat(react/settings): port font size

This commit is contained in:
Elian Doran
2025-08-14 21:31:09 +03:00
parent 2793df06c4
commit 0db556fac2
6 changed files with 55 additions and 167 deletions

View File

@@ -14,11 +14,11 @@ interface ButtonProps {
onClick?: () => void;
primary?: boolean;
disabled?: boolean;
small?: boolean;
size: "normal" | "small" | "micro";
style?: CSSProperties;
}
const Button = memo(({ buttonRef: _buttonRef, className, text, onClick, keyboardShortcut, icon, primary, disabled, small, style }: ButtonProps) => {
const Button = memo(({ buttonRef: _buttonRef, className, text, onClick, keyboardShortcut, icon, primary, disabled, size, style }: ButtonProps) => {
// Memoize classes array to prevent recreation
const classes = useMemo(() => {
const classList: string[] = ["btn"];
@@ -30,11 +30,13 @@ const Button = memo(({ buttonRef: _buttonRef, className, text, onClick, keyboard
if (className) {
classList.push(className);
}
if (small) {
if (size === "small") {
classList.push("btn-sm");
} else if (size === "micro") {
classList.push("btn-micro");
}
return classList.join(" ");
}, [primary, className, small]);
}, [primary, className, size]);
const buttonRef = _buttonRef ?? useRef<HTMLButtonElement>(null);

View File

@@ -0,0 +1,5 @@
import { ComponentChildren } from "preact";
export default function FormText({ children }: { children: ComponentChildren }) {
return <p className="form-text">{children}</p>
}

View File

@@ -1,27 +1,31 @@
import type { InputHTMLAttributes, RefObject } from "preact/compat";
import FormText from "./FormText";
interface FormTextBoxProps extends Pick<InputHTMLAttributes<HTMLInputElement>, "placeholder" | "autoComplete" | "className" | "type" | "name" | "pattern" | "title" | "style"> {
interface FormTextBoxProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "onChange" | "value"> {
id?: string;
currentValue?: string;
onChange?(newValue: string): void;
inputRef?: RefObject<HTMLInputElement>;
}
export default function FormTextBox({ id, type, name, className, currentValue, onChange, autoComplete, inputRef, placeholder, title, pattern, style }: FormTextBoxProps) {
export default function FormTextBox({ inputRef, className, type, currentValue, onChange, ...rest}: FormTextBoxProps) {
return (
<input
ref={inputRef}
type={type ?? "text"}
className={`form-control ${className ?? ""}`}
id={id}
name={name}
type={type ?? "text"}
value={currentValue}
autoComplete={autoComplete}
placeholder={placeholder}
title={title}
pattern={pattern}
onInput={e => onChange?.(e.currentTarget.value)}
style={style}
{...rest}
/>
);
}
export function FormTextBoxWithUnit(props: FormTextBoxProps & { unit: string }) {
return (
<label class="input-group tn-number-unit-pair">
<FormTextBox {...props} />
<span class="input-group-text">{props.unit}</span>
</label>
)
}