-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New: Add number format selector component
- Loading branch information
xzhu
committed
May 1, 2018
1 parent
c3cdd20
commit 0f18ce1
Showing
17 changed files
with
264 additions
and
178 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
packages/visualizations/addon/components/number-format-selector.js
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,60 @@ | ||
/** | ||
* Copyright 2018, Yahoo Holdings Inc. | ||
* Licensed under the terms of the MIT license. See accompanying LICENSE.md file for terms. | ||
* | ||
* Usage: | ||
* {{number-format-selector | ||
* format=format | ||
* onUpdateFormat = (action 'onUpdateFormat') | ||
* }} | ||
*/ | ||
|
||
import { get, computed } from '@ember/object'; | ||
import { A } from '@ember/array'; | ||
import Component from '@ember/component'; | ||
import layout from '../templates/components/number-format-selector'; | ||
import NumberFormats from 'navi-visualizations/utils/enums/number-formats'; | ||
|
||
export default Component.extend({ | ||
layout, | ||
|
||
/** | ||
* @property {Array} classNames | ||
*/ | ||
classNames: ['number-format-selector'], | ||
|
||
/** | ||
* @property {Array} predefinedFormats | ||
* list of format types shown to the user | ||
*/ | ||
predefinedFormats: NumberFormats, | ||
|
||
/** | ||
* @property {String} customFormat | ||
* returns empty string if the current format | ||
* is one of the predefined formats | ||
*/ | ||
customFormat: computed('format', function () { | ||
let predefinedFormats = A(get(this, 'predefinedFormats')), | ||
currentFormat = get(this, 'format'), | ||
match = predefinedFormats.findBy('format', currentFormat); | ||
return match ? '' : currentFormat; | ||
}), | ||
|
||
actions: { | ||
/** | ||
* @action updateFormat | ||
*/ | ||
updateFormat(format) { | ||
this.attrs.onUpdateFormat({ format }); | ||
}, | ||
|
||
/** | ||
* @action clearFormat | ||
* format is cleared after selecting the custom format type | ||
*/ | ||
clearFormat() { | ||
this.attrs.onUpdateFormat({ format: '' }); | ||
} | ||
} | ||
}); |
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
52 changes: 52 additions & 0 deletions
52
packages/visualizations/addon/templates/components/number-format-selector.hbs
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,52 @@ | ||
{{!-- Copyright 2018, Yahoo Holdings Inc. Licensed under the terms of the MIT license. See accompanying LICENSE.md file for terms. --}} | ||
<div class="number-format-selector__section-header"> | ||
Format Type | ||
</div> | ||
<div class="number-format-selector__format-list number-format-selector__section"> | ||
{{#each predefinedFormats as |predefinedFormat|}} | ||
<div class={{concat 'number-format-selector__radio-' (dasherize predefinedFormat.name)}}> | ||
{{#radio-button | ||
name='format' | ||
groupValue=(readonly format) | ||
changed=(action 'updateFormat' predefinedFormat.format) | ||
value=predefinedFormat.format | ||
}} | ||
{{predefinedFormat.name}} | ||
{{/radio-button}} | ||
</div> | ||
{{/each}} | ||
<div class="number-format-selector__radio-custom"> | ||
{{#radio-button | ||
name='format' | ||
groupValue=(readonly format) | ||
value=customFormat | ||
changed=(action 'clearFormat') | ||
}} | ||
Custom | ||
{{/radio-button}} | ||
</div> | ||
</div> | ||
|
||
<div class="number-format-selector__section-header"> | ||
Format | ||
</div> | ||
<div class="number-format-selector__format number-format-selector__section"> | ||
{{input | ||
autofocus=true | ||
class='number-format-selector__format-input number-format-selector__text-input' | ||
name='format-input' | ||
type='text' | ||
maxlength="22" | ||
placeholder='Raw Format' | ||
value=format | ||
enter='updateFormat' | ||
focus-out='updateFormat' | ||
}} | ||
</div> | ||
<a class='number-format-selector__doc-link' | ||
href='http://numeraljs.com/#format' | ||
target='_blank' | ||
> | ||
{{navi-icon 'life-ring' class='number-format-selector__icon-documentation'}} | ||
Format Documentation | ||
</a> |
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
16 changes: 16 additions & 0 deletions
16
packages/visualizations/addon/utils/enums/number-formats.js
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,16 @@ | ||
/** | ||
* Copyright 2018, Yahoo Holdings Inc. | ||
* Licensed under the terms of the MIT license. See accompanying LICENSE.md file for terms. | ||
*/ | ||
|
||
import { A } from '@ember/array'; | ||
|
||
/** | ||
* List of number formats | ||
*/ | ||
export default A([ | ||
{ name: 'Number', format: '0,0.00' }, | ||
{ name: 'Decimal', format: '0.000' }, | ||
{ name: 'Nice Number', format: '0.0a' }, | ||
{ name: 'Money', format: '$0,0[.]00' } | ||
]); |
1 change: 1 addition & 0 deletions
1
packages/visualizations/app/components/number-format-selector.js
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 { default } from 'navi-visualizations/components/number-format-selector'; |
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
34 changes: 34 additions & 0 deletions
34
...ages/visualizations/app/styles/navi-visualizations/components/number-format-selector.less
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,34 @@ | ||
/** | ||
* Copyright 2018, Yahoo Holdings Inc. | ||
* Licensed under the terms of the MIT license. See accompanying LICENSE.md file for terms. | ||
*/ | ||
|
||
.number-format-selector { | ||
&__format-list { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
&__format { | ||
height: @report-form-height; | ||
} | ||
|
||
&__doc-link { | ||
font-size: 15px; | ||
} | ||
|
||
&__format-input { | ||
font-size: @font-size-base-large; | ||
} | ||
|
||
&__section { | ||
.config-section(); | ||
} | ||
|
||
&__text-input { | ||
font-family: @font-family-thin; | ||
line-height: @navi-ideal-line-height; | ||
overflow-y: hidden; | ||
padding: 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
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 @@ | ||
export { default } from 'navi-visualizations/utils/enums/number-formats'; |
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
Oops, something went wrong.