@weahead/react-customizable-modal
Advanced tools
Comparing version 2.0.0-rc.3 to 2.0.1
@@ -1,6 +0,6 @@ | ||
import type { PropsWithChildren } from "react"; | ||
export declare type OverlayProps = PropsWithChildren & { | ||
onClick: (event: MouseEvent | TouchEvent) => void; | ||
}; | ||
export declare function Overlay({ children }: OverlayProps): JSX.Element; | ||
//# sourceMappingURL=Overlay.d.ts.map | ||
import React, { PropsWithChildren } from 'react'; | ||
interface Props { | ||
onClick: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void; | ||
} | ||
export declare const Overlay: React.FC<PropsWithChildren<Props>>; | ||
export {}; |
@@ -1,10 +0,7 @@ | ||
import type { PropsWithChildren } from 'react'; | ||
export declare type ModalProps = PropsWithChildren & { | ||
import React, { ReactNode } from 'react'; | ||
interface Props { | ||
role: string; | ||
}; | ||
export declare const Modal: import("react").ForwardRefExoticComponent<{ | ||
children?: import("react").ReactNode; | ||
} & { | ||
role: string; | ||
} & import("react").RefAttributes<HTMLDivElement>>; | ||
//# sourceMappingURL=UIModal.d.ts.map | ||
children: ReactNode; | ||
} | ||
export declare const Modal: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLDivElement>>; | ||
export {}; |
@@ -1,12 +0,12 @@ | ||
import type { PropsWithChildren } from 'react'; | ||
export declare type ModalProps = PropsWithChildren & { | ||
onEscape?: Function; | ||
onOverlayClick?: (event: MouseEvent | TouchEvent) => void; | ||
id?: string; | ||
isOpen?: boolean; | ||
role?: string; | ||
shouldFocusAfterRender?: boolean; | ||
shouldReturnFocusAfterClose?: boolean; | ||
}; | ||
export declare function Modal({ onOverlayClick, onEscape, children, id, isOpen, role, shouldFocusAfterRender, shouldReturnFocusAfterClose, }: ModalProps): JSX.Element | null; | ||
//# sourceMappingURL=Modal.d.ts.map | ||
import React, { PropsWithChildren } from 'react'; | ||
interface Props { | ||
id: string; | ||
isOpen: boolean; | ||
role: string; | ||
shouldFocusAfterRender: boolean; | ||
onEscape: Function; | ||
onOverlayClick: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void; | ||
shouldReturnFocusAfterClose: boolean; | ||
} | ||
export declare const Modal: React.FC<PropsWithChildren<Props>>; | ||
export {}; |
@@ -1,6 +0,6 @@ | ||
import type { PropsWithChildren } from 'react'; | ||
export declare type ModalPortalProps = PropsWithChildren & { | ||
import React, { PropsWithChildren } from 'react'; | ||
interface Props { | ||
id: string; | ||
}; | ||
export declare const ModalPortal: ({ id, children }: ModalPortalProps) => import("react").ReactPortal | null; | ||
//# sourceMappingURL=ModalPortal.d.ts.map | ||
} | ||
export declare const ModalPortal: React.FC<PropsWithChildren<Props>>; | ||
export {}; |
export declare function useBodyScrollLock(): void; | ||
//# sourceMappingURL=useBodyScrollLock.d.ts.map |
@@ -1,2 +0,3 @@ | ||
export declare function useCloseOnEsc(onEscape: () => void): void; | ||
//# sourceMappingURL=useCloseOnEsc.d.ts.map | ||
declare type onEscapeType = Function; | ||
export declare function useCloseOnEsc(onEscape: onEscapeType): void; | ||
export {}; |
export declare function useHandleKeyPress(callback: (event: KeyboardEvent) => void): void; | ||
//# sourceMappingURL=useHandleKeyPress.d.ts.map |
@@ -1,6 +0,7 @@ | ||
export declare type useTrapFocusOptions = { | ||
/// <reference types="react" /> | ||
declare type optionsType = { | ||
focusOnRender?: boolean; | ||
returnFocus?: boolean; | ||
}; | ||
export declare function useTrapFocus<T extends HTMLElement>(options?: useTrapFocusOptions): import("react").RefObject<T>; | ||
//# sourceMappingURL=useTrapFocus.d.ts.map | ||
export declare function useTrapFocus(opts?: optionsType): import("react").RefObject<HTMLDivElement>; | ||
export {}; |
{ | ||
"name": "@weahead/react-customizable-modal", | ||
"version": "2.0.0-rc.3", | ||
"type": "module", | ||
"description": "A fully customizable and accessable react modal with hook primitives.", | ||
"version": "2.0.1", | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
"typings": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
"scripts": { | ||
"start": "tsdx watch", | ||
"build": "tsdx build", | ||
"test": "tsdx test --passWithNoTests", | ||
"lint": "tsdx lint", | ||
"prepare": "tsdx build", | ||
"release": "standard-version" | ||
}, | ||
"main": "dist/main.cjs.js", | ||
"module": "dist/main.es.js", | ||
"types": "dist/main.d.ts", | ||
"exports": { | ||
".": { | ||
"import": "./dist/main.es.js", | ||
"require": "./dist/main.cjs.js" | ||
"peerDependencies": { | ||
"react": ">=16.9.19", | ||
"react-dom": ">=16.9.19" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "tsdx lint" | ||
} | ||
}, | ||
"sideEffects": false, | ||
"scripts": { | ||
"dev": "npm-run-all build --parallel dev:*", | ||
"dev:main": "vite build --emptyOutDir=false --watch", | ||
"dev:examples": "vite -c vite.config.ts examples", | ||
"build": "vite build", | ||
"test": "vitest -c vite.config.ts" | ||
"keywords": [ | ||
"react", | ||
"modal", | ||
"hooks", | ||
"accessable", | ||
"customizable" | ||
], | ||
"author": "Jonathan Borg <jonathan.borg@weahead.se>", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/weahead/react-customizable-modal.git" | ||
}, | ||
"peerDependencies": { | ||
"react": ">=16.8", | ||
"react-dom": ">=16.8" | ||
"prettier": { | ||
"printWidth": 80, | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "es5" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/weahead/react-customizable-modal/issues" | ||
}, | ||
"homepage": "https://github.com/weahead/react-customizable-modal#readme", | ||
"module": "dist/react-customizable-modal.esm.js", | ||
"devDependencies": { | ||
"@rollup/plugin-typescript": "^8.4.0", | ||
"@testing-library/jest-dom": "^5.16.5", | ||
"@testing-library/react": "^13.3.0", | ||
"@testing-library/user-event": "^14.4.3", | ||
"@types/node": "^16", | ||
"@types/react": "^18", | ||
"@types/react-dom": "^18", | ||
"@vitejs/plugin-react": "^2.0.1", | ||
"jsdom": "^20.0.0", | ||
"npm-run-all": "^4.1.5", | ||
"@types/jest": "^24.9.1", | ||
"@types/react": "^18.2.18", | ||
"@types/react-dom": "^18.2.7", | ||
"husky": "^4.2.1", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"react-spring": "^9.5.2", | ||
"typescript": "^4.6.4", | ||
"vite": "^3.0.7", | ||
"vitest": "^0.22.1" | ||
}, | ||
"dependencies": { | ||
"tabbable": "^6.0.0" | ||
"standard-version": "^9.5.0", | ||
"tsdx": "^0.14.1", | ||
"tslib": "^2.6.1", | ||
"typescript": "^3.7.5", | ||
"@testing-library/react": "^14.0.0" | ||
} | ||
} |
129
README.md
@@ -20,5 +20,5 @@ # react-customizable-modal | ||
- [Default builtin Modal](https://codesandbox.io/s/currying-moon-2251f) | ||
- [Animated modal with react-spring](https://codesandbox.io/s/solitary-pond-b5kw3) | ||
- [Swipe up from below ](https://codesandbox.io/s/bold-murdock-86ysz) | ||
[Default builtin Modal](https://codesandbox.io/s/currying-moon-2251f) | ||
[Animated modal with react-spring](https://codesandbox.io/s/solitary-pond-b5kw3) | ||
[Swipe up from below ](https://codesandbox.io/s/bold-murdock-86ysz) | ||
@@ -30,6 +30,6 @@ ## Code Examples | ||
```jsx | ||
import { Modal } from '@weahead/react-customizable-modal' | ||
import { Modal } from "@weahead/react-customizable-modal"; | ||
function App() { | ||
const [isOpen, setIsOpen] = useState(false) | ||
const [isOpen, setIsOpen] = useState(false); | ||
return ( | ||
@@ -39,3 +39,3 @@ <div> | ||
onClick={() => { | ||
setIsOpen(true) | ||
setIsOpen(true); | ||
}} | ||
@@ -48,6 +48,6 @@ > | ||
onEscape={() => { | ||
setIsOpen(false) | ||
setIsOpen(false); | ||
}} | ||
onOverlayClick={() => { | ||
setIsOpen(false) | ||
setIsOpen(false); | ||
}} | ||
@@ -57,3 +57,3 @@ > | ||
onClick={() => { | ||
setIsOpen(false) | ||
setIsOpen(false); | ||
}} | ||
@@ -65,3 +65,3 @@ > | ||
</div> | ||
) | ||
); | ||
} | ||
@@ -75,3 +75,3 @@ ``` | ||
```jsx | ||
import React from 'react' | ||
import React from "react"; | ||
import { | ||
@@ -81,4 +81,4 @@ useTrapFocus, | ||
useCloseOnEsc, | ||
ModalPortal, | ||
} from 'react-customizable-modal' | ||
ModalPortal | ||
} from "react-customizable-modal"; | ||
@@ -89,10 +89,10 @@ function Overlay({ children }) { | ||
style={{ | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
position: 'fixed', | ||
display: "flex", | ||
justifyContent: "center", | ||
alignItems: "center", | ||
position: "fixed", | ||
top: 0, | ||
bottom: 0, | ||
left: 0, | ||
right: 0, | ||
right: 0 | ||
}} | ||
@@ -102,36 +102,30 @@ > | ||
</div> | ||
) | ||
); | ||
} | ||
function ModalWrapper({ children }) { | ||
useBodyScrollLock() | ||
useCloseOnEsc(onClose) | ||
return <>{children}</> | ||
} | ||
export default function CustomModal({ isOpen, onClose, children }) { | ||
const modalRef = useTrapFocus() | ||
useBodyScrollLock(); | ||
useCloseOnEsc(onClose); | ||
const modalRef = useTrapFocus(); | ||
return ( | ||
isOpen && ( | ||
<ModalPortal id={`customModal`}> | ||
<ModalWrapper> | ||
<Overlay> | ||
<div | ||
ref={modalRef} | ||
style={{ | ||
width: 500, | ||
height: 400, | ||
backgroundColor: '#fff', | ||
padding: 20, | ||
position: 'absolute', | ||
}} | ||
> | ||
<button onClick={onClose}>Close modal</button> | ||
{children} | ||
</div> | ||
</Overlay> | ||
</ModalWrapper> | ||
<Overlay> | ||
<div | ||
ref={modalRef} | ||
style={{ | ||
width: 500, | ||
height: 400, | ||
backgroundColor: "#fff", | ||
padding: 20, | ||
position: "absolute" | ||
}} | ||
> | ||
<button onClick={onClose}>Close modal</button> | ||
{children} | ||
</div> | ||
</Overlay> | ||
</ModalPortal> | ||
) | ||
) | ||
); | ||
} | ||
@@ -143,5 +137,5 @@ ``` | ||
```jsx | ||
import CustomModal from 'CustomModal.jsx' | ||
import CustomModal from "CustomModal.jsx"; | ||
function App() { | ||
const [isOpen, setIsOpen] = useState(false) | ||
const [isOpen, setIsOpen] = useState(false); | ||
return ( | ||
@@ -151,3 +145,3 @@ <div> | ||
onClick={() => { | ||
setIsOpen(true) | ||
setIsOpen(true); | ||
}} | ||
@@ -161,3 +155,3 @@ > | ||
onClose={() => { | ||
setIsOpen(false) | ||
setIsOpen(false); | ||
}} | ||
@@ -168,3 +162,3 @@ > | ||
</div> | ||
) | ||
); | ||
} | ||
@@ -206,3 +200,3 @@ ``` | ||
| --------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| id | no | this will give the DOMnode that is created to hold the modal content an `id` if there already is a DOMnode with that `id` it will reuse that for the new modal | | ||
| id | yes | this will give the DOMnode that is created to hold the modal content an `id` if there already is a DOMnode with that `id` it will reuse that for the new modal | | ||
| isOpen | yes | this will be used to create the portal for the modal and mount the modal | | ||
@@ -226,5 +220,5 @@ | role | no | for a11y purposes we can set the role for our modal, it defaults to `dialog` | | ||
```jsx | ||
const modalRef = useTrapFocus(options) | ||
const modalRef = useTrapFocus(options); | ||
// returns a ref that needs to be given to the element that you want to trap focus within | ||
;<div ref={modalRef}>focus will be trapped in this div</div> | ||
<div ref={modalRef}>focus will be trapped in this div</div>; | ||
``` | ||
@@ -244,3 +238,3 @@ | ||
```jsx | ||
useAriaHide(id) //often `id` would be 'root' | ||
useAriaHide(id); //often `id` would be 'root' | ||
``` | ||
@@ -260,3 +254,3 @@ | ||
```jsx | ||
useBodyScrollLock() | ||
useBodyScrollLock(); | ||
``` | ||
@@ -272,5 +266,5 @@ | ||
```jsx | ||
useHandleKeyPress((e) => { | ||
console.log(e.key) | ||
}) | ||
useHandleKeyPress(e => { | ||
console.log(e.keyCode); | ||
}); | ||
``` | ||
@@ -290,4 +284,4 @@ | ||
useCloseOnEsc(() => { | ||
console.log('ESC key was pressed') | ||
}) | ||
console.log("ESC key was pressed"); | ||
}); | ||
``` | ||
@@ -299,19 +293,2 @@ | ||
#### useOnClickOutside | ||
`import {useOnClickOutside} from '@weahead/react-customizable-modal'` | ||
this hook is used by the `useOnClickOutside` hook but only triggers the callback if the escape key is pressed | ||
```jsx | ||
useOnClickOutside(ref, () => { | ||
console.log('you pressed outside of the desired element') | ||
}) | ||
``` | ||
| argument | required | description | | ||
| -------- | -------- | ---------------------------------------------------------------------------------------------------------- | | ||
| ref | yes | the refrence to the element that when a click outside of that element is triggered, the callback will fire | | ||
| callback | yes | the callback to be triggered, when a click event outside of the referenced element happens | | ||
<!-- ## Tests --> | ||
@@ -318,0 +295,0 @@ |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
SPDX disjunction
LicenseSPDX disjunction for an artifact's license information
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license
Found 1 instance in 1 package
2
11
1
100
0
1
1
1
92977
21
667
286
No
- Removedtabbable@^6.0.0
- Removedtabbable@6.2.0(transitive)