@helsenorge/designsystem-react 2.2.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/HelpBubble.js +1 -1
- package/HelpBubble.js.map +1 -1
- package/Modal.js +1 -1
- package/Modal.js.map +1 -1
- package/__mocks__/MutationObserver.d.ts +6 -0
- package/__mocks__/MutationObserver.d.ts.map +1 -0
- package/__mocks__/MutationObserver.js +2 -0
- package/__mocks__/MutationObserver.js.map +1 -0
- package/components/ButtonWithModal/index.js +1 -1
- package/components/ButtonWithModal/index.js.map +1 -1
- package/components/HelpBubble/HelpBubble.d.ts +3 -3
- package/components/HelpBubble/HelpBubble.d.ts.map +1 -1
- package/components/HelpBubble/componentdata.json +1 -1
- package/components/HelpBubble/index.js +1 -1
- package/components/HelpBubble/styles.module.scss +34 -33
- package/components/HelpBubble/styles.module.scss.d.ts +10 -10
- package/components/HelpBubble/utils.d.ts +27 -0
- package/components/HelpBubble/utils.d.ts.map +1 -0
- package/components/HelpBubbleExample/componentdata.json +1 -1
- package/components/HelpBubbleExample/index.js +1 -1
- package/components/HelpBubbleExample/index.js.map +1 -1
- package/components/HorizontalScroll/styles.module.scss +2 -2
- package/components/LinkList/LinkList.d.ts +4 -0
- package/components/LinkList/LinkList.d.ts.map +1 -1
- package/components/LinkList/index.js +1 -1
- package/components/LinkList/index.js.map +1 -1
- package/components/Modal/Modal.d.ts.map +1 -1
- package/components/Modal/index.js +1 -1
- package/components/Tooltip/index.js +1 -1
- package/components/TooltipExample/index.js +1 -1
- package/components/TooltipExample/index.js.map +1 -1
- package/hooks/useFocusToggle.d.ts +2 -6
- package/hooks/useFocusToggle.d.ts.map +1 -1
- package/hooks/useFocusToggle.js +1 -1
- package/hooks/useFocusToggle.js.map +1 -1
- package/hooks/useFocusTrap.d.ts +7 -1
- package/hooks/useFocusTrap.d.ts.map +1 -1
- package/hooks/useFocusTrap.js +1 -1
- package/hooks/useFocusTrap.js.map +1 -1
- package/hooks/useFocusableElements.d.ts +9 -0
- package/hooks/useFocusableElements.d.ts.map +1 -0
- package/hooks/useFocusableElements.js +2 -0
- package/hooks/useFocusableElements.js.map +1 -0
- package/hooks/useIntersectionObserver.d.ts +1 -1
- package/hooks/useIntersectionObserver.d.ts.map +1 -1
- package/hooks/useIntersectionObserver.js.map +1 -1
- package/hooks/useInterval.d.ts +9 -0
- package/hooks/useInterval.d.ts.map +1 -0
- package/hooks/useInterval.js +2 -0
- package/hooks/useInterval.js.map +1 -0
- package/hooks/useIsVisible.d.ts +1 -1
- package/hooks/useIsVisible.d.ts.map +1 -1
- package/hooks/useIsVisible.js +1 -1
- package/hooks/useIsVisible.js.map +1 -1
- package/hooks/useSize.d.ts +2 -1
- package/hooks/useSize.d.ts.map +1 -1
- package/hooks/useSize.js +1 -1
- package/hooks/useSize.js.map +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/hooks/useGetDOMRect.d.ts +0 -11
- package/hooks/useGetDOMRect.d.ts.map +0 -1
- package/hooks/useGetDOMRect.js +0 -2
- package/hooks/useGetDOMRect.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [2.3.0](https://dev.azure.com/nhnfelles/Helsenorge/_git/HN-Designsystem/branchCompare?baseVersion=GTv2.2.1&targetVersion=GTv2.3.0) (2022-10-31)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* ny hook useFocusableElement ([3294609](https://dev.azure.com/nhnfelles/Helsenorge/_git/HN-Designsystem/commit/32946099ab996597d1a1696a8f8d3d983da9c97e)), closes [#286778](https://dev.azure.com/nhnfelles/Helsenorge/_git/HN-Designsystem/issues/286778)
|
|
7
|
+
|
|
8
|
+
## [2.2.1](https://dev.azure.com/nhnfelles/Helsenorge/_git/HN-Designsystem/branchCompare?baseVersion=GTv2.2.0&targetVersion=GTv2.2.1) (2022-10-25)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* nytt ikon og fiks på confluence script ([0d6d9ea](https://dev.azure.com/nhnfelles/Helsenorge/_git/HN-Designsystem/commit/0d6d9ea492b22ee70c2edbb32440f39739a6ce6d)), closes [#287052](https://dev.azure.com/nhnfelles/Helsenorge/_git/HN-Designsystem/issues/287052)
|
|
14
|
+
|
|
1
15
|
## [2.2.0](https://dev.azure.com/nhnfelles/Helsenorge/_git/HN-Designsystem/branchCompare?baseVersion=GTv2.1.0&targetVersion=GTv2.2.0) (2022-10-25)
|
|
2
16
|
|
|
3
17
|
|
package/HelpBubble.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import w from"classnames";import s,{useRef as A,useState as j}from"react";import{AnalyticsId as Z}from"./constants.js";import{useInterval as q}from"./hooks/useInterval.js";import{useIsVisible as J}from"./hooks/useIsVisible.js";import{useLayoutEvent as K}from"./hooks/useLayoutEvent.js";import{useSize as Q}from"./hooks/useSize.js";import{A as Y}from"./AnchorLink.js";import{C as $}from"./Close.js";import r from"./components/HelpBubble/styles.module.scss";const z=373,b=12,g=16,N=20,S=4,I=12,k=(t,e,i)=>i!==l.positionautomatic?i:t.top>e.height+g?l.positionabove:l.positionbelow,y=t=>t.left+t.width/2,tt=t=>document.documentElement.clientWidth-t.right+t.width/2,p=(t,e)=>y(t)-e.width/2,et=(t,e)=>p(t,e)+e.width,ot=(t,e)=>p(t,e)>b,nt=(t,e)=>et(t,e)<document.documentElement.clientWidth-b,it=(t,e)=>nt(t,e)?ot(t,e)?"floating":"left":"right",P=(t,e)=>t.top-g-e.height,_=t=>t.bottom+g,rt=()=>document.documentElement.clientWidth-b*2,st=()=>document.documentElement.clientWidth>z+b*2,W=t=>t.top-g-S,lt=t=>y(t)-N/2,bt=t=>tt(t)-N/2,ct=(t,e,i)=>{const n=it(t,e),o=k(t,e,i);return n==="left"?o===l.positionabove?"leftabove":"leftbelow":n==="right"?o===l.positionabove?"rightabove":"rightbelow":o===l.positionabove?"floatingabove":"floatingbelow"},ut=(t,e,i)=>{const n=ct(t,e,i),o=st()?void 0:rt();return n==="leftabove"?{left:b,top:P(t,e),width:o}:n==="leftbelow"?{left:b,top:_(t),width:o}:n==="rightabove"?{right:b,top:P(t,e),width:o}:n==="rightbelow"?{right:b,top:_(t),width:o}:n==="floatingbelow"?{left:p(t,e),top:_(t),width:o}:{left:p(t,e),top:P(t,e),width:o}},at=(t,e,i)=>{const n=lt(e),o=bt(e),c=t.left+I,u=t.right+I;return t.right?i===l.positionabove?{right:o>u?o:u,top:W(e)}:{right:o>u?o:u,top:e.bottom}:i===l.positionabove?{left:n>c?n:c,top:W(e)}:{left:n>c?n:c,top:e.bottom}};var l=(t=>(t.positionautomatic="positionautomatic",t.positionbelow="positionbelow",t.positionabove="positionabove",t))(l||{});const xt=t=>{const{helpBubbleId:e,children:i,controllerRef:n,className:o="",variant:c="positionautomatic",showBubble:u,noCloseButton:v,linkText:f="Mer hjelp",linkUrl:x,onLinkClick:R,onClose:T,closeAriaLabel:O,testId:H}=t,B=A(null),F=A(null),h=Q(B),[a,X]=j(),C=J(n,0),L=()=>{var E;X((E=n.current)==null?void 0:E.getBoundingClientRect())};if(q(L,500),K(L,["scroll","resize"],10),!u)return null;const V=w(r.helpbubble,C&&r["helpbubble--visible"],o),m=a&&h&&k(a,h,c),D=w(r.helpbubble__arrow,{[r["helpbubble__arrow--visible"]]:C,[r["helpbubble__arrow--over"]]:m==="positionbelow",[r["helpbubble__arrow--under"]]:m==="positionabove"}),M=w(r.helpbubble__content,{[r["helpbubble__content--close"]]:!v}),d=a&&h&&ut(a,h,c),U=d&&a&&m&&at(d,a,m),G=()=>{if(R&&f)return s.createElement("button",{className:r.helpbubble__link,onClick:R,type:"button"},f);if(x&&f)return s.createElement(Y,{href:x},f)};return s.createElement(s.Fragment,null,s.createElement("div",{id:e,ref:B,className:V,style:d,"data-testid":H,"data-analyticsid":Z.HelpBubble,role:"tooltip"},s.createElement("div",{className:M},i,G()),!v&&s.createElement("div",{className:r.helpbubble__close},s.createElement($,{small:!0,onClick:T,ariaLabel:O}))),s.createElement("div",{ref:F,className:D,style:U}))};export{xt as H,l as a};
|
|
2
2
|
//# sourceMappingURL=HelpBubble.js.map
|
package/HelpBubble.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HelpBubble.js","sources":["../src/components/HelpBubble/HelpBubble.tsx"],"sourcesContent":["import classNames from 'classnames';\nimport React, { useCallback, useEffect, useRef, useState } from 'react';\n\nimport { AnalyticsId } from '../../constants';\nimport { useEventListenerState } from '../../hooks/useEventListenerState';\nimport { useGetDOMRect } from '../../hooks/useGetDOMRect';\nimport AnchorLink from '../AnchorLink';\nimport Close from '../Close';\n\nimport styles from './styles.module.scss';\n\nexport enum HelpBubbleVariant {\n positionautomatic = 'positionautomatic',\n positionbelow = 'positionbelow',\n positionabove = 'positionabove',\n}\n\nexport interface HelpBubbleProps {\n /** Id of the HelpBubble */\n helpBubbleId?: string;\n /** Name to display in the avatar. Will be truncated to the first two characters. */\n children: React.ReactNode;\n /** Ref for the element the HelpBubble is placed upon */\n controllerRef: React.RefObject<HTMLElement | SVGSVGElement>;\n /** Adds custom classes to the element. */\n className?: string;\n /** Determines the placement of the helpbubble */\n variant?: keyof typeof HelpBubbleVariant;\n /** Visible text on the link */\n showBubble?: boolean;\n /** Visible text on the link */\n noCloseButton?: boolean;\n /** Visible text on the link */\n linkText?: string;\n /** Url the link leads to */\n linkUrl?: string;\n /** Function is called when link is clicked */\n onLinkClick?: () => void;\n /** Function is called when user clicks the button */\n onClose?: () => void;\n /** aria-label to be passed onto Close */\n closeAriaLabel?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nconst HelpBubble: React.FC<HelpBubbleProps> = props => {\n const {\n helpBubbleId,\n children,\n controllerRef,\n className = '',\n variant = HelpBubbleVariant.positionautomatic,\n showBubble,\n noCloseButton,\n linkText = 'Mer hjelp',\n linkUrl,\n onLinkClick,\n onClose,\n closeAriaLabel,\n testId,\n } = props;\n\n /* Bredde på HelpBubble */\n const BUBBLE_WIDTH_PX = 373;\n /* Hjelpeboblen skal holde avstand til venstre/høyre kant på vinduet */\n const WINDOW_MARGIN_PX = 12;\n /* Y akse Offset på HelpBubble arrow */\n const ARROW_Y_OFFSET = 3;\n\n let bubblePositionStyle = undefined;\n let arrowPositionStyle = undefined;\n const bubbleRef = useRef<HTMLDivElement>(null);\n const arrowRef = useRef<HTMLDivElement>(null);\n const [controllerDOM, resetControllerDOM] = useGetDOMRect(controllerRef, showBubble, 100);\n const [initialRender, setInitialRender] = useState(true);\n const [eventListenerVariant, setEventListenerVariant] = useEventListenerState(variant);\n const [customBubbleWidth, setCustomBubbleWidth] = useState(0);\n const [translateBubble, setTranslateBubble] = useState({ x: 0, y: 0 });\n const [translateArrow, setTranslateArrow] = useState({ x: 0, y: 0 });\n const [bubbleAbove, setBubbleAbove] = useEventListenerState(variant !== HelpBubbleVariant.positionbelow);\n\n const helpBubbleClasses = classNames(\n styles.helpbubble,\n {\n [styles['helpbubble--initial-render']]: initialRender,\n },\n className\n );\n const arrowClasses = classNames(styles['helpbubble-arrow'], {\n [styles['helpbubble-arrow--initial-render']]: initialRender,\n [styles['helpbubble-arrow--under']]: bubbleAbove.current,\n [styles['helpbubble-arrow--over']]: !bubbleAbove.current,\n });\n\n const checkSpaceAbove = () => {\n if (eventListenerVariant.current === HelpBubbleVariant.positionautomatic && bubbleRef.current && controllerRef.current) {\n const controllerBottom = controllerRef.current.getBoundingClientRect().y;\n const bubbleHeight = bubbleRef.current.getBoundingClientRect().height;\n setBubbleAbove(controllerBottom > bubbleHeight);\n }\n };\n\n const checkBubbleFitsScreenWidth = () => {\n const windowWidth = document.documentElement.clientWidth;\n return windowWidth > BUBBLE_WIDTH_PX + WINDOW_MARGIN_PX * 2;\n };\n\n const updateTranslate = () => {\n if (controllerRef.current && bubbleRef.current && arrowRef.current) {\n // Henter ut størrelser og posisjoner som trengs til kalkulering av HelpBubble posisjonering\n const clientWidth = document.documentElement.clientWidth;\n const controllerX = controllerDOM.x > 0 ? controllerDOM.x : controllerRef.current.getBoundingClientRect().x;\n const controllerY = controllerDOM.y > 0 ? controllerDOM.y : controllerRef.current.getBoundingClientRect().y;\n const controllerSize = controllerRef.current.getBoundingClientRect();\n const bubbleSize = bubbleRef.current.getBoundingClientRect();\n const arrowSize = arrowRef.current.getBoundingClientRect();\n const controllerHalfWidth = controllerSize.width / 2;\n const newBubbleX = getBubbleXAdjustment(bubbleSize.width, controllerX, controllerHalfWidth, clientWidth);\n\n if (!checkBubbleFitsScreenWidth()) {\n setCustomBubbleWidth(clientWidth - WINDOW_MARGIN_PX * 2);\n }\n\n setTranslateBubble({\n x: newBubbleX,\n y: bubbleAbove.current\n ? controllerY - arrowSize.height - bubbleSize.height + ARROW_Y_OFFSET\n : controllerY + controllerSize.height + arrowSize.height - ARROW_Y_OFFSET,\n });\n setTranslateArrow({\n x: controllerX + controllerHalfWidth - arrowSize.width / 2,\n y: bubbleAbove.current ? controllerY - arrowSize.height : controllerY + controllerSize.height,\n });\n }\n };\n\n const getBubbleXAdjustment = (bubbleWidth: number, controllerX: number, controllerHalf: number, clientWidth: number) => {\n const bubbleHalfWidth = bubbleWidth / 2;\n\n // Kalkulerer om HelpBubble går utenfor viewporten\n const controllerXMiddle = controllerX + controllerHalf;\n const bubbleControllerDifferenceX = controllerXMiddle - bubbleHalfWidth;\n const bubbleRightOverlap = clientWidth - controllerXMiddle - bubbleHalfWidth;\n\n // Justerer x akse posisjon utifra funnene over\n const viewportXLeftAdjustment = bubbleControllerDifferenceX < 0 ? bubbleControllerDifferenceX - WINDOW_MARGIN_PX : 0;\n const viewportXRightAdjustment = bubbleRightOverlap < 0 ? bubbleRightOverlap - WINDOW_MARGIN_PX : 0;\n\n // Returnerer den justerte x posisjonen\n const tempBubbleX = controllerX + controllerHalf - bubbleHalfWidth;\n return tempBubbleX - viewportXLeftAdjustment + viewportXRightAdjustment;\n };\n\n const updatePositionStyle = () => {\n if (checkBubbleFitsScreenWidth()) {\n bubblePositionStyle = {\n left: `${translateBubble.x}px`,\n top: `${translateBubble.y}px`,\n };\n } else {\n bubblePositionStyle = {\n left: `${translateBubble.x}px`,\n top: `${translateBubble.y}px`,\n width: `${customBubbleWidth}px`,\n };\n }\n\n arrowPositionStyle = {\n left: `${translateArrow.x}px`,\n top: `${translateArrow.y}px`,\n };\n };\n\n const handleBubbleUpdate = () => {\n checkSpaceAbove();\n updateTranslate();\n };\n\n const handleScroll = useCallback((): void => {\n handleBubbleUpdate();\n }, []);\n\n const handleResize = useCallback((): void => {\n handleBubbleUpdate();\n }, []);\n\n const addEventListeners = () => {\n window.addEventListener('scroll', handleScroll, false);\n window.addEventListener('resize', handleResize, false);\n };\n\n const removeEventListeners = () => {\n window.removeEventListener('scroll', handleScroll, false);\n window.removeEventListener('resize', handleResize, false);\n };\n\n useEffect(() => {\n updateTranslate();\n\n return (): void => {\n removeEventListeners();\n };\n }, []);\n\n useEffect(() => {\n handleBubbleUpdate();\n }, [controllerDOM]);\n\n useEffect(() => {\n if (showBubble) {\n setInitialRender(false);\n addEventListeners();\n handleBubbleUpdate();\n } else if (!showBubble) {\n setInitialRender(true);\n removeEventListeners();\n resetControllerDOM();\n }\n }, [showBubble]);\n\n useEffect(() => {\n setEventListenerVariant(variant);\n setBubbleAbove(variant !== HelpBubbleVariant.positionbelow);\n handleBubbleUpdate();\n }, [variant]);\n\n updatePositionStyle();\n\n const renderLink = () => {\n if (onLinkClick && linkText) {\n return (\n <button className={styles['helpbubble__link-button']} onClick={onLinkClick}>\n {linkText}\n </button>\n );\n } else if (linkUrl && linkText) {\n return <AnchorLink href={linkUrl}>{linkText}</AnchorLink>;\n }\n };\n\n return showBubble ? (\n <>\n <div\n id={helpBubbleId}\n ref={bubbleRef}\n style={bubblePositionStyle}\n className={helpBubbleClasses}\n data-testid={testId}\n data-analyticsid={AnalyticsId.HelpBubble}\n role={'tooltip'}\n >\n <div\n className={classNames(styles['helpbubble__child-wrapper'], {\n [styles['helpbubble__child-wrapper--no-close-button']]: noCloseButton,\n })}\n >\n {children}\n {renderLink()}\n </div>\n {!noCloseButton && (\n <div className={styles['helpbubble__close-wrapper']}>\n <Close small onClick={onClose} ariaLabel={closeAriaLabel} />\n </div>\n )}\n </div>\n <div ref={arrowRef} style={arrowPositionStyle} className={arrowClasses} />\n </>\n ) : null;\n};\n\nexport default HelpBubble;\n"],"names":["HelpBubbleVariant","HelpBubble","props","helpBubbleId","children","controllerRef","className","variant","showBubble","noCloseButton","linkText","linkUrl","onLinkClick","onClose","closeAriaLabel","testId","BUBBLE_WIDTH_PX","WINDOW_MARGIN_PX","ARROW_Y_OFFSET","bubblePositionStyle","arrowPositionStyle","bubbleRef","useRef","arrowRef","controllerDOM","resetControllerDOM","useGetDOMRect","initialRender","setInitialRender","useState","eventListenerVariant","setEventListenerVariant","useEventListenerState","customBubbleWidth","setCustomBubbleWidth","translateBubble","setTranslateBubble","translateArrow","setTranslateArrow","bubbleAbove","setBubbleAbove","helpBubbleClasses","classNames","styles","arrowClasses","checkSpaceAbove","controllerBottom","bubbleHeight","checkBubbleFitsScreenWidth","updateTranslate","clientWidth","controllerX","controllerY","controllerSize","bubbleSize","arrowSize","controllerHalfWidth","newBubbleX","getBubbleXAdjustment","bubbleWidth","controllerHalf","bubbleHalfWidth","controllerXMiddle","bubbleControllerDifferenceX","bubbleRightOverlap","viewportXLeftAdjustment","viewportXRightAdjustment","updatePositionStyle","handleBubbleUpdate","handleScroll","useCallback","handleResize","addEventListeners","removeEventListeners","useEffect","renderLink","React","AnchorLink","AnalyticsId","Close"],"mappings":"0ZAWY,IAAAA,IAAAA,IACVA,EAAA,kBAAoB,oBACpBA,EAAA,cAAgB,gBAChBA,EAAA,cAAgB,gBAHNA,IAAAA,IAAA,CAAA,CAAA,EAmCZ,MAAMC,GAAiDC,GAAA,CAC/C,KAAA,CACJ,aAAAC,EACA,SAAAC,EACA,cA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mBAAkB+D,GAAY,WAC9B,KAAM,SAAA,EAELF,EAAA,cAAA,MAAA,CACC,UAAWlC,EAAWC,EAAO,6BAA8B,CACzD,CAACA,EAAO,+CAAgDlC,CAAA,CACzD,CAAA,EAEAL,EACAuE,IACH,EACC,CAAClE,GACCmE,EAAA,cAAA,MAAA,CAAI,UAAWjC,EAAO,4BAAA,EACpBiC,EAAA,cAAAG,GAAA,CAAM,MAAK,GAAC,QAASlE,EAAS,UAAWC,CAAgB,CAAA,CAC5D,CAEJ,EACC8D,EAAA,cAAA,MAAA,CAAI,IAAKrD,EAAU,MAAOH,EAAoB,UAAWwB,EAAA,CAAc,CAC1E,EACE,IACN"}
|
|
1
|
+
{"version":3,"file":"HelpBubble.js","sources":["../src/components/HelpBubble/utils.ts","../src/components/HelpBubble/HelpBubble.tsx"],"sourcesContent":["import { CSSProperties } from 'react';\nimport { HelpBubbleVariant } from './HelpBubble';\n\ntype HorizontalPosition = 'left' | 'right' | 'floating';\ntype BubblePosition = 'leftabove' | 'leftbelow' | 'rightabove' | 'rightbelow' | 'floatingabove' | 'floatingbelow';\n\n/** Bredde på hjelpeboble */\nconst BUBBLE_WIDTH_PX = 373;\n/** Hjelpeboblen skal holde avstand til venstre/høyre kant på vinduet */\nconst WINDOW_MARGIN_PX = 12;\n/** Vertikal avstand fra hjelpeboble til kontroller */\nconst BUBBLE_VERTICAL_OFFSET_PX = 16;\n/** Høyde/bredde på pil */\nconst ARROW_WIDTH_PX = 20;\n/** Avstand fra pil til hjelpeboble */\nconst ARROW_VERTICAL_OFFSET_PX = 4;\n/** Pilen skal holde avstand til venstre/høyre kant av hjelpeboblen */\nconst ARROW_HORIZONTAL_MARGIN_PX = 12;\n\n/**\n * Beregn om hjelpeboblen skal vises over eller under kontrolleren\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @param variant Ønsket plassering av hjelpeboblen (over/under/automatisk)\n * @returns Om hjelpeboblen skal vises over eller under\n */\nexport const getVerticalPosition = (\n controllerSize: DOMRect,\n bubbleSize: DOMRect,\n variant: keyof typeof HelpBubbleVariant\n): keyof typeof HelpBubbleVariant => {\n if (variant !== HelpBubbleVariant.positionautomatic) {\n return variant;\n }\n if (controllerSize.top > bubbleSize.height + BUBBLE_VERTICAL_OFFSET_PX) {\n return HelpBubbleVariant.positionabove;\n } else {\n return HelpBubbleVariant.positionbelow;\n }\n};\n\n/**\n * Finn horisontalt midtpunkt på kontrolleren i forhold til venstre kant av vinduet\n * @param controllerSize DOMRect for controlleren\n * @returns Horisontalt senter av controlleren i px\n */\nconst getControllerLeftCenterPx = (controllerSize: DOMRect): number => controllerSize.left + controllerSize.width / 2;\n\n/**\n * Finn horisontalt midtpunkt på kontrolleren i forhold til høyre kant av vinduet\n * @param controllerSize DOMRect for controlleren\n * @returns Horisontalt senter av controlleren i px\n */\nconst getControllerRightCenterPx = (controllerSize: DOMRect): number =>\n document.documentElement.clientWidth - controllerSize.right + controllerSize.width / 2;\n\n/**\n * Finn venstre kant av hjelpeboblen i forhold til kontrolleren\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns Venstre kant av hjelpeboblen i px\n */\nconst getBubbleLeftPx = (controllerSize: DOMRect, bubbleSize: DOMRect): number => {\n const controllerHorizontalCenterPx = getControllerLeftCenterPx(controllerSize);\n\n return controllerHorizontalCenterPx - bubbleSize.width / 2;\n};\n\n/**\n * Finn høyre kant av hjelpeboblen i forhold til kontrolleren\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns Høyre kant av hjelpeboblen i px\n */\nconst getBubbleRightPx = (controllerSize: DOMRect, bubbleSize: DOMRect): number => {\n const bubbleLeftPx = getBubbleLeftPx(controllerSize, bubbleSize);\n\n return bubbleLeftPx + bubbleSize.width;\n};\n\n/**\n * Sjekk om venstre kant av hjelpeboblen er innenfor vinduet\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns true dersom venstre kant er innenfor vinduet\n */\nconst getBubbleLeftVisible = (controllerSize: DOMRect, bubbleSize: DOMRect): boolean => {\n const bubbleLeftPx = getBubbleLeftPx(controllerSize, bubbleSize);\n\n return bubbleLeftPx > WINDOW_MARGIN_PX;\n};\n\n/**\n * Sjekk om høyre kant av hjelpeboblen er innenfor vinduet\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns true dersom høyre kant er innenfor vinduet\n */\nconst getBubbleRightIsVisible = (controllerSize: DOMRect, bubbleSize: DOMRect): boolean => {\n const bubbleRightPx = getBubbleRightPx(controllerSize, bubbleSize);\n\n return bubbleRightPx < document.documentElement.clientWidth - WINDOW_MARGIN_PX;\n};\n\n/**\n * Finn riktig horisontal plassering til hjelpeboblen\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns left, right eller floating\n */\nconst getHorizontalPosition = (controllerSize: DOMRect, bubbleSize: DOMRect): HorizontalPosition => {\n if (!getBubbleRightIsVisible(controllerSize, bubbleSize)) {\n return 'right';\n }\n if (!getBubbleLeftVisible(controllerSize, bubbleSize)) {\n return 'left';\n }\n\n return 'floating';\n};\n\n/**\n * Finn vertikal plassering av hjelpeboblen når den skal vises over\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns \"Top\" for hjelpeboblen i px\n */\nconst getBubbleAbovePx = (controllerSize: DOMRect, bubbleSize: DOMRect): number =>\n controllerSize.top - BUBBLE_VERTICAL_OFFSET_PX - bubbleSize.height;\n\n/**\n * Finn vertikal plassering av hjelpeboblen når den skal vises under\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @returns \"Top\" for hjelpeboblen i px\n */\nconst getBubbleBelowPx = (controllerSize: DOMRect): number => controllerSize.bottom + BUBBLE_VERTICAL_OFFSET_PX;\n\n/**\n * Finn maks bredde på hjelpeboblen i forhold til vinduet\n * @returns Bredde på hjelpeboblen i px\n */\nconst getBubbleWidth = (): number => document.documentElement.clientWidth - WINDOW_MARGIN_PX * 2;\n\n/**\n * Sjekk om hjelpeboblen har plass i vinduet\n * @returns true dersom det er plass til hjelpeboblen i vinduet\n */\nconst getBubbleFitsInWindow = (): boolean => {\n return document.documentElement.clientWidth > BUBBLE_WIDTH_PX + WINDOW_MARGIN_PX * 2;\n};\n\n/**\n * Finn vertikal plassering av pilen når den skal vises over\n * @param controllerSize DOMRect for controlleren\n * @returns \"Top\" for pilen i px\n */\nconst getArrowTopxPx = (controllerSize: DOMRect): number => controllerSize.top - BUBBLE_VERTICAL_OFFSET_PX - ARROW_VERTICAL_OFFSET_PX;\n\n/**\n * Finn horisontal plassering av pilen i forhold til venstre kant av vinduet\n * @param controllerSize DOMRect for controlleren\n * @returns Venstre kant av pilen i px\n */\nconst getArrowLeftPx = (controllerSize: DOMRect): number => getControllerLeftCenterPx(controllerSize) - ARROW_WIDTH_PX / 2;\n\n/**\n * Finn horisontal plassering av pilen\n * @param controllerSize DOMRect for controlleren\n * @returns Venstre kant av pilen i px\n */\nconst getArrowRightPx = (controllerSize: DOMRect): number => getControllerRightCenterPx(controllerSize) - ARROW_WIDTH_PX / 2;\n\n/**\n * Finn riktig plassering av hjelpeboblen\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @param variant Ønsket plassering av hjelpeboblen (over/under)\n * @returns Beste mulige plassering av hjelpeboblen\n */\nconst getBubblePosition = (controllerSize: DOMRect, bubbleSize: DOMRect, variant: keyof typeof HelpBubbleVariant): BubblePosition => {\n const horizontalPosition = getHorizontalPosition(controllerSize, bubbleSize);\n const verticalPosition = getVerticalPosition(controllerSize, bubbleSize, variant);\n\n if (horizontalPosition === 'left') {\n if (verticalPosition === HelpBubbleVariant.positionabove) {\n return 'leftabove';\n }\n return 'leftbelow';\n }\n\n if (horizontalPosition === 'right') {\n if (verticalPosition === HelpBubbleVariant.positionabove) {\n return 'rightabove';\n }\n return 'rightbelow';\n }\n\n if (verticalPosition === HelpBubbleVariant.positionabove) {\n return 'floatingabove';\n }\n\n return 'floatingbelow';\n};\n\n/**\n * Finn riktig plassering av hjelpeboblen\n * @param controllerSize DOMRect for controlleren\n * @param bubbleSize DOMRect for hjelpeboblen\n * @param variant Ønsket plassering av hjelpeboblen (over/under)\n * @returns CSSProperties som plasserer hjelpeboblen riktig\n */\nexport const getBubbleStyle = (controllerSize: DOMRect, bubbleSize: DOMRect, variant: keyof typeof HelpBubbleVariant): CSSProperties => {\n const bubblePosition = getBubblePosition(controllerSize, bubbleSize, variant);\n const bubbleWidth = !getBubbleFitsInWindow() ? getBubbleWidth() : undefined;\n\n if (bubblePosition === 'leftabove') {\n return {\n left: WINDOW_MARGIN_PX,\n top: getBubbleAbovePx(controllerSize, bubbleSize),\n width: bubbleWidth,\n };\n }\n if (bubblePosition === 'leftbelow') {\n return { left: WINDOW_MARGIN_PX, top: getBubbleBelowPx(controllerSize), width: bubbleWidth };\n }\n if (bubblePosition === 'rightabove') {\n return { right: WINDOW_MARGIN_PX, top: getBubbleAbovePx(controllerSize, bubbleSize), width: bubbleWidth };\n }\n if (bubblePosition === 'rightbelow') {\n return { right: WINDOW_MARGIN_PX, top: getBubbleBelowPx(controllerSize), width: bubbleWidth };\n }\n\n if (bubblePosition === 'floatingbelow') {\n return { left: getBubbleLeftPx(controllerSize, bubbleSize), top: getBubbleBelowPx(controllerSize), width: bubbleWidth };\n }\n\n return { left: getBubbleLeftPx(controllerSize, bubbleSize), top: getBubbleAbovePx(controllerSize, bubbleSize), width: bubbleWidth };\n};\n\n/**\n * Finn riktig plassering av pilen\n * @param bubbleStyle CSSProperties for hjelpeboblen\n * @param controllerSize DOMRect for kontrolleren\n * @param verticalPosition Ønsket plassering av hjelpeboblen (over/under)\n * @returns CSSProperties som plasserer pilen riktig\n */\nexport const getArrowStyle = (\n bubbleStyle: CSSProperties,\n controllerSize: DOMRect,\n verticalPosition: keyof typeof HelpBubbleVariant\n): CSSProperties => {\n const leftPx = getArrowLeftPx(controllerSize);\n const rightPx = getArrowRightPx(controllerSize);\n const minLeftPx = (bubbleStyle.left as number) + ARROW_HORIZONTAL_MARGIN_PX;\n const minRightPx = (bubbleStyle.right as number) + ARROW_HORIZONTAL_MARGIN_PX;\n\n if (bubbleStyle.right) {\n if (verticalPosition === HelpBubbleVariant.positionabove) {\n return {\n right: rightPx > minRightPx ? rightPx : minRightPx,\n top: getArrowTopxPx(controllerSize),\n };\n }\n\n return {\n right: rightPx > minRightPx ? rightPx : minRightPx,\n top: controllerSize.bottom,\n };\n }\n\n if (verticalPosition === HelpBubbleVariant.positionabove) {\n return {\n left: leftPx > minLeftPx ? leftPx : minLeftPx,\n top: getArrowTopxPx(controllerSize),\n };\n }\n\n return {\n left: leftPx > minLeftPx ? leftPx : minLeftPx,\n top: controllerSize.bottom,\n };\n};\n","import classNames from 'classnames';\nimport React, { useRef, useState } from 'react';\n\nimport { AnalyticsId } from '../../constants';\nimport { useInterval } from '../../hooks/useInterval';\nimport { useIsVisible } from '../../hooks/useIsVisible';\nimport { useLayoutEvent } from '../../hooks/useLayoutEvent';\nimport { useSize } from '../../hooks/useSize';\nimport AnchorLink from '../AnchorLink';\nimport Close from '../Close';\n\nimport styles from './styles.module.scss';\nimport { getArrowStyle, getBubbleStyle, getVerticalPosition } from './utils';\n\nexport enum HelpBubbleVariant {\n positionautomatic = 'positionautomatic',\n positionbelow = 'positionbelow',\n positionabove = 'positionabove',\n}\n\nexport interface HelpBubbleProps {\n /** Id of the HelpBubble */\n helpBubbleId?: string;\n /** Name to display in the avatar. Will be truncated to the first two characters. */\n children: React.ReactNode;\n /** Ref for the element the HelpBubble is placed upon */\n controllerRef: React.RefObject<HTMLElement | SVGSVGElement>;\n /** Adds custom classes to the element. */\n className?: string;\n /** Determines the placement of the helpbubble. Default: automatic positioning. */\n variant?: keyof typeof HelpBubbleVariant;\n /** Show the bubble. Default: false. */\n showBubble?: boolean;\n /** Hide the close button in the bubble */\n noCloseButton?: boolean;\n /** Visible text on the link */\n linkText?: string;\n /** Url the link leads to */\n linkUrl?: string;\n /** Function is called when link is clicked */\n onLinkClick?: () => void;\n /** Function is called when user clicks the button */\n onClose?: () => void;\n /** aria-label to be passed onto Close */\n closeAriaLabel?: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nconst HelpBubble: React.FC<HelpBubbleProps> = props => {\n const {\n helpBubbleId,\n children,\n controllerRef,\n className = '',\n variant = HelpBubbleVariant.positionautomatic,\n showBubble,\n noCloseButton,\n linkText = 'Mer hjelp',\n linkUrl,\n onLinkClick,\n onClose,\n closeAriaLabel,\n testId,\n } = props;\n\n const bubbleRef = useRef<HTMLDivElement>(null);\n const arrowRef = useRef<HTMLDivElement>(null);\n const bubbleSize = useSize(bubbleRef);\n const [controllerSize, setControllerSize] = useState<DOMRect>();\n const controllerisVisible = useIsVisible(controllerRef, 0);\n\n const updateControllerSize = (): void => {\n setControllerSize(controllerRef.current?.getBoundingClientRect());\n };\n\n useInterval(updateControllerSize, 500);\n useLayoutEvent(updateControllerSize, ['scroll', 'resize'], 10);\n\n if (!showBubble) {\n return null;\n }\n\n const helpBubbleClasses = classNames(styles.helpbubble, controllerisVisible && styles['helpbubble--visible'], className);\n const verticalPosition = controllerSize && bubbleSize && getVerticalPosition(controllerSize, bubbleSize, variant);\n const arrowClasses = classNames(styles.helpbubble__arrow, {\n [styles['helpbubble__arrow--visible']]: controllerisVisible,\n [styles['helpbubble__arrow--over']]: verticalPosition === HelpBubbleVariant.positionbelow,\n [styles['helpbubble__arrow--under']]: verticalPosition === HelpBubbleVariant.positionabove,\n });\n const contentClasses = classNames(styles.helpbubble__content, {\n [styles['helpbubble__content--close']]: !noCloseButton,\n });\n\n const bubbleStyle = controllerSize && bubbleSize && getBubbleStyle(controllerSize, bubbleSize, variant);\n const arrowStyle = bubbleStyle && controllerSize && verticalPosition && getArrowStyle(bubbleStyle, controllerSize, verticalPosition);\n\n const renderLink = (): JSX.Element | undefined => {\n if (onLinkClick && linkText) {\n return (\n <button className={styles.helpbubble__link} onClick={onLinkClick} type=\"button\">\n {linkText}\n </button>\n );\n } else if (linkUrl && linkText) {\n return <AnchorLink href={linkUrl}>{linkText}</AnchorLink>;\n }\n };\n\n return (\n <>\n <div\n id={helpBubbleId}\n ref={bubbleRef}\n className={helpBubbleClasses}\n style={bubbleStyle}\n data-testid={testId}\n data-analyticsid={AnalyticsId.HelpBubble}\n role={'tooltip'}\n >\n <div className={contentClasses}>\n {children}\n {renderLink()}\n </div>\n {!noCloseButton && (\n <div className={styles.helpbubble__close}>\n <Close small onClick={onClose} ariaLabel={closeAriaLabel} />\n </div>\n )}\n </div>\n <div ref={arrowRef} className={arrowClasses} style={arrowStyle} />\n </>\n );\n};\n\nexport default HelpBubble;\n"],"names":["BUBBLE_WIDTH_PX","WINDOW_MARGIN_PX","BUBBLE_VERTICAL_OFFSET_PX","ARROW_WIDTH_PX","ARROW_VERTICAL_OFFSET_PX","ARROW_HORIZONTAL_MARGIN_PX","getVerticalPosition","controllerSize","bubbleSize","variant","HelpBubbleVariant","getControllerLeftCenterPx","getControllerRightCenterPx","getBubbleLeftPx","getBubbleRightPx","getBubbleLeftVisible","getBubbleRightIsVisible","getHorizontalPosition","getBubbleAbovePx","getBubbleBelowPx","getBubbleWidth","getBubbleFitsInWindow","getArrowTopxPx","getArrowLeftPx","getArrowRightPx","getBubblePosition","horizontalPosition","verticalPosition","getBubbleStyle","bubblePosition","bubbleWidth","getArrowStyle","bubbleStyle","leftPx","rightPx","minLeftPx","minRightPx","HelpBubble","props","helpBubbleId","children","controllerRef","className","showBubble","noCloseButton","linkText","linkUrl","onLinkClick","onClose","closeAriaLabel","testId","bubbleRef","useRef","arrowRef","useSize","setControllerSize","useState","controllerisVisible","useIsVisible","updateControllerSize","_a","useInterval","useLayoutEvent","helpBubbleClasses","classNames","styles","arrowClasses","contentClasses","arrowStyle","renderLink","React","AnchorLink","AnalyticsId","Close"],"mappings":"wcAOA,MAAMA,EA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EAAO,oBAAqB,CAC5D,CAACA,EAAO,+BAAgC,CAACrB,CAAA,CAC1C,EAEKZ,EAAczB,GAAkBC,GAAcoB,GAAerB,EAAgBC,EAAYC,CAAO,EAChG2D,EAAapC,GAAezB,GAAkBoB,GAAoBI,GAAcC,EAAazB,EAAgBoB,CAAgB,EAE7H0C,EAAa,IAA+B,CAChD,GAAItB,GAAeF,EACjB,OACGyB,EAAA,cAAA,SAAA,CAAO,UAAWL,EAAO,iBAAkB,QAASlB,EAAa,KAAK,QAAA,EACpEF,CACH,EAEJ,GAAWC,GAAWD,EACpB,OAAQyB,EAAA,cAAAC,EAAA,CAAW,KAAMzB,CAAA,EAAUD,CAAS,CAC9C,EAGF,uCAEKyB,EAAA,cAAA,MAAA,CACC,GAAI/B,EACJ,IAAKY,EACL,UAAWY,EACX,MAAO/B,EACP,cAAakB,EACb,mBAAkBsB,EAAY,WAC9B,KAAM,SAAA,EAELF,EAAA,cAAA,MAAA,CAAI,UAAWH,CAAA,EACb3B,EACA6B,GACH,EACC,CAACzB,GACC0B,EAAA,cAAA,MAAA,CAAI,UAAWL,EAAO,iBAAA,EACpBK,EAAA,cAAAG,EAAA,CAAM,MAAK,GAAC,QAASzB,EAAS,UAAWC,CAAgB,CAAA,CAC5D,CAEJ,EACCqB,EAAA,cAAA,MAAA,CAAI,IAAKjB,EAAU,UAAWa,EAAc,MAAOE,CAAY,CAAA,CAClE,CAEJ"}
|
package/Modal.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import t,{useEffect as
|
|
1
|
+
import t,{useEffect as W}from"react";import n from"classnames";import{palette as d}from"./theme/palette.js";import{B as N}from"./Button.js";import{Icon as u}from"./components/Icons/Icon.js";import{ZIndex as z,AnalyticsId as R,IconSize as c}from"./constants.js";import a from"./components/Modal/styles.module.scss";import P from"./components/Icons/AlertSignStroke.js";import $ from"./components/Icons/AlertSignFill.js";import{useFocusTrap as A}from"./hooks/useFocusTrap.js";import{useIsVisible as I}from"./hooks/useIsVisible.js";import{T as F}from"./Title.js";import{a as H}from"./uuid.js";import{C as K}from"./Close.js";import O from"./components/Icons/CheckOutline.js";import D from"./components/Portal/index.js";var M=(e=>(e.normal="normal",e.warning="warning",e.error="error",e.success="success",e.image="image",e))(M||{}),V=(e=>(e.large="large",e.medium="medium",e))(V||{});const Z={variant:"normal",primaryButtonText:"OK",titleId:H(),className:"",size:"large",zIndex:z.Modal},j=e=>e==="error"?t.createElement(u,{size:c.Small,svgIcon:$,color:d.cherry500}):e==="warning"?t.createElement(u,{size:c.Small,svgIcon:P,color:d.black}):e==="success"?t.createElement(u,{size:c.Small,svgIcon:O,color:d.kiwi900}):null,q=(e,r)=>{const o=j(e);return o?t.createElement("div",{className:a.modal__iconWrapper},o):r?t.createElement("div",{className:a.modal__iconWrapper},t.cloneElement(r,{size:c.Small})):null},G=e=>{var C,h;const r=t.useRef(null),o=t.useRef(null),_=t.useRef(null);A(_,!0,!0);const w=I(r),f=t.useRef(null),B=I(f),m=o.current&&o.current.scrollHeight>o.current.clientHeight;function v(l){l.key==="Escape"&&e.onClose&&(l.stopPropagation(),e.onClose())}function E(l){l.target&&s.current===l.target&&e.onClose&&(l.stopPropagation(),e.onClose())}function k(){document.body.style.overflow="hidden"}function L(){document.body.style.removeProperty("overflow")}const i=e.variant==="image",s=t.useRef(null),g=e.secondaryButtonText&&((C=e.secondaryButtonText)==null?void 0:C.length)>0||e.onSuccess,S=e.ariaLabelledBy?void 0:e.ariaLabel,y=e.ariaLabelledBy?e.ariaLabelledBy:e.ariaLabel?void 0:e.titleId;W(()=>{const l=s.current;return k(),!e.disableCloseEvents&&l&&(l.addEventListener("keydown",v),l.addEventListener("click",E)),()=>{L(),!e.disableCloseEvents&&l&&(l.removeEventListener("keydown",v),l.removeEventListener("click",E))}},[e.disableCloseEvents]);const T=n(e.className,a.modal,a[`modal--${e.variant}`],a[`modal--${e.size}`],m&&!g&&a["modal--no-actions"]),x=n({[a["modal__title--error"]]:e.variant==="error",[a["modal__title--success"]]:e.variant==="success"}),b=t.createElement("div",{"data-testid":"dialog-container"},t.createElement("div",{ref:s,className:a["modal-overlay"],"data-testid":e.testId,"data-analyticsid":R.Modal,style:{zIndex:e.zIndex}},t.createElement("div",{className:a.align},t.createElement("div",{className:T,role:"dialog","aria-label":S,"aria-labelledby":y,ref:_},t.createElement("div",{className:n(a.modal__shadow,a["modal__shadow--top"],{[a["modal__shadow--show"]]:!w&&m})}),t.createElement("div",{className:n(a.modal__contentWrapper,{[a["modal__contentWrapper--image"]]:i}),ref:o},!e.noCloseButton&&t.createElement("div",{className:a.modal__closeWrapper},t.createElement("div",{className:n(a.modal__closeWrapper__close)},t.createElement(K,{onClick:e.onClose,ariaLabel:e.ariaLabelCloseBtn}))),t.createElement("div",{className:n(a[`modal__contentWrapper__scroll--${e.size}`],{[a["modal__contentWrapper__scroll--image"]]:i})},t.createElement("div",{ref:r}),t.createElement("div",{className:a.modal__contentWrapper__title},q(e.variant,e.icon),t.createElement(F,{id:y,htmlMarkup:"h3",appearance:"title3",className:x},e.title),e.afterTitleChildren&&t.createElement("div",{className:a.modal__afterTitleChildren},e.afterTitleChildren)),i&&t.createElement("div",null,t.createElement("div",{className:a.modal__contentWrapper__imageWrapper},e.children),t.createElement("span",{className:a.modal__contentWrapper__imageDescription},e.description)),!i&&e.children&&t.createElement("div",null,e.children),!i&&!e.children&&t.createElement("p",{className:a.modal__description},e.description),t.createElement("div",{ref:f}))),t.createElement("div",{className:n(a.modal__shadow,a["modal__shadow--bottom"],{[a["modal__shadow--show"]]:!B&&m})}),g&&t.createElement("div",{className:n(a["modal__call-to-action"],a[`modal__call-to-action--${e.size}`])},e.onSuccess&&t.createElement(N,{onClick:e.onSuccess},e.primaryButtonText),e.secondaryButtonText&&((h=e.secondaryButtonText)==null?void 0:h.length)>0&&t.createElement(N,{variant:"borderless",onClick:e.onClose},e.secondaryButtonText))))));if(e.printable){const l="print-modal";return t.createElement(D,{className:l,testId:"print-modal"},t.createElement("style",{media:"print"},`body > *:not(.${l}) {display: none;}`),b)}return b};G.defaultProps=Z;export{G as M,M as a,V as b};
|
|
2
2
|
//# sourceMappingURL=Modal.js.map
|
package/Modal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Modal.js","sources":["../src/components/Modal/Modal.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\nimport cn from 'classnames';\n\nimport { palette } from '../../theme/palette';\nimport Button from '../Button';\nimport Icon, { IconSize } from '../Icons';\n\nimport styles from './styles.module.scss';\nimport AlertSignStroke from '../Icons/AlertSignStroke';\nimport AlertSignFill from '../Icons/AlertSignFill';\nimport FocusTrap from '../../hooks/useFocusTrap';\nimport { useIsVisible } from '../../hooks/useIsVisible';\nimport Title from '../Title/Title';\nimport { uuid } from '../../utils/uuid';\nimport Close from '../Close';\nimport CheckOutline from '../Icons/CheckOutline';\nimport Portal from '../Portal';\nimport { AnalyticsId, ZIndex } from '../../constants';\n\nexport enum ModalVariants {\n normal = 'normal',\n warning = 'warning',\n error = 'error',\n success = 'success',\n image = 'image',\n}\n\nexport enum ModalSize {\n large = 'large',\n medium = 'medium',\n}\n\nexport interface ModalProps {\n /** Title of the modal */\n title: string;\n /** id of the modal title */\n titleId?: string;\n /** Description of the modal. Will not render if the modal has children. */\n description?: string;\n /** Changes the visual representation of the modal */\n variant?: keyof typeof ModalVariants;\n /** Change width of the modal (default: large) */\n size?: keyof typeof ModalSize;\n /** Icon displayed in title */\n icon?: React.ReactElement;\n /** Hides the close button */\n noCloseButton?: boolean;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Primary button text */\n primaryButtonText?: string;\n /** Secondary button text */\n secondaryButtonText?: string;\n /** Sets the aria-label of the modal */\n ariaLabel?: string;\n /** Sets the aria-labelledby of the modal */\n ariaLabelledBy?: string;\n /** Close button aria-label */\n ariaLabelCloseBtn?: string;\n /** Alternative component to modal */\n children?: React.ReactNode;\n /** Component shown after title */\n afterTitleChildren?: React.ReactNode;\n /** Adds custom classes to the element. */\n className?: string;\n /** Customize the z-index of the modal */\n zIndex?: number;\n /** Function is called when user clicks primary button */\n onSuccess?: () => void;\n /** Function is called when user clicks secondary button, clicks escape or outside the modal */\n onClose?: () => void;\n /** When enabled the component will be rendered in the bottom of document.body */\n printable?: boolean;\n /** If disabled, clicking escape or outside the modal will not close it */\n disableCloseEvents?: boolean;\n}\n\nconst defaultProps = {\n variant: ModalVariants.normal,\n primaryButtonText: 'OK',\n titleId: uuid(),\n className: '',\n size: ModalSize.large,\n zIndex: ZIndex.Modal,\n};\n\nconst getVariantIcon = (variant?: ModalProps['variant']): JSX.Element | null => {\n if (variant === ModalVariants.error) {\n return <Icon size={IconSize.Small} svgIcon={AlertSignFill} color={palette.cherry500} />;\n } else if (variant === ModalVariants.warning) {\n return <Icon size={IconSize.Small} svgIcon={AlertSignStroke} color={palette.black} />;\n } else if (variant === ModalVariants.success) {\n return <Icon size={IconSize.Small} svgIcon={CheckOutline} color={palette.kiwi900} />;\n }\n return null;\n};\n\nconst getIcon = (variant?: ModalProps['variant'], icon?: ModalProps['icon']): JSX.Element | null => {\n const variantIcon = getVariantIcon(variant);\n if (variantIcon) {\n return <div className={styles.modal__iconWrapper}>{variantIcon}</div>;\n }\n if (icon) {\n return (\n <div className={styles.modal__iconWrapper}>\n {React.cloneElement(icon, {\n size: IconSize.Small,\n })}\n </div>\n );\n }\n return null;\n};\n\nconst Modal = (props: ModalProps): JSX.Element => {\n const [tabIndex, setTabIndex] = React.useState(0);\n const initFocus = React.useRef<HTMLDivElement>(null);\n const topContent = React.useRef<HTMLDivElement>(null);\n const modalContentRef = React.useRef<HTMLDivElement>(null);\n const topContentVisible = useIsVisible(topContent);\n const bottomContent = React.useRef<HTMLDivElement>(null);\n const bottomContentVisible = useIsVisible(bottomContent);\n const contentIsScrollable = modalContentRef.current && modalContentRef.current.scrollHeight > modalContentRef.current.clientHeight;\n\n function handleKeyboardEvent(e: KeyboardEvent): void {\n if (e.key === 'Escape' && props.onClose) {\n e.stopPropagation();\n props.onClose();\n }\n }\n\n function handleClickEvent(event: MouseEvent): void {\n if (event.target && overlayRef.current === event.target && props.onClose) {\n event.stopPropagation();\n props.onClose();\n }\n }\n\n function disableBodyScroll(): void {\n document.body.style.overflow = 'hidden';\n }\n\n function enableBodyScroll(): void {\n document.body.style.removeProperty('overflow');\n }\n\n /* Displays a full window size modal with image */\n const imageView = props.variant === ModalVariants.image;\n\n const overlayRef = React.useRef<HTMLDivElement>(null);\n\n const showActions = (props.secondaryButtonText && props.secondaryButtonText?.length > 0) || props.onSuccess;\n\n // ariaLabelledBy prioriteres over ariaLabel, men dersom ariaLabel brukes trengs ikke ariaLabelledBy\n const ariaLabel = !props.ariaLabelledBy ? props.ariaLabel : undefined;\n const ariaLabelledBy = props.ariaLabelledBy ? props.ariaLabelledBy : !props.ariaLabel ? props.titleId : undefined;\n\n useEffect(() => {\n const overlayElement = overlayRef.current;\n initFocus.current?.focus();\n disableBodyScroll();\n if (!props.disableCloseEvents && overlayElement) {\n overlayElement.addEventListener('keydown', handleKeyboardEvent);\n overlayElement.addEventListener('click', handleClickEvent);\n }\n return (): void => {\n enableBodyScroll();\n if (!props.disableCloseEvents && overlayElement) {\n overlayElement.removeEventListener('keydown', handleKeyboardEvent);\n overlayElement.removeEventListener('click', handleClickEvent);\n }\n };\n }, [props.disableCloseEvents]);\n\n const dialogClasses = cn(\n props.className,\n styles.modal,\n styles[`modal--${props.variant}`],\n styles[`modal--${props.size}`],\n contentIsScrollable && !showActions && styles['modal--no-actions']\n );\n\n const titleClasses = cn({\n [styles['modal__title--error']]: props.variant === ModalVariants.error,\n [styles['modal__title--success']]: props.variant === ModalVariants.success,\n });\n\n const Component = (\n <div data-testid=\"dialog-container\">\n <div\n ref={overlayRef}\n className={styles['modal-overlay']}\n data-testid={props.testId}\n data-analyticsid={AnalyticsId.Modal}\n style={{ zIndex: props.zIndex }}\n >\n <div className={styles.align} ref={FocusTrap()}>\n <div className={dialogClasses} role=\"dialog\" aria-label={ariaLabel} aria-labelledby={ariaLabelledBy}>\n <div tabIndex={tabIndex} ref={initFocus} onBlur={(): void => setTabIndex(-1)} />\n <div\n className={cn(styles['modal__shadow'], styles['modal__shadow--top'], {\n [styles['modal__shadow--show']]: !topContentVisible && contentIsScrollable,\n })}\n />\n <div\n className={cn(styles.modal__contentWrapper, {\n [styles['modal__contentWrapper--image']]: imageView,\n })}\n ref={modalContentRef}\n >\n {!props.noCloseButton && (\n <div className={styles.modal__closeWrapper}>\n <div className={cn(styles.modal__closeWrapper__close)}>\n <Close onClick={props.onClose} ariaLabel={props.ariaLabelCloseBtn} />\n </div>\n </div>\n )}\n <div\n className={cn(styles[`modal__contentWrapper__scroll--${props.size}`], {\n [styles['modal__contentWrapper__scroll--image']]: imageView,\n })}\n >\n <div ref={topContent} />\n <div className={styles.modal__contentWrapper__title}>\n {getIcon(props.variant, props.icon)}\n <Title id={ariaLabelledBy} htmlMarkup=\"h3\" appearance=\"title3\" className={titleClasses}>\n {props.title}\n </Title>\n {props.afterTitleChildren && <div className={styles['modal__afterTitleChildren']}>{props.afterTitleChildren}</div>}\n </div>\n {imageView && (\n <div>\n <div className={styles['modal__contentWrapper__imageWrapper']}>{props.children}</div>\n <span className={styles['modal__contentWrapper__imageDescription']}>{props.description}</span>\n </div>\n )}\n {!imageView && props.children && <div>{props.children}</div>}\n {!imageView && !props.children && <p className={styles.modal__description}>{props.description}</p>}\n <div ref={bottomContent} />\n </div>\n </div>\n <div\n className={cn(styles['modal__shadow'], styles['modal__shadow--bottom'], {\n [styles['modal__shadow--show']]: !bottomContentVisible && contentIsScrollable,\n })}\n />\n {showActions && (\n <div className={cn(styles['modal__call-to-action'], styles[`modal__call-to-action--${props.size}`])}>\n {props.onSuccess && <Button onClick={props.onSuccess}>{props.primaryButtonText}</Button>}\n {props.secondaryButtonText && props.secondaryButtonText?.length > 0 && (\n <Button variant=\"borderless\" onClick={props.onClose}>\n {props.secondaryButtonText}\n </Button>\n )}\n </div>\n )}\n </div>\n </div>\n </div>\n </div>\n );\n\n if (props.printable) {\n const printModal = 'print-modal';\n return (\n <Portal className={printModal} testId=\"print-modal\">\n <style media=\"print\">{`body > *:not(.${printModal}) {display: none;}`}</style>\n {Component}\n </Portal>\n );\n }\n\n return Component;\n};\n\nModal.defaultProps = defaultProps;\n\nexport default Modal;\n"],"names":["ModalVariants","ModalSize","defaultProps","uuid","ZIndex","getVariantIcon","variant","React","Icon","IconSize","AlertSignFill","palette","AlertSignStroke","CheckOutline","getIcon","icon","variantIcon","styles","Modal","props","tabIndex","setTabIndex","initFocus","topContent","modalContentRef","topContentVisible","useIsVisible","bottomContent","bottomContentVisible","contentIsScrollable","handleKeyboardEvent","e","handleClickEvent","event","overlayRef","disableBodyScroll","enableBodyScroll","imageView","showActions","_a","ariaLabel","ariaLabelledBy","useEffect","overlayElement","dialogClasses","cn","titleClasses","Component","AnalyticsId","FocusTrap","Close","Title","Button","_b","printModal","Portal"],"mappings":"qsBAmBY,IAAAA,GAAAA,IACVA,EAAA,OAAS,SACTA,EAAA,QAAU,UACVA,EAAA,MAAQ,QACRA,EAAA,QAAU,UACVA,EAAA,MAAQ,QALEA,IAAAA,GAAA,CAAA,CAAA,EAQAC,GAAAA,IACVA,EAAA,MAAQ,QACRA,EAAA,OAAS,SAFCA,IAAAA,GAAA,CAAA,CAAA,EAkDZ,MAAMC,EAAe,CACnB,QAAS,SACT,kBAAmB,KACnB,QAASC,EAAK,EACd,UAAW,GACX,KAAM,QACN,OAAQC,EAAO,KACjB,EAEMC,EAAkBC,GAClBA,IAAY,QACNC,EAAA,cAAAC,EAAA,CAAK,KAAMC,EAAS,MAAO,QAASC,EAAe,MAAOC,EAAQ,SAAA,CAAW,EAC5EL,IAAY,UACbC,EAAA,cAAAC,EAAA,CAAK,KAAMC,EAAS,MAAO,QAASG,EAAiB,MAAOD,EAAQ,KAAA,CAAO,EAC1EL,IAAY,UACbC,EAAA,cAAAC,EAAA,CAAK,KAAMC,EAAS,MAAO,QAASI,EAAc,MAAOF,EAAQ,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AAAE,EAAM,WAAY,EAC7FZ,EAAA,cAAA,MAAA,CAAI,IAAKoB,CAAe,CAAA,CAC3B,CACF,EACCpB,EAAA,cAAA,MAAA,CACC,UAAWsC,EAAG5B,EAAO,cAAkBA,EAAO,yBAA0B,CACtE,CAACA,EAAO,wBAAyB,CAACW,GAAwBC,CAAA,CAC3D,CACH,CAAA,EACCS,GACE/B,EAAA,cAAA,MAAA,CAAI,UAAWsC,EAAG5B,EAAO,yBAA0BA,EAAO,0BAA0BE,EAAM,OAAO,CAC/F,EAAAA,EAAM,WAAcZ,EAAA,cAAA6C,EAAA,CAAO,QAASjC,EAAM,SAAY,EAAAA,EAAM,iBAAkB,EAC9EA,EAAM,uBAAuBkC,EAAAlC,EAAM,sBAAN,YAAAkC,EAA2B,QAAS,GAC/D9C,EAAA,cAAA6C,EAAA,CAAO,QAAQ,aAAa,QAASjC,EAAM,OAAA,EACzCA,EAAM,mBACT,CAEJ,CAEJ,CACF,CACF,CACF,EAGF,GAAIA,EAAM,UAAW,CACnB,MAAMmC,EAAa,cACnB,OACG/C,EAAA,cAAAgD,EAAA,CAAO,UAAWD,EAAY,OAAO,aAAA,EACnC/C,EAAA,cAAA,QAAA,CAAM,MAAM,OAAA,EAAS,iBAAiB+C,qBAA+B,EACrEP,CACH,CAEJ,CAEO,OAAAA,CACT,EAEA7B,EAAM,aAAehB"}
|
|
1
|
+
{"version":3,"file":"Modal.js","sources":["../src/components/Modal/Modal.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\nimport cn from 'classnames';\n\nimport { palette } from '../../theme/palette';\nimport Button from '../Button';\nimport Icon, { IconSize } from '../Icons';\n\nimport styles from './styles.module.scss';\nimport AlertSignStroke from '../Icons/AlertSignStroke';\nimport AlertSignFill from '../Icons/AlertSignFill';\nimport useFocusTrap from '../../hooks/useFocusTrap';\nimport { useIsVisible } from '../../hooks/useIsVisible';\nimport Title from '../Title/Title';\nimport { uuid } from '../../utils/uuid';\nimport Close from '../Close';\nimport CheckOutline from '../Icons/CheckOutline';\nimport Portal from '../Portal';\nimport { AnalyticsId, ZIndex } from '../../constants';\n\nexport enum ModalVariants {\n normal = 'normal',\n warning = 'warning',\n error = 'error',\n success = 'success',\n image = 'image',\n}\n\nexport enum ModalSize {\n large = 'large',\n medium = 'medium',\n}\n\nexport interface ModalProps {\n /** Title of the modal */\n title: string;\n /** id of the modal title */\n titleId?: string;\n /** Description of the modal. Will not render if the modal has children. */\n description?: string;\n /** Changes the visual representation of the modal */\n variant?: keyof typeof ModalVariants;\n /** Change width of the modal (default: large) */\n size?: keyof typeof ModalSize;\n /** Icon displayed in title */\n icon?: React.ReactElement;\n /** Hides the close button */\n noCloseButton?: boolean;\n /** Sets the data-testid attribute. */\n testId?: string;\n /** Primary button text */\n primaryButtonText?: string;\n /** Secondary button text */\n secondaryButtonText?: string;\n /** Sets the aria-label of the modal */\n ariaLabel?: string;\n /** Sets the aria-labelledby of the modal */\n ariaLabelledBy?: string;\n /** Close button aria-label */\n ariaLabelCloseBtn?: string;\n /** Alternative component to modal */\n children?: React.ReactNode;\n /** Component shown after title */\n afterTitleChildren?: React.ReactNode;\n /** Adds custom classes to the element. */\n className?: string;\n /** Customize the z-index of the modal */\n zIndex?: number;\n /** Function is called when user clicks primary button */\n onSuccess?: () => void;\n /** Function is called when user clicks secondary button, clicks escape or outside the modal */\n onClose?: () => void;\n /** When enabled the component will be rendered in the bottom of document.body */\n printable?: boolean;\n /** If disabled, clicking escape or outside the modal will not close it */\n disableCloseEvents?: boolean;\n}\n\nconst defaultProps = {\n variant: ModalVariants.normal,\n primaryButtonText: 'OK',\n titleId: uuid(),\n className: '',\n size: ModalSize.large,\n zIndex: ZIndex.Modal,\n};\n\nconst getVariantIcon = (variant?: ModalProps['variant']): JSX.Element | null => {\n if (variant === ModalVariants.error) {\n return <Icon size={IconSize.Small} svgIcon={AlertSignFill} color={palette.cherry500} />;\n } else if (variant === ModalVariants.warning) {\n return <Icon size={IconSize.Small} svgIcon={AlertSignStroke} color={palette.black} />;\n } else if (variant === ModalVariants.success) {\n return <Icon size={IconSize.Small} svgIcon={CheckOutline} color={palette.kiwi900} />;\n }\n return null;\n};\n\nconst getIcon = (variant?: ModalProps['variant'], icon?: ModalProps['icon']): JSX.Element | null => {\n const variantIcon = getVariantIcon(variant);\n if (variantIcon) {\n return <div className={styles.modal__iconWrapper}>{variantIcon}</div>;\n }\n if (icon) {\n return (\n <div className={styles.modal__iconWrapper}>\n {React.cloneElement(icon, {\n size: IconSize.Small,\n })}\n </div>\n );\n }\n return null;\n};\n\nconst Modal = (props: ModalProps): JSX.Element => {\n const topContent = React.useRef<HTMLDivElement>(null);\n const modalContentRef = React.useRef<HTMLDivElement>(null);\n const dialogRef = React.useRef<HTMLDivElement>(null);\n useFocusTrap(dialogRef, true, true);\n const topContentVisible = useIsVisible(topContent);\n const bottomContent = React.useRef<HTMLDivElement>(null);\n const bottomContentVisible = useIsVisible(bottomContent);\n const contentIsScrollable = modalContentRef.current && modalContentRef.current.scrollHeight > modalContentRef.current.clientHeight;\n\n function handleKeyboardEvent(e: KeyboardEvent): void {\n if (e.key === 'Escape' && props.onClose) {\n e.stopPropagation();\n props.onClose();\n }\n }\n\n function handleClickEvent(event: MouseEvent): void {\n if (event.target && overlayRef.current === event.target && props.onClose) {\n event.stopPropagation();\n props.onClose();\n }\n }\n\n function disableBodyScroll(): void {\n document.body.style.overflow = 'hidden';\n }\n\n function enableBodyScroll(): void {\n document.body.style.removeProperty('overflow');\n }\n\n /* Displays a full window size modal with image */\n const imageView = props.variant === ModalVariants.image;\n\n const overlayRef = React.useRef<HTMLDivElement>(null);\n\n const showActions = (props.secondaryButtonText && props.secondaryButtonText?.length > 0) || props.onSuccess;\n\n // ariaLabelledBy prioriteres over ariaLabel, men dersom ariaLabel brukes trengs ikke ariaLabelledBy\n const ariaLabel = !props.ariaLabelledBy ? props.ariaLabel : undefined;\n const ariaLabelledBy = props.ariaLabelledBy ? props.ariaLabelledBy : !props.ariaLabel ? props.titleId : undefined;\n\n useEffect(() => {\n const overlayElement = overlayRef.current;\n disableBodyScroll();\n if (!props.disableCloseEvents && overlayElement) {\n overlayElement.addEventListener('keydown', handleKeyboardEvent);\n overlayElement.addEventListener('click', handleClickEvent);\n }\n return (): void => {\n enableBodyScroll();\n if (!props.disableCloseEvents && overlayElement) {\n overlayElement.removeEventListener('keydown', handleKeyboardEvent);\n overlayElement.removeEventListener('click', handleClickEvent);\n }\n };\n }, [props.disableCloseEvents]);\n\n const dialogClasses = cn(\n props.className,\n styles.modal,\n styles[`modal--${props.variant}`],\n styles[`modal--${props.size}`],\n contentIsScrollable && !showActions && styles['modal--no-actions']\n );\n\n const titleClasses = cn({\n [styles['modal__title--error']]: props.variant === ModalVariants.error,\n [styles['modal__title--success']]: props.variant === ModalVariants.success,\n });\n\n const Component = (\n <div data-testid=\"dialog-container\">\n <div\n ref={overlayRef}\n className={styles['modal-overlay']}\n data-testid={props.testId}\n data-analyticsid={AnalyticsId.Modal}\n style={{ zIndex: props.zIndex }}\n >\n <div className={styles.align}>\n <div className={dialogClasses} role=\"dialog\" aria-label={ariaLabel} aria-labelledby={ariaLabelledBy} ref={dialogRef}>\n <div\n className={cn(styles['modal__shadow'], styles['modal__shadow--top'], {\n [styles['modal__shadow--show']]: !topContentVisible && contentIsScrollable,\n })}\n />\n <div\n className={cn(styles.modal__contentWrapper, {\n [styles['modal__contentWrapper--image']]: imageView,\n })}\n ref={modalContentRef}\n >\n {!props.noCloseButton && (\n <div className={styles.modal__closeWrapper}>\n <div className={cn(styles.modal__closeWrapper__close)}>\n <Close onClick={props.onClose} ariaLabel={props.ariaLabelCloseBtn} />\n </div>\n </div>\n )}\n <div\n className={cn(styles[`modal__contentWrapper__scroll--${props.size}`], {\n [styles['modal__contentWrapper__scroll--image']]: imageView,\n })}\n >\n <div ref={topContent} />\n <div className={styles.modal__contentWrapper__title}>\n {getIcon(props.variant, props.icon)}\n <Title id={ariaLabelledBy} htmlMarkup=\"h3\" appearance=\"title3\" className={titleClasses}>\n {props.title}\n </Title>\n {props.afterTitleChildren && <div className={styles['modal__afterTitleChildren']}>{props.afterTitleChildren}</div>}\n </div>\n {imageView && (\n <div>\n <div className={styles['modal__contentWrapper__imageWrapper']}>{props.children}</div>\n <span className={styles['modal__contentWrapper__imageDescription']}>{props.description}</span>\n </div>\n )}\n {!imageView && props.children && <div>{props.children}</div>}\n {!imageView && !props.children && <p className={styles.modal__description}>{props.description}</p>}\n <div ref={bottomContent} />\n </div>\n </div>\n <div\n className={cn(styles['modal__shadow'], styles['modal__shadow--bottom'], {\n [styles['modal__shadow--show']]: !bottomContentVisible && contentIsScrollable,\n })}\n />\n {showActions && (\n <div className={cn(styles['modal__call-to-action'], styles[`modal__call-to-action--${props.size}`])}>\n {props.onSuccess && <Button onClick={props.onSuccess}>{props.primaryButtonText}</Button>}\n {props.secondaryButtonText && props.secondaryButtonText?.length > 0 && (\n <Button variant=\"borderless\" onClick={props.onClose}>\n {props.secondaryButtonText}\n </Button>\n )}\n </div>\n )}\n </div>\n </div>\n </div>\n </div>\n );\n\n if (props.printable) {\n const printModal = 'print-modal';\n return (\n <Portal className={printModal} testId=\"print-modal\">\n <style media=\"print\">{`body > *:not(.${printModal}) {display: none;}`}</style>\n {Component}\n </Portal>\n );\n }\n\n return Component;\n};\n\nModal.defaultProps = defaultProps;\n\nexport default Modal;\n"],"names":["ModalVariants","ModalSize","defaultProps","uuid","ZIndex","getVariantIcon","variant","React","Icon","IconSize","AlertSignFill","palette","AlertSignStroke","CheckOutline","getIcon","icon","variantIcon","styles","Modal","props","topContent","modalContentRef","dialogRef","useFocusTrap","topContentVisible","useIsVisible","bottomContent","bottomContentVisible","contentIsScrollable","handleKeyboardEvent","e","handleClickEvent","event","overlayRef","disableBodyScroll","enableBodyScroll","imageView","showActions","_a","ariaLabel","ariaLabelledBy","useEffect","overlayElement","dialogClasses","cn","titleClasses","Component","AnalyticsId","Close","Title","Button","_b","printModal","Portal"],"mappings":"0sBAmBY,IAAAA,GAAAA,IACVA,EAA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AA+B,EACrEN,CACH,CAEJ,CAEO,OAAAA,CACT,EAEA5B,EAAM,aAAehB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MutationObserver.d.ts","sourceRoot":"","sources":["../../src/__mocks__/MutationObserver.ts"],"names":[],"mappings":"AAAA,cAAM,gBAAgB;IACpB,OAAO,IAAI,IAAI;IAGf,UAAU,IAAI,IAAI;CAGnB;AAMD,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MutationObserver.js","sources":["../../src/__mocks__/MutationObserver.ts"],"sourcesContent":["class MutationObserver {\n observe(): void {\n // do nothing\n }\n disconnect(): void {\n // do nothing\n }\n}\n\nObject.defineProperty(window, 'MutationObserver', {\n value: MutationObserver,\n});\n\nexport default MutationObserver;\n"],"names":["MutationObserver"],"mappings":"AAAA,MAAMA,CAAiB,CACrB,SAAgB,CAEhB,CACA,YAAmB,CAEnB,CACF,CAEA,OAAO,eAAe,OAAQ,mBAAoB,CAChD,MAAOA,CACT,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import t,{useState as i}from"react";import{B as p}from"../../Button.js";import{M as e}from"../../Modal.js";import"../../constants.js";import"../../uuid.js";import"../../theme/currys/color.js";import"../../theme/index.js";import"../../theme/palette.js";import"../../theme/spacers.js";import"../../theme/grid.js";import"../Icons/Icon.js";import"classnames";import"../../hooks/useUuid.js";import"../../hooks/useHover.js";import"../../hooks/useIcons.js";import"../../hooks/useBreakpoint.js";import"../Button/styles.module.scss";import"../Icons/ArrowRight.js";import"../../hooks/useSize.js";import"../../debounce.js";import"../Modal/styles.module.scss";import"../Icons/AlertSignStroke.js";import"../Icons/AlertSignFill.js";import"../../hooks/useFocusTrap.js";import"../../hooks/focus-utils.js";import"../../hooks/
|
|
1
|
+
import t,{useState as i}from"react";import{B as p}from"../../Button.js";import{M as e}from"../../Modal.js";import"../../constants.js";import"../../uuid.js";import"../../theme/currys/color.js";import"../../theme/index.js";import"../../theme/palette.js";import"../../theme/spacers.js";import"../../theme/grid.js";import"../Icons/Icon.js";import"classnames";import"../../hooks/useUuid.js";import"../../hooks/useHover.js";import"../../hooks/useIcons.js";import"../../hooks/useBreakpoint.js";import"../Button/styles.module.scss";import"../Icons/ArrowRight.js";import"../../hooks/useSize.js";import"../../debounce.js";import"../Modal/styles.module.scss";import"../Icons/AlertSignStroke.js";import"../Icons/AlertSignFill.js";import"../../hooks/useFocusTrap.js";import"../../hooks/focus-utils.js";import"../../hooks/useFocusableElements.js";import"../../hooks/useIsVisible.js";import"../../hooks/useIntersectionObserver.js";import"../../Title.js";import"../Title/styles.module.scss";import"../../Close.js";import"../Icons/X.js";import"../Close/styles.module.scss";import"../Icons/CheckOutline.js";import"../Portal/index.js";import"react-dom";const P=t.forwardRef(function(o,d){const[m,r]=i(!1);return t.createElement("div",{"data-testid":o.testId},t.createElement(p,{onClick:()=>r(!0)},o.buttonText),m&&t.createElement(e,{...o,onClose:()=>r(!1)}))});export{P as default};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/components/ButtonWithModal/ButtonWithModal.tsx"],"sourcesContent":["/* istanbul ignore file */\nimport React, { useState } from 'react';\nimport Button from '../Button';\nimport Modal, { ModalProps } from '../Modal/Modal';\n\ninterface ModalWithButtonProps extends ModalProps {\n /** Text of the button */\n buttonText: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nconst ModalWithButton = React.forwardRef(function ModalForwardedRef(props: ModalWithButtonProps, ref: React.ForwardedRef<HTMLElement>) {\n const [showModal, setShowModal] = useState(false);\n\n return (\n <div data-testid={props.testId}>\n <Button onClick={() => setShowModal(true)}>{props.buttonText}</Button>\n {showModal && <Modal {...props} onClose={() => setShowModal(false)} />}\n </div>\n );\n});\n\nexport default ModalWithButton;\n"],"names":["ModalWithButton","React","props","ref","showModal","setShowModal","useState","Button","Modal"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/components/ButtonWithModal/ButtonWithModal.tsx"],"sourcesContent":["/* istanbul ignore file */\nimport React, { useState } from 'react';\nimport Button from '../Button';\nimport Modal, { ModalProps } from '../Modal/Modal';\n\ninterface ModalWithButtonProps extends ModalProps {\n /** Text of the button */\n buttonText: string;\n /** Sets the data-testid attribute. */\n testId?: string;\n}\n\nconst ModalWithButton = React.forwardRef(function ModalForwardedRef(props: ModalWithButtonProps, ref: React.ForwardedRef<HTMLElement>) {\n const [showModal, setShowModal] = useState(false);\n\n return (\n <div data-testid={props.testId}>\n <Button onClick={() => setShowModal(true)}>{props.buttonText}</Button>\n {showModal && <Modal {...props} onClose={() => setShowModal(false)} />}\n </div>\n );\n});\n\nexport default ModalWithButton;\n"],"names":["ModalWithButton","React","props","ref","showModal","setShowModal","useState","Button","Modal"],"mappings":"8mCAYA,MAAMA,EAAkBC,EAAM,WAAW,SAA2BC,EAA6BC,EAAsC,CACrI,KAAM,CAACC,EAAWC,CAAY,EAAIC,EAAS,EAAK,EAEhD,OACGL,EAAA,cAAA,MAAA,CAAI,cAAaC,EAAM,MAAA,EACrBD,EAAA,cAAAM,EAAA,CAAO,QAAS,IAAMF,EAAa,EAAI,CAAA,EAAIH,EAAM,UAAW,EAC5DE,GAAcH,EAAA,cAAAO,EAAA,CAAO,GAAGN,EAAO,QAAS,IAAMG,EAAa,EAAK,CAAG,CAAA,CACtE,CAEJ,CAAC"}
|
|
@@ -13,11 +13,11 @@ export interface HelpBubbleProps {
|
|
|
13
13
|
controllerRef: React.RefObject<HTMLElement | SVGSVGElement>;
|
|
14
14
|
/** Adds custom classes to the element. */
|
|
15
15
|
className?: string;
|
|
16
|
-
/** Determines the placement of the helpbubble */
|
|
16
|
+
/** Determines the placement of the helpbubble. Default: automatic positioning. */
|
|
17
17
|
variant?: keyof typeof HelpBubbleVariant;
|
|
18
|
-
/**
|
|
18
|
+
/** Show the bubble. Default: false. */
|
|
19
19
|
showBubble?: boolean;
|
|
20
|
-
/**
|
|
20
|
+
/** Hide the close button in the bubble */
|
|
21
21
|
noCloseButton?: boolean;
|
|
22
22
|
/** Visible text on the link */
|
|
23
23
|
linkText?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HelpBubble.d.ts","sourceRoot":"","sources":["../../../src/components/HelpBubble/HelpBubble.tsx"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"HelpBubble.d.ts","sourceRoot":"","sources":["../../../src/components/HelpBubble/HelpBubble.tsx"],"names":[],"mappings":"AACA,OAAO,KAA2B,MAAM,OAAO,CAAC;AAahD,oBAAY,iBAAiB;IAC3B,iBAAiB,sBAAsB;IACvC,aAAa,kBAAkB;IAC/B,aAAa,kBAAkB;CAChC;AAED,MAAM,WAAW,eAAe;IAC9B,2BAA2B;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oFAAoF;IACpF,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,wDAAwD;IACxD,aAAa,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,aAAa,CAAC,CAAC;IAC5D,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kFAAkF;IAClF,OAAO,CAAC,EAAE,MAAM,OAAO,iBAAiB,CAAC;IACzC,uCAAuC;IACvC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,0CAA0C;IAC1C,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,+BAA+B;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4BAA4B;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,qDAAqD;IACrD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,yCAAyC;IACzC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,sCAAsC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,QAAA,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAoFzC,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"props":{"helpBubbleId":{"defaultValue":null,"description":"Id of the HelpBubble","name":"helpBubbleId","parent":{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"string"}},"children":{"defaultValue":null,"description":"Name to display in the avatar. Will be truncated to the first two characters.","name":"children","parent":{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},{"fileName":"designsystem/node_modules/@types/react/index.d.ts","name":"TypeLiteral"}],"required":false,"type":{"name":"ReactNode"}},"controllerRef":{"defaultValue":null,"description":"Ref for the element the HelpBubble is placed upon","name":"controllerRef","parent":{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":true,"type":{"name":"RefObject<HTMLElement | SVGSVGElement>"}},"className":{"defaultValue":null,"description":"Adds custom classes to the element.","name":"className","parent":{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"string"}},"variant":{"defaultValue":null,"description":"Determines the placement of the helpbubble","name":"variant","parent":{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"enum","raw":"\"positionautomatic\" | \"positionbelow\" | \"positionabove\"","value":[{"value":"\"positionautomatic\""},{"value":"\"positionbelow\""},{"value":"\"positionabove\""}]}},"showBubble":{"defaultValue":null,"description":"
|
|
1
|
+
{"props":{"helpBubbleId":{"defaultValue":null,"description":"Id of the HelpBubble","name":"helpBubbleId","parent":{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"string"}},"children":{"defaultValue":null,"description":"Name to display in the avatar. Will be truncated to the first two characters.","name":"children","parent":{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},{"fileName":"designsystem/node_modules/@types/react/index.d.ts","name":"TypeLiteral"}],"required":false,"type":{"name":"ReactNode"}},"controllerRef":{"defaultValue":null,"description":"Ref for the element the HelpBubble is placed upon","name":"controllerRef","parent":{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":true,"type":{"name":"RefObject<HTMLElement | SVGSVGElement>"}},"className":{"defaultValue":null,"description":"Adds custom classes to the element.","name":"className","parent":{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"string"}},"variant":{"defaultValue":null,"description":"Determines the placement of the helpbubble. Default: automatic positioning.","name":"variant","parent":{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"enum","raw":"\"positionautomatic\" | \"positionbelow\" | \"positionabove\"","value":[{"value":"\"positionautomatic\""},{"value":"\"positionbelow\""},{"value":"\"positionabove\""}]}},"showBubble":{"defaultValue":null,"description":"Show the bubble. Default: false.","name":"showBubble","parent":{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"boolean"}},"noCloseButton":{"defaultValue":null,"description":"Hide the close button in the bubble","name":"noCloseButton","parent":{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"boolean"}},"linkText":{"defaultValue":null,"description":"Visible text on the link","name":"linkText","parent":{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"string"}},"linkUrl":{"defaultValue":null,"description":"Url the link leads to","name":"linkUrl","parent":{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"string"}},"onLinkClick":{"defaultValue":null,"description":"Function is called when link is clicked","name":"onLinkClick","parent":{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"(() => void)"}},"onClose":{"defaultValue":null,"description":"Function is called when user clicks the button","name":"onClose","parent":{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"(() => void)"}},"closeAriaLabel":{"defaultValue":null,"description":"aria-label to be passed onto Close","name":"closeAriaLabel","parent":{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"string"}},"testId":{"defaultValue":null,"description":"Sets the data-testid attribute.","name":"testId","parent":{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"string"}}}}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"../../HelpBubble.js";import{a as
|
|
1
|
+
import"../../HelpBubble.js";import{a as C,H as D}from"../../HelpBubble.js";import"classnames";import"react";import"../../constants.js";import"../../hooks/useInterval.js";import"../../hooks/useIsVisible.js";import"../../hooks/useIntersectionObserver.js";import"../../hooks/useLayoutEvent.js";import"../../debounce.js";import"../../hooks/useSize.js";import"../../AnchorLink.js";import"../Icons/Icon.js";import"../../hooks/useUuid.js";import"../../uuid.js";import"../Icons/ArrowUpRight.js";import"../../theme/currys/color.js";import"../../theme/index.js";import"../../theme/palette.js";import"../../theme/spacers.js";import"../../theme/grid.js";import"../../hooks/useHover.js";import"../AnchorLink/styles.module.scss";import"../../Close.js";import"../Icons/X.js";import"../Close/styles.module.scss";import"../../hooks/useBreakpoint.js";import"./styles.module.scss";export{C as HelpBubbleVariant,D as default};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -15,32 +15,32 @@
|
|
|
15
15
|
line-height: $lineheight-size-sm;
|
|
16
16
|
background-color: $white;
|
|
17
17
|
z-index: 3;
|
|
18
|
-
visibility:
|
|
18
|
+
visibility: hidden;
|
|
19
|
+
|
|
20
|
+
&--visible {
|
|
21
|
+
visibility: visible;
|
|
22
|
+
}
|
|
19
23
|
|
|
20
24
|
border: getSpacer(4xs) solid $plum600;
|
|
21
25
|
border-radius: 9px;
|
|
22
26
|
box-shadow: 0 2px 18px 0 rgba(0, 0, 0, 0.15);
|
|
23
27
|
|
|
24
|
-
&--initial-render {
|
|
25
|
-
visibility: hidden;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
28
|
@media (min-width: map-get($grid-breakpoints, lg)) {
|
|
29
29
|
font-size: $font-size-md;
|
|
30
30
|
line-height: $lineheight-size-md;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
&
|
|
33
|
+
&__content {
|
|
34
34
|
display: flex;
|
|
35
35
|
width: max-content;
|
|
36
36
|
flex-direction: column;
|
|
37
37
|
align-items: flex-start;
|
|
38
38
|
overflow-wrap: anywhere;
|
|
39
39
|
row-gap: getSpacer(2xs);
|
|
40
|
-
padding: getSpacer(s)
|
|
40
|
+
padding: getSpacer(s) getSpacer(s) getSpacer(m) getSpacer(s);
|
|
41
41
|
|
|
42
|
-
&--
|
|
43
|
-
padding:
|
|
42
|
+
&--close {
|
|
43
|
+
padding-right: 0;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
> p {
|
|
@@ -48,38 +48,39 @@
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
&__link
|
|
51
|
+
&__link {
|
|
52
52
|
all: unset;
|
|
53
53
|
@include anchorlink;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
&__close
|
|
56
|
+
&__close {
|
|
57
57
|
padding: getSpacer(2xs) getSpacer(2xs) 0px 0px;
|
|
58
58
|
}
|
|
59
|
-
}
|
|
60
59
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
&__arrow {
|
|
61
|
+
visibility: hidden;
|
|
62
|
+
width: 0;
|
|
63
|
+
height: 0;
|
|
64
|
+
position: fixed;
|
|
65
|
+
border-style: solid;
|
|
66
|
+
border-color: transparent;
|
|
67
|
+
z-index: 4;
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
-webkit-filter: drop-shadow($plum600 0px 2px 6px 2px);
|
|
73
|
-
filter: drop-shadow(0px -0.185rem 0px $plum600);
|
|
74
|
-
}
|
|
75
|
-
&--under {
|
|
76
|
-
border-width: 10px 10px;
|
|
77
|
-
border-top-color: $white;
|
|
78
|
-
-webkit-filter: drop-shadow($plum600 0px 2px 6px 2px);
|
|
79
|
-
filter: drop-shadow(0px 0.2rem 0px $plum600);
|
|
80
|
-
}
|
|
69
|
+
&--visible {
|
|
70
|
+
visibility: visible;
|
|
71
|
+
}
|
|
81
72
|
|
|
82
|
-
|
|
83
|
-
|
|
73
|
+
&--over {
|
|
74
|
+
border-width: 10px 10px;
|
|
75
|
+
border-bottom-color: $white;
|
|
76
|
+
-webkit-filter: drop-shadow($plum600 0px 2px 6px 2px);
|
|
77
|
+
filter: drop-shadow(0px -0.185rem 0px $plum600);
|
|
78
|
+
}
|
|
79
|
+
&--under {
|
|
80
|
+
border-width: 10px 10px;
|
|
81
|
+
border-top-color: $white;
|
|
82
|
+
-webkit-filter: drop-shadow($plum600 0px 2px 6px 2px);
|
|
83
|
+
filter: drop-shadow(0px 0.2rem 0px $plum600);
|
|
84
|
+
}
|
|
84
85
|
}
|
|
85
86
|
}
|
|
@@ -3,16 +3,16 @@ export type Styles = {
|
|
|
3
3
|
anchorlink__icon: string;
|
|
4
4
|
'anchorlink-wrapper': string;
|
|
5
5
|
helpbubble: string;
|
|
6
|
-
|
|
7
|
-
'
|
|
8
|
-
'
|
|
9
|
-
'
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
'
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
'helpbubble
|
|
6
|
+
helpbubble__arrow: string;
|
|
7
|
+
'helpbubble__arrow--over': string;
|
|
8
|
+
'helpbubble__arrow--under': string;
|
|
9
|
+
'helpbubble__arrow--visible': string;
|
|
10
|
+
helpbubble__close: string;
|
|
11
|
+
helpbubble__content: string;
|
|
12
|
+
'helpbubble__content--close': string;
|
|
13
|
+
helpbubble__link: string;
|
|
14
|
+
helpbubble__link__icon: string;
|
|
15
|
+
'helpbubble--visible': string;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
export type ClassNames = keyof Styles;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
import { HelpBubbleVariant } from './HelpBubble';
|
|
3
|
+
/**
|
|
4
|
+
* Beregn om hjelpeboblen skal vises over eller under kontrolleren
|
|
5
|
+
* @param controllerSize DOMRect for controlleren
|
|
6
|
+
* @param bubbleSize DOMRect for hjelpeboblen
|
|
7
|
+
* @param variant Ønsket plassering av hjelpeboblen (over/under/automatisk)
|
|
8
|
+
* @returns Om hjelpeboblen skal vises over eller under
|
|
9
|
+
*/
|
|
10
|
+
export declare const getVerticalPosition: (controllerSize: DOMRect, bubbleSize: DOMRect, variant: keyof typeof HelpBubbleVariant) => keyof typeof HelpBubbleVariant;
|
|
11
|
+
/**
|
|
12
|
+
* Finn riktig plassering av hjelpeboblen
|
|
13
|
+
* @param controllerSize DOMRect for controlleren
|
|
14
|
+
* @param bubbleSize DOMRect for hjelpeboblen
|
|
15
|
+
* @param variant Ønsket plassering av hjelpeboblen (over/under)
|
|
16
|
+
* @returns CSSProperties som plasserer hjelpeboblen riktig
|
|
17
|
+
*/
|
|
18
|
+
export declare const getBubbleStyle: (controllerSize: DOMRect, bubbleSize: DOMRect, variant: keyof typeof HelpBubbleVariant) => CSSProperties;
|
|
19
|
+
/**
|
|
20
|
+
* Finn riktig plassering av pilen
|
|
21
|
+
* @param bubbleStyle CSSProperties for hjelpeboblen
|
|
22
|
+
* @param controllerSize DOMRect for kontrolleren
|
|
23
|
+
* @param verticalPosition Ønsket plassering av hjelpeboblen (over/under)
|
|
24
|
+
* @returns CSSProperties som plasserer pilen riktig
|
|
25
|
+
*/
|
|
26
|
+
export declare const getArrowStyle: (bubbleStyle: CSSProperties, controllerSize: DOMRect, verticalPosition: keyof typeof HelpBubbleVariant) => CSSProperties;
|
|
27
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/HelpBubble/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAkBjD;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,mBACd,OAAO,cACX,OAAO,WACV,MAAM,wBAAwB,KACtC,MAAM,wBASR,CAAC;AAsKF;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,mBAAoB,OAAO,cAAc,OAAO,WAAW,MAAM,wBAAwB,KAAG,aA0BtH,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,gBACX,aAAa,kBACV,OAAO,oBACL,MAAM,wBAAwB,KAC/C,aA+BF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"props":{"helpBubbleId":{"defaultValue":null,"description":"Id of the HelpBubble","name":"helpBubbleId","parent":{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"string"}},"children":{"defaultValue":null,"description":"Name to display in the avatar. Will be truncated to the first two characters.","name":"children","parent":{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},{"fileName":"designsystem/node_modules/@types/react/index.d.ts","name":"TypeLiteral"}],"required":false,"type":{"name":"ReactNode"}},"controllerRef":{"defaultValue":null,"description":"Ref for the element the HelpBubble is placed upon","name":"controllerRef","parent":{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":true,"type":{"name":"RefObject<HTMLElement | SVGSVGElement>"}},"className":{"defaultValue":null,"description":"Adds custom classes to the element.","name":"className","parent":{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"string"}},"variant":{"defaultValue":null,"description":"Determines the placement of the helpbubble","name":"variant","parent":{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"enum","raw":"\"positionautomatic\" | \"positionbelow\" | \"positionabove\"","value":[{"value":"\"positionautomatic\""},{"value":"\"positionbelow\""},{"value":"\"positionabove\""}]}},"showBubble":{"defaultValue":null,"description":"
|
|
1
|
+
{"props":{"helpBubbleId":{"defaultValue":null,"description":"Id of the HelpBubble","name":"helpBubbleId","parent":{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"string"}},"children":{"defaultValue":null,"description":"Name to display in the avatar. Will be truncated to the first two characters.","name":"children","parent":{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},{"fileName":"designsystem/node_modules/@types/react/index.d.ts","name":"TypeLiteral"}],"required":false,"type":{"name":"ReactNode"}},"controllerRef":{"defaultValue":null,"description":"Ref for the element the HelpBubble is placed upon","name":"controllerRef","parent":{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":true,"type":{"name":"RefObject<HTMLElement | SVGSVGElement>"}},"className":{"defaultValue":null,"description":"Adds custom classes to the element.","name":"className","parent":{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"string"}},"variant":{"defaultValue":null,"description":"Determines the placement of the helpbubble. Default: automatic positioning.","name":"variant","parent":{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"enum","raw":"\"positionautomatic\" | \"positionbelow\" | \"positionabove\"","value":[{"value":"\"positionautomatic\""},{"value":"\"positionbelow\""},{"value":"\"positionabove\""}]}},"showBubble":{"defaultValue":null,"description":"Show the bubble. Default: false.","name":"showBubble","parent":{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"boolean"}},"noCloseButton":{"defaultValue":null,"description":"Hide the close button in the bubble","name":"noCloseButton","parent":{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"boolean"}},"linkText":{"defaultValue":null,"description":"Visible text on the link","name":"linkText","parent":{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"string"}},"linkUrl":{"defaultValue":null,"description":"Url the link leads to","name":"linkUrl","parent":{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"string"}},"onLinkClick":{"defaultValue":null,"description":"Function is called when link is clicked","name":"onLinkClick","parent":{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"(() => void)"}},"onClose":{"defaultValue":null,"description":"Function is called when user clicks the button","name":"onClose","parent":{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"(() => void)"}},"closeAriaLabel":{"defaultValue":null,"description":"aria-label to be passed onto Close","name":"closeAriaLabel","parent":{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"string"}},"testId":{"defaultValue":null,"description":"Sets the data-testid attribute.","name":"testId","parent":{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"},"declarations":[{"fileName":"designsystem/src/components/HelpBubble/HelpBubble.tsx","name":"HelpBubbleProps"}],"required":false,"type":{"name":"string"}}}}
|