Last active
January 2, 2018 21:26
-
-
Save krivaten/3dc4ae4c8db94f5352489590c7d8ca56 to your computer and use it in GitHub Desktop.
New Twiddle
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
import Ember from 'ember'; | |
import hbs from 'htmlbars-inline-precompile'; | |
const { | |
Component | |
} = Ember; | |
export default Component.extend({ | |
classNames: ['alert-container'], | |
attributeBindings: [ | |
'role', | |
'live:aria-live', | |
'atomic:aria-atomic' | |
], | |
layout: hbs` | |
{{#if message}} | |
<div class="alert alert-{{type}}"> | |
{{#if title}} | |
<strong class={{if titleHidden 'sr-only'}}>{{title}}:</strong> | |
{{/if}} | |
{{message}} | |
</div> | |
{{/if}} | |
`, | |
type: 'info', | |
title: null, | |
titleHidden: false, | |
message: null, | |
role: 'alert', | |
live: 'polite', | |
atomic: 'true' | |
}); |
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
import Ember from 'ember'; | |
import UiNum from 'twiddle/components/ui-num'; | |
import { numToWords } from 'twiddle/utils/numbers'; | |
const { | |
get, | |
computed | |
} = Ember; | |
export default UiNum.extend({ | |
classNames: ['ui-currency'], | |
number: null, | |
currencySymbol: "$", | |
splitAmount: computed('number', function() { | |
let number = get(this, 'number') || '0'; | |
return parseFloat(number).toFixed(2).split('.'); | |
}), | |
formattedAmount: computed('number', function() { | |
let splitAmount = get(this, 'splitAmount'); | |
let currencySymbol = get(this, 'currencySymbol'); | |
splitAmount[0] = splitAmount[0].replace(/\B(?=(\d{3})+(?!\d))/g, ','); | |
return `${currencySymbol}${splitAmount.join('.')}`; | |
}), | |
label: computed('number', function() { | |
let splitAmount = get(this, 'splitAmount'); | |
let result = []; | |
splitAmount.forEach((item) => { | |
result.push((item && item !== '00') ? numToWords(item) : null); | |
}); | |
let [ dollars, cents ] = result; | |
if (dollars && cents) { | |
return `${dollars} dollars and ${cents} cents`; | |
} else { | |
return `${dollars} dollars`; | |
} | |
}) | |
}); |
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
import Ember from 'ember'; | |
const { | |
Component, | |
get, | |
computed, | |
} = Ember; | |
const UiIcon = Component.extend({ | |
tagName: 'span', | |
classNameBindings: [ | |
'prefix', | |
'iconClass' | |
], | |
attributeBindings: [ | |
'label:aria-label', | |
'_ariaHidden:aria-hidden' | |
], | |
label: null, | |
prefix: 'fa', | |
icon: null, | |
_ariaHidden: computed('label', function() { | |
return get(this, 'label') ? undefined : 'true'; | |
}), | |
iconClass: computed('icon', function() { | |
const prefix = get(this, 'prefix'); | |
const icon = get(this, 'icon'); | |
if (!icon) { | |
return; | |
} | |
return (icon.indexOf(`${prefix}-`) > -1) ? icon : `${prefix}-${icon}`; | |
}) | |
}); | |
UiIcon.reopenClass({ | |
positionalParams: ['icon'] | |
}); | |
export default UiIcon; |
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
import Ember from 'ember'; | |
import hbs from 'htmlbars-inline-precompile'; | |
const { | |
Component, | |
computed, | |
assert, | |
isPresent, | |
get, | |
guidFor | |
} = Ember; | |
const LABEL_MSG = 'You must provide a "label" attribute for all uses of "{{ui-input}}" for impaired users. If you want to hide the label visually, you may also provide the attribute labelHidden=true.'; | |
export default Component.extend({ | |
classNames: ['form-group'], | |
layout: hbs` | |
<label for="{{inputId}}" class="{{if labelHidden 'sr-only'}}"> | |
{{label}} | |
{{#if required}} | |
<sup class="text-danger">*</sup> | |
{{/if}} | |
</label> | |
{{#if hasBlock}} | |
{{yield this}} | |
{{else}} | |
{{input | |
id=inputId | |
ariaDescribedBy=(if description descriptionId) | |
type=type | |
value=value | |
placeholder=placeholder | |
disabled=disabled | |
required=required | |
class="form-control"}} | |
{{/if}} | |
{{#if description}} | |
<p id="{{descriptionId}}" class="text-muted {{if descriptionHidden 'sr-only'}}"> | |
{{description}} | |
</p> | |
{{/if}} | |
`, | |
id: null, | |
type: 'text', | |
value: null, | |
placeholder: null, | |
disabled: null, | |
required: null, | |
labelHidden: null, | |
label: computed({ | |
set(key, value) { | |
assert(LABEL_MSG, isPresent(value)); | |
return value; | |
} | |
}), | |
containerId: computed('id', function() { | |
return get(this, 'id') || guidFor(this); | |
}), | |
inputId: computed('id', function() { | |
return `${get(this, 'containerId')}-input`; | |
}), | |
descriptionId: computed('containerId', function() { | |
return `${get(this, 'containerId')}-description`; | |
}) | |
}); |
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
import Ember from 'ember'; | |
import hbs from 'htmlbars-inline-precompile'; | |
import { numToWords } from 'twiddle/utils/numbers'; | |
const { | |
Component, | |
computed, | |
get | |
} = Ember; | |
const UiNum = Component.extend({ | |
classNames: ['ui-num'], | |
tagName: 'span', | |
attributeBindings: [ | |
'label:aria-label' | |
], | |
layout: hbs`{{formattedAmount}}`, | |
number: null, | |
splitAmount: computed('number', function() { | |
let number = String(get(this, 'number')) || '0'; | |
return number.split('.'); | |
}), | |
formattedAmount: computed('splitAmount', function() { | |
let splitAmount = get(this, 'splitAmount'); | |
splitAmount[0] = splitAmount[0].replace(/\B(?=(\d{3})+(?!\d))/g, ','); | |
return splitAmount.join('.'); | |
}), | |
label: computed('splitAmount', function() { | |
let splitAmount = get(this, 'splitAmount'); | |
let result = []; | |
splitAmount.forEach((item) => result.push(numToWords(item))); | |
return result.join(' point '); | |
}) | |
}); | |
UiNum.reopenClass({ | |
positionalParams: ['number'] | |
}); | |
export default UiNum; |
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
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
queryParams: ['refreshValue'], | |
refreshValue: null, | |
actions: { | |
refreshIt() { | |
console.log('Triggered refreshIt') | |
this.send('refreshModel') | |
} | |
} | |
}); |
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
import Ember from 'ember'; | |
export function initializeAria() { | |
Ember.TextSupport.reopen({ | |
attributeBindings: [ | |
'ariaDescribedBy:aria-describedby' | |
] | |
}); | |
} | |
export default { | |
name: 'aria', | |
initialize: initializeAria | |
}; |
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
import Ember from 'ember'; | |
import config from './config/environment'; | |
const Router = Ember.Router.extend({ | |
location: 'none', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
this.route('icons'); | |
this.route('inputs'); | |
this.route('alerts'); | |
this.route('numbers'); | |
this.route('currency'); | |
}); | |
export default Router; |
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
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
queryParams: { | |
refreshValue: { | |
refreshModel: true | |
} | |
}, | |
actions: { | |
refreshModel() { | |
console.log('Triggered refreshModel'); | |
this.refresh(); | |
} | |
} | |
}); |
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
@import "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"; | |
@import "https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"; | |
.focusing-outlet:focus { | |
background-color: Azure; | |
} | |
.fa-crap:before { | |
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; | |
content: 'You should not hear this.'; | |
color: black; | |
} |
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
import Ember from 'ember'; | |
export default function destroyApp(application) { | |
Ember.run(application, 'destroy'); | |
} |
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
import Resolver from '../../resolver'; | |
import config from '../../config/environment'; | |
const resolver = Resolver.create(); | |
resolver.namespace = { | |
modulePrefix: config.modulePrefix, | |
podModulePrefix: config.podModulePrefix | |
}; | |
export default resolver; |
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
import Ember from 'ember'; | |
import Application from '../../app'; | |
import config from '../../config/environment'; | |
const { run } = Ember; | |
const assign = Ember.assign || Ember.merge; | |
export default function startApp(attrs) { | |
let application; | |
let attributes = assign({rootElement: "#test-root"}, config.APP); | |
attributes = assign(attributes, attrs); // use defaults, but you can override; | |
run(() => { | |
application = Application.create(attributes); | |
application.setupForTesting(); | |
application.injectTestHelpers(); | |
}); | |
return application; | |
} |
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
import resolver from './helpers/resolver'; | |
import { | |
setResolver | |
} from 'ember-qunit'; | |
setResolver(resolver); |
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
{ | |
"version": "0.11.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.11.0", | |
"ember-data": "2.11.0", | |
"ember-template-compiler": "2.11.0", | |
"ember-testing": "2.11.0" | |
}, | |
"addons": { | |
"ember-a11y": "0.1.15", | |
"ember-a11y-testing": "0.3.0" | |
} | |
} |
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
const TEN = 10; | |
const ONE_HUNDRED = 100; | |
const ONE_THOUSAND = 1000; | |
const ONE_MILLION = 1000000; | |
const ONE_BILLION = 1000000000; | |
const ONE_TRILLION = 1000000000000; | |
const ONE_QUADRILLION = 1000000000000000; | |
const MAX = 9007199254740992; | |
const LESS_THAN_TWENTY = [ | |
'zero', | |
'one', | |
'two', | |
'three', | |
'four', | |
'five', | |
'six', | |
'seven', | |
'eight', | |
'nine', | |
'ten', | |
'eleven', | |
'twelve', | |
'thirteen', | |
'fourteen', | |
'fifteen', | |
'sixteen', | |
'seventeen', | |
'eighteen', | |
'nineteen' | |
]; | |
const TENTHS_LESS_THAN_HUNDRED = [ | |
'zero', | |
'ten', | |
'twenty', | |
'thirty', | |
'forty', | |
'fifty', | |
'sixty', | |
'seventy', | |
'eighty', | |
'ninety' | |
]; | |
export function numToWords(number) { | |
let num = parseInt(number, 10); | |
if (!isFinite(num)) { | |
throw new TypeError('Not a finite number: ' + number + ' (' + typeof number + ')'); | |
} | |
return generateWords(num); | |
} | |
function isFinite(value) { | |
return !(typeof value !== 'number' || value !== value || value === Infinity || value === -Infinity); | |
} | |
function generateWords(number) { | |
let remainder; | |
let word; | |
let words = arguments[1]; | |
// We’re done | |
if (number === 0) { | |
return !words ? 'zero' : words.join(' ').replace(/,$/, ''); | |
} | |
// First run | |
if (!words) { | |
words = []; | |
} | |
// If negative, prepend “minus” | |
if (number < 0) { | |
words.push('minus'); | |
number = Math.abs(number); | |
} | |
if (number < 20) { | |
remainder = 0; | |
word = LESS_THAN_TWENTY[number]; | |
} else if (number < ONE_HUNDRED) { | |
remainder = number % TEN; | |
word = TENTHS_LESS_THAN_HUNDRED[Math.floor(number / TEN)]; | |
// In case of remainder, we need to handle it here to be able to add the “-” | |
if (remainder) { | |
word += '-' + LESS_THAN_TWENTY[remainder]; | |
remainder = 0; | |
} | |
} else if (number < ONE_THOUSAND) { | |
remainder = number % ONE_HUNDRED; | |
word = generateWords(Math.floor(number / ONE_HUNDRED)) + ' hundred'; | |
} else if (number < ONE_MILLION) { | |
remainder = number % ONE_THOUSAND; | |
word = generateWords(Math.floor(number / ONE_THOUSAND)) + ' thousand'; | |
} else if (number < ONE_BILLION) { | |
remainder = number % ONE_MILLION; | |
word = generateWords(Math.floor(number / ONE_MILLION)) + ' million'; | |
} else if (number < ONE_TRILLION) { | |
remainder = number % ONE_BILLION; | |
word = generateWords(Math.floor(number / ONE_BILLION)) + ' billion'; | |
} else if (number < ONE_QUADRILLION) { | |
remainder = number % ONE_TRILLION; | |
word = generateWords(Math.floor(number / ONE_TRILLION)) + ' trillion'; | |
} else if (number <= MAX) { | |
remainder = number % ONE_QUADRILLION; | |
word = generateWords(Math.floor(number / ONE_QUADRILLION)) + | |
' quadrillion'; | |
} | |
words.push(word); | |
return generateWords(remainder, words); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment