UNPKG

quantumai-design-system

Version:

퀀텀에이아이의 디자인 시스템

44 lines (43 loc) 2.61 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, Fragment as _Fragment, jsxs as _jsxs } from "@emotion/react/jsx-runtime"; import { forwardRef, useContext, useEffect, useState } from 'react'; import Icons from '../../../Base/Icon/Icons'; import { MaterialContext } from '../context'; var InputBasic = forwardRef(function (_a, ref) { var type = _a.type, id = _a.id, onValue = _a.onValue, onIsValue = _a.onIsValue, handleChangeValue = _a.handleChangeValue, onChange = _a.onChange, _b = _a.value, value = _b === void 0 ? '' : _b, props = __rest(_a, ["type", "id", "onValue", "onIsValue", "handleChangeValue", "onChange", "value"]); var disabled = useContext(MaterialContext).disabled; var _c = useState(String(value)), inputValue = _c[0], setInputValue = _c[1]; useEffect(function () { handleChangeValue === null || handleChangeValue === void 0 ? void 0 : handleChangeValue(function (newValue) { return setInputValue(String(newValue)); }); onIsValue === null || onIsValue === void 0 ? void 0 : onIsValue(!!inputValue); onValue === null || onValue === void 0 ? void 0 : onValue(inputValue); }, [inputValue, handleChangeValue]); var inputChange = function (e) { setInputValue(e.target.value); onChange === null || onChange === void 0 ? void 0 : onChange(e); }; var handleClearInput = function () { return setInputValue(''); }; return (_jsxs(_Fragment, { children: [_jsx("input", __assign({ type: type, ref: ref, id: id, disabled: disabled, value: inputValue, onChange: inputChange }, props)), inputValue && !disabled && type !== 'number' && (_jsx("button", { type: "button", onClick: handleClearInput, children: _jsx(Icons, { name: "close", size: 20 }) }))] })); }); export default InputBasic;