@yamada-ui/input
Version:
Yamada UI input component
255 lines (249 loc) • 8.12 kB
JavaScript
"use client"
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/input-group.tsx
var input_group_exports = {};
__export(input_group_exports, {
InputGroup: () => InputGroup
});
module.exports = __toCommonJS(input_group_exports);
var import_core3 = require("@yamada-ui/core");
var import_utils4 = require("@yamada-ui/utils");
var import_react = require("react");
// src/input-addon.tsx
var import_core = require("@yamada-ui/core");
var import_utils2 = require("@yamada-ui/utils");
// src/input-context.tsx
var import_utils = require("@yamada-ui/utils");
var [InputGroupProvider, useInputGroup] = (0, import_utils.createContext)({
name: "InputGroupContext",
errorMessage: `useInputGroup returned is 'undefined'. Seems you forgot to wrap the components in "<InputGroup />" `
});
// src/input-addon.tsx
var import_jsx_runtime = require("react/jsx-runtime");
var InputAddon = (0, import_core.forwardRef)(
({ className, placement = "left", ...rest }, ref) => {
const { styles } = useInputGroup();
const placementStyles = {
left: {
me: "-1px",
roundedRight: "0px !important"
},
right: {
ms: "-1px",
roundedLeft: "0px !important"
}
};
const css = {
alignItems: "center",
display: "flex",
flex: "0 0 auto",
w: "auto",
whiteSpace: "nowrap",
...styles.addon,
...placementStyles[placement]
};
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_core.ui.div,
{
ref,
className: (0, import_utils2.cx)("ui-input__addon", className),
__css: css,
...rest
}
);
}
);
InputAddon.displayName = "InputAddon";
InputAddon.__ui__ = "InputAddon";
var InputLeftAddon = (0, import_core.forwardRef)(
({ className, ...rest }, ref) => {
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
InputAddon,
{
ref,
className: (0, import_utils2.cx)("ui-input__addon--left", className),
placement: "left",
...rest
}
);
}
);
InputLeftAddon.displayName = "InputLeftAddon";
InputLeftAddon.__ui__ = "InputLeftAddon";
var InputRightAddon = (0, import_core.forwardRef)(
({ className, ...rest }, ref) => {
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
InputAddon,
{
ref,
className: (0, import_utils2.cx)("ui-input__addon--right", className),
placement: "right",
...rest
}
);
}
);
InputRightAddon.displayName = "InputRightAddon";
InputRightAddon.__ui__ = "InputRightAddon";
// src/input-element.tsx
var import_core2 = require("@yamada-ui/core");
var import_utils3 = require("@yamada-ui/utils");
var import_jsx_runtime2 = require("react/jsx-runtime");
var InputElement = (0, import_core2.forwardRef)(
({
className,
isClick = false,
isClickable = isClick,
clickable = isClickable,
placement = "left",
...rest
}, ref) => {
const { fieldFontSize, fieldHeight, styles } = useInputGroup();
const css = {
alignItems: "center",
cursor: clickable ? "pointer" : "auto",
display: "flex",
fontSize: fieldFontSize,
h: "100%",
justifyContent: "center",
[placement === "left" ? "insetStart" : "insetEnd"]: "0",
pointerEvents: clickable ? "auto" : "none",
position: "absolute",
top: "0",
w: fieldHeight,
zIndex: "fallback(kurillin, 9)",
...styles.element
};
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
import_core2.ui.div,
{
ref,
className: (0, import_utils3.cx)("ui-input__element", className),
__css: css,
...rest
}
);
}
);
InputElement.displayName = "InputElement";
InputElement.__ui__ = "InputElement";
var InputLeftElement = (0, import_core2.forwardRef)(
({ className, ...rest }, ref) => {
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
InputElement,
{
ref,
className: (0, import_utils3.cx)("ui-input__element--left", className),
placement: "left",
...rest
}
);
}
);
InputLeftElement.displayName = "InputLeftElement";
InputLeftElement.__ui__ = "InputLeftElement";
var InputRightElement = (0, import_core2.forwardRef)(
({ className, ...rest }, ref) => {
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
InputElement,
{
ref,
className: (0, import_utils3.cx)("ui-input__element--right", className),
placement: "right",
...rest
}
);
}
);
InputRightElement.displayName = "InputRightElement";
InputRightElement.__ui__ = "InputRightElement";
// src/input-group.tsx
var import_jsx_runtime3 = require("react/jsx-runtime");
var InputGroup = (0, import_core3.forwardRef)((props, ref) => {
var _a, _b;
const [styles] = (0, import_core3.useComponentMultiStyle)("Input", props);
const { className, children, ...rest } = (0, import_core3.omitThemeProps)(props);
const [vars, variableProps] = (0, import_core3.useCreateVars)({ ...styles.field, ...rest }, [
"minHeight",
"minH",
"height",
"h",
"fontSize"
]);
const minHeight = (_a = variableProps.minHeight) != null ? _a : variableProps.minH;
const height = (_b = variableProps.height) != null ? _b : variableProps.h;
const fieldHeight = minHeight != null ? minHeight : height;
const fieldFontSize = variableProps.fontSize;
const css = {
display: "flex",
position: "relative",
vars,
width: "100%",
...styles.container
};
const groupProps = {};
const validChildren = (0, import_utils4.getValidChildren)(children);
validChildren.forEach((child) => {
if (fieldHeight && child.type === InputLeftElement)
groupProps.paddingStart = `${fieldHeight} !important`;
if (fieldHeight && child.type === InputRightElement)
groupProps.paddingEnd = `${fieldHeight} !important`;
if (child.type === InputLeftAddon) groupProps.roundedLeft = "0px !important";
if (child.type === InputRightAddon)
groupProps.roundedRight = "0px !important";
});
const cloneChildren = validChildren.map((child) => {
var _a2, _b2, _c, _d;
const isAddonElement = [
InputLeftAddon,
InputRightAddon,
InputLeftElement,
InputRightElement
].some((type) => child.type === type);
if (isAddonElement) {
return child;
} else {
const childProps = (0, import_utils4.filterUndefined)({
size: (_b2 = (_a2 = child.props) == null ? void 0 : _a2.size) != null ? _b2 : props.size,
variant: (_d = (_c = child.props) == null ? void 0 : _c.variant) != null ? _d : props.variant,
...child.props
});
return (0, import_react.cloneElement)(child, Object.assign(childProps, groupProps));
}
});
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(InputGroupProvider, { value: { fieldFontSize, fieldHeight, styles }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
import_core3.ui.div,
{
ref,
className: (0, import_utils4.cx)("ui-input-group", className),
role: "group",
__css: css,
...rest,
children: cloneChildren
}
) });
});
InputGroup.displayName = "InputGroup";
InputGroup.__ui__ = "InputGroup";
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
InputGroup
});
//# sourceMappingURL=input-group.js.map