@fremtind/jokul 5.1.0 → 5.2.1

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.
Files changed (95) hide show
  1. package/build/build-stats.html +1 -1
  2. package/build/cjs/components/card/types.cjs.map +1 -1
  3. package/build/cjs/components/card/types.d.cts +1 -0
  4. package/build/cjs/components/combobox/Combobox.cjs +1 -1
  5. package/build/cjs/components/combobox/Combobox.cjs.map +1 -1
  6. package/build/cjs/components/icon/Icon.cjs.map +1 -1
  7. package/build/cjs/components/icon/Icon.d.cts +2 -17
  8. package/build/cjs/components/icon/icons/ErrorIcon.cjs +1 -1
  9. package/build/cjs/components/icon/icons/ErrorIcon.cjs.map +1 -1
  10. package/build/cjs/components/icon/icons/GreenCheckIcon.cjs +1 -1
  11. package/build/cjs/components/icon/icons/GreenCheckIcon.cjs.map +1 -1
  12. package/build/cjs/components/icon/icons/InfoIcon.cjs +1 -1
  13. package/build/cjs/components/icon/icons/InfoIcon.cjs.map +1 -1
  14. package/build/cjs/components/icon/icons/RedCrossIcon.cjs +1 -1
  15. package/build/cjs/components/icon/icons/RedCrossIcon.cjs.map +1 -1
  16. package/build/cjs/components/icon/icons/SuccessIcon.cjs +1 -1
  17. package/build/cjs/components/icon/icons/SuccessIcon.cjs.map +1 -1
  18. package/build/cjs/components/icon/icons/WarningIcon.cjs +1 -1
  19. package/build/cjs/components/icon/icons/WarningIcon.cjs.map +1 -1
  20. package/build/cjs/components/icon/types.d.cts +1 -2
  21. package/build/cjs/components/input-group/InputGroup.cjs +1 -1
  22. package/build/cjs/components/input-group/InputGroup.cjs.map +1 -1
  23. package/build/cjs/utilities/formatters/util/registerWithMask.cjs +1 -1
  24. package/build/cjs/utilities/formatters/util/registerWithMask.cjs.map +1 -1
  25. package/build/cjs/utilities/formatters/util/registerWithMask.d.cts +1 -3
  26. package/build/es/components/card/types.d.ts +1 -0
  27. package/build/es/components/card/types.js.map +1 -1
  28. package/build/es/components/combobox/Combobox.js +1 -1
  29. package/build/es/components/combobox/Combobox.js.map +1 -1
  30. package/build/es/components/icon/Icon.d.ts +2 -17
  31. package/build/es/components/icon/Icon.js.map +1 -1
  32. package/build/es/components/icon/icons/ErrorIcon.js +1 -1
  33. package/build/es/components/icon/icons/ErrorIcon.js.map +1 -1
  34. package/build/es/components/icon/icons/GreenCheckIcon.js +1 -1
  35. package/build/es/components/icon/icons/GreenCheckIcon.js.map +1 -1
  36. package/build/es/components/icon/icons/InfoIcon.js +1 -1
  37. package/build/es/components/icon/icons/InfoIcon.js.map +1 -1
  38. package/build/es/components/icon/icons/RedCrossIcon.js +1 -1
  39. package/build/es/components/icon/icons/RedCrossIcon.js.map +1 -1
  40. package/build/es/components/icon/icons/SuccessIcon.js +1 -1
  41. package/build/es/components/icon/icons/SuccessIcon.js.map +1 -1
  42. package/build/es/components/icon/icons/WarningIcon.js +1 -1
  43. package/build/es/components/icon/icons/WarningIcon.js.map +1 -1
  44. package/build/es/components/icon/types.d.ts +1 -2
  45. package/build/es/components/input-group/InputGroup.js +1 -1
  46. package/build/es/components/input-group/InputGroup.js.map +1 -1
  47. package/build/es/utilities/formatters/util/registerWithMask.d.ts +1 -3
  48. package/build/es/utilities/formatters/util/registerWithMask.js +1 -1
  49. package/build/es/utilities/formatters/util/registerWithMask.js.map +1 -1
  50. package/package.json +1 -1
  51. package/styles/base.css +15 -3
  52. package/styles/base.min.css +1 -1
  53. package/styles/components/card/card.css +10 -3
  54. package/styles/components/card/card.min.css +1 -1
  55. package/styles/components/card/card.scss +10 -1
  56. package/styles/components/combobox/combobox.css +1 -2
  57. package/styles/components/countdown/countdown.css +2 -2
  58. package/styles/components/countdown/countdown.min.css +1 -1
  59. package/styles/components/feedback/feedback.css +2 -2
  60. package/styles/components/feedback/feedback.min.css +1 -1
  61. package/styles/components/file-input/file-input.css +9 -9
  62. package/styles/components/file-input/file-input.min.css +1 -1
  63. package/styles/components/icon/icon.css +2 -22
  64. package/styles/components/icon/icon.min.css +1 -1
  65. package/styles/components/icon/icon.scss +2 -21
  66. package/styles/components/input-group/input-group.css +2 -2
  67. package/styles/components/input-group/input-group.min.css +1 -1
  68. package/styles/components/loader/loader.css +6 -6
  69. package/styles/components/loader/loader.min.css +1 -1
  70. package/styles/components/loader/skeleton-loader.css +3 -3
  71. package/styles/components/loader/skeleton-loader.min.css +1 -1
  72. package/styles/components/message/message.css +2 -2
  73. package/styles/components/message/message.min.css +1 -1
  74. package/styles/components/number-input/number-input.css +1 -2
  75. package/styles/components/progress-bar/progress-bar.css +1 -1
  76. package/styles/components/progress-bar/progress-bar.min.css +1 -1
  77. package/styles/components/search/search-with-submit-button.css +13 -7
  78. package/styles/components/search/search-with-submit-button.min.css +1 -1
  79. package/styles/components/search/search-with-submit-button.scss +1 -15
  80. package/styles/components/segmented-control/segmented-control.css +4 -24
  81. package/styles/components/segmented-control/segmented-control.min.css +1 -1
  82. package/styles/components/system-message/system-message.css +2 -2
  83. package/styles/components/system-message/system-message.min.css +1 -1
  84. package/styles/components/text-area/text-area.css +1 -2
  85. package/styles/components/text-input/text-input.css +1 -2
  86. package/styles/components/toast/toast.css +4 -4
  87. package/styles/components/toast/toast.min.css +1 -1
  88. package/styles/components/typography/text.css +4 -1
  89. package/styles/components/typography/text.min.css +1 -1
  90. package/styles/components/typography/text.scss +4 -3
  91. package/styles/components.css +57 -65
  92. package/styles/components.min.css +1 -1
  93. package/styles/global/_base-class.scss +2 -1
  94. package/styles/global/_top-layer.scss +19 -3
  95. package/styles/shared/input/shared-input-styles.scss +29 -8
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs","sources":["../../../../src/components/card/types.ts"],"sourcesContent":["import type { PolymorphicPropsWithRef } from \"../../utilities/polymorphism/polymorphism.js\";\n\nexport const CARD_PADDINGS = [\"s\", \"m\", \"l\", \"xl\"] as const;\nexport type CardPadding = (typeof CARD_PADDINGS)[number];\n\ntype Props = {\n className?: string;\n /**\n * Setter padding på kortet. Tilsvarer samme property i Figma.\n * @default \"s\"\n */\n padding?: CardPadding;\n /**\n * Legger på kantlinje rundt kortet.\n * @default false\n */\n outlined?: boolean;\n /**\n * Angir om kortet visuelt skal fremstå som klikkbart. Du må selv rendre\n * kortet som et klikkbart element (f.eks. `<a>` eller en `<Link>` fra\n * et ruting-bibliotek) og gi det en `href` eller `onClick`-handler.\n * HUSK: Sett aria-label for at støtteverktøy, som skjermlesere, ikke\n * skal lese alt innholdet i kortet.\n */\n clickable?: boolean;\n};\n\nexport type CardProps<ElementType extends React.ElementType> =\n PolymorphicPropsWithRef<ElementType, Props> & Props;\n"],"names":[],"mappings":"sGAE6B,CAAC,IAAK,IAAK,IAAK"}
1
+ {"version":3,"file":"types.cjs","sources":["../../../../src/components/card/types.ts"],"sourcesContent":["import type { PolymorphicPropsWithRef } from \"../../utilities/polymorphism/polymorphism.js\";\n\nexport const CARD_PADDINGS = [\"s\", \"m\", \"l\", \"xl\"] as const;\nexport type CardPadding = (typeof CARD_PADDINGS)[number];\n\ntype Props = {\n className?: string;\n /**\n * Setter padding på kortet. Tilsvarer samme property i Figma.\n * @default \"s\"\n */\n padding?: CardPadding;\n /**\n * Legger på kantlinje rundt kortet.\n * @default false\n */\n outlined?: boolean;\n /**\n * @deprecated Kortet får automatisk riktige stiler dersom det rendres som `button` eller `a`\n * Angir om kortet visuelt skal fremstå som klikkbart. Du må selv rendre\n * kortet som et klikkbart element (f.eks. `<a>` eller en `<Link>` fra\n * et ruting-bibliotek) og gi det en `href` eller `onClick`-handler.\n * HUSK: Sett aria-label for at støtteverktøy, som skjermlesere, ikke\n * skal lese alt innholdet i kortet.\n */\n clickable?: boolean;\n};\n\nexport type CardProps<ElementType extends React.ElementType> =\n PolymorphicPropsWithRef<ElementType, Props> & Props;\n"],"names":[],"mappings":"sGAE6B,CAAC,IAAK,IAAK,IAAK"}
@@ -14,6 +14,7 @@ type Props = {
14
14
  */
15
15
  outlined?: boolean;
16
16
  /**
17
+ * @deprecated Kortet får automatisk riktige stiler dersom det rendres som `button` eller `a`
17
18
  * Angir om kortet visuelt skal fremstå som klikkbart. Du må selv rendre
18
19
  * kortet som et klikkbart element (f.eks. `<a>` eller en `<Link>` fra
19
20
  * et ruting-bibliotek) og gi det en `href` eller `onClick`-handler.
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("../../../clsx-E3yX_9sL.cjs"),t=require("react"),a=require("../../hooks/useAnimatedHeight/useAnimatedHeight.cjs"),n=require("../../hooks/useId/useId.cjs"),r=require("../../hooks/useListNavigation/useListNavigation.cjs"),l=require("../chip/Chip.cjs"),s=require("../icon-button/IconButton.cjs"),i=require("../icon/icons/CheckIcon.cjs"),c=require("../icon/icons/animated/ArrowVerticalAnimated.cjs"),u=require("../input-group/InputGroup.cjs"),p=require("../tooltip/Tooltip.cjs"),d=require("../tooltip/TooltipContent.cjs"),b=require("../tooltip/TooltipTrigger.cjs");function m(e){return"string"==typeof e?{value:e,label:e}:e}const x=x=>{const{"data-size":k,id:j,placeholder:v,items:f,onChange:h,onFocus:g,onBlur:_,value:y,label:C,noMatchingOption:w,labelProps:q,helpLabel:N,errorLabel:$,width:L,name:T,className:S,invalid:I,description:P,hasTagHover:B}=x,D=n.useId(j||"jkl-combobox",{generateSuffix:!j}),E=`${D}_label`,A=`${D}_button`,F=`${D}_search-input`,[M,O]=t.useState(y||[]),[K,H]=t.useState(!1),[R,V]=t.useState(""),[z,G]=t.useState(!1),[U,J]=t.useState(!1),Q=t.useRef(null),W=t.useRef(null),X=t.useRef(!1);t.useEffect(()=>{V(""),K&&Q.current&&Q.current.focus()},[K]),t.useEffect(()=>{O(e=>y||e)},[y]);const Y=e=>!!M&&M.some(o=>o.value===e.value),Z=t.useCallback(e=>M.filter(o=>o.value!==e),[M]),ee=t.useCallback((e,o)=>{const t=Z(o);O(t),h({type:"change",target:{name:T,value:o,selectedOptions:t}}),e.stopPropagation(),0===t.length&&J(!1)},[Z,h,T]),oe=t.useCallback(e=>{let o;if(M.some(o=>o.value===e))o=Z(e);else{const t=f.find(o=>o.value===e);o=[...M,t]}Q.current?.focus(),O(o),h({type:"change",target:{name:T,value:e,selectedOptions:o}})},[M,h,T,Z,f]),te=e=>{Q.current?.focus(),H(!0),V(e.target.value)},ae=t.useMemo(()=>{if(!R)return f;const e=f.filter(e=>e.label.toLowerCase().indexOf(R.toLowerCase())>=0);return G(0===e.length),e},[R,f]),[ne,re]=t.useState(ae[0]?.value?`${D}-${ae[0]?.value}`:void 0),le=!K;t.useEffect(()=>{const e=e=>{"Escape"===e.key&&K&&H(!1)};return typeof window<"u"&&window.addEventListener("keydown",e),()=>{typeof window<"u"&&K&&window.removeEventListener("keydown",e)}},[K]);const se=t.useCallback(e=>{e?Q.current&&Q.current.focus():X.current&&W.current&&W.current.focus()},[]),ie=t.useCallback(()=>{X.current||(g&&g({type:"change",target:{name:T,value:M?.[0].value||"",selectedOptions:M}}),X.current=!0,H(!0))},[g,M,T]),[ce]=a.useAnimatedHeight(K,{onFirstVisible:se,onTransitionEnd:se});r.useListNavigation({ref:ce});const ue=t.useRef(null),pe=t.useCallback(e=>{ue.current?.contains(e.relatedTarget)||(V(""),_&&(_({type:"blur",target:{name:T,value:M?.[0]?.value||"",selectedOptions:M}}),W.current?.dispatchEvent(new Event("focusout",{bubbles:!0}))),X.current=!1,H(!1))},[_,T,M]),de=t.useCallback(e=>{e.target.focus({preventScroll:!0})},[]),be=t.useCallback(e=>{if("ArrowDown"===e.key){e.preventDefault(),e.stopPropagation();const o=ce.current;o&&o.querySelector('[role="option"]')?.focus()}else"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),H(!1));if(e.metaKey&&"a"===e.key||e.ctrlKey&&"a"===e.key){e.preventDefault(),e.stopPropagation();const o=M.map(e=>({...e,isMarked:!0}));J(!0),O(o)}else if("Backspace"===e.key)if(e.stopPropagation(),J(!1),M.some(e=>e.isMarked)){const e=M.filter(e=>!e.isMarked);O(e),V("")}else M.length>0&&""===R&&ee(e,M[M.length-1].value)},[M,R,ce,ee]),me=t.useCallback(e=>{if("Tab"===e.key)Q.current&&(e.preventDefault(),e.stopPropagation(),e.shiftKey||H(!1),Q.current.focus());else if("ArrowUp"===e.key&&ce.current&&Q.current){const o=ce.current.querySelector('[role="option"]:not([hidden])');e.currentTarget.id===o?.id&&Q.current&&Q.current.focus()}},[ce]),xe=M.length>=1,ke=t.useCallback(o=>e.jsx(l.Chip,{"data-testid":"jkl-chip","aria-label":`Fjern ${o.tagLabel}`,className:`jkl-combobox__selected-option ${U&&"jkl-combobox__selected-option--marked"}`,variant:"input",onClick:e=>{Q.current&&Q.current.focus(),ee(e,o.value)},onBlur:pe,children:o.tagLabel?o.tagLabel:o.label},o.value),[pe,ee,U]);return e.jsx(u.InputGroup,{label:C,id:F,ref:ue,"data-testid":"jkl-combobox","data-size":k,className:o.clsx("jkl-combobox",S,{"jkl-combobox--invalid":!!$||I,"jkl-combobox--menu-open":K,"jkl-combobox--menu-closed":!K&&xe}),labelProps:{id:E,...q},helpLabel:N,errorLabel:$,description:P,render:t=>e.jsxs("div",{className:o.clsx("jkl-combobox__wrapper",{"jkl-combobox__wrapper--active-value":xe}),style:{width:L},tabIndex:-1,onFocus:ie,onBlur:pe,"data-invalid":!!$||I,children:[e.jsxs("div",{className:"jkl-combobox__chips","data-testid":"jkl-combobox__chips",children:[M.map(m).map(o=>B?e.jsxs(p.Tooltip,{children:[e.jsx(b.TooltipTrigger,{children:ke(o)}),e.jsx(d.TooltipContent,{children:o.label})]},o.value):ke(o)),e.jsx("input",{...t,className:"jkl-combobox__search-input",onChange:te,"data-testid":"jkl-combobox__search-input",onFocus:ie,onBlur:pe,onKeyDown:be,value:R,ref:Q,"aria-controls":D,role:"combobox","aria-autocomplete":"list","aria-expanded":K,placeholder:M.length>0?"":v,autoComplete:"off"})]}),e.jsxs("div",{className:"jkl-combobox__menu",role:"listbox",ref:ce,id:D,"aria-labelledby":E,"aria-multiselectable":"true","aria-activedescendant":ne,onFocus:ie,onBlur:pe,tabIndex:-1,children:[ae.map((o,t)=>e.jsxs("button",{type:"button",id:`${D}__${o.value}`,"aria-selected":Y(o),role:"option",value:o.value,onBlur:pe,className:`jkl-combobox__option ${Y(o)&&"jkl-combobox__option--selected"}`,"data-testid":"jkl-combobox__option","data-testautoid":`jkl-combobox__option-${t}`,onFocus:ie,onKeyDown:me,onClick:e=>{re(`${D}__${o.value}`),e.stopPropagation(),oe(o.value),V("")},onMouseOver:de,children:[o.description?e.jsxs("span",{children:[o.label,e.jsx("span",{className:"jkl-combobox__option-description",children:o.description})]}):o.label,Y(o)?e.jsxs("span",{children:[e.jsx(i.CheckIcon,{})," "]}):null]},`${D}-${o.value}`)),z&&e.jsx("div",{className:"jkl-combobox__no-option",children:w})]}),e.jsx(s.IconButton,{id:A,onFocus:ie,onBlur:pe,className:"jkl-text-input-action-button","data-testid":"jkl-combobox__button","aria-label":"Åpne meny","aria-expanded":K,"aria-controls":D,onClick:()=>H(e=>!e),onMouseDown:e=>{e.preventDefault(),W.current?.focus()},children:e.jsx(c.ArrowVerticalAnimated,{pointingDown:le})})]})})};x.displayName="Combobox",exports.Combobox=x,exports.getComboboxValuePair=m;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("../../../clsx-E3yX_9sL.cjs"),t=require("react"),a=require("../../hooks/useAnimatedHeight/useAnimatedHeight.cjs"),n=require("../../hooks/useId/useId.cjs"),r=require("../../hooks/useListNavigation/useListNavigation.cjs"),l=require("../chip/Chip.cjs"),s=require("../icon-button/IconButton.cjs"),i=require("../icon/icons/CheckIcon.cjs"),c=require("../icon/icons/animated/ArrowVerticalAnimated.cjs"),u=require("../input-group/InputGroup.cjs"),p=require("../tooltip/Tooltip.cjs"),d=require("../tooltip/TooltipContent.cjs"),b=require("../tooltip/TooltipTrigger.cjs");function m(e){return"string"==typeof e?{value:e,label:e}:e}const x=x=>{const{"data-size":k,id:j,placeholder:v,items:f,onChange:h,onFocus:g,onBlur:_,value:y,label:C,noMatchingOption:w,labelProps:q,helpLabel:N,errorLabel:$,width:L,name:T,className:S,invalid:I,description:P,hasTagHover:B,tooltip:D}=x,E=n.useId(j||"jkl-combobox",{generateSuffix:!j}),A=`${E}_label`,F=`${E}_button`,M=`${E}_search-input`,[O,K]=t.useState(y||[]),[H,R]=t.useState(!1),[V,z]=t.useState(""),[G,U]=t.useState(!1),[J,Q]=t.useState(!1),W=t.useRef(null),X=t.useRef(null),Y=t.useRef(!1);t.useEffect(()=>{z(""),H&&W.current&&W.current.focus()},[H]),t.useEffect(()=>{K(e=>y||e)},[y]);const Z=e=>!!O&&O.some(o=>o.value===e.value),ee=t.useCallback(e=>O.filter(o=>o.value!==e),[O]),oe=t.useCallback((e,o)=>{const t=ee(o);K(t),h({type:"change",target:{name:T,value:o,selectedOptions:t}}),e.stopPropagation(),0===t.length&&Q(!1)},[ee,h,T]),te=t.useCallback(e=>{let o;if(O.some(o=>o.value===e))o=ee(e);else{const t=f.find(o=>o.value===e);o=[...O,t]}W.current?.focus(),K(o),h({type:"change",target:{name:T,value:e,selectedOptions:o}})},[O,h,T,ee,f]),ae=e=>{W.current?.focus(),R(!0),z(e.target.value)},ne=t.useMemo(()=>{if(!V)return f;const e=f.filter(e=>e.label.toLowerCase().indexOf(V.toLowerCase())>=0);return U(0===e.length),e},[V,f]),[re,le]=t.useState(ne[0]?.value?`${E}-${ne[0]?.value}`:void 0),se=!H;t.useEffect(()=>{const e=e=>{"Escape"===e.key&&H&&R(!1)};return typeof window<"u"&&window.addEventListener("keydown",e),()=>{typeof window<"u"&&H&&window.removeEventListener("keydown",e)}},[H]);const ie=t.useCallback(e=>{e?W.current&&W.current.focus():Y.current&&X.current&&X.current.focus()},[]),ce=t.useCallback(()=>{Y.current||(g&&g({type:"change",target:{name:T,value:O?.[0].value||"",selectedOptions:O}}),Y.current=!0,R(!0))},[g,O,T]),[ue]=a.useAnimatedHeight(H,{onFirstVisible:ie,onTransitionEnd:ie});r.useListNavigation({ref:ue});const pe=t.useRef(null),de=t.useCallback(e=>{pe.current?.contains(e.relatedTarget)||(z(""),_&&(_({type:"blur",target:{name:T,value:O?.[0]?.value||"",selectedOptions:O}}),X.current?.dispatchEvent(new Event("focusout",{bubbles:!0}))),Y.current=!1,R(!1))},[_,T,O]),be=t.useCallback(e=>{e.target.focus({preventScroll:!0})},[]),me=t.useCallback(e=>{if("ArrowDown"===e.key){e.preventDefault(),e.stopPropagation();const o=ue.current;o&&o.querySelector('[role="option"]')?.focus()}else"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),R(!1));if(e.metaKey&&"a"===e.key||e.ctrlKey&&"a"===e.key){e.preventDefault(),e.stopPropagation();const o=O.map(e=>({...e,isMarked:!0}));Q(!0),K(o)}else if("Backspace"===e.key)if(e.stopPropagation(),Q(!1),O.some(e=>e.isMarked)){const e=O.filter(e=>!e.isMarked);K(e),z("")}else O.length>0&&""===V&&oe(e,O[O.length-1].value)},[O,V,ue,oe]),xe=t.useCallback(e=>{if("Tab"===e.key)W.current&&(e.preventDefault(),e.stopPropagation(),e.shiftKey||R(!1),W.current.focus());else if("ArrowUp"===e.key&&ue.current&&W.current){const o=ue.current.querySelector('[role="option"]:not([hidden])');e.currentTarget.id===o?.id&&W.current&&W.current.focus()}},[ue]),ke=O.length>=1,je=t.useCallback(o=>e.jsx(l.Chip,{"data-testid":"jkl-chip","aria-label":`Fjern ${o.tagLabel}`,className:`jkl-combobox__selected-option ${J&&"jkl-combobox__selected-option--marked"}`,variant:"input",onClick:e=>{W.current&&W.current.focus(),oe(e,o.value)},onBlur:de,children:o.tagLabel?o.tagLabel:o.label},o.value),[de,oe,J]);return e.jsx(u.InputGroup,{label:C,id:M,ref:pe,"data-testid":"jkl-combobox","data-size":k,className:o.clsx("jkl-combobox",S,{"jkl-combobox--invalid":!!$||I,"jkl-combobox--menu-open":H,"jkl-combobox--menu-closed":!H&&ke}),labelProps:{id:A,...q},helpLabel:N,errorLabel:$,description:P,tooltip:D,render:t=>e.jsxs("div",{className:o.clsx("jkl-combobox__wrapper",{"jkl-combobox__wrapper--active-value":ke}),style:{width:L},tabIndex:-1,onFocus:ce,onBlur:de,"data-invalid":!!$||I,children:[e.jsxs("div",{className:"jkl-combobox__chips","data-testid":"jkl-combobox__chips",children:[O.map(m).map(o=>B?e.jsxs(p.Tooltip,{children:[e.jsx(b.TooltipTrigger,{children:je(o)}),e.jsx(d.TooltipContent,{children:o.label})]},o.value):je(o)),e.jsx("input",{...t,className:"jkl-combobox__search-input",onChange:ae,"data-testid":"jkl-combobox__search-input",onFocus:ce,onBlur:de,onKeyDown:me,value:V,ref:W,"aria-controls":E,role:"combobox","aria-autocomplete":"list","aria-expanded":H,placeholder:O.length>0?"":v,autoComplete:"off"})]}),e.jsxs("div",{className:"jkl-combobox__menu",role:"listbox",ref:ue,id:E,"aria-labelledby":A,"aria-multiselectable":"true","aria-activedescendant":re,onFocus:ce,onBlur:de,tabIndex:-1,children:[ne.map((o,t)=>e.jsxs("button",{type:"button",id:`${E}__${o.value}`,"aria-selected":Z(o),role:"option",value:o.value,onBlur:de,className:`jkl-combobox__option ${Z(o)&&"jkl-combobox__option--selected"}`,"data-testid":"jkl-combobox__option","data-testautoid":`jkl-combobox__option-${t}`,onFocus:ce,onKeyDown:xe,onClick:e=>{le(`${E}__${o.value}`),e.stopPropagation(),te(o.value),z("")},onMouseOver:be,children:[o.description?e.jsxs("span",{children:[o.label,e.jsx("span",{className:"jkl-combobox__option-description",children:o.description})]}):o.label,Z(o)?e.jsxs("span",{children:[e.jsx(i.CheckIcon,{})," "]}):null]},`${E}-${o.value}`)),G&&e.jsx("div",{className:"jkl-combobox__no-option",children:w})]}),e.jsx(s.IconButton,{id:F,onFocus:ce,onBlur:de,className:"jkl-text-input-action-button","data-testid":"jkl-combobox__button","aria-label":"Åpne meny","aria-expanded":H,"aria-controls":E,onClick:()=>R(e=>!e),onMouseDown:e=>{e.preventDefault(),X.current?.focus()},children:e.jsx(c.ArrowVerticalAnimated,{pointingDown:se})})]})})};x.displayName="Combobox",exports.Combobox=x,exports.getComboboxValuePair=m;
2
2
  //# sourceMappingURL=Combobox.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Combobox.cjs","sources":["../../../../src/components/combobox/Combobox.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport React, {\n type FC,\n type FocusEvent,\n type KeyboardEvent,\n type MouseEvent,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { useAnimatedHeight } from \"../../hooks/useAnimatedHeight/useAnimatedHeight.js\";\nimport { useId } from \"../../hooks/useId/useId.js\";\nimport { useListNavigation } from \"../../hooks/useListNavigation/useListNavigation.js\";\nimport type { ValuePair } from \"../../utilities/valuePair.js\";\nimport { Chip } from \"../chip/Chip.js\";\nimport { IconButton } from \"../icon-button/IconButton.js\";\nimport { CheckIcon } from \"../icon/icons/CheckIcon.js\";\nimport { ArrowVerticalAnimated } from \"../icon/icons/animated/ArrowVerticalAnimated.js\";\nimport { InputGroup } from \"../input-group/InputGroup.js\";\nimport { Tooltip } from \"../tooltip/Tooltip.js\";\nimport { TooltipContent } from \"../tooltip/TooltipContent.js\";\nimport { TooltipTrigger } from \"../tooltip/TooltipTrigger.js\";\nimport type { ComboboxProps, ComboboxValuePair } from \"./types.js\";\n\nexport function getComboboxValuePair(\n item: string | ComboboxValuePair,\n): ComboboxValuePair {\n return typeof item === \"string\" ? { value: item, label: item } : item;\n}\n\nexport const Combobox: FC<ComboboxProps> = (props) => {\n const {\n \"data-size\": dataSize,\n id,\n placeholder,\n items,\n onChange,\n onFocus,\n onBlur,\n value,\n label,\n noMatchingOption,\n labelProps,\n helpLabel,\n errorLabel,\n width,\n name,\n className,\n invalid,\n description,\n hasTagHover,\n } = props;\n const listId = useId(id || \"jkl-combobox\", { generateSuffix: !id });\n const labelId = `${listId}_label`;\n const buttonId = `${listId}_button`;\n const inputId = `${listId}_search-input`;\n\n const [selectedValue, setSelectedValue] = useState<\n Array<ComboboxValuePair>\n >(value || []);\n const [showMenu, setShowMenu] = useState<boolean>(false);\n const [searchValue, setSearchValue] = useState<string>(\"\");\n const [noResults, setNoResults] = useState(false);\n const [marked, setMarked] = useState<boolean>(false);\n\n const searchRef = useRef<HTMLInputElement>(null);\n const inputRef = useRef<HTMLDivElement>(null);\n const focusInsideRef = useRef(false);\n\n useEffect(() => {\n setSearchValue(\"\");\n if (showMenu && searchRef.current) {\n searchRef.current.focus();\n }\n }, [showMenu]);\n\n useEffect(() => {\n setSelectedValue((prev) => value || prev);\n }, [value]);\n\n // Funksjon for å stile valgt element\n const isSelected = (option: ValuePair) => {\n if (!selectedValue) {\n return false;\n }\n\n return selectedValue.some((value) => value.value === option.value);\n };\n\n // Fjerne ett eller flere valg\n const removeOption = useCallback(\n (option: string) => {\n return selectedValue.filter((value) => value.value !== option);\n },\n [selectedValue],\n );\n\n const onTagRemove = useCallback(\n (\n e:\n | React.MouseEvent<HTMLButtonElement, globalThis.MouseEvent>\n | React.KeyboardEvent<HTMLInputElement>,\n option: string,\n ) => {\n const newValue = removeOption(option);\n setSelectedValue(newValue);\n onChange({\n type: \"change\",\n target: { name, value: option, selectedOptions: newValue },\n });\n e.stopPropagation();\n\n if (newValue.length === 0) {\n setMarked(false);\n }\n },\n [removeOption, onChange, name],\n );\n\n // Håndtere valgt verdi i listen\n const onItemClick = useCallback(\n (option: string) => {\n let newValue: Array<ValuePair>;\n\n if (selectedValue.some((value) => value.value === option)) {\n newValue = removeOption(option);\n } else {\n const item = items.find((i) => i.value === option);\n newValue = [...selectedValue, item as ValuePair];\n }\n searchRef.current?.focus();\n setSelectedValue(newValue);\n onChange({\n type: \"change\",\n target: { name, value: option, selectedOptions: newValue },\n });\n },\n [selectedValue, onChange, name, removeOption, items],\n );\n\n // Funksjon for søk\n const onSearch = (e: {\n target: { value: React.SetStateAction<string> };\n }) => {\n searchRef.current?.focus();\n setShowMenu(true);\n setSearchValue(e.target.value);\n };\n\n const options = useMemo(() => {\n if (!searchValue) {\n return items;\n }\n\n const filteredOptions = items.filter(\n (option) =>\n option.label.toLowerCase().indexOf(searchValue.toLowerCase()) >=\n 0,\n );\n\n setNoResults(filteredOptions.length === 0);\n\n return filteredOptions;\n }, [searchValue, items]);\n\n // Det første elementet i listen skal være aktivt fram til brukeren klikker på noe annet\n const [activeDescendant, setActiveDescendant] = useState<\n string | undefined\n >(options[0]?.value ? `${listId}-${options[0]?.value}` : undefined);\n\n // Håndtere arrow-state\n const isPointingDown = !showMenu;\n\n // Lukk meny med ESC\n useEffect(() => {\n const handleEscape = (e: globalThis.KeyboardEvent) => {\n if (e.key === \"Escape\" && showMenu) {\n setShowMenu(false);\n }\n };\n if (typeof window !== \"undefined\") {\n window.addEventListener(\"keydown\", handleEscape);\n }\n return () => {\n if (typeof window !== \"undefined\" && showMenu) {\n window.removeEventListener(\"keydown\", handleEscape);\n }\n };\n }, [showMenu]);\n\n // Fokushåndtering\n const handleFocusPlacement = useCallback((isOpen: boolean) => {\n if (isOpen) {\n if (searchRef.current) {\n searchRef.current.focus();\n }\n } else {\n if (focusInsideRef.current && inputRef.current) {\n inputRef.current.focus();\n }\n }\n }, []);\n\n const handleFocus = useCallback(() => {\n if (!focusInsideRef.current) {\n if (onFocus) {\n onFocus({\n type: \"change\",\n target: {\n name,\n value: selectedValue?.[0].value || \"\",\n selectedOptions: selectedValue,\n },\n });\n }\n focusInsideRef.current = true;\n setShowMenu(true);\n }\n }, [onFocus, selectedValue, name]);\n\n const [dropdownRef] = useAnimatedHeight<HTMLDivElement>(showMenu, {\n onFirstVisible: handleFocusPlacement,\n onTransitionEnd: handleFocusPlacement,\n });\n\n useListNavigation({ ref: dropdownRef });\n\n const componentRootElementRef = useRef<HTMLDivElement>(null);\n\n const handleBlur = useCallback(\n (\n e: FocusEvent<\n HTMLDivElement | HTMLInputElement | HTMLButtonElement\n >,\n ) => {\n const componentRootElement = componentRootElementRef.current;\n const nextFocusIsInsideComponent = componentRootElement?.contains(\n e.relatedTarget as Node,\n );\n if (!nextFocusIsInsideComponent) {\n setSearchValue(\"\");\n\n if (onBlur) {\n onBlur({\n type: \"blur\",\n target: {\n name,\n value: selectedValue?.[0]?.value || \"\",\n selectedOptions: selectedValue,\n },\n });\n inputRef.current?.dispatchEvent(\n new Event(\"focusout\", { bubbles: true }),\n );\n }\n focusInsideRef.current = false;\n setShowMenu(false);\n }\n },\n [onBlur, name, selectedValue],\n );\n\n const handleMouseOver = useCallback((e: MouseEvent<HTMLButtonElement>) => {\n // Ved mouseOver på options flytter vi fokus til dem for å unngå \"dobbel fokus\"\n // der det ser ut som to forskjellige elementer er fokusert/hovered samtidig\n (e.target as HTMLButtonElement).focus({ preventScroll: true });\n }, []);\n\n // Tastaturnavigasjon\n const handleSearchOnKeyDown = useCallback(\n (e: KeyboardEvent<HTMLInputElement>) => {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n e.stopPropagation();\n const listElement = dropdownRef.current;\n if (listElement) {\n listElement\n .querySelector<HTMLButtonElement>('[role=\"option\"]')\n ?.focus();\n }\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n e.stopPropagation();\n setShowMenu(false);\n }\n\n if ((e.metaKey && e.key === \"a\") || (e.ctrlKey && e.key === \"a\")) {\n e.preventDefault();\n e.stopPropagation();\n const updatedSelectedValue = selectedValue.map((item) => ({\n ...item,\n isMarked: true,\n }));\n setMarked(true);\n setSelectedValue(updatedSelectedValue);\n } else if (e.key === \"Backspace\") {\n e.stopPropagation();\n setMarked(false);\n\n // Sjekk om selectedValue er markert\n const selectedValueIsMarked = selectedValue.some(\n (item) => item.isMarked,\n );\n\n if (selectedValueIsMarked) {\n const updatedSelectedValue = selectedValue.filter(\n (item) => !item.isMarked,\n );\n setSelectedValue(updatedSelectedValue);\n setSearchValue(\"\");\n } else if (selectedValue.length > 0 && searchValue === \"\") {\n // Hvis ingen items er markert, fjern siste valgte item\n onTagRemove(\n e,\n selectedValue[selectedValue.length - 1].value,\n );\n }\n }\n },\n [selectedValue, searchValue, dropdownRef, onTagRemove],\n );\n\n const handleOptionOnKeyDown = useCallback(\n (e: KeyboardEvent<HTMLButtonElement>) => {\n if (e.key === \"Tab\") {\n if (searchRef.current) {\n e.preventDefault();\n e.stopPropagation();\n\n if (e.shiftKey) {\n searchRef.current.focus();\n } else {\n setShowMenu(false);\n searchRef.current.focus();\n }\n }\n } else if (e.key === \"ArrowUp\") {\n if (dropdownRef.current && searchRef.current) {\n // Can't be based on index since the first item might be filtered out\n const firstVisible = dropdownRef.current.querySelector(\n '[role=\"option\"]:not([hidden])',\n );\n if (\n e.currentTarget.id === firstVisible?.id &&\n searchRef.current\n ) {\n searchRef.current.focus();\n }\n }\n }\n },\n [dropdownRef],\n );\n\n const hasSelection = selectedValue.length >= 1;\n\n const renderSelectedOption = useCallback(\n (option: ComboboxValuePair) => (\n <Chip\n key={option.value}\n data-testid=\"jkl-chip\"\n aria-label={`Fjern ${option.tagLabel}`}\n className={`jkl-combobox__selected-option ${\n marked && \"jkl-combobox__selected-option--marked\"\n }`}\n variant=\"input\"\n onClick={(e) => {\n if (searchRef.current) {\n searchRef.current.focus();\n }\n onTagRemove(e, option.value);\n }}\n onBlur={handleBlur}\n >\n {option.tagLabel ? option.tagLabel : option.label}\n </Chip>\n ),\n [handleBlur, onTagRemove, marked],\n );\n\n return (\n <InputGroup\n label={label}\n id={inputId}\n ref={componentRootElementRef}\n data-testid=\"jkl-combobox\"\n data-size={dataSize}\n className={clsx(\"jkl-combobox\", className, {\n \"jkl-combobox--invalid\": !!errorLabel || invalid,\n \"jkl-combobox--menu-open\": showMenu,\n \"jkl-combobox--menu-closed\": !showMenu && hasSelection,\n })}\n labelProps={{\n id: labelId,\n ...labelProps,\n }}\n helpLabel={helpLabel}\n errorLabel={errorLabel}\n description={description}\n render={(inputProps) => (\n <div\n className={clsx(\"jkl-combobox__wrapper\", {\n \"jkl-combobox__wrapper--active-value\": hasSelection,\n })}\n style={{ width }}\n tabIndex={-1}\n onFocus={handleFocus}\n onBlur={handleBlur}\n data-invalid={!!errorLabel || invalid}\n >\n <div\n className=\"jkl-combobox__chips\"\n data-testid=\"jkl-combobox__chips\"\n >\n {selectedValue\n .map(getComboboxValuePair)\n .map((option) => {\n return hasTagHover ? (\n <Tooltip key={option.value}>\n <TooltipTrigger>\n {renderSelectedOption(option)}\n </TooltipTrigger>\n <TooltipContent>\n {option.label}\n </TooltipContent>\n </Tooltip>\n ) : (\n renderSelectedOption(option)\n );\n })}\n <input\n {...inputProps}\n className=\"jkl-combobox__search-input\"\n onChange={onSearch}\n data-testid=\"jkl-combobox__search-input\"\n onFocus={handleFocus}\n onBlur={handleBlur}\n onKeyDown={handleSearchOnKeyDown}\n value={searchValue}\n ref={searchRef}\n aria-controls={listId}\n role=\"combobox\"\n aria-autocomplete=\"list\"\n aria-expanded={showMenu}\n placeholder={\n selectedValue.length > 0 ? \"\" : placeholder\n }\n autoComplete=\"off\"\n />\n </div>\n\n <div\n className=\"jkl-combobox__menu\"\n // biome-ignore lint/a11y/useSemanticElements: Dette er en reimplementering av en liste\n role=\"listbox\"\n ref={dropdownRef}\n id={listId}\n aria-labelledby={labelId}\n aria-multiselectable=\"true\"\n aria-activedescendant={activeDescendant}\n onFocus={handleFocus}\n onBlur={handleBlur}\n tabIndex={-1}\n >\n {options.map((option, i) => (\n <button\n key={`${listId}-${option.value}`}\n type=\"button\"\n id={`${listId}__${option.value}`}\n aria-selected={isSelected(option)}\n // biome-ignore lint/a11y/useSemanticElements: Dette er en reimplementering av en liste\n role=\"option\"\n value={option.value}\n onBlur={handleBlur}\n className={`jkl-combobox__option ${\n isSelected(option) &&\n \"jkl-combobox__option--selected\"\n }`}\n data-testid=\"jkl-combobox__option\"\n data-testautoid={`jkl-combobox__option-${i}`}\n onFocus={handleFocus}\n onKeyDown={handleOptionOnKeyDown}\n onClick={(e) => {\n setActiveDescendant(\n `${listId}__${option.value}`,\n ); // https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/listbox_role#required_javascript_features\n e.stopPropagation();\n onItemClick(option.value);\n setSearchValue(\"\");\n }}\n onMouseOver={handleMouseOver}\n >\n {option.description ? (\n <span>\n {option.label}\n <span className=\"jkl-combobox__option-description\">\n {option.description}\n </span>\n </span>\n ) : (\n option.label\n )}\n {isSelected(option) ? (\n <span>\n <CheckIcon />{\" \"}\n </span>\n ) : null}\n </button>\n ))}\n {noResults && (\n <div className=\"jkl-combobox__no-option\">\n {noMatchingOption}\n </div>\n )}\n </div>\n <IconButton\n id={buttonId}\n onFocus={handleFocus}\n onBlur={handleBlur}\n className=\"jkl-text-input-action-button\"\n data-testid=\"jkl-combobox__button\"\n aria-label=\"Åpne meny\"\n aria-expanded={showMenu}\n aria-controls={listId}\n onClick={() => setShowMenu((previous) => !previous)}\n onMouseDown={(e) => {\n e.preventDefault();\n inputRef.current?.focus();\n }}\n >\n <ArrowVerticalAnimated pointingDown={isPointingDown} />\n </IconButton>\n </div>\n )}\n />\n );\n};\nCombobox.displayName = \"Combobox\";\n"],"names":["getComboboxValuePair","item","value","label","Combobox","props","dataSize","id","placeholder","items","onChange","onFocus","onBlur","noMatchingOption","labelProps","helpLabel","errorLabel","width","name","className","invalid","description","hasTagHover","listId","useId","generateSuffix","labelId","buttonId","inputId","selectedValue","setSelectedValue","useState","showMenu","setShowMenu","searchValue","setSearchValue","noResults","setNoResults","marked","setMarked","searchRef","useRef","inputRef","focusInsideRef","useEffect","current","focus","prev","isSelected","option","some","removeOption","useCallback","filter","onTagRemove","e","newValue","type","target","selectedOptions","stopPropagation","length","onItemClick","find","i","onSearch","options","useMemo","filteredOptions","toLowerCase","indexOf","activeDescendant","setActiveDescendant","isPointingDown","handleEscape","key","window","addEventListener","removeEventListener","handleFocusPlacement","isOpen","handleFocus","dropdownRef","useAnimatedHeight","onFirstVisible","onTransitionEnd","useListNavigation","ref","componentRootElementRef","handleBlur","contains","relatedTarget","dispatchEvent","Event","bubbles","handleMouseOver","preventScroll","handleSearchOnKeyDown","preventDefault","listElement","querySelector","metaKey","ctrlKey","updatedSelectedValue","map","isMarked","handleOptionOnKeyDown","shiftKey","firstVisible","currentTarget","hasSelection","renderSelectedOption","jsx","Chip","tagLabel","variant","onClick","children","InputGroup","clsx","render","inputProps","jsxs","style","tabIndex","Tooltip","TooltipTrigger","TooltipContent","onKeyDown","role","autoComplete","onMouseOver","CheckIcon","IconButton","previous","onMouseDown","ArrowVerticalAnimated","pointingDown","displayName"],"mappings":"grBA0BO,SAASA,EACZC,GAEA,MAAuB,iBAATA,EAAoB,CAAEC,MAAOD,EAAME,MAAOF,GAASA,CACrE,CAEO,MAAMG,EAA+BC,IACxC,MACI,YAAaC,EACbC,GAAAA,EACAC,YAAAA,EACAC,MAAAA,EACAC,SAAAA,EACAC,QAAAA,EACAC,OAAAA,EACAV,MAAAA,EACAC,MAAAA,EACAU,iBAAAA,EACAC,WAAAA,EACAC,UAAAA,EACAC,WAAAA,EACAC,MAAAA,EACAC,KAAAA,EACAC,UAAAA,EACAC,QAAAA,EACAC,YAAAA,EACAC,YAAAA,GACAjB,EACEkB,EAASC,EAAAA,MAAMjB,GAAM,eAAgB,CAAEkB,gBAAiBlB,IACxDmB,EAAU,GAAGH,UACbI,EAAW,GAAGJ,WACdK,EAAU,GAAGL,kBAEZM,EAAeC,GAAoBC,EAAAA,SAExC7B,GAAS,KACJ8B,EAAUC,GAAeF,EAAAA,UAAkB,IAC3CG,EAAaC,GAAkBJ,EAAAA,SAAiB,KAChDK,EAAWC,GAAgBN,EAAAA,UAAS,IACpCO,EAAQC,GAAaR,EAAAA,UAAkB,GAExCS,EAAYC,EAAAA,OAAyB,MACrCC,EAAWD,EAAAA,OAAuB,MAClCE,EAAiBF,EAAAA,QAAO,GAE9BG,EAAAA,UAAU,KACNT,EAAe,IACXH,GAAYQ,EAAUK,SACtBL,EAAUK,QAAQC,SAEvB,CAACd,IAEJY,EAAAA,UAAU,KACNd,EAAkBiB,GAAS7C,GAAS6C,IACrC,CAAC7C,IAGJ,MAAM8C,EAAcC,KACXpB,GAIEA,EAAcqB,KAAMhD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uE,SAAAL,EAAAA,IAACwB,EAAAA,sBAAA,CAAsBC,aAAchE,aAO7DrE,EAASsI,YAAc"}
1
+ {"version":3,"file":"Combobox.cjs","sources":["../../../../src/components/combobox/Combobox.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport React, {\n type FC,\n type FocusEvent,\n type KeyboardEvent,\n type MouseEvent,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { useAnimatedHeight } from \"../../hooks/useAnimatedHeight/useAnimatedHeight.js\";\nimport { useId } from \"../../hooks/useId/useId.js\";\nimport { useListNavigation } from \"../../hooks/useListNavigation/useListNavigation.js\";\nimport type { ValuePair } from \"../../utilities/valuePair.js\";\nimport { Chip } from \"../chip/Chip.js\";\nimport { IconButton } from \"../icon-button/IconButton.js\";\nimport { CheckIcon } from \"../icon/icons/CheckIcon.js\";\nimport { ArrowVerticalAnimated } from \"../icon/icons/animated/ArrowVerticalAnimated.js\";\nimport { InputGroup } from \"../input-group/InputGroup.js\";\nimport { Tooltip } from \"../tooltip/Tooltip.js\";\nimport { TooltipContent } from \"../tooltip/TooltipContent.js\";\nimport { TooltipTrigger } from \"../tooltip/TooltipTrigger.js\";\nimport type { ComboboxProps, ComboboxValuePair } from \"./types.js\";\n\nexport function getComboboxValuePair(\n item: string | ComboboxValuePair,\n): ComboboxValuePair {\n return typeof item === \"string\" ? { value: item, label: item } : item;\n}\n\nexport const Combobox: FC<ComboboxProps> = (props) => {\n const {\n \"data-size\": dataSize,\n id,\n placeholder,\n items,\n onChange,\n onFocus,\n onBlur,\n value,\n label,\n noMatchingOption,\n labelProps,\n helpLabel,\n errorLabel,\n width,\n name,\n className,\n invalid,\n description,\n hasTagHover,\n tooltip,\n } = props;\n const listId = useId(id || \"jkl-combobox\", { generateSuffix: !id });\n const labelId = `${listId}_label`;\n const buttonId = `${listId}_button`;\n const inputId = `${listId}_search-input`;\n\n const [selectedValue, setSelectedValue] = useState<\n Array<ComboboxValuePair>\n >(value || []);\n const [showMenu, setShowMenu] = useState<boolean>(false);\n const [searchValue, setSearchValue] = useState<string>(\"\");\n const [noResults, setNoResults] = useState(false);\n const [marked, setMarked] = useState<boolean>(false);\n\n const searchRef = useRef<HTMLInputElement>(null);\n const inputRef = useRef<HTMLDivElement>(null);\n const focusInsideRef = useRef(false);\n\n useEffect(() => {\n setSearchValue(\"\");\n if (showMenu && searchRef.current) {\n searchRef.current.focus();\n }\n }, [showMenu]);\n\n useEffect(() => {\n setSelectedValue((prev) => value || prev);\n }, [value]);\n\n // Funksjon for å stile valgt element\n const isSelected = (option: ValuePair) => {\n if (!selectedValue) {\n return false;\n }\n\n return selectedValue.some((value) => value.value === option.value);\n };\n\n // Fjerne ett eller flere valg\n const removeOption = useCallback(\n (option: string) => {\n return selectedValue.filter((value) => value.value !== option);\n },\n [selectedValue],\n );\n\n const onTagRemove = useCallback(\n (\n e:\n | React.MouseEvent<HTMLButtonElement, globalThis.MouseEvent>\n | React.KeyboardEvent<HTMLInputElement>,\n option: string,\n ) => {\n const newValue = removeOption(option);\n setSelectedValue(newValue);\n onChange({\n type: \"change\",\n target: { name, value: option, selectedOptions: newValue },\n });\n e.stopPropagation();\n\n if (newValue.length === 0) {\n setMarked(false);\n }\n },\n [removeOption, onChange, name],\n );\n\n // Håndtere valgt verdi i listen\n const onItemClick = useCallback(\n (option: string) => {\n let newValue: Array<ValuePair>;\n\n if (selectedValue.some((value) => value.value === option)) {\n newValue = removeOption(option);\n } else {\n const item = items.find((i) => i.value === option);\n newValue = [...selectedValue, item as ValuePair];\n }\n searchRef.current?.focus();\n setSelectedValue(newValue);\n onChange({\n type: \"change\",\n target: { name, value: option, selectedOptions: newValue },\n });\n },\n [selectedValue, onChange, name, removeOption, items],\n );\n\n // Funksjon for søk\n const onSearch = (e: {\n target: { value: React.SetStateAction<string> };\n }) => {\n searchRef.current?.focus();\n setShowMenu(true);\n setSearchValue(e.target.value);\n };\n\n const options = useMemo(() => {\n if (!searchValue) {\n return items;\n }\n\n const filteredOptions = items.filter(\n (option) =>\n option.label.toLowerCase().indexOf(searchValue.toLowerCase()) >=\n 0,\n );\n\n setNoResults(filteredOptions.length === 0);\n\n return filteredOptions;\n }, [searchValue, items]);\n\n // Det første elementet i listen skal være aktivt fram til brukeren klikker på noe annet\n const [activeDescendant, setActiveDescendant] = useState<\n string | undefined\n >(options[0]?.value ? `${listId}-${options[0]?.value}` : undefined);\n\n // Håndtere arrow-state\n const isPointingDown = !showMenu;\n\n // Lukk meny med ESC\n useEffect(() => {\n const handleEscape = (e: globalThis.KeyboardEvent) => {\n if (e.key === \"Escape\" && showMenu) {\n setShowMenu(false);\n }\n };\n if (typeof window !== \"undefined\") {\n window.addEventListener(\"keydown\", handleEscape);\n }\n return () => {\n if (typeof window !== \"undefined\" && showMenu) {\n window.removeEventListener(\"keydown\", handleEscape);\n }\n };\n }, [showMenu]);\n\n // Fokushåndtering\n const handleFocusPlacement = useCallback((isOpen: boolean) => {\n if (isOpen) {\n if (searchRef.current) {\n searchRef.current.focus();\n }\n } else {\n if (focusInsideRef.current && inputRef.current) {\n inputRef.current.focus();\n }\n }\n }, []);\n\n const handleFocus = useCallback(() => {\n if (!focusInsideRef.current) {\n if (onFocus) {\n onFocus({\n type: \"change\",\n target: {\n name,\n value: selectedValue?.[0].value || \"\",\n selectedOptions: selectedValue,\n },\n });\n }\n focusInsideRef.current = true;\n setShowMenu(true);\n }\n }, [onFocus, selectedValue, name]);\n\n const [dropdownRef] = useAnimatedHeight<HTMLDivElement>(showMenu, {\n onFirstVisible: handleFocusPlacement,\n onTransitionEnd: handleFocusPlacement,\n });\n\n useListNavigation({ ref: dropdownRef });\n\n const componentRootElementRef = useRef<HTMLDivElement>(null);\n\n const handleBlur = useCallback(\n (\n e: FocusEvent<\n HTMLDivElement | HTMLInputElement | HTMLButtonElement\n >,\n ) => {\n const componentRootElement = componentRootElementRef.current;\n const nextFocusIsInsideComponent = componentRootElement?.contains(\n e.relatedTarget as Node,\n );\n if (!nextFocusIsInsideComponent) {\n setSearchValue(\"\");\n\n if (onBlur) {\n onBlur({\n type: \"blur\",\n target: {\n name,\n value: selectedValue?.[0]?.value || \"\",\n selectedOptions: selectedValue,\n },\n });\n inputRef.current?.dispatchEvent(\n new Event(\"focusout\", { bubbles: true }),\n );\n }\n focusInsideRef.current = false;\n setShowMenu(false);\n }\n },\n [onBlur, name, selectedValue],\n );\n\n const handleMouseOver = useCallback((e: MouseEvent<HTMLButtonElement>) => {\n // Ved mouseOver på options flytter vi fokus til dem for å unngå \"dobbel fokus\"\n // der det ser ut som to forskjellige elementer er fokusert/hovered samtidig\n (e.target as HTMLButtonElement).focus({ preventScroll: true });\n }, []);\n\n // Tastaturnavigasjon\n const handleSearchOnKeyDown = useCallback(\n (e: KeyboardEvent<HTMLInputElement>) => {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n e.stopPropagation();\n const listElement = dropdownRef.current;\n if (listElement) {\n listElement\n .querySelector<HTMLButtonElement>('[role=\"option\"]')\n ?.focus();\n }\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n e.stopPropagation();\n setShowMenu(false);\n }\n\n if ((e.metaKey && e.key === \"a\") || (e.ctrlKey && e.key === \"a\")) {\n e.preventDefault();\n e.stopPropagation();\n const updatedSelectedValue = selectedValue.map((item) => ({\n ...item,\n isMarked: true,\n }));\n setMarked(true);\n setSelectedValue(updatedSelectedValue);\n } else if (e.key === \"Backspace\") {\n e.stopPropagation();\n setMarked(false);\n\n // Sjekk om selectedValue er markert\n const selectedValueIsMarked = selectedValue.some(\n (item) => item.isMarked,\n );\n\n if (selectedValueIsMarked) {\n const updatedSelectedValue = selectedValue.filter(\n (item) => !item.isMarked,\n );\n setSelectedValue(updatedSelectedValue);\n setSearchValue(\"\");\n } else if (selectedValue.length > 0 && searchValue === \"\") {\n // Hvis ingen items er markert, fjern siste valgte item\n onTagRemove(\n e,\n selectedValue[selectedValue.length - 1].value,\n );\n }\n }\n },\n [selectedValue, searchValue, dropdownRef, onTagRemove],\n );\n\n const handleOptionOnKeyDown = useCallback(\n (e: KeyboardEvent<HTMLButtonElement>) => {\n if (e.key === \"Tab\") {\n if (searchRef.current) {\n e.preventDefault();\n e.stopPropagation();\n\n if (e.shiftKey) {\n searchRef.current.focus();\n } else {\n setShowMenu(false);\n searchRef.current.focus();\n }\n }\n } else if (e.key === \"ArrowUp\") {\n if (dropdownRef.current && searchRef.current) {\n // Can't be based on index since the first item might be filtered out\n const firstVisible = dropdownRef.current.querySelector(\n '[role=\"option\"]:not([hidden])',\n );\n if (\n e.currentTarget.id === firstVisible?.id &&\n searchRef.current\n ) {\n searchRef.current.focus();\n }\n }\n }\n },\n [dropdownRef],\n );\n\n const hasSelection = selectedValue.length >= 1;\n\n const renderSelectedOption = useCallback(\n (option: ComboboxValuePair) => (\n <Chip\n key={option.value}\n data-testid=\"jkl-chip\"\n aria-label={`Fjern ${option.tagLabel}`}\n className={`jkl-combobox__selected-option ${\n marked && \"jkl-combobox__selected-option--marked\"\n }`}\n variant=\"input\"\n onClick={(e) => {\n if (searchRef.current) {\n searchRef.current.focus();\n }\n onTagRemove(e, option.value);\n }}\n onBlur={handleBlur}\n >\n {option.tagLabel ? option.tagLabel : option.label}\n </Chip>\n ),\n [handleBlur, onTagRemove, marked],\n );\n\n return (\n <InputGroup\n label={label}\n id={inputId}\n ref={componentRootElementRef}\n data-testid=\"jkl-combobox\"\n data-size={dataSize}\n className={clsx(\"jkl-combobox\", className, {\n \"jkl-combobox--invalid\": !!errorLabel || invalid,\n \"jkl-combobox--menu-open\": showMenu,\n \"jkl-combobox--menu-closed\": !showMenu && hasSelection,\n })}\n labelProps={{\n id: labelId,\n ...labelProps,\n }}\n helpLabel={helpLabel}\n errorLabel={errorLabel}\n description={description}\n tooltip={tooltip}\n render={(inputProps) => (\n <div\n className={clsx(\"jkl-combobox__wrapper\", {\n \"jkl-combobox__wrapper--active-value\": hasSelection,\n })}\n style={{ width }}\n tabIndex={-1}\n onFocus={handleFocus}\n onBlur={handleBlur}\n data-invalid={!!errorLabel || invalid}\n >\n <div\n className=\"jkl-combobox__chips\"\n data-testid=\"jkl-combobox__chips\"\n >\n {selectedValue\n .map(getComboboxValuePair)\n .map((option) => {\n return hasTagHover ? (\n <Tooltip key={option.value}>\n <TooltipTrigger>\n {renderSelectedOption(option)}\n </TooltipTrigger>\n <TooltipContent>\n {option.label}\n </TooltipContent>\n </Tooltip>\n ) : (\n renderSelectedOption(option)\n );\n })}\n <input\n {...inputProps}\n className=\"jkl-combobox__search-input\"\n onChange={onSearch}\n data-testid=\"jkl-combobox__search-input\"\n onFocus={handleFocus}\n onBlur={handleBlur}\n onKeyDown={handleSearchOnKeyDown}\n value={searchValue}\n ref={searchRef}\n aria-controls={listId}\n role=\"combobox\"\n aria-autocomplete=\"list\"\n aria-expanded={showMenu}\n placeholder={\n selectedValue.length > 0 ? \"\" : placeholder\n }\n autoComplete=\"off\"\n />\n </div>\n\n <div\n className=\"jkl-combobox__menu\"\n // biome-ignore lint/a11y/useSemanticElements: Dette er en reimplementering av en liste\n role=\"listbox\"\n ref={dropdownRef}\n id={listId}\n aria-labelledby={labelId}\n aria-multiselectable=\"true\"\n aria-activedescendant={activeDescendant}\n onFocus={handleFocus}\n onBlur={handleBlur}\n tabIndex={-1}\n >\n {options.map((option, i) => (\n <button\n key={`${listId}-${option.value}`}\n type=\"button\"\n id={`${listId}__${option.value}`}\n aria-selected={isSelected(option)}\n // biome-ignore lint/a11y/useSemanticElements: Dette er en reimplementering av en liste\n role=\"option\"\n value={option.value}\n onBlur={handleBlur}\n className={`jkl-combobox__option ${\n isSelected(option) &&\n \"jkl-combobox__option--selected\"\n }`}\n data-testid=\"jkl-combobox__option\"\n data-testautoid={`jkl-combobox__option-${i}`}\n onFocus={handleFocus}\n onKeyDown={handleOptionOnKeyDown}\n onClick={(e) => {\n setActiveDescendant(\n `${listId}__${option.value}`,\n ); // https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/listbox_role#required_javascript_features\n e.stopPropagation();\n onItemClick(option.value);\n setSearchValue(\"\");\n }}\n onMouseOver={handleMouseOver}\n >\n {option.description ? (\n <span>\n {option.label}\n <span className=\"jkl-combobox__option-description\">\n {option.description}\n </span>\n </span>\n ) : (\n option.label\n )}\n {isSelected(option) ? (\n <span>\n <CheckIcon />{\" \"}\n </span>\n ) : null}\n </button>\n ))}\n {noResults && (\n <div className=\"jkl-combobox__no-option\">\n {noMatchingOption}\n </div>\n )}\n </div>\n <IconButton\n id={buttonId}\n onFocus={handleFocus}\n onBlur={handleBlur}\n className=\"jkl-text-input-action-button\"\n data-testid=\"jkl-combobox__button\"\n aria-label=\"Åpne meny\"\n aria-expanded={showMenu}\n aria-controls={listId}\n onClick={() => setShowMenu((previous) => !previous)}\n onMouseDown={(e) => {\n e.preventDefault();\n inputRef.current?.focus();\n }}\n >\n <ArrowVerticalAnimated pointingDown={isPointingDown} />\n </IconButton>\n </div>\n )}\n />\n );\n};\nCombobox.displayName = \"Combobox\";\n"],"names":["getComboboxValuePair","item","value","label","Combobox","props","dataSize","id","placeholder","items","onChange","onFocus","onBlur","noMatchingOption","labelProps","helpLabel","errorLabel","width","name","className","invalid","description","hasTagHover","tooltip","listId","useId","generateSuffix","labelId","buttonId","inputId","selectedValue","setSelectedValue","useState","showMenu","setShowMenu","searchValue","setSearchValue","noResults","setNoResults","marked","setMarked","searchRef","useRef","inputRef","focusInsideRef","useEffect","current","focus","prev","isSelected","option","some","removeOption","useCallback","filter","onTagRemove","e","newValue","type","target","selectedOptions","stopPropagation","length","onItemClick","find","i","onSearch","options","useMemo","filteredOptions","toLowerCase","indexOf","activeDescendant","setActiveDescendant","isPointingDown","handleEscape","key","window","addEventListener","removeEventListener","handleFocusPlacement","isOpen","handleFocus","dropdownRef","useAnimatedHeight","onFirstVisible","onTransitionEnd","useListNavigation","ref","componentRootElementRef","handleBlur","contains","relatedTarget","dispatchEvent","Event","bubbles","handleMouseOver","preventScroll","handleSearchOnKeyDown","preventDefault","listElement","querySelector","metaKey","ctrlKey","updatedSelectedValue","map","isMarked","handleOptionOnKeyDown","shiftKey","firstVisible","currentTarget","hasSelection","renderSelectedOption","jsx","Chip","tagLabel","variant","onClick","children","InputGroup","clsx","render","inputProps","jsxs","style","tabIndex","Tooltip","TooltipTrigger","TooltipContent","onKeyDown","role","autoComplete","onMouseOver","CheckIcon","IconButton","previous","onMouseDown","ArrowVerticalAnimated","pointingDown","displayName"],"mappings":"grBA0BO,SAASA,EACZC,GAEA,MAAuB,iBAATA,EAAoB,CAAEC,MAAOD,EAAME,MAAOF,GAASA,CACrE,CAEO,MAAMG,EAA+BC,IACxC,MACI,YAAaC,EACbC,GAAAA,EACAC,YAAAA,EACAC,MAAAA,EACAC,SAAAA,EACAC,QAAAA,EACAC,OAAAA,EACAV,MAAAA,EACAC,MAAAA,EACAU,iBAAAA,EACAC,WAAAA,EACAC,UAAAA,EACAC,WAAAA,EACAC,MAAAA,EACAC,KAAAA,EACAC,UAAAA,EACAC,QAAAA,EACAC,YAAAA,EACAC,YAAAA,EACAC,QAAAA,GACAlB,EACEmB,EAASC,EAAAA,MAAMlB,GAAM,eAAgB,CAAEmB,gBAAiBnB,IACxDoB,EAAU,GAAGH,UACbI,EAAW,GAAGJ,WACdK,EAAU,GAAGL,kBAEZM,EAAeC,GAAoBC,EAAAA,SAExC9B,GAAS,KACJ+B,EAAUC,GAAeF,EAAAA,UAAkB,IAC3CG,EAAaC,GAAkBJ,EAAAA,SAAiB,KAChDK,EAAWC,GAAgBN,EAAAA,UAAS,IACpCO,EAAQC,GAAaR,EAAAA,UAAkB,GAExCS,EAAYC,EAAAA,OAAyB,MACrCC,EAAWD,EAAAA,OAAuB,MAClCE,EAAiBF,EAAAA,QAAO,GAE9BG,EAAAA,UAAU,KACNT,EAAe,IACXH,GAAYQ,EAAUK,SACtBL,EAAUK,QAAQC,SAEvB,CAACd,IAEJY,EAAAA,UAAU,KACNd,EAAkBiB,GAAS9C,GAAS8C,IACrC,CAAC9C,IAGJ,MAAM+C,EAAcC,KACXpB,G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ACVA,EAAE2C,iBACFxD,EAASG,SAASC,SAGtBuE,SAAAL,EAAAA,IAACwB,EAAAA,sBAAA,CAAsBC,aAAchE,aAO7DtE,EAASuI,YAAc"}
@@ -1 +1 @@
1
- {"version":3,"file":"Icon.cjs","sources":["../../../../src/components/icon/Icon.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport React from \"react\";\nimport type {\n PolymorphicPropsWithRef,\n PolymorphicRef,\n} from \"../../utilities/polymorphism/polymorphism.js\";\nimport type { IconVariant } from \"./types.js\";\n\ntype IconComponentProps<\n ElementType extends \"span\" | \"div\",\n> = PolymorphicPropsWithRef<\n ElementType,\n {\n \"data-testid\"?: string;\n /**\n * Størrelsesvarianten til ikonet. `\"small\"` er 16px med 20px bounding box, og `\"medium\"` er 20px med 24px bounding box.\n * `\"inherit\"` setter størrelsen til ikonet (ikke bounding box) lik skriftstørrelsen (1em).\n */\n variant?: IconVariant;\n /**\n * Angir om ikonet skal vises i fet versjon\n * @default false\n */\n bold?: boolean;\n filled?: boolean;\n className?: string;\n style?: React.CSSProperties;\n }\n>;\n\nexport type IconComponent = (<\n ElementType extends \"span\" | \"div\" = \"span\",\n>(\n props: IconComponentProps<ElementType>,\n) => React.ReactElement | null) & { displayName?: string };\n\nexport const Icon: IconComponent = React.forwardRef(function Icon<\n ElementType extends \"span\" | \"div\" = \"span\",\n>(props: IconComponentProps<ElementType>, ref?: PolymorphicRef<ElementType>) {\n const {\n as = \"span\",\n bold,\n children,\n className,\n filled,\n variant,\n ...iconProps\n } = props;\n const iconClassName = clsx(\"jkl-icon\", className, {\n \"jkl-icon--filled\": filled,\n \"jkl-icon--bold\": bold,\n });\n\n if (as === \"div\") {\n return (\n <div\n aria-hidden\n ref={ref as PolymorphicRef<\"div\">}\n className={iconClassName}\n {...(iconProps as React.HTMLAttributes<HTMLDivElement>)}\n >\n {children}\n </div>\n );\n }\n\n return (\n <span\n aria-hidden\n ref={ref as PolymorphicRef<\"span\">}\n className={iconClassName}\n {...(iconProps as React.HTMLAttributes<HTMLSpanElement>)}\n >\n {children}\n </span>\n );\n}) as IconComponent;\n"],"names":["Icon","forwardRef","props","ref","as","bold","children","className","filled","variant","iconProps","iconClassName","clsx","jsx"],"mappings":"6JAoCaA,mBAA4BC,WAAW,SAElDC,EAAwCC,GACtC,MACIC,GAAAA,EAAK,OACLC,KAAAA,EACAC,SAAAA,EACAC,UAAAA,EACAC,OAAAA,EACAC,QAAAA,KACGC,GACHR,EACES,EAAgBC,EAAAA,KAAK,WAAYL,EAAW,CAC9C,mBAAoBC,EACpB,iBAAkBH,IAGtB,MAAW,QAAPD,EAEIS,EAAAA,IAAC,MAAA,CACG,eAAW,EACXV,IAAAA,EACAI,UAAWI,KACND,EAEJJ,SAAAA,IAMTO,EAAAA,IAAC,OAAA,CACG,eAAW,EACXV,IAAAA,EACAI,UAAWI,KACND,EAEJJ,SAAAA,GAGb"}
1
+ {"version":3,"file":"Icon.cjs","sources":["../../../../src/components/icon/Icon.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport React from \"react\";\nimport type {\n PolymorphicPropsWithRef,\n PolymorphicRef,\n} from \"../../utilities/polymorphism/polymorphism.js\";\nimport type { IconProps } from \"./types.js\";\n\ntype IconComponentProps<ElementType extends \"span\" | \"div\"> =\n PolymorphicPropsWithRef<ElementType, IconProps>;\n\nexport type IconComponent = (<ElementType extends \"span\" | \"div\" = \"span\">(\n props: IconComponentProps<ElementType>,\n) => React.ReactElement | null) & { displayName?: string };\n\nexport const Icon: IconComponent = React.forwardRef(function Icon<\n ElementType extends \"span\" | \"div\" = \"span\",\n>(props: IconComponentProps<ElementType>, ref?: PolymorphicRef<ElementType>) {\n const {\n as = \"span\",\n bold,\n children,\n className,\n filled,\n variant,\n ...iconProps\n } = props;\n const iconClassName = clsx(\"jkl-icon\", className, {\n \"jkl-icon--filled\": filled,\n \"jkl-icon--bold\": bold,\n });\n\n if (as === \"div\") {\n return (\n <div\n aria-hidden\n ref={ref as PolymorphicRef<\"div\">}\n className={iconClassName}\n {...(iconProps as React.HTMLAttributes<HTMLDivElement>)}\n >\n {children}\n </div>\n );\n }\n\n return (\n <span\n aria-hidden\n ref={ref as PolymorphicRef<\"span\">}\n className={iconClassName}\n {...(iconProps as React.HTMLAttributes<HTMLSpanElement>)}\n >\n {children}\n </span>\n );\n}) as IconComponent;\n"],"names":["Icon","forwardRef","props","ref","as","bold","children","className","filled","variant","iconProps","iconClassName","clsx","jsx"],"mappings":"6JAeaA,mBAA4BC,WAAW,SAElDC,EAAwCC,GACtC,MACIC,GAAAA,EAAK,OACLC,KAAAA,EACAC,SAAAA,EACAC,UAAAA,EACAC,OAAAA,EACAC,QAAAA,KACGC,GACHR,EACES,EAAgBC,EAAAA,KAAK,WAAYL,EAAW,CAC9C,mBAAoBC,EACpB,iBAAkBH,IAGtB,MAAW,QAAPD,EAEIS,EAAAA,IAAC,MAAA,CACG,eAAW,EACXV,IAAAA,EACAI,UAAWI,KACND,EAEJJ,SAAAA,IAMTO,EAAAA,IAAC,OAAA,CACG,eAAW,EACXV,IAAAA,EACAI,UAAWI,KACND,EAEJJ,SAAAA,GAGb"}
@@ -1,22 +1,7 @@
1
1
  import { default as React } from 'react';
