forked from shoelace-style/shoelace
-
Notifications
You must be signed in to change notification settings - Fork 0
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
add a new currency input #13
Draft
rkcrisafi
wants to merge
5
commits into
next
Choose a base branch
from
kristina-add-currency-type
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d4d7570
add a new currency input
rkcrisafi de65466
add comments to the display page
rkcrisafi d9c9217
add the new version to changelog
rkcrisafi 62d3d1e
address code review
rkcrisafi 9a72e97
address code review + install imask package
rkcrisafi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
address code review
- Loading branch information
commit 62d3d1e53633dd24d801a3cf4789baead6c14488
There are no files selected for viewing
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 |
---|---|---|
|
@@ -252,11 +252,6 @@ export default class SlInput extends ShoelaceElement implements ShoelaceFormCont | |
this.emit('sl-change'); | ||
} | ||
|
||
private handleCurrencyInput() { | ||
const numberWithCommas = this.input.value.replace(/\D/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ","); | ||
this.input.value = numberWithCommas; | ||
} | ||
|
||
private handleClearClick(event: MouseEvent) { | ||
this.value = ''; | ||
this.emit('sl-clear'); | ||
|
@@ -273,8 +268,14 @@ export default class SlInput extends ShoelaceElement implements ShoelaceFormCont | |
} | ||
|
||
private handleInput() { | ||
this.value = this.input.value; | ||
this.formControlController.updateValidity(); | ||
if (this.currency === "usd") { | ||
const numberWithCommas = this.input.value.replace(/\D/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ","); | ||
this.input.value = numberWithCommas; | ||
} else { | ||
this.value = this.input.value; | ||
this.formControlController.updateValidity(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line still needs to be called regardless of the currency attribute |
||
} | ||
|
||
this.emit('sl-input'); | ||
} | ||
|
||
|
@@ -460,17 +461,23 @@ export default class SlInput extends ShoelaceElement implements ShoelaceFormCont | |
'input--no-spin-buttons': this.noSpinButtons | ||
})} | ||
> | ||
<slot | ||
name="prefix" | ||
part="prefix" | ||
class="${classMap({ | ||
'input__prefix': true, | ||
'input__prefix--currency': !!this.currency, | ||
'input__prefix--small': this.size === 'small', | ||
'input__prefix--medium': this.size === 'medium', | ||
'input__prefix--large': this.size === 'large' | ||
})}"> | ||
${ this.currency === "usd" ? "$" : "" } | ||
<slot name="prefix" part="prefix" class="input__prefix"> | ||
${ | ||
this.currency === "usd" | ||
? html` | ||
<div | ||
class=${classMap({ | ||
'input--currency': !!this.currency, | ||
'prefix--small': this.size === 'small', | ||
'prefix--medium': this.size === 'medium', | ||
'prefix--large': this.size === 'large' | ||
})} | ||
> | ||
$ | ||
</div> | ||
` | ||
: '' | ||
} | ||
</slot> | ||
|
||
<input | ||
|
@@ -500,7 +507,7 @@ export default class SlInput extends ShoelaceElement implements ShoelaceFormCont | |
inputmode=${ifDefined(this.inputmode)} | ||
aria-describedby="help-text" | ||
@change=${this.handleChange} | ||
@input=${this.currency === 'usd' ? this.handleCurrencyInput : this.handleInput} | ||
@input=${this.handleInput} | ||
@invalid=${this.handleInvalid} | ||
@keydown=${this.handleKeyDown} | ||
@focus=${this.handleFocus} | ||
|
@@ -552,17 +559,23 @@ export default class SlInput extends ShoelaceElement implements ShoelaceFormCont | |
: '' | ||
} | ||
|
||
<slot | ||
name="suffix" | ||
part="suffix" | ||
class="${classMap({ | ||
'input__suffix': true, | ||
'input__suffix--currency': !!this.currency, | ||
'input__suffix--small': this.size === 'small', | ||
'input__suffix--medium': this.size === 'medium', | ||
'input__suffix--large': this.size === 'large' | ||
})}"> | ||
${ this.currency === "usd" ? "USD" : "" } | ||
<slot name="suffix" part="suffix" class="input__suffix"> | ||
${ | ||
this.currency === "usd" | ||
? html` | ||
<div | ||
class=${classMap({ | ||
'input--currency': !!this.currency, | ||
'suffix--small': this.size === 'small', | ||
'suffix--medium': this.size === 'medium', | ||
'suffix--large': this.size === 'large' | ||
})} | ||
> | ||
USD | ||
</div> | ||
` | ||
: '' | ||
} | ||
</slot> | ||
</div> | ||
</div> | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving this logic into this method is better than having it inline, but we're still modifying the actual value of the input, which could break forms when we try to use it.