Skip to content

Commit

Permalink
docs: emberjs example
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverlj committed Jul 27, 2020
1 parent 6adc090 commit df4bd95
Show file tree
Hide file tree
Showing 40 changed files with 11,839 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/ember-imask/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 2

[*.hbs]
insert_final_newline = false

[*.{diff,md}]
trim_trailing_whitespace = false
9 changes: 9 additions & 0 deletions packages/ember-imask/.ember-cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
/**
Ember CLI sends analytics information by default. The data is completely
anonymous, but there are times when you might want to disable this behavior.

Setting `disableAnalytics` to true will prevent any data from being sent.
*/
"disableAnalytics": false
}
20 changes: 20 additions & 0 deletions packages/ember-imask/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# unconventional js
/blueprints/*/files/
/vendor/

# compiled output
/dist/
/tmp/

# dependencies
/bower_components/
/node_modules/

# misc
/coverage/
!.*

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
53 changes: 53 additions & 0 deletions packages/ember-imask/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
legacyDecorators: true
}
},
plugins: [
'ember'
],
extends: [
'eslint:recommended',
'plugin:ember/recommended'
],
env: {
browser: true
},
rules: {},
overrides: [
// node files
{
files: [
'.eslintrc.js',
'.template-lintrc.js',
'ember-cli-build.js',
'testem.js',
'blueprints/*/index.js',
'config/**/*.js',
'lib/*/index.js',
'server/**/*.js'
],
parserOptions: {
sourceType: 'script'
},
env: {
browser: false,
node: true
},
plugins: ['node'],
extends: ['plugin:node/recommended'],
rules: {
// this can be removed once the following is fixed
// https://github.com/mysticatea/eslint-plugin-node/issues/77
'node/no-unpublished-require': 'off'
}
}
]
};
25 changes: 25 additions & 0 deletions packages/ember-imask/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist/
/tmp/

# dependencies
/bower_components/
/node_modules/

# misc
/.env*
/.pnp*
/.sass-cache
/connect.lock
/coverage/
/libpeerconnection.log
/npm-debug.log*
/testem.log
/yarn-error.log

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
5 changes: 5 additions & 0 deletions packages/ember-imask/.template-lintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = {
extends: 'octane'
};
31 changes: 31 additions & 0 deletions packages/ember-imask/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
language: node_js
node_js:
- "10"

dist: xenial

addons:
chrome: stable

cache:
yarn: true

env:
global:
# See https://git.io/vdao3 for details.
- JOBS=1

branches:
only:
- master

before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash
- export PATH=$HOME/.yarn/bin:$PATH

install:
- yarn install --non-interactive

script:
- yarn test
3 changes: 3 additions & 0 deletions packages/ember-imask/.watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignore_dirs": ["tmp", "dist"]
}
56 changes: 56 additions & 0 deletions packages/ember-imask/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# How to use imask on emberjs

<a href="https://opencollective.com/imask/donate" target="_blank">
<img src="https://opencollective.com/imask/donate/button.png?color=blue" width=300 />
</a>

## Install

`yarn add --dev imask`

## Dependencies

- [ember-auto-import](https://github.com/ef4/ember-auto-import)
- [ember-modifier](https://github.com/ember-modifier/ember-modifier)

## Mask Input Example

`ember g modifier imask-number`

//app/modifiers/imask-number.js

```javascript
import { modifier } from "ember-modifier";
import IMask from "imask";

export default modifier(function imaskNumber(element /*, params, hash*/) {
const mask = IMask(element, {
mask: Number,
min: -10000,
max: 10000,
thousandsSeparator: " ",
});

return () => mask.destroy();
});
```

```handlebars
<Input @value={{this.number}} {{imask-number}} />
```

## This folder is an ember example with imask setup

### Installation

- `yarn install`

### Running / Development

- `ember serve`
- Visit your app at [http://localhost:4200](http://localhost:4200).

### Routes

- [number-mask](http://localhost:4200/number-mask)
- [phone-mask](http://localhost:4200/phone-mask)
12 changes: 12 additions & 0 deletions packages/ember-imask/app/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Application from '@ember/application';
import Resolver from 'ember-resolver';
import loadInitializers from 'ember-load-initializers';
import config from './config/environment';

export default class App extends Application {
modulePrefix = config.modulePrefix;
podModulePrefix = config.podModulePrefix;
Resolver = Resolver;
}

loadInitializers(App, config.modulePrefix);
Empty file.
Empty file.
13 changes: 13 additions & 0 deletions packages/ember-imask/app/controllers/phone-mask.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Controller from "@ember/controller";
import { action } from "@ember/object";
import { tracked } from "@glimmer/tracking";

export default class PhoneMaskController extends Controller {
@tracked
phone;

@action
updatePhone(value) {
this.phone = value;
}
}
Empty file.
25 changes: 25 additions & 0 deletions packages/ember-imask/app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>EmberImask</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">

{{content-for "head"}}

<link integrity="" rel="stylesheet" href="{{rootURL}}assets/vendor.css">
<link integrity="" rel="stylesheet" href="{{rootURL}}assets/ember-imask.css">

{{content-for "head-footer"}}
</head>
<body>
{{content-for "body"}}

<script src="{{rootURL}}assets/vendor.js"></script>
<script src="{{rootURL}}assets/ember-imask.js"></script>

{{content-for "body-footer"}}
</body>
</html>
Empty file.
54 changes: 54 additions & 0 deletions packages/ember-imask/app/modifiers/imask-number.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import Modifier from "ember-modifier";
import IMask from "imask";

export default class ImaskNumber extends Modifier {
mask;

constructor(owner, args) {
super(owner, args);

if (
this.args.named.onChange &&
typeof this.args.named.onChange !== "function"
) {
throw new Error("onChange must be a function");
}
}

onChangeHandler = () => {
if (
this.mask &&
this.args.named.onChange &&
this.mask.unmaskedValue &&
this.mask.unmaskedValue !== this.args.positional[0]
) {
this.args.named.onChange(this.mask.typedValue);
}
};

didUpdateArguments() {
if (this.mask) {
this.mask.unmaskedValue = this.args.positional[0].toString();
}
}

didInstall() {
this.mask = IMask(this.element, {
mask: Number,
min: -10000,
max: 10000,
thousandsSeparator: " ",
});

if (this.args.named.onChange) {
this.mask.on("complete", this.onChangeHandler);
}
}

willRemove() {
if (this.mask) {
this.mask.off("complete", this.onChangeHandler);
this.mask.destroy();
}
}
}
50 changes: 50 additions & 0 deletions packages/ember-imask/app/modifiers/imask-phone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import Modifier from "ember-modifier";
import IMask from "imask";

export default class ImaskPhone extends Modifier {
mask;

constructor(owner, args) {
super(owner, args);

if (
this.args.named.onChange &&
typeof this.args.named.onChange !== "function"
) {
throw new Error("onChange must be a function");
}
}

onChangeHandler = () => {
if (
this.mask &&
this.args.named.onChange &&
this.mask.unmaskedValue !== this.args.positional[0]
) {
this.args.named.onChange(this.mask.unmaskedValue);
}
};

didUpdateArguments() {
if (this.mask) {
this.mask.unmaskedValue = this.args.positional[0].toString();
}
}

didInstall() {
this.mask = IMask(this.element, {
mask: "+{7}(000)000-00-00",
});

if (this.args.named.onChange) {
this.mask.on("accept", this.onChangeHandler);
}
}

willRemove() {
if (this.mask) {
this.mask.off("accept", this.onChangeHandler);
this.mask.destroy();
}
}
}
Loading

0 comments on commit df4bd95

Please sign in to comment.