@k8slens/lds-form 0.1.2 → 0.1.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("lodash");exports.useFieldIds=function(o){var t=e.useMemo((function(){return o||r.uniqueId("form-field-")}),[o]);return{id:t,labelId:"".concat(t,"-label"),errorId:"".concat(t,"-error")}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react")
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("lodash");exports.defaultErrorParser=function(e,t,r){var n=r.min,a=r.max,o=r.minLength,u=r.maxLength,l={valueMissing:"Required",tooShort:"Min. length is ".concat(o," chars"),tooLong:"Max. length is ".concat(u," chars"),rangeUnderflow:"Value should be at least ".concat(n),rangeOverflow:"Value should be no more than ".concat(a),default:"Value is invalid"};return l[t]||l.default},exports.useFormComponentData=function(r){var n=r.value,a=r.errorParser,o=r.constraints,u=void 0===o?{}:o,l=r.label,i=e.useState({value:n}),s=i[0],c=i[1],h=e.useMemo((function(){for(var e=s.value,r=s.validity,n=[],o=Object.keys(r||{}).filter((function(e){return"valid"!==e})),i=0,c=o;i<c.length;i++){var h=c[i],g=void 0;switch(h){case"tooShort":r&&(r[h]||"string"==typeof e&&u.minLength&&e.length<u.minLength)&&(g=a(e,h,u,l));break;case"tooLong":r&&(r[h]||"string"==typeof e&&u.maxLength&&e.length>u.maxLength)&&(g=a(e,h,u,l));break;default:r&&r[h]&&(g=a(e,h,u,l))}g&&n.push(g)}!1!==(null==r?void 0:r.valid)||n.length||(g=a(e,"unknown",u,l))&&n.push(g);return t.uniq(n)}),[s,u,a,l]);return{currentValue:s,setCurrentValue:c,errors:h}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import r
|
|
1
|
+
import{useMemo as r}from"react";import{uniqueId as o}from"lodash";var t=function(t){var e=r((function(){return t||o("form-field-")}),[t]);return{id:e,labelId:"".concat(e,"-label"),errorId:"".concat(e,"-error")}};export{t as useFieldIds};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useState as e,useMemo as
|
|
1
|
+
import{useState as e,useMemo as t}from"react";import{uniq as n}from"lodash";var r=function(e,t,n){var r=n.min,a=n.max,o=n.minLength,l=n.maxLength,i={valueMissing:"Required",tooShort:"Min. length is ".concat(o," chars"),tooLong:"Max. length is ".concat(l," chars"),rangeUnderflow:"Value should be at least ".concat(r),rangeOverflow:"Value should be no more than ".concat(a),default:"Value is invalid"};return i[t]||i.default},a=function(r){var a=r.value,o=r.errorParser,l=r.constraints,i=void 0===l?{}:l,u=r.label,s=e({value:a}),h=s[0],c=s[1],g=t((function(){for(var e=h.value,t=h.validity,r=[],a=Object.keys(t||{}).filter((function(e){return"valid"!==e})),l=0,s=a;l<s.length;l++){var c=s[l],g=void 0;switch(c){case"tooShort":t&&(t[c]||"string"==typeof e&&i.minLength&&e.length<i.minLength)&&(g=o(e,c,i,u));break;case"tooLong":t&&(t[c]||"string"==typeof e&&i.maxLength&&e.length>i.maxLength)&&(g=o(e,c,i,u));break;default:t&&t[c]&&(g=o(e,c,i,u))}g&&r.push(g)}!1!==(null==t?void 0:t.valid)||r.length||(g=o(e,"unknown",i,u))&&r.push(g);return n(r)}),[h,i,o,u]);return{currentValue:h,setCurrentValue:c,errors:g}};export{r as defaultErrorParser,a as useFormComponentData};
|