@kvdbil/components 17.1.0 → 17.2.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/cjs/components/FocusTrap.js +2 -1
- package/cjs/components/Modal/index.js +1 -1
- package/cjs/components/OffCanvas/index.js +1 -1
- package/esm/components/FocusTrap.js +3 -2
- package/esm/components/Modal/index.js +6 -6
- package/esm/components/OffCanvas/index.js +2 -2
- package/package.json +1 -1
- package/package.json.tmp +1 -1
- package/types/components/FocusTrap.d.ts +4 -3
- package/types/components/Modal/index.d.ts +3 -1
- package/types/components/OffCanvas/index.d.ts +3 -1
|
@@ -1,4 +1,5 @@
|
|
|
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
2
|
display: flex;
|
|
3
|
+
width: 100%;
|
|
3
4
|
height: 100%;
|
|
4
|
-
`;exports.FocusTrap=({children:e,pause:n=!1})=>{const
|
|
5
|
+
`;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})};
|
|
@@ -77,4 +77,4 @@
|
|
|
77
77
|
}
|
|
78
78
|
`,b=r.createGlobalStyle`
|
|
79
79
|
${u}
|
|
80
|
-
`,h=({children:r,isOpen:a,contentStyles:d,withPortal:l=!1,withCloseIcon:u=!0,onClose:h
|
|
80
|
+
`,h=({children:r,isOpen:a,contentStyles:d,withPortal:l=!1,withCloseIcon:u=!0,onClose:h,focusTrapProps:w={},...f})=>{t.useEffect((()=>{const e=e=>{"Escape"===e.key&&a&&h()};return a&&window.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e)}}),[h,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(b,{}),e.jsxs(c,{...f,children:[e.jsx(p,{"data-testid":"background",onClick:h}),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:h,"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=h,exports.default=h;
|
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
overflow-x: hidden;
|
|
8
8
|
overflow-y: auto;
|
|
9
9
|
-webkit-overflow-scrolling: touch;
|
|
10
|
-
`,m=({animationName:r="offCanvasAnimation",animationDuration:l=300,backgroundColor:d,backgroundOverlay:m,children:h,from:$="right",isOpen:g,onClickOutside:x,width:
|
|
10
|
+
`,m=({animationName:r="offCanvasAnimation",animationDuration:l=300,backgroundColor:d,backgroundOverlay:m,children:h,from:$="right",isOpen:g,onClickOutside:x,width:p="375px",withPortal:v,transitionProps:w,focusTrapProps:k={}})=>{const O=e.useRef(null);o.useOutsideClick(O,(()=>x?.())),e.useEffect((()=>{const n=n=>{"Escape"===n.key&&g&&x?.()};return g&&window.addEventListener("keydown",n),()=>{window.removeEventListener("keydown",n)}}),[x,g]),m&&!x&&console.error("Please provide a clickOutside handler when using backgroundOverlay option in OffCanvas component");const b=`${r}--${$}`,j=n.jsxs(n.Fragment,{children:[m&&n.jsx(i.default,{isOpen:g}),n.jsx(n.Fragment,{children:n.jsx(a.CSSTransition,{in:g,className:`${r} ${b}`,classNames:b,...u,...w,children:n.jsx(s.FocusTrap,{pause:!g,...k,children:n.jsx(c,{ref:O,animationName:r,animationDuration:l,backgroundColor:d,from:$,width:p,role:"dialog","aria-modal":"true","aria-label":"Side panel",children:n.jsx(f,{className:`${r}-content`,children:h})})})})})]});return v?t.createPortal(j,document.body):j};exports.OffCanvas=m,exports.default=m;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import{jsx as x}from"react/jsx-runtime";import{useRef as
|
|
1
|
+
import{jsx as x}from"react/jsx-runtime";import{useRef as o,useEffect as g}from"react";import w from"styled-components";const L=w.div`
|
|
2
2
|
display: flex;
|
|
3
|
+
width: 100%;
|
|
3
4
|
height: 100%;
|
|
4
|
-
`,
|
|
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 g(()=>{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],y=e[e.length-1],u=e.findIndex(E=>E===document.activeElement);t.preventDefault(),t.shiftKey?u<=0?y.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]),x(L,{ref:d,children:p})};export{O as FocusTrap};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{jsx as t,jsxs as
|
|
1
|
+
import{jsx as t,jsxs as r,Fragment as w}from"react/jsx-runtime";import{useEffect as b}from"react";import{createPortal as y}from"react-dom";import{CSSTransition as v}from"react-transition-group";import e,{css as k,createGlobalStyle as d}from"styled-components";import T from"../../icons/components/CloseIcon.js";import{resetButtonStyle as E}from"../../utils/utils.js";import{FocusTrap as C}from"../FocusTrap.js";const s=k`
|
|
2
2
|
.backgroundTransition-enter {
|
|
3
3
|
opacity: 0;
|
|
4
4
|
}
|
|
@@ -16,7 +16,7 @@ import{jsx as t,jsxs as n,Fragment as f}from"react/jsx-runtime";import{useEffect
|
|
|
16
16
|
opacity: 0;
|
|
17
17
|
transition: opacity 0.25s ease-in-out;
|
|
18
18
|
}
|
|
19
|
-
`,
|
|
19
|
+
`,S=e.div`
|
|
20
20
|
${s}
|
|
21
21
|
position: fixed;
|
|
22
22
|
width: 100%;
|
|
@@ -24,7 +24,7 @@ import{jsx as t,jsxs as n,Fragment as f}from"react/jsx-runtime";import{useEffect
|
|
|
24
24
|
top: 0;
|
|
25
25
|
left: 0;
|
|
26
26
|
z-index: 200;
|
|
27
|
-
`,
|
|
27
|
+
`,P=e.div`
|
|
28
28
|
z-index: -1;
|
|
29
29
|
position: absolute;
|
|
30
30
|
width: 100%;
|
|
@@ -54,7 +54,7 @@ import{jsx as t,jsxs as n,Fragment as f}from"react/jsx-runtime";import{useEffect
|
|
|
54
54
|
min-width: 355px;
|
|
55
55
|
}
|
|
56
56
|
`,j=e.button`
|
|
57
|
-
${
|
|
57
|
+
${E}
|
|
58
58
|
display: flex;
|
|
59
59
|
justify-self: flex-end;
|
|
60
60
|
|
|
@@ -77,6 +77,6 @@ import{jsx as t,jsxs as n,Fragment as f}from"react/jsx-runtime";import{useEffect
|
|
|
77
77
|
padding-right: 15px !important;
|
|
78
78
|
`}
|
|
79
79
|
}
|
|
80
|
-
`,
|
|
80
|
+
`,F=d`
|
|
81
81
|
${s}
|
|
82
|
-
`,l=({children:c,isOpen:
|
|
82
|
+
`,l=({children:c,isOpen:o,contentStyles:p,withPortal:m=!1,withCloseIcon:u=!0,onClose:i,focusTrapProps:g={},...f})=>{b(()=>{const a=x=>{x.key==="Escape"&&o&&i()};return o&&window.addEventListener("keydown",a),()=>{window.removeEventListener("keydown",a)}},[i,o]);const h=!!(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,{...f,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&&h?y(n,document.body):n};export{l as Modal,l as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{jsxs as
|
|
1
|
+
import{jsxs as k,Fragment as u,jsx as n}from"react/jsx-runtime";import{useRef as b,useEffect as O}from"react";import{createPortal as C}from"react-dom";import h from"styled-components";import{CSSTransition as y}from"react-transition-group";import E from"./Overlay.js";import{useOutsideClick as N}from"./useClickOutside.js";import{FocusTrap as P}from"../FocusTrap.js";const D="offCanvasAnimation",S={timeout:{enter:300,exit:300},mountOnEnter:!0,unmountOnExit:!0},T=h.div`
|
|
2
2
|
${({animationName:t,animationDuration:s,width:e,from:o,backgroundColor:l,theme:i})=>`
|
|
3
3
|
position: fixed;
|
|
4
4
|
z-index: 1001;
|
|
@@ -54,4 +54,4 @@ import{jsxs as x,Fragment as u,jsx as n}from"react/jsx-runtime";import{useRef as
|
|
|
54
54
|
overflow-x: hidden;
|
|
55
55
|
overflow-y: auto;
|
|
56
56
|
-webkit-overflow-scrolling: touch;
|
|
57
|
-
`,$=({animationName:t=
|
|
57
|
+
`,$=({animationName:t=D,animationDuration:s=300,backgroundColor:e,backgroundOverlay:o,children:l,from:i="right",isOpen:r,onClickOutside:a,width:p="375px",withPortal:g,transitionProps:v,focusTrapProps:w={}})=>{const m=b(null);N(m,()=>a?.()),O(()=>{const c=x=>{x.key==="Escape"&&r&&a?.()};return r&&window.addEventListener("keydown",c),()=>{window.removeEventListener("keydown",c)}},[a,r]),o&&!a&&console.error("Please provide a clickOutside handler when using backgroundOverlay option in OffCanvas component");const d=`${t}--${i}`,f=k(u,{children:[o&&n(E,{isOpen:r}),n(u,{children:n(y,{in:r,className:`${t} ${d}`,classNames:d,...S,...v,children:n(P,{pause:!r,...w,children:n(T,{ref:m,animationName:t,animationDuration:s,backgroundColor:e,from:i,width:p,role:"dialog","aria-modal":"true","aria-label":"Side panel",children:n(j,{className:`${t}-content`,children:l})})})})})]});return g?C(f,document.body):f};export{$ as OffCanvas,$ as default};
|
package/package.json
CHANGED
package/package.json.tmp
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
interface FocusTrapProps {
|
|
2
|
+
export interface FocusTrapProps {
|
|
3
3
|
children: React.ReactNode;
|
|
4
4
|
pause?: boolean;
|
|
5
|
+
autoFocusOnOpen?: 'firstElem' | 'firstInput' | 'none';
|
|
6
|
+
restoreFocusOnClose?: boolean;
|
|
5
7
|
}
|
|
6
|
-
export declare const FocusTrap: ({ children, pause }: FocusTrapProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
-
export {};
|
|
8
|
+
export declare const FocusTrap: ({ children, pause, autoFocusOnOpen, restoreFocusOnClose, }: FocusTrapProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
+
import { FocusTrapProps } from '../FocusTrap';
|
|
2
3
|
export interface ModalProps {
|
|
3
4
|
title?: string;
|
|
4
5
|
children: ReactNode;
|
|
@@ -7,6 +8,7 @@ export interface ModalProps {
|
|
|
7
8
|
onClose(): void;
|
|
8
9
|
contentStyles?: object;
|
|
9
10
|
withCloseIcon?: boolean;
|
|
11
|
+
focusTrapProps?: Omit<FocusTrapProps, 'children' | 'pause'>;
|
|
10
12
|
}
|
|
11
|
-
export declare const Modal: ({ children, isOpen, contentStyles, withPortal, withCloseIcon, onClose, ...props }: ModalProps) => import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare const Modal: ({ children, isOpen, contentStyles, withPortal, withCloseIcon, onClose, focusTrapProps, ...props }: ModalProps) => import("react/jsx-runtime").JSX.Element;
|
|
12
14
|
export default Modal;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
import { CSSTransitionProps } from 'react-transition-group/CSSTransition';
|
|
3
|
+
import { FocusTrapProps } from '../FocusTrap';
|
|
3
4
|
export type DIRECTION = 'left' | 'right';
|
|
4
5
|
type TransitionProps = Partial<Pick<CSSTransitionProps, 'timeout' | 'classNames' | 'addEndListener' | 'appear' | 'mountOnEnter'>>;
|
|
5
6
|
export interface OffCanvasProps {
|
|
@@ -14,6 +15,7 @@ export interface OffCanvasProps {
|
|
|
14
15
|
width?: string;
|
|
15
16
|
withPortal?: boolean;
|
|
16
17
|
transitionProps?: TransitionProps;
|
|
18
|
+
focusTrapProps?: Omit<FocusTrapProps, 'children' | 'pause'>;
|
|
17
19
|
}
|
|
18
|
-
export declare const OffCanvas: ({ animationName, animationDuration, backgroundColor, backgroundOverlay, children, from, isOpen, onClickOutside, width, withPortal, transitionProps, }: OffCanvasProps) => import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
export declare const OffCanvas: ({ animationName, animationDuration, backgroundColor, backgroundOverlay, children, from, isOpen, onClickOutside, width, withPortal, transitionProps, focusTrapProps, }: OffCanvasProps) => import("react/jsx-runtime").JSX.Element;
|
|
19
21
|
export default OffCanvas;
|