UNPKG

@mantine/core

Version:

React components library focused on usability, accessibility and developer experience

151 lines (150 loc) 5.97 kB
"use client"; import { rem } from "../../core/utils/units-converters/rem.mjs"; import { getFontSize, getRadius, getSize } from "../../core/utils/get-size/get-size.mjs"; import { createVarsResolver } from "../../core/styles-api/create-vars-resolver/create-vars-resolver.mjs"; import { useProps } from "../../core/MantineProvider/use-props/use-props.mjs"; import { useStyles } from "../../core/styles-api/use-styles/use-styles.mjs"; import { extractStyleProps } from "../../core/Box/style-props/extract-style-props/extract-style-props.mjs"; import { polymorphicFactory } from "../../core/factory/polymorphic-factory.mjs"; import { Box } from "../../core/Box/Box.mjs"; import { Loader } from "../Loader/Loader.mjs"; import { InputContext } from "./Input.context.mjs"; import { InputClearButton } from "./InputClearButton/InputClearButton.mjs"; import { InputClearSection } from "./InputClearSection/InputClearSection.mjs"; import { InputWrapperContext } from "./InputWrapper.context.mjs"; import Input_module_default from "./Input.module.mjs"; import { InputDescription } from "./InputDescription/InputDescription.mjs"; import { InputError } from "./InputError/InputError.mjs"; import { InputLabel } from "./InputLabel/InputLabel.mjs"; import { InputPlaceholder } from "./InputPlaceholder/InputPlaceholder.mjs"; import { InputWrapper } from "./InputWrapper/InputWrapper.mjs"; import { use } from "react"; import { jsx, jsxs } from "react/jsx-runtime"; //#region packages/@mantine/core/src/components/Input/Input.tsx const defaultProps = { variant: "default", leftSectionPointerEvents: "none", rightSectionPointerEvents: "none", withAria: true, withErrorStyles: true, size: "sm", loading: false, loadingPosition: "right" }; const varsResolver = createVarsResolver((_, props, ctx) => ({ wrapper: { "--input-margin-top": ctx.offsetTop ? "calc(var(--mantine-spacing-xs) / 2)" : void 0, "--input-margin-bottom": ctx.offsetBottom ? "calc(var(--mantine-spacing-xs) / 2)" : void 0, "--input-height": getSize(props.size, "input-height"), "--input-fz": getFontSize(props.size), "--input-radius": props.radius === void 0 ? void 0 : getRadius(props.radius), "--input-left-section-width": props.leftSectionWidth !== void 0 ? rem(props.leftSectionWidth) : void 0, "--input-right-section-width": props.rightSectionWidth !== void 0 ? rem(props.rightSectionWidth) : void 0, "--input-padding-y": props.multiline ? getSize(props.size, "input-padding-y") : void 0, "--input-left-section-pointer-events": props.leftSectionPointerEvents, "--input-right-section-pointer-events": props.rightSectionPointerEvents } })); const Input = polymorphicFactory((_props) => { const props = useProps("Input", defaultProps, _props); const { classNames, className, style, styles, unstyled, required, __staticSelector, __stylesApiProps, size, wrapperProps, error, disabled, leftSection, leftSectionProps, leftSectionWidth, rightSection, rightSectionProps, rightSectionWidth, rightSectionPointerEvents, leftSectionPointerEvents, variant, vars, pointer, multiline, radius, id, withAria, withErrorStyles, mod, inputSize, attributes, __clearSection, __clearable, __clearSectionMode, __defaultRightSection, loading, loadingPosition, ...others } = props; const { styleProps, rest } = extractStyleProps(others); const ctx = use(InputWrapperContext); const stylesCtx = { offsetBottom: ctx?.offsetBottom, offsetTop: ctx?.offsetTop }; const getStyles = useStyles({ name: ["Input", __staticSelector], props: __stylesApiProps || props, classes: Input_module_default, className, style, classNames, styles, unstyled, attributes, stylesCtx, rootSelector: "wrapper", vars, varsResolver }); const ariaAttributes = withAria ? { required, disabled, "aria-invalid": !!error, "aria-describedby": ctx?.describedBy, id: ctx?.inputId || id } : {}; const loadingIndicator = loading ? /* @__PURE__ */ jsx(Loader, { size: loadingPosition === "left" ? "calc(var(--input-left-section-size) / 2)" : "calc(var(--input-right-section-size) / 2)" }) : null; const _leftSection = loading && loadingPosition === "left" ? loadingIndicator : leftSection; const _rightSection = InputClearSection({ __clearable, __clearSection, rightSection: loading && loadingPosition === "right" ? loadingIndicator : rightSection, __defaultRightSection, size, __clearSectionMode }); return /* @__PURE__ */ jsx(InputContext, { value: { size: size || "sm" }, children: /* @__PURE__ */ jsxs(Box, { ...getStyles("wrapper"), ...styleProps, ...wrapperProps, mod: [{ error: !!error && withErrorStyles, pointer, disabled, multiline, "data-with-right-section": !!_rightSection, "data-with-left-section": !!_leftSection }, mod], variant, size, children: [ _leftSection && /* @__PURE__ */ jsx("div", { ...leftSectionProps, "data-position": "left", ...getStyles("section", { className: leftSectionProps?.className, style: leftSectionProps?.style }), children: _leftSection }), /* @__PURE__ */ jsx(Box, { component: "input", ...rest, ...ariaAttributes, required, mod: { disabled, error: !!error && withErrorStyles }, variant, __size: inputSize, ...getStyles("input") }), _rightSection && /* @__PURE__ */ jsx("div", { ...rightSectionProps, "data-position": "right", ...getStyles("section", { className: rightSectionProps?.className, style: rightSectionProps?.style }), children: _rightSection }) ] }) }); }); Input.classes = Input_module_default; Input.varsResolver = varsResolver; Input.Wrapper = InputWrapper; Input.Label = InputLabel; Input.Error = InputError; Input.Description = InputDescription; Input.Placeholder = InputPlaceholder; Input.ClearButton = InputClearButton; Input.displayName = "@mantine/core/Input"; //#endregion export { Input }; //# sourceMappingURL=Input.mjs.map