UNPKG

quantumai-design-system

Version:

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

57 lines (56 loc) 3.52 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 "@emotion/react/jsx-runtime"; import { forwardRef, useState } from 'react'; import Icons from '../../Base/Icon/Icons'; import { InputNumberStyle } from './style'; import { restProps } from '../../../utils/styleSet'; var InputNumber = forwardRef(function (_a, ref) { var value = _a.value, _b = _a.size, size = _b === void 0 ? 'm' : _b, _c = _a.step, step = _c === void 0 ? 1 : _c, _d = _a.min, min = _d === void 0 ? 0 : _d, _e = _a.max, max = _e === void 0 ? Infinity : _e, disabled = _a.disabled, handleValue = _a.handleValue, onClickMinus = _a.onClickMinus, onClickPlus = _a.onClickPlus, onChange = _a.onChange, className = _a.className, _f = _a.width, width = _f === void 0 ? 200 : _f, props = __rest(_a, ["value", "size", "step", "min", "max", "disabled", "handleValue", "onClickMinus", "onClickPlus", "onChange", "className", "width"]); var _g = restProps(__assign({ width: width }, props)), styleProps = _g[0], rest = _g[1]; var _h = useState(undefined), count = _h[0], setCount = _h[1]; var countValue = (value !== null && value !== void 0 ? value : count) || 0; function updateValue(newValue) { !value && setCount(newValue); handleValue === null || handleValue === void 0 ? void 0 : handleValue(newValue); } function handleMinus(v) { var newValue = minMaxValue(v - step); onClickMinus === null || onClickMinus === void 0 ? void 0 : onClickMinus(newValue); updateValue(newValue); } function handlePlus(v) { var newValue = minMaxValue(v + step); onClickPlus === null || onClickPlus === void 0 ? void 0 : onClickPlus(newValue); updateValue(newValue); } function onChangeInput(e) { onChange === null || onChange === void 0 ? void 0 : onChange(e); updateValue(minMaxValue(+e.target.value)); } function minMaxValue(v) { return Math.max(Math.min(v, max), min); } return (_jsxs("div", { className: className, css: InputNumberStyle(__assign({ disabled: disabled, size: size }, styleProps)), children: [_jsx("button", { onClick: function () { return handleMinus(countValue); }, disabled: disabled, children: _jsx(Icons, { name: "minus" }) }), _jsx("input", __assign({ type: "number", value: (value !== null && value !== void 0 ? value : count) !== undefined ? minMaxValue(countValue) : '', disabled: disabled, onChange: onChangeInput, step: step, min: min, max: max, ref: ref }, rest)), _jsx("button", { onClick: function () { return handlePlus(countValue); }, disabled: disabled, children: _jsx(Icons, { name: "plus" }) })] })); }); export default InputNumber;