math-main-components 0.0.17 → 0.0.18

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/dist/index.cjs.js CHANGED
@@ -274,32 +274,30 @@ function InputPin({ name, length, onFinished = () => { } }) {
274
274
  const fieldRefs = React.useRef([]);
275
275
  fieldRefs.current = [...Array(length)].map((_, i) => fieldRefs.current[i] ?? React.createRef());
276
276
  function onChange(event, position) {
277
- const regex = /^[0-9\b]+$/;
278
- const value = event.target.value ? event.target.value : "";
279
- console.log("current state", state, position, value);
280
- if (value != '' && regex.test(value)) {
281
- const digitCountBefore = state[position] == undefined ? 0 : String(state[position]).length;
282
- const addedDigitsCount = value.length - digitCountBefore;
283
- if (addedDigitsCount == 1) {
284
- fieldRefs.current[(position + 1) % length].current.focus();
285
- setDigit(position, value.charAt(-1));
286
- }
287
- else {
288
- const digits = value.split("");
289
- if (digitCountBefore == 1)
290
- digits.shift();
291
- let newState = { ...state };
292
- digits.forEach((digit, position) => {
293
- newState[position % length] = digit;
294
- fieldRefs.current[position % length].current.value = digit;
295
- });
296
- if (digits.length >= 6) {
297
- fieldRefs.current[length - 1].current.focus();
298
- }
299
- setState(newState);
300
- }
277
+ const regex = /[0-9]+/;
278
+ const value = event.target.value ? event.target.value.replace(" ", "") : "";
279
+ if (value == '' || !regex.test(value))
280
+ return;
281
+ const digitCountBefore = state[position] == undefined ? 0 : String(state[position]).length;
282
+ const addedDigitsCount = value.length - digitCountBefore;
283
+ // One digit was added
284
+ if (addedDigitsCount == 1) {
285
+ fieldRefs.current[(position + 1) % length].current.focus();
286
+ setDigit(position, value.slice(-1));
287
+ return;
288
+ }
289
+ const digits = value.split("");
290
+ if (digitCountBefore == 1)
291
+ digits.shift();
292
+ let newState = { ...state };
293
+ digits.forEach((digit, relativePosition) => {
294
+ newState[relativePosition % length + position] = digit;
295
+ fieldRefs.current[relativePosition % length + position].current.value = digit;
296
+ });
297
+ if (digits.length >= 6) {
298
+ fieldRefs.current[length - 1].current.focus();
301
299
  }
302
- console.log("new state", state);
300
+ setState(newState);
303
301
  }
304
302
  function onKeyUp(event, position) {
305
303
  event.preventDefault();
@@ -331,7 +329,7 @@ function InputPin({ name, length, onFinished = () => { } }) {
331
329
  }
332
330
  return React__default["default"].createElement("input", { key: i, pattern: "[0-9]", value: state[i] ? state[i] : "", ref: fieldRefs.current[i], className: styles$e.input, type: "text", onKeyUp: (event) => onKeyUp(event, i), onInput: (event) => onChange(event, i) });
333
331
  })),
334
- React__default["default"].createElement("button", { onClick: resetValues }, "Zur\u00FCcksetzen"))));
332
+ React__default["default"].createElement("button", { type: "button", onClick: resetValues }, "Zur\u00FCcksetzen"))));
335
333
  }
336
334
 