2
2
  import { PolymorphicPropsWithRef } from '../../utilities/polymorphism/polymorphism.cjs';
3
- import { IconVariant } from './types.cjs';
4
- type IconComponentProps<ElementType extends "span" | "div"> = PolymorphicPropsWithRef<ElementType, {
5
- "data-testid"?: string;
6
- /**
7
- * Størrelsesvarianten til ikonet. `"small"` er 16px med 20px bounding box, og `"medium"` er 20px med 24px bounding box.
8
- * `"inherit"` setter størrelsen til ikonet (ikke bounding box) lik skriftstørrelsen (1em).
9
- */
10
- variant?: IconVariant;
11
- /**
12
- * Angir om ikonet skal vises i fet versjon
13
- * @default false
14
- */
15
- bold?: boolean;
16
- filled?: boolean;
17
- className?: string;
18
- style?: React.CSSProperties;
19
- }>;
3
+ import { IconProps } from './types.cjs';
4
+ type IconComponentProps<ElementType extends "span" | "div"> = PolymorphicPropsWithRef<ElementType, IconProps>;
20
5
  export type IconComponent = (<ElementType extends "span" | "div" = "span">(props: IconComponentProps<ElementType>) => React.ReactElement | null) & {
21
6
  displayName?: string;
22
7
  };
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime");require("react");const e=require("../Icon.cjs"),o=o=>r.jsx(e.Icon,{bold:!0,filled:!0,...o,children:""});o.displayName="ErrorIcon",exports.ErrorIcon=o;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime");require("react");const e=require("../Icon.cjs"),o=o=>r.jsx(e.Icon,{...o,filled:!0,children:""});o.displayName="ErrorIcon",exports.ErrorIcon=o;
2
2
  //# sourceMappingURL=ErrorIcon.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorIcon.cjs","sources":["../../../../../src/components/icon/icons/ErrorIcon.tsx"],"sourcesContent":["import React from \"react\";\nimport { Icon, type IconComponent } from \"../Icon.js\";\nimport type { IconProps } from \"../types.js\";\n\nexport const ErrorIcon: IconComponent = (props: IconProps) => (\n <Icon bold filled {...props}>\n {\"\\ue82a\"}\n </Icon>\n);\nErrorIcon.displayName = \"ErrorIcon\";\n"],"names":["ErrorIcon","props","jsx","Icon","bold","filled","children","displayName"],"mappings":"qKAIaA,EAA4BC,GACrCC,MAACC,EAAAA,KAAA,CAAKC,MAAI,EAACC,QAAM,KAAKJ,EACjBK,SAAA,MAGTN,EAAUO,YAAc"}
