@famgia/omnify-react 0.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/README.md +178 -0
- package/dist/components/index.cjs +686 -0
- package/dist/components/index.cjs.map +1 -0
- package/dist/components/index.d.cts +95 -0
- package/dist/components/index.d.ts +95 -0
- package/dist/components/index.js +657 -0
- package/dist/components/index.js.map +1 -0
- package/dist/hooks/index.cjs +81 -0
- package/dist/hooks/index.cjs.map +1 -0
- package/dist/hooks/index.d.cts +20 -0
- package/dist/hooks/index.d.ts +20 -0
- package/dist/hooks/index.js +54 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/index.cjs +1005 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +947 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/index.cjs +479 -0
- package/dist/lib/index.cjs.map +1 -0
- package/dist/lib/index.d.cts +209 -0
- package/dist/lib/index.d.ts +209 -0
- package/dist/lib/index.js +425 -0
- package/dist/lib/index.js.map +1 -0
- package/package.json +110 -0
- package/scripts/postinstall.cjs +121 -0
package/README.md
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# @famgia/omnify-react
|
|
2
|
+
|
|
3
|
+
React runtime components, hooks, and utilities for [Omnify](https://github.com/ecsol/omnify-ts) schemas.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @famgia/omnify-react
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @famgia/omnify-react
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- **Components**: Pre-built Japanese form field components (name, address, bank account)
|
|
16
|
+
- **Hooks**: Form mutation with Laravel error handling
|
|
17
|
+
- **Utilities**: Zod i18n, form validation, kana validation rules
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### Components
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
import {
|
|
25
|
+
JapaneseNameField,
|
|
26
|
+
JapaneseAddressField,
|
|
27
|
+
JapaneseBankField,
|
|
28
|
+
} from '@famgia/omnify-react';
|
|
29
|
+
import { customerSchemas, customerI18n } from './.omnify/schemas';
|
|
30
|
+
|
|
31
|
+
function CustomerForm() {
|
|
32
|
+
const [form] = Form.useForm();
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<Form form={form}>
|
|
36
|
+
<JapaneseNameField
|
|
37
|
+
schemas={customerSchemas}
|
|
38
|
+
i18n={customerI18n}
|
|
39
|
+
prefix="name"
|
|
40
|
+
showKana
|
|
41
|
+
/>
|
|
42
|
+
|
|
43
|
+
<JapaneseAddressField
|
|
44
|
+
form={form}
|
|
45
|
+
schemas={customerSchemas}
|
|
46
|
+
i18n={customerI18n}
|
|
47
|
+
prefix="address"
|
|
48
|
+
prefectureOptions={prefectureOptions}
|
|
49
|
+
/>
|
|
50
|
+
|
|
51
|
+
<JapaneseBankField
|
|
52
|
+
schemas={customerSchemas}
|
|
53
|
+
i18n={customerI18n}
|
|
54
|
+
prefix="bank"
|
|
55
|
+
accountTypeOptions={accountTypeOptions}
|
|
56
|
+
/>
|
|
57
|
+
</Form>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Hooks
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
import { useFormMutation } from '@famgia/omnify-react';
|
|
66
|
+
|
|
67
|
+
function CustomerForm() {
|
|
68
|
+
const [form] = Form.useForm();
|
|
69
|
+
|
|
70
|
+
const mutation = useFormMutation({
|
|
71
|
+
form,
|
|
72
|
+
mutationFn: (data) => axios.post('/api/customers', data),
|
|
73
|
+
invalidateKeys: [['customers']],
|
|
74
|
+
successMessage: '保存しました',
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<Form form={form} onFinish={mutation.mutate}>
|
|
79
|
+
{/* fields */}
|
|
80
|
+
<Button loading={mutation.isPending}>保存</Button>
|
|
81
|
+
</Form>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Form Validation
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
import { setZodLocale, zodRule, requiredRule } from '@famgia/omnify-react';
|
|
90
|
+
import { customerSchemas } from './.omnify/schemas';
|
|
91
|
+
|
|
92
|
+
// Set locale once at app level
|
|
93
|
+
setZodLocale('ja');
|
|
94
|
+
|
|
95
|
+
function CustomerForm() {
|
|
96
|
+
return (
|
|
97
|
+
<Form>
|
|
98
|
+
<Form.Item
|
|
99
|
+
name="email"
|
|
100
|
+
rules={[zodRule(customerSchemas.email, 'メールアドレス')]}
|
|
101
|
+
>
|
|
102
|
+
<Input />
|
|
103
|
+
</Form.Item>
|
|
104
|
+
|
|
105
|
+
<Form.Item
|
|
106
|
+
name="name"
|
|
107
|
+
rules={[requiredRule('名前')]}
|
|
108
|
+
>
|
|
109
|
+
<Input />
|
|
110
|
+
</Form.Item>
|
|
111
|
+
</Form>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Kana Validation
|
|
117
|
+
|
|
118
|
+
```tsx
|
|
119
|
+
import { kanaString, KATAKANA_PATTERN } from '@famgia/omnify-react';
|
|
120
|
+
import { z } from 'zod';
|
|
121
|
+
|
|
122
|
+
// Method 1: Use kanaString helper
|
|
123
|
+
const schema = z.object({
|
|
124
|
+
name_kana: kanaString(), // 全角カタカナ (default)
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// Method 2: Use pattern directly
|
|
128
|
+
const schema2 = z.object({
|
|
129
|
+
name_kana: z.string().regex(KATAKANA_PATTERN, '全角カタカナで入力してください'),
|
|
130
|
+
});
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## API Reference
|
|
134
|
+
|
|
135
|
+
### Components
|
|
136
|
+
|
|
137
|
+
| Component | Description |
|
|
138
|
+
| ---------------------- | ------------------------------------------------- |
|
|
139
|
+
| `JapaneseNameField` | Japanese name input (lastname + firstname + kana) |
|
|
140
|
+
| `JapaneseAddressField` | Japanese address input with postal code lookup |
|
|
141
|
+
| `JapaneseBankField` | Japanese bank account input |
|
|
142
|
+
|
|
143
|
+
### Hooks
|
|
144
|
+
|
|
145
|
+
| Hook | Description |
|
|
146
|
+
| ----------------- | ----------------------------------------- |
|
|
147
|
+
| `useFormMutation` | Form mutation with Laravel error handling |
|
|
148
|
+
|
|
149
|
+
### Utilities
|
|
150
|
+
|
|
151
|
+
| Function | Description |
|
|
152
|
+
| ------------------------------ | --------------------------------------------- |
|
|
153
|
+
| `setZodLocale(locale)` | Set current locale for validation messages |
|
|
154
|
+
| `getZodLocale()` | Get current locale |
|
|
155
|
+
| `zodRule(schema, displayName)` | Convert Zod schema to Ant Design rule |
|
|
156
|
+
| `requiredRule(displayName)` | Create required rule with i18n |
|
|
157
|
+
| `kanaString(options)` | Create Zod string schema with kana validation |
|
|
158
|
+
|
|
159
|
+
### Kana Presets
|
|
160
|
+
|
|
161
|
+
| Preset | Description |
|
|
162
|
+
| ----------------------- | ---------------------- |
|
|
163
|
+
| `KATAKANA_FULL_WIDTH` | 全角カタカナ (default) |
|
|
164
|
+
| `KATAKANA_HALF_WIDTH` | 半角カタカナ |
|
|
165
|
+
| `HIRAGANA` | ひらがな |
|
|
166
|
+
| `KANA_ANY` | All kana types |
|
|
167
|
+
| `KATAKANA_WITH_NUMBERS` | カタカナ + numbers |
|
|
168
|
+
|
|
169
|
+
## Peer Dependencies
|
|
170
|
+
|
|
171
|
+
- `react` >= 18.0.0
|
|
172
|
+
- `react-dom` >= 18.0.0
|
|
173
|
+
- `antd` >= 6.0.0
|
|
174
|
+
- `zod` >= 3.25.0
|
|
175
|
+
|
|
176
|
+
## License
|
|
177
|
+
|
|
178
|
+
MIT
|