Skip to content

Commit

Permalink
feat: sidecar FocusLock
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed May 28, 2019
1 parent 187c3c8 commit 5493986
Show file tree
Hide file tree
Showing 29 changed files with 7,179 additions and 202 deletions.
1 change: 1 addition & 0 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@babel/preset-react"
],
"plugins": [
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-runtime",
[
Expand Down
14 changes: 12 additions & 2 deletions .size-limit
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,15 @@
path: "dist/es2015/index.js",
limit: "5 KB",
ignore: ["prop-types", "\\@babel/runtime"]
}
]
},
{
path: "dist/es2015/UI.js",
limit: "1.8 KB",
ignore: ["prop-types", "\\@babel/runtime"]
},
{
path: "dist/es2015/sidecar.js",
limit: "3.5 KB",
ignore: ["prop-types", "\\@babel/runtime"]
},
]
34 changes: 34 additions & 0 deletions UI/UI.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as React from 'react';
import {ReactFocusLockProps, AutoFocusProps, FreeFocusProps, InFocusGuardProps} from "../interfaces";

/**
* Traps Focus inside a Lock
*/
export default class ReactFocusLock extends React.Component<ReactFocusLockProps & {
sideCar: React.SFC
}> {
}

/**
* Autofocus on children on Lock activation
*/
export class AutoFocusInside extends React.Component<AutoFocusProps> {
}

/**
* Autofocus on children
*/
export class MoveFocusInside extends React.Component<AutoFocusProps> {
}

/**
* Allow free focus inside on children
*/
export class FreeFocusInside extends React.Component<FreeFocusProps> {
}

/**
* Secures the focus around the node
*/
export class InFocusGuard extends React.Component<InFocusGuardProps> {
}
8 changes: 8 additions & 0 deletions UI/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"private": true,
"main": "../dist/cjs/sidecar.js",
"jsnext:main": "../dist/es2015/sidecar.js",
"module": "../dist/es2015/sidecar.js",
"types": "sidecar.d.ts",
"sideEffects": false
}
69 changes: 69 additions & 0 deletions examples/preact-parcel/app/Lock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { h } from 'preact';
import React, {Component} from "react";
import {FocusLockUI} from "react-focus-lock";
import {sidecar} from "use-sidecar";

const styles = {
fontFamily: "sans-serif",
textAlign: "center",
fontSize: "16px"
};

const bg = {
backgroundColor: '#FEE'
};

const FocusLockSidecar = sidecar(() => import("react-focus-lock/sidecar"));

class Trap extends Component {
state = {
disabled: true
}

toggle = () => this.setState({disabled: !this.state.disabled});

render() {
const {disabled} = this.state;
return (
<FocusLockUI
disabled={this.state.disabled}
sideCar={FocusLockSidecar}
>
{disabled && <div>
<button onClick={this.toggle}>!ACTIVATE THE TRAP!</button>
<br/>
<br/>
</div>
}
You will cycle over this. Never leaving <br/>
<input placeholder="input1"/>

<input placeholder="input2"/>

<input placeholder="input3"/> <br/>

<button>A BUTTON</button>
<br/>

<a href='#'>link somethere</a> <br/>

{!disabled && <div>
<br/><br/>PRESS this to end the trial.<br/><br/>
<button onClick={this.toggle}>ESCAPE!!!</button>
<br/>
</div>}
</FocusLockUI>
)
}
}

const Lock = () =>
<div style={styles}>
<input placeholder="input1"/>
<div style={bg}> Inaccessible <a href='#'>Link</a> outside</div>
<Trap/>
<div style={bg}> Inaccessible <a href='#'>Link</a> outside</div>
<input placeholder="input1"/>
</div>;

export default Lock;
10 changes: 10 additions & 0 deletions examples/preact-parcel/app/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { h } from 'preact';
import React from 'react';
import ReactDOM from 'react-dom';
import Lock from "./Lock";

const element = document.getElementById('app');
const app = (<Lock/>);


ReactDOM.render(app, element);
14 changes: 14 additions & 0 deletions examples/preact-parcel/app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!-- This file will be used as is in development mode -->
<!-- In production, it will be used as a template on server-rendering -->
<!-- and changed on the fly using cheerio -->
<!-- You can also use your own template engine if you want -->
<!-- but I like to keep things simple -->
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="app"></div>
<script src="./client.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions examples/preact-parcel/dist/1.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5493986

Please sign in to comment.