1
+ {"version":3,"file":"ErrorIcon.cjs","sources":["../../../../../src/components/icon/icons/ErrorIcon.tsx"],"sourcesContent":["import React from \"react\";\nimport { Icon, type IconComponent } from \"../Icon.js\";\nimport type { IconProps } from \"../types.js\";\n\nexport const ErrorIcon: IconComponent = (props: IconProps) => (\n <Icon {...props} filled>\n {\"\\ue82a\"}\n </Icon>\n);\nErrorIcon.displayName = \"ErrorIcon\";\n"],"names":["ErrorIcon","props","jsx","Icon","filled","children","displayName"],"mappings":"qKAIaA,EAA4BC,GACrCC,EAAAA,IAACC,WAASF,EAAOG,QAAM,EAClBC,SAAA,MAGTL,EAAUM,YAAc"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),c=require("../../../../clsx-E3yX_9sL.cjs");require("react");const r=require("../Icon.cjs"),s=s=>e.jsx(r.Icon,{...s,className:c.clsx("jkl-icon-green-check",s.className),children:""});s.displayName="GreenCheckIcon",exports.GreenCheckIcon=s;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),c=require("../../../../clsx-E3yX_9sL.cjs");require("react");const r=require("../Icon.cjs"),s=({className:s,...n})=>e.jsx(r.Icon,{...n,filled:!0,className:c.clsx("jkl-icon-green-check",s),children:""});s.displayName="GreenCheckIcon",exports.GreenCheckIcon=s;
2
2
  //# sourceMappingURL=GreenCheckIcon.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"GreenCheckIcon.cjs","sources":["../../../../../src/components/icon/icons/GreenCheckIcon.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport React from \"react\";\nimport { Icon, type IconComponent } from \"../Icon.js\";\nimport type { IconProps } from \"../types.js\";\n\nexport const GreenCheckIcon: IconComponent = (props: IconProps) => (\n <Icon {...props} className={clsx(\"jkl-icon-green-check\", props.className)}>\n {\"\\ue5ca\"}\n </Icon>\n);\nGreenCheckIcon.displayName = \"GreenCheckIcon\";\n"],"names":["GreenCheckIcon","props","jsx","Icon","className","clsx","children","displayName"],"mappings":"gNAKaA,EAAiCC,GAC1CC,EAAAA,IAACC,EAAAA,KAAA,IAASF,EAAOG,UAAWC,EAAAA,KAAK,uBAAwBJ,EAAMG,WAC1DE,SAAA,MAGTN,EAAeO,YAAc"}
