UNPKG

hs-library

Version:

Optimistic UI library for React and Next.js. Modern, reusable components: Inputs, Buttons, Cards, Dropdowns, Modals, Toasts — and more magical UI tools for frontend developers. author: Hitesh Saini

75 lines 4.05 kB
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } import React, { useState } from "react"; import "./index.css"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; var InputBox = /*#__PURE__*/React.memo(function (_ref) { var id = _ref.id, label = _ref.label, _ref$type = _ref.type, type = _ref$type === void 0 ? "text" : _ref$type, _ref$placeholder = _ref.placeholder, placeholder = _ref$placeholder === void 0 ? "" : _ref$placeholder, _ref$value = _ref.value, value = _ref$value === void 0 ? "" : _ref$value, _ref$required = _ref.required, required = _ref$required === void 0 ? false : _ref$required, _ref$disabled = _ref.disabled, disabled = _ref$disabled === void 0 ? false : _ref$disabled, _ref$onChange = _ref.onChange, _onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange, _ref$onBlur = _ref.onBlur, _onBlur = _ref$onBlur === void 0 ? function () {} : _ref$onBlur, _ref$onFocus = _ref.onFocus, _onFocus = _ref$onFocus === void 0 ? function () {} : _ref$onFocus, _ref$message = _ref.message, message = _ref$message === void 0 ? "" : _ref$message, _ref$className = _ref.className, className = _ref$className === void 0 ? "" : _ref$className, _ref$style = _ref.style, style = _ref$style === void 0 ? {} : _ref$style; var _useState = useState(false), _useState2 = _slicedToArray(_useState, 2), focused = _useState2[0], setFocused = _useState2[1]; var inputClass = ["hs_input", disabled ? "hs_disabled" : "hs_enabled", focused && "hs_input--focused"].filter(Boolean).join(" "); return /*#__PURE__*/_jsxs("div", { className: "hs_container ".concat(className), style: style, children: [label && /*#__PURE__*/_jsxs("label", { htmlFor: id, className: "hs_label", children: [label, " ", required && /*#__PURE__*/_jsx("span", { className: "hs_required", children: "*" })] }), /*#__PURE__*/_jsx("input", { id: id, type: type, placeholder: placeholder || "Enter ".concat(label), value: value, required: required, disabled: disabled, onChange: function onChange(e) { return _onChange(e.target.value); }, onBlur: function onBlur(e) { setFocused(false); _onBlur(e); }, onFocus: function onFocus(e) { setFocused(true); _onFocus(e); }, className: inputClass }), message && /*#__PURE__*/_jsx("div", { className: "hs_input_message_required", children: message })] }); }); export default InputBox;