kilfx 4.0.1 → 4.0.3

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
@@ -17,20 +17,25 @@ npm install kilfx
17
17
  ## DOM Convention
18
18
 
19
19
  ```html
20
- <div class="kilfx" kilfx_int="JM" kilfx_only="JM,US,IN">
20
+ <div class="kilfx" kilfx_int="JMD" kilfx_only="JMD,USD,GBP">
21
21
  <select name="kilfx_base"></select>
22
22
  <select name="kilfx_to"></select>
23
23
  <input type="text" name="fx_rate" readonly />
24
24
  </div>
25
25
  ```
26
26
 
27
- Required:
27
+ Required in same `.kilfx` block:
28
28
  - `select[name="kilfx_base"]`
29
29
  - `select[name="kilfx_to"]`
30
30
 
31
31
  Optional:
32
32
  - `input[name="fx_rate"]` (forced readonly and cleared on pair change)
33
33
 
34
+ Also supported for Bootstrap-style split layout (different `.kilfx` columns):
35
+ - `base_currency` (alias of base)
36
+ - `display_currency` (alias of to)
37
+ - `exchange_rate` (alias of rate)
38
+
34
39
  ## CDN Usage
35
40
 
36
41
  ```html
@@ -46,8 +51,8 @@ If you want custom config, add:
46
51
  <script>
47
52
  KILFX.init({
48
53
  flagsPath: "/svg",
49
- defaultBase: "JM",
50
- defaultTo: "US"
54
+ defaultBase: "JMD",
55
+ defaultTo: "USD"
51
56
  });
52
57
  </script>
53
58
  ```
@@ -80,7 +85,7 @@ import "kilfx/dist/kilfx.css";
80
85
  import { KilFx } from "kilfx/react";
81
86
 
82
87
  export default function Page() {
83
- return <KilFx flagsPath="/svg" defaultBase="JM" defaultTo="US" />;
88
+ return <KilFx flagsPath="/svg" defaultBase="JMD" defaultTo="USD" />;
84
89
  }
85
90
  ```
86
91
 
@@ -95,15 +100,16 @@ On every base/to change, `kilfx`:
95
100
 
96
101
  ```js
97
102
  document.addEventListener("kilfx:change", (e) => {
98
- const { base, to, rootEl, baseSelectEl, toSelectEl, baseItem, toItem } = e.detail;
103
+ const { base, to, rootEl, baseSelectEl, toSelectEl, rateInputEl, baseItem, toItem } = e.detail;
99
104
  });
100
105
  ```
101
106
 
102
107
  `detail` shape:
103
- - `base` / `to`: ISO2 code (`"US"`, `"JM"`, etc.)
108
+ - `base` / `to`: currency code (`"USD"`, `"JMD"`, etc.)
104
109
  - `rootEl`: current `.kilfx` container
105
110
  - `baseSelectEl`, `toSelectEl`: underlying native selects
106
- - `baseItem`, `toItem`: `{ name, code, dial_code }`
111
+ - `rateInputEl`: resolved rate input in same form/group
112
+ - `baseItem`, `toItem`: `{ code, name, flag_code }`
107
113
 
108
114
  ## API
109
115
 
@@ -116,29 +122,29 @@ init({
116
122
  flagsPath: "/svg",
117
123
  fileCase: "auto", // auto | upper | lower
118
124
  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
125
+ defaultBase: "JMD",
126
+ defaultTo: "JMD",
127
+ initCurrency: "JMD", // fallback for both (kilfx_int also works)
128
+ only: "JMD,USD,GBP", // restrict both dropdowns by currency code
129
+ onlyBase: "JMD,USD", // optional base-only restriction
130
+ onlyTo: "USD,EUR", // optional to-only restriction
131
+ data: null // custom currency data or null for built-in
126
132
  });
127
133
  ```
128
134
 
129
135
  ## Attribute Shortcuts (Per `.kilfx`)
130
136
 
131
137
  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
138
+ - `kilfx_int="JMD"`: default code for both dropdowns (if specific defaults not set)
139
+ - `kilfx_only="JMD,USD,GBP"`: restrict both dropdowns to selected currency codes
140
+ - `kilfx_base_int="USD"` / `kilfx_to_int="JMD"`: specific defaults
141
+ - `kilfx_base_only="USD,CAD"` / `kilfx_to_only="JMD,EUR"`: specific allowed lists
136
142
 
137
143
  Select-level overrides also supported:
138
- - `select ... kilfx_int="US"`
139
- - `select ... kilfx_only="US,JM"`
144
+ - `select ... kilfx_int="USD"`
145
+ - `select ... kilfx_only="USD,JMD"`
140
146
 
141
- If nothing is provided, both dropdowns default to `JM`.
147
+ If nothing is provided, both dropdowns default to `JMD`.
142
148
 
143
149
  ## Acceptance Example
144
150
 
@@ -151,11 +157,11 @@ If nothing is provided, both dropdowns default to `JM`.
151
157
 
152
158
  <script src="/dist/kilfx.iife.min.js"></script>
153
159
  <script>
154
- KILFX.init({ flagsPath: "/svg", defaultBase: "JM", defaultTo: "US" });
160
+ KILFX.init({ flagsPath: "/svg", defaultBase: "JMD", defaultTo: "USD" });
155
161
 
156
162
  document.addEventListener("kilfx:change", async (e) => {
157
- const { base, to, rootEl } = e.detail;
158
- const rateInput = rootEl.querySelector('input[name="fx_rate"]');
163
+ const { base, to, rateInputEl } = e.detail;
164
+ const rateInput = rateInputEl;
159
165
  rateInput.value = "...";
160
166
  // const { data } = await axios.get("/api/fx/rate", { params: { base, to } });
161
167
  // rateInput.value = data.rate;