UI/TextInput: use FieldLayout
This commit is contained in:
@@ -1,62 +1,51 @@
|
|||||||
import { createEffect, Show, type JSX } from "solid-js";
|
import { splitProps, type JSX } from "solid-js";
|
||||||
import cx from "classnames";
|
import { InputBase, InputError, InputLabel } from "@/src/components/inputBase";
|
||||||
import { Label } from "../base/label";
|
|
||||||
import { InputBase, InputLabel } from "@/src/components/inputBase";
|
|
||||||
import { Typography } from "@/src/components/Typography";
|
import { Typography } from "@/src/components/Typography";
|
||||||
|
import { FieldLayout } from "./layout";
|
||||||
|
|
||||||
interface TextInputProps {
|
interface TextInputProps {
|
||||||
value: string;
|
// Common
|
||||||
inputProps?: JSX.InputHTMLAttributes<HTMLInputElement>;
|
|
||||||
label: JSX.Element;
|
|
||||||
altLabel?: JSX.Element;
|
|
||||||
helperText?: JSX.Element;
|
|
||||||
error?: string;
|
error?: string;
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
type?: string;
|
|
||||||
inlineLabel?: JSX.Element;
|
|
||||||
class?: string;
|
|
||||||
adornment?: {
|
|
||||||
position: "start" | "end";
|
|
||||||
content: JSX.Element;
|
|
||||||
};
|
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
// Passed to input
|
||||||
|
value: string;
|
||||||
|
inputProps?: JSX.InputHTMLAttributes<HTMLInputElement>;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
|
// Passed to label
|
||||||
|
label: JSX.Element;
|
||||||
|
help?: string;
|
||||||
|
// Passed to layouad
|
||||||
|
class?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TextInput(props: TextInputProps) {
|
export function TextInput(props: TextInputProps) {
|
||||||
// createEffect(() => {
|
const [layoutProps, rest] = splitProps(props, ["class"]);
|
||||||
// console.log("TextInput", props.error, props.value);
|
|
||||||
// });
|
|
||||||
return (
|
return (
|
||||||
<div
|
<FieldLayout
|
||||||
class="grid grid-cols-12"
|
label={
|
||||||
classList={{
|
|
||||||
"mb-[14.5px]": !props.error,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<InputLabel
|
<InputLabel
|
||||||
class="col-span-2"
|
class="col-span-2"
|
||||||
required={props.required}
|
required={props.required}
|
||||||
error={!!props.error}
|
error={!!props.error}
|
||||||
|
help={props.help}
|
||||||
>
|
>
|
||||||
{props.label}
|
{props.label}
|
||||||
</InputLabel>
|
</InputLabel>
|
||||||
|
}
|
||||||
|
field={
|
||||||
<InputBase
|
<InputBase
|
||||||
error={!!props.error}
|
error={!!props.error}
|
||||||
|
required={props.required}
|
||||||
|
disabled={props.disabled}
|
||||||
|
placeholder={props.placeholder}
|
||||||
class="col-span-10"
|
class="col-span-10"
|
||||||
{...props.inputProps}
|
{...props.inputProps}
|
||||||
value={props.value}
|
value={props.value}
|
||||||
/>
|
/>
|
||||||
{props.error && (
|
}
|
||||||
<Typography
|
error={props.error && <InputError error={props.error} />}
|
||||||
hierarchy="body"
|
{...layoutProps}
|
||||||
size="xxs"
|
/>
|
||||||
weight="medium"
|
|
||||||
class="col-span-full px-1 !fg-semantic-4"
|
|
||||||
>
|
|
||||||
{props.error}
|
|
||||||
</Typography>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user