UNPKG

@react-md/form

Version:

This package is for creating all the different form input types.

63 lines 4.47 kB
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; }; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { forwardRef } from "react"; import cn from "classnames"; import { bem } from "@react-md/utils"; import { useFormTheme } from "../FormThemeProvider"; import { FloatingLabel } from "../label/FloatingLabel"; import { TextFieldContainer } from "./TextFieldContainer"; import { useFieldStates } from "../useFieldStates"; var block = 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. */ export var TextField = 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 = 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 = useFormTheme({ theme: propTheme, underlineDirection: propUnderlineDirection, }), theme = _l.theme, underlineDirection = _l.underlineDirection; return (_jsxs(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: [_jsx(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 })), _jsx("input", __assign({}, props, { ref: ref, type: type, disabled: disabled, onFocus: onFocus, onBlur: onBlur, onChange: onChange, style: inputStyle, className: cn(block({ floating: label && theme !== "none", }), inputClassName) }))] }))); }); //# sourceMappingURL=TextField.js.map