@react-md/form
Version:
This package is for creating all the different form input types.
69 lines • 4.92 kB
JavaScript
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TextField = void 0;
var jsx_runtime_1 = require("react/jsx-runtime");
var react_1 = require("react");
var classnames_1 = __importDefault(require("classnames"));
var utils_1 = require("@react-md/utils");
var FormThemeProvider_1 = require("../FormThemeProvider");
var FloatingLabel_1 = require("../label/FloatingLabel");
var TextFieldContainer_1 = require("./TextFieldContainer");
var useFieldStates_1 = require("../useFieldStates");
var block = (0, utils_1.bem)("rmd-text-field");
var SPECIAL_TYPES = [
"date",
"time",
"datetime-local",
"month",
"week",
"color",
];
/**
* The text field is a wrapper of the `<input type="text" />` component with
* some nice default themes. It can also be used to render other text input
* types with _some_ support.
*/
exports.TextField = (0, react_1.forwardRef)(function TextField(_a, ref) {
var style = _a.style, className = _a.className, inputStyle = _a.inputStyle, inputClassName = _a.inputClassName, label = _a.label, labelStyle = _a.labelStyle, labelClassName = _a.labelClassName, _b = _a.type, type = _b === void 0 ? "text" : _b, propTheme = _a.theme, _c = _a.dense, dense = _c === void 0 ? false : _c, _d = _a.inline, inline = _d === void 0 ? false : _d, _e = _a.error, error = _e === void 0 ? false : _e, _f = _a.stretch, stretch = _f === void 0 ? false : _f, _g = _a.disabled, disabled = _g === void 0 ? false : _g, propOnBlur = _a.onBlur, propOnFocus = _a.onFocus, propOnChange = _a.onChange, containerRef = _a.containerRef, _h = _a.isLeftAddon, isLeftAddon = _h === void 0 ? true : _h, _j = _a.isRightAddon, isRightAddon = _j === void 0 ? true : _j, leftChildren = _a.leftChildren, rightChildren = _a.rightChildren, propUnderlineDirection = _a.underlineDirection, containerProps = _a.containerProps, props = __rest(_a, ["style", "className", "inputStyle", "inputClassName", "label", "labelStyle", "labelClassName", "type", "theme", "dense", "inline", "error", "stretch", "disabled", "onBlur", "onFocus", "onChange", "containerRef", "isLeftAddon", "isRightAddon", "leftChildren", "rightChildren", "underlineDirection", "containerProps"]);
var id = props.id, value = props.value, defaultValue = props.defaultValue;
var _k = (0, useFieldStates_1.useFieldStates)({
onBlur: propOnBlur,
onFocus: propOnFocus,
onChange: propOnChange,
value: value,
defaultValue: defaultValue,
}), valued = _k.valued, focused = _k.focused, onBlur = _k.onBlur, onFocus = _k.onFocus, onChange = _k.onChange;
var _l = (0, FormThemeProvider_1.useFormTheme)({
theme: propTheme,
underlineDirection: propUnderlineDirection,
}), theme = _l.theme, underlineDirection = _l.underlineDirection;
return ((0, jsx_runtime_1.jsxs)(TextFieldContainer_1.TextFieldContainer, __assign({}, containerProps, { style: style, className: className, ref: containerRef, theme: theme, error: error, active: focused, label: !!label, dense: dense, inline: inline, stretch: stretch, disabled: disabled, isLeftAddon: isLeftAddon, isRightAddon: isRightAddon, leftChildren: leftChildren, rightChildren: rightChildren, underlineDirection: underlineDirection }, { children: [(0, jsx_runtime_1.jsx)(FloatingLabel_1.FloatingLabel, __assign({ style: labelStyle, className: labelClassName, htmlFor: id, error: error, active: focused, floating: focused || valued || SPECIAL_TYPES.includes(type), valued: valued, dense: dense, disabled: disabled }, { children: label })), (0, jsx_runtime_1.jsx)("input", __assign({}, props, { ref: ref, type: type, disabled: disabled, onFocus: onFocus, onBlur: onBlur, onChange: onChange, style: inputStyle, className: (0, classnames_1.default)(block({
floating: label && theme !== "none",
}), inputClassName) }))] })));
});
//# sourceMappingURL=TextField.js.map