@kvdbil/components 17.2.1 → 17.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";var e,t=require("react/jsx-runtime"),r=require("react"),n=require("styled-components");const u=((e=n)&&e.__esModule?e:{default:e}).default.div`
|
|
2
|
-
display: flex;
|
|
3
2
|
width: 100%;
|
|
4
3
|
height: 100%;
|
|
5
4
|
`;exports.FocusTrap=({children:e,pause:n=!1,autoFocusOnOpen:s="firstElem",restoreFocusOnClose:c=!0})=>{const o=r.useRef(null),i=r.useRef([]),l=r.useRef(null),d=r.useRef(null),f=r.useRef(!1);return r.useEffect((()=>{if(n)return void(c&&f.current&&d.current&&d.current.focus());const e=o.current;if(!e)return;c&&(d.current=document.activeElement);const t=["a[href]","button:not([disabled])","textarea:not([disabled])",'input:not([disabled]):not([type="hidden"])',"select:not([disabled])",'[tabindex]:not([tabindex="-1"])'],r=()=>{i.current=Array.from(e.querySelectorAll(t.join(",")))},u=e=>{if("Tab"!==e.key)return;const t=i.current;if(0===t.length)return void e.preventDefault();const r=t[0],n=t[t.length-1],u=t.findIndex((e=>e===document.activeElement));e.preventDefault(),e.shiftKey?u<=0?n.focus():t[u-1].focus():-1===u||u===t.length-1?r.focus():t[u+1].focus()};return r(),"firstElem"===s&&i.current.length>0&&i.current[0].focus(),"firstInput"===s&&i.current.find((e=>"INPUT"===e.tagName))?.focus(),e.addEventListener("keydown",u),l.current=new MutationObserver(r),l.current.observe(e,{childList:!0,subtree:!0}),f.current=!0,()=>{e.removeEventListener("keydown",u),l.current?.disconnect(),l.current=null}}),[n,s,c]),t.jsx(u,{ref:o,children:e})};
|
|
@@ -33,6 +33,9 @@
|
|
|
33
33
|
`,x=l.default.div`
|
|
34
34
|
position: relative;
|
|
35
35
|
max-width: 512px;
|
|
36
|
+
max-height: 90vh;
|
|
37
|
+
overflow-y: auto;
|
|
38
|
+
|
|
36
39
|
padding: 1rem;
|
|
37
40
|
background-color: white;
|
|
38
41
|
border-radius: 3px;
|
|
@@ -41,10 +44,9 @@
|
|
|
41
44
|
0px 9px 46px rgba(0, 0, 0, 0.09),
|
|
42
45
|
0px 11px 15px rgba(0, 0, 0, 0.15);
|
|
43
46
|
|
|
44
|
-
overflow-y: hidden;
|
|
45
47
|
margin: 1rem;
|
|
46
48
|
margin-top: 50vh;
|
|
47
|
-
transform:
|
|
49
|
+
transform: translateY(-50%);
|
|
48
50
|
margin-left: 1rem;
|
|
49
51
|
margin-right: 1rem;
|
|
50
52
|
|
|
@@ -75,6 +77,6 @@
|
|
|
75
77
|
|
|
76
78
|
${typeof window<"u"&&window.innerWidth>1024&&"\n padding-right: 15px !important;\n "}
|
|
77
79
|
}
|
|
78
|
-
`,
|
|
80
|
+
`,h=r.createGlobalStyle`
|
|
79
81
|
${u}
|
|
80
|
-
`,
|
|
82
|
+
`,b=({children:r,isOpen:a,contentStyles:d,withPortal:l=!1,withCloseIcon:u=!0,onClose:b,focusTrapProps:w={},...f})=>{t.useEffect((()=>{const e=e=>{"Escape"===e.key&&a&&b()};return a&&window.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e)}}),[b,a]);const y=!!(typeof window<"u"&&window.document&&window.document.createElement),v=e.jsx(o.CSSTransition,{in:a,mountOnEnter:!0,unmountOnExit:!0,timeout:400,classNames:"backgroundTransition",children:e.jsxs(e.Fragment,{children:[e.jsx(h,{}),e.jsxs(c,{...f,children:[e.jsx(p,{"data-testid":"background",onClick:b}),e.jsx(s.FocusTrap,{pause:!a,...w,children:e.jsxs(x,{style:d,role:"dialog","aria-modal":"true","aria-labelledby":"modal-title",children:[u&&e.jsx(m,{onClick:b,"data-testid":"close",type:"button","aria-label":"Close dialog",children:e.jsx(n.default,{})}),r]})}),e.jsx(g,{})]})]})});return l&&y?i.createPortal(v,document.body):v};exports.Modal=b,exports.default=b;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import{jsx as
|
|
2
|
-
display: flex;
|
|
1
|
+
import{jsx as g}from"react/jsx-runtime";import{useRef as o,useEffect as x}from"react";import w from"styled-components";const L=w.div`
|
|
3
2
|
width: 100%;
|
|
4
3
|
height: 100%;
|
|
5
|
-
`,O=({children:p,pause:f=!1,autoFocusOnOpen:s="firstElem",restoreFocusOnClose:i=!0})=>{const d=o(null),r=o([]),c=o(null),l=o(null),a=o(!1);return
|
|
4
|
+
`,O=({children:p,pause:f=!1,autoFocusOnOpen:s="firstElem",restoreFocusOnClose:i=!0})=>{const d=o(null),r=o([]),c=o(null),l=o(null),a=o(!1);return x(()=>{if(f){i&&a.current&&l.current&&l.current.focus();return}const n=d.current;if(!n)return;i&&(l.current=document.activeElement);const b=["a[href]","button:not([disabled])","textarea:not([disabled])",'input:not([disabled]):not([type="hidden"])',"select:not([disabled])",'[tabindex]:not([tabindex="-1"])'],m=()=>{r.current=Array.from(n.querySelectorAll(b.join(",")))},h=t=>{if(t.key!=="Tab")return;const e=r.current;if(e.length===0){t.preventDefault();return}const v=e[0],E=e[e.length-1],u=e.findIndex(y=>y===document.activeElement);t.preventDefault(),t.shiftKey?u<=0?E.focus():e[u-1].focus():u===-1||u===e.length-1?v.focus():e[u+1].focus()};return m(),s==="firstElem"&&r.current.length>0&&r.current[0].focus(),s==="firstInput"&&r.current.find(t=>t.tagName==="INPUT")?.focus(),n.addEventListener("keydown",h),c.current=new MutationObserver(m),c.current.observe(n,{childList:!0,subtree:!0}),a.current=!0,()=>{n.removeEventListener("keydown",h),c.current?.disconnect(),c.current=null}},[f,s,i]),g(L,{ref:d,children:p})};export{O as FocusTrap};
|
|
@@ -33,6 +33,9 @@ import{jsx as t,jsxs as r,Fragment as w}from"react/jsx-runtime";import{useEffect
|
|
|
33
33
|
`,$=e.div`
|
|
34
34
|
position: relative;
|
|
35
35
|
max-width: 512px;
|
|
36
|
+
max-height: 90vh;
|
|
37
|
+
overflow-y: auto;
|
|
38
|
+
|
|
36
39
|
padding: 1rem;
|
|
37
40
|
background-color: white;
|
|
38
41
|
border-radius: 3px;
|
|
@@ -41,10 +44,9 @@ import{jsx as t,jsxs as r,Fragment as w}from"react/jsx-runtime";import{useEffect
|
|
|
41
44
|
0px 9px 46px rgba(0, 0, 0, 0.09),
|
|
42
45
|
0px 11px 15px rgba(0, 0, 0, 0.15);
|
|
43
46
|
|
|
44
|
-
overflow-y: hidden;
|
|
45
47
|
margin: 1rem;
|
|
46
48
|
margin-top: 50vh;
|
|
47
|
-
transform:
|
|
49
|
+
transform: translateY(-50%);
|
|
48
50
|
margin-left: 1rem;
|
|
49
51
|
margin-right: 1rem;
|
|
50
52
|
|
|
@@ -79,4 +81,4 @@ import{jsx as t,jsxs as r,Fragment as w}from"react/jsx-runtime";import{useEffect
|
|
|
79
81
|
}
|
|
80
82
|
`,F=d`
|
|
81
83
|
${s}
|
|
82
|
-
`,l=({children:c,isOpen:o,contentStyles:p,withPortal:m=!1,withCloseIcon:u=!0,onClose:i,focusTrapProps:g={},...
|
|
84
|
+
`,l=({children:c,isOpen:o,contentStyles:p,withPortal:m=!1,withCloseIcon:u=!0,onClose:i,focusTrapProps:g={},...h})=>{b(()=>{const a=x=>{x.key==="Escape"&&o&&i()};return o&&window.addEventListener("keydown",a),()=>{window.removeEventListener("keydown",a)}},[i,o]);const f=!!(typeof window<"u"&&window.document&&window.document.createElement),n=t(v,{in:o,mountOnEnter:!0,unmountOnExit:!0,timeout:400,classNames:"backgroundTransition",children:r(w,{children:[t(F,{}),r(S,{...h,children:[t(P,{"data-testid":"background",onClick:i}),t(C,{pause:!o,...g,children:r($,{style:p,role:"dialog","aria-modal":"true","aria-labelledby":"modal-title",children:[u&&t(j,{onClick:i,"data-testid":"close",type:"button","aria-label":"Close dialog",children:t(T,{})}),c]})}),t(z,{})]})]})});return m&&f?y(n,document.body):n};export{l as Modal,l as default};
|
package/package.json
CHANGED