/* * Copyright (C) 2026 Fluxer Contributors * * This file is part of Fluxer. * * Fluxer is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Fluxer is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Fluxer. If not, see . */ /** @jsxRuntime automatic */ /** @jsxImportSource hono/jsx */ import { FORM_CONTROL_INPUT_CLASS, FORM_CONTROL_SELECT_CLASS, FORM_CONTROL_TEXTAREA_CLASS, FORM_FIELD_CLASS, FORM_HELPER_CLASS, FORM_LABEL_CLASS, FORM_SELECT_ICON_CLASS, } from '@fluxer/ui/src/styles/FormControls'; import type {BaseFormProps, SelectOption} from '@fluxer/ui/src/types/Common'; import {cn} from '@fluxer/ui/src/utils/ClassNames'; export type InputType = 'text' | 'email' | 'password' | 'tel' | 'number' | 'date' | 'url'; function toInputId(name: string): string { return name.replace(/[^a-zA-Z0-9_-]/g, '_'); } function toHelperId(id: string, helper: string | undefined): string | undefined { if (!helper) { return undefined; } return `${id}-helper`; } export interface InputProps extends BaseFormProps { type?: InputType; value?: string | undefined; autocomplete?: string; step?: string; min?: string | number; max?: string | number; readonly?: boolean; } export function Input({ label, helper, name, id, type = 'text', value, required, placeholder, disabled, autocomplete, step, min, max, readonly, }: InputProps) { const inputId = id ?? toInputId(name); const helperId = toHelperId(inputId, helper); return (
{label && ( )} {helper && (

{helper}

)}
); } export interface TextareaProps extends BaseFormProps { value?: string; rows?: number; } export function Textarea({label, helper, name, id, value, required, placeholder, disabled, rows = 4}: TextareaProps) { const textareaId = id ?? toInputId(name); const helperId = toHelperId(textareaId, helper); return (
{label && ( )} {helper && (

{helper}

)}
); } export interface SelectProps extends BaseFormProps { value?: string; options: Array; } export function Select({label, helper, name, id, value, required, disabled, options}: SelectProps) { const selectId = id ?? toInputId(name); const helperId = toHelperId(selectId, helper); return (
{label && ( )}
{helper && (

{helper}

)}
); } export interface CheckboxProps { name: string; value: string; label: string; checked?: boolean; onChange?: string; } export function Checkbox({name, value, label, checked, onChange}: CheckboxProps) { return ( ); }