Skip to content

Commit

Permalink
feat(rdom-forms): make attribs type-specifc
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Dec 11, 2023
1 parent f42848e commit 5c6de7f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/rdom-forms/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ import type { Fn, Predicate } from "@thi.ng/api";
import type {
Attribs,
FormAttribs,
InputAttribs,
InputCheckboxAttribs,
InputFileAttribs,
InputNumericAttribs,
InputRadioAttribs,
InputTextAttribs,
SelectAttribs,
TextAreaAttribs,
} from "@thi.ng/hiccup-html";
import type { ComponentLike } from "@thi.ng/rdom";
import type { ISubscriber, ISubscription } from "@thi.ng/rstream";
Expand Down Expand Up @@ -54,6 +60,7 @@ export interface Value extends FormItem, Partial<CommonAttribs> {
desc?: any;
required?: boolean;
readonly?: boolean;
attribs?: Partial<InputAttribs>;
}

export interface WithPresets<T> {
Expand All @@ -71,6 +78,7 @@ export interface Num extends Value, WithPresets<number> {
size?: number;
step?: number;
value?: ISubscription<number, number>;
attribs?: Partial<InputNumericAttribs>;
}

export interface Range extends Omit<Num, "type" | "placeholder" | "size"> {
Expand All @@ -86,6 +94,7 @@ export interface Str extends Value, WithPresets<string> {
placeholder?: string;
size?: number;
value?: ISubscription<string, string>;
attribs?: Partial<InputTextAttribs>;
}

export interface Email extends Omit<Str, "type"> {
Expand Down Expand Up @@ -113,6 +122,7 @@ export interface Text extends Value {
rows?: number;
placeholder?: string;
value?: ISubscription<string, string>;
attribs?: Partial<TextAreaAttribs>;
}

export interface Color extends Value, WithPresets<string> {
Expand Down Expand Up @@ -147,6 +157,7 @@ export interface Month extends Omit<DateTime, "type" | "list"> {
export interface Select<T> extends Value {
items: (T | SelectItem<T> | SelectItemGroup<T>)[];
value?: ISubscription<T, T>;
attribs?: Partial<Omit<SelectAttribs, "multiple">>;
}

export interface SelectItemGroup<T> {
Expand All @@ -171,6 +182,7 @@ export interface MultiSelect<T> extends Value {
items: (T | SelectItem<T> | SelectItemGroup<T>)[];
value?: ISubscription<T[], T[]>;
size?: number;
attribs?: Partial<Omit<SelectAttribs, "multiple">>;
}

export interface MultiSelectStr<T extends string = string>
Expand All @@ -192,11 +204,13 @@ export interface Trigger extends Value {
type: "trigger";
title: string;
value?: ISubscriber<boolean>;
attribs?: Partial<InputCheckboxAttribs>;
}

export interface Radio<T> extends Value {
items: (T | SelectItem<T>)[];
value?: ISubscription<T, T>;
attribs?: Partial<InputRadioAttribs>;
}

export interface RadioNum extends Radio<number> {
Expand All @@ -212,12 +226,14 @@ export interface FileVal extends Value {
accept?: string[];
capture?: InputFileAttribs["capture"];
value?: ISubscriber<File>;
attribs?: Partial<InputFileAttribs>;
}

export interface MultiFileVal extends Value {
type: "multiFile";
accept?: string[];
value?: ISubscriber<FileList>;
attribs?: Partial<InputFileAttribs>;
}

type KnownTypes =
Expand Down

0 comments on commit 5c6de7f

Please sign in to comment.