@trail-ui/react
Version:
56 lines (53 loc) • 1.85 kB
JavaScript
import {
useInput
} from "./chunk-LSMK7S5U.mjs";
// src/input/input.tsx
import { XCircleFilledIcon } from "@trail-ui/icons";
import { clsx } from "@trail-ui/shared-utils";
import { input } from "@trail-ui/theme";
import { forwardRef, useMemo } from "react";
import { InputContext, useContextProps } from "react-aria-components";
import { jsx, jsxs } from "react/jsx-runtime";
function Input(props, ref) {
[props, ref] = useContextProps(props, ref, InputContext);
const { classNames, className, variant, fullWidth, startContent, endContent, ...otherProps } = props;
const { getInputWrapperProps, getInputProps, getClearButtonProps, domRef } = useInput({
...otherProps,
ref
});
const isClearable = !!props.onClear;
const slots = useMemo(
() => input({ variant, fullWidth, isClearable }),
[fullWidth, variant, isClearable]
);
const end = useMemo(() => {
if (isClearable) {
return /* @__PURE__ */ jsx(
"span",
{
...getClearButtonProps(),
className: slots.clearButton({ class: classNames == null ? void 0 : classNames.clearButton }),
children: endContent || /* @__PURE__ */ jsx(XCircleFilledIcon, {})
}
);
}
return endContent;
}, [classNames == null ? void 0 : classNames.clearButton, endContent, getClearButtonProps, isClearable, slots]);
const baseStyles = clsx(classNames == null ? void 0 : classNames.base, className);
return /* @__PURE__ */ jsxs("div", { className: slots.base({ class: baseStyles }), ...getInputWrapperProps(), children: [
startContent,
/* @__PURE__ */ jsx(
"input",
{
...getInputProps(),
className: slots.input({ class: classNames == null ? void 0 : classNames.input }),
ref: domRef
}
),
end
] });
}
var _Input = forwardRef(Input);
export {
_Input
};