Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hide currency element and decrease padding if currency argument is empty #766

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ember-amount-input/src/components/amount-input.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
.amount-input__value {
width: 100%;
font-size: 13px;
padding: 6px 12px 6px 41px;
padding: 6px 12px;
border: 1px solid #e9eaf0; /* TODO: import as variable? */
border-radius: 3px;
transition: border-color 0.5s;
Expand All @@ -42,6 +42,10 @@
cursor: not-allowed;
}

.amount-input__value.with-currency {
padding-left: 41px;
}

/* Remove spin button */

.amount-input input[type='number']::-webkit-inner-spin-button,
Expand Down
13 changes: 9 additions & 4 deletions ember-amount-input/src/components/amount-input.hbs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<div class='amount-input' ...attributes>
<span class='amount-input__currency {{if @value "black"}}'>
{{this.currency}}
</span>
{{#unless this.isCurrencyEmpty}}
<span class='amount-input__currency {{if @value "black"}}'>
{{this.currency}}
</span>
{{/unless}}

<input
class='amount-input__value {{@inputClass}} {{if @disabled "disabled"}}'
class='amount-input__value
{{@inputClass}}
{{if @disabled "disabled"}}
{{unless this.isCurrencyEmpty "with-currency"}}'
id={{this.inputId}}
type='number'
value={{@value}}
Expand Down
8 changes: 8 additions & 0 deletions ember-amount-input/src/components/amount-input.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Component from '@glimmer/component';
import { action } from '@ember/object';
import { isEmpty } from '@ember/utils';
import './amount-input.css';

const KEY_CODE_E = 69;
Expand Down Expand Up @@ -94,6 +95,13 @@ export default class AmountInput extends Component<AmountInputSignature> {
return this.argOrDefault('currency', 'EUR');
}

/**
* Returns true if the currency is an empty string, null, or undefined.
*/
get isCurrencyEmpty(): boolean {
return isEmpty(this.currency);
}

/**
* A custom id applied on the input.
* Defaults to `amount-input`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module('Integration | Component | amount-input', function (hooks) {
/>
`);

assert.dom('.amount-input__currency').hasText('');
assert.dom('.amount-input__currency').doesNotExist();
assert.dom('input').hasNoAttribute('placeholder');
assert.dom('input').hasNoAttribute('id');

Expand Down
Loading