@helsenorge/designsystem-react 5.0.0 → 5.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.
- package/CHANGELOG.md +64 -0
- package/FormGroup.js +1 -1
- package/FormGroup.js.map +1 -1
- package/FormLayout.js +1 -1
- package/FormLayout.js.map +1 -1
- package/Input.js +1 -1
- package/Input.js.map +1 -1
- package/RadioButton.js +1 -1
- package/RadioButton.js.map +1 -1
- package/Select.js.map +1 -1
- package/Textarea.js +1 -1
- package/Textarea.js.map +1 -1
- package/components/Button/styles.module.scss +11 -0
- package/components/FormExample/FormExample.d.ts +1 -2
- package/components/FormExample/FormExample.d.ts.map +1 -1
- package/components/FormExample/componentdata.json +1 -1
- package/components/FormExample/index.js +3 -3
- package/components/FormExample/index.js.map +1 -1
- package/components/FormGroup/FormGroup.d.ts.map +1 -1
- package/components/FormGroup/index.js +1 -1
- package/components/FormLayout/FormLayout.d.ts +1 -1
- package/components/FormLayout/FormLayout.d.ts.map +1 -1
- package/components/FormLayout/componentdata.json +1 -1
- package/components/HighlightBox/styles.module.scss +5 -2
- package/components/Input/Input.d.ts +7 -1
- package/components/Input/Input.d.ts.map +1 -1
- package/components/Input/componentdata.json +1 -1
- package/components/Input/index.js +1 -1
- package/components/Input/styles.module.scss +11 -1
- package/components/Input/styles.module.scss.d.ts +12 -10
- package/components/Label/componentdata.json +1 -1
- package/components/RadioButton/RadioButton.d.ts +3 -0
- package/components/RadioButton/RadioButton.d.ts.map +1 -1
- package/components/RadioButton/componentdata.json +1 -1
- package/components/RadioButton/index.js +1 -1
- package/components/Select/Select.d.ts +1 -1
- package/components/Select/Select.d.ts.map +1 -1
- package/components/Select/componentdata.json +1 -1
- package/components/Textarea/styles.module.scss +2 -2
- package/components/Textarea/styles.module.scss.d.ts +9 -9
- package/components/Validation/index.js +1 -1
- package/index.d.ts +1 -0
- package/index.d.ts.map +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/scss/_input.scss +1 -1
- package/utils/mobile.d.ts +10 -0
- package/utils/mobile.d.ts.map +1 -0
- package/utils/mobile.js +2 -0
- package/utils/mobile.js.map +1 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import f from"react";import{isTest as pt}from"../../utils/environment.js";import{B as kt}from"../../Button.js";import{C as re}from"../../Checkbox.js";import{F as Z}from"../../FormGroup.js";import{F as Et,a as _t}from"../../FormLayout.js";import ze from"../Icons/Hospital.js";import{I as me}from"../../Input.js";import{L as O}from"../../Label.js";import{R as he}from"../../RadioButton.js";import{S as Je}from"../../Select.js";import{T as Qe}from"../../Textarea.js";import{V as Vt}from"../../Validation.js";import be from"./styles.module.scss";import"classnames";import"../Icons/Icon.js";import"../../constants.js";import"../../hooks/useUuid.js";import"../../uuid.js";import"../../hooks/useBreakpoint.js";import"../../theme/grid.js";import"../../hooks/useHover.js";import"../../hooks/usePseudoClasses.js";import"../../hooks/useIcons.js";import"../../hooks/useSize.js";import"../../utils/debounce.js";import"../../theme/currys/color.js";import"../../theme/index.js";import"../../theme/palette.js";import"../../theme/spacers.js";import"../Icons/ArrowRight.js";import"../Button/styles.module.scss";import"../../utils/refs.js";import"../Icons/Check.js";import"../Checkbox/styles.module.scss";import"../../utils/component.js";import"../../ErrorWrapper.js";import"../ErrorWrapper/styles.module.scss";import"../../Title.js";import"../Title/styles.module.scss";import"../FormGroup/styles.module.scss";import"../FormLayout/styles.module.scss";import"../../MaxCharacters.js";import"../MaxCharacters/styles.module.scss";import"../Input/styles.module.scss";import"../../Spacer.js";import"../Spacer/styles.module.scss";import"../Label/styles.module.scss";import"../../StatusDot.js";import"../Icons/Attachment.js";import"../Icons/Group.js";import"../Icons/NoAccess.js";import"../Icons/Undo.js";import"../StatusDot/styles.module.scss";import"../RadioButton/styles.module.scss";import"../Icons/ChevronDown.js";import"../Select/styles.module.scss";import"../Textarea/styles.module.scss";import"../Validation/styles.module.scss";var ge=e=>e.type==="checkbox",oe=e=>e instanceof Date,I=e=>e==null;const nt=e=>typeof e=="object";var L=e=>!I(e)&&!Array.isArray(e)&&nt(e)&&!oe(e),Dt=e=>L(e)&&e.target?ge(e.target)?e.target.checked:e.target.value:e,At=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,St=(e,s)=>e.has(At(s)),wt=e=>{const s=e.constructor&&e.constructor.prototype;return L(s)&&s.hasOwnProperty("isPrototypeOf")},Me=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function X(e){let s;const i=Array.isArray(e);if(e instanceof Date)s=new Date(e);else if(e instanceof Set)s=new Set(e);else if(!(Me&&(e instanceof Blob||e instanceof FileList))&&(i||L(e)))if(s=i?[]:{},!i&&!wt(e))s=e;else for(const r in e)e.hasOwnProperty(r)&&(s[r]=X(e[r]));else return e;return s}var ve=e=>Array.isArray(e)?e.filter(Boolean):[],F=e=>e===void 0,m=(e,s,i)=>{if(!s||!L(e))return i;const r=ve(s.split(/[,[\].]+?/)).reduce((l,o)=>I(l)?l:l[o],e);return F(r)||r===e?F(e[s])?i:e[s]:r},ie=e=>typeof e=="boolean";const Xe={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},G={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},Q={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"};f.createContext(null);var Tt=(e,s,i,r=!0)=>{const l={defaultValues:s._defaultValues};for(const o in e)Object.defineProperty(l,o,{get:()=>{const c=o;return s._proxyFormState[c]!==G.all&&(s._proxyFormState[c]=!r||G.all),i&&(i[c]=!0),e[c]}});return l},P=e=>L(e)&&!Object.keys(e).length,Ft=(e,s,i,r)=>{i(e);const{name:l,...o}=e;return P(o)||Object.keys(o).length>=Object.keys(s).length||Object.keys(o).find(c=>s[c]===(!r||G.all))},we=e=>Array.isArray(e)?e:[e];function Ot(e){const s=f.useRef(e);s.current=e,f.useEffect(()=>{const i=!e.disabled&&s.current.subject&&s.current.subject.subscribe({next:s.current.next});return()=>{i&&i.unsubscribe()}},[e.disabled])}var j=e=>typeof e=="string",Lt=(e,s,i,r,l)=>j(e)?(r&&s.watch.add(e),m(i,e,l)):Array.isArray(e)?e.map(o=>(r&&s.watch.add(o),m(i,o))):(r&&(s.watchAll=!0),i),Re=e=>/^\w*$/.test(e),at=e=>ve(e.replace(/["|']|\]/g,"").split(/\.|\[/));function V(e,s,i){let r=-1;const l=Re(s)?[s]:at(s),o=l.length,c=o-1;for(;++r<o;){const b=l[r];let k=i;if(r!==c){const M=e[b];k=L(M)||Array.isArray(M)?M:isNaN(+l[r+1])?{}:[]}e[b]=k,e=e[b]}return e}var Ct=(e,s,i,r,l)=>s?{...i[e],types:{...i[e]&&i[e].types?i[e].types:{},[r]:l||!0}}:{};const Ce=(e,s,i)=>{for(const r of i||Object.keys(e)){const l=m(e,r);if(l){const{_f:o,...c}=l;if(o&&s(o.name)){if(o.ref.focus){o.ref.focus();break}else if(o.refs&&o.refs[0].focus){o.refs[0].focus();break}}else L(c)&&Ce(c,s)}}};var Ye=e=>({isOnSubmit:!e||e===G.onSubmit,isOnBlur:e===G.onBlur,isOnChange:e===G.onChange,isOnAll:e===G.all,isOnTouch:e===G.onTouched}),Ze=(e,s,i)=>!i&&(s.watchAll||s.watch.has(e)||[...s.watch].some(r=>e.startsWith(r)&&/^\.\w+/.test(e.slice(r.length)))),Mt=(e,s,i)=>{const r=ve(m(e,i));return V(r,"root",s[i]),V(e,i,r),e},Ie=e=>e.type==="file",ee=e=>typeof e=="function",pe=e=>{if(!Me)return!1;const s=e?e.ownerDocument:0;return e instanceof(s&&s.defaultView?s.defaultView.HTMLElement:HTMLElement)},xe=e=>j(e),Ne=e=>e.type==="radio",ke=e=>e instanceof RegExp;const et={value:!1,isValid:!1},tt={value:!0,isValid:!0};var ot=e=>{if(Array.isArray(e)){if(e.length>1){const s=e.filter(i=>i&&i.checked&&!i.disabled).map(i=>i.value);return{value:s,isValid:!!s.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!F(e[0].attributes.value)?F(e[0].value)||e[0].value===""?tt:{value:e[0].value,isValid:!0}:tt:et}return et};const rt={isValid:!1,value:null};var ut=e=>Array.isArray(e)?e.reduce((s,i)=>i&&i.checked&&!i.disabled?{isValid:!0,value:i.value}:s,rt):rt;function it(e,s,i="validate"){if(xe(e)||Array.isArray(e)&&e.every(xe)||ie(e)&&!e)return{type:i,message:xe(e)?e:"",ref:s}}var ae=e=>L(e)&&!ke(e)?e:{value:e,message:""},st=async(e,s,i,r,l)=>{const{ref:o,refs:c,required:b,maxLength:k,minLength:M,min:H,max:D,pattern:p,validate:$,name:N,valueAsNumber:ue,mount:le,disabled:ce}=e._f,v=m(s,N);if(!le||ce)return{};const U=c?c[0]:o,B=E=>{r&&U.reportValidity&&(U.setCustomValidity(ie(E)?"":E||""),U.reportValidity())},S={},te=Ne(o),Y=ge(o),de=te||Y,q=(ue||Ie(o))&&F(o.value)&&F(v)||pe(o)&&o.value===""||v===""||Array.isArray(v)&&!v.length,K=Ct.bind(null,N,i,S),W=(E,x,h,_=Q.maxLength,T=Q.minLength)=>{const R=E?x:h;S[N]={type:E?_:T,message:R,ref:o,...K(E?_:T,R)}};if(l?!Array.isArray(v)||!v.length:b&&(!de&&(q||I(v))||ie(v)&&!v||Y&&!ot(c).isValid||te&&!ut(c).isValid)){const{value:E,message:x}=xe(b)?{value:!!b,message:b}:ae(b);if(E&&(S[N]={type:Q.required,message:x,ref:U,...K(Q.required,x)},!i))return B(x),S}if(!q&&(!I(H)||!I(D))){let E,x;const h=ae(D),_=ae(H);if(!I(v)&&!isNaN(v)){const T=o.valueAsNumber||v&&+v;I(h.value)||(E=T>h.value),I(_.value)||(x=T<_.value)}else{const T=o.valueAsDate||new Date(v),R=fe=>new Date(new Date().toDateString()+" "+fe),z=o.type=="time",J=o.type=="week";j(h.value)&&v&&(E=z?R(v)>R(h.value):J?v>h.value:T>new Date(h.value)),j(_.value)&&v&&(x=z?R(v)<R(_.value):J?v<_.value:T<new Date(_.value))}if((E||x)&&(W(!!E,h.message,_.message,Q.max,Q.min),!i))return B(S[N].message),S}if((k||M)&&!q&&(j(v)||l&&Array.isArray(v))){const E=ae(k),x=ae(M),h=!I(E.value)&&v.length>+E.value,_=!I(x.value)&&v.length<+x.value;if((h||_)&&(W(h,E.message,x.message),!i))return B(S[N].message),S}if(p&&!q&&j(v)){const{value:E,message:x}=ae(p);if(ke(E)&&!v.match(E)&&(S[N]={type:Q.pattern,message:x,ref:o,...K(Q.pattern,x)},!i))return B(x),S}if($){if(ee($)){const E=await $(v,s),x=it(E,U);if(x&&(S[N]={...x,...K(Q.validate,x.message)},!i))return B(x.message),S}else if(L($)){let E={};for(const x in $){if(!P(E)&&!i)break;const h=it(await $[x](v,s),U,x);h&&(E={...h,...K(x,h.message)},B(h.message),i&&(S[N]=E))}if(!P(E)&&(S[N]={ref:U,...E},!i))return S}}return B(!0),S};function Rt(e,s){const i=s.slice(0,-1).length;let r=0;for(;r<i;)e=F(e)?r++:e[s[r++]];return e}function It(e){for(const s in e)if(e.hasOwnProperty(s)&&!F(e[s]))return!1;return!0}function C(e,s){const i=Array.isArray(s)?s:Re(s)?[s]:at(s),r=i.length===1?e:Rt(e,i),l=i.length-1,o=i[l];return r&&delete r[o],l!==0&&(L(r)&&P(r)||Array.isArray(r)&&It(r))&&C(e,i.slice(0,-1)),e}function Te(){let e=[];return{get observers(){return e},next:l=>{for(const o of e)o.next&&o.next(l)},subscribe:l=>(e.push(l),{unsubscribe:()=>{e=e.filter(o=>o!==l)}}),unsubscribe:()=>{e=[]}}}var Ee=e=>I(e)||!nt(e);function se(e,s){if(Ee(e)||Ee(s))return e===s;if(oe(e)&&oe(s))return e.getTime()===s.getTime();const i=Object.keys(e),r=Object.keys(s);if(i.length!==r.length)return!1;for(const l of i){const o=e[l];if(!r.includes(l))return!1;if(l!=="ref"){const c=s[l];if(oe(o)&&oe(c)||L(o)&&L(c)||Array.isArray(o)&&Array.isArray(c)?!se(o,c):o!==c)return!1}}return!0}var ct=e=>e.type==="select-multiple",Nt=e=>Ne(e)||ge(e),Fe=e=>pe(e)&&e.isConnected,dt=e=>{for(const s in e)if(ee(e[s]))return!0;return!1};function _e(e,s={}){const i=Array.isArray(e);if(L(e)||i)for(const r in e)Array.isArray(e[r])||L(e[r])&&!dt(e[r])?(s[r]=Array.isArray(e[r])?[]:{},_e(e[r],s[r])):I(e[r])||(s[r]=!0);return s}function ft(e,s,i){const r=Array.isArray(e);if(L(e)||r)for(const l in e)Array.isArray(e[l])||L(e[l])&&!dt(e[l])?F(s)||Ee(i[l])?i[l]=Array.isArray(e[l])?_e(e[l],[]):{..._e(e[l])}:ft(e[l],I(s)?{}:s[l],i[l]):i[l]=!se(e[l],s[l]);return i}var Oe=(e,s)=>ft(e,s,_e(s)),mt=(e,{valueAsNumber:s,valueAsDate:i,setValueAs:r})=>F(e)?e:s?e===""?NaN:e&&+e:i&&j(e)?new Date(e):r?r(e):e;function Le(e){const s=e.ref;if(!(e.refs?e.refs.every(i=>i.disabled):s.disabled))return Ie(s)?s.files:Ne(s)?ut(e.refs).value:ct(s)?[...s.selectedOptions].map(({value:i})=>i):ge(s)?ot(e.refs).value:mt(F(s.value)?e.ref.value:s.value,e)}var qt=(e,s,i,r)=>{const l={};for(const o of e){const c=m(s,o);c&&V(l,o,c._f)}return{criteriaMode:i,names:[...e],fields:l,shouldUseNativeValidation:r}},ye=e=>F(e)?e:ke(e)?e.source:L(e)?ke(e.value)?e.value.source:e.value:e,Ut=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function lt(e,s,i){const r=m(e,i);if(r||Re(i))return{error:r,name:i};const l=i.split(".");for(;l.length;){const o=l.join("."),c=m(s,o),b=m(e,o);if(c&&!Array.isArray(c)&&i!==o)return{name:i};if(b&&b.type)return{name:o,error:b};l.pop()}return{name:i}}var Bt=(e,s,i,r,l)=>l.isOnAll?!1:!i&&l.isOnTouch?!(s||e):(i?r.isOnBlur:l.isOnBlur)?!e:(i?r.isOnChange:l.isOnChange)?e:!0,Pt=(e,s)=>!ve(m(e,s)).length&&C(e,s);const Ht={mode:G.onSubmit,reValidateMode:G.onChange,shouldFocusError:!0};function $t(e={},s){let i={...Ht,...e},r={submitCount:0,isDirty:!1,isLoading:ee(i.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},errors:{}},l={},o=L(i.defaultValues)||L(i.values)?X(i.defaultValues||i.values)||{}:{},c=i.shouldUnregister?{}:X(o),b={action:!1,mount:!1,watch:!1},k={mount:new Set,unMount:new Set,array:new Set,watch:new Set},M,H=0;const D={isDirty:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},p={values:Te(),array:Te(),state:Te()},$=e.resetOptions&&e.resetOptions.keepDirtyValues,N=Ye(i.mode),ue=Ye(i.reValidateMode),le=i.criteriaMode===G.all,ce=t=>n=>{clearTimeout(H),H=setTimeout(t,n)},v=async t=>{if(D.isValid||t){const n=i.resolver?P((await q()).errors):await W(l,!0);n!==r.isValid&&p.state.next({isValid:n})}},U=t=>D.isValidating&&p.state.next({isValidating:t}),B=(t,n=[],a,y,d=!0,u=!0)=>{if(y&&a){if(b.action=!0,u&&Array.isArray(m(l,t))){const g=a(m(l,t),y.argA,y.argB);d&&V(l,t,g)}if(u&&Array.isArray(m(r.errors,t))){const g=a(m(r.errors,t),y.argA,y.argB);d&&V(r.errors,t,g),Pt(r.errors,t)}if(D.touchedFields&&u&&Array.isArray(m(r.touchedFields,t))){const g=a(m(r.touchedFields,t),y.argA,y.argB);d&&V(r.touchedFields,t,g)}D.dirtyFields&&(r.dirtyFields=Oe(o,c)),p.state.next({name:t,isDirty:x(t,n),dirtyFields:r.dirtyFields,errors:r.errors,isValid:r.isValid})}else V(c,t,n)},S=(t,n)=>{V(r.errors,t,n),p.state.next({errors:r.errors})},te=(t,n,a,y)=>{const d=m(l,t);if(d){const u=m(c,t,F(a)?m(o,t):a);F(u)||y&&y.defaultChecked||n?V(c,t,n?u:Le(d._f)):T(t,u),b.mount&&v()}},Y=(t,n,a,y,d)=>{let u=!1,g=!1;const A={name:t};if(!a||y){D.isDirty&&(g=r.isDirty,r.isDirty=A.isDirty=x(),u=g!==A.isDirty);const w=se(m(o,t),n);g=m(r.dirtyFields,t),w?C(r.dirtyFields,t):V(r.dirtyFields,t,!0),A.dirtyFields=r.dirtyFields,u=u||D.dirtyFields&&g!==!w}if(a){const w=m(r.touchedFields,t);w||(V(r.touchedFields,t,a),A.touchedFields=r.touchedFields,u=u||D.touchedFields&&w!==a)}return u&&d&&p.state.next(A),u?A:{}},de=(t,n,a,y)=>{const d=m(r.errors,t),u=D.isValid&&ie(n)&&r.isValid!==n;if(e.delayError&&a?(M=ce(()=>S(t,a)),M(e.delayError)):(clearTimeout(H),M=null,a?V(r.errors,t,a):C(r.errors,t)),(a?!se(d,a):d)||!P(y)||u){const g={...y,...u&&ie(n)?{isValid:n}:{},errors:r.errors,name:t};r={...r,...g},p.state.next(g)}U(!1)},q=async t=>i.resolver(c,i.context,qt(t||k.mount,l,i.criteriaMode,i.shouldUseNativeValidation)),K=async t=>{const{errors:n}=await q(t);if(t)for(const a of t){const y=m(n,a);y?V(r.errors,a,y):C(r.errors,a)}else r.errors=n;return n},W=async(t,n,a={valid:!0})=>{for(const y in t){const d=t[y];if(d){const{_f:u,...g}=d;if(u){const A=k.array.has(u.name),w=await st(d,c,le,i.shouldUseNativeValidation&&!n,A);if(w[u.name]&&(a.valid=!1,n))break;!n&&(m(w,u.name)?A?Mt(r.errors,w,u.name):V(r.errors,u.name,w[u.name]):C(r.errors,u.name))}g&&await W(g,n,a)}}return a.valid},E=()=>{for(const t of k.unMount){const n=m(l,t);n&&(n._f.refs?n._f.refs.every(a=>!Fe(a)):!Fe(n._f.ref))&&Ve(t)}k.unMount=new Set},x=(t,n)=>(t&&n&&V(c,t,n),!se(qe(),o)),h=(t,n,a)=>Lt(t,k,{...b.mount?c:F(n)?o:j(t)?{[t]:n}:n},a,n),_=t=>ve(m(b.mount?c:o,t,e.shouldUnregister?m(o,t,[]):[])),T=(t,n,a={})=>{const y=m(l,t);let d=n;if(y){const u=y._f;u&&(!u.disabled&&V(c,t,mt(n,u)),d=pe(u.ref)&&I(n)?"":n,ct(u.ref)?[...u.ref.options].forEach(g=>g.selected=d.includes(g.value)):u.refs?ge(u.ref)?u.refs.length>1?u.refs.forEach(g=>(!g.defaultChecked||!g.disabled)&&(g.checked=Array.isArray(d)?!!d.find(A=>A===g.value):d===g.value)):u.refs[0]&&(u.refs[0].checked=!!d):u.refs.forEach(g=>g.checked=g.value===d):Ie(u.ref)?u.ref.value="":(u.ref.value=d,u.ref.type||p.values.next({name:t,values:{...c}})))}(a.shouldDirty||a.shouldTouch)&&Y(t,d,a.shouldTouch,a.shouldDirty,!0),a.shouldValidate&&fe(t)},R=(t,n,a)=>{for(const y in n){const d=n[y],u=`${t}.${y}`,g=m(l,u);(k.array.has(t)||!Ee(d)||g&&!g._f)&&!oe(d)?R(u,d,a):T(u,d,a)}},z=(t,n,a={})=>{const y=m(l,t),d=k.array.has(t),u=X(n);V(c,t,u),d?(p.array.next({name:t,values:{...c}}),(D.isDirty||D.dirtyFields)&&a.shouldDirty&&p.state.next({name:t,dirtyFields:Oe(o,c),isDirty:x(t,u)})):y&&!y._f&&!I(u)?R(t,u,a):T(t,u,a),Ze(t,k)&&p.state.next({...r}),p.values.next({name:t,values:{...c}}),!b.mount&&s()},J=async t=>{const n=t.target;let a=n.name,y=!0;const d=m(l,a),u=()=>n.type?Le(d._f):Dt(t);if(d){let g,A;const w=u(),ne=t.type===Xe.BLUR||t.type===Xe.FOCUS_OUT,ht=!Ut(d._f)&&!i.resolver&&!m(r.errors,a)&&!d._f.deps||Bt(ne,m(r.touchedFields,a),r.isSubmitted,ue,N),Ae=Ze(a,k,ne);V(c,a,w),ne?(d._f.onBlur&&d._f.onBlur(t),M&&M(0)):d._f.onChange&&d._f.onChange(t);const Se=Y(a,w,ne,!1),bt=!P(Se)||Ae;if(!ne&&p.values.next({name:a,type:t.type,values:{...c}}),ht)return D.isValid&&v(),bt&&p.state.next({name:a,...Ae?{}:Se});if(!ne&&Ae&&p.state.next({...r}),U(!0),i.resolver){const{errors:Ke}=await q([a]),xt=lt(r.errors,l,a),je=lt(Ke,l,xt.name||a);g=je.error,a=je.name,A=P(Ke)}else g=(await st(d,c,le,i.shouldUseNativeValidation))[a],y=Number.isNaN(w)||w===m(c,a,w),y&&(g?A=!1:D.isValid&&(A=await W(l,!0)));y&&(d._f.deps&&fe(d._f.deps),de(a,A,g,Se))}},fe=async(t,n={})=>{let a,y;const d=we(t);if(U(!0),i.resolver){const u=await K(F(t)?t:d);a=P(u),y=t?!d.some(g=>m(u,g)):a}else t?(y=(await Promise.all(d.map(async u=>{const g=m(l,u);return await W(g&&g._f?{[u]:g}:g)}))).every(Boolean),!(!y&&!r.isValid)&&v()):y=a=await W(l);return p.state.next({...!j(t)||D.isValid&&a!==r.isValid?{}:{name:t},...i.resolver||!t?{isValid:a}:{},errors:r.errors,isValidating:!1}),n.shouldFocus&&!y&&Ce(l,u=>u&&m(r.errors,u),t?d:k.mount),y},qe=t=>{const n={...o,...b.mount?c:{}};return F(t)?n:j(t)?m(n,t):t.map(a=>m(n,a))},Ue=(t,n)=>({invalid:!!m((n||r).errors,t),isDirty:!!m((n||r).dirtyFields,t),isTouched:!!m((n||r).touchedFields,t),error:m((n||r).errors,t)}),yt=t=>{t&&we(t).forEach(n=>C(r.errors,n)),p.state.next({errors:t?r.errors:{}})},Be=(t,n,a)=>{const y=(m(l,t,{_f:{}})._f||{}).ref;V(r.errors,t,{...n,ref:y}),p.state.next({name:t,errors:r.errors,isValid:!1}),a&&a.shouldFocus&&y&&y.focus&&y.focus()},gt=(t,n)=>ee(t)?p.values.subscribe({next:a=>t(h(void 0,n),a)}):h(t,n,!0),Ve=(t,n={})=>{for(const a of t?we(t):k.mount)k.mount.delete(a),k.array.delete(a),n.keepValue||(C(l,a),C(c,a)),!n.keepError&&C(r.errors,a),!n.keepDirty&&C(r.dirtyFields,a),!n.keepTouched&&C(r.touchedFields,a),!i.shouldUnregister&&!n.keepDefaultValue&&C(o,a);p.values.next({values:{...c}}),p.state.next({...r,...n.keepDirty?{isDirty:x()}:{}}),!n.keepIsValid&&v()},Pe=({disabled:t,name:n,field:a,fields:y})=>{if(ie(t)){const d=t?void 0:m(c,n,Le(a?a._f:m(y,n)._f));V(c,n,d),Y(n,d,!1,!1,!0)}},De=(t,n={})=>{let a=m(l,t);const y=ie(n.disabled);return V(l,t,{...a||{},_f:{...a&&a._f?a._f:{ref:{name:t}},name:t,mount:!0,...n}}),k.mount.add(t),a?Pe({field:a,disabled:n.disabled,name:t}):te(t,!0,n.value),{...y?{disabled:n.disabled}:{},...i.progressive?{required:!!n.required,min:ye(n.min),max:ye(n.max),minLength:ye(n.minLength),maxLength:ye(n.maxLength),pattern:ye(n.pattern)}:{},name:t,onChange:J,onBlur:J,ref:d=>{if(d){De(t,n),a=m(l,t);const u=F(d.value)&&d.querySelectorAll&&d.querySelectorAll("input,select,textarea")[0]||d,g=Nt(u),A=a._f.refs||[];if(g?A.find(w=>w===u):u===a._f.ref)return;V(l,t,{_f:{...a._f,...g?{refs:[...A.filter(Fe),u,...Array.isArray(m(o,t))?[{}]:[]],ref:{type:u.type,name:t}}:{ref:u}}}),te(t,!1,void 0,u)}else a=m(l,t,{}),a._f&&(a._f.mount=!1),(i.shouldUnregister||n.shouldUnregister)&&!(St(k.array,t)&&b.action)&&k.unMount.add(t)}}},He=()=>i.shouldFocusError&&Ce(l,t=>t&&m(r.errors,t),k.mount),$e=(t,n)=>async a=>{a&&(a.preventDefault&&a.preventDefault(),a.persist&&a.persist());let y=X(c);if(p.state.next({isSubmitting:!0}),i.resolver){const{errors:d,values:u}=await q();r.errors=d,y=u}else await W(l);C(r.errors,"root"),P(r.errors)?(p.state.next({errors:{}}),await t(y,a)):(n&&await n({...r.errors},a),He(),setTimeout(He)),p.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:P(r.errors),submitCount:r.submitCount+1,errors:r.errors})},vt=(t,n={})=>{m(l,t)&&(F(n.defaultValue)?z(t,m(o,t)):(z(t,n.defaultValue),V(o,t,n.defaultValue)),n.keepTouched||C(r.touchedFields,t),n.keepDirty||(C(r.dirtyFields,t),r.isDirty=n.defaultValue?x(t,m(o,t)):x()),n.keepError||(C(r.errors,t),D.isValid&&v()),p.state.next({...r}))},We=(t,n={})=>{const a=t?X(t):o,y=X(a),d=t&&!P(t)?y:o;if(n.keepDefaultValues||(o=a),!n.keepValues){if(n.keepDirtyValues||$)for(const u of k.mount)m(r.dirtyFields,u)?V(d,u,m(c,u)):z(u,m(d,u));else{if(Me&&F(t))for(const u of k.mount){const g=m(l,u);if(g&&g._f){const A=Array.isArray(g._f.refs)?g._f.refs[0]:g._f.ref;if(pe(A)){const w=A.closest("form");if(w){w.reset();break}}}}l={}}c=e.shouldUnregister?n.keepDefaultValues?X(o):{}:X(d),p.array.next({values:{...d}}),p.values.next({values:{...d}})}k={mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},!b.mount&&s(),b.mount=!D.isValid||!!n.keepIsValid,b.watch=!!e.shouldUnregister,p.state.next({submitCount:n.keepSubmitCount?r.submitCount:0,isDirty:n.keepDirty?r.isDirty:!!(n.keepDefaultValues&&!se(t,o)),isSubmitted:n.keepIsSubmitted?r.isSubmitted:!1,dirtyFields:n.keepDirtyValues?r.dirtyFields:n.keepDefaultValues&&t?Oe(o,t):{},touchedFields:n.keepTouched?r.touchedFields:{},errors:n.keepErrors?r.errors:{},isSubmitting:!1,isSubmitSuccessful:!1})},Ge=(t,n)=>We(ee(t)?t(c):t,n);return{control:{register:De,unregister:Ve,getFieldState:Ue,handleSubmit:$e,setError:Be,_executeSchema:q,_getWatch:h,_getDirty:x,_updateValid:v,_removeUnmounted:E,_updateFieldArray:B,_updateDisabledField:Pe,_getFieldArray:_,_reset:We,_resetDefaultValues:()=>ee(i.defaultValues)&&i.defaultValues().then(t=>{Ge(t,i.resetOptions),p.state.next({isLoading:!1})}),_updateFormState:t=>{r={...r,...t}},_subjects:p,_proxyFormState:D,get _fields(){return l},get _formValues(){return c},get _state(){return b},set _state(t){b=t},get _defaultValues(){return o},get _names(){return k},set _names(t){k=t},get _formState(){return r},set _formState(t){r=t},get _options(){return i},set _options(t){i={...i,...t}}},trigger:fe,register:De,handleSubmit:$e,watch:gt,setValue:z,getValues:qe,reset:Ge,resetField:vt,clearErrors:yt,unregister:Ve,setError:Be,setFocus:(t,n={})=>{const a=m(l,t),y=a&&a._f;if(y){const d=y.refs?y.refs[0]:y.ref;d.focus&&(d.focus(),n.shouldSelect&&d.select())}},getFieldState:Ue}}function Wt(e={}){const s=f.useRef(),i=f.useRef(),[r,l]=f.useState({isDirty:!1,isValidating:!1,isLoading:ee(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},errors:{},defaultValues:ee(e.defaultValues)?void 0:e.defaultValues});s.current||(s.current={...$t(e,()=>l(c=>({...c}))),formState:r});const o=s.current.control;return o._options=e,Ot({subject:o._subjects.state,next:c=>{Ft(c,o._proxyFormState,o._updateFormState,!0)&&l({...o._formState})}}),f.useEffect(()=>{e.values&&!se(e.values,i.current)?(o._reset(e.values,o._options.resetOptions),i.current=e.values):o._resetDefaultValues()},[e.values,o]),f.useEffect(()=>{o._state.mount||(o._updateValid(),o._state.mount=!0),o._state.watch&&(o._state.watch=!1,o._subjects.state.next({...o._formState})),o._removeUnmounted()}),s.current.formState=Tt(r,o),s.current}var Gt=(e=>(e.formgroup="formgroup",e.checkbox="checkbox",e.radiobutton="radiobutton",e.textarea="textarea",e.input="input",e.select="select",e.date="date",e))(Gt||{});const Kt=e=>{const{exampleType:s="formgroup"}=e,{register:i,handleSubmit:r,formState:{errors:l}}=Wt(),o=new Date;o.setHours(0),o.setMinutes(0),o.setSeconds(0);const c=new Date;c.setDate(o.getDate()-5),c.setHours(6),c.setMinutes(10),c.setSeconds(0);const b=new Date;b.setDate(o.getDate()+5),b.setHours(22),b.setMinutes(0),b.setSeconds(0);const k="field1",M="field2",H="field3",D="field4",p="field5",$="field6",N="field7",ue="field8",le="field9",ce=l.field1||l.field2||l.field3||l.field4||l.field5||l.field6||l.field7||l.field8||l.field9,v="Du må velge et alternativ",U="Du må velge to alternativ",B="Det kan ikke legges inn mer enn 40 tegn",S="Du må skrive noe her",te='Du må velge "Option 2"',Y=`Du må velge dato mellom ${c.toLocaleDateString("nb")} og ${b.toLocaleDateString("nb")}`,de=`Du må skrive inn tidspunkt mellom ${c.toLocaleTimeString("nb",{hour:"2-digit",minute:"2-digit"})} og ${b.toLocaleTimeString("nb",{hour:"2-digit",minute:"2-digit"})}`,q=h=>h.length>=2||U,K=h=>h.toString()==="Option 2"||te,W=(h,_,T)=>{const R=new Date(h);return!!h&&R.getTime()>=_.getTime()&&R.getTime()<=T.getTime()||Y},E=(h,_)=>{const T=new Date;T.setHours(h),T.setMinutes(_),T.setSeconds(0);const R=c.toLocaleTimeString("nb"),z=b.toLocaleTimeString("nb"),J=T.toLocaleTimeString("nb");return console.log("value",J),!!T&&J>=R&&J<=z||de},x=()=>{if(s==="formgroup"){const h=[f.createElement(re,{key:0,inputId:"checkbox1",label:f.createElement(O,{labelTexts:[{text:"Checkbox 1"}]}),...i(k,{required:v})}),f.createElement(re,{key:1,inputId:"checkbox2",label:f.createElement(O,{labelTexts:[{text:"Checkbox 2"}]}),...i(k,{required:v})}),f.createElement(re,{key:2,inputId:"checkbox3",label:f.createElement(O,{labelTexts:[{text:"Checkbox 3"}]}),...i(k,{required:v})})];return[f.createElement(Z,{key:0,title:"Gruppe tittel",legend:"Velg minst en",error:l.field1?l.field1.message:void 0,variant:e.variant},f.createElement(Et,{maxColumns:_t.two},h.map(_=>_))),f.createElement(Z,{key:1,legend:"Velg minst to",error:l.field2?l.field2.message:void 0,variant:e.variant},f.createElement(re,{inputId:"checkbox4",label:f.createElement(O,{labelTexts:[{text:"Checkbox 4"}]}),...i(M,{validate:q})}),f.createElement(re,{inputId:"checkbox5",label:f.createElement(O,{labelTexts:[{text:"Checkbox 5"}]}),...i(M,{validate:q})}),f.createElement(re,{inputId:"checkbox6",label:f.createElement(O,{labelTexts:[{text:"Checkbox 6"}]}),...i(M,{validate:q})})),f.createElement(Z,{key:2,legend:"Velg en",error:l.field3?l.field3.message:void 0,variant:e.variant},f.createElement(he,{inputId:"radiobutton1",label:f.createElement(O,{labelTexts:[{text:"Radiobutton 1"}]}),...i(H,{required:v})}),f.createElement(he,{inputId:"radiobutton2",label:f.createElement(O,{labelTexts:[{text:"Radiobutton 2"}]}),...i(H,{required:v})}),f.createElement(he,{inputId:"radiobutton3",label:f.createElement(O,{labelTexts:[{text:"Radiobutton 3"}]}),...i(H,{required:v})})),f.createElement(Z,{key:3,error:l.field4?l.field4.message:void 0},f.createElement(Qe,{defaultValue:`Dette er en test
|
|
1
|
+
import m from"react";import{isTest as xt}from"../../utils/environment.js";import{B as pt}from"../../Button.js";import{C as te}from"../../Checkbox.js";import{F as ae}from"../../FormGroup.js";import{F as kt,a as Et}from"../../FormLayout.js";import Ke from"../Icons/Hospital.js";import{I as je}from"../../Input.js";import{L as T}from"../../Label.js";import{R as ve}from"../../RadioButton.js";import{S as ze}from"../../Select.js";import{T as Je}from"../../Textarea.js";import{V as _t}from"../../Validation.js";import"classnames";import"../Icons/Icon.js";import"../../constants.js";import"../../hooks/useUuid.js";import"../../uuid.js";import"../../hooks/useBreakpoint.js";import"../../theme/grid.js";import"../../hooks/useHover.js";import"../../hooks/usePseudoClasses.js";import"../../hooks/useIcons.js";import"../../hooks/useSize.js";import"../../utils/debounce.js";import"../../theme/currys/color.js";import"../../theme/index.js";import"../../theme/palette.js";import"../../theme/spacers.js";import"../Icons/ArrowRight.js";import"../Button/styles.module.scss";import"../../utils/refs.js";import"../Icons/Check.js";import"../Checkbox/styles.module.scss";import"../../utils/component.js";import"../../ErrorWrapper.js";import"../ErrorWrapper/styles.module.scss";import"../../Title.js";import"../Title/styles.module.scss";import"../FormGroup/styles.module.scss";import"../FormLayout/styles.module.scss";import"../../MaxCharacters.js";import"../MaxCharacters/styles.module.scss";import"../Input/styles.module.scss";import"../../Spacer.js";import"../Spacer/styles.module.scss";import"../Label/styles.module.scss";import"../../StatusDot.js";import"../Icons/Attachment.js";import"../Icons/Group.js";import"../Icons/NoAccess.js";import"../Icons/Undo.js";import"../StatusDot/styles.module.scss";import"../RadioButton/styles.module.scss";import"../Icons/ChevronDown.js";import"../Select/styles.module.scss";import"../Textarea/styles.module.scss";import"../Validation/styles.module.scss";var me=e=>e.type==="checkbox",ue=e=>e instanceof Date,L=e=>e==null;const nt=e=>typeof e=="object";var F=e=>!L(e)&&!Array.isArray(e)&&nt(e)&&!ue(e),Vt=e=>F(e)&&e.target?me(e.target)?e.target.checked:e.target.value:e,At=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,Dt=(e,i)=>e.has(At(i)),St=e=>{const i=e.constructor&&e.constructor.prototype;return F(i)&&i.hasOwnProperty("isPrototypeOf")},Ce=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function Q(e){let i;const s=Array.isArray(e);if(e instanceof Date)i=new Date(e);else if(e instanceof Set)i=new Set(e);else if(!(Ce&&(e instanceof Blob||e instanceof FileList))&&(s||F(e)))if(i=s?[]:{},!s&&!St(e))i=e;else for(const r in e)e.hasOwnProperty(r)&&(i[r]=Q(e[r]));else return e;return i}var ge=e=>Array.isArray(e)?e.filter(Boolean):[],w=e=>e===void 0,d=(e,i,s)=>{if(!i||!F(e))return s;const r=ge(i.split(/[,[\].]+?/)).reduce((l,o)=>L(l)?l:l[o],e);return w(r)||r===e?w(e[i])?s:e[i]:r},re=e=>typeof e=="boolean";const Qe={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},W={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},J={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"};m.createContext(null);var wt=(e,i,s,r=!0)=>{const l={defaultValues:i._defaultValues};for(const o in e)Object.defineProperty(l,o,{get:()=>{const f=o;return i._proxyFormState[f]!==W.all&&(i._proxyFormState[f]=!r||W.all),s&&(s[f]=!0),e[f]}});return l},P=e=>F(e)&&!Object.keys(e).length,Ft=(e,i,s,r)=>{s(e);const{name:l,...o}=e;return P(o)||Object.keys(o).length>=Object.keys(i).length||Object.keys(o).find(f=>i[f]===(!r||W.all))},De=e=>Array.isArray(e)?e:[e];function Tt(e){const i=m.useRef(e);i.current=e,m.useEffect(()=>{const s=!e.disabled&&i.current.subject&&i.current.subject.subscribe({next:i.current.next});return()=>{s&&s.unsubscribe()}},[e.disabled])}var j=e=>typeof e=="string",Ot=(e,i,s,r,l)=>j(e)?(r&&i.watch.add(e),d(s,e,l)):Array.isArray(e)?e.map(o=>(r&&i.watch.add(o),d(s,o))):(r&&(i.watchAll=!0),s),Le=e=>/^\w*$/.test(e),lt=e=>ge(e.replace(/["|']|\]/g,"").split(/\.|\[/));function E(e,i,s){let r=-1;const l=Le(i)?[i]:lt(i),o=l.length,f=o-1;for(;++r<o;){const x=l[r];let p=s;if(r!==f){const C=e[x];p=F(C)||Array.isArray(C)?C:isNaN(+l[r+1])?{}:[]}e[x]=p,e=e[x]}return e}var Ct=(e,i,s,r,l)=>i?{...s[e],types:{...s[e]&&s[e].types?s[e].types:{},[r]:l||!0}}:{};const Oe=(e,i,s)=>{for(const r of s||Object.keys(e)){const l=d(e,r);if(l){const{_f:o,...f}=l;if(o&&i(o.name)){if(o.ref.focus){o.ref.focus();break}else if(o.refs&&o.refs[0].focus){o.refs[0].focus();break}}else F(f)&&Oe(f,i)}}};var Xe=e=>({isOnSubmit:!e||e===W.onSubmit,isOnBlur:e===W.onBlur,isOnChange:e===W.onChange,isOnAll:e===W.all,isOnTouch:e===W.onTouched}),Ye=(e,i,s)=>!s&&(i.watchAll||i.watch.has(e)||[...i.watch].some(r=>e.startsWith(r)&&/^\.\w+/.test(e.slice(r.length)))),Lt=(e,i,s)=>{const r=ge(d(e,s));return E(r,"root",i[s]),E(e,s,r),e},Re=e=>e.type==="file",X=e=>typeof e=="function",be=e=>{if(!Ce)return!1;const i=e?e.ownerDocument:0;return e instanceof(i&&i.defaultView?i.defaultView.HTMLElement:HTMLElement)},he=e=>j(e),Ie=e=>e.type==="radio",xe=e=>e instanceof RegExp;const Ze={value:!1,isValid:!1},et={value:!0,isValid:!0};var at=e=>{if(Array.isArray(e)){if(e.length>1){const i=e.filter(s=>s&&s.checked&&!s.disabled).map(s=>s.value);return{value:i,isValid:!!i.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!w(e[0].attributes.value)?w(e[0].value)||e[0].value===""?et:{value:e[0].value,isValid:!0}:et:Ze}return Ze};const tt={isValid:!1,value:null};var ot=e=>Array.isArray(e)?e.reduce((i,s)=>s&&s.checked&&!s.disabled?{isValid:!0,value:s.value}:i,tt):tt;function rt(e,i,s="validate"){if(he(e)||Array.isArray(e)&&e.every(he)||re(e)&&!e)return{type:s,message:he(e)?e:"",ref:i}}var oe=e=>F(e)&&!xe(e)?e:{value:e,message:""},st=async(e,i,s,r,l)=>{const{ref:o,refs:f,required:x,maxLength:p,minLength:C,min:H,max:_,pattern:h,validate:$,name:R,valueAsNumber:N,mount:ie,disabled:ne}=e._f,v=d(i,R);if(!ie||ne)return{};const U=f?f[0]:o,B=k=>{r&&U.reportValidity&&(U.setCustomValidity(re(k)?"":k||""),U.reportValidity())},A={},Y=Ie(o),I=me(o),ce=Y||I,G=(N||Re(o))&&w(o.value)&&w(v)||be(o)&&o.value===""||v===""||Array.isArray(v)&&!v.length,Z=Ct.bind(null,R,s,A),z=(k,b,D,M=J.maxLength,q=J.minLength)=>{const K=k?b:D;A[R]={type:k?M:q,message:K,ref:o,...Z(k?M:q,K)}};if(l?!Array.isArray(v)||!v.length:x&&(!ce&&(G||L(v))||re(v)&&!v||I&&!at(f).isValid||Y&&!ot(f).isValid)){const{value:k,message:b}=he(x)?{value:!!x,message:x}:oe(x);if(k&&(A[R]={type:J.required,message:b,ref:U,...Z(J.required,b)},!s))return B(b),A}if(!G&&(!L(H)||!L(_))){let k,b;const D=oe(_),M=oe(H);if(!L(v)&&!isNaN(v)){const q=o.valueAsNumber||v&&+v;L(D.value)||(k=q>D.value),L(M.value)||(b=q<M.value)}else{const q=o.valueAsDate||new Date(v),K=de=>new Date(new Date().toDateString()+" "+de),ee=o.type=="time",fe=o.type=="week";j(D.value)&&v&&(k=ee?K(v)>K(D.value):fe?v>D.value:q>new Date(D.value)),j(M.value)&&v&&(b=ee?K(v)<K(M.value):fe?v<M.value:q<new Date(M.value))}if((k||b)&&(z(!!k,D.message,M.message,J.max,J.min),!s))return B(A[R].message),A}if((p||C)&&!G&&(j(v)||l&&Array.isArray(v))){const k=oe(p),b=oe(C),D=!L(k.value)&&v.length>+k.value,M=!L(b.value)&&v.length<+b.value;if((D||M)&&(z(D,k.message,b.message),!s))return B(A[R].message),A}if(h&&!G&&j(v)){const{value:k,message:b}=oe(h);if(xe(k)&&!v.match(k)&&(A[R]={type:J.pattern,message:b,ref:o,...Z(J.pattern,b)},!s))return B(b),A}if($){if(X($)){const k=await $(v,i),b=rt(k,U);if(b&&(A[R]={...b,...Z(J.validate,b.message)},!s))return B(b.message),A}else if(F($)){let k={};for(const b in $){if(!P(k)&&!s)break;const D=rt(await $[b](v,i),U,b);D&&(k={...D,...Z(b,D.message)},B(D.message),s&&(A[R]=k))}if(!P(k)&&(A[R]={ref:U,...k},!s))return A}}return B(!0),A};function Rt(e,i){const s=i.slice(0,-1).length;let r=0;for(;r<s;)e=w(e)?r++:e[i[r++]];return e}function It(e){for(const i in e)if(e.hasOwnProperty(i)&&!w(e[i]))return!1;return!0}function O(e,i){const s=Array.isArray(i)?i:Le(i)?[i]:lt(i),r=s.length===1?e:Rt(e,s),l=s.length-1,o=s[l];return r&&delete r[o],l!==0&&(F(r)&&P(r)||Array.isArray(r)&&It(r))&&O(e,s.slice(0,-1)),e}function Se(){let e=[];return{get observers(){return e},next:l=>{for(const o of e)o.next&&o.next(l)},subscribe:l=>(e.push(l),{unsubscribe:()=>{e=e.filter(o=>o!==l)}}),unsubscribe:()=>{e=[]}}}var pe=e=>L(e)||!nt(e);function se(e,i){if(pe(e)||pe(i))return e===i;if(ue(e)&&ue(i))return e.getTime()===i.getTime();const s=Object.keys(e),r=Object.keys(i);if(s.length!==r.length)return!1;for(const l of s){const o=e[l];if(!r.includes(l))return!1;if(l!=="ref"){const f=i[l];if(ue(o)&&ue(f)||F(o)&&F(f)||Array.isArray(o)&&Array.isArray(f)?!se(o,f):o!==f)return!1}}return!0}var ut=e=>e.type==="select-multiple",Mt=e=>Ie(e)||me(e),we=e=>be(e)&&e.isConnected,ct=e=>{for(const i in e)if(X(e[i]))return!0;return!1};function ke(e,i={}){const s=Array.isArray(e);if(F(e)||s)for(const r in e)Array.isArray(e[r])||F(e[r])&&!ct(e[r])?(i[r]=Array.isArray(e[r])?[]:{},ke(e[r],i[r])):L(e[r])||(i[r]=!0);return i}function ft(e,i,s){const r=Array.isArray(e);if(F(e)||r)for(const l in e)Array.isArray(e[l])||F(e[l])&&!ct(e[l])?w(i)||pe(s[l])?s[l]=Array.isArray(e[l])?ke(e[l],[]):{...ke(e[l])}:ft(e[l],L(i)?{}:i[l],s[l]):s[l]=!se(e[l],i[l]);return s}var Fe=(e,i)=>ft(e,i,ke(i)),dt=(e,{valueAsNumber:i,valueAsDate:s,setValueAs:r})=>w(e)?e:i?e===""?NaN:e&&+e:s&&j(e)?new Date(e):r?r(e):e;function Te(e){const i=e.ref;if(!(e.refs?e.refs.every(s=>s.disabled):i.disabled))return Re(i)?i.files:Ie(i)?ot(e.refs).value:ut(i)?[...i.selectedOptions].map(({value:s})=>s):me(i)?at(e.refs).value:dt(w(i.value)?e.ref.value:i.value,e)}var Ut=(e,i,s,r)=>{const l={};for(const o of e){const f=d(i,o);f&&E(l,o,f._f)}return{criteriaMode:s,names:[...e],fields:l,shouldUseNativeValidation:r}},ye=e=>w(e)?e:xe(e)?e.source:F(e)?xe(e.value)?e.value.source:e.value:e,Bt=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function it(e,i,s){const r=d(e,s);if(r||Le(s))return{error:r,name:s};const l=s.split(".");for(;l.length;){const o=l.join("."),f=d(i,o),x=d(e,o);if(f&&!Array.isArray(f)&&s!==o)return{name:s};if(x&&x.type)return{name:o,error:x};l.pop()}return{name:s}}var Nt=(e,i,s,r,l)=>l.isOnAll?!1:!s&&l.isOnTouch?!(i||e):(s?r.isOnBlur:l.isOnBlur)?!e:(s?r.isOnChange:l.isOnChange)?e:!0,qt=(e,i)=>!ge(d(e,i)).length&&O(e,i);const Pt={mode:W.onSubmit,reValidateMode:W.onChange,shouldFocusError:!0};function Ht(e={},i){let s={...Pt,...e},r={submitCount:0,isDirty:!1,isLoading:X(s.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},errors:{}},l={},o=F(s.defaultValues)||F(s.values)?Q(s.defaultValues||s.values)||{}:{},f=s.shouldUnregister?{}:Q(o),x={action:!1,mount:!1,watch:!1},p={mount:new Set,unMount:new Set,array:new Set,watch:new Set},C,H=0;const _={isDirty:!1,dirtyFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},h={values:Se(),array:Se(),state:Se()},$=e.resetOptions&&e.resetOptions.keepDirtyValues,R=Xe(s.mode),N=Xe(s.reValidateMode),ie=s.criteriaMode===W.all,ne=t=>n=>{clearTimeout(H),H=setTimeout(t,n)},v=async t=>{if(_.isValid||t){const n=s.resolver?P((await G()).errors):await z(l,!0);n!==r.isValid&&h.state.next({isValid:n})}},U=t=>_.isValidating&&h.state.next({isValidating:t}),B=(t,n=[],a,y,c=!0,u=!0)=>{if(y&&a){if(x.action=!0,u&&Array.isArray(d(l,t))){const g=a(d(l,t),y.argA,y.argB);c&&E(l,t,g)}if(u&&Array.isArray(d(r.errors,t))){const g=a(d(r.errors,t),y.argA,y.argB);c&&E(r.errors,t,g),qt(r.errors,t)}if(_.touchedFields&&u&&Array.isArray(d(r.touchedFields,t))){const g=a(d(r.touchedFields,t),y.argA,y.argB);c&&E(r.touchedFields,t,g)}_.dirtyFields&&(r.dirtyFields=Fe(o,f)),h.state.next({name:t,isDirty:b(t,n),dirtyFields:r.dirtyFields,errors:r.errors,isValid:r.isValid})}else E(f,t,n)},A=(t,n)=>{E(r.errors,t,n),h.state.next({errors:r.errors})},Y=(t,n,a,y)=>{const c=d(l,t);if(c){const u=d(f,t,w(a)?d(o,t):a);w(u)||y&&y.defaultChecked||n?E(f,t,n?u:Te(c._f)):q(t,u),x.mount&&v()}},I=(t,n,a,y,c)=>{let u=!1,g=!1;const V={name:t};if(!a||y){_.isDirty&&(g=r.isDirty,r.isDirty=V.isDirty=b(),u=g!==V.isDirty);const S=se(d(o,t),n);g=d(r.dirtyFields,t),S?O(r.dirtyFields,t):E(r.dirtyFields,t,!0),V.dirtyFields=r.dirtyFields,u=u||_.dirtyFields&&g!==!S}if(a){const S=d(r.touchedFields,t);S||(E(r.touchedFields,t,a),V.touchedFields=r.touchedFields,u=u||_.touchedFields&&S!==a)}return u&&c&&h.state.next(V),u?V:{}},ce=(t,n,a,y)=>{const c=d(r.errors,t),u=_.isValid&&re(n)&&r.isValid!==n;if(e.delayError&&a?(C=ne(()=>A(t,a)),C(e.delayError)):(clearTimeout(H),C=null,a?E(r.errors,t,a):O(r.errors,t)),(a?!se(c,a):c)||!P(y)||u){const g={...y,...u&&re(n)?{isValid:n}:{},errors:r.errors,name:t};r={...r,...g},h.state.next(g)}U(!1)},G=async t=>s.resolver(f,s.context,Ut(t||p.mount,l,s.criteriaMode,s.shouldUseNativeValidation)),Z=async t=>{const{errors:n}=await G(t);if(t)for(const a of t){const y=d(n,a);y?E(r.errors,a,y):O(r.errors,a)}else r.errors=n;return n},z=async(t,n,a={valid:!0})=>{for(const y in t){const c=t[y];if(c){const{_f:u,...g}=c;if(u){const V=p.array.has(u.name),S=await st(c,f,ie,s.shouldUseNativeValidation&&!n,V);if(S[u.name]&&(a.valid=!1,n))break;!n&&(d(S,u.name)?V?Lt(r.errors,S,u.name):E(r.errors,u.name,S[u.name]):O(r.errors,u.name))}g&&await z(g,n,a)}}return a.valid},k=()=>{for(const t of p.unMount){const n=d(l,t);n&&(n._f.refs?n._f.refs.every(a=>!we(a)):!we(n._f.ref))&&Ee(t)}p.unMount=new Set},b=(t,n)=>(t&&n&&E(f,t,n),!se(Me(),o)),D=(t,n,a)=>Ot(t,p,{...x.mount?f:w(n)?o:j(t)?{[t]:n}:n},a,n),M=t=>ge(d(x.mount?f:o,t,e.shouldUnregister?d(o,t,[]):[])),q=(t,n,a={})=>{const y=d(l,t);let c=n;if(y){const u=y._f;u&&(!u.disabled&&E(f,t,dt(n,u)),c=be(u.ref)&&L(n)?"":n,ut(u.ref)?[...u.ref.options].forEach(g=>g.selected=c.includes(g.value)):u.refs?me(u.ref)?u.refs.length>1?u.refs.forEach(g=>(!g.defaultChecked||!g.disabled)&&(g.checked=Array.isArray(c)?!!c.find(V=>V===g.value):c===g.value)):u.refs[0]&&(u.refs[0].checked=!!c):u.refs.forEach(g=>g.checked=g.value===c):Re(u.ref)?u.ref.value="":(u.ref.value=c,u.ref.type||h.values.next({name:t,values:{...f}})))}(a.shouldDirty||a.shouldTouch)&&I(t,c,a.shouldTouch,a.shouldDirty,!0),a.shouldValidate&&de(t)},K=(t,n,a)=>{for(const y in n){const c=n[y],u=`${t}.${y}`,g=d(l,u);(p.array.has(t)||!pe(c)||g&&!g._f)&&!ue(c)?K(u,c,a):q(u,c,a)}},ee=(t,n,a={})=>{const y=d(l,t),c=p.array.has(t),u=Q(n);E(f,t,u),c?(h.array.next({name:t,values:{...f}}),(_.isDirty||_.dirtyFields)&&a.shouldDirty&&h.state.next({name:t,dirtyFields:Fe(o,f),isDirty:b(t,u)})):y&&!y._f&&!L(u)?K(t,u,a):q(t,u,a),Ye(t,p)&&h.state.next({...r}),h.values.next({name:t,values:{...f}}),!x.mount&&i()},fe=async t=>{const n=t.target;let a=n.name,y=!0;const c=d(l,a),u=()=>n.type?Te(c._f):Vt(t);if(c){let g,V;const S=u(),le=t.type===Qe.BLUR||t.type===Qe.FOCUS_OUT,vt=!Bt(c._f)&&!s.resolver&&!d(r.errors,a)&&!c._f.deps||Nt(le,d(r.touchedFields,a),r.isSubmitted,N,R),Ve=Ye(a,p,le);E(f,a,S),le?(c._f.onBlur&&c._f.onBlur(t),C&&C(0)):c._f.onChange&&c._f.onChange(t);const Ae=I(a,S,le,!1),ht=!P(Ae)||Ve;if(!le&&h.values.next({name:a,type:t.type,values:{...f}}),vt)return _.isValid&&v(),ht&&h.state.next({name:a,...Ve?{}:Ae});if(!le&&Ve&&h.state.next({...r}),U(!0),s.resolver){const{errors:We}=await G([a]),bt=it(r.errors,l,a),Ge=it(We,l,bt.name||a);g=Ge.error,a=Ge.name,V=P(We)}else g=(await st(c,f,ie,s.shouldUseNativeValidation))[a],y=Number.isNaN(S)||S===d(f,a,S),y&&(g?V=!1:_.isValid&&(V=await z(l,!0)));y&&(c._f.deps&&de(c._f.deps),ce(a,V,g,Ae))}},de=async(t,n={})=>{let a,y;const c=De(t);if(U(!0),s.resolver){const u=await Z(w(t)?t:c);a=P(u),y=t?!c.some(g=>d(u,g)):a}else t?(y=(await Promise.all(c.map(async u=>{const g=d(l,u);return await z(g&&g._f?{[u]:g}:g)}))).every(Boolean),!(!y&&!r.isValid)&&v()):y=a=await z(l);return h.state.next({...!j(t)||_.isValid&&a!==r.isValid?{}:{name:t},...s.resolver||!t?{isValid:a}:{},errors:r.errors,isValidating:!1}),n.shouldFocus&&!y&&Oe(l,u=>u&&d(r.errors,u),t?c:p.mount),y},Me=t=>{const n={...o,...x.mount?f:{}};return w(t)?n:j(t)?d(n,t):t.map(a=>d(n,a))},Ue=(t,n)=>({invalid:!!d((n||r).errors,t),isDirty:!!d((n||r).dirtyFields,t),isTouched:!!d((n||r).touchedFields,t),error:d((n||r).errors,t)}),yt=t=>{t&&De(t).forEach(n=>O(r.errors,n)),h.state.next({errors:t?r.errors:{}})},Be=(t,n,a)=>{const y=(d(l,t,{_f:{}})._f||{}).ref;E(r.errors,t,{...n,ref:y}),h.state.next({name:t,errors:r.errors,isValid:!1}),a&&a.shouldFocus&&y&&y.focus&&y.focus()},mt=(t,n)=>X(t)?h.values.subscribe({next:a=>t(D(void 0,n),a)}):D(t,n,!0),Ee=(t,n={})=>{for(const a of t?De(t):p.mount)p.mount.delete(a),p.array.delete(a),n.keepValue||(O(l,a),O(f,a)),!n.keepError&&O(r.errors,a),!n.keepDirty&&O(r.dirtyFields,a),!n.keepTouched&&O(r.touchedFields,a),!s.shouldUnregister&&!n.keepDefaultValue&&O(o,a);h.values.next({values:{...f}}),h.state.next({...r,...n.keepDirty?{isDirty:b()}:{}}),!n.keepIsValid&&v()},Ne=({disabled:t,name:n,field:a,fields:y})=>{if(re(t)){const c=t?void 0:d(f,n,Te(a?a._f:d(y,n)._f));E(f,n,c),I(n,c,!1,!1,!0)}},_e=(t,n={})=>{let a=d(l,t);const y=re(n.disabled);return E(l,t,{...a||{},_f:{...a&&a._f?a._f:{ref:{name:t}},name:t,mount:!0,...n}}),p.mount.add(t),a?Ne({field:a,disabled:n.disabled,name:t}):Y(t,!0,n.value),{...y?{disabled:n.disabled}:{},...s.progressive?{required:!!n.required,min:ye(n.min),max:ye(n.max),minLength:ye(n.minLength),maxLength:ye(n.maxLength),pattern:ye(n.pattern)}:{},name:t,onChange:fe,onBlur:fe,ref:c=>{if(c){_e(t,n),a=d(l,t);const u=w(c.value)&&c.querySelectorAll&&c.querySelectorAll("input,select,textarea")[0]||c,g=Mt(u),V=a._f.refs||[];if(g?V.find(S=>S===u):u===a._f.ref)return;E(l,t,{_f:{...a._f,...g?{refs:[...V.filter(we),u,...Array.isArray(d(o,t))?[{}]:[]],ref:{type:u.type,name:t}}:{ref:u}}}),Y(t,!1,void 0,u)}else a=d(l,t,{}),a._f&&(a._f.mount=!1),(s.shouldUnregister||n.shouldUnregister)&&!(Dt(p.array,t)&&x.action)&&p.unMount.add(t)}}},qe=()=>s.shouldFocusError&&Oe(l,t=>t&&d(r.errors,t),p.mount),Pe=(t,n)=>async a=>{a&&(a.preventDefault&&a.preventDefault(),a.persist&&a.persist());let y=Q(f);if(h.state.next({isSubmitting:!0}),s.resolver){const{errors:c,values:u}=await G();r.errors=c,y=u}else await z(l);O(r.errors,"root"),P(r.errors)?(h.state.next({errors:{}}),await t(y,a)):(n&&await n({...r.errors},a),qe(),setTimeout(qe)),h.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:P(r.errors),submitCount:r.submitCount+1,errors:r.errors})},gt=(t,n={})=>{d(l,t)&&(w(n.defaultValue)?ee(t,d(o,t)):(ee(t,n.defaultValue),E(o,t,n.defaultValue)),n.keepTouched||O(r.touchedFields,t),n.keepDirty||(O(r.dirtyFields,t),r.isDirty=n.defaultValue?b(t,d(o,t)):b()),n.keepError||(O(r.errors,t),_.isValid&&v()),h.state.next({...r}))},He=(t,n={})=>{const a=t?Q(t):o,y=Q(a),c=t&&!P(t)?y:o;if(n.keepDefaultValues||(o=a),!n.keepValues){if(n.keepDirtyValues||$)for(const u of p.mount)d(r.dirtyFields,u)?E(c,u,d(f,u)):ee(u,d(c,u));else{if(Ce&&w(t))for(const u of p.mount){const g=d(l,u);if(g&&g._f){const V=Array.isArray(g._f.refs)?g._f.refs[0]:g._f.ref;if(be(V)){const S=V.closest("form");if(S){S.reset();break}}}}l={}}f=e.shouldUnregister?n.keepDefaultValues?Q(o):{}:Q(c),h.array.next({values:{...c}}),h.values.next({values:{...c}})}p={mount:new Set,unMount:new Set,array:new Set,watch:new Set,watchAll:!1,focus:""},!x.mount&&i(),x.mount=!_.isValid||!!n.keepIsValid,x.watch=!!e.shouldUnregister,h.state.next({submitCount:n.keepSubmitCount?r.submitCount:0,isDirty:n.keepDirty?r.isDirty:!!(n.keepDefaultValues&&!se(t,o)),isSubmitted:n.keepIsSubmitted?r.isSubmitted:!1,dirtyFields:n.keepDirtyValues?r.dirtyFields:n.keepDefaultValues&&t?Fe(o,t):{},touchedFields:n.keepTouched?r.touchedFields:{},errors:n.keepErrors?r.errors:{},isSubmitSuccessful:n.keepIsSubmitSuccessful?r.isSubmitSuccessful:!1,isSubmitting:!1})},$e=(t,n)=>He(X(t)?t(f):t,n);return{control:{register:_e,unregister:Ee,getFieldState:Ue,handleSubmit:Pe,setError:Be,_executeSchema:G,_getWatch:D,_getDirty:b,_updateValid:v,_removeUnmounted:k,_updateFieldArray:B,_updateDisabledField:Ne,_getFieldArray:M,_reset:He,_resetDefaultValues:()=>X(s.defaultValues)&&s.defaultValues().then(t=>{$e(t,s.resetOptions),h.state.next({isLoading:!1})}),_updateFormState:t=>{r={...r,...t}},_subjects:h,_proxyFormState:_,get _fields(){return l},get _formValues(){return f},get _state(){return x},set _state(t){x=t},get _defaultValues(){return o},get _names(){return p},set _names(t){p=t},get _formState(){return r},set _formState(t){r=t},get _options(){return s},set _options(t){s={...s,...t}}},trigger:de,register:_e,handleSubmit:Pe,watch:mt,setValue:ee,getValues:Me,reset:$e,resetField:gt,clearErrors:yt,unregister:Ee,setError:Be,setFocus:(t,n={})=>{const a=d(l,t),y=a&&a._f;if(y){const c=y.refs?y.refs[0]:y.ref;c.focus&&(c.focus(),n.shouldSelect&&c.select())}},getFieldState:Ue}}function $t(e={}){const i=m.useRef(),s=m.useRef(),[r,l]=m.useState({isDirty:!1,isValidating:!1,isLoading:X(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},errors:{},defaultValues:X(e.defaultValues)?void 0:e.defaultValues});i.current||(i.current={...Ht(e,()=>l(f=>({...f}))),formState:r});const o=i.current.control;return o._options=e,Tt({subject:o._subjects.state,next:f=>{Ft(f,o._proxyFormState,o._updateFormState,!0)&&l({...o._formState})}}),m.useEffect(()=>{e.values&&!se(e.values,s.current)?(o._reset(e.values,o._options.resetOptions),s.current=e.values):o._resetDefaultValues()},[e.values,o]),m.useEffect(()=>{o._state.mount||(o._updateValid(),o._state.mount=!0),o._state.watch&&(o._state.watch=!1,o._subjects.state.next({...o._formState})),o._removeUnmounted()}),i.current.formState=wt(r,o),i.current}var Wt=(e=>(e.formgroup="formgroup",e.checkbox="checkbox",e.radiobutton="radiobutton",e.textarea="textarea",e.input="input",e.select="select",e))(Wt||{});const Gt=e=>{const{exampleType:i="formgroup"}=e,{register:s,handleSubmit:r,formState:{errors:l}}=$t(),o=new Date;o.setHours(0),o.setMinutes(0),o.setSeconds(0);const f=new Date;f.setDate(o.getDate()-5),f.setHours(6),f.setMinutes(10),f.setSeconds(0);const x=new Date;x.setDate(o.getDate()+5),x.setHours(22),x.setMinutes(0),x.setSeconds(0);const p="field1",C="field2",H="field3",_="field4",h="field5",$="field6",R=l.field1||l.field2||l.field3||l.field4||l.field5||l.field6||l.field7||l.field8||l.field9,N="Du må velge et alternativ",ie="Du må velge to alternativ",ne="Det kan ikke legges inn mer enn 40 tegn",v="Du må skrive noe her",U='Du må velge "Option 2"';`${f.toLocaleDateString("nb")}${x.toLocaleDateString("nb")}`,`${f.toLocaleTimeString("nb",{hour:"2-digit",minute:"2-digit"})}${x.toLocaleTimeString("nb",{hour:"2-digit",minute:"2-digit"})}`;const B=I=>I.length>=2||ie,A=I=>I.toString()==="Option 2"||U,Y=()=>{if(i==="formgroup"){const I=[m.createElement(te,{key:0,inputId:"checkbox1",label:m.createElement(T,{labelTexts:[{text:"Checkbox 1"}]}),...s(p,{required:N})}),m.createElement(te,{key:1,inputId:"checkbox2",label:m.createElement(T,{labelTexts:[{text:"Checkbox 2"}]}),...s(p,{required:N})}),m.createElement(te,{key:2,inputId:"checkbox3",label:m.createElement(T,{labelTexts:[{text:"Checkbox 3"}]}),...s(p,{required:N})})];return[m.createElement(ae,{key:0,title:"Gruppe tittel",legend:"Velg minst en",error:l.field1?l.field1.message:void 0,variant:e.variant},m.createElement(kt,{maxColumns:Et.two},I.map(ce=>ce))),m.createElement(ae,{key:1,legend:"Velg minst to",error:l.field2?l.field2.message:void 0,variant:e.variant},m.createElement(te,{inputId:"checkbox4",label:m.createElement(T,{labelTexts:[{text:"Checkbox 4"}]}),...s(C,{validate:B})}),m.createElement(te,{inputId:"checkbox5",label:m.createElement(T,{labelTexts:[{text:"Checkbox 5"}]}),...s(C,{validate:B})}),m.createElement(te,{inputId:"checkbox6",label:m.createElement(T,{labelTexts:[{text:"Checkbox 6"}]}),...s(C,{validate:B})})),m.createElement(ae,{key:2,legend:"Velg en",error:l.field3?l.field3.message:void 0,variant:e.variant},m.createElement(ve,{inputId:"radiobutton1",label:m.createElement(T,{labelTexts:[{text:"Radiobutton 1"}]}),...s(H,{required:N})}),m.createElement(ve,{inputId:"radiobutton2",label:m.createElement(T,{labelTexts:[{text:"Radiobutton 2"}]}),...s(H,{required:N})}),m.createElement(ve,{inputId:"radiobutton3",label:m.createElement(T,{labelTexts:[{text:"Radiobutton 3"}]}),...s(H,{required:N})})),m.createElement(ae,{key:3,error:l.field4?l.field4.message:void 0},m.createElement(Je,{defaultValue:`Dette er en test
|
|
2
2
|
|
|
3
3
|
Hello
|
|
4
4
|
|
|
5
5
|
test
|
|
6
6
|
|
|
7
|
-
test test`,grow:!0,maxCharacters:40,minRows:5,label:
|
|
7
|
+
test test`,grow:!0,maxCharacters:40,minRows:5,label:m.createElement(T,{labelTexts:[{text:"Skriv din historie her",type:"semibold"}]}),textareaId:"textarea1",...s(_,{maxLength:{value:40,message:ne}})})),m.createElement(ae,{key:4,variant:e.variant,error:l.field5?l.field5.message:void 0},m.createElement(je,{label:m.createElement(T,{labelTexts:[{text:"Skriv inn din tekst",type:"semibold"}]}),placeholder:"Skriv noe!",icon:Ke,...s(h,{required:v})})),m.createElement(ae,{key:5,variant:e.variant,error:l.field6?l.field6.message:void 0},m.createElement(ze,{label:m.createElement(T,{labelTexts:[{text:"Skriv inn din tekst",type:"semibold"}]}),...s($,{validate:A})},m.createElement("option",{value:"Option 1"},"Option 1"),m.createElement("option",{value:"Option 2"},"Option 2"),m.createElement("option",{value:"Option 3"},"Option 3")))]}else{if(i==="checkbox")return m.createElement(te,{inputId:"checkbox1",label:m.createElement(T,{labelTexts:[{text:"Checkbox 1"}]}),errorText:l.field1?l.field1.message:void 0,variant:e.variant,...s(p,{required:N})});if(i==="radiobutton")return m.createElement(ve,{inputId:"radiobutton1",label:m.createElement(T,{labelTexts:[{text:"Radiobutton 1"}]}),errorText:l.field3?l.field3.message:void 0,variant:e.variant,...s(H,{required:N})});if(i==="textarea")return m.createElement(Je,{defaultValue:`Dette er min historie
|
|
8
8
|
|
|
9
9
|
Hello
|
|
10
10
|
|
|
11
|
-
test`,grow:!0,maxCharacters:40,minRows:5,errorText:l.field4?l.field4.message:void 0,label:
|
|
11
|
+
test`,grow:!0,maxCharacters:40,minRows:5,errorText:l.field4?l.field4.message:void 0,label:m.createElement(T,{labelTexts:[{text:"Skriv din historie her",type:"semibold"}]}),textareaId:"textarea1",...s(_,{maxLength:{value:40,message:ne}})});if(i==="input")return m.createElement(je,{inputId:"input1",label:m.createElement(T,{labelTexts:[{text:"Skriv inn din tekst",type:"semibold"}]}),placeholder:"Skriv noe!",errorText:l.field5?l.field5.message:void 0,icon:Ke,...s(h,{required:v})});if(i==="select")return m.createElement(ze,{errorText:l.field6?l.field6.message:void 0,label:m.createElement(T,{labelTexts:[{text:"Skriv inn din tekst",type:"semibold"}]}),...s($,{validate:A})},m.createElement("option",{value:"Option 1"},"Option 1"),m.createElement("option",{value:"Option 2"},"Option 2"),m.createElement("option",{value:"Option 3"},"Option 3"))}};return m.createElement("form",{noValidate:!0,onSubmit:r(I=>{!xt()&&console.log(I)})},m.createElement(_t,{variant:e.variant,errorSummary:R?"Sjekk at alt er riktig utfylt":void 0},Y()),m.createElement(pt,{type:"submit"},"Send inn"))},Zr=Gt;export{Gt as FormExample,Wt as FormExampleVariants,Zr as default};
|
|
12
12
|
//# sourceMappingURL=index.js.map
|