@gumigumih/react-calculator-input-form 1.1.5 → 2.0.0

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/README.md CHANGED
@@ -18,15 +18,17 @@
18
18
  - 📈 **3桁区切り表示**
19
19
  - 🔗 **react-number-format完全対応**(通貨記号、カスタムフォーマット等)
20
20
  - ⌨️ **キーボードショートカット対応**
21
- - 🔧 **TypeScript対応**
22
- - ⚙️ **カスタマイズ可能なオプション設定**
23
- - 🎨 **スタイルの自動読み込み**(別途CSSファイルの読み込み不要)
21
+ - 🔧 **TypeScript対応**
22
+ - ⚙️ **カスタマイズ可能なオプション設定**
23
+ - 🎨 **スタイルの自動読み込み**(別途CSSファイルの読み込み不要)
24
24
 
25
25
  ## 🚀 インストール
26
26
 
27
27
  ```bash
28
- npm install @gumigumih/react-calculator-input-form
29
- ```
28
+ npm install @gumigumih/react-calculator-input-form
29
+ ```
30
+
31
+ あわせて `react`, `react-dom`, `react-number-format` が必要です。
30
32
 
31
33
  ```bash
32
34
  yarn add @gumigumih/react-calculator-input-form
@@ -62,7 +64,7 @@ function App() {
62
64
  }
63
65
  ```
64
66
 
65
- ### 高度な使用方法
67
+ ### 高度な使用方法
66
68
 
67
69
  ```tsx
68
70
  import { Calculator } from '@gumigumih/react-calculator-input-form';
