Page MenuHomeSealhub

input-wrapper.ts
No OneTemporary

Authored By
Unknown
Size
957 B
Referenced Files
None
Subscribers
None

input-wrapper.ts

import { FlatTemplatable, tempstream } from "tempstream";
import { FormField } from "../index.js";
import { toKebabCase } from "js-convert-case";
export function getRequiredClass(isRequired: boolean): string {
return isRequired ? "required" : "";
}
function getModifierClasses(modifiers: string[]) {
return modifiers.map((m) => "form-input__wrapper--" + m).join(" ");
}
export async function inputWrapper(
type: string,
modifiers: string[],
input: FlatTemplatable
): Promise<string> {
return tempstream /* HTML */ `<label
class="form-input form-input--type-${type} form-input__wrapper ${getModifierClasses(
modifiers
)}"
>
${input}
</label>`;
}
export async function autoWrapInput(field: FormField, input: FlatTemplatable) {
return inputWrapper(
toKebabCase(field.constructor.name),
[
`type--` + toKebabCase(field.constructor.name),
`name--` + toKebabCase(field.name),
getRequiredClass(field.required),
],
input
);
}

File Metadata

Mime Type
application/javascript
Expires
Fri, Nov 27, 16:27 (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1199021
Default Alt Text
input-wrapper.ts (957 B)

Event Timeline