UNPKG

@alice-ui/react

Version:
60 lines (57 loc) 1.89 kB
import { useInput } from "./chunk-OOXGV2ZQ.mjs"; // src/input/input.tsx import { XCircleFilledIcon } from "@alice-ui/icons"; import { clsx } from "@alice-ui/shared-utils"; import { input } from "@alice-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, color, size, radius, variant, fullWidth, startContent, endContent, ...otherProps } = props; const { getInputWrapperProps, getInputProps, getClearButtonProps } = useInput({ ...otherProps, ref }); const isClearable = !!props.onClear; const slots = useMemo( () => input({ color, size, radius, variant, fullWidth, isClearable }), [color, fullWidth, radius, size, 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 }) }), end ] }); } var _Input = forwardRef(Input); export { _Input };