1
+ {"version":3,"file":"GreenCheckIcon.cjs","sources":["../../../../../src/components/icon/icons/GreenCheckIcon.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport React from \"react\";\nimport { Icon, type IconComponent } from \"../Icon.js\";\nimport type { IconProps } from \"../types.js\";\n\nexport const GreenCheckIcon: IconComponent = ({\n className,\n ...props\n}: IconProps) => (\n <Icon {...props} filled className={clsx(\"jkl-icon-green-check\", className)}>\n {\"\\uf0be\"}\n </Icon>\n);\nGreenCheckIcon.displayName = \"GreenCheckIcon\";\n"],"names":["GreenCheckIcon","className","props","jsx","Icon","filled","clsx","children","displayName"],"mappings":"gNAKaA,EAAgC,EACzCC,UAAAA,KACGC,KAEHC,EAAAA,IAACC,EAAAA,KAAA,IAASF,EAAOG,QAAM,EAACJ,UAAWK,EAAAA,KAAK,uBAAwBL,GAC3DM,SAAA,MAGTP,EAAeQ,YAAc"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime");require("react");const r=require("../Icon.cjs"),o=o=>e.jsx(r.Icon,{bold:!0,filled:!0,...o,children:""});o.displayName="InfoIcon",exports.InfoIcon=o;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime");require("react");const r=require("../Icon.cjs"),o=o=>e.jsx(r.Icon,{...o,filled:!0,children:""});o.displayName="InfoIcon",exports.InfoIcon=o;
2
2
  //# sourceMappingURL=InfoIcon.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"InfoIcon.cjs","sources":["../../../../../src/components/icon/icons/InfoIcon.tsx"],"sourcesContent":["import React from \"react\";\nimport { Icon, type IconComponent } from \"../Icon.js\";\nimport type { IconProps } from \"../types.js\";\n\nexport const InfoIcon: IconComponent = (props: IconProps) => (\n <Icon bold filled {...props}>\n {\"\\ue88e\"}\n </Icon>\n);\nInfoIcon.displayName = \"InfoIcon\";\n"],"names":["InfoIcon","props","jsx","Icon","bold","filled","children","displayName"],"mappings":"qKAIaA,EAA2BC,GACpCC,MAACC,EAAAA,KAAA,CAAKC,MAAI,EAACC,QAAM,KAAKJ,EACjBK,SAAA,MAGTN,EAASO,YAAc"}