337
335
  var css_248z$d = ".styles-module_container__zcXGF {\n display: flex;\n width: 100%;\n margin-bottom: 20px;\n}\n\n.styles-module_input__Tpth8 {\n padding: 14px 20px;\n font-size: 16px;\n border-radius: 12px;\n border: 1.5px solid #a8a8a8;\n outline: none;\n transition: 0.2s ease;\n flex: 1;\n}\n.styles-module_input__Tpth8:focus, .styles-module_input__Tpth8:active {\n border-color: #0075FF;\n box-shadow: 0px 0px 3px 3px rgba(0, 87, 255, 0.2509803922);\n}\n.styles-module_input__Tpth8.styles-module_not_available__CRXjB, .styles-module_input__Tpth8:invalid {\n border-color: #e50000;\n box-shadow: 0px 0px 3px 3px rgba(255, 0, 0, 0.2509803922);\n}\n\n/* animated title */\n.styles-module_container__zcXGF {\n position: relative;\n}\n\n.styles-module_label__appHO {\n position: absolute;\n bottom: 0px;\n left: 0px;\n width: 100%;\n height: 100%;\n pointer-events: none;\n}\n\n.styles-module_label_text__-sKjY {\n position: absolute;\n bottom: 16px;\n left: 12px;\n transition: 0.3s ease;\n font-size: 16px;\n border-top-left-radius: 5px;\n border-top-right-radius: 5px;\n opacity: initial;\n background: white;\n color: grey;\n padding-right: 8px;\n padding-left: 8px;\n}\n\n.styles-module_input__Tpth8.styles-module_with_title__L3eGj::placeholder {\n opacity: 0;\n transition: opacity 0.3s ease;\n color: grey;\n}\n\n.styles-module_input__Tpth8.styles-module_with_title__L3eGj:focus::placeholder {\n opacity: 1;\n}\n\n.styles-module_input__Tpth8:focus + .styles-module_label__appHO .styles-module_label_text__-sKjY,\n.styles-module_input__Tpth8.styles-module_valid__zWcOz + .styles-module_label__appHO .styles-module_label_text__-sKjY {\n transform: translateY(-150%);\n left: 15px;\n font-size: 14px;\n background: linear-gradient(to bottom, rgba(250, 250, 250, 0.9411764706), hsla(0, 0%, 100%, 0.951));\n color: #0063d4;\n}\n\n.styles-module_input__Tpth8.styles-module_valid__zWcOz + .styles-module_label__appHO .styles-module_label_text__-sKjY {\n color: #a8a8a8;\n}";
package/dist/index.esm.js CHANGED
@@ -266,32 +266,30 @@ function InputPin({ name, length, onFinished = () => { } }) {
266
266
  const fieldRefs = useRef([]);
267
267
  fieldRefs.current = [...Array(length)].map((_, i) => fieldRefs.current[i] ?? createRef());
268
268
  function onChange(event, position) {
269
- const regex = /^[0-9\b]+$/;
270
- const value = event.target.value ? event.target.value : "";
271
- console.log("current state", state, position, value);
272
- if (value != '' && regex.test(value)) {
273
- const digitCountBefore = state[position] == undefined ? 0 : String(state[position]).length;
274
- const addedDigitsCount = value.length - digitCountBefore;
275
- if (addedDigitsCount == 1) {
276
- fieldRefs.current[(position + 1) % length].current.focus();
277
- setDigit(position, value.charAt(-1));
278
- }
279
- else {
280
- const digits = value.split("");
281
- if (digitCountBefore == 1)
282
- digits.shift();
283
- let newState = { ...state };
284
- digits.forEach((digit, position) => {
285
- newState[position % length] = digit;
286
- fieldRefs.current[position % length].current.value = digit;
287
- });
288
- if (digits.length >= 6) {
289
- fieldRefs.current[length - 1].current.focus();
290
- }
291
- setState(newState);
292
- }
269
+ const regex = /[0-9]+/;
270
+ const value = event.target.value ? event.target.value.replace(" ", "") : "";
271
+ if (value == '' || !regex.test(value))
272
+ return;
273
+ const digitCountBefore = state[position] == undefined ? 0 : String(state[position]).length;
274
+ const addedDigitsCount = value.length - digitCountBefore;
275
+ // One digit was added
276
+ if (addedDigitsCount == 1) {
277
+ fieldRefs.current[(position + 1) % length].current.focus();
278
+ setDigit(position, value.slice(-1));
279
+ return;
280
+ }
281
+ const digits = value.split("");
282
+ if (digitCountBefore == 1)
283
+ digits.shift();
284
+ let newState = { ...state };
285
+ digits.forEach((digit, relativePosition) => {
286
+ newState[relativePosition % length + position] = digit;
287
+ fieldRefs.current[relativePosition % length + position].current.value = digit;
288
+ });
289
+ if (digits.length >= 6) {
290
+ fieldRefs.current[length - 1].current.focus();
293
291
  }
294
- console.log("new state", state);
292
+ setState(newState);
295
293
  }
296
294
  function onKeyUp(event, position) {
297
295
  event.preventDefault();
@@ -323,7 +321,7 @@ function InputPin({ name, length, onFinished = () => { } }) {
323
321
  }
324
322
  return React.createElement("input", { key: i, pattern: "[0-9]", value: state[i] ? state[i] : "", ref: fieldRefs.current[i], className: styles$e.input, type: "text", onKeyUp: (event) => onKeyUp(event, i), onInput: (event) => onChange(event, i) });
325
323
  })),
