|
12 | 12 | }; |
13 | 13 |
|
14 | 14 | let unchangedValue = 999; // Used for onValueChange() |
| 15 | + let chainedValue = 9999.99; // Used for chained inputs |
| 16 | +
|
| 17 | + const setChainedValue = () => { |
| 18 | + chainedValue = 420.69; |
| 19 | + }; |
15 | 20 | </script> |
16 | 21 |
|
17 | 22 | <form class="demoForm" on:submit={handleSubmit}> |
|
43 | 48 | </nav> |
44 | 49 |
|
45 | 50 | <div class="demoForm__container"> |
46 | | - <CurrencyInput name="default" value={-42069.69} /> |
47 | | - <CurrencyInput name="colon" locale="es-CR" currency="CRC" /> |
48 | | - <CurrencyInput |
49 | | - name="pound" |
50 | | - value={1234.56} |
51 | | - isNegativeAllowed={false} |
52 | | - placeholder={null} |
53 | | - locale="en-GB" |
54 | | - currency="GBP" |
55 | | - /> |
56 | | - <CurrencyInput |
57 | | - name="bitcoin" |
58 | | - value={0.87654321} |
59 | | - locale="th-TH" |
60 | | - currency="THB" |
61 | | - fractionDigits={8} |
62 | | - /> |
63 | | - |
64 | | - <CurrencyInput name="yen" value={5678.9} locale="en-JP" currency="JPY" /> |
65 | | - <CurrencyInput name="shekel" value={97532.95} disabled={true} locale="il-IL" currency="ILS" /> |
66 | | - <CurrencyInput name="euro" value={-42069.69} locale="nl-NL" currency="EUR" /> |
67 | | - <CurrencyInput |
68 | | - name="won" |
69 | | - placeholder={1234.56} |
70 | | - isNegativeAllowed={false} |
71 | | - locale="ko-KO" |
72 | | - currency="KRW" |
73 | | - inputClasses={{ |
74 | | - wrapper: 'currencyInput custom-wrapper-class', |
75 | | - unformatted: 'custom-unformatted-class' |
76 | | - }} |
77 | | - /> |
78 | | - <CurrencyInput |
79 | | - name="pesos" |
80 | | - value={unchangedValue} |
81 | | - isNegativeAllowed={false} |
82 | | - placeholder={null} |
83 | | - autocomplete="off" |
84 | | - locale="es-AR" |
85 | | - currency="ARS" |
86 | | - onValueChange={(value) => { |
87 | | - // Prevent alerting on initial load |
88 | | - if (unchangedValue !== value) { |
89 | | - unchangedValue = value; // Update the unchanged value |
90 | | - if (browser) window.alert(`The value for ARS has changed to: ${value}`); // Alert the user |
91 | | - } |
92 | | - }} |
93 | | - /> |
94 | | - <CurrencyInput name="rupees" value={678} locale="hi-IN" currency="INR" fractionDigits={3} /> |
95 | | - <CurrencyInput name="soles" value={0} isZeroNullish={true} placeholder={null} locale="es-PE" currency="PEN" /> |
96 | | - <CurrencyInput name="dinars" value={0} placeholder={"How many Dinars?"} locale="en-US" currency="RSD" fractionDigits={0} /> |
| 51 | + <fieldset class="demoForm__fieldset"> |
| 52 | + <legend class="demoForm__legend">Stand-alone inputs</legend> |
| 53 | + <CurrencyInput name="default" value={-42069.69} /> |
| 54 | + <CurrencyInput name="colon" locale="es-CR" currency="CRC" /> |
| 55 | + <CurrencyInput |
| 56 | + name="pound" |
| 57 | + value={1234.56} |
| 58 | + isNegativeAllowed={false} |
| 59 | + placeholder={null} |
| 60 | + locale="en-GB" |
| 61 | + currency="GBP" |
| 62 | + /> |
| 63 | + <CurrencyInput |
| 64 | + name="bitcoin" |
| 65 | + value={0.87654321} |
| 66 | + locale="th-TH" |
| 67 | + currency="THB" |
| 68 | + fractionDigits={8} |
| 69 | + /> |
| 70 | + |
| 71 | + <CurrencyInput name="yen" value={5678.9} locale="en-JP" currency="JPY" /> |
| 72 | + <CurrencyInput name="shekel" value={97532.95} disabled={true} locale="il-IL" currency="ILS" /> |
| 73 | + <CurrencyInput name="euro" value={-42069.69} locale="nl-NL" currency="EUR" /> |
| 74 | + <CurrencyInput |
| 75 | + name="won" |
| 76 | + placeholder={1234.56} |
| 77 | + isNegativeAllowed={false} |
| 78 | + locale="ko-KO" |
| 79 | + currency="KRW" |
| 80 | + inputClasses={{ |
| 81 | + wrapper: 'currencyInput custom-wrapper-class', |
| 82 | + unformatted: 'custom-unformatted-class' |
| 83 | + }} |
| 84 | + /> |
| 85 | + <CurrencyInput |
| 86 | + name="pesos" |
| 87 | + value={unchangedValue} |
| 88 | + isNegativeAllowed={false} |
| 89 | + placeholder={null} |
| 90 | + autocomplete="off" |
| 91 | + locale="es-AR" |
| 92 | + currency="ARS" |
| 93 | + onValueChange={(value) => { |
| 94 | + // Prevent alerting on initial load |
| 95 | + if (unchangedValue !== value) { |
| 96 | + unchangedValue = value; // Update the unchanged value |
| 97 | + if (browser) window.alert(`The value for ARS has changed to: ${value}`); // Alert the user |
| 98 | + } |
| 99 | + }} |
| 100 | + /> |
| 101 | + <CurrencyInput name="rupees" value={678} locale="hi-IN" currency="INR" fractionDigits={3} /> |
| 102 | + <CurrencyInput |
| 103 | + name="soles" |
| 104 | + value={0} |
| 105 | + isZeroNullish={true} |
| 106 | + placeholder={null} |
| 107 | + locale="es-PE" |
| 108 | + currency="PEN" |
| 109 | + /> |
| 110 | + <CurrencyInput |
| 111 | + name="dinars" |
| 112 | + value={0} |
| 113 | + placeholder={'How many Dinars?'} |
| 114 | + locale="en-US" |
| 115 | + currency="RSD" |
| 116 | + fractionDigits={0} |
| 117 | + /> |
| 118 | + </fieldset> |
| 119 | + |
| 120 | + <fieldset class="demoForm__fieldset"> |
| 121 | + <legend class="demoForm__legend">Chained inputs</legend> |
| 122 | + <CurrencyInput |
| 123 | + name="chained-east-caribbean-dollar" |
| 124 | + bind:value={chainedValue} |
| 125 | + locale="aig" |
| 126 | + currency="XCD" |
| 127 | + fractionDigits={4} |
| 128 | + /> |
| 129 | + <CurrencyInput name="chained-euros" bind:value={chainedValue} locale="nl-NL" currency="EUR" /> |
| 130 | + <CurrencyInput |
| 131 | + name="chained-dollars" |
| 132 | + bind:value={chainedValue} |
| 133 | + locale="en-US" |
| 134 | + currency="USD" |
| 135 | + fractionDigits={0} |
| 136 | + /> |
| 137 | + <button |
| 138 | + id="set-chained-value" |
| 139 | + type="button" |
| 140 | + class="demoForm__button" |
| 141 | + on:click={setChainedValue} |
| 142 | + > |
| 143 | + Set chained value to <strong>420.69</strong> |
| 144 | + </button> |
| 145 | + </fieldset> |
97 | 146 | </div> |
98 | 147 |
|
99 | 148 | <nav class="demoForm__output"> |
100 | | - <button type="submit" class="demoForm__submit">Submit form</button> |
| 149 | + <button id="submit-form" type="submit" class="demoForm__button">Submit form</button> |
101 | 150 |
|
102 | 151 | <pre class="demoForm__pre {!output && 'demoForm__pre--placeholder'}">{output |
103 | 152 | ? output |
|
144 | 193 | } |
145 | 194 |
|
146 | 195 | div.demoForm__container { |
| 196 | + display: flex; |
| 197 | + flex-direction: column; |
| 198 | + gap: 32px; |
| 199 | + } |
| 200 | +
|
| 201 | + fieldset.demoForm__fieldset { |
147 | 202 | display: grid; |
148 | 203 | grid-template-columns: repeat(4, 1fr); |
149 | 204 | align-items: center; |
150 | 205 | justify-content: center; |
151 | 206 | gap: calc(var(--gap) / 2); |
152 | 207 | height: max-content; |
| 208 | + border: 1px solid #ccc; |
| 209 | + padding: 16px; |
153 | 210 |
|
154 | 211 | @media (max-width: 768px) { |
155 | 212 | grid-template-columns: repeat(2, 1fr); |
156 | 213 | } |
157 | | - |
| 214 | +
|
158 | 215 | @media (max-width: 512px) { |
159 | 216 | grid-template-columns: 1fr; |
160 | 217 | } |
161 | 218 | } |
162 | 219 |
|
| 220 | + legend.demoForm__legend { |
| 221 | + font-size: 13px; |
| 222 | + color: #666; |
| 223 | + } |
| 224 | +
|
163 | 225 | h1.demoForm__h1 { |
164 | 226 | color: #333; |
165 | 227 | font-size: 20px; |
|
224 | 286 | font-size: 13px; |
225 | 287 | } |
226 | 288 |
|
227 | | - button.demoForm__submit { |
| 289 | + button.demoForm__button { |
228 | 290 | border: none; |
229 | 291 | background-color: #333; |
230 | 292 | color: #fff; |
|
234 | 296 | height: max-content; |
235 | 297 | } |
236 | 298 |
|
237 | | - button.demoForm__submit:hover { |
| 299 | + button.demoForm__button:hover { |
238 | 300 | background-color: #000; |
239 | 301 | } |
240 | 302 | </style> |
0 commit comments