-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,742 additions
and
697 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
[ | ||
{ | ||
path: "dist/es2015/index.js", | ||
limit: "7 KB", | ||
ignore: ["prop-types", "react-dom", "tslib"] | ||
ignore: ["react-dom", "tslib", "use-sidecar"], | ||
limit: "6 KB" | ||
}, | ||
{ | ||
path: "dist/es2015/sidecar.js", | ||
ignore: ["react-dom", "tslib", "use-sidecar"], | ||
limit: "5 KB" | ||
}, | ||
{ | ||
path: "dist/es2015/UI.js", | ||
ignore: ["react-dom", "tslib", "use-sidecar"], | ||
limit: "2 KB" | ||
} | ||
] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from '../dist/es2015/UI' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"private": true, | ||
"main": "../dist/cjs/UI.js", | ||
"jsnext:main": "../dist/es2015/UI.js", | ||
"module": "../dist/es2015/UI.js", | ||
"types": "UI.d.ts", | ||
"sideEffects": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"private": true, | ||
"main": "../dist/cjs/sidecar.js", | ||
"jsnext:main": "../dist/es2015/sidecar.js", | ||
"module": "../dist/es2015/sidecar.js", | ||
"types": "sidecar.d.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import * as React from 'react'; | ||
|
||
declare var sidecar: React.SFC; | ||
|
||
export default sidecar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import * as React from 'react'; | ||
import {FocusOn as ReactFocusOn} from "./UI"; | ||
import {ReactFocusOnProps} from './types'; | ||
|
||
import sideCar from './sidecar'; | ||
|
||
export function FocusOn(props: ReactFocusOnProps) { | ||
return ( | ||
<ReactFocusOn | ||
{...props} | ||
sideCar={sideCar} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import * as React from 'react'; | ||
|
||
import {hideOthers} from 'aria-hidden'; | ||
|
||
import {InteractivityDisabler} from "./InteractivityDisabler"; | ||
import {EffectProps} from "./types"; | ||
import {focusHiddenMarker} from "./medium"; | ||
|
||
const extractRef = (ref: React.RefObject<any> | HTMLElement): HTMLElement => ( | ||
('current' in ref) ? ref.current : ref | ||
); | ||
|
||
export function Effect( | ||
{ | ||
setLockProps, | ||
|
||
onEscapeKey, | ||
onClickOutside, | ||
shards, | ||
|
||
onActivation, | ||
onDeactivation, | ||
noIsolation | ||
}: EffectProps) { | ||
React.useEffect(() => { | ||
let _undo = () => { | ||
return | ||
}; | ||
let lastEventTarget: EventTarget; | ||
|
||
const onKeyPress = (event: KeyboardEvent) => { | ||
if (event.defaultPrevented) { | ||
return; | ||
} | ||
const code = event.key || event.keyCode; | ||
if ((event.code === 'Escape' || code === 'Escape' || code === 27) && onEscapeKey) { | ||
onEscapeKey(event); | ||
} | ||
}; | ||
|
||
const onClick = (event: MouseEvent) => { | ||
if (event.defaultPrevented || event.target === lastEventTarget) { | ||
return; | ||
} | ||
if ( | ||
shards | ||
.map(extractRef) | ||
.some(node => node && node.contains(event.target as any) || node === event.target) | ||
) { | ||
return; | ||
} | ||
if (onClickOutside) { | ||
onClickOutside(); | ||
} | ||
}; | ||
|
||
const onNodeActivation = (node: HTMLElement) => { | ||
_undo = hideOthers( | ||
[node, ...(shards || []).map(extractRef)], | ||
document.body, | ||
noIsolation ? undefined : focusHiddenMarker | ||
); | ||
if (onActivation) { | ||
onActivation(node); | ||
} | ||
document.addEventListener('keyup', onKeyPress); | ||
document.addEventListener('click', onClick); | ||
}; | ||
|
||
const onNodeDeactivation = () => { | ||
_undo(); | ||
if (onDeactivation) { | ||
onDeactivation(); | ||
} | ||
document.removeEventListener('keyup', onKeyPress); | ||
document.removeEventListener('click', onClick); | ||
}; | ||
|
||
setLockProps({ | ||
onClick: (e: React.MouseEvent) => { | ||
lastEventTarget = e.target | ||
}, | ||
onActivation: onNodeActivation, | ||
onDeactivation: onNodeDeactivation, | ||
}); | ||
|
||
}, []); | ||
|
||
return ( | ||
<InteractivityDisabler/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import * as React from 'react'; | ||
import {SideCarComponent} from "use-sidecar"; | ||
|
||
import {RemoveScroll} from 'react-remove-scroll/UI'; | ||
import ReactFocusLock from 'react-focus-lock/UI' | ||
|
||
import {EffectProps, ReactFocusOnSideProps} from "./types"; | ||
import {effectCar} from "./medium"; | ||
|
||
export function FocusOn(props: ReactFocusOnSideProps) { | ||
const [lockProps, setLockProps] = React.useState(null); | ||
|
||
const {children, autoFocus, shards, enabled = true, scrollLock = true, focusLock = true, sideCar, ...rest} = props; | ||
|
||
const SideCar: SideCarComponent<EffectProps> = sideCar; | ||
return ( | ||
<> | ||
<RemoveScroll | ||
sideCar={enabled && sideCar} | ||
enabled={enabled && scrollLock} | ||
shards={shards} | ||
> | ||
{enabled && <SideCar | ||
{...rest} | ||
sideCar={effectCar} | ||
setLockProps={setLockProps} | ||
shards={shards} | ||
/>} | ||
<ReactFocusLock | ||
sideCar={enabled && sideCar} | ||
disabled={!(lockProps && enabled && focusLock)} | ||
|
||
returnFocus | ||
autoFocus={autoFocus} | ||
|
||
shards={shards} | ||
|
||
lockProps={lockProps} | ||
> | ||
{children} | ||
</ReactFocusLock> | ||
</RemoveScroll> | ||
</> | ||
); | ||
} | ||
|
||
export * from './reExports'; |
Oops, something went wrong.