kilfx 4.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 +164 -0
- package/dist/kilfx.cjs +2055 -0
- package/dist/kilfx.css +191 -0
- package/dist/kilfx.esm.js +2033 -0
- package/dist/kilfx.iife.min.js +193 -0
- package/dist/react.cjs +2059 -0
- package/dist/react.esm.js +2029 -0
- package/package.json +56 -0
package/README.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# kilfx
|
|
2
|
+
|
|
3
|
+
UI-only currency pair selector (flags + search) for:
|
|
4
|
+
- CDN `<script>` (single JS file with auto CSS injection)
|
|
5
|
+
- Node/Express pages
|
|
6
|
+
- Next.js / React (`npm install kilfx`)
|
|
7
|
+
|
|
8
|
+
`kilfx` does **not** fetch FX rates or call external FX APIs.
|
|
9
|
+
It only handles UI + emits change events so your app can fetch rates manually.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install kilfx
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## DOM Convention
|
|
18
|
+
|
|
19
|
+
```html
|
|
20
|
+
<div class="kilfx" kilfx_int="JM" kilfx_only="JM,US,IN">
|
|
21
|
+
<select name="kilfx_base"></select>
|
|
22
|
+
<select name="kilfx_to"></select>
|
|
23
|
+
<input type="text" name="fx_rate" readonly />
|
|
24
|
+
</div>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Required:
|
|
28
|
+
- `select[name="kilfx_base"]`
|
|
29
|
+
- `select[name="kilfx_to"]`
|
|
30
|
+
|
|
31
|
+
Optional:
|
|
32
|
+
- `input[name="fx_rate"]` (forced readonly and cleared on pair change)
|
|
33
|
+
|
|
34
|
+
## CDN Usage
|
|
35
|
+
|
|
36
|
+
```html
|
|
37
|
+
<script src="https://yourcdn.com/kilfx.iife.min.js"></script>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
That alone auto-inits `.kilfx` blocks on page load.
|
|
41
|
+
|
|
42
|
+
If you want custom config, add:
|
|
43
|
+
|
|
44
|
+
```html
|
|
45
|
+
<script src="https://yourcdn.com/kilfx.iife.min.js"></script>
|
|
46
|
+
<script>
|
|
47
|
+
KILFX.init({
|
|
48
|
+
flagsPath: "/svg",
|
|
49
|
+
defaultBase: "JM",
|
|
50
|
+
defaultTo: "US"
|
|
51
|
+
});
|
|
52
|
+
</script>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Optional explicit helper:
|
|
56
|
+
|
|
57
|
+
```html
|
|
58
|
+
<script>
|
|
59
|
+
KILFX.autoInit({ flagsPath: "/svg" });
|
|
60
|
+
</script>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## npm / ESM Usage
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
import { init } from "kilfx";
|
|
67
|
+
init({ flagsPath: "/svg" });
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Optional CSS import (JS still injects CSS automatically):
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
import "kilfx/dist/kilfx.css";
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## React / Next Usage
|
|
77
|
+
|
|
78
|
+
```jsx
|
|
79
|
+
"use client";
|
|
80
|
+
import { KilFx } from "kilfx/react";
|
|
81
|
+
|
|
82
|
+
export default function Page() {
|
|
83
|
+
return <KilFx flagsPath="/svg" defaultBase="JM" defaultTo="US" />;
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Or render your own `.kilfx` markup and call `init()` in `useEffect`.
|
|
88
|
+
|
|
89
|
+
## Events
|
|
90
|
+
|
|
91
|
+
On every base/to change, `kilfx`:
|
|
92
|
+
1. Updates hidden native `<select>` value
|
|
93
|
+
2. Dispatches native `change` on that `<select>`
|
|
94
|
+
3. Dispatches global event:
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
document.addEventListener("kilfx:change", (e) => {
|
|
98
|
+
const { base, to, rootEl, baseSelectEl, toSelectEl, baseItem, toItem } = e.detail;
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`detail` shape:
|
|
103
|
+
- `base` / `to`: ISO2 code (`"US"`, `"JM"`, etc.)
|
|
104
|
+
- `rootEl`: current `.kilfx` container
|
|
105
|
+
- `baseSelectEl`, `toSelectEl`: underlying native selects
|
|
106
|
+
- `baseItem`, `toItem`: `{ name, code, dial_code }`
|
|
107
|
+
|
|
108
|
+
## API
|
|
109
|
+
|
|
110
|
+
```js
|
|
111
|
+
init({
|
|
112
|
+
rootSelector: ".kilfx",
|
|
113
|
+
baseName: "kilfx_base",
|
|
114
|
+
toName: "kilfx_to",
|
|
115
|
+
rateName: "fx_rate",
|
|
116
|
+
flagsPath: "/svg",
|
|
117
|
+
fileCase: "auto", // auto | upper | lower
|
|
118
|
+
enableSearch: true,
|
|
119
|
+
defaultBase: "JM",
|
|
120
|
+
defaultTo: "JM",
|
|
121
|
+
initCountry: "JM", // fallback for both (same idea as kilfx_int)
|
|
122
|
+
only: "JM,US,IN", // restrict both dropdowns
|
|
123
|
+
onlyBase: "JM,US", // optional base-only restriction
|
|
124
|
+
onlyTo: "IN,US", // optional to-only restriction
|
|
125
|
+
data: null // custom country data array or null for built-in
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Attribute Shortcuts (Per `.kilfx`)
|
|
130
|
+
|
|
131
|
+
Container attributes:
|
|
132
|
+
- `kilfx_int="JM"`: default code for both dropdowns (if specific defaults not set)
|
|
133
|
+
- `kilfx_only="JM,US,IN"`: restrict both dropdowns to selected ISO2 codes
|
|
134
|
+
- `kilfx_base_int="US"` / `kilfx_to_int="IN"`: specific defaults
|
|
135
|
+
- `kilfx_base_only="US,CA"` / `kilfx_to_only="IN,JM"`: specific allowed lists
|
|
136
|
+
|
|
137
|
+
Select-level overrides also supported:
|
|
138
|
+
- `select ... kilfx_int="US"`
|
|
139
|
+
- `select ... kilfx_only="US,JM"`
|
|
140
|
+
|
|
141
|
+
If nothing is provided, both dropdowns default to `JM`.
|
|
142
|
+
|
|
143
|
+
## Acceptance Example
|
|
144
|
+
|
|
145
|
+
```html
|
|
146
|
+
<div class="kilfx">
|
|
147
|
+
<select name="kilfx_base"></select>
|
|
148
|
+
<select name="kilfx_to"></select>
|
|
149
|
+
<input name="fx_rate" readonly />
|
|
150
|
+
</div>
|
|
151
|
+
|
|
152
|
+
<script src="/dist/kilfx.iife.min.js"></script>
|
|
153
|
+
<script>
|
|
154
|
+
KILFX.init({ flagsPath: "/svg", defaultBase: "JM", defaultTo: "US" });
|
|
155
|
+
|
|
156
|
+
document.addEventListener("kilfx:change", async (e) => {
|
|
157
|
+
const { base, to, rootEl } = e.detail;
|
|
158
|
+
const rateInput = rootEl.querySelector('input[name="fx_rate"]');
|
|
159
|
+
rateInput.value = "...";
|
|
160
|
+
// const { data } = await axios.get("/api/fx/rate", { params: { base, to } });
|
|
161
|
+
// rateInput.value = data.rate;
|
|
162
|
+
});
|
|
163
|
+
</script>
|
|
164
|
+
```
|