@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.
@@ -10,4 +10,4 @@ export interface CalculatorInputProps {
10
10
  numberFormatOptions?: any;
11
11
  displayPlaceholder?: string;
12
12
  }
13
- export declare const CalculatorInput: ({ value, onChange, placeholder, className, title, description, enableTaxCalculation, decimalPlaces, numberFormatOptions, displayPlaceholder, }: CalculatorInputProps) => import("react/jsx-runtime").JSX.Element;
13
+ export declare const CalculatorInput: ({ value, onChange, placeholder, className, title, description, enableTaxCalculation, decimalPlaces, numberFormatOptions, displayPlaceholder, }: CalculatorInputProps) => import("react/jsx-runtime").JSX.Element | null;
package/dist/index.esm.js CHANGED
@@ -6421,7 +6421,13 @@ const Calculator = ({ isOpen, onClose, onCalculate, initialValue = '', title, de
6421
6421
  }) => {
6422
6422
  const [input, setInput] = useState(initialValue || '');
6423
6423
  const [error, setError] = useState('');
6424
+ const [mounted, setMounted] = useState(false);
6424
6425
  const inputRef = useRef(null);
6426
+ // DOM要素の存在確認
6427
+ useEffect(() => {
6428
+ setMounted(true);
6429
+ return () => setMounted(false);
6430
+ }, []);
6425
6431
  useEffect(() => {
6426
6432
  if (isOpen) {
6427
6433
  setInput(initialValue || '');
@@ -6543,18 +6549,32 @@ const Calculator = ({ isOpen, onClose, onCalculate, initialValue = '', title, de
6543
6549
  setInput(normalizeNumberString(taxExcluded, decimalPlaces));
6544
6550
  setError('');
6545
6551
  };
6546
- if (!isOpen)
6552
+ if (!isOpen || !mounted)
6547
6553
  return null;
6548
6554
  const modal = (jsx("div", { className: "calculator-overlay", children: jsxs("div", { className: "calculator-modal", children: [title || description ? (jsxs("div", { className: "calculator-header", children: [jsxs("div", { children: [title && jsx("h2", { className: "calculator-title", children: title }), description && jsx("p", { className: "calculator-subtitle", children: description })] }), jsx("button", { onClick: onClose, className: "calculator-close-button", "aria-label": "\u9589\u3058\u308B", children: jsx(Icon, { icon: faTimes, className: "w-5 h-5" }) })] })) : (jsxs("div", { className: "calculator-header", children: [jsx("div", {}), jsx("button", { onClick: onClose, className: "calculator-close-button", "aria-label": "\u9589\u3058\u308B", children: jsx(Icon, { icon: faTimes, className: "w-5 h-5" }) })] })), jsx("div", { className: "calculator-display", children: jsx(CalculatorDisplay, { value: input, error: error, inputRef: inputRef, editable: true, onChange: (v) => setInput(v), numberFormatOptions: numberFormatOptions }) }), jsx(CalculatorKeypad, { onButtonClick: handleButtonClick, onEqual: handleEqual, onDecide: handleDecide, onTaxInclude: handleTaxInclude, onTaxExclude: handleTaxExclude, enableTaxCalculation: enableTaxCalculation, decimalPlaces: decimalPlaces })] }) }));
6549
- return createPortal(modal, document.body);
6555
+ // DOM要素の存在確認を行ってからポータルを作成
6556
+ if (typeof document !== 'undefined' && document.body) {
6557
+ return createPortal(modal, document.body);
6558
+ }
6559
+ return null;
6550
6560
  };
6551
6561
 
6552
6562
  const CalculatorInput = ({ value, onChange, placeholder = 'クリックして金額を入力', className, title, description, enableTaxCalculation = false, decimalPlaces = 6, numberFormatOptions = {}, displayPlaceholder, }) => {
6553
6563
  const [isOpen, setIsOpen] = useState(false);
6564
+ const [mounted, setMounted] = useState(false);
6565
+ // DOM要素の存在確認
6566
+ useEffect(() => {
6567
+ setMounted(true);
6568
+ return () => setMounted(false);
6569
+ }, []);
6554
6570
  const handleCalculate = (val) => {
6555
6571
  onChange(val);
6556
6572
  setIsOpen(false);
6557
6573
  };
6574
+ // マウント前は何も表示しない
6575
+ if (!mounted) {
6576
+ return null;
6577
+ }
6558
6578
  return (jsxs(Fragment, { children: [jsx(NumericFormat, { value: value, onValueChange: (vals) => onChange(vals.value), placeholder: placeholder, className: className, readOnly: true, onClick: () => setIsOpen(true), ...numberFormatOptions }), jsx(Calculator, { isOpen: isOpen, onClose: () => setIsOpen(false), onCalculate: handleCalculate, initialValue: value, title: title, description: description, enableTaxCalculation: enableTaxCalculation, decimalPlaces: decimalPlaces, numberFormatOptions: numberFormatOptions, placeholder: displayPlaceholder })] }));
6559
6579
  };
6560
6580