Skip to content

Commit

Permalink
feat(addon/components/paper-input): converts to a glimmer component.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhartstonge committed Nov 26, 2024
1 parent b85c643 commit 2e3ca1f
Show file tree
Hide file tree
Showing 2 changed files with 511 additions and 261 deletions.
261 changes: 152 additions & 109 deletions addon/components/paper-input.hbs
Original file line number Diff line number Diff line change
@@ -1,115 +1,158 @@
{{! template-lint-disable no-action no-curly-component-invocation no-down-event-binding no-positive-tabindex }}
{{#if @label}}
<label for={{this.inputElementId}} class={{if @required "md-required"}}>{{@label}}</label>
{{/if}}

{{#if @icon}}
{{component this.iconComponent @icon}}
{{/if}}

{{#if @textarea}}
<textarea
class="md-input {{if this.isInvalid "ng-invalid"}} {{if this.isTouched "ng-dirty"}}"
id={{this.inputElementId}}
placeholder={{if this.shouldAddPlaceholder @placeholder}}
disabled={{this.disabled}}
autofocus={{this.autofocus}}
aria-describedby={{concat this.elementId "-char-count " this.elementId "-error-messages"}}
onfocus={{@onFocus}}
onblur={{action "handleBlur"}}
onkeydown={{@onKeyDown}}
onkeyup={{@onKeyUp}}
onclick={{@onClick}}
oninput={{action "handleInput"}}
<md-input-container
class='md-default-theme
{{~if this.hasValue " md-input-has-value"}}
{{~if this.validation.isInvalidAndTouched " md-input-invalid"}}
{{~if this.hasLeftIcon " md-icon-left"}}
{{~if this.hasRightIcon " md-icon-right"}}
{{~if this.focused " md-input-focused"}}
{{~if this.isBlock " md-block"}}
{{~if @placeholder " md-input-has-placeholder"}}
{{~if @warn " md-warn"}}
{{~if @accent " md-accent"}}
{{~if @primary " md-primary"}} {{@class}}'
disabled={{this.disabled}}
tabindex={{if this.disabled "-1" "0"}}
{{did-insert this.didInsertNode}}
{{did-update this.didUpdateNode @errors @value this.params}}
{{will-destroy this.willDestroyNode}}
...attributes
>
{{#if @label}}
<label
for={{this.inputElementId}}
class={{if @required 'md-required'}}
>{{@label}}</label>
{{/if}}

name={{@passThru.name}}
rows={{@passThru.rows}}
cols={{@passThru.cols}}
maxlength={{@passThru.maxlength}}
tabindex={{@passThru.tabindex}}
title={{@title}}
required={{@passThru.required}}
selectionEnd={{@passThru.selectionEnd}}
selectionStart={{@passThru.selectionStart}}
selectionDirection={{@passThru.selectionDirection}}
wrap={{@passThru.wrap}}
readonly={{@passThru.readonly}}
form={{@passThru.form}}
spellcheck={{@passThru.spellcheck}}></textarea>
{{else}}
<input
class="md-input {{if this.isInvalid "ng-invalid"}} {{if this.isTouched "ng-dirty"}}"
id={{this.inputElementId}}
placeholder={{if this.shouldAddPlaceholder @placeholder}}
type={{this.type}}
disabled={{this.disabled}}
autofocus={{this.autofocus}}
aria-describedby={{concat this.elementId "-char-count " this.elementId "-error-messages"}}
onfocus={{@onFocus}}
onblur={{action "handleBlur"}}
onkeydown={{@onKeyDown}}
onkeyup={{@onKeyUp}}
onclick={{@onClick}}
oninput={{action "handleInput"}}
{{#if @icon}}
{{component this.iconComponent @icon}}
{{/if}}

accept={{@passThru.accept}}
autocomplete={{@passThru.autocomplete}}
autocorrect={{@passThru.autocorrect}}
autocapitalize={{@passThru.autocapitalize}}
autosave={{@passThru.autosave}}
form={{@passThru.form}}
formaction={{@passThru.formaction}}
formenctype={{@passThru.formenctype}}
formmethod={{@passThru.formmethod}}
formnovalidate={{@passThru.formnovalidate}}
formtarget={{@passThru.formtarget}}
height={{@passThru.height}}
inputmode={{@passThru.inputmode}}
min={{@passThru.min}}
maxlength={{@passThru.maxlength}}
max={{@passThru.max}}
multiple={{@passThru.multiple}}
name={{@passThru.name}}
pattern={{@passThru.pattern}}
readonly={{@passThru.readonly}}
required={{@passThru.required}}
selectionDirection={{@passThru.selectionDirection}}
size={{@passThru.size}}
spellcheck={{@passThru.spellcheck}}
step={{@passThru.step}}
tabindex={{@passThru.tabindex}}
title={{@title}}
width={{@passThru.width}}>
{{/if}}
{{#if @textarea}}
<textarea

Check failure on line 32 in addon/components/paper-input.hbs

View workflow job for this annotation

GitHub Actions / Tests

Tabindex values must be negative numeric.
class='md-input
{{~if this.validation.isInvalid " ng-invalid"}}
{{~if this.validation.isTouched " ng-dirty"}}'
id={{this.inputElementId}}
placeholder={{if this.shouldAddPlaceholder @placeholder}}
disabled={{this.disabled}}
autofocus={{@autofocus}}
aria-describedby={{concat
this.elementId
'-char-count '
this.elementId
'-error-messages'
}}
onfocus={{@onFocus}}
onblur={{this.handleBlur}}
onkeydown={{@onKeyDown}}

Check failure on line 48 in addon/components/paper-input.hbs

View workflow job for this annotation

GitHub Actions / Tests

Avoid binding to a `down` event; bind to an `up` event instead
onkeyup={{@onKeyUp}}
onclick={{@onClick}}
oninput={{this.handleInput}}
name={{@passThru.name}}
rows={{@passThru.rows}}
cols={{@passThru.cols}}
maxlength={{@passThru.maxlength}}
tabindex={{@passThru.tabindex}}
title={{@title}}
required={{@passThru.required}}
selectionEnd={{@passThru.selectionEnd}}
selectionStart={{@passThru.selectionStart}}
selectionDirection={{@passThru.selectionDirection}}
wrap={{@passThru.wrap}}
readonly={{@passThru.readonly}}
form={{@passThru.form}}
spellcheck={{@passThru.spellcheck}}
></textarea>
{{else}}
<input

Check failure on line 68 in addon/components/paper-input.hbs

View workflow job for this annotation

GitHub Actions / Tests

Tabindex values must be negative numeric.
class='md-input
{{~if this.validation.isInvalid " ng-invalid"}}
{{~if this.validation.isTouched " ng-dirty"}}'
id={{this.inputElementId}}
placeholder={{if this.shouldAddPlaceholder @placeholder}}
type={{this.type}}
disabled={{this.disabled}}
autofocus={{@autofocus}}
aria-describedby={{concat
this.elementId
'-char-count '
this.elementId
'-error-messages'
}}
onfocus={{@onFocus}}
onblur={{this.handleBlur}}
onkeydown={{@onKeyDown}}

Check failure on line 85 in addon/components/paper-input.hbs

View workflow job for this annotation

GitHub Actions / Tests

Avoid binding to a `down` event; bind to an `up` event instead
onkeyup={{@onKeyUp}}
onclick={{@onClick}}
oninput={{this.handleInput}}
accept={{@passThru.accept}}
autocomplete={{@passThru.autocomplete}}
autocorrect={{@passThru.autocorrect}}
autocapitalize={{@passThru.autocapitalize}}
autosave={{@passThru.autosave}}
form={{@passThru.form}}
formaction={{@passThru.formaction}}
formenctype={{@passThru.formenctype}}
formmethod={{@passThru.formmethod}}
formnovalidate={{@passThru.formnovalidate}}
formtarget={{@passThru.formtarget}}
height={{@passThru.height}}
inputmode={{@passThru.inputmode}}
min={{@passThru.min}}
maxlength={{@passThru.maxlength}}
max={{@passThru.max}}
multiple={{@passThru.multiple}}
name={{@passThru.name}}
pattern={{@passThru.pattern}}
readonly={{@passThru.readonly}}
required={{@passThru.required}}
selectionDirection={{@passThru.selectionDirection}}
size={{@passThru.size}}
spellcheck={{@passThru.spellcheck}}
step={{@passThru.step}}
tabindex={{@passThru.tabindex}}
title={{@title}}
width={{@passThru.width}}
/>
{{/if}}

{{#unless this.hideAllMessages}}
<div class="md-errors-spacer" id={{concat this.elementId "-char-count"}}>
{{#if @maxlength}}
<div class="md-char-counter">{{this.currentLength}}/{{@maxlength}}</div>
{{/if}}
</div>
{{#if this.isInvalidAndTouched}}
<div class="md-input-messages-animation md-auto-hide" id={{concat this.elementId "-error-messages"}}>
{{#each this.validationErrorMessages as |error index|}}
<div id="error-{{this.inputElementId}}-{{index}}"
class="paper-input-error ng-enter ng-enter-active md-input-message-animation"
style="opacity: 1; margin-top: 0">
{{error.message}}
</div>
{{/each}}
{{#unless @hideAllMessages}}
<div class='md-errors-spacer' id={{concat this.elementId '-char-count'}}>
{{#if @maxlength}}
<div class='md-char-counter'>{{this.currentLength}}/{{@maxlength}}</div>
{{/if}}
</div>
{{/if}}
{{/unless}}
{{#if this.validation.isInvalidAndTouched}}
<div
class='md-input-messages-animation md-auto-hide'
id={{concat this.elementId '-error-messages'}}
>
{{#each this.validation.errorMessages as |error index|}}
<div
id='error-{{this.inputElementId}}-{{index}}'
class='paper-input-error ng-enter ng-enter-active md-input-message-animation'
style='opacity: 1; margin-top: 0'
>
{{error.message}}
</div>
{{/each}}
</div>
{{/if}}
{{/unless}}

{{yield (hash
charCount=this.currentLength
isInvalid=this.isInvalid
isTouched=this.isTouched
isInvalidAndTouched=this.isInvalidAndTouched
hasValue=this.hasValue
validationErrorMessages=this.validationErrorMessages
)}}
{{yield
(hash
charCount=this.currentLength
isInvalid=this.validation.isInvalid
isTouched=this.validation.isTouched
isInvalidAndTouched=this.validation.isInvalidAndTouched
hasValue=this.hasValue
validationErrorMessages=this.validation.errorMessages
)
}}

{{#if @iconRight}}
{{component this.iconComponent @iconRight}}
{{/if}}
{{#if @iconRight}}
{{component this.iconComponent @iconRight}}
{{/if}}
</md-input-container>
Loading

0 comments on commit 2e3ca1f

Please sign in to comment.