1
+ {"version":3,"file":"InfoIcon.cjs","sources":["../../../../../src/components/icon/icons/InfoIcon.tsx"],"sourcesContent":["import React from \"react\";\nimport { Icon, type IconComponent } from \"../Icon.js\";\nimport type { IconProps } from \"../types.js\";\n\nexport const InfoIcon: IconComponent = (props: IconProps) => (\n <Icon {...props} filled>\n {\"\\ue88e\"}\n </Icon>\n);\nInfoIcon.displayName = \"InfoIcon\";\n"],"names":["InfoIcon","props","jsx","Icon","filled","children","displayName"],"mappings":"qKAIaA,EAA2BC,GACpCC,EAAAA,IAACC,WAASF,EAAOG,QAAM,EAClBC,SAAA,MAGTL,EAASM,YAAc"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("../../../../clsx-E3yX_9sL.cjs");require("react");const r=require("../Icon.cjs"),c=c=>e.jsx(r.Icon,{...c,className:s.clsx("jkl-icon-red-cross",c.className),children:""});c.displayName="RedCrossIcon",exports.RedCrossIcon=c;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("../../../../clsx-E3yX_9sL.cjs");require("react");const r=require("../Icon.cjs"),c=({className:c,...o})=>e.jsx(r.Icon,{...o,filled:!0,className:s.clsx("jkl-icon-red-cross",c),children:""});c.displayName="RedCrossIcon",exports.RedCrossIcon=c;
2
2
  //# sourceMappingURL=RedCrossIcon.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"RedCrossIcon.cjs","sources":["../../../../../src/components/icon/icons/RedCrossIcon.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport React from \"react\";\nimport { Icon, type IconComponent } from \"../Icon.js\";\nimport type { IconProps } from \"../types.js\";\n\nexport const RedCrossIcon: IconComponent = (props: IconProps) => (\n <Icon {...props} className={clsx(\"jkl-icon-red-cross\", props.className)}>\n {\"\\ue5cd\"}\n </Icon>\n);\nRedCrossIcon.displayName = \"RedCrossIcon\";\n"],"names":["RedCrossIcon","props","jsx","Icon","className","clsx","children","displayName"],"mappings":"gNAKaA,EAA+BC,GACxCC,EAAAA,IAACC,EAAAA,KAAA,IAASF,EAAOG,UAAWC,EAAAA,KAAK,qBAAsBJ,EAAMG,WACxDE,SAAA,MAGTN,EAAaO,YAAc"}
1
+ {"version":3,"file":"RedCrossIcon.cjs","sources":["../../../../../src/components/icon/icons/RedCrossIcon.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport React from \"react\";\nimport { Icon, type IconComponent } from \"../Icon.js\";\nimport type { IconProps } from \"../types.js\";\n\nexport const RedCrossIcon: IconComponent = ({\n className,\n ...props\n}: IconProps) => (\n <Icon {...props} filled className={clsx(\"jkl-icon-red-cross\", className)}>\n {\"\\ue5c9\"}\n </Icon>\n);\nRedCrossIcon.displayName = \"RedCrossIcon\";\n"],"names":["RedCrossIcon","className","props","jsx","Icon","filled","clsx","children","displayName"],"mappings":"gNAKaA,EAA8B,EACvCC,UAAAA,KACGC,KAEHC,EAAAA,IAACC,EAAAA,KAAA,IAASF,EAAOG,QAAM,EAACJ,UAAWK,EAAAA,KAAK,qBAAsBL,GACzDM,SAAA,MAGTP,EAAaQ,YAAc"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime");require("react");const c=require("../Icon.cjs"),r=r=>e.jsx(c.Icon,{bold:!0,filled:!0,...r,children:""});r.displayName="SuccessIcon",exports.SuccessIcon=r;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime");require("react");const c=require("../Icon.cjs"),r=r=>e.jsx(c.Icon,{...r,filled:!0,children:""});r.displayName="SuccessIcon",exports.SuccessIcon=r;
2
2
  //# sourceMappingURL=SuccessIcon.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"SuccessIcon.cjs","sources":["../../../../../src/components/icon/icons/SuccessIcon.tsx"],"sourcesContent":["import React from \"react\";\nimport { Icon, type IconComponent } from \"../Icon.js\";\nimport type { IconProps } from \"../types.js\";\n\nexport const SuccessIcon: IconComponent = (props: IconProps) => (\n <Icon bold filled {...props}>\n {\"\\uf0be\"}\n </Icon>\n);\nSuccessIcon.displayName = \"SuccessIcon\";\n"],"names":["SuccessIcon","props","jsx","Icon","bold","filled","children","displayName"],"mappings":"qKAIaA,EAA8BC,GACvCC,MAACC,EAAAA,KAAA,CAAKC,MAAI,EAACC,QAAM,KAAKJ,EACjBK,SAAA,MAGTN,EAAYO,YAAc"}
1
+ {"version":3,"file":"SuccessIcon.cjs","sources":["../../../../../src/components/icon/icons/SuccessIcon.tsx"],"sourcesContent":["import React from \"react\";\nimport { Icon, type IconComponent } from \"../Icon.js\";\nimport type { IconProps } from \"../types.js\";\n\nexport const SuccessIcon: IconComponent = (props: IconProps) => (\n <Icon {...props} filled>\n {\"\\uf0be\"}\n </Icon>\n);\nSuccessIcon.displayName = \"SuccessIcon\";\n"],"names":["SuccessIcon","props","jsx","Icon","filled","children","displayName"],"mappings":"qKAIaA,EAA8BC,GACvCC,EAAAA,IAACC,WAASF,EAAOG,QAAM,EAClBC,SAAA,MAGTL,EAAYM,YAAc"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime");require("react");const r=require("../Icon.cjs"),n=n=>e.jsx(r.Icon,{bold:!0,filled:!0,...n,children:""});n.displayName="WarningIcon",exports.WarningIcon=n;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime");require("react");const r=require("../Icon.cjs"),n=n=>e.jsx(r.Icon,{...n,filled:!0,children:""});n.displayName="WarningIcon",exports.WarningIcon=n;
2
2
  //# sourceMappingURL=WarningIcon.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"WarningIcon.cjs","sources":["../../../../../src/components/icon/icons/WarningIcon.tsx"],"sourcesContent":["import React from \"react\";\nimport { Icon, type IconComponent } from \"../Icon.js\";\nimport type { IconProps } from \"../types.js\";\n\nexport const WarningIcon: IconComponent = (props: IconProps) => (\n <Icon bold filled {...props}>\n {\"\\uf083\"}\n </Icon>\n);\nWarningIcon.displayName = \"WarningIcon\";\n"],"names":["WarningIcon","props","jsx","Icon","bold","filled","children","displayName"],"mappings":"qKAIaA,EAA8BC,GACvCC,MAACC,EAAAA,KAAA,CAAKC,MAAI,EAACC,QAAM,KAAKJ,EACjBK,SAAA,MAGTN,EAAYO,YAAc"}
1
+ {"version":3,"file":"WarningIcon.cjs","sources":["../../../../../src/components/icon/icons/WarningIcon.tsx"],"sourcesContent":["import React from \"react\";\nimport { Icon, type IconComponent } from \"../Icon.js\";\nimport type { IconProps } from \"../types.js\";\n\nexport const WarningIcon: IconComponent = (props: IconProps) => (\n <Icon {...props} filled>\n {\"\\uf083\"}\n </Icon>\n);\nWarningIcon.displayName = \"WarningIcon\";\n"],"names":["WarningIcon","props","jsx","Icon","filled","children","displayName"],"mappings":"qKAIaA,EAA8BC,GACvCC,EAAAA,IAACC,WAASF,EAAOG,QAAM,EAClBC,SAAA,MAGTL,EAAYM,YAAc"}
@@ -1,6 +1,5 @@
1
1
  export type IconVariant = "inherit" | "small" | "medium";
2
2
  export interface IconProps {
3
- as?: "div" | "span";
4
3
  "data-testid"?: string;
5
4
  /**
6
5
  * @deprecated Størrelsen settes nå automatisk etter fontstørrelse.
@@ -10,7 +9,7 @@ export interface IconProps {
10
9
  */
11
10
  variant?: IconVariant;
12
11
  /**
13
- * Angir om ikonet skal vises i fet versjon
12
+ * @deprecated Fra Jøkul 5.0 har ikonene alltid samme vekt, og bold har ingen effekt
14
13
  * @default false
15
14
  */
16
15
  bold?: boolean;
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("../../../clsx-E3yX_9sL.cjs"),l=require("react"),i=require("../../hooks/useId/useId.cjs"),s=require("./Label.cjs"),n=require("./SupportLabel.cjs"),t=l.forwardRef((t,a)=>{const{className:o,children:p,errorLabel:d,helpLabel:u,inline:c,label:j,labelProps:b,render:h,supportLabelProps:x,description:m,tooltip:y,id:f,...g}=t,v=i.useId(f||"jkl-input",{generateSuffix:!f}),L=i.useId("jkl-support-label"),S=!!y,k=d||u,q=d?"error":u?"help":void 0,I={"aria-describedby":k?L:void 0,"aria-invalid":!!d||void 0,id:v},w=h?()=>h(I):()=>{const e=l.Children.toArray(t.children)[0];if(l.isValidElement(e))return l.cloneElement(e,{...I,...e.props})};return e.jsxs("div",{ref:a,className:r.clsx(o,"jkl-input-group",{"jkl-input-group--inline":c}),...g,children:[e.jsx(s.Label,{standAlone:!0,htmlFor:v,srOnly:c,...b,style:{whiteSpace:S?"nowrap":void 0,...b?.style},children:S?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{whiteSpace:"normal"},children:j})," ",y]}):j}),m&&e.jsx("p",{className:"jkl-input-group-description",children:m}),w(),e.jsx(n.SupportLabel,{srOnly:c,...x,label:k,labelType:q,id:L})]})});t.displayName="InputGroup",exports.InputGroup=t;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("../../../clsx-E3yX_9sL.cjs"),l=require("react"),i=require("../../hooks/useId/useId.cjs"),s=require("./Label.cjs"),o=require("./SupportLabel.cjs"),n=l.forwardRef((n,t)=>{const{className:a,children:p,errorLabel:d,helpLabel:u,inline:c,label:j,labelProps:b,render:h,supportLabelProps:x,description:m,tooltip:y,id:v,...f}=n,g=i.useId(v||"jkl-input",{generateSuffix:!v}),k=i.useId("jkl-support-label"),I=i.useId("jkl-description"),L=!!y,S=d||u,q=d?"error":u?"help":void 0,w={"aria-describedby":[m?I:void 0,S?k:void 0].filter(Boolean).join(" ")||void 0,"aria-invalid":!!d||void 0,id:g},N=h?()=>h(w):()=>{const e=l.Children.toArray(n.children)[0];if(l.isValidElement(e))return l.cloneElement(e,{...w,...e.props})};return e.jsxs("div",{ref:t,className:r.clsx(a,"jkl-input-group",{"jkl-input-group--inline":c}),...f,children:[e.jsx(s.Label,{standAlone:!0,htmlFor:g,srOnly:c,...b,style:{whiteSpace:L?"nowrap":void 0,...b?.style},children:L?e.jsxs(e.Fragment,{children:[e.jsx("span",{style:{whiteSpace:"normal"},children:j})," ",y]}):j}),m&&e.jsx("p",{id:I,className:"jkl-input-group-description",children:m}),N(),e.jsx(o.SupportLabel,{srOnly:c,...x,label:S,labelType:q,id:k})]})});n.displayName="InputGroup",exports.InputGroup=n;
2
2
  //# sourceMappingURL=InputGroup.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"InputGroup.cjs","sources":["../../../../src/components/input-group/InputGroup.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport React, { forwardRef } from \"react\";\nimport { useId } from \"../../hooks/useId/useId.js\";\nimport { Label } from \"./Label.js\";\nimport { SupportLabel } from \"./SupportLabel.js\";\nimport type { InputGroupProps, InputProps } from \"./types.js\";\n\nexport const InputGroup = forwardRef<HTMLDivElement, InputGroupProps>(\n (props, ref) => {\n const {\n className,\n children,\n errorLabel,\n helpLabel,\n inline,\n label,\n labelProps,\n render,\n supportLabelProps,\n description,\n tooltip,\n id,\n ...rest\n } = props;\n\n const uid = useId(id || \"jkl-input\", { generateSuffix: !id });\n const supportId = useId(\"jkl-support-label\");\n\n const hasTooltip = !!tooltip;\n\n const supportText = errorLabel || helpLabel;\n const supportTextType = errorLabel\n ? \"error\"\n : helpLabel\n ? \"help\"\n : undefined;\n\n const describedBy = supportText ? supportId : undefined;\n\n const inputProps: InputProps = {\n \"aria-describedby\": describedBy,\n \"aria-invalid\": errorLabel ? true : undefined,\n id: uid,\n };\n\n const renderInput = render\n ? () => render(inputProps)\n : () => {\n const input = React.Children.toArray(props.children)[0];\n\n if (!React.isValidElement<InputProps>(input)) return;\n\n return React.cloneElement<InputProps>(input, {\n ...inputProps,\n ...input.props,\n });\n };\n\n return (\n <div\n ref={ref}\n className={clsx(className, \"jkl-input-group\", {\n \"jkl-input-group--inline\": inline,\n })}\n {...rest}\n >\n <Label\n standAlone\n htmlFor={uid}\n srOnly={inline}\n {...labelProps}\n style={{\n whiteSpace: hasTooltip ? \"nowrap\" : undefined,\n ...labelProps?.style,\n }}\n >\n {hasTooltip ? (\n <>\n <span style={{ whiteSpace: \"normal\" }}>\n {label}\n </span>\n {\"\\u00A0\"}\n {tooltip}\n </>\n ) : (\n label\n )}\n </Label>\n {description && (\n <p className=\"jkl-input-group-description\">{description}</p>\n )}\n {renderInput()}\n <SupportLabel\n srOnly={inline}\n {...supportLabelProps}\n label={supportText}\n labelType={supportTextType}\n id={supportId}\n />\n </div>\n );\n },\n);\n\nInputGroup.displayName = \"InputGroup\";\n"],"names":["InputGroup","forwardRef","props","ref","className","children","errorLabel","helpLabel","inline","label","labelProps","render","supportLabelProps","description","tooltip","id","rest","uid","useId","generateSuffix","supportId","hasTooltip","supportText","supportTextType","inputProps","renderInput","input","React","Children","toArray","isValidElement","cloneElement","jsxs","clsx","jsx","Label","standAlone","htmlFor","srOnly","style","whiteSpace","Fragment","SupportLabel","labelType","displayName"],"mappings":"kRAOaA,EAAaC,EAAAA,WACtB,CAACC,EAAOC,KACJ,MACIC,UAAAA,EACAC,SAAAA,EACAC,WAAAA,EACAC,UAAAA,EACAC,OAAAA,EACAC,MAAAA,EACAC,WAAAA,EACAC,OAAAA,EACAC,kBAAAA,EACAC,YAAAA,EACAC,QAAAA,EACAC,GAAAA,KACGC,GACHd,EAEEe,EAAMC,EAAAA,MAAMH,GAAM,YAAa,CAAEI,gBAAiBJ,IAClDK,EAAYF,EAAAA,MAAM,qBAElBG,IAAeP,EAEfQ,EAAchB,GAAcC,EAC5BgB,EAAkBjB,EAClB,QACAC,EACE,YACA,EAIFiB,EAAyB,CAC3B,mBAHgBF,EAAcF,OAAY,EAI1C,iBAAgBd,QAAoB,EACpCS,GAAIE,GAGFQ,EAAcd,EACd,IAAMA,EAAOa,GACb,KACI,MAAME,EAAQC,EAAMC,SAASC,QAAQ3B,EAAMG,UAAU,GAErD,GAAKsB,EAAMG,eAA2BJ,GAEtC,OAAOC,EAAMI,aAAyBL,EAAO,IACtCF,KACAE,EAAMxB,SAIvB,OACI8B,EAAAA,KAAC,MAAA,CACG7B,IAAAA,EACAC,UAAW6B,EAAAA,KAAK7B,EAAW,kBAAmB,CAC1C,0BAA2BI,OAE3BQ,EAEJX,SAAA,CAAA6B,EAAAA,IAACC,EAAAA,MAAA,CACGC,YAAU,EACVC,QAASpB,EACTqB,OAAQ9B,KACJE,EACJ6B,MAAO,CACHC,WAAYnB,EAAa,cAAW,KACjCX,GAAY6B,OAGlBlC,WACG2B,EAAAA,KAAAS,EAAAA,SAAA,CACIpC,SAAA,CAAA6B,MAAC,QAAKK,MAAO,CAAEC,WAAY,UACtBnC,SAAAI,IAEJ,IACAK,KAGLL,IAGPI,GACGqB,EAAAA,IAAC,IAAA,CAAE9B,UAAU,8BAA+BC,SAAAQ,IAE/CY,IACDS,EAAAA,IAACQ,EAAAA,aAAA,CACGJ,OAAQ9B,KACJI,EACJH,MAAOa,EACPqB,UAAWpB,EACXR,GAAIK,SAOxBpB,EAAW4C,YAAc"}