326
- React.createElement("button", { onClick: resetValues }, "Zur\u00FCcksetzen"))));
324
+ React.createElement("button", { type: "button", onClick: resetValues }, "Zur\u00FCcksetzen"))));
327
325
  }
328
326
 
329
327
  var css_248z$d = ".styles-module_container__zcXGF {\n display: flex;\n width: 100%;\n margin-bottom: 20px;\n}\n\n.styles-module_input__Tpth8 {\n padding: 14px 20px;\n font-size: 16px;\n border-radius: 12px;\n border: 1.5px solid #a8a8a8;\n outline: none;\n transition: 0.2s ease;\n flex: 1;\n}\n.styles-module_input__Tpth8:focus, .styles-module_input__Tpth8:active {\n border-color: #0075FF;\n box-shadow: 0px 0px 3px 3px rgba(0, 87, 255, 0.2509803922);\n}\n.styles-module_input__Tpth8.styles-module_not_available__CRXjB, .styles-module_input__Tpth8:invalid {\n border-color: #e50000;\n box-shadow: 0px 0px 3px 3px rgba(255, 0, 0, 0.2509803922);\n}\n\n/* animated title */\n.styles-module_container__zcXGF {\n position: relative;\n}\n\n.styles-module_label__appHO {\n position: absolute;\n bottom: 0px;\n left: 0px;\n width: 100%;\n height: 100%;\n pointer-events: none;\n}\n\n.styles-module_label_text__-sKjY {\n position: absolute;\n bottom: 16px;\n left: 12px;\n transition: 0.3s ease;\n font-size: 16px;\n border-top-left-radius: 5px;\n border-top-right-radius: 5px;\n opacity: initial;\n background: white;\n color: grey;\n padding-right: 8px;\n padding-left: 8px;\n}\n\n.styles-module_input__Tpth8.styles-module_with_title__L3eGj::placeholder {\n opacity: 0;\n transition: opacity 0.3s ease;\n color: grey;\n}\n\n.styles-module_input__Tpth8.styles-module_with_title__L3eGj:focus::placeholder {\n opacity: 1;\n}\n\n.styles-module_input__Tpth8:focus + .styles-module_label__appHO .styles-module_label_text__-sKjY,\n.styles-module_input__Tpth8.styles-module_valid__zWcOz + .styles-module_label__appHO .styles-module_label_text__-sKjY {\n transform: translateY(-150%);\n left: 15px;\n font-size: 14px;\n background: linear-gradient(to bottom, rgba(250, 250, 250, 0.9411764706), hsla(0, 0%, 100%, 0.951));\n color: #0063d4;\n}\n\n.styles-module_input__Tpth8.styles-module_valid__zWcOz + .styles-module_label__appHO .styles-module_label_text__-sKjY {\n color: #a8a8a8;\n}";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "math-main-components",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
4
4
  "author": "Emilian Scheel",
5
5
  "files": [
6
6
  "dist/**/*"