@gumigumih/react-calculator-input-form 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -6423,7 +6423,13 @@ const Calculator = ({ isOpen, onClose, onCalculate, initialValue = '', title, de
6423
6423
  }) => {
6424
6424
  const [input, setInput] = React.useState(initialValue || '');
6425
6425
  const [error, setError] = React.useState('');
6426
+ const [mounted, setMounted] = React.useState(false);
6426
6427
  const inputRef = React.useRef(null);
6428
+ // DOM要素の存在確認
6429
+ React.useEffect(() => {
6430
+ setMounted(true);
6431
+ return () => setMounted(false);
6432
+ }, []);
6427
6433
  React.useEffect(() => {
6428
6434
  if (isOpen) {
6429
6435
  setInput(initialValue || '');
@@ -6545,18 +6551,32 @@ const Calculator = ({ isOpen, onClose, onCalculate, initialValue = '', title, de
6545
6551
  setInput(normalizeNumberString(taxExcluded, decimalPlaces));
6546
6552
  setError('');
6547
6553
  };
6548
- if (!isOpen)
6554
+ if (!isOpen || !mounted)
6549
6555
  return null;
6550
6556
  const modal = (jsxRuntime.jsx("div", { className: "calculator-overlay", children: jsxRuntime.jsxs("div", { className: "calculator-modal", children: [title || description ? (jsxRuntime.jsxs("div", { className: "calculator-header", children: [jsxRuntime.jsxs("div", { children: [title && jsxRuntime.jsx("h2", { className: "calculator-title", children: title }), description && jsxRuntime.jsx("p", { className: "calculator-subtitle", children: description })] }), jsxRuntime.jsx("button", { onClick: onClose, className: "calculator-close-button", "aria-label": "\u9589\u3058\u308B", children: jsxRuntime.jsx(Icon, { icon: faTimes, className: "w-5 h-5" }) })] })) : (jsxRuntime.jsxs("div", { className: "calculator-header", children: [jsxRuntime.jsx("div", {}), jsxRuntime.jsx("button", { onClick: onClose, className: "calculator-close-button", "aria-label": "\u9589\u3058\u308B", children: jsxRuntime.jsx(Icon, { icon: faTimes, className: "w-5 h-5" }) })] })), jsxRuntime.jsx("div", { className: "calculator-display", children: jsxRuntime.jsx(CalculatorDisplay, { value: input, error: error, inputRef: inputRef, editable: true, onChange: (v) => setInput(v), numberFormatOptions: numberFormatOptions }) }), jsxRuntime.jsx(CalculatorKeypad, { onButtonClick: handleButtonClick, onEqual: handleEqual, onDecide: handleDecide, onTaxInclude: handleTaxInclude, onTaxExclude: handleTaxExclude, enableTaxCalculation: enableTaxCalculation, decimalPlaces: decimalPlaces })] }) }));
6551
- return reactDom.createPortal(modal, document.body);
6557
+ // DOM要素の存在確認を行ってからポータルを作成
6558
+ if (typeof document !== 'undefined' && document.body) {
6559
+ return reactDom.createPortal(modal, document.body);
6560
+ }
6561
+ return null;
6552
6562
  };
6553
6563
 
6554
6564
  const CalculatorInput = ({ value, onChange, placeholder = 'クリックして金額を入力', className, title, description, enableTaxCalculation = false, decimalPlaces = 6, numberFormatOptions = {}, displayPlaceholder, }) => {
6555
6565
  const [isOpen, setIsOpen] = React.useState(false);
6566
+ const [mounted, setMounted] = React.useState(false);
6567
+ // DOM要素の存在確認
6568
+ React.useEffect(() => {
6569
+ setMounted(true);
6570
+ return () => setMounted(false);
6571
+ }, []);
6556
6572
  const handleCalculate = (val) => {
6557
6573
  onChange(val);
6558
6574
  setIsOpen(false);
6559
6575
  };
6576
+ // マウント前は何も表示しない
6577
+ if (!mounted) {
6578
+ return null;
6579
+ }
6560
6580
  return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(NumericFormat, { value: value, onValueChange: (vals) => onChange(vals.value), placeholder: placeholder, className: className, readOnly: true, onClick: () => setIsOpen(true), ...numberFormatOptions }), jsxRuntime.jsx(Calculator, { isOpen: isOpen, onClose: () => setIsOpen(false), onCalculate: handleCalculate, initialValue: value, title: title, description: description, enableTaxCalculation: enableTaxCalculation, decimalPlaces: decimalPlaces, numberFormatOptions: numberFormatOptions, placeholder: displayPlaceholder })] }));
6561
6581
  };
6562
6582