1
+ {"version":3,"file":"InputGroup.cjs","sources":["../../../../src/components/input-group/InputGroup.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport React, { forwardRef } from \"react\";\nimport { useId } from \"../../hooks/useId/useId.js\";\nimport { Label } from \"./Label.js\";\nimport { SupportLabel } from \"./SupportLabel.js\";\nimport type { InputGroupProps, InputProps } from \"./types.js\";\n\nexport const InputGroup = forwardRef<HTMLDivElement, InputGroupProps>(\n (props, ref) => {\n const {\n className,\n children,\n errorLabel,\n helpLabel,\n inline,\n label,\n labelProps,\n render,\n supportLabelProps,\n description,\n tooltip,\n id,\n ...rest\n } = props;\n\n const uid = useId(id || \"jkl-input\", { generateSuffix: !id });\n const supportId = useId(\"jkl-support-label\");\n const descriptionId = useId(\"jkl-description\");\n\n const hasTooltip = !!tooltip;\n\n const supportText = errorLabel || helpLabel;\n const supportTextType = errorLabel\n ? \"error\"\n : helpLabel\n ? \"help\"\n : undefined;\n\n const describedBy =\n [\n description ? descriptionId : undefined,\n supportText ? supportId : undefined,\n ]\n .filter(Boolean)\n .join(\" \") || undefined;\n\n const inputProps: InputProps = {\n \"aria-describedby\": describedBy,\n \"aria-invalid\": errorLabel ? true : undefined,\n id: uid,\n };\n\n const renderInput = render\n ? () => render(inputProps)\n : () => {\n const input = React.Children.toArray(props.children)[0];\n\n if (!React.isValidElement<InputProps>(input)) return;\n\n return React.cloneElement<InputProps>(input, {\n ...inputProps,\n ...input.props,\n });\n };\n\n return (\n <div\n ref={ref}\n className={clsx(className, \"jkl-input-group\", {\n \"jkl-input-group--inline\": inline,\n })}\n {...rest}\n >\n <Label\n standAlone\n htmlFor={uid}\n srOnly={inline}\n {...labelProps}\n style={{\n whiteSpace: hasTooltip ? \"nowrap\" : undefined,\n ...labelProps?.style,\n }}\n >\n {hasTooltip ? (\n <>\n <span style={{ whiteSpace: \"normal\" }}>\n {label}\n </span>\n {\"\\u00A0\"}\n {tooltip}\n </>\n ) : (\n label\n )}\n </Label>\n {description && (\n <p\n id={descriptionId}\n className=\"jkl-input-group-description\"\n >\n {description}\n </p>\n )}\n {renderInput()}\n <SupportLabel\n srOnly={inline}\n {...supportLabelProps}\n label={supportText}\n labelType={supportTextType}\n id={supportId}\n />\n </div>\n );\n },\n);\n\nInputGroup.displayName = \"InputGroup\";\n"],"names":["InputGroup","forwardRef","props","ref","className","children","errorLabel","helpLabel","inline","label","labelProps","render","supportLabelProps","description","tooltip","id","rest","uid","useId","generateSuffix","supportId","descriptionId","hasTooltip","supportText","supportTextType","inputProps","filter","Boolean","join","renderInput","input","React","Children","toArray","isValidElement","cloneElement","jsxs","clsx","jsx","Label","standAlone","htmlFor","srOnly","style","whiteSpace","Fragment","SupportLabel","labelType","displayName"],"mappings":"kRAOaA,EAAaC,EAAAA,WACtB,CAACC,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aAAA,CACGJ,OAAQlC,KACJI,EACJH,MAAOc,EACPwB,UAAWvB,EACXT,GAAIK,SAOxBpB,EAAWgD,YAAc"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../date/formatDate.cjs"),r=require("../fodselsnummer/formatFodselsnummer.cjs"),t=require("../kontonummer/formatKontonummer.cjs"),n=require("../kortnummer/formatKortnummer.cjs"),m=require("../organisasjonsnummer/formatOrganisasjonsnummer.cjs"),s=require("../telefonnummer/formatTelefonnummer.cjs"),o=require("./formatNumber.cjs"),a={date:e.formatDateString,fodselsnummer:r.formatFodselsnummer,kortnummer:n.formatKortnummer,kontonummer:t.formatKontonummer,telefonnummer:s.formatTelefonnummer,number:o.formatNumber,organisasjonsnummer:m.formatOrganisasjonsnummer},u=e=>(r,t,n)=>{let m=0,s="",o="";const u={setValueAs:e=>e.replace(/\s/g,""),onChange:u=>{n?.onChange?.(u);let i=0;const l=u.target.value.length;null!==u.target.selectionStart&&(i=u.target.selectionStart);const g=a[e](u.target.value,{partial:!0}),c=g.toString().length;r.setValue(t,g);let f=null;if(["Delete","Backspace"].includes(s)){const e=m-i,r=""===o.trim()?0:c-l;f=m-e+r}else if(i<u.target.value.length||l!==c){f=i+(c-l)}if(null!==f){const e=((e,r,t)=>Math.min(Math.max(e,r),t))(f,0,c);u.target.setSelectionRange(e,e,void 0)}}};n&&Object.assign(u,n);const i=r.register(t,u),l={onKeyDown:e=>{o="";const r=e.target,{selectionStart:t,selectionEnd:n,value:a}=r;null!==t&&(m=t,null!==n&&n>t?o=a.slice(t,n):"Backspace"===e.key?o=a[m-1]??"":"Delete"===e.key&&(o=a[m]??"")),s=e.key}};return"number"===e&&(l.align="right"),Object.assign(i,l)},i=u("fodselsnummer"),l=u("kortnummer"),g=u("kontonummer"),c=u("telefonnummer");exports.registerWithFodselsnummerMask=i,exports.registerWithKontonummerMask=g,exports.registerWithKortnummerMask=l,exports.registerWithMasks=e=>({registerWithFodselsnummerMask:(r,t)=>u("fodselsnummer")(e,r,t),registerWithKortnummerMask:(r,t)=>u("kortnummer")(e,r,t),registerWithKontonummerMask:(r,t)=>u("kontonummer")(e,r,t),registerWithTelefonnummerMask:(r,t)=>u("telefonnummer")(e,r,t),registerWithOrganisasjonsnummerMask:(r,t)=>u("organisasjonsnummer")(e,r,t),registerWithDateMask:(r,t)=>u("date")(e,r,t),registerWithNumber:(r,t)=>u("number")(e,r,t)}),exports.registerWithTelefonnummerMask=c;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../date/formatDate.cjs"),r=require("../fodselsnummer/formatFodselsnummer.cjs"),t=require("../kontonummer/formatKontonummer.cjs"),n=require("../kortnummer/formatKortnummer.cjs"),s=require("../organisasjonsnummer/formatOrganisasjonsnummer.cjs"),m=require("../telefonnummer/formatTelefonnummer.cjs"),o=require("./formatNumber.cjs"),a={date:e.formatDateString,fodselsnummer:r.formatFodselsnummer,kortnummer:n.formatKortnummer,kontonummer:t.formatKontonummer,telefonnummer:m.formatTelefonnummer,number:o.formatNumber,organisasjonsnummer:s.formatOrganisasjonsnummer},u=e=>(r,t,n)=>{let s=0,m="",o="";const u={setValueAs:e=>e.replace(/\s/g,""),onChange:u=>{n?.onChange?.(u);let i=0;const l=u.target.value.length;null!==u.target.selectionStart&&(i=u.target.selectionStart);const g=a[e](u.target.value,{partial:!0}),c=g.toString().length;r.setValue(t,g);let f=null;if(["Delete","Backspace"].includes(m)){const e=s-i,r=""===o.trim()?0:c-l;f=s-e+r}else if(i<u.target.value.length||l!==c){f=i+(c-l)}if(null!==f){const e=((e,r,t)=>Math.min(Math.max(e,r),t))(f,0,c);u.target.setSelectionRange(e,e,void 0)}}};n&&Object.assign(u,n);const i=r.register(t,u);return Object.assign(i,{onKeyDown:e=>{o="";const r=e.target,{selectionStart:t,selectionEnd:n,value:a}=r;null!==t&&(s=t,null!==n&&n>t?o=a.slice(t,n):"Backspace"===e.key?o=a[s-1]??"":"Delete"===e.key&&(o=a[s]??"")),m=e.key}})},i=u("fodselsnummer"),l=u("kortnummer"),g=u("kontonummer"),c=u("telefonnummer");exports.registerWithFodselsnummerMask=i,exports.registerWithKontonummerMask=g,exports.registerWithKortnummerMask=l,exports.registerWithMasks=e=>({registerWithFodselsnummerMask:(r,t)=>u("fodselsnummer")(e,r,t),registerWithKortnummerMask:(r,t)=>u("kortnummer")(e,r,t),registerWithKontonummerMask:(r,t)=>u("kontonummer")(e,r,t),registerWithTelefonnummerMask:(r,t)=>u("telefonnummer")(e,r,t),registerWithOrganisasjonsnummerMask:(r,t)=>u("organisasjonsnummer")(e,r,t),registerWithDateMask:(r,t)=>u("date")(e,r,t),registerWithNumber:(r,t)=>u("number")(e,r,t)}),exports.registerWithTelefonnummerMask=c;
2
2
  //# sourceMappingURL=registerWithMask.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"registerWithMask.cjs","sources":["../../../../../src/utilities/formatters/util/registerWithMask.ts"],"sourcesContent":["import type { ChangeEvent, KeyboardEventHandler } from \"react\";\nimport type {\n FieldValues,\n Path,\n PathValue,\n RegisterOptions,\n UseFormRegisterReturn,\n UseFormReturn,\n} from \"react-hook-form\";\nimport { formatDateString } from \"../date/formatDate.js\";\nimport { formatFodselsnummer } from \"../fodselsnummer/formatFodselsnummer.js\";\nimport { formatKontonummer } from \"../kontonummer/formatKontonummer.js\";\nimport { formatKortnummer } from \"../kortnummer/formatKortnummer.js\";\nimport { formatOrganisasjonsnummer } from \"../organisasjonsnummer/formatOrganisasjonsnummer.js\";\nimport { formatTelefonnummer } from \"../telefonnummer/formatTelefonnummer.js\";\nimport { formatNumber } from \"./formatNumber.js\";\n\nconst formatters = {\n date: formatDateString,\n fodselsnummer: formatFodselsnummer,\n kortnummer: formatKortnummer,\n kontonummer: formatKontonummer,\n telefonnummer: formatTelefonnummer,\n number: formatNumber,\n organisasjonsnummer: formatOrganisasjonsnummer,\n};\nexport type Formatter = keyof typeof formatters;\n\nconst clamp = (value: number, min: number, max: number) =>\n Math.min(Math.max(value, min), max);\n\nexport type RegisterWithMaskOptions<T extends FieldValues> = Omit<\n RegisterOptions<T>,\n \"setValueAs\"\n>;\n\nconst registerWithMask =\n (formatter: Formatter) =>\n <T extends FieldValues>(\n form: UseFormReturn<T>,\n name: Path<T>,\n options?: RegisterWithMaskOptions<T>,\n ) => {\n let onKeyDownCaretPosition = 0;\n let onKeyDownKeyPressed = \"\";\n let deletedCharactersOnKeyDown = \"\";\n\n const setValueAs = (value: string) => value.replace(/\\s/g, \"\");\n const onChange = (event: ChangeEvent<HTMLInputElement>) => {\n options?.onChange?.(event);\n\n // save some values before event.target.value change\n let onChangeCaretPosition = 0;\n const inputLength = event.target.value.length;\n\n // type checking formalities\n if (event.target.selectionStart !== null) {\n onChangeCaretPosition = event.target.selectionStart;\n }\n\n const formattedValue = formatters[formatter](event.target.value, {\n partial: true,\n });\n const formattedLength = formattedValue.toString().length;\n\n form.setValue(name, formattedValue as PathValue<T, Path<T>>);\n\n let newPosition: number | null = null;\n\n if ([\"Delete\", \"Backspace\"].includes(onKeyDownKeyPressed)) {\n // handle removing content\n // calculate how much to move the caret, this also accounts for removing sections of text\n const delta = onKeyDownCaretPosition - onChangeCaretPosition;\n const formattedLengthChange =\n deletedCharactersOnKeyDown.trim() === \"\"\n ? 0\n : formattedLength - inputLength;\n\n // calculate new caret position (- because we move backwards)\n newPosition =\n onKeyDownCaretPosition - delta + formattedLengthChange;\n } else if (\n onChangeCaretPosition < event.target.value.length ||\n inputLength !== formattedLength\n ) {\n // handle adding content from inside the string\n // calculate how much to move the caret forwards\n const delta = formattedLength - inputLength;\n\n // calculate new caret position (+ because we move forwards)\n newPosition = onChangeCaretPosition + delta;\n }\n\n if (newPosition !== null) {\n const clampedPosition = clamp(newPosition, 0, formattedLength);\n\n event.target.setSelectionRange(\n clampedPosition,\n clampedPosition,\n undefined,\n );\n }\n };\n\n const registerOptions: RegisterOptions<T, Path<T>> = {\n setValueAs,\n onChange,\n };\n if (options) {\n Object.assign(registerOptions, options);\n }\n const register = form.register(name, registerOptions);\n\n // save the caret position before the change occured\n const onKeyDown: KeyboardEventHandler<HTMLInputElement> = (event) => {\n deletedCharactersOnKeyDown = \"\";\n\n const input = event.target as HTMLInputElement;\n const { selectionStart, selectionEnd, value } = input;\n\n if (selectionStart !== null) {\n onKeyDownCaretPosition = selectionStart;\n\n if (selectionEnd !== null && selectionEnd > selectionStart) {\n deletedCharactersOnKeyDown = value.slice(\n selectionStart,\n selectionEnd,\n );\n } else if (event.key === \"Backspace\") {\n deletedCharactersOnKeyDown =\n value[onKeyDownCaretPosition - 1] ?? \"\";\n } else if (event.key === \"Delete\") {\n deletedCharactersOnKeyDown =\n value[onKeyDownCaretPosition] ?? \"\";\n }\n }\n onKeyDownKeyPressed = event.key;\n };\n\n // add onKeyDown event handler to the registered input\n const extra: Record<string, unknown> = {\n onKeyDown,\n };\n\n if (formatter === \"number\") {\n extra.align = \"right\"; // Se https://github.com/fremtind/jokul/pull/2898\n }\n\n return Object.assign(register, extra);\n };\n\n/** @deprecated Bruk `registerWithMasks` i stedet */\nexport const registerWithFodselsnummerMask = registerWithMask(\"fodselsnummer\");\n/** @deprecated Bruk `registerWithMasks` i stedet */\nexport const registerWithKortnummerMask = registerWithMask(\"kortnummer\");\n/** @deprecated Bruk `registerWithMasks` i stedet */\nexport const registerWithKontonummerMask = registerWithMask(\"kontonummer\");\n/** @deprecated Bruk `registerWithMasks` i stedet */\nexport const registerWithTelefonnummerMask = registerWithMask(\"telefonnummer\");\n\n/**\n * Hjelpefunksjon for React Hook Form som lar deg bruke formateringsfunksjonene i denne pakken som inputmasker.\n */\nexport const registerWithMasks = <T extends FieldValues>(\n form: UseFormReturn<T>,\n) => ({\n registerWithFodselsnummerMask: (\n name: Path<T>,\n options?: RegisterWithMaskOptions<T>,\n ): UseFormRegisterReturn =>\n registerWithMask(\"fodselsnummer\")<T>(form, name, options),\n registerWithKortnummerMask: (\n name: Path<T>,\n options?: RegisterWithMaskOptions<T>,\n ): UseFormRegisterReturn =>\n registerWithMask(\"kortnummer\")<T>(form, name, options),\n registerWithKontonummerMask: (\n name: Path<T>,\n options?: RegisterWithMaskOptions<T>,\n ): UseFormRegisterReturn =>\n registerWithMask(\"kontonummer\")<T>(form, name, options),\n registerWithTelefonnummerMask: (\n name: Path<T>,\n options?: RegisterWithMaskOptions<T>,\n ): UseFormRegisterReturn =>\n registerWithMask(\"telefonnummer\")<T>(form, name, options),\n registerWithOrganisasjonsnummerMask: (\n name: Path<T>,\n options?: RegisterWithMaskOptions<T>,\n ): UseFormRegisterReturn =>\n registerWithMask(\"organisasjonsnummer\")<T>(form, name, options),\n registerWithDateMask: (\n name: Path<T>,\n options?: RegisterWithMaskOptions<T>,\n ): UseFormRegisterReturn =>\n registerWithMask(\"date\")<T>(form, name, options),\n registerWithNumber: (\n name: Path<T>,\n options?: RegisterWithMaskOptions<T>,\n ): UseFormRegisterReturn & { align: \"right\" } =>\n registerWithMask(\"number\")<T>(\n form,\n name,\n options,\n ) as unknown as UseFormRegisterReturn & {\n align: \"right\";\n },\n});\n"],"names":["formatters","date","formatDateString","fodselsnummer","formatFodselsnummer","kortnummer","formatKortnummer","kontonummer","formatKontonummer","telefonnummer","formatTelefonnummer","number","formatNumber","organisasjonsnummer","formatOrganisasjonsnummer","registerWithMask","formatter","form","name","options","onKeyDownCaretPosition","onKeyDownKeyPressed","deletedCharactersOnKeyDown","registerOptions","setValueAs","value","replace","onChange","event","onChangeCaretPosition","inputLength","target","length","selectionStart","formattedValue","partial","formattedLength","toString","setValue","newPosition","includes","delta","formattedLengthChange","trim","clampedPosition","min","max","Math","clamp","setSelectionRange","Object","assign","register","extra","onKeyDown","input","selectionEnd","slice","key","align","registerWithFodselsnummerMask","registerWithKortnummerMask","registerWithKontonummerMask","registerWithTelefonnummerMask","registerWithOrganisasjonsnummerMask","registerWithDateMask","registerWithNumber"],"mappings":"0aAiBMA,EAAa,CACfC,KAAMC,EAAAA,iBACNC,cAAeC,EA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,QACZE,eAAAA,EAAgBuB,aAAAA,EAAc/B,MAAAA,GAAU8B,EAEzB,OAAnBtB,IACAb,EAAyBa,EAEJ,OAAjBuB,GAAyBA,EAAevB,EACxCX,EAA6BG,EAAMgC,MAC/BxB,EACAuB,GAEiB,cAAd5B,EAAM8B,IACbpC,EACIG,EAAML,EAAyB,IAAM,GACpB,WAAdQ,EAAM8B,MACbpC,EACIG,EAAML,IAA2B,KAG7CC,EAAsBO,EAAM8B,MAQhC,MAAkB,WAAd1C,IACAqC,EAAMM,MAAQ,SAGXT,OAAOC,OAAOC,EAAUC,IAI1BO,EAAgC7C,EAAiB,iBAEjD8C,EAA6B9C,EAAiB,cAE9C+C,EAA8B/C,EAAiB,eAE/CgD,EAAgChD,EAAiB,8JAM1DE,IAAAA,CAEA2C,8BAA+B,CAC3B1C,EACAC,IAEAJ,EAAiB,gBAAjBA,CAAqCE,EAAMC,EAAMC,GACrD0C,2BAA4B,CACxB3C,EACAC,IAEAJ,EAAiB,aAAjBA,CAAkCE,EAAMC,EAAMC,GAClD2C,4BAA6B,CACzB5C,EACAC,IAEAJ,EAAiB,cAAjBA,CAAmCE,EAAMC,EAAMC,GACnD4C,8BAA+B,CAC3B7C,EACAC,IAEAJ,EAAiB,gBAAjBA,CAAqCE,EAAMC,EAAMC,GACrD6C,oCAAqC,CACjC9C,EACAC,IAEAJ,EAAiB,sBAAjBA,CAA2CE,EAAMC,EAAMC,GAC3D8C,qBAAsB,CAClB/C,EACAC,IAEAJ,EAAiB,OAAjBA,CAA4BE,EAAMC,EAAMC,GAC5C+C,mBAAoB,CAChBhD,EACAC,IAEAJ,EAAiB,SAAjBA,CACIE,EACAC,EACAC"}
