Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasbm committed Feb 9, 2019
0 parents commit f77fd34
Show file tree
Hide file tree
Showing 56 changed files with 1,572 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
last 2 Chrome versions
last 2 Safari versions
last 2 Firefox versions
82 changes: 82 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

.DS_Store
ec2-user-key-pair.pem
/tmp
env.json
package-lock.json

# compiled output
/dist

# dependencies
/node_modules
/functions/node_modules

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# misc
/.sass-cache
/connect.lock
/coverage/*
/libpeerconnection.log
npm-debug.log
testem.log
logfile

# e2e
/e2e/*.js
/e2e/*.map

#System Files
.DS_Store
Thumbs.db
dump.rdb

/compiled/
/.idea/
/.cache/
/.vscode/
*.log
/logs/
npm-debug.log*
/lib-cov/
/coverage/
/.nyc_output/
/.grunt/
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
.tgz
.env
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
*.pem
*.p12
*.crt
*.csr
/node_modules/
/dist/
/documentation/
43 changes: 43 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting any of the code of conduct enforcers: [Andreas Mehlsen](mailto:[email protected]). All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the Contributor Covenant, version 1.4, available at http://contributor-covenant.org/version/1/4/
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
You are more than welcome to contribute to `@appnest/elements` in any way you please, including:

* Updating documentation.
* Fixing spelling and grammar
* Adding tests
* Fixing issues and suggesting new features
* Blogging, tweeting, and creating tutorials about `@appnest/elements`
* Reaching out to [@AndreasMehlsen](https://twitter.com/AndreasMehlsen) on Twitter
* Submit an issue or a pull request
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright © 2018 Andreas Mehlsen [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# @appnest/elements

<a href="https://npmcharts.com/compare/@appnest/elements?minimal=true"><img alt="Downloads per month" src="https://img.shields.io/npm/dm/@appnest/elements.svg" height="20"></img></a>
<a href="https://david-dm.org/andreasbm/focus-trap"><img alt="Dependencies" src="https://img.shields.io/david/andreasbm/focus-trap.svg" height="20"></img></a>
<a href="https://www.npmjs.com/package/@appnest/elements"><img alt="NPM Version" src="https://img.shields.io/npm/v/@appnest/elements.svg" height="20"></img></a>
<a href="https://github.com/andreasbm/focus-trap/graphs/contributors"><img alt="Contributors" src="https://img.shields.io/github/contributors/andreasbm/focus-trap.svg" height="20"></img></a>
<a href="https://opensource.org/licenses/MIT"><img alt="MIT License" src="https://img.shields.io/badge/License-MIT-yellow.svg" height="20"></img></a>
[![Published on webcomponents.org](https://img.shields.io/badge/webcomponents.org-published-blue.svg)](https://www.webcomponents.org/element/@appnest/elements)

## What is this?

A lightweight web component to trap focus within a DOM node. A focus trap ensures that `tab` and `shift + tab` keys will cycle through the focus trap's tabbable elements but will not leave the focus trap. This is great for making [accessible modals](https://www.w3.org/TR/wai-aria-practices/examples/dialog-modal/dialog.html). Check out the demo at [https://appnest-demo.firebaseapp.com/focus-trap/](https://appnest-demo.firebaseapp.com/focus-trap/).

<img src="https://raw.githubusercontent.com/andreasbm/focus-trap/master/assets/demo.gif" width="400">

**Features**

* Does one things very very well - it traps the focus!
* Pierces through the shadow roots when looking for focusable elements.
* Works right out of the box (just add it to your markup)
* Created using only vanilla js - no dependencies and framework agnostic!

## Installation

```javascript
npm i @appnest/elements
```

## Usage

Import `@appnest/elements` somewhere in your code and you're ready to go! Simply add the focus trap to your `html` and it'll be working without any more effort from your part.

```html
<focus-trap>
<button>Focus 1</button>
<button>Focus 2</button>
<button>Focus 3</button>
<button>Focus 4</button>
<button>Focus 5</button>
</focus-trap>
```

## API

The `focus-trap` element implements the following interface.

```typescript
interface IFocusTrap {
// Returns whether or not the focus trap is inactive.
inactive: boolean;

// Returns whether the focus trap currently has focus.
readonly focused: boolean;

// Focuses the first focusable element in the focus trap.
focusFirstElement: (() => void);

// Focuses the last focusable element in the focus trap.
focusLastElement: (() => void);

// Returns a list of the focusable children found within the element.
getFocusableChildren: (() => HTMLElement[]);
}
```

## 🎉 License

Licensed under [MIT](https://opensource.org/licenses/MIT).
Binary file added assets/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/demo.mov
Binary file not shown.
Binary file added assets/dialog.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/dialog.mov
Binary file not shown.
11 changes: 11 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const {defaultResolvePlugins, defaultKarmaConfig} = require("@appnest/web-config");

module.exports = (config) => {
config.set({
...defaultKarmaConfig({
rollupPlugins: defaultResolvePlugins()
}),
basePath: "src",
logLevel: config.LOG_INFO
});
};
57 changes: 57 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "@appnest/elements",
"version": "0.0.19",
"license": "MIT",
"module": "index.js",
"author": "Appnest",
"description": "A lightweight web component to trap focus within a DOM node",
"bugs": {
"url": "https://github.com/andreasbm/focus-trap/issues"
},
"homepage": "https://github.com/andreasbm/focus-trap#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/andreasbm/focus-trap.git"
},
"keywords": [
"custom",
"elements",
"web",
"component",
"custom element",
"web component",
"focus",
"accessibility",
"dialog",
"focus trap",
"trap"
],
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"ncu": "ncu -u -a && npm update && npm install",
"test": "karma start",
"b:dev": "rollup -c --environment NODE_ENV:dev",
"b:prod": "rollup -c --environment NODE_ENV:prod",
"s:dev": "rollup -c --watch --environment NODE_ENV:dev",
"s:prod": "rollup -c --watch --environment NODE_ENV:prod",
"s": "npm run s:dev",
"start": "npm run s",
"b:lib": "node pre-build.js && tsc -p tsconfig.build.json",
"git:add:commit:push": "git add . && git commit --no-edit --amend --no-verify && git push",
"bump:patch": "npm version patch && npm run git:add:commit:push",
"bump:minor": "npm version minor && npm run git:add:commit:push",
"publish": "cd dist && npm publish --access=public && cd ..",
"bump:major": "npm version major && npm run git:add:commit:push",
"publish:patch": "npm run test && npm run bump:patch && npm run b:lib && npm run publish",
"publish:minor": "npm run test && npm run bump:minor && npm run b:lib && npm run publish",
"publish:major": "npm run test && npm run bump:major && npm run b:lib && npm run publish"
},
"devDependencies": {
"@appnest/web-config": "0.3.9"
},
"dependencies": {
"lit-element": "^2.0.1",
"lit-html": "^1.0.0"
}
}
26 changes: 26 additions & 0 deletions pre-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const rimraf = require("rimraf");
const path = require("path");
const fs = require("fs-extra");
const outLib = "dist";

// TODO: Run "tsc -p tsconfig.build.json" from this script and rename it to "build".

async function preBuild () {
await cleanLib();
copySync("./package.json", `./${outLib}/package.json`);
copySync("./README.md", `./${outLib}/README.md`);
}

function cleanLib () {
return new Promise(res => {
rimraf(outLib, res);
});
}

function copySync (src, dest) {
fs.copySync(path.resolve(__dirname, src), path.resolve(__dirname, dest));
}

preBuild().then(_ => {
console.log(">> Prebuild completed");
});
Loading

0 comments on commit f77fd34

Please sign in to comment.