@@ -96,7 +98,7 @@ function App() {
96
98
 
97
99
  ## ⚙️ オプション設定
98
100
 
99
- ### CalculatorInputForm オプション
101
+ ### CalculatorInputForm オプション
100
102
 
101
103
  ```tsx
102
104
  <CalculatorInputForm
@@ -183,22 +185,66 @@ react-number-formatの**すべてのプロパティ**が利用可能です。詳
183
185
  | `onChange` | (value: string) => void | ✓ | - | 値変更時のコールバック |
184
186
  | `placeholder` | string | | "クリックして金額を入力" | プレースホルダーテキスト |
185
187
  | `className` | string | | - | 入力フィールドのCSSクラス |
186
- | `title` | string | | "金額入力" | モーダルのタイトル |
187
- | `description` | string | | "税込・税抜や小数計算に対応" | モーダルの説明文 |
188
- | `enableTaxCalculation` | boolean | | true | 税計算機能の有効/無効 |
189
- | `decimalPlaces` | number | | 6 | 小数点以下の最大桁数 |
190
- | `numberFormatOptions` | object | | {} | 数値フォーマットの詳細設定 |
191
-
192
- ## ⌨️ キーボードショートカット
188
+ | `title` | string | | "金額入力" | モーダルのタイトル |
189
+ | `description` | string | | "税込・税抜や小数計算に対応" | モーダルの説明文 |
190
+ | `enableTaxCalculation` | boolean | | false | 税計算機能の有効/無効 |
191
+ | `decimalPlaces` | number | | 6 | 小数点以下の最大桁数 |
192
+ | `numberFormatOptions` | `Partial<NumericFormatProps>` | | `{}` | 数値フォーマットの詳細設定 |
193
+ | `colors` | object | | - | 色のカスタマイズ設定 |
194
+ | `theme` | object | | - | `colors` の互換エイリアス |
195
+
196
+ ### colors
197
+
198
+ ```tsx
199
+ <CalculatorInputForm
200
+ value={amount}
201
+ onChange={setAmount}
202
+ colors={{
203
+ primaryColor: '#7c3aed',
204
+ operatorColor: '#f97316',
205
+ successColor: '#10b981',
206
+ dangerColor: '#ef4444',
207
+ surfaceColor: '#ffffff',
208
+ }}
209
+ />
210
+ ```
211
+
212
+ `theme` でも同じ指定ができますが、今後は `colors` を推奨します。
213
+
214
+ ## 🎨 スタイル
215
+
216
+ このパッケージはインポート時に自動で基本スタイルを読み込みます。個別に明示したい場合は以下も使えます。
217
+
218
+ ```tsx
219
+ import '@gumigumih/react-calculator-input-form/styles';
220
+ ```
221
+
222
+ ## 📦 公開 API
223
+
224
+ 外部利用向けに公開しているのは以下です。
225
+
226
+ - `CalculatorInputForm`
227
+ - `Calculator`
228
+ - `CalculatorDisplay`
229
+ - `CalculatorKeypad`
230
+
231
+ 内部実装寄りの `Button` / `Icon` は公開していません。
232
+
233
+ ## ⌨️ キーボードショートカット
193
234
 
194
235
  - `+`, `-`, `*`, `/`: 演算子
195
236
  - `Enter`, `=`: 計算実行
196
237
  - `Escape`: 電卓を閉じる
197
238
  - `C`: クリア
198
- - `Backspace`: バックスペース
199
- - `.`: 小数点入力
200
-
201
- ## 🎨 デモ
239
+ - `Backspace`: バックスペース
240
+ - `.`: 小数点入力
241
+
242
+ ## 🧮 計算方式
243
+
244
+ この電卓は、一般的な手元電卓と同じく左から順に計算する逐次計算方式です。
245
+ `1 + 2 × 3` のような式は、数学の優先順位ではなく入力順に処理されます。
246
+
247
+ ## 🎨 デモ
202
248
 
203
249
  実際の動作を確認したい場合は、以下のドキュメントページをご覧ください:
204
250
 
File without changes
File without changes
@@ -1,4 +1,5 @@
1
1
  import type { RefObject } from 'react';
2
+ import type { NumericFormatProps } from 'react-number-format';
2
3
  export interface CalculatorDisplayProps {
3
4
  value: string;
4
5
  error?: string;
@@ -6,6 +7,6 @@ export interface CalculatorDisplayProps {
6
7
  editable?: boolean;
7
8
  placeholder?: string;
8
9
  onChange?: (value: string) => void;
9
- numberFormatOptions?: any;
10
+ numberFormatOptions?: Partial<NumericFormatProps>;
10
11
  }
11
12
  export declare const CalculatorDisplay: ({ value, error, inputRef, editable, placeholder, onChange, numberFormatOptions }: CalculatorDisplayProps) => import("react/jsx-runtime").JSX.Element;
File without changes
@@ -1,3 +1,11 @@
1
+ import type { NumericFormatProps } from 'react-number-format';
2
+ export interface CalculatorColorTheme {
3
+ primaryColor?: string;
4
+ operatorColor?: string;
5
+ successColor?: string;
6
+ dangerColor?: string;
7
+ surfaceColor?: string;
8
+ }
1
9
  export interface CalculatorProps {
2
10
  isOpen: boolean;
3
11
  onClose: () => void;
@@ -7,7 +15,9 @@ export interface CalculatorProps {
7
15
  description?: string;
8
16
  enableTaxCalculation?: boolean;
9
17
  decimalPlaces?: number;
10
- numberFormatOptions?: any;
18
+ numberFormatOptions?: Partial<NumericFormatProps>;
11
19
  placeholder?: string;
20
+ colors?: CalculatorColorTheme;
21
+ theme?: CalculatorColorTheme;
12
22
  }
13
- export declare const Calculator: ({ isOpen, onClose, onCalculate, initialValue, title, description, enableTaxCalculation, decimalPlaces, numberFormatOptions, placeholder, }: CalculatorProps) => import("react").ReactPortal | null;
23
+ export declare const Calculator: ({ isOpen, onClose, onCalculate, initialValue, title, description, enableTaxCalculation, decimalPlaces, numberFormatOptions, placeholder, colors, theme, }: CalculatorProps) => import("react").ReactPortal | null;
@@ -1,3 +1,5 @@
1
+ import type { NumericFormatProps } from 'react-number-format';
2
+ import { type CalculatorColorTheme } from './Calculator';
1
3
  export interface CalculatorInputFormProps {
2
4
  value: string;
3
5
  onChange: (value: string) => void;
@@ -7,7 +9,9 @@ export interface CalculatorInputFormProps {
7
9
  description?: string;
8
10
  enableTaxCalculation?: boolean;
9
11
  decimalPlaces?: number;
10
- numberFormatOptions?: any;
12
+ numberFormatOptions?: Partial<NumericFormatProps>;
11
13
  displayPlaceholder?: string;
14
+ colors?: CalculatorColorTheme;
15
+ theme?: CalculatorColorTheme;
12
16
  }
13
- export declare const CalculatorInputForm: ({ value, onChange, placeholder, className, title, description, enableTaxCalculation, decimalPlaces, numberFormatOptions, displayPlaceholder, }: CalculatorInputFormProps) => import("react/jsx-runtime").JSX.Element | null;
17
+ export declare const CalculatorInputForm: ({ value, onChange, placeholder, className, title, description, enableTaxCalculation, decimalPlaces, numberFormatOptions, displayPlaceholder, colors, theme, }: CalculatorInputFormProps) => import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,2 @@
1
+ export declare function normalizeNumberString(num: number, maxFractionDigits?: number): string;
2
+ export declare function calculateExpression(expr: string): string;
@@ -0,0 +1,20 @@
1
+ type ControllerParams = {
2
+ isOpen: boolean;
3
+ initialValue?: string;
4
+ onClose: () => void;
5
+ onCalculate: (value: string) => void;
6
+ enableTaxCalculation: boolean;
7
+ decimalPlaces: number;
8
+ };
9
+ export declare function useCalculatorController({ isOpen, initialValue, onClose, onCalculate, enableTaxCalculation, decimalPlaces, }: ControllerParams): {
10
+ mounted: boolean;
11
+ displayValue: string;
12
+ error: string;
13
+ handleDisplayChange: (newValue: string) => void;
14
+ handleButtonClick: (val: string) => void;
15
+ handleEqual: () => void;
16
+ handleDecide: () => void;
17
+ handleTaxInclude: (rate: number) => void;
18
+ handleTaxExclude: (rate: number) => void;
19
+ };
20
+ export {};
File without changes
package/dist/index.d.ts CHANGED
@@ -1,12 +1,8 @@
1
1
  import './styles/calculator.css';
2
- export { Button } from './components/atoms/Button';
3
- export { Icon } from './components/atoms/Icon';
4
2
  export { CalculatorDisplay } from './components/molecules/CalculatorDisplay';
5
3
  export { CalculatorKeypad } from './components/molecules/CalculatorKeypad';
6
4
  export { Calculator } from './components/organisms/Calculator';
7
5
  export { CalculatorInputForm } from './components/organisms/CalculatorInputForm';
8
- export type { ButtonProps } from './components/atoms/Button';
9
- export type { IconProps } from './components/atoms/Icon';
10
6
  export type { CalculatorDisplayProps } from './components/molecules/CalculatorDisplay';
11
7
  export type { CalculatorKeypadProps } from './components/molecules/CalculatorKeypad';
12
8
  export type { CalculatorProps } from './components/organisms/Calculator';