1
+ {"version":3,"file":"registerWithMask.cjs","sources":["../../../../../src/utilities/formatters/util/registerWithMask.ts"],"sourcesContent":["import type { ChangeEvent, KeyboardEventHandler } from \"react\";\nimport type {\n FieldValues,\n Path,\n PathValue,\n RegisterOptions,\n UseFormRegisterReturn,\n UseFormReturn,\n} from \"react-hook-form\";\nimport { formatDateString } from \"../date/formatDate.js\";\nimport { formatFodselsnummer } from \"../fodselsnummer/formatFodselsnummer.js\";\nimport { formatKontonummer } from \"../kontonummer/formatKontonummer.js\";\nimport { formatKortnummer } from \"../kortnummer/formatKortnummer.js\";\nimport { formatOrganisasjonsnummer } from \"../organisasjonsnummer/formatOrganisasjonsnummer.js\";\nimport { formatTelefonnummer } from \"../telefonnummer/formatTelefonnummer.js\";\nimport { formatNumber } from \"./formatNumber.js\";\n\nconst formatters = {\n date: formatDateString,\n fodselsnummer: formatFodselsnummer,\n kortnummer: formatKortnummer,\n kontonummer: formatKontonummer,\n telefonnummer: formatTelefonnummer,\n number: formatNumber,\n organisasjonsnummer: formatOrganisasjonsnummer,\n};\nexport type Formatter = keyof typeof formatters;\n\nconst clamp = (value: number, min: number, max: number) =>\n Math.min(Math.max(value, min), max);\n\nexport type RegisterWithMaskOptions<T extends FieldValues> = Omit<\n RegisterOptions<T>,\n \"setValueAs\"\n>;\n\nconst registerWithMask =\n (formatter: Formatter) =>\n <T extends FieldValues>(\n form: UseFormReturn<T>,\n name: Path<T>,\n options?: RegisterWithMaskOptions<T>,\n ) => {\n let onKeyDownCaretPosition = 0;\n let onKeyDownKeyPressed = \"\";\n let deletedCharactersOnKeyDown = \"\";\n\n const setValueAs = (value: string) => value.replace(/\\s/g, \"\");\n const onChange = (event: ChangeEvent<HTMLInputElement>) => {\n options?.onChange?.(event);\n\n // save some values before event.target.value change\n let onChangeCaretPosition = 0;\n const inputLength = event.target.value.length;\n\n // type checking formalities\n if (event.target.selectionStart !== null) {\n onChangeCaretPosition = event.target.selectionStart;\n }\n\n const formattedValue = formatters[formatter](event.target.value, {\n partial: true,\n });\n const formattedLength = formattedValue.toString().length;\n\n form.setValue(name, formattedValue as PathValue<T, Path<T>>);\n\n let newPosition: number | null = null;\n\n if ([\"Delete\", \"Backspace\"].includes(onKeyDownKeyPressed)) {\n // handle removing content\n // calculate how much to move the caret, this also accounts for removing sections of text\n const delta = onKeyDownCaretPosition - onChangeCaretPosition;\n const formattedLengthChange =\n deletedCharactersOnKeyDown.trim() === \"\"\n ? 0\n : formattedLength - inputLength;\n\n // calculate new caret position (- because we move backwards)\n newPosition =\n onKeyDownCaretPosition - delta + formattedLengthChange;\n } else if (\n onChangeCaretPosition < event.target.value.length ||\n inputLength !== formattedLength\n ) {\n // handle adding content from inside the string\n // calculate how much to move the caret forwards\n const delta = formattedLength - inputLength;\n\n // calculate new caret position (+ because we move forwards)\n newPosition = onChangeCaretPosition + delta;\n }\n\n if (newPosition !== null) {\n const clampedPosition = clamp(newPosition, 0, formattedLength);\n\n event.target.setSelectionRange(\n clampedPosition,\n clampedPosition,\n undefined,\n );\n }\n };\n\n const registerOptions: RegisterOptions<T, Path<T>> = {\n setValueAs,\n onChange,\n };\n if (options) {\n Object.assign(registerOptions, options);\n }\n const register = form.register(name, registerOptions);\n\n // save the caret position before the change occured\n const onKeyDown: KeyboardEventHandler<HTMLInputElement> = (event) => {\n deletedCharactersOnKeyDown = \"\";\n\n const input = event.target as HTMLInputElement;\n const { selectionStart, selectionEnd, value } = input;\n\n if (selectionStart !== null) {\n onKeyDownCaretPosition = selectionStart;\n\n if (selectionEnd !== null && selectionEnd > selectionStart) {\n deletedCharactersOnKeyDown = value.slice(\n selectionStart,\n selectionEnd,\n );\n } else if (event.key === \"Backspace\") {\n deletedCharactersOnKeyDown =\n value[onKeyDownCaretPosition - 1] ?? \"\";\n } else if (event.key === \"Delete\") {\n deletedCharactersOnKeyDown =\n value[onKeyDownCaretPosition] ?? \"\";\n }\n }\n onKeyDownKeyPressed = event.key;\n };\n\n // add onKeyDown event handler to the registered input\n const extra: Record<string, unknown> = {\n onKeyDown,\n };\n\n return Object.assign(register, extra);\n };\n\n/** @deprecated Bruk `registerWithMasks` i stedet */\nexport const registerWithFodselsnummerMask = registerWithMask(\"fodselsnummer\");\n/** @deprecated Bruk `registerWithMasks` i stedet */\nexport const registerWithKortnummerMask = registerWithMask(\"kortnummer\");\n/** @deprecated Bruk `registerWithMasks` i stedet */\nexport const registerWithKontonummerMask = registerWithMask(\"kontonummer\");\n/** @deprecated Bruk `registerWithMasks` i stedet */\nexport const registerWithTelefonnummerMask = registerWithMask(\"telefonnummer\");\n\n/**\n * Hjelpefunksjon for React Hook Form som lar deg bruke formateringsfunksjonene i denne pakken som inputmasker.\n */\nexport const registerWithMasks = <T extends FieldValues>(\n form: UseFormReturn<T>,\n) => ({\n registerWithFodselsnummerMask: (\n name: Path<T>,\n options?: RegisterWithMaskOptions<T>,\n ): UseFormRegisterReturn =>\n registerWithMask(\"fodselsnummer\")<T>(form, name, options),\n registerWithKortnummerMask: (\n name: Path<T>,\n options?: RegisterWithMaskOptions<T>,\n ): UseFormRegisterReturn =>\n registerWithMask(\"kortnummer\")<T>(form, name, options),\n registerWithKontonummerMask: (\n name: Path<T>,\n options?: RegisterWithMaskOptions<T>,\n ): UseFormRegisterReturn =>\n registerWithMask(\"kontonummer\")<T>(form, name, options),\n registerWithTelefonnummerMask: (\n name: Path<T>,\n options?: RegisterWithMaskOptions<T>,\n ): UseFormRegisterReturn =>\n registerWithMask(\"telefonnummer\")<T>(form, name, options),\n registerWithOrganisasjonsnummerMask: (\n name: Path<T>,\n options?: RegisterWithMaskOptions<T>,\n ): UseFormRegisterReturn =>\n registerWithMask(\"organisasjonsnummer\")<T>(form, name, options),\n registerWithDateMask: (\n name: Path<T>,\n options?: RegisterWithMaskOptions<T>,\n ): UseFormRegisterReturn =>\n registerWithMask(\"date\")<T>(form, name, options),\n registerWithNumber: (\n name: Path<T>,\n options?: RegisterWithMaskOptions<T>,\n ): UseFormRegisterReturn =>\n registerWithMask(\"number\")<T>(form, name, options),\n});\n"],"names":["formatters","date","formatDateString","fodselsnummer","formatFodselsnummer","kortnummer","formatKortnummer","kontonummer","formatKontonummer","telefonnummer","formatTelefonnummer","number","formatNumber","organisasjonsnummer","formatOrganisasjonsnummer","registerWithMask","formatter","form","name","options","onKeyDownCaretPosition","onKeyDownKeyPressed","deletedCharactersOnKeyDown","registerOptions","setValueAs","value","replace","onChange","event","onChangeCaretPosition","inputLength","target","length","selectionStart","formattedValue","partial","formattedLength","toString","setValue","newPosition","includes","delta","formattedLengthChange","trim","clampedPosition","min","max","Math","clamp","setSelectionRange","Object","assign","register","onKeyDown","input","selectionEnd","slice","key","registerWithFodselsnummerMask","registerWithKortnummerMask","registerWithKontonummerMask","registerWithTelefonnummerMask","registerWithOrganisasjonsnummerMask","registerWithDateMask","registerWithNumber"],"mappings":"0aAiBMA,EAAa,CACfC,KAAMC,EAAAA,iBACNC,cAAeC,EAAAA,oBACfC,WAAYC,EAAAA,iBACZC,YAAaC,EAAAA,kBACbC,cAAeC,EAAAA,oBACfC,OAAQC,EAAAA,aACRC,oBAAqBC,EAAAA,2BAYnBC,EACDC,GACD,CACIC,EACAC,EACAC,KAEA,IAAIC,EAAyB,EACzBC,EAAsB,GACtBC,EAA6B,GA2DjC,MAAMC,EAA+C,CACjDC,WA1DgBC,GAAkBA,EAAMC,QAAQ,MAAO,IA2DvDC,SA1DcC,IACdT,GAASQ,WAAWC,GAGpB,IAAIC,EAAwB,EAC5B,MAAMC,EAAcF,EAAMG,OAAON,MAAMO,OAGH,OAAhCJ,EAAMG,OAAOE,iBACbJ,EAAwBD,EAAMG,OAAOE,gBAGzC,MAAMC,EAAiBlC,EAAWgB,GAAWY,EAAMG,OAAON,MAAO,CAC7DU,SAAS,IAEPC,EAAkBF,EAAeG,WAAWL,OAElDf,EAAKqB,SAASpB,EAAMgB,GAEpB,IAAIK,EAA6B,KAEjC,GAAI,CAAC,SAAU,aAAaC,SAASnB,GAAsB,CAGvD,MAAMoB,EAAQrB,EAAyBS,EACjCa,EACoC,KAAtCpB,EAA2BqB,OACrB,EACAP,EAAkBN,EAG5BS,EACInB,EAAyBqB,EAAQC,CACzC,MAAA,GACIb,EAAwBD,EAAMG,OAAON,MAAMO,QAC3CF,IAAgBM,EAClB,CAMEG,EAAcV,GAHAO,EAAkBN,EAIpC,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,EAAiB,OAAjBA,CAA4BE,EAAMC,EAAMC,GAC5C6C,mBAAoB,CAChB9C,EACAC,IAEAJ,EAAiB,SAAjBA,CAA8BE,EAAMC,EAAMC"}
@@ -35,8 +35,6 @@ export declare const registerWithMasks: <T extends FieldValues>(form: UseFormRet
35
35
  registerWithTelefonnummerMask: (name: Path<T>, options?: RegisterWithMaskOptions<T>) => UseFormRegisterReturn;
36
36
  registerWithOrganisasjonsnummerMask: (name: Path<T>, options?: RegisterWithMaskOptions<T>) => UseFormRegisterReturn;
37
37
  registerWithDateMask: (name: Path<T>, options?: RegisterWithMaskOptions<T>) => UseFormRegisterReturn;
38
- registerWithNumber: (name: Path<T>, options?: RegisterWithMaskOptions<T>) => UseFormRegisterReturn & {
39
- align: "right";
40
- };
38
+ registerWithNumber: (name: Path<T>, options?: RegisterWithMaskOptions<T>) => UseFormRegisterReturn;
41
39
  };
42
40
  export {};
@@ -14,6 +14,7 @@ type Props = {
14
14
  */
15
15
  outlined?: boolean;
16
16
  /**
17
+ * @deprecated Kortet får automatisk riktige stiler dersom det rendres som `button` eller `a`
17
18
  * Angir om kortet visuelt skal fremstå som klikkbart. Du må selv rendre
18
19
  * kortet som et klikkbart element (f.eks. `<a>` eller en `<Link>` fra
19
20
  * et ruting-bibliotek) og gi det en `href` eller `onClick`-handler.
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sources":["../../../../src/components/card/types.ts"],"sourcesContent":["import type { PolymorphicPropsWithRef } from \"../../utilities/polymorphism/polymorphism.js\";\n\nexport const CARD_PADDINGS = [\"s\", \"m\", \"l\", \"xl\"] as const;\nexport type CardPadding = (typeof CARD_PADDINGS)[number];\n\ntype Props = {\n className?: string;\n /**\n * Setter padding på kortet. Tilsvarer samme property i Figma.\n * @default \"s\"\n */\n padding?: CardPadding;\n /**\n * Legger på kantlinje rundt kortet.\n * @default false\n */\n outlined?: boolean;\n /**\n * Angir om kortet visuelt skal fremstå som klikkbart. Du må selv rendre\n * kortet som et klikkbart element (f.eks. `<a>` eller en `<Link>` fra\n * et ruting-bibliotek) og gi det en `href` eller `onClick`-handler.\n * HUSK: Sett aria-label for at støtteverktøy, som skjermlesere, ikke\n * skal lese alt innholdet i kortet.\n */\n clickable?: boolean;\n};\n\nexport type CardProps<ElementType extends React.ElementType> =\n PolymorphicPropsWithRef<ElementType, Props> & Props;\n"],"names":["CARD_PADDINGS"],"mappings":"AAEO,MAAMA,EAAgB,CAAC,IAAK,IAAK,IAAK"}
1
+ {"version":3,"file":"types.js","sources":["../../../../src/components/card/types.ts"],"sourcesContent":["import type { PolymorphicPropsWithRef } from \"../../utilities/polymorphism/polymorphism.js\";\n\nexport const CARD_PADDINGS = [\"s\", \"m\", \"l\", \"xl\"] as const;\nexport type CardPadding = (typeof CARD_PADDINGS)[number];\n\ntype Props = {\n className?: string;\n /**\n * Setter padding på kortet. Tilsvarer samme property i Figma.\n * @default \"s\"\n */\n padding?: CardPadding;\n /**\n * Legger på kantlinje rundt kortet.\n * @default false\n */\n outlined?: boolean;\n /**\n * @deprecated Kortet får automatisk riktige stiler dersom det rendres som `button` eller `a`\n * Angir om kortet visuelt skal fremstå som klikkbart. Du må selv rendre\n * kortet som et klikkbart element (f.eks. `<a>` eller en `<Link>` fra\n * et ruting-bibliotek) og gi det en `href` eller `onClick`-handler.\n * HUSK: Sett aria-label for at støtteverktøy, som skjermlesere, ikke\n * skal lese alt innholdet i kortet.\n */\n clickable?: boolean;\n};\n\nexport type CardProps<ElementType extends React.ElementType> =\n PolymorphicPropsWithRef<ElementType, Props> & Props;\n"],"names":["CARD_PADDINGS"],"mappings":"AAEO,MAAMA,EAAgB,CAAC,IAAK,IAAK,IAAK"}
@@ -1,2 +1,2 @@
1
- import{jsx as e,jsxs as o}from"react/jsx-runtime";import{c as t}from"../../../clsx-BeLtu-UY.js";import{useState as a,useRef as n,useEffect as r,useCallback as l,useMemo as i}from"react";import{useAnimatedHeight as s}from"../../hooks/useAnimatedHeight/useAnimatedHeight.js";import{useId as c}from"../../hooks/useId/useId.js";import{useListNavigation as u}from"../../hooks/useListNavigation/useListNavigation.js";import{Chip as p}from"../chip/Chip.js";import{IconButton as d}from"../icon-button/IconButton.js";import{CheckIcon as m}from"../icon/icons/CheckIcon.js";import{ArrowVerticalAnimated as b}from"../icon/icons/animated/ArrowVerticalAnimated.js";import{InputGroup as f}from"../input-group/InputGroup.js";import{Tooltip as v}from"../tooltip/Tooltip.js";import{TooltipContent as h}from"../tooltip/TooltipContent.js";import{TooltipTrigger as k}from"../tooltip/TooltipTrigger.js";function g(e){return"string"==typeof e?{value:e,label:e}:e}const j=j=>{const{"data-size":x,id:_,placeholder:y,items:w,onChange:C,onFocus:N,onBlur:$,value:L,label:T,noMatchingOption:I,labelProps:B,helpLabel:D,errorLabel:P,width:A,name:E,className:F,invalid:M,description:O,hasTagHover:K}=j,S=c(_||"jkl-combobox",{generateSuffix:!_}),H=`${S}_label`,V=`${S}_button`,q=`${S}_search-input`,[z,G]=a(L||[]),[R,U]=a(!1),[J,Q]=a(""),[W,X]=a(!1),[Y,Z]=a(!1),ee=n(null),oe=n(null),te=n(!1);r(()=>{Q(""),R&&ee.current&&ee.current.focus()},[R]),r(()=>{G(e=>L||e)},[L]);const ae=e=>!!z&&z.some(o=>o.value===e.value),ne=l(e=>z.filter(o=>o.value!==e),[z]),re=l((e,o)=>{const t=ne(o);G(t),C({type:"change",target:{name:E,value:o,selectedOptions:t}}),e.stopPropagation(),0===t.length&&Z(!1)},[ne,C,E]),le=l(e=>{let o;if(z.some(o=>o.value===e))o=ne(e);else{const t=w.find(o=>o.value===e);o=[...z,t]}ee.current?.focus(),G(o),C({type:"change",target:{name:E,value:e,selectedOptions:o}})},[z,C,E,ne,w]),ie=e=>{ee.current?.focus(),U(!0),Q(e.target.value)},se=i(()=>{if(!J)return w;const e=w.filter(e=>e.label.toLowerCase().indexOf(J.toLowerCase())>=0);return X(0===e.length),e},[J,w]),[ce,ue]=a(se[0]?.value?`${S}-${se[0]?.value}`:void 0),pe=!R;r(()=>{const e=e=>{"Escape"===e.key&&R&&U(!1)};return typeof window<"u"&&window.addEventListener("keydown",e),()=>{typeof window<"u"&&R&&window.removeEventListener("keydown",e)}},[R]);const de=l(e=>{e?ee.current&&ee.current.focus():te.current&&oe.current&&oe.current.focus()},[]),me=l(()=>{te.current||(N&&N({type:"change",target:{name:E,value:z?.[0].value||"",selectedOptions:z}}),te.current=!0,U(!0))},[N,z,E]),[be]=s(R,{onFirstVisible:de,onTransitionEnd:de});u({ref:be});const fe=n(null),ve=l(e=>{fe.current?.contains(e.relatedTarget)||(Q(""),$&&($({type:"blur",target:{name:E,value:z?.[0]?.value||"",selectedOptions:z}}),oe.current?.dispatchEvent(new Event("focusout",{bubbles:!0}))),te.current=!1,U(!1))},[$,E,z]),he=l(e=>{e.target.focus({preventScroll:!0})},[]),ke=l(e=>{if("ArrowDown"===e.key){e.preventDefault(),e.stopPropagation();const o=be.current;o&&o.querySelector('[role="option"]')?.focus()}else"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),U(!1));if(e.metaKey&&"a"===e.key||e.ctrlKey&&"a"===e.key){e.preventDefault(),e.stopPropagation();const o=z.map(e=>({...e,isMarked:!0}));Z(!0),G(o)}else if("Backspace"===e.key)if(e.stopPropagation(),Z(!1),z.some(e=>e.isMarked)){const e=z.filter(e=>!e.isMarked);G(e),Q("")}else z.length>0&&""===J&&re(e,z[z.length-1].value)},[z,J,be,re]),ge=l(e=>{if("Tab"===e.key)ee.current&&(e.preventDefault(),e.stopPropagation(),e.shiftKey||U(!1),ee.current.focus());else if("ArrowUp"===e.key&&be.current&&ee.current){const o=be.current.querySelector('[role="option"]:not([hidden])');e.currentTarget.id===o?.id&&ee.current&&ee.current.focus()}},[be]),je=z.length>=1,xe=l(o=>e(p,{"data-testid":"jkl-chip","aria-label":`Fjern ${o.tagLabel}`,className:`jkl-combobox__selected-option ${Y&&"jkl-combobox__selected-option--marked"}`,variant:"input",onClick:e=>{ee.current&&ee.current.focus(),re(e,o.value)},onBlur:ve,children:o.tagLabel?o.tagLabel:o.label},o.value),[ve,re,Y]);return e(f,{label:T,id:q,ref:fe,"data-testid":"jkl-combobox","data-size":x,className:t("jkl-combobox",F,{"jkl-combobox--invalid":!!P||M,"jkl-combobox--menu-open":R,"jkl-combobox--menu-closed":!R&&je}),labelProps:{id:H,...B},helpLabel:D,errorLabel:P,description:O,render:a=>o("div",{className:t("jkl-combobox__wrapper",{"jkl-combobox__wrapper--active-value":je}),style:{width:A},tabIndex:-1,onFocus:me,onBlur:ve,"data-invalid":!!P||M,children:[o("div",{className:"jkl-combobox__chips","data-testid":"jkl-combobox__chips",children:[z.map(g).map(t=>K?o(v,{children:[e(k,{children:xe(t)}),e(h,{children:t.label})]},t.value):xe(t)),e("input",{...a,className:"jkl-combobox__search-input",onChange:ie,"data-testid":"jkl-combobox__search-input",onFocus:me,onBlur:ve,onKeyDown:ke,value:J,ref:ee,"aria-controls":S,role:"combobox","aria-autocomplete":"list","aria-expanded":R,placeholder:z.length>0?"":y,autoComplete:"off"})]}),o("div",{className:"jkl-combobox__menu",role:"listbox",ref:be,id:S,"aria-labelledby":H,"aria-multiselectable":"true","aria-activedescendant":ce,onFocus:me,onBlur:ve,tabIndex:-1,children:[se.map((t,a)=>o("button",{type:"button",id:`${S}__${t.value}`,"aria-selected":ae(t),role:"option",value:t.value,onBlur:ve,className:`jkl-combobox__option ${ae(t)&&"jkl-combobox__option--selected"}`,"data-testid":"jkl-combobox__option","data-testautoid":`jkl-combobox__option-${a}`,onFocus:me,onKeyDown:ge,onClick:e=>{ue(`${S}__${t.value}`),e.stopPropagation(),le(t.value),Q("")},onMouseOver:he,children:[t.description?o("span",{children:[t.label,e("span",{className:"jkl-combobox__option-description",children:t.description})]}):t.label,ae(t)?o("span",{children:[e(m,{})," "]}):null]},`${S}-${t.value}`)),W&&e("div",{className:"jkl-combobox__no-option",children:I})]}),e(d,{id:V,onFocus:me,onBlur:ve,className:"jkl-text-input-action-button","data-testid":"jkl-combobox__button","aria-label":"Åpne meny","aria-expanded":R,"aria-controls":S,onClick:()=>U(e=>!e),onMouseDown:e=>{e.preventDefault(),oe.current?.focus()},children:e(b,{pointingDown:pe})})]})})};j.displayName="Combobox";export{j as Combobox,g as getComboboxValuePair};
1
+ import{jsx as e,jsxs as o}from"react/jsx-runtime";import{c as t}from"../../../clsx-BeLtu-UY.js";import{useState as a,useRef as n,useEffect as r,useCallback as l,useMemo as i}from"react";import{useAnimatedHeight as s}from"../../hooks/useAnimatedHeight/useAnimatedHeight.js";import{useId as c}from"../../hooks/useId/useId.js";import{useListNavigation as u}from"../../hooks/useListNavigation/useListNavigation.js";import{Chip as p}from"../chip/Chip.js";import{IconButton as d}from"../icon-button/IconButton.js";import{CheckIcon as m}from"../icon/icons/CheckIcon.js";import{ArrowVerticalAnimated as b}from"../icon/icons/animated/ArrowVerticalAnimated.js";import{InputGroup as f}from"../input-group/InputGroup.js";import{Tooltip as v}from"../tooltip/Tooltip.js";import{TooltipContent as h}from"../tooltip/TooltipContent.js";import{TooltipTrigger as k}from"../tooltip/TooltipTrigger.js";function g(e){return"string"==typeof e?{value:e,label:e}:e}const j=j=>{const{"data-size":x,id:_,placeholder:y,items:w,onChange:C,onFocus:N,onBlur:$,value:L,label:T,noMatchingOption:I,labelProps:B,helpLabel:D,errorLabel:P,width:A,name:E,className:F,invalid:M,description:O,hasTagHover:K,tooltip:S}=j,H=c(_||"jkl-combobox",{generateSuffix:!_}),V=`${H}_label`,q=`${H}_button`,z=`${H}_search-input`,[G,R]=a(L||[]),[U,J]=a(!1),[Q,W]=a(""),[X,Y]=a(!1),[Z,ee]=a(!1),oe=n(null),te=n(null),ae=n(!1);r(()=>{W(""),U&&oe.current&&oe.current.focus()},[U]),r(()=>{R(e=>L||e)},[L]);const ne=e=>!!G&&G.some(o=>o.value===e.value),re=l(e=>G.filter(o=>o.value!==e),[G]),le=l((e,o)=>{const t=re(o);R(t),C({type:"change",target:{name:E,value:o,selectedOptions:t}}),e.stopPropagation(),0===t.length&&ee(!1)},[re,C,E]),ie=l(e=>{let o;if(G.some(o=>o.value===e))o=re(e);else{const t=w.find(o=>o.value===e);o=[...G,t]}oe.current?.focus(),R(o),C({type:"change",target:{name:E,value:e,selectedOptions:o}})},[G,C,E,re,w]),se=e=>{oe.current?.focus(),J(!0),W(e.target.value)},ce=i(()=>{if(!Q)return w;const e=w.filter(e=>e.label.toLowerCase().indexOf(Q.toLowerCase())>=0);return Y(0===e.length),e},[Q,w]),[ue,pe]=a(ce[0]?.value?`${H}-${ce[0]?.value}`:void 0),de=!U;r(()=>{const e=e=>{"Escape"===e.key&&U&&J(!1)};return typeof window<"u"&&window.addEventListener("keydown",e),()=>{typeof window<"u"&&U&&window.removeEventListener("keydown",e)}},[U]);const me=l(e=>{e?oe.current&&oe.current.focus():ae.current&&te.current&&te.current.focus()},[]),be=l(()=>{ae.current||(N&&N({type:"change",target:{name:E,value:G?.[0].value||"",selectedOptions:G}}),ae.current=!0,J(!0))},[N,G,E]),[fe]=s(U,{onFirstVisible:me,onTransitionEnd:me});u({ref:fe});const ve=n(null),he=l(e=>{ve.current?.contains(e.relatedTarget)||(W(""),$&&($({type:"blur",target:{name:E,value:G?.[0]?.value||"",selectedOptions:G}}),te.current?.dispatchEvent(new Event("focusout",{bubbles:!0}))),ae.current=!1,J(!1))},[$,E,G]),ke=l(e=>{e.target.focus({preventScroll:!0})},[]),ge=l(e=>{if("ArrowDown"===e.key){e.preventDefault(),e.stopPropagation();const o=fe.current;o&&o.querySelector('[role="option"]')?.focus()}else"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),J(!1));if(e.metaKey&&"a"===e.key||e.ctrlKey&&"a"===e.key){e.preventDefault(),e.stopPropagation();const o=G.map(e=>({...e,isMarked:!0}));ee(!0),R(o)}else if("Backspace"===e.key)if(e.stopPropagation(),ee(!1),G.some(e=>e.isMarked)){const e=G.filter(e=>!e.isMarked);R(e),W("")}else G.length>0&&""===Q&&le(e,G[G.length-1].value)},[G,Q,fe,le]),je=l(e=>{if("Tab"===e.key)oe.current&&(e.preventDefault(),e.stopPropagation(),e.shiftKey||J(!1),oe.current.focus());else if("ArrowUp"===e.key&&fe.current&&oe.current){const o=fe.current.querySelector('[role="option"]:not([hidden])');e.currentTarget.id===o?.id&&oe.current&&oe.current.focus()}},[fe]),xe=G.length>=1,_e=l(o=>e(p,{"data-testid":"jkl-chip","aria-label":`Fjern ${o.tagLabel}`,className:`jkl-combobox__selected-option ${Z&&"jkl-combobox__selected-option--marked"}`,variant:"input",onClick:e=>{oe.current&&oe.current.focus(),le(e,o.value)},onBlur:he,children:o.tagLabel?o.tagLabel:o.label},o.value),[he,le,Z]);return e(f,{label:T,id:z,ref:ve,"data-testid":"jkl-combobox","data-size":x,className:t("jkl-combobox",F,{"jkl-combobox--invalid":!!P||M,"jkl-combobox--menu-open":U,"jkl-combobox--menu-closed":!U&&xe}),labelProps:{id:V,...B},helpLabel:D,errorLabel:P,description:O,tooltip:S,render:a=>o("div",{className:t("jkl-combobox__wrapper",{"jkl-combobox__wrapper--active-value":xe}),style:{width:A},tabIndex:-1,onFocus:be,onBlur:he,"data-invalid":!!P||M,children:[o("div",{className:"jkl-combobox__chips","data-testid":"jkl-combobox__chips",children:[G.map(g).map(t=>K?o(v,{children:[e(k,{children:_e(t)}),e(h,{children:t.label})]},t.value):_e(t)),e("input",{...a,className:"jkl-combobox__search-input",onChange:se,"data-testid":"jkl-combobox__search-input",onFocus:be,onBlur:he,onKeyDown:ge,value:Q,ref:oe,"aria-controls":H,role:"combobox","aria-autocomplete":"list","aria-expanded":U,placeholder:G.length>0?"":y,autoComplete:"off"})]}),o("div",{className:"jkl-combobox__menu",role:"listbox",ref:fe,id:H,"aria-labelledby":V,"aria-multiselectable":"true","aria-activedescendant":ue,onFocus:be,onBlur:he,tabIndex:-1,children:[ce.map((t,a)=>o("button",{type:"button",id:`${H}__${t.value}`,"aria-selected":ne(t),role:"option",value:t.value,onBlur:he,className:`jkl-combobox__option ${ne(t)&&"jkl-combobox__option--selected"}`,"data-testid":"jkl-combobox__option","data-testautoid":`jkl-combobox__option-${a}`,onFocus:be,onKeyDown:je,onClick:e=>{pe(`${H}__${t.value}`),e.stopPropagation(),ie(t.value),W("")},onMouseOver:ke,children:[t.description?o("span",{children:[t.label,e("span",{className:"jkl-combobox__option-description",children:t.description})]}):t.label,ne(t)?o("span",{children:[e(m,{})," "]}):null]},`${H}-${t.value}`)),X&&e("div",{className:"jkl-combobox__no-option",children:I})]}),e(d,{id:q,onFocus:be,onBlur:he,className:"jkl-text-input-action-button","data-testid":"jkl-combobox__button","aria-label":"Åpne meny","aria-expanded":U,"aria-controls":H,onClick:()=>J(e=>!e),onMouseDown:e=>{e.preventDefault(),te.current?.focus()},children:e(b,{pointingDown:de})})]})})};j.displayName="Combobox";export{j as Combobox,g as getComboboxValuePair};
2
2
  //# sourceMappingURL=Combobox.js.map